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

[Util] Add verify execution result cmd #6746

Merged
merged 7 commits into from
Dec 2, 2024

Conversation

zhangchiqing
Copy link
Member

@zhangchiqing zhangchiqing commented Nov 20, 2024

Working towards #6557

This PR implemented option 4 in the above issue.

It adds a util command verify-execution-result that takes execution node's data and verifies every single chunks for a range blocks.

Since we would like to make sure future cadence versions are backward compatible. This util allows us to capture any backward compatibilities issue from either FVM or cadence related changes.

For instance, if cadence introduces a breaking change, then it will be caught by running this verify-execution-result with a latest snapshot of EN. The util can verify the last 1M blocks, and 1 of the chunk might fail caused by the breaking change.

I have verified with the latest testnet snapshot, and it worked. It verified 200K blocks after 3 hours, roughly 18 blocks per sec. The memory needed is about 14G.

Future optimization can be done by parallelizing the verification.

@@ -661,42 +646,3 @@ func executorsOf(receipts []*flow.ExecutionReceipt, resultID flow.Identifier) (f

return agrees, disagrees
}

// EndStateCommitment computes the end state of the given chunk.
func EndStateCommitment(result *flow.ExecutionResult, chunkIndex uint64, systemChunk bool) (flow.StateCommitment, error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

moving these functions to a separate package, so that it can be reused.

@codecov-commenter
Copy link

codecov-commenter commented Nov 20, 2024

Codecov Report

Attention: Patch coverage is 3.35821% with 259 lines in your changes missing coverage. Please review.

Project coverage is 41.17%. Comparing base (fb77044) to head (df4891d).

Files with missing lines Patch % Lines
engine/verification/verifier/verifiers.go 0.00% 133 Missing ⚠️
cmd/util/cmd/verify_execution_result/cmd.go 0.00% 56 Missing ⚠️
model/verification/convert/convert.go 0.00% 48 Missing ⚠️
fvm/initialize/options.go 0.00% 18 Missing ⚠️
cmd/scaffold.go 0.00% 3 Missing ⚠️
cmd/util/cmd/root.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6746      +/-   ##
==========================================
- Coverage   41.23%   41.17%   -0.07%     
==========================================
  Files        2061     2065       +4     
  Lines      182702   182905     +203     
==========================================
- Hits        75345    75307      -38     
- Misses     101049   101290     +241     
  Partials     6308     6308              
Flag Coverage Δ
unittests 41.17% <3.35%> (-0.07%) ⬇️

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.

"last k sealed blocks to verify")

Cmd.Flags().StringVar(&flagFromTo, "from_to", "",
"the height range to verify blocks, i.e, 1-1000, 1000-2000, 2000-3000, etc.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"the height range to verify blocks, i.e, 1-1000, 1000-2000, 2000-3000, etc.")
"the height range to verify blocks (inclusive), i.e, 1-1000, 1000-2000, 2000-3000, etc.")


blockID := header.ID()

if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like something was removed. should the also be removed?

return chunkVerifier
}

func initFvmOptions(chainID flow.ChainID, headers storage.Headers) []fvm.Option {
Copy link
Contributor

Choose a reason for hiding this comment

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

can this reuse code from the standard initialization? I worry that the config will drift and we will need to maintain multiple this init in multiple files

@zhangchiqing zhangchiqing force-pushed the leo/cmd-add-verify-execution-result branch from 89ae34a to 6453fb4 Compare November 22, 2024 14:30
Copy link
Member

@fxamacker fxamacker left a comment

Choose a reason for hiding this comment

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

I mostly reviewed from Go programming perspective and left some comments.

}

log.Info().Msgf("verifying range from %d to %d", from, to)
err = verifier.VerifyRange(from, to, flow.Testnet, flagDatadir, flagChunkDataPackDir)
Copy link
Member

Choose a reason for hiding this comment

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

Need to use chain ID provided by user.

Suggested change
err = verifier.VerifyRange(from, to, flow.Testnet, flagDatadir, flagChunkDataPackDir)
err = verifier.VerifyRange(from, to, flow.ChainID(flagChain), flagDatadir, flagChunkDataPackDir)


} else {
log.Info().Msgf("verifying last %d sealed blocks", flagLastK)
err := verifier.VerifyLastKHeight(flagLastK, flow.Testnet, flagDatadir, flagChunkDataPackDir)
Copy link
Member

Choose a reason for hiding this comment

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

Same as above. Need to use chain ID provided by user.

Suggested change
err := verifier.VerifyLastKHeight(flagLastK, flow.Testnet, flagDatadir, flagChunkDataPackDir)
err := verifier.VerifyLastKHeight(flagLastK, flow.ChainID(flagChain), flagDatadir, flagChunkDataPackDir)

log.Info().Msgf("verifying range from %d to %d", from, to)
err = verifier.VerifyRange(from, to, flow.Testnet, flagDatadir, flagChunkDataPackDir)
if err != nil {
log.Fatal().Err(err).Msg("could not verify last k height")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
log.Fatal().Err(err).Msg("could not verify last k height")
log.Fatal().Err(err).Msg("could not verify range from %d to %d", from, to)

if err != nil {
return fmt.Errorf("could not init storages: %w", err)
}
defer db.Close()
Copy link
Member

Choose a reason for hiding this comment

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

Do we also need to close chunkDataPackDB (e.g. by using "chunkDataPackDB.Close()" in defer)?

Maybe have a separate initChunkDataPack() to return chunkDataPackDB so we can close it in defer.

}

root := state.Params().SealedRoot().Height
from := lastSealed.Height - k + 1

This comment was marked as resolved.

if err != nil {
return fmt.Errorf("could not init storages: %w", err)
}
defer db.Close()
Copy link
Member

Choose a reason for hiding this comment

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

Same as above about closing ChunkDataPackDB.

}
defer db.Close()

for height := from; height <= to; height++ {

This comment was marked as resolved.

Comment on lines +37 to +38
Cmd.Flags().StringVar(&flagDatadir, "datadir", "/var/flow/data/protocol",
"directory that stores the protocol state")

This comment was marked as resolved.

Comment on lines +40 to +42
Cmd.Flags().StringVar(&flagChunkDataPackDir, "chunk_data_pack_dir", "/var/flow/data/chunk_data_pack",
"directory that stores the protocol state")

This comment was marked as resolved.

Copy link
Member

@fxamacker fxamacker left a comment

Choose a reason for hiding this comment

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

Thanks for updating the PR! I left some comments.

Comment on lines 84 to 90
defer func() {
err := closer()
if err != nil {
log.Error().Err(err).Msg("failed to close storages")
}
}()
Copy link
Member

Choose a reason for hiding this comment

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

Same as above to consider returning closer() error as well.

@zhangchiqing zhangchiqing force-pushed the leo/cmd-add-verify-execution-result branch from 0c99a9e to df4891d Compare December 2, 2024 21:02
@zhangchiqing zhangchiqing added this pull request to the merge queue Dec 2, 2024
Merged via the queue into master with commit c96b754 Dec 2, 2024
55 checks passed
@zhangchiqing zhangchiqing deleted the leo/cmd-add-verify-execution-result branch December 2, 2024 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants