From 9fc5e93fb73e771fe125cd9b571415aefc1af39d Mon Sep 17 00:00:00 2001 From: terence tsao Date: Sun, 12 May 2024 08:10:57 -0700 Subject: [PATCH] Update interop genesis for Electra --- cmd/prysmctl/testnet/generate_genesis.go | 4 ++++ runtime/interop/genesis.go | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/cmd/prysmctl/testnet/generate_genesis.go b/cmd/prysmctl/testnet/generate_genesis.go index 8ee5905447f7..9fcee9a064fe 100644 --- a/cmd/prysmctl/testnet/generate_genesis.go +++ b/cmd/prysmctl/testnet/generate_genesis.go @@ -273,6 +273,7 @@ func generateGenesis(ctx context.Context) (state.BeaconState, error) { gen.Timestamp = f.GenesisTime gen.Config.ShanghaiTime = interop.GethShanghaiTime(f.GenesisTime, params.BeaconConfig()) gen.Config.CancunTime = interop.GethCancunTime(f.GenesisTime, params.BeaconConfig()) + gen.Config.PragueTime = interop.GethPragueTime(f.GenesisTime, params.BeaconConfig()) fields := logrus.Fields{} if gen.Config.ShanghaiTime != nil { @@ -281,6 +282,9 @@ func generateGenesis(ctx context.Context) (state.BeaconState, error) { if gen.Config.CancunTime != nil { fields["cancun"] = fmt.Sprintf("%d", *gen.Config.CancunTime) } + if gen.Config.PragueTime != nil { + fields["prague"] = fmt.Sprintf("%d", *gen.Config.PragueTime) + } log.WithFields(fields).Info("Setting fork geth times") if v > version.Altair { // set ttd to zero so EL goes post-merge immediately diff --git a/runtime/interop/genesis.go b/runtime/interop/genesis.go index c20a4cce013c..df2dc0ad5a33 100644 --- a/runtime/interop/genesis.go +++ b/runtime/interop/genesis.go @@ -92,7 +92,7 @@ func GethShanghaiTime(genesisTime uint64, cfg *clparams.BeaconChainConfig) *uint return shanghaiTime } -// GethCancunTime calculates the absolute time of the shanghai (aka capella) fork block +// GethCancunTime calculates the absolute time of the cancun (aka deneb) fork block // by adding the relative time of the capella the fork epoch to the given genesis timestamp. func GethCancunTime(genesisTime uint64, cfg *clparams.BeaconChainConfig) *uint64 { var cancunTime *uint64 @@ -107,6 +107,21 @@ func GethCancunTime(genesisTime uint64, cfg *clparams.BeaconChainConfig) *uint64 return cancunTime } +// GethPragueTime calculates the absolute time of the prague (aka electra) fork block +// by adding the relative time of the capella the fork epoch to the given genesis timestamp. +func GethPragueTime(genesisTime uint64, cfg *clparams.BeaconChainConfig) *uint64 { + var pragueTime *uint64 + if cfg.ElectraForkEpoch != math.MaxUint64 { + startSlot, err := slots.EpochStart(cfg.ElectraForkEpoch) + if err == nil { + startTime := slots.StartTime(genesisTime, startSlot) + newTime := uint64(startTime.Unix()) + pragueTime = &newTime + } + } + return pragueTime +} + // GethTestnetGenesis creates a genesis.json for eth1 clients with a set of defaults suitable for ephemeral testnets, // like in an e2e test. The parameters are minimal but the full value is returned unmarshaled so that it can be // customized as desired. @@ -118,6 +133,7 @@ func GethTestnetGenesis(genesisTime uint64, cfg *clparams.BeaconChainConfig) *co shanghaiTime := GethShanghaiTime(genesisTime, cfg) cancunTime := GethCancunTime(genesisTime, cfg) + pragueTime := GethPragueTime(genesisTime, cfg) cc := ¶ms.ChainConfig{ ChainID: big.NewInt(defaultTestChainId), HomesteadBlock: bigz, @@ -143,6 +159,7 @@ func GethTestnetGenesis(genesisTime uint64, cfg *clparams.BeaconChainConfig) *co }, ShanghaiTime: shanghaiTime, CancunTime: cancunTime, + PragueTime: pragueTime, } da := defaultDepositContractAllocation(cfg.DepositContractAddress) ma := minerAllocation()