mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 05:47:59 -05:00
WIP
This commit is contained in:
@@ -34,7 +34,9 @@ func NewGenesisBlock(stateRoot []byte) *ethpb.SignedBeaconBlock {
|
||||
}
|
||||
return block
|
||||
}
|
||||
|
||||
var ErrUnrecognizedState = errors.New("uknonwn underlying type for state.BeaconState value")
|
||||
|
||||
func NewGenesisBlockForState(root [32]byte, st state.BeaconState) (interfaces.SignedBeaconBlock, error) {
|
||||
ps := st.ToProto()
|
||||
switch ps.(type) {
|
||||
@@ -55,44 +57,52 @@ func NewGenesisBlockForState(root [32]byte, st state.BeaconState) (interfaces.Si
|
||||
Signature: params.BeaconConfig().EmptySignature[:],
|
||||
})
|
||||
case *ethpb.BeaconStateBellatrix:
|
||||
return blocks.NewSignedBeaconBlock(ðpb.SignedBeaconBlockBellatrix{
|
||||
Block: ðpb.BeaconBlockBellatrix{
|
||||
hi, err := st.LatestExecutionPayloadHeader()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
txr, err := hi.TransactionsRoot()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
h := &enginev1.ExecutionPayloadHeader{
|
||||
ParentHash: bytesutil.SafeCopyBytes(hi.ParentHash()),
|
||||
FeeRecipient: bytesutil.SafeCopyBytes(hi.FeeRecipient()),
|
||||
StateRoot: bytesutil.SafeCopyBytes(hi.StateRoot()),
|
||||
ReceiptsRoot: bytesutil.SafeCopyBytes(hi.ReceiptsRoot()),
|
||||
LogsBloom: bytesutil.SafeCopyBytes(hi.LogsBloom()),
|
||||
PrevRandao: bytesutil.SafeCopyBytes(hi.PrevRandao()),
|
||||
BlockNumber: hi.BlockNumber(),
|
||||
GasLimit: hi.GasLimit(),
|
||||
GasUsed: hi.GasUsed(),
|
||||
Timestamp: hi.Timestamp(),
|
||||
ExtraData: bytesutil.SafeCopyBytes(hi.ExtraData()),
|
||||
BaseFeePerGas: bytesutil.SafeCopyBytes(hi.BaseFeePerGas()),
|
||||
BlockHash: bytesutil.SafeCopyBytes(hi.BlockHash()),
|
||||
TransactionsRoot: bytesutil.SafeCopyBytes(txr),
|
||||
}
|
||||
return blocks.NewSignedBeaconBlock(ðpb.SignedBlindedBeaconBlockBellatrix{
|
||||
Block: ðpb.BlindedBeaconBlockBellatrix{
|
||||
ParentRoot: params.BeaconConfig().ZeroHash[:],
|
||||
StateRoot: root[:],
|
||||
Body: ðpb.BeaconBlockBodyBellatrix{
|
||||
Body: ðpb.BlindedBeaconBlockBodyBellatrix{
|
||||
RandaoReveal: make([]byte, 96),
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
DepositRoot: make([]byte, 32),
|
||||
BlockHash: make([]byte, 32),
|
||||
},
|
||||
Graffiti: make([]byte, 32),
|
||||
Eth1Data: st.Eth1Data(),
|
||||
Graffiti: make([]byte, 32),
|
||||
SyncAggregate: ðpb.SyncAggregate{
|
||||
SyncCommitteeBits: make([]byte, fieldparams.SyncCommitteeLength/8),
|
||||
SyncCommitteeSignature: make([]byte, fieldparams.BLSSignatureLength),
|
||||
},
|
||||
ExecutionPayload: &enginev1.ExecutionPayload{
|
||||
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),
|
||||
},
|
||||
ExecutionPayloadHeader: h,
|
||||
},
|
||||
},
|
||||
Signature: params.BeaconConfig().EmptySignature[:],
|
||||
})
|
||||
/*
|
||||
return blocks.NewSignedBeaconBlock(ðpb.BeaconBlockBellatrix{
|
||||
Body: })
|
||||
*/
|
||||
default:
|
||||
return nil, ErrUnrecognizedState
|
||||
/*
|
||||
case *ethpb.BeaconStateAltair:
|
||||
case *ethpb.BeaconStateCapella:
|
||||
*/
|
||||
/*
|
||||
case *ethpb.BeaconStateAltair:
|
||||
case *ethpb.BeaconStateCapella:
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@ package transition
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/blocks"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/altair"
|
||||
|
||||
enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1"
|
||||
@@ -10,7 +14,6 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
b "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/blocks"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil"
|
||||
@@ -60,7 +63,7 @@ import (
|
||||
// return state
|
||||
//
|
||||
// This method differs from the spec so as to process deposits beforehand instead of the end of the function.
|
||||
func GenesisBeaconStateBellatrix(ctx context.Context, deposits []*ethpb.Deposit, genesisTime uint64, eth1Data *ethpb.Eth1Data) (state.BeaconState, error) {
|
||||
func GenesisBeaconStateBellatrix(ctx context.Context, deposits []*ethpb.Deposit, genesisTime uint64, eth1Data *ethpb.Eth1Data, ep *enginev1.ExecutionPayload) (state.BeaconState, error) {
|
||||
st, err := EmptyGenesisStateBellatrix()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -77,12 +80,18 @@ func GenesisBeaconStateBellatrix(ctx context.Context, deposits []*ethpb.Deposit,
|
||||
return nil, errors.Wrap(err, "could not process validator deposits")
|
||||
}
|
||||
|
||||
return OptimizedGenesisBeaconStateBellatrix(genesisTime, st, st.Eth1Data())
|
||||
// After deposits have been processed, overwrite eth1data to what is passed in. This allows us to "pre-mine" validators
|
||||
// without the deposit root and count mismatching the real deposit contract.
|
||||
if err := st.SetEth1Data(eth1Data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return OptimizedGenesisBeaconStateBellatrix(genesisTime, st, st.Eth1Data(), ep)
|
||||
}
|
||||
|
||||
// OptimizedGenesisBeaconState is used to create a state that has already processed deposits. This is to efficiently
|
||||
// create a mainnet state at chainstart.
|
||||
func OptimizedGenesisBeaconStateBellatrix(genesisTime uint64, preState state.BeaconState, eth1Data *ethpb.Eth1Data) (state.BeaconState, error) {
|
||||
func OptimizedGenesisBeaconStateBellatrix(genesisTime uint64, preState state.BeaconState, eth1Data *ethpb.Eth1Data, ep *enginev1.ExecutionPayload) (state.BeaconState, error) {
|
||||
if eth1Data == nil {
|
||||
return nil, errors.New("no eth1data provided for genesis state")
|
||||
}
|
||||
@@ -128,6 +137,14 @@ func OptimizedGenesisBeaconStateBellatrix(genesisTime uint64, preState state.Bea
|
||||
scores = append(scores, 0)
|
||||
}
|
||||
}
|
||||
wep, err := blocks.WrappedExecutionPayload(ep)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
eph, err := blocks.PayloadToHeader(wep)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
st := ðpb.BeaconStateBellatrix{
|
||||
// Misc fields.
|
||||
Slot: 0,
|
||||
@@ -168,44 +185,22 @@ func OptimizedGenesisBeaconStateBellatrix(genesisTime uint64, preState state.Bea
|
||||
Slashings: slashings,
|
||||
|
||||
// Eth1 data.
|
||||
Eth1Data: eth1Data,
|
||||
Eth1DataVotes: []*ethpb.Eth1Data{},
|
||||
Eth1DepositIndex: preState.Eth1DepositIndex(),
|
||||
LatestExecutionPayloadHeader: &enginev1.ExecutionPayloadHeader{
|
||||
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),
|
||||
TransactionsRoot: make([]byte, 32),
|
||||
},
|
||||
InactivityScores: scores,
|
||||
Eth1Data: eth1Data,
|
||||
Eth1DataVotes: []*ethpb.Eth1Data{},
|
||||
Eth1DepositIndex: preState.Eth1DepositIndex(),
|
||||
LatestExecutionPayloadHeader: eph,
|
||||
InactivityScores: scores,
|
||||
}
|
||||
|
||||
bodyRoot, err := (ðpb.BeaconBlockBodyBellatrix{
|
||||
RandaoReveal: make([]byte, 96),
|
||||
Eth1Data: ðpb.Eth1Data{
|
||||
DepositRoot: make([]byte, 32),
|
||||
BlockHash: make([]byte, 32),
|
||||
},
|
||||
Graffiti: make([]byte, 32),
|
||||
Eth1Data: eth1Data,
|
||||
Graffiti: make([]byte, 32),
|
||||
SyncAggregate: ðpb.SyncAggregate{
|
||||
SyncCommitteeBits: make([]byte, fieldparams.SyncCommitteeLength/8),
|
||||
SyncCommitteeSignature: make([]byte, fieldparams.BLSSignatureLength),
|
||||
},
|
||||
ExecutionPayload: &enginev1.ExecutionPayload{
|
||||
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),
|
||||
},
|
||||
ExecutionPayload: ep,
|
||||
}).HashTreeRoot()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not hash tree root empty block body")
|
||||
|
||||
@@ -2,7 +2,6 @@ package kv
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/ssz/detect"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -26,6 +25,15 @@ func (s *Store) SaveGenesisData(ctx context.Context, genesisState state.BeaconSt
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not get genesis block root")
|
||||
}
|
||||
/*
|
||||
lbhr, err := genesisState.LatestBlockHeader().HashTreeRoot()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unable to compute HTR of latest block header from genesis state")
|
||||
}
|
||||
if genesisBlkRoot != lbhr {
|
||||
return fmt.Errorf("state.latest_block_header=%#x does not match derived genessis block root=%#x", genesisBlkRoot, lbhr)
|
||||
}
|
||||
*/
|
||||
if err := s.SaveBlock(ctx, wsb); err != nil {
|
||||
return errors.Wrap(err, "could not save genesis block")
|
||||
}
|
||||
|
||||
@@ -307,7 +307,8 @@ func (s *Service) updateBeaconNodeStats() {
|
||||
s.cfg.beaconNodeStatsUpdater.Update(bs)
|
||||
}
|
||||
|
||||
func (s *Service) updateConnectedETH1(state bool) {
|
||||
func (s *Service) updateConnectedETH1(state bool, reason string) {
|
||||
log.Infof("updateConnectedETH1 - %s", reason)
|
||||
s.connectedETH1 = state
|
||||
s.updateBeaconNodeStats()
|
||||
}
|
||||
@@ -319,10 +320,14 @@ func (s *Service) followedBlockHeight(ctx context.Context) (uint64, error) {
|
||||
latestBlockTime := uint64(0)
|
||||
if s.latestEth1Data.BlockTime > followTime {
|
||||
latestBlockTime = s.latestEth1Data.BlockTime - followTime
|
||||
if s.latestEth1Data.BlockHeight < params.BeaconConfig().Eth1FollowDistance {
|
||||
latestBlockTime = s.latestEth1Data.BlockTime
|
||||
}
|
||||
}
|
||||
log.WithField("distance", params.BeaconConfig().Eth1FollowDistance).WithField("followTime", followTime).WithField("BlockTime", s.latestEth1Data.BlockTime).WithField("BlockHeight", s.latestEth1Data.BlockHeight).WithField("latestBlockTime", latestBlockTime).Info("followedBlockHeight")
|
||||
blk, err := s.BlockByTimestamp(ctx, latestBlockTime)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
return 0, errors.Wrapf(err, "BlockByTimestamp=%d", latestBlockTime)
|
||||
}
|
||||
return blk.Number.Uint64(), nil
|
||||
}
|
||||
@@ -467,7 +472,7 @@ func (s *Service) handleETH1FollowDistance() {
|
||||
}
|
||||
if !s.chainStartData.Chainstarted {
|
||||
if err := s.processChainStartFromBlockNum(ctx, big.NewInt(int64(s.latestEth1Data.LastRequestedBlock))); err != nil {
|
||||
s.runError = err
|
||||
s.runError = errors.Wrap(err, "processChainStartFromBlockNum")
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
@@ -481,7 +486,7 @@ func (s *Service) handleETH1FollowDistance() {
|
||||
return
|
||||
}
|
||||
if err := s.requestBatchedHeadersAndLogs(ctx); err != nil {
|
||||
s.runError = err
|
||||
s.runError = errors.Wrap(err, "requestBatchedHeadersAndLogs")
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
@@ -511,6 +516,7 @@ func (s *Service) initPOWService() {
|
||||
ctx := s.ctx
|
||||
header, err := s.HeaderByNumber(ctx, nil)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "HeaderByNumber")
|
||||
s.retryExecutionClientConnection(ctx, err)
|
||||
errorLogger(err, "Unable to retrieve latest execution client header")
|
||||
continue
|
||||
@@ -523,6 +529,7 @@ func (s *Service) initPOWService() {
|
||||
s.latestEth1DataLock.Unlock()
|
||||
|
||||
if err := s.processPastLogs(ctx); err != nil {
|
||||
err = errors.Wrap(err, "processPastLogs")
|
||||
s.retryExecutionClientConnection(ctx, err)
|
||||
errorLogger(
|
||||
err,
|
||||
@@ -532,6 +539,7 @@ func (s *Service) initPOWService() {
|
||||
}
|
||||
// Cache eth1 headers from our voting period.
|
||||
if err := s.cacheHeadersForEth1DataVote(ctx); err != nil {
|
||||
err = errors.Wrap(err, "cacheHeadersForEth1DataVote")
|
||||
s.retryExecutionClientConnection(ctx, err)
|
||||
if errors.Is(err, errBlockTimeTooLate) {
|
||||
log.WithError(err).Debug("Unable to cache headers for execution client votes")
|
||||
@@ -550,6 +558,7 @@ func (s *Service) initPOWService() {
|
||||
if genHash != [32]byte{} {
|
||||
genHeader, err := s.HeaderByHash(ctx, genHash)
|
||||
if err != nil {
|
||||
err = errors.Wrapf(err, "HeaderByHash, hash=%#x", genHash)
|
||||
s.retryExecutionClientConnection(ctx, err)
|
||||
errorLogger(err, "Unable to retrieve proof-of-stake genesis block data")
|
||||
continue
|
||||
@@ -558,6 +567,7 @@ func (s *Service) initPOWService() {
|
||||
}
|
||||
s.chainStartData.GenesisBlock = genBlock
|
||||
if err := s.savePowchainData(ctx); err != nil {
|
||||
err = errors.Wrap(err, "savePowchainData")
|
||||
s.retryExecutionClientConnection(ctx, err)
|
||||
errorLogger(err, "Unable to save execution client data")
|
||||
continue
|
||||
@@ -583,7 +593,7 @@ func (s *Service) run(done <-chan struct{}) {
|
||||
s.isRunning = false
|
||||
s.runError = nil
|
||||
s.rpcClient.Close()
|
||||
s.updateConnectedETH1(false)
|
||||
s.updateConnectedETH1(false, "context canceled in run()")
|
||||
log.Debug("Context closed, exiting goroutine")
|
||||
return
|
||||
case <-s.eth1HeadTicker.C:
|
||||
@@ -641,11 +651,11 @@ func (s *Service) cacheHeadersForEth1DataVote(ctx context.Context) error {
|
||||
// Find the end block to request from.
|
||||
end, err := s.followedBlockHeight(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
return errors.Wrap(err, "followedBlockHeight")
|
||||
}
|
||||
start, err := s.determineEarliestVotingBlock(ctx, end)
|
||||
if err != nil {
|
||||
return err
|
||||
return errors.Wrapf(err, "determineEarliestVotingBlock=%d", end)
|
||||
}
|
||||
return s.cacheBlockHeaders(start, end)
|
||||
}
|
||||
@@ -677,7 +687,7 @@ func (s *Service) cacheBlockHeaders(start, end uint64) error {
|
||||
}
|
||||
continue
|
||||
}
|
||||
return err
|
||||
return errors.Wrapf(err, "cacheBlockHeaders, start=%d, end=%d", startReq, endReq)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -696,15 +706,22 @@ func (s *Service) determineEarliestVotingBlock(ctx context.Context, followBlock
|
||||
}
|
||||
return earliestBlk, nil
|
||||
}
|
||||
if s.latestEth1Data.BlockHeight < params.BeaconConfig().Eth1FollowDistance {
|
||||
return 0, nil
|
||||
}
|
||||
votingTime := slots.VotingPeriodStartTime(genesisTime, currSlot)
|
||||
followBackDist := 2 * params.BeaconConfig().SecondsPerETH1Block * params.BeaconConfig().Eth1FollowDistance
|
||||
if followBackDist > votingTime {
|
||||
return 0, errors.Errorf("invalid genesis time provided. %d > %d", followBackDist, votingTime)
|
||||
}
|
||||
earliestValidTime := votingTime - followBackDist
|
||||
if earliestValidTime > s.latestEth1Data.BlockTime {
|
||||
return 0, nil
|
||||
}
|
||||
/*
|
||||
if earliestValidTime > s.latestEth1Data.BlockTime {
|
||||
return 0, nil
|
||||
}
|
||||
log.WithField("earliestValidTime", earliestValidTime).Info("calling BlockByTimestamp")
|
||||
*/
|
||||
log.WithField("distance", params.BeaconConfig().Eth1FollowDistance).WithField("earliestValidTime", earliestValidTime).WithField("BlockTime", s.latestEth1Data.BlockTime).WithField("BlockHeight", s.latestEth1Data.BlockHeight).WithField("followBlock", followBlock).Info("determineEarliestVotingBlock")
|
||||
hdr, err := s.BlockByTimestamp(ctx, earliestValidTime)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
||||
@@ -11,7 +11,7 @@ const (
|
||||
func E2ETestConfig() *BeaconChainConfig {
|
||||
e2eConfig := MinimalSpecConfig()
|
||||
e2eConfig.DepositContractAddress = "0x4242424242424242424242424242424242424242"
|
||||
e2eConfig.Eth1FollowDistance = 0
|
||||
e2eConfig.Eth1FollowDistance = 8
|
||||
|
||||
// Misc.
|
||||
e2eConfig.MinGenesisActiveValidatorCount = 256
|
||||
@@ -52,7 +52,7 @@ func E2ETestConfig() *BeaconChainConfig {
|
||||
func E2EMainnetTestConfig() *BeaconChainConfig {
|
||||
e2eConfig := MainnetConfig().Copy()
|
||||
e2eConfig.DepositContractAddress = "0x4242424242424242424242424242424242424242"
|
||||
e2eConfig.Eth1FollowDistance = 0
|
||||
e2eConfig.Eth1FollowDistance = 8
|
||||
|
||||
// Misc.
|
||||
e2eConfig.MinGenesisActiveValidatorCount = 256
|
||||
|
||||
@@ -5,6 +5,8 @@ package interop
|
||||
import (
|
||||
"context"
|
||||
|
||||
enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
coreState "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/transition"
|
||||
statenative "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
||||
@@ -16,7 +18,7 @@ import (
|
||||
|
||||
// GenerateGenesisStateBellatrix 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 GenerateGenesisStateBellatrix(ctx context.Context, genesisTime, numValidators uint64) (*ethpb.BeaconStateBellatrix, []*ethpb.Deposit, error) {
|
||||
func GenerateGenesisStateBellatrix(ctx context.Context, genesisTime, numValidators uint64, ep *enginev1.ExecutionPayload, ed *ethpb.Eth1Data) (*ethpb.BeaconStateBellatrix, []*ethpb.Deposit, error) {
|
||||
privKeys, pubKeys, err := DeterministicallyGenerateKeys(0 /*startIndex*/, numValidators)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrapf(err, "could not deterministically generate keys for %d validators", numValidators)
|
||||
@@ -25,13 +27,13 @@ func GenerateGenesisStateBellatrix(ctx context.Context, genesisTime, numValidato
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, "could not generate deposit data from keys")
|
||||
}
|
||||
return GenerateGenesisStateBellatrixFromDepositData(ctx, genesisTime, depositDataItems, depositDataRoots)
|
||||
return GenerateGenesisStateBellatrixFromDepositData(ctx, genesisTime, depositDataItems, depositDataRoots, ep, ed)
|
||||
}
|
||||
|
||||
// GenerateGenesisStateBellatrixFromDepositData creates a genesis state given a list of
|
||||
// deposit data items and their corresponding roots.
|
||||
func GenerateGenesisStateBellatrixFromDepositData(
|
||||
ctx context.Context, genesisTime uint64, depositData []*ethpb.Deposit_Data, depositDataRoots [][]byte,
|
||||
ctx context.Context, genesisTime uint64, depositData []*ethpb.Deposit_Data, depositDataRoots [][]byte, ep *enginev1.ExecutionPayload, e1d *ethpb.Eth1Data,
|
||||
) (*ethpb.BeaconStateBellatrix, []*ethpb.Deposit, error) {
|
||||
t, err := trie.GenerateTrieFromItems(depositDataRoots, params.BeaconConfig().DepositContractTreeDepth)
|
||||
if err != nil {
|
||||
@@ -41,23 +43,19 @@ func GenerateGenesisStateBellatrixFromDepositData(
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, "could not generate deposits from the deposit data provided")
|
||||
}
|
||||
root, err := t.HashTreeRoot()
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, "could not hash tree root of deposit trie")
|
||||
}
|
||||
if genesisTime == 0 {
|
||||
genesisTime = uint64(time.Now().Unix())
|
||||
}
|
||||
beaconState, err := coreState.GenesisBeaconStateBellatrix(ctx, deposits, genesisTime, ðpb.Eth1Data{
|
||||
DepositRoot: root[:],
|
||||
DepositCount: uint64(len(deposits)),
|
||||
BlockHash: mockEth1BlockHash,
|
||||
})
|
||||
beaconState, err := coreState.GenesisBeaconStateBellatrix(ctx, deposits, genesisTime, e1d, ep)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, "could not generate genesis state")
|
||||
}
|
||||
|
||||
pbState, err := statenative.ProtobufBeaconStateBellatrix(beaconState.ToProtoUnsafe())
|
||||
bsi := beaconState.ToProtoUnsafe()
|
||||
pbb, ok := bsi.(*ethpb.BeaconStateBellatrix)
|
||||
if !ok {
|
||||
return nil, nil, errors.New("unexpected BeaconState version")
|
||||
}
|
||||
pbState, err := statenative.ProtobufBeaconStateBellatrix(pbb)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@@ -12,6 +12,13 @@ import (
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/ssz"
|
||||
enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
||||
|
||||
@@ -175,10 +182,10 @@ func NewBeaconNode(config *e2etypes.E2EConfig, index int, enr string) *BeaconNod
|
||||
}
|
||||
|
||||
func (node *BeaconNode) generateGenesis(ctx context.Context) (state.BeaconState, error) {
|
||||
genesis, _, err := interop.GenerateGenesisStateBellatrix(ctx, e2e.TestParams.CLGenesisTime, params.BeaconConfig().MinGenesisActiveValidatorCount)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if e2e.TestParams.Eth1GenesisBlock == nil {
|
||||
return nil, errors.New("Cannot construct bellatrix block, e2e.TestParams.Eth1GenesisBlock == nil")
|
||||
}
|
||||
gb := e2e.TestParams.Eth1GenesisBlock
|
||||
|
||||
// so the DepositRoot in the BeaconState should be set to the HTR of an empty deposit trie.
|
||||
t, err := trie.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
|
||||
@@ -189,11 +196,39 @@ func (node *BeaconNode) generateGenesis(ctx context.Context) (state.BeaconState,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
genesis.Eth1Data.DepositRoot = dr[:]
|
||||
if e2e.TestParams.Eth1BlockHash != nil {
|
||||
genesis.Eth1Data.BlockHash = e2e.TestParams.Eth1BlockHash.Bytes()
|
||||
e1d := ðpb.Eth1Data{
|
||||
DepositRoot: dr[:],
|
||||
DepositCount: 0,
|
||||
BlockHash: gb.Hash().Bytes(),
|
||||
}
|
||||
log.Infof("genesis eth1 block root=%#x", genesis.Eth1Data.BlockHash)
|
||||
|
||||
txRoot, err := ssz.TransactionsRoot(make([][]byte, 0))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error computing empty tx root")
|
||||
}
|
||||
payload := &enginev1.ExecutionPayload{
|
||||
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),
|
||||
}
|
||||
genesis, _, err := interop.GenerateGenesisStateBellatrix(ctx, e2e.TestParams.CLGenesisTime, params.BeaconConfig().MinGenesisActiveValidatorCount, payload, e1d)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Infof("tx root = %#x, max len=%d", txRoot, len(genesis.LatestExecutionPayloadHeader.ExtraData))
|
||||
log.WithField("block_root", fmt.Sprintf("%#x", genesis.Eth1Data.BlockHash)).WithField("deposit_count", genesis.Eth1Data.DepositCount).WithField("deposit_root", fmt.Sprintf("%#x", genesis.Eth1Data.DepositRoot)).Info("genesis eth1 data")
|
||||
|
||||
return state_native.InitializeFromProtoUnsafeBellatrix(genesis)
|
||||
}
|
||||
|
||||
@@ -204,6 +239,16 @@ func (node *BeaconNode) saveGenesis(ctx context.Context) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
root, err := g.HashTreeRoot(ctx)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
lbhr, err := g.LatestBlockHeader().HashTreeRoot()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
log.WithField("fork_version", g.Fork().CurrentVersion).WithField("latest_block_header.root", fmt.Sprintf("%#x", lbhr)).WithField("root", fmt.Sprintf("%#x", root)).Infof("BeaconState infoz")
|
||||
|
||||
genesisBytes, err := g.MarshalSSZ()
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
@@ -233,7 +233,7 @@ func (m *Miner) Start(ctx context.Context) error {
|
||||
}
|
||||
log.Infof("genesis block timestamp=%d", block.Time())
|
||||
eth1BlockHash := block.Hash()
|
||||
e2e.TestParams.Eth1BlockHash = ð1BlockHash
|
||||
e2e.TestParams.Eth1GenesisBlock = block
|
||||
log.Infof("miner says genesis block root=%#x", eth1BlockHash)
|
||||
cAddr := common.HexToAddress(params.BeaconConfig().DepositContractAddress)
|
||||
code, err := web3.CodeAt(ctx, cAddr, nil)
|
||||
|
||||
@@ -472,20 +472,20 @@ func (r *testRunner) defaultEndToEndRun() error {
|
||||
if !ok {
|
||||
return errors.New("incorrect component type")
|
||||
}
|
||||
beaconNodes, ok := r.comHandler.beaconNodes.(*components.BeaconNodeSet)
|
||||
if !ok {
|
||||
return errors.New("incorrect component type")
|
||||
}
|
||||
beaconNodes, ok := r.comHandler.beaconNodes.(*components.BeaconNodeSet)
|
||||
if !ok {
|
||||
return errors.New("incorrect component type")
|
||||
}
|
||||
bootNode, ok := r.comHandler.bootnode.(*components.BootNode)
|
||||
if !ok {
|
||||
return errors.New("incorrect component type")
|
||||
}
|
||||
|
||||
keypath, err := e2e.TestParams.Paths.MinerKeyPath()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting miner key path from bazel static files in defaultEndToEndRun")
|
||||
}
|
||||
r.testDepositsAndTx(ctx, g, keypath, []e2etypes.ComponentRunner{beaconNodes})
|
||||
keypath, err := e2e.TestParams.Paths.MinerKeyPath()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting miner key path from bazel static files in defaultEndToEndRun")
|
||||
}
|
||||
r.testDepositsAndTx(ctx, g, keypath, []e2etypes.ComponentRunner{beaconNodes})
|
||||
|
||||
// Create GRPC connection to beacon nodes.
|
||||
conns, closeConns, err := helpers.NewLocalConnections(ctx, e2e.TestParams.BeaconNodeCount)
|
||||
|
||||
@@ -14,8 +14,9 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
|
||||
"github.com/bazelbuild/rules_go/go/tools/bazel"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
cfgparams "github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
"github.com/prysmaticlabs/prysm/v3/io/file"
|
||||
)
|
||||
@@ -29,7 +30,7 @@ type params struct {
|
||||
LighthouseBeaconNodeCount int
|
||||
Ports *ports
|
||||
Paths *paths
|
||||
Eth1BlockHash *common.Hash
|
||||
Eth1GenesisBlock *types.Block
|
||||
StartTime time.Time
|
||||
CLGenesisTime uint64
|
||||
Eth1GenesisTime uint64
|
||||
|
||||
Reference in New Issue
Block a user