mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-23 11:57:18 +00:00
d077483577
* v3 import renamings * tidy * fmt * rev * Update beacon-chain/core/epoch/precompute/reward_penalty_test.go * Update beacon-chain/core/helpers/validators_test.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/iface/BUILD.bazel * Update beacon-chain/db/kv/kv.go * Update beacon-chain/db/kv/state.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/sync/initial-sync/service.go * fix deps * fix bad replacements * fix bad replacements * change back * gohashtree version * fix deps Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com>
54 lines
1.8 KiB
Go
54 lines
1.8 KiB
Go
package genesis
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/node"
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/sync/genesis"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
var (
|
|
// StatePath defines a flag to start the beacon chain from a give genesis state file.
|
|
StatePath = &cli.PathFlag{
|
|
Name: "genesis-state",
|
|
Usage: "Load a genesis state from ssz file. Testnet genesis files can be found in the " +
|
|
"eth2-clients/eth2-testnets repository on github.",
|
|
}
|
|
BeaconAPIURL = &cli.StringFlag{
|
|
Name: "genesis-beacon-api-url",
|
|
Usage: "URL of a synced beacon node to trust for obtaining genesis state. " +
|
|
"As an additional safety measure, it is strongly recommended to only use this option in conjunction with " +
|
|
"--weak-subjectivity-checkpoint flag",
|
|
}
|
|
)
|
|
|
|
// BeaconNodeOptions is responsible for determining if the checkpoint sync options have been used, and if so,
|
|
// reading the block and state ssz-serialized values from the filesystem locations specified and preparing a
|
|
// checkpoint.Initializer, which uses the provided io.ReadClosers to initialize the beacon node database.
|
|
func BeaconNodeOptions(c *cli.Context) (node.Option, error) {
|
|
statePath := c.Path(StatePath.Name)
|
|
remoteURL := c.String(BeaconAPIURL.Name)
|
|
if remoteURL != "" {
|
|
return func(node *node.BeaconNode) error {
|
|
var err error
|
|
node.GenesisInitializer, err = genesis.NewAPIInitializer(remoteURL)
|
|
if err != nil {
|
|
return errors.Wrap(err, "error constructing beacon node api client for genesis state init")
|
|
}
|
|
return nil
|
|
}, nil
|
|
}
|
|
|
|
if statePath == "" {
|
|
return nil, nil
|
|
}
|
|
|
|
return func(node *node.BeaconNode) (err error) {
|
|
node.GenesisInitializer, err = genesis.NewFileInitializer(statePath)
|
|
if err != nil {
|
|
return errors.Wrap(err, "error preparing to initialize genesis db state from local ssz files")
|
|
}
|
|
return nil
|
|
}, nil
|
|
}
|