diff --git a/cl/cltypes/types.go b/cl/cltypes/types.go index 25f6a7c65ee..1145c683263 100644 --- a/cl/cltypes/types.go +++ b/cl/cltypes/types.go @@ -308,9 +308,8 @@ type SignedAggregateAndProof struct { Signature [96]byte `ssz-size:"96"` } -// BeaconState is used to create the initial store through checkpoint sync. -// we only use FinalizedCheckpoint field. -type BeaconState struct { +// BellatrixBeaconState is the bellatrix beacon state. +type BeaconStateBellatrix struct { GenesisTime uint64 GenesisValidatorsRoot [32]byte `ssz-size:"32"` Slot uint64 @@ -339,7 +338,7 @@ type BeaconState struct { } // BlockRoot retrieves a the state block root from the state. -func (b *BeaconState) BlockRoot() ([32]byte, error) { +func (b *BeaconStateBellatrix) BlockRoot() ([32]byte, error) { stateRoot, err := b.HashTreeRoot() if err != nil { return [32]byte{}, nil diff --git a/cl/cltypes/types_encoding.go b/cl/cltypes/types_encoding.go index 8b6d6f2dc6d..71521f2368f 100644 --- a/cl/cltypes/types_encoding.go +++ b/cl/cltypes/types_encoding.go @@ -1,5 +1,5 @@ // Code generated by fastssz. DO NOT EDIT. -// Hash: bb0ba844f1abd9ee25529f05cb8f4e437b0f280e014272498d9f3a84050e0e9f +// Hash: 7c8477ab1247c0b019c7e3741d39b4970fb3af2a9f8765806dbd44d4911e2d21 package cltypes import ( @@ -3882,13 +3882,13 @@ func (s *SignedAggregateAndProof) HashTreeRootWith(hh *ssz.Hasher) (err error) { return } -// MarshalSSZ ssz marshals the BeaconState object -func (b *BeaconState) MarshalSSZ() ([]byte, error) { +// MarshalSSZ ssz marshals the BeaconStateBellatrix object +func (b *BeaconStateBellatrix) MarshalSSZ() ([]byte, error) { return ssz.MarshalSSZ(b) } -// MarshalSSZTo ssz marshals the BeaconState object to a target array -func (b *BeaconState) MarshalSSZTo(buf []byte) (dst []byte, err error) { +// MarshalSSZTo ssz marshals the BeaconStateBellatrix object to a target array +func (b *BeaconStateBellatrix) MarshalSSZTo(buf []byte) (dst []byte, err error) { dst = buf offset := int(2736633) @@ -4117,8 +4117,8 @@ func (b *BeaconState) MarshalSSZTo(buf []byte) (dst []byte, err error) { return } -// UnmarshalSSZ ssz unmarshals the BeaconState object -func (b *BeaconState) UnmarshalSSZ(buf []byte) error { +// UnmarshalSSZ ssz unmarshals the BeaconStateBellatrix object +func (b *BeaconStateBellatrix) UnmarshalSSZ(buf []byte) error { var err error size := uint64(len(buf)) if size < 2736633 { @@ -4390,8 +4390,8 @@ func (b *BeaconState) UnmarshalSSZ(buf []byte) error { return err } -// SizeSSZ returns the ssz encoded size in bytes for the BeaconState object -func (b *BeaconState) SizeSSZ() (size int) { +// SizeSSZ returns the ssz encoded size in bytes for the BeaconStateBellatrix object +func (b *BeaconStateBellatrix) SizeSSZ() (size int) { size = 2736633 // Field (7) 'HistoricalRoots' @@ -4424,13 +4424,13 @@ func (b *BeaconState) SizeSSZ() (size int) { return } -// HashTreeRoot ssz hashes the BeaconState object -func (b *BeaconState) HashTreeRoot() ([32]byte, error) { +// HashTreeRoot ssz hashes the BeaconStateBellatrix object +func (b *BeaconStateBellatrix) HashTreeRoot() ([32]byte, error) { return ssz.HashWithDefaultHasher(b) } -// HashTreeRootWith ssz hashes the BeaconState object with a hasher -func (b *BeaconState) HashTreeRootWith(hh *ssz.Hasher) (err error) { +// HashTreeRootWith ssz hashes the BeaconStateBellatrix object with a hasher +func (b *BeaconStateBellatrix) HashTreeRootWith(hh *ssz.Hasher) (err error) { indx := hh.Index() // Field (0) 'GenesisTime' diff --git a/cmd/erigon-cl/core/checkpoint.go b/cmd/erigon-cl/core/checkpoint.go index a98464c34d8..0b0832da13b 100644 --- a/cmd/erigon-cl/core/checkpoint.go +++ b/cmd/erigon-cl/core/checkpoint.go @@ -10,7 +10,7 @@ import ( "github.com/ledgerwatch/log/v3" ) -func RetrieveBeaconState(ctx context.Context, uri string) (*cltypes.BeaconState, error) { +func RetrieveBeaconState(ctx context.Context, uri string) (*cltypes.BeaconStateBellatrix, error) { log.Info("[Checkpoint Sync] Requesting beacon state", "uri", uri) req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri, nil) if err != nil { @@ -36,7 +36,7 @@ func RetrieveBeaconState(ctx context.Context, uri string) (*cltypes.BeaconState, return nil, fmt.Errorf("checkpoint sync failed %s", err) } - beaconState := &cltypes.BeaconState{} + beaconState := &cltypes.BeaconStateBellatrix{} err = beaconState.UnmarshalSSZ(marshaled) if err != nil { return nil, fmt.Errorf("checkpoint sync failed %s", err) diff --git a/cmd/erigon-cl/core/rawdb/accessors.go b/cmd/erigon-cl/core/rawdb/accessors.go index bfd50684b8d..b9ff8ef94b7 100644 --- a/cmd/erigon-cl/core/rawdb/accessors.go +++ b/cmd/erigon-cl/core/rawdb/accessors.go @@ -23,7 +23,7 @@ func EncodeNumber(n uint64) []byte { } // WriteBeaconState writes beacon state for specific block to database. -func WriteBeaconState(tx kv.Putter, state *cltypes.BeaconState) error { +func WriteBeaconState(tx kv.Putter, state *cltypes.BeaconStateBellatrix) error { data, err := utils.EncodeSSZSnappy(state) if err != nil { return err @@ -33,12 +33,12 @@ func WriteBeaconState(tx kv.Putter, state *cltypes.BeaconState) error { } // ReadBeaconState reads beacon state for specific block from database. -func ReadBeaconState(tx kv.Getter, slot uint64) (*cltypes.BeaconState, error) { +func ReadBeaconState(tx kv.Getter, slot uint64) (*cltypes.BeaconStateBellatrix, error) { data, err := tx.GetOne(kv.BeaconState, EncodeNumber(slot)) if err != nil { return nil, err } - state := &cltypes.BeaconState{} + state := &cltypes.BeaconStateBellatrix{} if len(data) == 0 { return nil, nil diff --git a/cmd/erigon-cl/core/state/getters.go b/cmd/erigon-cl/core/state/getters.go new file mode 100644 index 00000000000..ee5ac7074d3 --- /dev/null +++ b/cmd/erigon-cl/core/state/getters.go @@ -0,0 +1,142 @@ +package state + +import ( + "github.com/ledgerwatch/erigon/cl/cltypes" + "github.com/ledgerwatch/erigon/common" +) + +// Just a bunch of simple getters. + +func (b *BeaconState) GenesisTime() uint64 { + return b.genesisTime +} + +func (b *BeaconState) GenesisValidatorsRoot() common.Hash { + return b.genesisValidatorsRoot +} + +func (b *BeaconState) Slot() uint64 { + return b.slot +} + +func (b *BeaconState) Fork() *cltypes.Fork { + return b.fork +} + +func (b *BeaconState) LatestBlockHeader() *cltypes.BeaconBlockHeader { + return b.latestBlockHeader +} + +func (b *BeaconState) BlockRoots() [][32]byte { + return b.blockRoots +} + +func (b *BeaconState) StateRoots() [][32]byte { + return b.stateRoots +} + +func (b *BeaconState) HistoricalRoots() [][32]byte { + return b.historicalRoots +} + +func (b *BeaconState) Eth1Data() *cltypes.Eth1Data { + return b.eth1Data +} + +func (b *BeaconState) Eth1DataVotes() []*cltypes.Eth1Data { + return b.eth1DataVotes +} + +func (b *BeaconState) Eth1DepositIndex() uint64 { + return b.eth1DepositIndex +} + +func (b *BeaconState) Validators() []*cltypes.Validator { + return b.validators +} + +func (b *BeaconState) Balances() []uint64 { + return b.balances +} + +func (b *BeaconState) RandaoMixes() [][32]byte { + return b.randaoMixes +} + +func (b *BeaconState) Slashings() []uint64 { + return b.slashings +} + +func (b *BeaconState) PreviousEpochParticipation() []byte { + return b.previousEpochParticipation +} + +func (b *BeaconState) CurrentEpochParticipation() []byte { + return b.currentEpochParticipation +} + +func (b *BeaconState) JustificationBits() []byte { + return b.justificationBits +} + +func (b *BeaconState) PreviousJustifiedCheckpoint() *cltypes.Checkpoint { + return b.previousJustifiedCheckpoint +} + +func (b *BeaconState) CurrentJustifiedCheckpoint() *cltypes.Checkpoint { + return b.currentJustifiedCheckpoint +} + +func (b *BeaconState) FinalizedCheckpoint() *cltypes.Checkpoint { + return b.finalizedCheckpoint +} + +func (b *BeaconState) CurrentSyncCommittee() *cltypes.SyncCommittee { + return b.currentSyncCommittee +} + +func (b *BeaconState) NextSyncCommittee() *cltypes.SyncCommittee { + return b.nextSyncCommittee +} + +func (b *BeaconState) LatestExecutionPayloadHeader() *cltypes.ExecutionHeader { + return b.latestExecutionPayloadHeader +} + +// GetStateSSZObject allows us to use ssz methods. +func (b *BeaconState) GetStateSSZObject() cltypes.ObjectSSZ { + switch b.version { + case BellatrixVersion: + return &cltypes.BeaconStateBellatrix{ + GenesisTime: b.genesisTime, + GenesisValidatorsRoot: b.genesisValidatorsRoot, + Slot: b.slot, + Fork: b.fork, + LatestBlockHeader: b.latestBlockHeader, + BlockRoots: b.blockRoots, + StateRoots: b.stateRoots, + HistoricalRoots: b.historicalRoots, + Eth1Data: b.eth1Data, + Eth1DataVotes: b.eth1DataVotes, + Eth1DepositIndex: b.eth1DepositIndex, + Validators: b.validators, + Balances: b.balances, + RandaoMixes: b.randaoMixes, + Slashings: b.slashings, + PreviousEpochParticipation: b.previousEpochParticipation, + CurrentEpochParticipation: b.currentEpochParticipation, + JustificationBits: b.justificationBits, + FinalizedCheckpoint: b.finalizedCheckpoint, + CurrentJustifiedCheckpoint: b.currentJustifiedCheckpoint, + PreviousJustifiedCheckpoint: b.previousJustifiedCheckpoint, + InactivityScores: b.inactivityScores, + CurrentSyncCommittee: b.currentSyncCommittee, + NextSyncCommittee: b.nextSyncCommittee, + LatestExecutionPayloadHeader: b.latestExecutionPayloadHeader, + } + case CapellaVersion: + panic("not implemented") + default: + panic("not a valid version") + } +} diff --git a/cmd/erigon-cl/core/state/leaf_indexes.go b/cmd/erigon-cl/core/state/leaf_indexes.go new file mode 100644 index 00000000000..374d3c48e79 --- /dev/null +++ b/cmd/erigon-cl/core/state/leaf_indexes.go @@ -0,0 +1,33 @@ +package state + +// All position of all the leaves of the state merkle tree. +const ( + GenesisTimeLeafIndex = 0 + GenesisValidatorsRootLeafIndex = 1 + SlotLeafIndex = 2 + ForkLeafIndex = 3 + LatestBlockHeaderLeafIndex = 4 + BlockRootsLeafIndex = 5 + StateRootsLeafIndex = 6 + HistoricalRootsLeafIndex = 7 + Eth1DataLeafIndex = 8 + Eth1DataVotesLeafIndex = 9 + Eth1DepositIndexLeafIndex = 10 + ValidatorsLeafIndex = 11 + BalancesLeafIndex = 12 + RandaoMixesLeafIndex = 13 + SlashingsLeafIndex = 14 + PreviousEpochParticipationLeafIndex = 15 + CurrentEpochParticipationLeafIndex = 16 + JustificationBitsLeafIndex = 17 + PreviousJustifiedCheckpointLeafIndex = 18 + CurrentJustifiedCheckpointLeafIndex = 19 + FinalizedCheckpointLeafIndex = 20 + InactivityScoresLeafIndex = 21 + CurrentSyncCommitteeLeafIndex = 22 + NextSyncCommitteeLeafIndex = 23 + LatestExecutionPayloadHeaderLeafIndex = 24 + + // Leaves sizes + BellatrixLeavesSize = 25 +) diff --git a/cmd/erigon-cl/core/state/setters.go b/cmd/erigon-cl/core/state/setters.go new file mode 100644 index 00000000000..294ac8dfc84 --- /dev/null +++ b/cmd/erigon-cl/core/state/setters.go @@ -0,0 +1,128 @@ +package state + +import ( + "github.com/ledgerwatch/erigon/cl/cltypes" + "github.com/ledgerwatch/erigon/common" +) + +// Below are setters. Note that they also dirty the state. + +func (b *BeaconState) SetGenesisTime(genesisTime uint64) { + b.touchedLeaves[GenesisTimeLeafIndex] = true + b.genesisTime = genesisTime +} + +func (b *BeaconState) SetGenesisValidatorsRoot(genesisValidatorRoot common.Hash) { + b.touchedLeaves[GenesisValidatorsRootLeafIndex] = true + b.genesisValidatorsRoot = genesisValidatorRoot +} + +func (b *BeaconState) SetSlot(slot uint64) { + b.touchedLeaves[SlotLeafIndex] = true + b.slot = slot +} + +func (b *BeaconState) SetFork(fork *cltypes.Fork) { + b.touchedLeaves[ForkLeafIndex] = true + b.fork = fork +} + +func (b *BeaconState) SetLatestBlockHeader(header *cltypes.BeaconBlockHeader) { + b.touchedLeaves[LatestBlockHeaderLeafIndex] = true + b.latestBlockHeader = header +} + +func (b *BeaconState) SetBlockRoots(blockRoots [][32]byte) { + b.touchedLeaves[BlockRootsLeafIndex] = true + b.blockRoots = blockRoots +} + +func (b *BeaconState) SetStateRoots(stateRoots [][32]byte) { + b.touchedLeaves[StateRootsLeafIndex] = true + b.stateRoots = stateRoots +} + +func (b *BeaconState) SetHistoricalRoots(historicalRoots [][32]byte) { + b.touchedLeaves[HistoricalRootsLeafIndex] = true + b.historicalRoots = historicalRoots +} + +func (b *BeaconState) SetEth1Data(eth1Data *cltypes.Eth1Data) { + b.touchedLeaves[Eth1DataLeafIndex] = true + b.eth1Data = eth1Data +} + +func (b *BeaconState) SetEth1DataVotes(eth1DataVotes []*cltypes.Eth1Data) { + b.touchedLeaves[Eth1DataVotesLeafIndex] = true + b.eth1DataVotes = eth1DataVotes +} + +func (b *BeaconState) SetEth1DepositIndex(eth1DepositIndex uint64) { + b.touchedLeaves[Eth1DepositIndexLeafIndex] = true + b.eth1DepositIndex = eth1DepositIndex +} + +func (b *BeaconState) SetValidators(validators []*cltypes.Validator) { + b.touchedLeaves[ValidatorsLeafIndex] = true + b.validators = validators +} + +func (b *BeaconState) SetBalances(balances []uint64) { + b.touchedLeaves[BalancesLeafIndex] = true + b.balances = balances +} + +func (b *BeaconState) SetRandaoMixes(randaoMixes [][32]byte) { + b.touchedLeaves[RandaoMixesLeafIndex] = true + b.randaoMixes = randaoMixes +} + +func (b *BeaconState) SetSlashings(slashings []uint64) { + b.touchedLeaves[SlashingsLeafIndex] = true + b.slashings = slashings +} + +func (b *BeaconState) SetPreviousEpochParticipation(previousEpochParticipation []byte) { + b.touchedLeaves[PreviousEpochParticipationLeafIndex] = true + b.previousEpochParticipation = previousEpochParticipation +} + +func (b *BeaconState) SetCurrentEpochParticipation(currentEpochParticipation []byte) { + b.touchedLeaves[CurrentEpochParticipationLeafIndex] = true + b.currentEpochParticipation = currentEpochParticipation +} + +func (b *BeaconState) SetJustificationBits(justificationBits []byte) { + b.touchedLeaves[JustificationBitsLeafIndex] = true + b.justificationBits = justificationBits +} + +func (b *BeaconState) SetPreviousJustifiedCheckpoint(previousJustifiedCheckpoint *cltypes.Checkpoint) { + b.touchedLeaves[PreviousJustifiedCheckpointLeafIndex] = true + b.previousJustifiedCheckpoint = previousJustifiedCheckpoint +} + +func (b *BeaconState) SetCurrentJustifiedCheckpoint(currentJustifiedCheckpoint *cltypes.Checkpoint) { + b.touchedLeaves[CurrentJustifiedCheckpointLeafIndex] = true + b.currentJustifiedCheckpoint = currentJustifiedCheckpoint +} + +func (b *BeaconState) SetFinalizedCheckpoint(finalizedCheckpoint *cltypes.Checkpoint) { + b.touchedLeaves[FinalizedCheckpointLeafIndex] = true + b.finalizedCheckpoint = finalizedCheckpoint +} + +func (b *BeaconState) SetCurrentSyncCommittee(currentSyncCommittee *cltypes.SyncCommittee) { + b.touchedLeaves[CurrentSyncCommitteeLeafIndex] = true + b.currentSyncCommittee = currentSyncCommittee +} + +func (b *BeaconState) SetNextSyncCommittee(nextSyncCommittee *cltypes.SyncCommittee) { + b.touchedLeaves[NextSyncCommitteeLeafIndex] = true + b.nextSyncCommittee = nextSyncCommittee +} + +func (b *BeaconState) SetLatestExecutionPayloadHeader(header *cltypes.ExecutionHeader) { + b.touchedLeaves[LatestExecutionPayloadHeaderLeafIndex] = true + b.latestExecutionPayloadHeader = header +} diff --git a/cmd/erigon-cl/core/state/state.go b/cmd/erigon-cl/core/state/state.go new file mode 100644 index 00000000000..f3c4ef00dc8 --- /dev/null +++ b/cmd/erigon-cl/core/state/state.go @@ -0,0 +1,107 @@ +package state + +import ( + "github.com/ledgerwatch/erigon/cl/cltypes" + "github.com/ledgerwatch/erigon/common" +) + +type HashFunc func([]byte) ([32]byte, error) + +type StateVersion int + +// We do not care about Phase0 and Altair because they are both pre-merge. +const ( + BellatrixVersion StateVersion = 0 + CapellaVersion StateVersion = 1 // Unimplemented! +) + +type BeaconState struct { + // State fields + genesisTime uint64 + genesisValidatorsRoot common.Hash + slot uint64 + fork *cltypes.Fork + latestBlockHeader *cltypes.BeaconBlockHeader + blockRoots [][32]byte + stateRoots [][32]byte + historicalRoots [][32]byte + eth1Data *cltypes.Eth1Data + eth1DataVotes []*cltypes.Eth1Data + eth1DepositIndex uint64 + validators []*cltypes.Validator + balances []uint64 + randaoMixes [][32]byte + slashings []uint64 + previousEpochParticipation []byte + currentEpochParticipation []byte + justificationBits []byte + previousJustifiedCheckpoint *cltypes.Checkpoint + currentJustifiedCheckpoint *cltypes.Checkpoint + finalizedCheckpoint *cltypes.Checkpoint + inactivityScores []uint64 + currentSyncCommittee *cltypes.SyncCommittee + nextSyncCommittee *cltypes.SyncCommittee + latestExecutionPayloadHeader *cltypes.ExecutionHeader + // Internals + version StateVersion // State version + leaves []common.Hash // Pre-computed leaves. + touchedLeaves map[int]bool // Maps each leaf to whether they were touched or not. + /*root common.Hash // Cached state root. + hasher HashFunc // Merkle root hasher.*/ +} + +// FromBellatrixState initialize the beacon state as a bellatrix state. +func FromBellatrixState(state *cltypes.BeaconStateBellatrix) *BeaconState { + return &BeaconState{ + genesisTime: state.GenesisTime, + genesisValidatorsRoot: state.GenesisValidatorsRoot, + slot: state.Slot, + fork: state.Fork, + latestBlockHeader: state.LatestBlockHeader, + blockRoots: state.BlockRoots, + stateRoots: state.StateRoots, + historicalRoots: state.HistoricalRoots, + eth1Data: state.Eth1Data, + eth1DataVotes: state.Eth1DataVotes, + eth1DepositIndex: state.Eth1DepositIndex, + validators: state.Validators, + balances: state.Balances, + randaoMixes: state.RandaoMixes, + slashings: state.Slashings, + previousEpochParticipation: state.PreviousEpochParticipation, + currentEpochParticipation: state.CurrentEpochParticipation, + justificationBits: state.JustificationBits, + previousJustifiedCheckpoint: state.PreviousJustifiedCheckpoint, + currentJustifiedCheckpoint: state.CurrentJustifiedCheckpoint, + finalizedCheckpoint: state.FinalizedCheckpoint, + inactivityScores: state.InactivityScores, + currentSyncCommittee: state.CurrentSyncCommittee, + nextSyncCommittee: state.NextSyncCommittee, + latestExecutionPayloadHeader: state.LatestExecutionPayloadHeader, + // Internals + version: BellatrixVersion, + leaves: make([]common.Hash, BellatrixLeavesSize), + touchedLeaves: map[int]bool{}, + // TODO: Make proper hasher + } +} + +// MarshallSSZTo encodes the state into the given buffer. +func (b *BeaconState) MarshalSSZTo(dst []byte) ([]byte, error) { + return b.GetStateSSZObject().MarshalSSZTo(dst) +} + +// MarshallSSZTo encodes the state. +func (b *BeaconState) MarshalSSZ() ([]byte, error) { + return b.GetStateSSZObject().MarshalSSZ() +} + +// MarshallSSZTo retrieve the SSZ encoded length of the state. +func (b *BeaconState) SizeSSZ() int { + return b.GetStateSSZObject().SizeSSZ() +} + +// MarshallSSZTo retrieve the SSZ encoded length of the state. +func (b *BeaconState) UnmarshalSSZ(buf []byte) error { + panic("beacon state should be derived, use FromBellatrixState instead.") +} diff --git a/cmd/erigon-cl/core/transition/process_slots.go b/cmd/erigon-cl/core/transition/process_slots.go index ca7e16ed57c..c0ec4ac8eed 100644 --- a/cmd/erigon-cl/core/transition/process_slots.go +++ b/cmd/erigon-cl/core/transition/process_slots.go @@ -7,7 +7,7 @@ import ( "github.com/ledgerwatch/erigon/cl/cltypes" ) -func (s *StateTransistor) transitionState(state *cltypes.BeaconState, block *cltypes.SignedBeaconBlockBellatrix, validate bool) error { +func (s *StateTransistor) transitionState(state *cltypes.BeaconStateBellatrix, block *cltypes.SignedBeaconBlockBellatrix, validate bool) error { cur_block := block.Block s.processSlots(state, cur_block.Slot) if validate { @@ -33,7 +33,7 @@ func (s *StateTransistor) transitionState(state *cltypes.BeaconState, block *clt } // transitionSlot is called each time there is a new slot to process -func (s *StateTransistor) transitionSlot(state *cltypes.BeaconState) error { +func (s *StateTransistor) transitionSlot(state *cltypes.BeaconStateBellatrix) error { previousStateRoot, err := state.HashTreeRoot() if err != nil { return err @@ -50,7 +50,7 @@ func (s *StateTransistor) transitionSlot(state *cltypes.BeaconState) error { return nil } -func (s *StateTransistor) processSlots(state *cltypes.BeaconState, slot uint64) error { +func (s *StateTransistor) processSlots(state *cltypes.BeaconStateBellatrix, slot uint64) error { if slot <= state.Slot { return fmt.Errorf("new slot: %d not greater than state slot: %d", slot, state.Slot) } @@ -66,7 +66,7 @@ func (s *StateTransistor) processSlots(state *cltypes.BeaconState, slot uint64) return nil } -func (s *StateTransistor) verifyBlockSignature(state *cltypes.BeaconState, block *cltypes.SignedBeaconBlockBellatrix) (bool, error) { +func (s *StateTransistor) verifyBlockSignature(state *cltypes.BeaconStateBellatrix, block *cltypes.SignedBeaconBlockBellatrix) (bool, error) { proposer := state.Validators[block.Block.ProposerIndex] signing_root, err := block.Block.Body.HashTreeRoot() if err != nil { diff --git a/cmd/erigon-cl/core/transition/process_slots_test.go b/cmd/erigon-cl/core/transition/process_slots_test.go index a977ae67afe..086141542eb 100644 --- a/cmd/erigon-cl/core/transition/process_slots_test.go +++ b/cmd/erigon-cl/core/transition/process_slots_test.go @@ -39,8 +39,8 @@ var ( blockHashValidator1 = "f5b74f03650fb65362badf85660ab2f6e92e8df10af9a981a2b5a4df1d9f2479" ) -func getEmptyState() *cltypes.BeaconState { - return &cltypes.BeaconState{ +func getEmptyState() *cltypes.BeaconStateBellatrix { + return &cltypes.BeaconStateBellatrix{ Fork: &cltypes.Fork{}, LatestBlockHeader: &cltypes.BeaconBlockHeader{}, Eth1Data: &cltypes.Eth1Data{}, @@ -86,8 +86,8 @@ func getTestBeaconBlock() *cltypes.SignedBeaconBlockBellatrix { } } -func getTestBeaconState() *cltypes.BeaconState { - return &cltypes.BeaconState{ +func getTestBeaconState() *cltypes.BeaconStateBellatrix { + return &cltypes.BeaconStateBellatrix{ BlockRoots: make([][32]byte, 8192), StateRoots: make([][32]byte, 8192), RandaoMixes: make([][32]byte, 65536), @@ -114,14 +114,14 @@ func getTestBeaconState() *cltypes.BeaconState { } } -func getTestBeaconStateWithValidator() *cltypes.BeaconState { +func getTestBeaconStateWithValidator() *cltypes.BeaconStateBellatrix { res := getTestBeaconState() res.Validators = append(res.Validators, testValidator) res.Validators[0].WithdrawalCredentials = make([]byte, 32) return res } -func prepareNextBeaconState(t *testing.T, slots []uint64, stateHashs, blockHashs []string, nextState *cltypes.BeaconState) *cltypes.BeaconState { +func prepareNextBeaconState(t *testing.T, slots []uint64, stateHashs, blockHashs []string, nextState *cltypes.BeaconStateBellatrix) *cltypes.BeaconStateBellatrix { // Set slot to initial index. for i, val := range slots { nextState.Slot = val @@ -149,8 +149,8 @@ func TestTransitionSlot(t *testing.T) { slot42.Slot = 42 testCases := []struct { description string - prevState *cltypes.BeaconState - expectedState *cltypes.BeaconState + prevState *cltypes.BeaconStateBellatrix + expectedState *cltypes.BeaconStateBellatrix wantErr bool }{ { @@ -214,8 +214,8 @@ func TestProcessSlots(t *testing.T) { slot42.Slot = 42 testCases := []struct { description string - prevState *cltypes.BeaconState - expectedState *cltypes.BeaconState + prevState *cltypes.BeaconStateBellatrix + expectedState *cltypes.BeaconStateBellatrix numSlots uint64 startSlot uint64 wantErr bool @@ -293,7 +293,7 @@ func TestVerifyBlockSignature(t *testing.T) { badSigBlock.Signature = badSignature testCases := []struct { description string - state *cltypes.BeaconState + state *cltypes.BeaconStateBellatrix block *cltypes.SignedBeaconBlockBellatrix wantValid bool wantErr bool @@ -352,9 +352,9 @@ func TestTransitionState(t *testing.T) { badStateRootBlock.Block.StateRoot = [32]byte{} testCases := []struct { description string - prevState *cltypes.BeaconState + prevState *cltypes.BeaconStateBellatrix block *cltypes.SignedBeaconBlockBellatrix - expectedState *cltypes.BeaconState + expectedState *cltypes.BeaconStateBellatrix wantErr bool }{ { diff --git a/cmd/erigon-cl/core/transition/state_transistor.go b/cmd/erigon-cl/core/transition/state_transistor.go index 74301c935f4..f2c47662814 100644 --- a/cmd/erigon-cl/core/transition/state_transistor.go +++ b/cmd/erigon-cl/core/transition/state_transistor.go @@ -7,12 +7,12 @@ import ( // StateTransistor takes care of state transition type StateTransistor struct { - state *cltypes.BeaconState + state *cltypes.BeaconStateBellatrix beaconConfig *clparams.BeaconChainConfig genesisConfig *clparams.GenesisConfig } -func New(state *cltypes.BeaconState, beaconConfig *clparams.BeaconChainConfig, genesisConfig *clparams.GenesisConfig) *StateTransistor { +func New(state *cltypes.BeaconStateBellatrix, beaconConfig *clparams.BeaconChainConfig, genesisConfig *clparams.GenesisConfig) *StateTransistor { return &StateTransistor{ state: state, beaconConfig: beaconConfig, diff --git a/cmd/erigon-cl/main.go b/cmd/erigon-cl/main.go index 3d22e388fe0..f53ec341670 100644 --- a/cmd/erigon-cl/main.go +++ b/cmd/erigon-cl/main.go @@ -86,7 +86,7 @@ Loop: return nil } -func startSentinel(cliCtx *cli.Context, cfg lcCli.ConsensusClientCliCfg, state *cltypes.BeaconState) (sentinelrpc.SentinelClient, error) { +func startSentinel(cliCtx *cli.Context, cfg lcCli.ConsensusClientCliCfg, state *cltypes.BeaconStateBellatrix) (sentinelrpc.SentinelClient, error) { forkDigest, err := fork.ComputeForkDigest(cfg.BeaconCfg, cfg.GenesisCfg) if err != nil { return nil, err @@ -114,7 +114,7 @@ func startSentinel(cliCtx *cli.Context, cfg lcCli.ConsensusClientCliCfg, state * return s, nil } -func getCheckpointState(ctx context.Context, db kv.RwDB) (*cltypes.BeaconState, error) { +func getCheckpointState(ctx context.Context, db kv.RwDB) (*cltypes.BeaconStateBellatrix, error) { uri := clparams.GetCheckpointSyncEndpoint(clparams.MainnetNetwork) diff --git a/cmd/erigon-cl/stages/stage_beacon_blocks.go b/cmd/erigon-cl/stages/stage_beacon_blocks.go index f0412f482d6..81f9ce56e09 100644 --- a/cmd/erigon-cl/stages/stage_beacon_blocks.go +++ b/cmd/erigon-cl/stages/stage_beacon_blocks.go @@ -20,13 +20,13 @@ type StageBeaconsBlockCfg struct { downloader *network.ForwardBeaconDownloader genesisCfg *clparams.GenesisConfig beaconCfg *clparams.BeaconChainConfig - state *cltypes.BeaconState + state *cltypes.BeaconStateBellatrix } const maxOptimisticDistance = 8 func StageBeaconsBlock(db kv.RwDB, downloader *network.ForwardBeaconDownloader, genesisCfg *clparams.GenesisConfig, - beaconCfg *clparams.BeaconChainConfig, state *cltypes.BeaconState) StageBeaconsBlockCfg { + beaconCfg *clparams.BeaconChainConfig, state *cltypes.BeaconStateBellatrix) StageBeaconsBlockCfg { return StageBeaconsBlockCfg{ db: db, downloader: downloader, diff --git a/cmd/erigon-cl/stages/stages.go b/cmd/erigon-cl/stages/stages.go index 3fac311b27e..5a80d0e8ba3 100644 --- a/cmd/erigon-cl/stages/stages.go +++ b/cmd/erigon-cl/stages/stages.go @@ -52,7 +52,7 @@ func NewConsensusStagedSync(ctx context.Context, forwardDownloader *network.ForwardBeaconDownloader, genesisCfg *clparams.GenesisConfig, beaconCfg *clparams.BeaconChainConfig, - state *cltypes.BeaconState, + state *cltypes.BeaconStateBellatrix, triggerExecution triggerExecutionFunc, clearEth1Data bool, ) (*stagedsync.Sync, error) { diff --git a/cmd/erigon-cl/stages/stages_beacon_state.go b/cmd/erigon-cl/stages/stages_beacon_state.go index f9e9b4a41bf..9613514aff2 100644 --- a/cmd/erigon-cl/stages/stages_beacon_state.go +++ b/cmd/erigon-cl/stages/stages_beacon_state.go @@ -19,13 +19,13 @@ type StageBeaconStateCfg struct { db kv.RwDB genesisCfg *clparams.GenesisConfig beaconCfg *clparams.BeaconChainConfig - state *cltypes.BeaconState + state *cltypes.BeaconStateBellatrix clearEth1Data bool // Whether we want to discard eth1 data. triggerExecution triggerExecutionFunc } func StageBeaconState(db kv.RwDB, genesisCfg *clparams.GenesisConfig, - beaconCfg *clparams.BeaconChainConfig, state *cltypes.BeaconState, triggerExecution triggerExecutionFunc, clearEth1Data bool) StageBeaconStateCfg { + beaconCfg *clparams.BeaconChainConfig, state *cltypes.BeaconStateBellatrix, triggerExecution triggerExecutionFunc, clearEth1Data bool) StageBeaconStateCfg { return StageBeaconStateCfg{ db: db, genesisCfg: genesisCfg,