Skip to content
Open
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
3 changes: 3 additions & 0 deletions changelog/muzry_update_checkpoint_options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Changed

- Refactor checkpoint options validation to use switch statement instead of multiple if conditions
28 changes: 14 additions & 14 deletions cmd/beacon-chain/sync/checkpoint/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,22 @@ func BeaconNodeOptions(c *cli.Context) ([]node.Option, error) {
return []node.Option{opt}, nil
}

if blockPath == "" && statePath == "" {
switch {
case blockPath == "" && statePath == "":
return nil, nil
}
if blockPath != "" && statePath == "" {
case blockPath == "" || statePath == "":
if blockPath == "" {
return nil, errors.New("--checkpoint-state specified, but not --checkpoint-block. both are required")
}
return nil, errors.New("--checkpoint-block specified, but not --checkpoint-state. both are required")
}
if blockPath == "" && statePath != "" {
return nil, errors.New("--checkpoint-state specified, but not --checkpoint-block. both are required")
}

opt := func(node *node.BeaconNode) (err error) {
node.CheckpointInitializer, err = checkpoint.NewFileInitializer(blockPath, statePath)
if err != nil {
return errors.Wrap(err, "error preparing to initialize checkpoint from local ssz files")
default:
opt := func(node *node.BeaconNode) (err error) {
node.CheckpointInitializer, err = checkpoint.NewFileInitializer(blockPath, statePath)
if err != nil {
return errors.Wrap(err, "error preparing to initialize checkpoint from local ssz files")
}
return nil
}
return nil
return []node.Option{opt}, nil
}
return []node.Option{opt}, nil
}