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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.82979% with 226 lines in your changes missing coverage. Please review.

Project coverage is 41.18%. Comparing base (ed149a7) to head (6453fb4).
Report is 99 commits behind head on master.

Files with missing lines Patch % Lines
engine/verification/verifier/verifiers.go 0.00% 124 Missing ⚠️
cmd/util/cmd/verify_execution_result/cmd.go 0.00% 53 Missing ⚠️
model/verification/convert/convert.go 0.00% 48 Missing ⚠️
cmd/util/cmd/root.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6746      +/-   ##
==========================================
- Coverage   41.19%   41.18%   -0.01%     
==========================================
  Files        2052     2063      +11     
  Lines      182215   182822     +607     
==========================================
+ Hits        75069    75301     +232     
- Misses     100852   101216     +364     
- Partials     6294     6305      +11     
Flag Coverage Δ
unittests 41.18% <3.82%> (-0.01%) ⬇️

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.


🚨 Try these New Features:

"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
Copy link
Member

Choose a reason for hiding this comment

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

Maybe check if k <= lastSealed.Height to prevent overflow since from is uint64?

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++ {
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 need to check from against first verifiable block as in VerifyLastKHeight()?


_, err = verifier.Verify(vcd)
if err != nil {
return fmt.Errorf("could not verify %d-th chunk: %w", i, err)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe also add height in the error message.

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

Choose a reason for hiding this comment

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

Maybe make datadir required.

Suggested change
Cmd.Flags().StringVar(&flagDatadir, "datadir", "/var/flow/data/protocol",
"directory that stores the protocol state")
Cmd.Flags().StringVar(&flagDatadir, "datadir", "/var/flow/data/protocol",
"directory that stores the protocol state")
_ = Cmd.MarkFlagRequired("datadir")

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

Choose a reason for hiding this comment

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

Maybe make chunk_data_pack_dir required.

Suggested change
Cmd.Flags().StringVar(&flagChunkDataPackDir, "chunk_data_pack_dir", "/var/flow/data/chunk_data_pack",
"directory that stores the protocol state")
Cmd.Flags().StringVar(&flagChunkDataPackDir, "chunk_data_pack_dir", "/var/flow/data/chunk_data_pack",
"directory that stores the protocol state")
_ = Cmd.MarkFlagRequired("chunk_data_pack_dir")

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