diff --git a/INTEROP.md b/INTEROP.md index 7e22eb70f..3167fb24a 100644 --- a/INTEROP.md +++ b/INTEROP.md @@ -25,7 +25,7 @@ You can use `bazel run //tools/genesis-state-gen` to create a deterministic gene ### Usage -- **--genesis-time** uint: Unix timestamp used as the genesis time in the generated genesis state +- **--genesis-time** uint: Unix timestamp used as the genesis time in the generated genesis state (defaults to now) - **--mainnet-config** bool: Select whether genesis state should be generated with mainnet or minimal (default) params - **--num-validators** int: Number of validators to deterministically include in the generated genesis state - **--output-ssz** string: Output filename of the SSZ marshaling of the generated genesis state @@ -50,7 +50,6 @@ bazel run //beacon-chain -- \ --deposit-contract 0xD775140349E6A5D12524C6ccc3d6A1d4519D4029 \ --clear-db \ --interop-num-validators 64 \ ---interop-genesis-time=$(date +%s) \ --interop-eth1data-votes ``` diff --git a/beacon-chain/interop-cold-start/service.go b/beacon-chain/interop-cold-start/service.go index 62d562e9a..f7a7a1d7f 100644 --- a/beacon-chain/interop-cold-start/service.go +++ b/beacon-chain/interop-cold-start/service.go @@ -83,6 +83,10 @@ func NewColdStartService(ctx context.Context, cfg *Config) *Service { if err != nil { log.Fatalf("Could not generate interop genesis state: %v", err) } + if s.genesisTime == 0 { + // Generated genesis time; fetch it + s.genesisTime = genesisState.GenesisTime + } if err := s.saveGenesisState(ctx, genesisState); err != nil { log.Fatalf("Could not save interop genesis state %v", err) } diff --git a/beacon-chain/node/node.go b/beacon-chain/node/node.go index 51d279ea8..742f85f9f 100644 --- a/beacon-chain/node/node.go +++ b/beacon-chain/node/node.go @@ -415,12 +415,11 @@ func (b *BeaconNode) registerRPCService(ctx *cli.Context) error { return err } - genesisTime := ctx.GlobalUint64(flags.InteropGenesisTimeFlag.Name) genesisValidators := ctx.GlobalUint64(flags.InteropNumValidatorsFlag.Name) genesisStatePath := ctx.GlobalString(flags.InteropGenesisStateFlag.Name) var depositFetcher depositcache.DepositFetcher var chainStartFetcher powchain.ChainStartFetcher - if genesisTime > 0 && genesisValidators > 0 || genesisStatePath != "" { + if genesisValidators > 0 || genesisStatePath != "" { var interopService *interopcoldstart.Service if err := b.services.FetchService(&interopService); err != nil { return err @@ -500,7 +499,7 @@ func (b *BeaconNode) registerInteropServices(ctx *cli.Context) error { genesisValidators := ctx.GlobalUint64(flags.InteropNumValidatorsFlag.Name) genesisStatePath := ctx.GlobalString(flags.InteropGenesisStateFlag.Name) - if genesisTime > 0 && genesisValidators > 0 || genesisStatePath != "" { + if genesisValidators > 0 || genesisStatePath != "" { svc := interopcoldstart.NewColdStartService(context.Background(), &interopcoldstart.Config{ GenesisTime: genesisTime, NumValidators: genesisValidators, @@ -510,8 +509,6 @@ func (b *BeaconNode) registerInteropServices(ctx *cli.Context) error { }) return b.services.RegisterService(svc) - } else if genesisTime+genesisValidators > 0 { - log.Errorf("%s and %s must be used together", flags.InteropNumValidatorsFlag.Name, flags.InteropGenesisTimeFlag.Name) } return nil } diff --git a/shared/interop/BUILD.bazel b/shared/interop/BUILD.bazel index 86cf535e5..dc8bc8b8e 100644 --- a/shared/interop/BUILD.bazel +++ b/shared/interop/BUILD.bazel @@ -15,6 +15,7 @@ go_library( "//shared/bls:go_default_library", "//shared/hashutil:go_default_library", "//shared/params:go_default_library", + "//shared/roughtime:go_default_library", "//shared/trieutil:go_default_library", "@com_github_pkg_errors//:go_default_library", "@com_github_prysmaticlabs_go_ssz//:go_default_library", diff --git a/shared/interop/generate_genesis_state.go b/shared/interop/generate_genesis_state.go index ae3cd581f..b1cd1a1a4 100644 --- a/shared/interop/generate_genesis_state.go +++ b/shared/interop/generate_genesis_state.go @@ -9,6 +9,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/bls" "github.com/prysmaticlabs/prysm/shared/hashutil" "github.com/prysmaticlabs/prysm/shared/params" + "github.com/prysmaticlabs/prysm/shared/roughtime" "github.com/prysmaticlabs/prysm/shared/trieutil" ) @@ -22,6 +23,7 @@ var ( ) // GenerateGenesisState deterministically given a genesis time and number of validators. +// If a genesis time of 0 is supplied it is set to the current time. func GenerateGenesisState(genesisTime, numValidators uint64) (*pb.BeaconState, []*ethpb.Deposit, error) { privKeys, pubKeys, err := DeterministicallyGenerateKeys(0 /*startIndex*/, numValidators) if err != nil { @@ -43,6 +45,9 @@ func GenerateGenesisState(genesisTime, numValidators uint64) (*pb.BeaconState, [ return nil, nil, errors.Wrap(err, "could not generate deposits from the deposit data provided") } root := trie.Root() + if genesisTime == 0 { + genesisTime = uint64(roughtime.Now().Unix()) + } beaconState, err := state.GenesisBeaconState(deposits, genesisTime, ðpb.Eth1Data{ DepositRoot: root[:], DepositCount: uint64(len(deposits)), diff --git a/tools/genesis-state-gen/main.go b/tools/genesis-state-gen/main.go index a6921bc94..61821beab 100644 --- a/tools/genesis-state-gen/main.go +++ b/tools/genesis-state-gen/main.go @@ -19,7 +19,7 @@ const ( var ( numValidators = flag.Int("num-validators", 0, "Number of validators to deterministically include in the generated genesis state") useMainnetConfig = flag.Bool("mainnet-config", false, "Select whether genesis state should be generated with mainnet or minimal (default) params") - genesisTime = flag.Uint64("genesis-time", 0, "Unix timestamp used as the genesis time in the generated genesis state") + genesisTime = flag.Uint64("genesis-time", 0, "Unix timestamp used as the genesis time in the generated genesis state (defaults to now)") sszOutputFile = flag.String("output-ssz", "", "Output filename of the SSZ marshaling of the generated genesis state") yamlOutputFile = flag.String("output-yaml", "", "Output filename of the YAML marshaling of the generated genesis state") jsonOutputFile = flag.String("output-json", "", "Output filename of the JSON marshaling of the generated genesis state") @@ -31,7 +31,7 @@ func main() { log.Fatal("Expected --num-validators to have been provided, received 0") } if *genesisTime == 0 { - log.Print("No --genesis-time specified, defaulting to 0 as the unix timestamp") + log.Print("No --genesis-time specified, defaulting to now") } if *sszOutputFile == "" && *yamlOutputFile == "" && *jsonOutputFile == "" { log.Fatal("Expected --output-ssz, --output-yaml, or --output-json to have been provided, received nil")