diff --git a/CHANGELOG.md b/CHANGELOG.md index c1b0f132cbb..0ca7ce6d046 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve - Simplified `ExitedValidatorIndices`. - Simplified `EjectedValidatorIndices`. - `engine_newPayloadV4`,`engine_getPayloadV4` are changes due to new execution request serialization decisions, [PR](https://github.com/prysmaticlabs/prysm/pull/14580) +- Fixed various small things in state-native code. - Use ROBlock earlier in block syncing pipeline. - Changed the signature of `ProcessPayload`. - Only Build the Protobuf state once during serialization. diff --git a/beacon-chain/core/blocks/withdrawals.go b/beacon-chain/core/blocks/withdrawals.go index f52378243b3..b7806503c9d 100644 --- a/beacon-chain/core/blocks/withdrawals.go +++ b/beacon-chain/core/blocks/withdrawals.go @@ -193,7 +193,7 @@ func ProcessWithdrawals(st state.BeaconState, executionData interfaces.Execution } if st.Version() >= version.Electra { - if err := st.DequeuePartialWithdrawals(processedPartialWithdrawalsCount); err != nil { + if err := st.DequeuePendingPartialWithdrawals(processedPartialWithdrawalsCount); err != nil { return nil, fmt.Errorf("unable to dequeue partial withdrawals from state: %w", err) } } diff --git a/beacon-chain/core/electra/deposits.go b/beacon-chain/core/electra/deposits.go index 098f2ceaf56..58fcbb3eee7 100644 --- a/beacon-chain/core/electra/deposits.go +++ b/beacon-chain/core/electra/deposits.go @@ -590,8 +590,8 @@ func processDepositRequest(beaconState state.BeaconState, request *enginev1.Depo } if err := beaconState.AppendPendingDeposit(ðpb.PendingDeposit{ PublicKey: bytesutil.SafeCopyBytes(request.Pubkey), - Amount: request.Amount, WithdrawalCredentials: bytesutil.SafeCopyBytes(request.WithdrawalCredentials), + Amount: request.Amount, Signature: bytesutil.SafeCopyBytes(request.Signature), Slot: beaconState.Slot(), }); err != nil { diff --git a/beacon-chain/core/electra/transition.go b/beacon-chain/core/electra/transition.go index 0f0111d5402..886de1fde0e 100644 --- a/beacon-chain/core/electra/transition.go +++ b/beacon-chain/core/electra/transition.go @@ -29,7 +29,6 @@ var ( ProcessParticipationFlagUpdates = altair.ProcessParticipationFlagUpdates ProcessSyncCommitteeUpdates = altair.ProcessSyncCommitteeUpdates AttestationsDelta = altair.AttestationsDelta - ProcessSyncAggregate = altair.ProcessSyncAggregate ) // ProcessEpoch describes the per epoch operations that are performed on the beacon state. diff --git a/beacon-chain/state/interfaces.go b/beacon-chain/state/interfaces.go index 7422c8d6de2..15b5544be80 100644 --- a/beacon-chain/state/interfaces.go +++ b/beacon-chain/state/interfaces.go @@ -316,7 +316,7 @@ type WriteOnlySyncCommittee interface { type WriteOnlyWithdrawals interface { AppendPendingPartialWithdrawal(ppw *ethpb.PendingPartialWithdrawal) error - DequeuePartialWithdrawals(num uint64) error + DequeuePendingPartialWithdrawals(num uint64) error SetNextWithdrawalIndex(i uint64) error SetNextWithdrawalValidatorIndex(i primitives.ValidatorIndex) error } diff --git a/beacon-chain/state/state-native/beacon_state.go b/beacon-chain/state/state-native/beacon_state.go index 576a6e2e7d0..83ed2ff84b5 100644 --- a/beacon-chain/state/state-native/beacon_state.go +++ b/beacon-chain/state/state-native/beacon_state.go @@ -29,7 +29,6 @@ type BeaconState struct { stateRoots customtypes.StateRoots stateRootsMultiValue *MultiValueStateRoots historicalRoots customtypes.HistoricalRoots - historicalSummaries []*ethpb.HistoricalSummary eth1Data *ethpb.Eth1Data eth1DataVotes []*ethpb.Eth1Data eth1DepositIndex uint64 @@ -55,8 +54,11 @@ type BeaconState struct { latestExecutionPayloadHeader *enginev1.ExecutionPayloadHeader latestExecutionPayloadHeaderCapella *enginev1.ExecutionPayloadHeaderCapella latestExecutionPayloadHeaderDeneb *enginev1.ExecutionPayloadHeaderDeneb - nextWithdrawalIndex uint64 - nextWithdrawalValidatorIndex primitives.ValidatorIndex + + // Capella fields + nextWithdrawalIndex uint64 + nextWithdrawalValidatorIndex primitives.ValidatorIndex + historicalSummaries []*ethpb.HistoricalSummary // Electra fields depositRequestsStartIndex uint64 @@ -90,7 +92,6 @@ type beaconStateMarshalable struct { BlockRoots customtypes.BlockRoots `json:"block_roots" yaml:"block_roots"` StateRoots customtypes.StateRoots `json:"state_roots" yaml:"state_roots"` HistoricalRoots customtypes.HistoricalRoots `json:"historical_roots" yaml:"historical_roots"` - HistoricalSummaries []*ethpb.HistoricalSummary `json:"historical_summaries" yaml:"historical_summaries"` Eth1Data *ethpb.Eth1Data `json:"eth_1_data" yaml:"eth_1_data"` Eth1DataVotes []*ethpb.Eth1Data `json:"eth_1_data_votes" yaml:"eth_1_data_votes"` Eth1DepositIndex uint64 `json:"eth_1_deposit_index" yaml:"eth_1_deposit_index"` @@ -114,6 +115,7 @@ type beaconStateMarshalable struct { LatestExecutionPayloadHeaderDeneb *enginev1.ExecutionPayloadHeaderDeneb `json:"latest_execution_payload_header_deneb" yaml:"latest_execution_payload_header_deneb"` NextWithdrawalIndex uint64 `json:"next_withdrawal_index" yaml:"next_withdrawal_index"` NextWithdrawalValidatorIndex primitives.ValidatorIndex `json:"next_withdrawal_validator_index" yaml:"next_withdrawal_validator_index"` + HistoricalSummaries []*ethpb.HistoricalSummary `json:"historical_summaries" yaml:"historical_summaries"` DepositRequestsStartIndex uint64 `json:"deposit_requests_start_index" yaml:"deposit_requests_start_index"` DepositBalanceToConsume primitives.Gwei `json:"deposit_balance_to_consume" yaml:"deposit_balance_to_consume"` ExitBalanceToConsume primitives.Gwei `json:"exit_balance_to_consume" yaml:"exit_balance_to_consume"` @@ -159,7 +161,6 @@ func (b *BeaconState) MarshalJSON() ([]byte, error) { BlockRoots: bRoots, StateRoots: sRoots, HistoricalRoots: b.historicalRoots, - HistoricalSummaries: b.historicalSummaries, Eth1Data: b.eth1Data, Eth1DataVotes: b.eth1DataVotes, Eth1DepositIndex: b.eth1DepositIndex, @@ -183,6 +184,7 @@ func (b *BeaconState) MarshalJSON() ([]byte, error) { LatestExecutionPayloadHeaderDeneb: b.latestExecutionPayloadHeaderDeneb, NextWithdrawalIndex: b.nextWithdrawalIndex, NextWithdrawalValidatorIndex: b.nextWithdrawalValidatorIndex, + HistoricalSummaries: b.historicalSummaries, DepositRequestsStartIndex: b.depositRequestsStartIndex, DepositBalanceToConsume: b.depositBalanceToConsume, ExitBalanceToConsume: b.exitBalanceToConsume, diff --git a/beacon-chain/state/state-native/setters_consolidation.go b/beacon-chain/state/state-native/setters_consolidation.go index d814832dd72..0caa85d6959 100644 --- a/beacon-chain/state/state-native/setters_consolidation.go +++ b/beacon-chain/state/state-native/setters_consolidation.go @@ -1,6 +1,8 @@ package state_native import ( + "errors" + "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native/types" "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/stateutil" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" @@ -15,6 +17,9 @@ func (b *BeaconState) AppendPendingConsolidation(val *ethpb.PendingConsolidation if b.version < version.Electra { return errNotSupported("AppendPendingConsolidation", b.version) } + if val == nil { + return errors.New("cannot append nil pending consolidation") + } b.lock.Lock() defer b.lock.Unlock() diff --git a/beacon-chain/state/state-native/setters_deposits.go b/beacon-chain/state/state-native/setters_deposits.go index d4ea73ccd9c..b64901dc7c1 100644 --- a/beacon-chain/state/state-native/setters_deposits.go +++ b/beacon-chain/state/state-native/setters_deposits.go @@ -1,6 +1,8 @@ package state_native import ( + "errors" + "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native/types" "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/stateutil" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" @@ -15,6 +17,9 @@ func (b *BeaconState) AppendPendingDeposit(pd *ethpb.PendingDeposit) error { if b.version < version.Electra { return errNotSupported("AppendPendingDeposit", b.version) } + if pd == nil { + return errors.New("cannot append nil pending deposit") + } b.lock.Lock() defer b.lock.Unlock() diff --git a/beacon-chain/state/state-native/setters_withdrawal.go b/beacon-chain/state/state-native/setters_withdrawal.go index 36b97a82676..37cfe600606 100644 --- a/beacon-chain/state/state-native/setters_withdrawal.go +++ b/beacon-chain/state/state-native/setters_withdrawal.go @@ -64,10 +64,10 @@ func (b *BeaconState) AppendPendingPartialWithdrawal(ppw *eth.PendingPartialWith return nil } -// DequeuePartialWithdrawals removes the partial withdrawals from the beginning of the partial withdrawals list. -func (b *BeaconState) DequeuePartialWithdrawals(n uint64) error { +// DequeuePendingPartialWithdrawals removes the partial withdrawals from the beginning of the partial withdrawals list. +func (b *BeaconState) DequeuePendingPartialWithdrawals(n uint64) error { if b.version < version.Electra { - return errNotSupported("DequeuePartialWithdrawals", b.version) + return errNotSupported("DequeuePendingPartialWithdrawals", b.version) } if n > uint64(len(b.pendingPartialWithdrawals)) { diff --git a/beacon-chain/state/state-native/setters_withdrawal_test.go b/beacon-chain/state/state-native/setters_withdrawal_test.go index d7627d39754..b2e2e5b119c 100644 --- a/beacon-chain/state/state-native/setters_withdrawal_test.go +++ b/beacon-chain/state/state-native/setters_withdrawal_test.go @@ -68,7 +68,7 @@ func TestDequeuePendingWithdrawals(t *testing.T) { num, err := s.NumPendingPartialWithdrawals() require.NoError(t, err) require.Equal(t, uint64(3), num) - require.NoError(t, s.DequeuePartialWithdrawals(2)) + require.NoError(t, s.DequeuePendingPartialWithdrawals(2)) num, err = s.NumPendingPartialWithdrawals() require.NoError(t, err) require.Equal(t, uint64(1), num) @@ -77,13 +77,13 @@ func TestDequeuePendingWithdrawals(t *testing.T) { num, err = s.NumPendingPartialWithdrawals() require.NoError(t, err) require.Equal(t, uint64(1), num) - require.ErrorContains(t, "cannot dequeue more withdrawals than are in the queue", s.DequeuePartialWithdrawals(2)) + require.ErrorContains(t, "cannot dequeue more withdrawals than are in the queue", s.DequeuePendingPartialWithdrawals(2)) // Removing all pending partial withdrawals should be OK. num, err = s.NumPendingPartialWithdrawals() require.NoError(t, err) require.Equal(t, uint64(1), num) - require.NoError(t, s.DequeuePartialWithdrawals(1)) + require.NoError(t, s.DequeuePendingPartialWithdrawals(1)) num, err = s.Copy().NumPendingPartialWithdrawals() require.NoError(t, err) require.Equal(t, uint64(0), num) @@ -91,7 +91,7 @@ func TestDequeuePendingWithdrawals(t *testing.T) { s, err = InitializeFromProtoDeneb(ð.BeaconStateDeneb{}) require.NoError(t, err) - require.ErrorContains(t, "is not supported", s.DequeuePartialWithdrawals(0)) + require.ErrorContains(t, "is not supported", s.DequeuePendingPartialWithdrawals(0)) } func TestAppendPendingWithdrawals(t *testing.T) { diff --git a/beacon-chain/state/state-native/spec_parameters.go b/beacon-chain/state/state-native/spec_parameters.go index 1612a71efbd..7c955e92c1d 100644 --- a/beacon-chain/state/state-native/spec_parameters.go +++ b/beacon-chain/state/state-native/spec_parameters.go @@ -14,7 +14,7 @@ func (b *BeaconState) ProportionalSlashingMultiplier() (uint64, error) { case version.Phase0: return params.BeaconConfig().ProportionalSlashingMultiplier, nil } - return 0, errNotSupported("ProportionalSlashingMultiplier()", b.version) + return 0, errNotSupported("ProportionalSlashingMultiplier", b.version) } func (b *BeaconState) InactivityPenaltyQuotient() (uint64, error) { @@ -26,5 +26,5 @@ func (b *BeaconState) InactivityPenaltyQuotient() (uint64, error) { case version.Phase0: return params.BeaconConfig().InactivityPenaltyQuotient, nil } - return 0, errNotSupported("InactivityPenaltyQuotient()", b.version) + return 0, errNotSupported("InactivityPenaltyQuotient", b.version) } diff --git a/beacon-chain/state/state-native/state_trie.go b/beacon-chain/state/state-native/state_trie.go index a5270f53342..66f2fbf89d8 100644 --- a/beacon-chain/state/state-native/state_trie.go +++ b/beacon-chain/state/state-native/state_trie.go @@ -96,10 +96,10 @@ var denebFields = append( var electraFields = append( altairFields, + types.LatestExecutionPayloadHeaderDeneb, types.NextWithdrawalIndex, types.NextWithdrawalValidatorIndex, types.HistoricalSummaries, - types.LatestExecutionPayloadHeaderDeneb, types.DepositRequestsStartIndex, types.DepositBalanceToConsume, types.ExitBalanceToConsume,