Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide ccf.EventsEncModeV0 and ccf.EventsEncModeV1 for encoding events in CCF format #3448

Open
Tracked by #6351
fxamacker opened this issue Jul 3, 2024 · 0 comments
Assignees
Labels
Go API Breaking Change Breaks programs which use the Cadence repo as a Go dependency Improvement Performance

Comments

@fxamacker
Copy link
Member

fxamacker commented 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Go API Breaking Change Breaks programs which use the Cadence repo as a Go dependency Improvement Performance
Projects
None yet
Development

No branches or pull requests

2 participants