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

Remove withdrawal Queue #11610

Merged
merged 1 commit into from
Nov 3, 2022
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
1 change: 0 additions & 1 deletion beacon-chain/state/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ go_library(
"//config/fieldparams:go_default_library",
"//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library",
"//proto/engine/v1:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
Expand Down
6 changes: 2 additions & 4 deletions beacon-chain/state/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
"github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1"
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
)

Expand Down Expand Up @@ -63,6 +62,7 @@ type ReadOnlyBeaconState interface {
IsNil() bool
Version() int
LatestExecutionPayloadHeader() (interfaces.ExecutionData, error)
LastWithdrawalValidatorIndex() (types.ValidatorIndex, error)
}

// WriteOnlyBeaconState defines a struct which only has write access to beacon state methods.
Expand All @@ -85,10 +85,8 @@ type WriteOnlyBeaconState interface {
UpdateSlashingsAtIndex(idx, val uint64) error
AppendHistoricalRoots(root [32]byte) error
SetLatestExecutionPayloadHeader(payload interfaces.ExecutionData) error
SetWithdrawalQueue(val []*enginev1.Withdrawal) error
AppendWithdrawal(val *enginev1.Withdrawal) error
SetNextWithdrawalIndex(i uint64) error
SetNextPartialWithdrawalValidatorIndex(i types.ValidatorIndex) error
SetLastWithdrawalValidatorIndex(i types.ValidatorIndex) error
}

