Description
openedon Jul 3, 2024
Updates epic:
Problem
Currently,ccf.EventsEncMode
matches default unsorted CCF codec settings. This can cause future issues because:
- CCF events format v0 and v1 use different CCF settings.
- FVM is using default settings while Flow Emulator is using
ccf.EventsEncMode
(currently same as default but not guaranteed).
Suggested Solution
I think a dedicated CCF mode (immutable settings) should be provided for each CCF-based format and version. For simplicity, maybe each exported CCF mode can use its name to identify the CCF-based format and version.
One benefit of providing such helper functions in here is to help prevent apps individually specifying CCF codec settings for CCF events, so we reduce risk of decoding apps and encoding apps using wrong/different serialization settings.
For example, we can export and use these dedicated modes for encoding events (v0 and v1):
ccf.EventsEncModeV0
: unsorted fields, etc. for compatibility with JSON-CDC, etc.ccf.EventsEncModeV1
: sorted fields, etc. for deterministic encoding
// EventsEncModeV0 is the old unsorted CCF encoding mode for events which contains
// immutable CCF encoding options. It is safe for concurrent use.
var EventsEncModeV0 = &encMode{
sortCompositeFields: SortNone,
sortIntersectionTypes: SortNone,
sortEntitlementTypes: SortNone,
}
// EventsEncModeV1 is the deterministic CCF encoding mode for events which contains
// immutable CCF encoding options. It is safe for concurrent use.
var EventsEncModeV1 = &encMode{
sortCompositeFields: SortBytewiseLexical,
sortIntersectionTypes: SortBytewiseLexical,
sortEntitlementTypes: SortBytewiseLexical,
}
We can also provide dedicated modes for CCF decoding. However, decoding modes can be addressed in a separate issue after encoding modes are resolved.
About CCF
- CCF Specs: https://github.com/onflow/ccf
- CCF Codec: https://github.com/onflow/cadence/tree/master/encoding/ccf