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

Add version, partial state indicator, and checksum to payload file (intermediate migration file) #5438

Merged
merged 5 commits into from
Feb 26, 2024

Conversation

fxamacker
Copy link
Member

Closes #5437

This PR updates the payload file produced by the state extraction program.

  • Added more metadata to the payload file and a command line flag:
    • file format version
    • partial state vs full state indicator (e.g. whether it includes payloads for all accounts or some)
    • checksum
  • Added --allow-partial-state-from-payload-file flag to execution-state-extract program.

User needs to specify this flag allow partial payload file as input (e.g. not all accounts) in order to prevent accidental use of partial state during real migration.

The primary use case for payload file is for development, testing, and debugging of migrations because it allows migrating a subset of payloads instead of all payloads.

Thanks @zhangchiqing for suggestion to add checksum to this payload file, etc.

Caveats (outside scope of this PR)

Outside the scope of this PR, CRC-32 should eventually be replaced by similar hash used by input files (currently also CRC-32).

Since the input files (checkpoint files) currently use CRC-32, the output file (payload file) also uses CRC-32. We can update the payload file when the checkpoint file format is changed to replace CRC-32 with hash as previously suggested at:

This commit also added --allow-partial-state-from-payload-file flag
to execution-state-extract program.

User needs to specify this flag allow partial payload file as input
(e.g. not all accounts) in order to prevent accidental use of
partial state during real migration.

The primary use case for payload file is for development, testing,
and debugging of migrations because it allows migrating a subset
of payloads instead of all payloads.
@fxamacker fxamacker added Improvement Execution Cadence Execution Team labels Feb 22, 2024
@fxamacker fxamacker requested review from turbolent, janezpodhostnik and a team February 22, 2024 18:08
@fxamacker fxamacker self-assigned this Feb 22, 2024
@codecov-commenter
Copy link

codecov-commenter commented Feb 22, 2024

Codecov Report

Attention: Patch coverage is 68.04511% with 85 lines in your changes are missing coverage. Please review.

Project coverage is 56.04%. Comparing base (c4831ee) to head (583caba).
Report is 6 commits behind head on master.

Files Patch % Lines
cmd/util/ledger/util/payload_file.go 64.70% 50 Missing and 22 partials ⚠️
cmd/util/ledger/util/payload_grouping.go 0.00% 7 Missing ⚠️
cmd/util/cmd/execution-state-extract/cmd.go 72.72% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5438      +/-   ##
==========================================
+ Coverage   56.00%   56.04%   +0.03%     
==========================================
  Files        1026     1026              
  Lines       99940   100033      +93     
==========================================
+ Hits        55973    56064      +91     
  Misses      39677    39677              
- Partials     4290     4292       +2     
Flag Coverage Δ
unittests 56.04% <68.04%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@zhangchiqing zhangchiqing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just some minor suggestions.

// newPayloadFileHeader() returns payload header, consisting of:
// - magic bytes (2 bytes)
// - version (2 bytes)
// - flags (2 bytes)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious why flag needs 2 bytes? isn't 1 byte is enough?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, 1 byte for flag is enough for now. But I ran into a situation in onflow/atree where all flag bits got used, so I use 2 bytes here to avoid this potential issue since it is only 1 extra byte written only once to a file.

exportedPayloadCount, err := util.CreatePayloadFile(
log,
outputPayloadFile,
payloads,
exportPayloadsByAddresses,
false, // payloads represents entire state.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create another CreatePayloadFileWithPartialStateFlag and make CreatePayloadFile to call CreatePayloadFileWithPartialStateFlag with partialStateFlag: false, so that we don't have to add this default value if not needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not in this case because most of the non-test calls of CreatePayloadFile() uses variable returned from another function call (not hard-coded) to indicate if input payloads are for partial or full state. So If we split it into two functions, we need to check this boolean and decide which function to call at higher level.

@fxamacker fxamacker enabled auto-merge February 26, 2024 19:16
@fxamacker fxamacker added this pull request to the merge queue Feb 26, 2024
Merged via the queue into master with commit 35d56ce Feb 26, 2024
50 of 51 checks passed
@fxamacker fxamacker deleted the fxamacker/improve-payload-file branch February 26, 2024 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Execution Cadence Execution Team Improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add version, checksum, and partial state indicator to intermediate migration payload file
4 participants