Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capella beacon state #11141

Merged
merged 51 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
d56db46
fork
rkapka Jul 29, 2022
657b897
types
rkapka Jul 29, 2022
fffa376
cloners
rkapka Jul 29, 2022
ed6c73a
getters
rkapka Jul 29, 2022
2b8a8da
remove CapellaBlind from fork
rkapka Jul 29, 2022
6d303f6
hasher
rkapka Jul 29, 2022
d21d437
setters
rkapka Jul 29, 2022
f061dab
spec params, config tests
rkapka Jul 29, 2022
00a840b
generate ssz
rkapka Aug 1, 2022
a8c9125
executionPayloadHeaderCapella
rkapka Aug 1, 2022
6790b1c
proto state
rkapka Aug 1, 2022
b1ba747
BeaconStateCapella SSZ
rkapka Aug 1, 2022
0b7cfbd
saving state
rkapka Aug 1, 2022
437c265
configfork
rkapka Aug 1, 2022
c5deedb
BUILD files
rkapka Aug 1, 2022
8af7855
Merge branch 'develop' into capella-state
rkapka Aug 1, 2022
d5e8c25
fix RealPosition
rkapka Aug 1, 2022
f98e90b
Merge branch '__develop' into capella-state
rkapka Aug 1, 2022
8b4b3cf
Merge remote-tracking branch 'origin/capella-state' into capella-state
rkapka Aug 1, 2022
d2aabcf
fix hasher
rkapka Aug 1, 2022
e74ad33
SetLatestExecutionPayloadHeaderCapella
rkapka Aug 1, 2022
e21ab9c
fix error message
rkapka Aug 1, 2022
c96303e
reduce complexity of saveStatesEfficientInternal
rkapka Aug 1, 2022
50ba24b
add latestExecutionPayloadHeaderCapella to minimal state
rkapka Aug 1, 2022
70c74ba
halway done interface
rkapka Aug 2, 2022
525066f
remove withdrawal methods
rkapka Aug 2, 2022
686d14c
merge setters
rkapka Aug 2, 2022
5926230
change signatures for v1 and v2
rkapka Aug 2, 2022
b05ed63
fixing errors pt. 1
rkapka Aug 2, 2022
bfeff5e
paylod_test fixes
rkapka Aug 2, 2022
a995186
fix everything
rkapka Aug 2, 2022
5d84931
remove unused func
rkapka Aug 2, 2022
ad28693
Merge branch '__develop' into capella-state
rkapka Sep 29, 2022
a311c89
fix tests
rkapka Sep 29, 2022
6326523
state_trie_test improvements
rkapka Sep 29, 2022
d7de7c7
in progress...
rkapka Sep 29, 2022
2647b1f
hasher test
rkapka Sep 29, 2022
bcae282
fix configs
rkapka Sep 30, 2022
fb6b1d1
Merge branch '__develop' into capella-state
rkapka Sep 30, 2022
0df2f33
simplify hashing
rkapka Sep 30, 2022
a117e0b
Revert "fix configs"
rkapka Sep 30, 2022
0b00e1e
remove capella from config test
rkapka Sep 30, 2022
1a43b53
Merge branch 'develop' into capella-state
rkapka Sep 30, 2022
5548f0f
unify locking
rkapka Oct 4, 2022
6a49722
Merge branch 'develop' into capella-state
terencechain Oct 4, 2022
54e519c
review
rkapka Oct 4, 2022
ae78e88
hashing
rkapka Oct 5, 2022
2ab4908
Merge branch 'develop' into capella-state
rkapka Oct 5, 2022
872245c
fixes
rkapka Oct 5, 2022
f437cd8
Merge branch 'develop' into capella-state
rauljordan Oct 5, 2022
6266ce2
Merge branch 'develop' into capella-state
rkapka Oct 12, 2022
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
24 changes: 24 additions & 0 deletions beacon-chain/db/kv/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,30 @@ func (s *Store) saveStatesEfficientInternal(ctx context.Context, tx *bolt.Tx, bl
if err := valIdxBkt.Put(rt[:], validatorKeys[i]); err != nil {
return err
}
case *ethpb.BeaconStateCapella:
Copy link
Contributor

Choose a reason for hiding this comment

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

This case switch is a good candidate for simplification using generics since all cases are the same function based on pbState.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this was my impression too. But I didn't want to refactor existing code in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

There isn't even a need for generics if we can just pass in fastssz.Marshaler as an interface (beacon state satisfies this)

var pbState *ethpb.BeaconStateCapella
var err error
pbState, err = statenative.ProtobufBeaconStateCapella(rawType)
rkapka marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
if pbState == nil {
return errors.New("nil state")
}
valEntries := pbState.Validators
pbState.Validators = make([]*ethpb.Validator, 0)
rawObj, err := pbState.MarshalSSZ()
if err != nil {
return err
}
encodedState := snappy.Encode(nil, append(bellatrixKey, rawObj...))
if err := bucket.Put(rt[:], encodedState); err != nil {
return err
}
pbState.Validators = valEntries
if err := valIdxBkt.Put(rt[:], validatorKeys[i]); err != nil {
return err
}
default:
return errors.New("invalid state type")
}
Expand Down
6 changes: 6 additions & 0 deletions beacon-chain/state/state-native/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ go_library(
"getters_state.go",
"getters_sync_committee.go",
"getters_validator.go",
"getters_withdrawal.go",
"hasher.go",
"proofs.go",
"readonly_validator.go",
Expand All @@ -30,6 +31,7 @@ go_library(
"setters_state.go",
"setters_sync_committee.go",
"setters_validator.go",
"setters_withdrawal.go",
"spec_parameters.go",
"ssz.go",
"state_trie.go",
Expand All @@ -42,6 +44,7 @@ go_library(
visibility = [
"//beacon-chain:__subpackages__",
"//contracts/deposit:__subpackages__",
"//encoding/ssz:__subpackages__",
"//proto/migration:__subpackages__",
"//proto/prysm/v1alpha1:__subpackages__",
"//proto/testing:__subpackages__",
Expand Down Expand Up @@ -90,11 +93,13 @@ go_test(
"getters_participation_test.go",
"getters_test.go",
"getters_validator_test.go",
"getters_withdrawal_test.go",
"hasher_test.go",
"proofs_test.go",
"readonly_validator_test.go",
"references_test.go",
"setters_attestation_test.go",
"setters_withdrawal_test.go",
"state_test.go",
"state_trie_test.go",
"types_test.go",
Expand All @@ -120,6 +125,7 @@ go_test(
"//proto/engine/v1:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//runtime/interop:go_default_library",
"//runtime/version:go_default_library",
"//testing/assert:go_default_library",
"//testing/require:go_default_library",
"//testing/util:go_default_library",
Expand Down
60 changes: 32 additions & 28 deletions beacon-chain/state/state-native/beacon_state_mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,38 @@ import (
// BeaconState defines a struct containing utilities for the Ethereum Beacon Chain state, defining
// getters and setters for its respective values and helpful functions such as HashTreeRoot().
type BeaconState struct {
version int
genesisTime uint64 `ssz-gen:"true"`
genesisValidatorsRoot customtypes.Byte32 `ssz-gen:"true" ssz-size:"32"`
slot eth2types.Slot `ssz-gen:"true"`
fork *ethpb.Fork `ssz-gen:"true"`
latestBlockHeader *ethpb.BeaconBlockHeader `ssz-gen:"true"`
blockRoots *customtypes.BlockRoots `ssz-gen:"true" ssz-size:"8192,32"`
stateRoots *customtypes.StateRoots `ssz-gen:"true" ssz-size:"8192,32"`
historicalRoots customtypes.HistoricalRoots `ssz-gen:"true" ssz-size:"?,32" ssz-max:"16777216"`
eth1Data *ethpb.Eth1Data `ssz-gen:"true"`
eth1DataVotes []*ethpb.Eth1Data `ssz-gen:"true" ssz-max:"2048"`
eth1DepositIndex uint64 `ssz-gen:"true"`
validators []*ethpb.Validator `ssz-gen:"true" ssz-max:"1099511627776"`
balances []uint64 `ssz-gen:"true" ssz-max:"1099511627776"`
randaoMixes *customtypes.RandaoMixes `ssz-gen:"true" ssz-size:"65536,32"`
slashings []uint64 `ssz-gen:"true" ssz-size:"8192"`
previousEpochAttestations []*ethpb.PendingAttestation `ssz-gen:"true" ssz-max:"4096"`
currentEpochAttestations []*ethpb.PendingAttestation `ssz-gen:"true" ssz-max:"4096"`
previousEpochParticipation []byte `ssz-gen:"true" ssz-max:"1099511627776"`
currentEpochParticipation []byte `ssz-gen:"true" ssz-max:"1099511627776"`
justificationBits bitfield.Bitvector4 `ssz-gen:"true" ssz-size:"1"`
previousJustifiedCheckpoint *ethpb.Checkpoint `ssz-gen:"true"`
currentJustifiedCheckpoint *ethpb.Checkpoint `ssz-gen:"true"`
finalizedCheckpoint *ethpb.Checkpoint `ssz-gen:"true"`
inactivityScores []uint64 `ssz-gen:"true" ssz-max:"1099511627776"`
currentSyncCommittee *ethpb.SyncCommittee `ssz-gen:"true"`
nextSyncCommittee *ethpb.SyncCommittee `ssz-gen:"true"`
latestExecutionPayloadHeader *enginev1.ExecutionPayloadHeader `ssz-gen:"true"`
version int
genesisTime uint64 `ssz-gen:"true"`
genesisValidatorsRoot customtypes.Byte32 `ssz-gen:"true" ssz-size:"32"`
slot eth2types.Slot `ssz-gen:"true"`
fork *ethpb.Fork `ssz-gen:"true"`
latestBlockHeader *ethpb.BeaconBlockHeader `ssz-gen:"true"`
blockRoots *customtypes.BlockRoots `ssz-gen:"true" ssz-size:"8192,32"`
stateRoots *customtypes.StateRoots `ssz-gen:"true" ssz-size:"8192,32"`
historicalRoots customtypes.HistoricalRoots `ssz-gen:"true" ssz-size:"?,32" ssz-max:"16777216"`
eth1Data *ethpb.Eth1Data `ssz-gen:"true"`
eth1DataVotes []*ethpb.Eth1Data `ssz-gen:"true" ssz-max:"2048"`
eth1DepositIndex uint64 `ssz-gen:"true"`
validators []*ethpb.Validator `ssz-gen:"true" ssz-max:"1099511627776"`
balances []uint64 `ssz-gen:"true" ssz-max:"1099511627776"`
randaoMixes *customtypes.RandaoMixes `ssz-gen:"true" ssz-size:"65536,32"`
slashings []uint64 `ssz-gen:"true" ssz-size:"8192"`
previousEpochAttestations []*ethpb.PendingAttestation `ssz-gen:"true" ssz-max:"4096"`
currentEpochAttestations []*ethpb.PendingAttestation `ssz-gen:"true" ssz-max:"4096"`
previousEpochParticipation []byte `ssz-gen:"true" ssz-max:"1099511627776"`
currentEpochParticipation []byte `ssz-gen:"true" ssz-max:"1099511627776"`
justificationBits bitfield.Bitvector4 `ssz-gen:"true" ssz-size:"1"`
previousJustifiedCheckpoint *ethpb.Checkpoint `ssz-gen:"true"`
currentJustifiedCheckpoint *ethpb.Checkpoint `ssz-gen:"true"`
finalizedCheckpoint *ethpb.Checkpoint `ssz-gen:"true"`
inactivityScores []uint64 `ssz-gen:"true" ssz-max:"1099511627776"`
currentSyncCommittee *ethpb.SyncCommittee `ssz-gen:"true"`
nextSyncCommittee *ethpb.SyncCommittee `ssz-gen:"true"`
latestExecutionPayloadHeader *enginev1.ExecutionPayloadHeader `ssz-gen:"true"`
latestExecutionPayloadHeaderCapella *enginev1.ExecutionPayloadHeaderCapella `ssz-gen:"true"`
rkapka marked this conversation as resolved.
Show resolved Hide resolved
withdrawalQueue []*enginev1.Withdrawal `ssz-gen:"true" ssz-max:"1099511627776"`
nextWithdrawalIndex uint64 `ssz-gen:"true"`
nextPartialWithdrawalValidatorIndex eth2types.ValidatorIndex `ssz-gen:"true"`

lock sync.RWMutex
dirtyFields map[nativetypes.FieldIndex]bool
Expand Down
59 changes: 31 additions & 28 deletions beacon-chain/state/state-native/beacon_state_minimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,37 @@ import (
// BeaconState defines a struct containing utilities for the Ethereum Beacon Chain state, defining
// getters and setters for its respective values and helpful functions such as HashTreeRoot().
type BeaconState struct {
version int
genesisTime uint64 `ssz-gen:"true"`
genesisValidatorsRoot customtypes.Byte32 `ssz-gen:"true" ssz-size:"32"`
slot eth2types.Slot `ssz-gen:"true"`
fork *ethpb.Fork `ssz-gen:"true"`
latestBlockHeader *ethpb.BeaconBlockHeader `ssz-gen:"true"`
blockRoots *customtypes.BlockRoots `ssz-gen:"true" ssz-size:"64,32"`
stateRoots *customtypes.StateRoots `ssz-gen:"true" ssz-size:"64,32"`
historicalRoots customtypes.HistoricalRoots `ssz-gen:"true" ssz-size:"?,32" ssz-max:"16777216"`
eth1Data *ethpb.Eth1Data `ssz-gen:"true"`
eth1DataVotes []*ethpb.Eth1Data `ssz-gen:"true" ssz-max:"32"`
eth1DepositIndex uint64 `ssz-gen:"true"`
validators []*ethpb.Validator `ssz-gen:"true" ssz-max:"1099511627776"`
balances []uint64 `ssz-gen:"true" ssz-max:"1099511627776"`
randaoMixes *customtypes.RandaoMixes `ssz-gen:"true" ssz-size:"64,32"`
slashings []uint64 `ssz-gen:"true" ssz-size:"64"`
previousEpochAttestations []*ethpb.PendingAttestation `ssz-gen:"true" ssz-max:"1024"`
currentEpochAttestations []*ethpb.PendingAttestation `ssz-gen:"true" ssz-max:"1024"`
previousEpochParticipation []byte `ssz-gen:"true" ssz-max:"1099511627776"`
currentEpochParticipation []byte `ssz-gen:"true" ssz-max:"1099511627776"`
justificationBits bitfield.Bitvector4 `ssz-gen:"true" ssz-size:"1"`
previousJustifiedCheckpoint *ethpb.Checkpoint `ssz-gen:"true"`
currentJustifiedCheckpoint *ethpb.Checkpoint `ssz-gen:"true"`
finalizedCheckpoint *ethpb.Checkpoint `ssz-gen:"true"`
inactivityScores []uint64 `ssz-gen:"true" ssz-max:"1099511627776"`
currentSyncCommittee *ethpb.SyncCommittee `ssz-gen:"true"`
nextSyncCommittee *ethpb.SyncCommittee `ssz-gen:"true"`
latestExecutionPayloadHeader *enginev1.ExecutionPayloadHeader `ssz-gen:"true"`
version int
genesisTime uint64 `ssz-gen:"true"`
genesisValidatorsRoot customtypes.Byte32 `ssz-gen:"true" ssz-size:"32"`
slot eth2types.Slot `ssz-gen:"true"`
fork *ethpb.Fork `ssz-gen:"true"`
latestBlockHeader *ethpb.BeaconBlockHeader `ssz-gen:"true"`
blockRoots *customtypes.BlockRoots `ssz-gen:"true" ssz-size:"64,32"`
stateRoots *customtypes.StateRoots `ssz-gen:"true" ssz-size:"64,32"`
historicalRoots customtypes.HistoricalRoots `ssz-gen:"true" ssz-size:"?,32" ssz-max:"16777216"`
eth1Data *ethpb.Eth1Data `ssz-gen:"true"`
eth1DataVotes []*ethpb.Eth1Data `ssz-gen:"true" ssz-max:"32"`
eth1DepositIndex uint64 `ssz-gen:"true"`
validators []*ethpb.Validator `ssz-gen:"true" ssz-max:"1099511627776"`
balances []uint64 `ssz-gen:"true" ssz-max:"1099511627776"`
randaoMixes *customtypes.RandaoMixes `ssz-gen:"true" ssz-size:"64,32"`
slashings []uint64 `ssz-gen:"true" ssz-size:"64"`
previousEpochAttestations []*ethpb.PendingAttestation `ssz-gen:"true" ssz-max:"1024"`
currentEpochAttestations []*ethpb.PendingAttestation `ssz-gen:"true" ssz-max:"1024"`
previousEpochParticipation []byte `ssz-gen:"true" ssz-max:"1099511627776"`
currentEpochParticipation []byte `ssz-gen:"true" ssz-max:"1099511627776"`
justificationBits bitfield.Bitvector4 `ssz-gen:"true" ssz-size:"1"`
previousJustifiedCheckpoint *ethpb.Checkpoint `ssz-gen:"true"`
currentJustifiedCheckpoint *ethpb.Checkpoint `ssz-gen:"true"`
finalizedCheckpoint *ethpb.Checkpoint `ssz-gen:"true"`
inactivityScores []uint64 `ssz-gen:"true" ssz-max:"1099511627776"`
currentSyncCommittee *ethpb.SyncCommittee `ssz-gen:"true"`
nextSyncCommittee *ethpb.SyncCommittee `ssz-gen:"true"`
latestExecutionPayloadHeader *enginev1.ExecutionPayloadHeader `ssz-gen:"true"`
withdrawalQueue []*enginev1.Withdrawal `ssz-gen:"true" ssz-max:"1099511627776"`
nextWithdrawalIndex uint64 `ssz-gen:"true"`
nextPartialWithdrawalValidatorIndex eth2types.ValidatorIndex `ssz-gen:"true"`

lock sync.RWMutex
dirtyFields map[nativetypes.FieldIndex]bool
Expand Down
24 changes: 23 additions & 1 deletion beacon-chain/state/state-native/getters_payload_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

// LatestExecutionPayloadHeader of the beacon state.
func (b *BeaconState) LatestExecutionPayloadHeader() (*enginev1.ExecutionPayloadHeader, error) {
if b.version == version.Phase0 || b.version == version.Altair {
if b.version != version.Bellatrix {
rkapka marked this conversation as resolved.
Show resolved Hide resolved
rkapka marked this conversation as resolved.
Show resolved Hide resolved
return nil, errNotSupported("LatestExecutionPayloadHeader", b.version)
}

Expand All @@ -27,3 +27,25 @@ func (b *BeaconState) LatestExecutionPayloadHeader() (*enginev1.ExecutionPayload
func (b *BeaconState) latestExecutionPayloadHeaderVal() *enginev1.ExecutionPayloadHeader {
return ethpb.CopyExecutionPayloadHeader(b.latestExecutionPayloadHeader)
}

// LatestExecutionPayloadHeaderCapella of the beacon state.
func (b *BeaconState) LatestExecutionPayloadHeaderCapella() (*enginev1.ExecutionPayloadHeaderCapella, error) {
rkapka marked this conversation as resolved.
Show resolved Hide resolved
if b.version != version.Capella {
return nil, errNotSupported("LatestExecutionPayloadHeaderCapella", b.version)
}

if b.latestExecutionPayloadHeaderCapella == nil {
return nil, nil
}

b.lock.RLock()
defer b.lock.RUnlock()

return b.latestExecutionPayloadHeaderCapellaVal(), nil
rkapka marked this conversation as resolved.
Show resolved Hide resolved
}

// latestExecutionPayloadHeaderCapellaVal of the beacon state.
// This assumes that a lock is already held on BeaconState.
func (b *BeaconState) latestExecutionPayloadHeaderCapellaVal() *enginev1.ExecutionPayloadHeaderCapella {
return ethpb.CopyExecutionPayloadHeaderCapella(b.latestExecutionPayloadHeaderCapella)
}
38 changes: 38 additions & 0 deletions beacon-chain/state/state-native/getters_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,34 @@ func (b *BeaconState) ToProtoUnsafe() interface{} {
NextSyncCommittee: b.nextSyncCommittee,
LatestExecutionPayloadHeader: b.latestExecutionPayloadHeader,
}
case version.Capella:
return &ethpb.BeaconStateCapella{
GenesisTime: b.genesisTime,
GenesisValidatorsRoot: gvrCopy[:],
Slot: b.slot,
Fork: b.fork,
LatestBlockHeader: b.latestBlockHeader,
BlockRoots: b.blockRoots.Slice(),
StateRoots: b.stateRoots.Slice(),
HistoricalRoots: b.historicalRoots.Slice(),
Eth1Data: b.eth1Data,
Eth1DataVotes: b.eth1DataVotes,
Eth1DepositIndex: b.eth1DepositIndex,
Validators: b.validators,
Balances: b.balances,
RandaoMixes: b.randaoMixes.Slice(),
Slashings: b.slashings,
PreviousEpochParticipation: b.previousEpochParticipation,
CurrentEpochParticipation: b.currentEpochParticipation,
JustificationBits: b.justificationBits,
PreviousJustifiedCheckpoint: b.previousJustifiedCheckpoint,
CurrentJustifiedCheckpoint: b.currentJustifiedCheckpoint,
FinalizedCheckpoint: b.finalizedCheckpoint,
InactivityScores: b.inactivityScores,
CurrentSyncCommittee: b.currentSyncCommittee,
NextSyncCommittee: b.nextSyncCommittee,
LatestExecutionPayloadHeader: b.latestExecutionPayloadHeaderCapella,
}
default:
return nil
}
Expand Down Expand Up @@ -267,6 +295,16 @@ func ProtobufBeaconStateBellatrix(s interface{}) (*ethpb.BeaconStateBellatrix, e
return pbState, nil
}

// ProtobufBeaconStateCapella transforms an input into beacon state Capella in the form of protobuf.
// Error is returned if the input is not type protobuf beacon state.
func ProtobufBeaconStateCapella(s interface{}) (*ethpb.BeaconStateCapella, error) {
pbState, ok := s.(*ethpb.BeaconStateCapella)
if !ok {
return nil, errors.New("input is not type pb.BeaconStateCapella")
}
return pbState, nil
}

// InnerStateUnsafe returns the pointer value of the underlying
// beacon state proto object, bypassing immutability. Use with care.
func (b *BeaconState) InnerStateUnsafe() interface{} {
Expand Down
49 changes: 49 additions & 0 deletions beacon-chain/state/state-native/getters_withdrawal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package state_native

import (
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
enginev1 "github.com/prysmaticlabs/prysm/proto/engine/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/runtime/version"
)

// WithdrawalQueue returns the list of pending withdrawals.
func (b *BeaconState) WithdrawalQueue() ([]*enginev1.Withdrawal, error) {
if b.version < version.Capella {
return nil, errNotSupported("WithdrawalQueue", b.version)
}

b.lock.RLock()
defer b.lock.RUnlock()

return b.withdrawalQueueVal(), nil
}

func (b *BeaconState) withdrawalQueueVal() []*enginev1.Withdrawal {
return ethpb.CopyWithdrawalSlice(b.withdrawalQueue)
}

// NextWithdrawalIndex returns the index that will be assigned to the next withdrawal.
func (b *BeaconState) NextWithdrawalIndex() (uint64, error) {
if b.version < version.Capella {
return 0, errNotSupported("NextWithdrawalIndex", b.version)
}

b.lock.RLock()
Copy link
Contributor

Choose a reason for hiding this comment

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

do we want a lock to read the version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Version? This is NextWithdrawalIndex. And we don't have a lock when reading the version.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think @potuz refers to b.version < version.Capella. This version field is something that could be updated while another thread could be trying to read it

defer b.lock.RUnlock()

return b.nextWithdrawalIndex, nil
}

// NextPartialWithdrawalValidatorIndex returns the index of the validator which is
// next in line for a partial withdrawal.
func (b *BeaconState) NextPartialWithdrawalValidatorIndex() (types.ValidatorIndex, error) {
if b.version < version.Capella {
return 0, errNotSupported("NextPartialWithdrawalValidatorIndex", b.version)
}

b.lock.RLock()
defer b.lock.RUnlock()

return b.nextPartialWithdrawalValidatorIndex, nil
}
Loading