Skip to content
Merged
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
4 changes: 4 additions & 0 deletions cmd/prysmctl/testnet/generate_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,16 @@ func generateGenesis(ctx context.Context) (state.BeaconState, error) {
// set timestamps for genesis and shanghai fork
gen.Timestamp = f.GenesisTime
gen.Config.ShanghaiTime = interop.GethShanghaiTime(f.GenesisTime, params.BeaconConfig())
//gen.Config.CancunTime = interop.GethCancunTime(f.GenesisTime, params.BeaconConfig())
gen.Config.CancunTime = interop.GethCancunTime(f.GenesisTime, params.BeaconConfig())
log.
WithField("shanghai", gen.Config.ShanghaiTime).
WithField("cancun", gen.Config.CancunTime).
Info("setting fork geth times")
if v > version.Altair {
// set ttd to zero so EL goes post-merge immediately
gen.Config.TerminalTotalDifficulty = big.NewInt(0)
gen.Config.TerminalTotalDifficultyPassed = true
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we have updated our e2e geth dependency to the v1.12 release, this should be moved into runtime/interop/genesis.go. This is because geth 1.12 won't run in miner mode and this flag needs to be specified for it to startup.

}
} else {
gen = interop.GethTestnetGenesis(f.GenesisTime, params.BeaconConfig())
Expand Down
15 changes: 15 additions & 0 deletions runtime/interop/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ func GethShanghaiTime(genesisTime uint64, cfg *clparams.BeaconChainConfig) *uint
return shanghaiTime
}

// GethShanghaiTime calculates the absolute time of the shanghai (aka capella) 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
if cfg.DenebForkEpoch != math.MaxUint64 {
startSlot, err := slots.EpochStart(cfg.DenebForkEpoch)
if err == nil {
startTime := slots.StartTime(genesisTime, startSlot)
newTime := uint64(startTime.Unix())
cancunTime = &newTime
}
}
return cancunTime
}

// 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 Down
74 changes: 72 additions & 2 deletions runtime/interop/premine-state.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func NewPreminedGenesis(ctx context.Context, t, nvals, pCreds uint64, version in

func (s *PremineGenesisConfig) prepare(ctx context.Context) (state.BeaconState, error) {
switch s.Version {
case version.Phase0, version.Altair, version.Bellatrix, version.Capella:
case version.Phase0, version.Altair, version.Bellatrix, version.Capella, version.Deneb:
default:
return nil, errors.Wrapf(errUnsupportedVersion, "version=%s", version.String(s.Version))
}
Expand Down Expand Up @@ -110,6 +110,11 @@ func (s *PremineGenesisConfig) empty() (state.BeaconState, error) {
if err != nil {
return nil, err
}
case version.Deneb:
e, err = state_native.InitializeFromProtoDeneb(&ethpb.BeaconStateDeneb{})
if err != nil {
return nil, err
}
default:
return nil, errUnsupportedVersion
}
Expand Down Expand Up @@ -287,6 +292,8 @@ func (s *PremineGenesisConfig) setFork(g state.BeaconState) error {
pv, cv = params.BeaconConfig().AltairForkVersion, params.BeaconConfig().BellatrixForkVersion
case version.Capella:
pv, cv = params.BeaconConfig().BellatrixForkVersion, params.BeaconConfig().CapellaForkVersion
case version.Deneb:
pv, cv = params.BeaconConfig().CapellaForkVersion, params.BeaconConfig().DenebForkVersion
default:
return errUnsupportedVersion
}
Expand Down Expand Up @@ -409,6 +416,34 @@ func (s *PremineGenesisConfig) setLatestBlockHeader(g state.BeaconState) error {
},
BlsToExecutionChanges: make([]*ethpb.SignedBLSToExecutionChange, 0),
}
case version.Deneb:
body = &ethpb.BeaconBlockBodyDeneb{
RandaoReveal: make([]byte, 96),
Eth1Data: &ethpb.Eth1Data{
DepositRoot: make([]byte, 32),
BlockHash: make([]byte, 32),
},
Graffiti: make([]byte, 32),
SyncAggregate: &ethpb.SyncAggregate{
SyncCommitteeBits: make([]byte, fieldparams.SyncCommitteeLength/8),
SyncCommitteeSignature: make([]byte, fieldparams.BLSSignatureLength),
},
ExecutionPayload: &enginev1.ExecutionPayloadDeneb{
ParentHash: make([]byte, 32),
FeeRecipient: make([]byte, 20),
StateRoot: make([]byte, 32),
ReceiptsRoot: make([]byte, 32),
LogsBloom: make([]byte, 256),
PrevRandao: make([]byte, 32),
BaseFeePerGas: make([]byte, 32),
BlockHash: make([]byte, 32),
Transactions: make([][]byte, 0),
Withdrawals: make([]*enginev1.Withdrawal, 0),
ExcessDataGas: 0,
},
BlsToExecutionChanges: make([]*ethpb.SignedBLSToExecutionChange, 0),
BlobKzgCommitments: make([][]byte, 0),
}
default:
return errUnsupportedVersion
}
Expand All @@ -426,6 +461,10 @@ func (s *PremineGenesisConfig) setLatestBlockHeader(g state.BeaconState) error {
}

func (s *PremineGenesisConfig) setExecutionPayload(g state.BeaconState) error {
if s.Version < version.Bellatrix {
return nil
}

gb := s.GB

var ed interfaces.ExecutionData
Expand Down Expand Up @@ -489,8 +528,39 @@ func (s *PremineGenesisConfig) setExecutionPayload(g state.BeaconState) error {
if err != nil {
return err
}
case version.Deneb:
payload := &enginev1.ExecutionPayloadDeneb{
ParentHash: gb.ParentHash().Bytes(),
FeeRecipient: gb.Coinbase().Bytes(),
StateRoot: gb.Root().Bytes(),
ReceiptsRoot: gb.ReceiptHash().Bytes(),
LogsBloom: gb.Bloom().Bytes(),
PrevRandao: params.BeaconConfig().ZeroHash[:],
BlockNumber: gb.NumberU64(),
GasLimit: gb.GasLimit(),
GasUsed: gb.GasUsed(),
Timestamp: gb.Time(),
ExtraData: gb.Extra()[:32],
BaseFeePerGas: bytesutil.PadTo(bytesutil.ReverseByteOrder(gb.BaseFee().Bytes()), fieldparams.RootLength),
BlockHash: gb.Hash().Bytes(),
Transactions: make([][]byte, 0),
Withdrawals: make([]*enginev1.Withdrawal, 0),
ExcessDataGas: 0,
}
wep, err := blocks.WrappedExecutionPayloadDeneb(payload, 0)
if err != nil {
return err
}
eph, err := blocks.PayloadToHeaderDeneb(wep)
if err != nil {
return err
}
ed, err = blocks.WrappedExecutionPayloadHeaderDeneb(eph, 0)
if err != nil {
return err
}
default:
return nil
return errUnsupportedVersion
}
return g.SetLatestExecutionPayloadHeader(ed)
}
Expand Down