-
Notifications
You must be signed in to change notification settings - Fork 180
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/Admin] Creating protocol snapshot from checkpoint file #5604
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1e77fdc
create protocol snapshot from checkpoint file
zhangchiqing b87ed9f
use validator
zhangchiqing 8c110ca
log blocksToSkip
zhangchiqing 645fceb
refactor GetValidSnapshot
zhangchiqing cba5888
update checkpoint.go to use GetDynamicBootstrapSnapshot
zhangchiqing 5f033da
Apply suggestions from code review
zhangchiqing 846967e
add todo
zhangchiqing f63c06f
fix lint
zhangchiqing File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package storage | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/rs/zerolog" | ||
|
||
"github.com/onflow/flow-go/admin" | ||
"github.com/onflow/flow-go/admin/commands" | ||
"github.com/onflow/flow-go/cmd/util/common" | ||
"github.com/onflow/flow-go/state/protocol" | ||
"github.com/onflow/flow-go/state/protocol/inmem" | ||
"github.com/onflow/flow-go/storage" | ||
"github.com/onflow/flow-go/utils/logging" | ||
) | ||
|
||
var _ commands.AdminCommand = (*ProtocolSnapshotCommand)(nil) | ||
|
||
// ProtocolSnapshotCommand is a command that generates a protocol snapshot for a checkpoint (usually latest checkpoint) | ||
// This command is only available for execution node | ||
type ProtocolSnapshotCommand struct { | ||
logger zerolog.Logger | ||
state protocol.State | ||
headers storage.Headers | ||
seals storage.Seals | ||
checkpointDir string // the directory where the checkpoint is stored | ||
} | ||
|
||
func NewProtocolSnapshotCommand( | ||
logger zerolog.Logger, | ||
state protocol.State, | ||
headers storage.Headers, | ||
seals storage.Seals, | ||
checkpointDir string, | ||
) *ProtocolSnapshotCommand { | ||
return &ProtocolSnapshotCommand{ | ||
logger: logger, | ||
state: state, | ||
headers: headers, | ||
seals: seals, | ||
checkpointDir: checkpointDir, | ||
} | ||
} | ||
|
||
func (s *ProtocolSnapshotCommand) Handler(_ context.Context, req *admin.CommandRequest) (interface{}, error) { | ||
s.logger.Info().Msgf("admintool: generating protocol snapshot") | ||
|
||
blocksToSkip := uint(0) | ||
|
||
// blocksToSkip is the number of blocks to skip when iterating the sealed heights to find the state commitment | ||
// in the checkpoint file. | ||
// default is 0 | ||
input, ok := req.Data.(map[string]interface{}) | ||
if ok { | ||
data, ok := input["blocks-to-skip"] | ||
|
||
if ok { | ||
n, ok := data.(float64) | ||
if !ok { | ||
return nil, fmt.Errorf("could not parse blocks-to-skip: %v", data) | ||
} | ||
blocksToSkip = uint(n) | ||
} | ||
} | ||
|
||
snapshot, sealedHeight, commit, 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", | ||
s.checkpointDir, err) | ||
} | ||
|
||
header, err := snapshot.Head() | ||
if err != nil { | ||
return nil, fmt.Errorf("could not get header from snapshot: %w", err) | ||
} | ||
|
||
serializable, err := inmem.FromSnapshot(snapshot) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not convert snapshot to serializable: %w", err) | ||
} | ||
|
||
s.logger.Info(). | ||
Uint64("finalized_height", header.Height). // finalized height | ||
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 | ||
Uint("blocks_to_skip", blocksToSkip). | ||
Msgf("admintool: protocol snapshot generated successfully") | ||
|
||
return commands.ConvertToMap(serializable.Encodable()) | ||
} | ||
|
||
func (s *ProtocolSnapshotCommand) Validator(_ *admin.CommandRequest) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose the validator should do this validation.