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

Log the checkpoint file when generating protocol snapshot #5679

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions admin/commands/storage/read_protocol_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (s *ProtocolSnapshotCommand) Handler(_ context.Context, req *admin.CommandR

s.logger.Info().Uint("blocksToSkip", blocksToSkip).Msgf("admintool: generating protocol snapshot")

snapshot, sealedHeight, commit, err := common.GenerateProtocolSnapshotForCheckpoint(
snapshot, sealedHeight, commit, checkpointFile, err := common.GenerateProtocolSnapshotForCheckpoint(
s.logger, s.state, s.headers, s.seals, s.checkpointDir, blocksToSkip)
if err != nil {
return nil, fmt.Errorf("could not generate protocol snapshot for checkpoint, checkpointDir %v: %w",
Expand All @@ -79,10 +79,19 @@ func (s *ProtocolSnapshotCommand) Handler(_ context.Context, req *admin.CommandR
Hex("finalized_block_id", logging.Entity(header)).
Uint64("sealed_height", sealedHeight).
Hex("sealed_commit", commit[:]). // not the commit for the finalized height, but for the sealed height
Str("checkpoint_file", checkpointFile).
Uint("blocks_to_skip", blocksToSkip).
Msgf("admintool: protocol snapshot generated successfully")

return commands.ConvertToMap(serializable.Encodable())
return commands.ConvertToMap(protocolSnapshotResponse{
Snapshot: serializable.Encodable(),
Checkpoint: checkpointFile,
})
Comment on lines +86 to +89
Copy link
Member Author

Choose a reason for hiding this comment

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

Returning the snapshot along with the checkpoint file name.

}

type protocolSnapshotResponse struct {
Snapshot inmem.EncodableSnapshot `json:"snapshot"`
Checkpoint string `json:"checkpoint"`
}

func (s *ProtocolSnapshotCommand) Validator(req *admin.CommandRequest) error {
Expand Down
7 changes: 4 additions & 3 deletions cmd/util/cmd/read-protocol-state/cmd/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@ func runSnapshot(*cobra.Command, []string) {
var protocolSnapshot protocol.Snapshot
var sealedHeight uint64
var sealedCommit flow.StateCommitment
var checkpointFile string
if flagCheckpointScanEndHeight < 0 {
// using default end height which is the last sealed height
protocolSnapshot, sealedHeight, sealedCommit, err = commonFuncs.GenerateProtocolSnapshotForCheckpoint(
protocolSnapshot, sealedHeight, sealedCommit, checkpointFile, err = commonFuncs.GenerateProtocolSnapshotForCheckpoint(
log.Logger, state, storages.Headers, storages.Seals, flagCheckpointDir, flagCheckpointScanStep)
} else {
// using customized end height
protocolSnapshot, sealedHeight, sealedCommit, err = commonFuncs.GenerateProtocolSnapshotForCheckpointWithHeights(
protocolSnapshot, sealedHeight, sealedCommit, checkpointFile, err = commonFuncs.GenerateProtocolSnapshotForCheckpointWithHeights(
log.Logger, state, storages.Headers, storages.Seals, flagCheckpointDir, flagCheckpointScanStep, uint64(flagCheckpointScanEndHeight))
}

Expand All @@ -85,7 +86,7 @@ func runSnapshot(*cobra.Command, []string) {
}

snapshot = protocolSnapshot
log.Info().Msgf("snapshot found, sealed height %v, commit %x", sealedHeight, sealedCommit)
log.Info().Msgf("snapshot found for checkpoint file %v, sealed height %v, commit %x", checkpointFile, sealedHeight, sealedCommit)
}

head, err := snapshot.Head()
Expand Down
14 changes: 7 additions & 7 deletions cmd/util/common/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ func GenerateProtocolSnapshotForCheckpoint(
seals storage.Seals,
checkpointDir string,
blocksToSkip uint,
) (protocol.Snapshot, uint64, flow.StateCommitment, error) {
) (protocol.Snapshot, uint64, flow.StateCommitment, string, error) {
// skip X blocks (i.e. 10) each time to find the block that produces the state commitment in the checkpoint file
// since a checkpoint file contains 500 tries, this allows us to find the block more efficiently
sealed, err := state.Sealed().Head()
if err != nil {
return nil, 0, flow.DummyStateCommitment, err
return nil, 0, flow.DummyStateCommitment, "", err
}
endHeight := sealed.Height

Expand Down Expand Up @@ -156,7 +156,7 @@ func GenerateProtocolSnapshotForCheckpointWithHeights(
checkpointDir string,
blocksToSkip uint,
endHeight uint64,
) (protocol.Snapshot, uint64, flow.StateCommitment, error) {
) (protocol.Snapshot, uint64, flow.StateCommitment, string, error) {
// Stop searching after 10,000 iterations or upon reaching the minimum height, whichever comes first.
startHeight := uint64(0)
// preventing startHeight from being negative
Expand All @@ -167,7 +167,7 @@ func GenerateProtocolSnapshotForCheckpointWithHeights(

checkpointFilePath, err := findLatestCheckpointFilePath(checkpointDir)
if err != nil {
return nil, 0, flow.DummyStateCommitment, fmt.Errorf("could not find latest checkpoint file in directory %v: %w", checkpointDir, err)
return nil, 0, flow.DummyStateCommitment, "", fmt.Errorf("could not find latest checkpoint file in directory %v: %w", checkpointDir, err)
}

log.Info().
Expand All @@ -178,18 +178,18 @@ func GenerateProtocolSnapshotForCheckpointWithHeights(
// find the height of the finalized block that produces the state commitment contained in the checkpoint file
sealedHeight, commit, finalizedHeight, err := FindHeightsByCheckpoints(logger, headers, seals, checkpointFilePath, blocksToSkip, startHeight, endHeight)
if err != nil {
return nil, 0, flow.DummyStateCommitment, fmt.Errorf("could not find sealed height in range [%v:%v] (blocksToSkip: %v) by checkpoints: %w",
return nil, 0, flow.DummyStateCommitment, "", fmt.Errorf("could not find sealed height in range [%v:%v] (blocksToSkip: %v) by checkpoints: %w",
startHeight, endHeight, blocksToSkip,
err)
}

snapshot := state.AtHeight(finalizedHeight)
validSnapshot, err := snapshots.GetDynamicBootstrapSnapshot(state, snapshot)
if err != nil {
return nil, 0, flow.DummyStateCommitment, fmt.Errorf("could not get dynamic bootstrap snapshot: %w", err)
return nil, 0, flow.DummyStateCommitment, "", fmt.Errorf("could not get dynamic bootstrap snapshot: %w", err)
}

return validSnapshot, sealedHeight, commit, nil
return validSnapshot, sealedHeight, commit, checkpointFilePath, nil
}

// hashesToCommits converts a list of ledger.RootHash to a list of flow.StateCommitment
Expand Down
Loading