mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 23:48:06 -05:00
* Electra: Beacon State * Electra: Beacon state fixes from PR 13919 * Add missing tests - part 1 * Split eip_7251_root.go into different files and reuse/share code with historical state summaries root. It's identical! * Add missing tests - part 2 * deposit receipts start index getters and setters (#13947) * adding in getters and setters for deposit receipts start index * adding tests * gaz * Add missing tests - part 3 of 3 Update the electra withdrawal example with a ssz state containing pending partial withdrawals * add tests for beacon-chain/state/state-native/getters_balance_deposits.go * Add electra field to testing/util/block.go execution payload * godoc commentary on public methods * Fix failing test * Add balances index out of bounds check and relevant tests. * Revert switch case electra * Instead of copying spectest data into testdata, use the spectest dependency * Deepsource fixes * Address @rkapka PR feedback * s/MaxPendingPartialsPerWithdrawalSweep/MaxPendingPartialsPerWithdrawalsSweep/ * Use multivalue slice compatible accessors for validator and balance in ActiveBalanceAtIndex * More @rkapka feedback. What a great reviewer! * More tests for branching logic in ExitEpochAndUpdateChurn * fix build --------- Co-authored-by: james-prysm <90280386+james-prysm@users.noreply.github.com>
94 lines
2.9 KiB
Go
94 lines
2.9 KiB
Go
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"
|
|
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/v5/runtime/version"
|
|
)
|
|
|
|
// SetNextWithdrawalIndex sets the index that will be assigned to the next withdrawal.
|
|
func (b *BeaconState) SetNextWithdrawalIndex(i uint64) error {
|
|
if b.version < version.Capella {
|
|
return errNotSupported("SetNextWithdrawalIndex", b.version)
|
|
}
|
|
|
|
b.lock.Lock()
|
|
defer b.lock.Unlock()
|
|
|
|
b.nextWithdrawalIndex = i
|
|
b.markFieldAsDirty(types.NextWithdrawalIndex)
|
|
return nil
|
|
}
|
|
|
|
// SetNextWithdrawalValidatorIndex sets the index of the validator which is
|
|
// next in line for a partial withdrawal.
|
|
func (b *BeaconState) SetNextWithdrawalValidatorIndex(i primitives.ValidatorIndex) error {
|
|
if b.version < version.Capella {
|
|
return errNotSupported("SetNextWithdrawalValidatorIndex", b.version)
|
|
}
|
|
|
|
b.lock.Lock()
|
|
defer b.lock.Unlock()
|
|
|
|
b.nextWithdrawalValidatorIndex = i
|
|
b.markFieldAsDirty(types.NextWithdrawalValidatorIndex)
|
|
return nil
|
|
}
|
|
|
|
// AppendPendingPartialWithdrawal is a mutating call to the beacon state which appends the given
|
|
// value to the end of the pending partial withdrawals slice in the state. This method requires
|
|
// access to the Lock on the state and only applies in electra or later.
|
|
func (b *BeaconState) AppendPendingPartialWithdrawal(ppw *eth.PendingPartialWithdrawal) error {
|
|
if b.version < version.Electra {
|
|
return errNotSupported("AppendPendingPartialWithdrawal", b.version)
|
|
}
|
|
|
|
if ppw == nil {
|
|
return errors.New("cannot append nil pending partial withdrawal")
|
|
}
|
|
|
|
b.lock.Lock()
|
|
defer b.lock.Unlock()
|
|
|
|
b.sharedFieldReferences[types.PendingPartialWithdrawals].MinusRef()
|
|
b.sharedFieldReferences[types.PendingPartialWithdrawals] = stateutil.NewRef(1)
|
|
|
|
b.pendingPartialWithdrawals = append(b.pendingPartialWithdrawals, ppw)
|
|
|
|
b.markFieldAsDirty(types.PendingPartialWithdrawals)
|
|
b.rebuildTrie[types.PendingPartialWithdrawals] = true
|
|
return nil
|
|
}
|
|
|
|
// DequeuePartialWithdrawals removes the partial withdrawals from the beginning of the partial withdrawals list.
|
|
func (b *BeaconState) DequeuePartialWithdrawals(n uint64) error {
|
|
if b.version < version.Electra {
|
|
return errNotSupported("DequeuePartialWithdrawals", b.version)
|
|
}
|
|
|
|
if n > uint64(len(b.pendingPartialWithdrawals)) {
|
|
return errors.New("cannot dequeue more withdrawals than are in the queue")
|
|
}
|
|
|
|
if n == 0 {
|
|
return nil // Don't wait on a lock for no reason.
|
|
}
|
|
|
|
b.lock.Lock()
|
|
defer b.lock.Unlock()
|
|
|
|
b.sharedFieldReferences[types.PendingPartialWithdrawals].MinusRef()
|
|
b.sharedFieldReferences[types.PendingPartialWithdrawals] = stateutil.NewRef(1)
|
|
|
|
b.pendingPartialWithdrawals = b.pendingPartialWithdrawals[n:]
|
|
|
|
b.markFieldAsDirty(types.PendingPartialWithdrawals)
|
|
b.rebuildTrie[types.PendingPartialWithdrawals] = true
|
|
|
|
return nil
|
|
}
|