Skip to content

Commit

Permalink
Update interop genesis for Electra (#13991)
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain authored May 12, 2024
1 parent d71079e commit e4310ae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cmd/prysmctl/testnet/generate_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
19 changes: 18 additions & 1 deletion runtime/interop/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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 := &params.ChainConfig{
ChainID: big.NewInt(defaultTestChainId),
HomesteadBlock: bigz,
Expand All @@ -143,6 +159,7 @@ func GethTestnetGenesis(genesisTime uint64, cfg *clparams.BeaconChainConfig) *co
},
ShanghaiTime: shanghaiTime,
CancunTime: cancunTime,
PragueTime: pragueTime,
}
da := defaultDepositContractAllocation(cfg.DepositContractAddress)
ma := minerAllocation()
Expand Down

0 comments on commit e4310ae

Please sign in to comment.