// ReadOnlyValidator defines a struct which only has read access to validator methods.
Expand Down
3 changes: 1 addition & 2 deletions beacon-chain/state/state-native/beacon_state_mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ type BeaconState struct {
nextSyncCommittee *ethpb.SyncCommittee `ssz-gen:"true"`
latestExecutionPayloadHeader *enginev1.ExecutionPayloadHeader `ssz-gen:"true"`
latestExecutionPayloadHeaderCapella *enginev1.ExecutionPayloadHeaderCapella `ssz-gen:"true"`
withdrawalQueue []*enginev1.Withdrawal `ssz-gen:"true" ssz-max:"1099511627776"`
nextWithdrawalIndex uint64 `ssz-gen:"true"`
nextPartialWithdrawalValidatorIndex eth2types.ValidatorIndex `ssz-gen:"true"`
lastWithdrawalValidatorIndex eth2types.ValidatorIndex `ssz-gen:"true"`
Copy link
Member

Choose a reason for hiding this comment

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

I think we can remove ssz-gen:"true", it's probably better to do it in another PR


lock sync.RWMutex
dirtyFields map[nativetypes.FieldIndex]bool
Expand Down
3 changes: 1 addition & 2 deletions beacon-chain/state/state-native/beacon_state_minimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ type BeaconState struct {
nextSyncCommittee *ethpb.SyncCommittee `ssz-gen:"true"`
latestExecutionPayloadHeader *enginev1.ExecutionPayloadHeader `ssz-gen:"true"`
latestExecutionPayloadHeaderCapella *enginev1.ExecutionPayloadHeaderCapella `ssz-gen:"true"`
withdrawalQueue []*enginev1.Withdrawal `ssz-gen:"true" ssz-max:"1099511627776"`
nextWithdrawalIndex uint64 `ssz-gen:"true"`
nextPartialWithdrawalValidatorIndex eth2types.ValidatorIndex `ssz-gen:"true"`
lastWithdrawalValidatorIndex eth2types.ValidatorIndex `ssz-gen:"true"`

lock sync.RWMutex
dirtyFields map[nativetypes.FieldIndex]bool
Expand Down
110 changes: 54 additions & 56 deletions beacon-chain/state/state-native/getters_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,34 +99,33 @@ func (b *BeaconState) ToProtoUnsafe() interface{} {
}
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,
WithdrawalQueue: b.withdrawalQueue,
NextWithdrawalIndex: b.nextWithdrawalIndex,
NextPartialWithdrawalValidatorIndex: b.nextPartialWithdrawalValidatorIndex,
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,
NextWithdrawalIndex: b.nextWithdrawalIndex,
LastWithdrawalValidatorIndex: b.lastWithdrawalValidatorIndex,
}
default:
return nil
Expand Down Expand Up @@ -226,34 +225,33 @@ func (b *BeaconState) ToProto() interface{} {
}
case version.Capella:
return &ethpb.BeaconStateCapella{
GenesisTime: b.genesisTime,
GenesisValidatorsRoot: gvrCopy[:],
Slot: b.slot,
Fork: b.forkVal(),
LatestBlockHeader: b.latestBlockHeaderVal(),
BlockRoots: b.blockRoots.Slice(),
StateRoots: b.stateRoots.Slice(),
HistoricalRoots: b.historicalRoots.Slice(),
Eth1Data: b.eth1DataVal(),
Eth1DataVotes: b.eth1DataVotesVal(),
Eth1DepositIndex: b.eth1DepositIndex,
Validators: b.validatorsVal(),
Balances: b.balancesVal(),
RandaoMixes: b.randaoMixes.Slice(),
Slashings: b.slashingsVal(),
PreviousEpochParticipation: b.previousEpochParticipationVal(),
CurrentEpochParticipation: b.currentEpochParticipationVal(),
JustificationBits: b.justificationBitsVal(),
PreviousJustifiedCheckpoint: b.previousJustifiedCheckpointVal(),
CurrentJustifiedCheckpoint: b.currentJustifiedCheckpointVal(),
FinalizedCheckpoint: b.finalizedCheckpointVal(),
InactivityScores: b.inactivityScoresVal(),
CurrentSyncCommittee: b.currentSyncCommitteeVal(),
NextSyncCommittee: b.nextSyncCommitteeVal(),
LatestExecutionPayloadHeader: b.latestExecutionPayloadHeaderCapellaVal(),
WithdrawalQueue: b.withdrawalQueueVal(),
NextWithdrawalIndex: b.nextWithdrawalIndex,
NextPartialWithdrawalValidatorIndex: b.nextPartialWithdrawalValidatorIndex,
GenesisTime: b.genesisTime,
GenesisValidatorsRoot: gvrCopy[:],
Slot: b.slot,
Fork: b.forkVal(),
LatestBlockHeader: b.latestBlockHeaderVal(),
BlockRoots: b.blockRoots.Slice(),
StateRoots: b.stateRoots.Slice(),
HistoricalRoots: b.historicalRoots.Slice(),
Eth1Data: b.eth1DataVal(),
Eth1DataVotes: b.eth1DataVotesVal(),
Eth1DepositIndex: b.eth1DepositIndex,
Validators: b.validatorsVal(),
Balances: b.balancesVal(),
RandaoMixes: b.randaoMixes.Slice(),
Slashings: b.slashingsVal(),
PreviousEpochParticipation: b.previousEpochParticipationVal(),
CurrentEpochParticipation: b.currentEpochParticipationVal(),
JustificationBits: b.justificationBitsVal(),
PreviousJustifiedCheckpoint: b.previousJustifiedCheckpointVal(),
CurrentJustifiedCheckpoint: b.currentJustifiedCheckpointVal(),
FinalizedCheckpoint: b.finalizedCheckpointVal(),
InactivityScores: b.inactivityScoresVal(),
CurrentSyncCommittee: b.currentSyncCommitteeVal(),
NextSyncCommittee: b.nextSyncCommitteeVal(),
LatestExecutionPayloadHeader: b.latestExecutionPayloadHeaderCapellaVal(),
NextWithdrawalIndex: b.nextWithdrawalIndex,
LastWithdrawalValidatorIndex: b.lastWithdrawalValidatorIndex,
}
default:
return nil
Expand Down
24 changes: 3 additions & 21 deletions beacon-chain/state/state-native/getters_withdrawal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,9 @@ package state_native

import (
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1"
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v3/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 {
Expand All @@ -37,13 +19,13 @@ func (b *BeaconState) NextWithdrawalIndex() (uint64, error) {

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

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

return b.nextPartialWithdrawalValidatorIndex, nil
return b.lastWithdrawalValidatorIndex, nil
}
37 changes: 5 additions & 32 deletions beacon-chain/state/state-native/getters_withdrawal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,11 @@ import (
"testing"

types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
enginev1 "github.com/prysmaticlabs/prysm/v3/proto/engine/v1"
"github.com/prysmaticlabs/prysm/v3/runtime/version"
"github.com/prysmaticlabs/prysm/v3/testing/assert"
"github.com/prysmaticlabs/prysm/v3/testing/require"
)

func TestWithdrawalQueue(t *testing.T) {
t.Run("ok", func(t *testing.T) {
ws := []*enginev1.Withdrawal{
{
WithdrawalIndex: 0,
ExecutionAddress: []byte("address1"),
Amount: 1,
},
{
WithdrawalIndex: 1,
ExecutionAddress: []byte("address2"),
Amount: 2,
},
}
s := BeaconState{version: version.Capella, withdrawalQueue: ws}
q, err := s.WithdrawalQueue()
require.NoError(t, err)
assert.DeepEqual(t, ws, q)
})
t.Run("version before Capella not supported", func(t *testing.T) {
s := BeaconState{version: version.Bellatrix}
_, err := s.WithdrawalQueue()
assert.ErrorContains(t, "WithdrawalQueue is not supported", err)
})
}

func TestNextWithdrawalIndex(t *testing.T) {
t.Run("ok", func(t *testing.T) {
s := BeaconState{version: version.Capella, nextWithdrawalIndex: 123}
Expand All @@ -50,16 +23,16 @@ func TestNextWithdrawalIndex(t *testing.T) {
})
}

func TestNextPartialWithdrawalValidatorIndex(t *testing.T) {
func TestLastWithdrawalValidatorIndex(t *testing.T) {
t.Run("ok", func(t *testing.T) {
s := BeaconState{version: version.Capella, nextPartialWithdrawalValidatorIndex: 123}
i, err := s.NextPartialWithdrawalValidatorIndex()
s := BeaconState{version: version.Capella, lastWithdrawalValidatorIndex: 123}
i, err := s.LastWithdrawalValidatorIndex()
require.NoError(t, err)
assert.Equal(t, types.ValidatorIndex(123), i)
})
t.Run("version before Capella not supported", func(t *testing.T) {
s := BeaconState{version: version.Bellatrix}
_, err := s.NextPartialWithdrawalValidatorIndex()
assert.ErrorContains(t, "NextPartialWithdrawalValidatorIndex is not supported", err)
_, err := s.LastWithdrawalValidatorIndex()
assert.ErrorContains(t, "LastWithdrawalValidatorIndex is not supported", err)
})
}
11 changes: 2 additions & 9 deletions beacon-chain/state/state-native/hasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,22 +246,15 @@ func ComputeFieldRootsWithHasher(ctx context.Context, state *BeaconState) ([][]b
}
fieldRoots[nativetypes.LatestExecutionPayloadHeaderCapella.RealPosition()] = executionPayloadRoot[:]

// Withdrawal queue root.
withdrawalQueueRoot, err := ssz.WithdrawalSliceRoot(hasher, state.withdrawalQueue, fieldparams.WithdrawalQueueLimit)
if err != nil {
return nil, err
}
fieldRoots[nativetypes.WithdrawalQueue.RealPosition()] = withdrawalQueueRoot[:]

// Next withdrawal index root.
nextWithdrawalIndexRoot := make([]byte, 32)
binary.LittleEndian.PutUint64(nextWithdrawalIndexRoot, state.nextWithdrawalIndex)
fieldRoots[nativetypes.NextWithdrawalIndex.RealPosition()] = nextWithdrawalIndexRoot

// Next partial withdrawal validator index root.
nextPartialWithdrawalValidatorIndexRoot := make([]byte, 32)
binary.LittleEndian.PutUint64(nextPartialWithdrawalValidatorIndexRoot, uint64(state.nextPartialWithdrawalValidatorIndex))
fieldRoots[nativetypes.NextPartialWithdrawalValidatorIndex.RealPosition()] = nextPartialWithdrawalValidatorIndexRoot
binary.LittleEndian.PutUint64(nextPartialWithdrawalValidatorIndexRoot, uint64(state.lastWithdrawalValidatorIndex))
fieldRoots[nativetypes.LastWithdrawalValidatorIndex.RealPosition()] = nextPartialWithdrawalValidatorIndexRoot
}

return fieldRoots, nil
Expand Down
4 changes: 1 addition & 3 deletions beacon-chain/state/state-native/hasher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,8 @@ func TestComputeFieldRootsWithHasher_Capella(t *testing.T) {
wrappedHeader, err := blocks.WrappedExecutionPayloadHeaderCapella(executionPayloadHeaderCapella())
require.NoError(t, err)
require.NoError(t, beaconState.SetLatestExecutionPayloadHeader(wrappedHeader))
require.NoError(t, beaconState.SetWithdrawalQueue([]*enginev1.Withdrawal{withdrawal()}))
require.NoError(t, beaconState.SetNextWithdrawalIndex(123))
require.NoError(t, beaconState.SetNextPartialWithdrawalValidatorIndex(123))
require.NoError(t, beaconState.SetLastWithdrawalValidatorIndex(123))

nativeState, ok := beaconState.(*statenative.BeaconState)
require.Equal(t, true, ok)
Expand Down Expand Up @@ -297,7 +296,6 @@ func TestComputeFieldRootsWithHasher_Capella(t *testing.T) {
{0x3d, 0xf3, 0x66, 0xd4, 0x12, 0x40, 0x3f, 0x28, 0xeb, 0xe4, 0x19, 0x59, 0xae, 0xab, 0x4d, 0xf3, 0x98, 0x88, 0x7f, 0x1e, 0x58, 0xa, 0x5d, 0xd4, 0xeb, 0xe5, 0x5d, 0x3d, 0x11, 0x70, 0x24, 0x76},
{0xd6, 0x4c, 0xb1, 0xac, 0x61, 0x7, 0x26, 0xbb, 0xd3, 0x27, 0x2a, 0xcd, 0xdd, 0x55, 0xf, 0x2b, 0x6a, 0xe8, 0x1, 0x31, 0x48, 0x66, 0x2f, 0x98, 0x7b, 0x6d, 0x27, 0x69, 0xd9, 0x40, 0xcc, 0x37},
{0x39, 0x29, 0x16, 0xe8, 0x5a, 0xd2, 0xb, 0xbb, 0x1f, 0xef, 0x6a, 0xe0, 0x2d, 0xa6, 0x6a, 0x46, 0x81, 0xba, 0xcf, 0x86, 0xfc, 0x16, 0x22, 0x2a, 0x9b, 0x72, 0x96, 0x71, 0x2b, 0xc7, 0x5b, 0x9d},
{0xf4, 0x45, 0x82, 0x69, 0xdb, 0xbf, 0x2e, 0x9, 0x52, 0xc0, 0xf9, 0xe8, 0x59, 0x17, 0xe0, 0xaf, 0x31, 0x80, 0x79, 0xf3, 0x1d, 0x9d, 0xce, 0xaa, 0xd8, 0x22, 0xc7, 0xeb, 0xf5, 0xd3, 0x85, 0x7e},
{0x7b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
{0x7b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
}
Expand Down
Loading