Files
prysm/beacon-chain/state/state-native/setters_consolidation.go
Preston Van Loon 9b2934f1f6 Electra: BeaconState implementation (#13919)
* 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>
2024-05-06 18:04:33 +00:00

85 lines
3.1 KiB
Go

package state_native
import (
"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"
"github.com/prysmaticlabs/prysm/v5/math"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
)
// AppendPendingConsolidation is a mutating call to the beacon state which appends the provided
// pending consolidation to the end of the slice on the state. This method requires access to the
// Lock on the state and only applies in electra or later.
func (b *BeaconState) AppendPendingConsolidation(val *ethpb.PendingConsolidation) error {
if b.version < version.Electra {
return errNotSupported("AppendPendingConsolidation", b.version)
}
b.lock.Lock()
defer b.lock.Unlock()
b.sharedFieldReferences[types.PendingConsolidations].MinusRef()
b.sharedFieldReferences[types.PendingConsolidations] = stateutil.NewRef(1)
b.pendingConsolidations = append(b.pendingConsolidations, val)
b.markFieldAsDirty(types.PendingConsolidations)
b.rebuildTrie[types.PendingConsolidations] = true
return nil
}
// SetPendingConsolidations is a mutating call to the beacon state which replaces the slice on the
// state with the given value. This method requires access to the Lock on the state and only applies
// in electra or later.
func (b *BeaconState) SetPendingConsolidations(val []*ethpb.PendingConsolidation) error {
if b.version < version.Electra {
return errNotSupported("SetPendingConsolidations", b.version)
}
b.lock.Lock()
defer b.lock.Unlock()
b.sharedFieldReferences[types.PendingConsolidations].MinusRef()
b.sharedFieldReferences[types.PendingConsolidations] = stateutil.NewRef(1)
b.pendingConsolidations = val
b.markFieldAsDirty(types.PendingConsolidations)
b.rebuildTrie[types.PendingConsolidations] = true
return nil
}
// SetEarliestConsolidationEpoch is a mutating call to the beacon state which sets the earlest
// consolidation epoch value. This method requires access to the Lock on the state and only applies
// in electra or later.
func (b *BeaconState) SetEarliestConsolidationEpoch(epoch primitives.Epoch) error {
if b.version < version.Electra {
return errNotSupported("SetEarliestConsolidationEpoch", b.version)
}
b.lock.Lock()
defer b.lock.Unlock()
b.earliestConsolidationEpoch = epoch
b.markFieldAsDirty(types.EarliestConsolidationEpoch)
b.rebuildTrie[types.EarliestConsolidationEpoch] = true
return nil
}
// SetConsolidationBalanceToConsume is a mutating call to the beacon state which sets the value of
// the consolidation balance to consume to the provided value. This method requires access to the
// Lock on the state and only applies in electra or later.
func (b *BeaconState) SetConsolidationBalanceToConsume(balance math.Gwei) error {
if b.version < version.Electra {
return errNotSupported("SetConsolidationBalanceToConsume", b.version)
}
b.lock.Lock()
defer b.lock.Unlock()
b.consolidationBalanceToConsume = balance
b.markFieldAsDirty(types.ConsolidationBalanceToConsume)
b.rebuildTrie[types.ConsolidationBalanceToConsume] = true
return nil
}