mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 11:32:09 +00:00
Integrate generate genesis (#12523)
Co-authored-by: Kasey Kirkham <kasey@users.noreply.github.com>
This commit is contained in:
parent
87cd96afd3
commit
2121d1f4f4
@ -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
|
||||
}
|
||||
} else {
|
||||
gen = interop.GethTestnetGenesis(f.GenesisTime, params.BeaconConfig())
|
||||
|
@ -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.
|
||||
|
@ -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))
|
||||
}
|
||||
@ -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(ðpb.BeaconStateDeneb{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
return nil, errUnsupportedVersion
|
||||
}
|
||||
@ -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
|
||||
}
|
||||
@ -409,6 +416,34 @@ func (s *PremineGenesisConfig) setLatestBlockHeader(g state.BeaconState) error {
|
||||
},
|
||||
BlsToExecutionChanges: make([]*ethpb.SignedBLSToExecutionChange, 0),
|
||||
}
|
||||
case version.Deneb:
|
||||
body = ðpb.BeaconBlockBodyDeneb{
|
||||
RandaoReveal: make([]byte, 96),
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
DepositRoot: make([]byte, 32),
|
||||
BlockHash: make([]byte, 32),
|
||||
},
|
||||
Graffiti: make([]byte, 32),
|
||||
SyncAggregate: ðpb.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
|
||||
}
|
||||
@ -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
|
||||
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user