mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-08 02:31:19 +00:00
77a9dca9eb
* e2e using dynamic configs; runtime bellatrix setup * starts from phase0 but fee recipient eval fails * lower TTD to cross before bellatrix epoch in e2e * fix debug printf * fix it * dynamic ttd and more robust fee_recipient eval * let multiplication set ttd=0 if bellatrix epoch=0 * refactoring fee recipient test after cognit errors * lint * appease deepsource * deep sourcin * gazelle * missed a usage of this when refactoring * refactoring premine genesis to work for all forks previous set of functions was a copypasta mess * gaz post-merge * gaz * resolve merge artifact and pr feedback * back out some unneeded changes * appease deepsource * move premine-state next to similar utils Co-authored-by: Kasey Kirkham <kasey@users.noreply.github.com> Co-authored-by: nisdas <nishdas93@gmail.com>
126 lines
4.5 KiB
Go
126 lines
4.5 KiB
Go
package state_native
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
nativetypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native/types"
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil"
|
|
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/v3/runtime/version"
|
|
)
|
|
|
|
// RotateAttestations sets the previous epoch attestations to the current epoch attestations and
|
|
// then clears the current epoch attestations.
|
|
func (b *BeaconState) RotateAttestations() error {
|
|
b.lock.Lock()
|
|
defer b.lock.Unlock()
|
|
|
|
if b.version != version.Phase0 {
|
|
return errNotSupported("RotateAttestations", b.version)
|
|
}
|
|
|
|
b.setPreviousEpochAttestations(b.currentEpochAttestationsVal())
|
|
b.setCurrentEpochAttestations([]*ethpb.PendingAttestation{})
|
|
return nil
|
|
}
|
|
|
|
func (b *BeaconState) setPreviousEpochAttestations(val []*ethpb.PendingAttestation) {
|
|
b.sharedFieldReferences[nativetypes.PreviousEpochAttestations].MinusRef()
|
|
b.sharedFieldReferences[nativetypes.PreviousEpochAttestations] = stateutil.NewRef(1)
|
|
|
|
b.previousEpochAttestations = val
|
|
b.markFieldAsDirty(nativetypes.PreviousEpochAttestations)
|
|
b.rebuildTrie[nativetypes.PreviousEpochAttestations] = true
|
|
}
|
|
|
|
func (b *BeaconState) setCurrentEpochAttestations(val []*ethpb.PendingAttestation) {
|
|
b.sharedFieldReferences[nativetypes.CurrentEpochAttestations].MinusRef()
|
|
b.sharedFieldReferences[nativetypes.CurrentEpochAttestations] = stateutil.NewRef(1)
|
|
|
|
b.currentEpochAttestations = val
|
|
b.markFieldAsDirty(nativetypes.CurrentEpochAttestations)
|
|
b.rebuildTrie[nativetypes.CurrentEpochAttestations] = true
|
|
}
|
|
|
|
// AppendCurrentEpochAttestations for the beacon state. Appends the new value
|
|
// to the the end of list.
|
|
func (b *BeaconState) AppendCurrentEpochAttestations(val *ethpb.PendingAttestation) error {
|
|
b.lock.Lock()
|
|
defer b.lock.Unlock()
|
|
|
|
if b.version != version.Phase0 {
|
|
return errNotSupported("AppendCurrentEpochAttestations", b.version)
|
|
}
|
|
|
|
atts := b.currentEpochAttestations
|
|
max := uint64(fieldparams.CurrentEpochAttestationsLength)
|
|
if uint64(len(atts)) >= max {
|
|
return fmt.Errorf("current pending attestation exceeds max length %d", max)
|
|
}
|
|
|
|
if b.sharedFieldReferences[nativetypes.CurrentEpochAttestations].Refs() > 1 {
|
|
// Copy elements in underlying array by reference.
|
|
atts = make([]*ethpb.PendingAttestation, len(b.currentEpochAttestations))
|
|
copy(atts, b.currentEpochAttestations)
|
|
b.sharedFieldReferences[nativetypes.CurrentEpochAttestations].MinusRef()
|
|
b.sharedFieldReferences[nativetypes.CurrentEpochAttestations] = stateutil.NewRef(1)
|
|
}
|
|
|
|
b.currentEpochAttestations = append(atts, val)
|
|
b.markFieldAsDirty(nativetypes.CurrentEpochAttestations)
|
|
b.addDirtyIndices(nativetypes.CurrentEpochAttestations, []uint64{uint64(len(b.currentEpochAttestations) - 1)})
|
|
return nil
|
|
}
|
|
|
|
// AppendPreviousEpochAttestations for the beacon state. Appends the new value
|
|
// to the the end of list.
|
|
func (b *BeaconState) AppendPreviousEpochAttestations(val *ethpb.PendingAttestation) error {
|
|
b.lock.Lock()
|
|
defer b.lock.Unlock()
|
|
|
|
if b.version != version.Phase0 {
|
|
return errNotSupported("AppendPreviousEpochAttestations", b.version)
|
|
}
|
|
|
|
atts := b.previousEpochAttestations
|
|
max := uint64(fieldparams.PreviousEpochAttestationsLength)
|
|
if uint64(len(atts)) >= max {
|
|
return fmt.Errorf("previous pending attestation exceeds max length %d", max)
|
|
}
|
|
|
|
if b.sharedFieldReferences[nativetypes.PreviousEpochAttestations].Refs() > 1 {
|
|
atts = make([]*ethpb.PendingAttestation, len(b.previousEpochAttestations))
|
|
copy(atts, b.previousEpochAttestations)
|
|
b.sharedFieldReferences[nativetypes.PreviousEpochAttestations].MinusRef()
|
|
b.sharedFieldReferences[nativetypes.PreviousEpochAttestations] = stateutil.NewRef(1)
|
|
}
|
|
|
|
b.previousEpochAttestations = append(atts, val)
|
|
b.markFieldAsDirty(nativetypes.PreviousEpochAttestations)
|
|
b.addDirtyIndices(nativetypes.PreviousEpochAttestations, []uint64{uint64(len(b.previousEpochAttestations) - 1)})
|
|
return nil
|
|
}
|
|
|
|
func (b *BeaconState) SetPreviousEpochAttestations(a []*ethpb.PendingAttestation) error {
|
|
b.lock.Lock()
|
|
defer b.lock.Unlock()
|
|
|
|
if b.version != version.Phase0 {
|
|
return errNotSupported("SetPreviousEpochAttestations", b.version)
|
|
}
|
|
b.setPreviousEpochAttestations(a)
|
|
return nil
|
|
}
|
|
|
|
func (b *BeaconState) SetCurrentEpochAttestations(a []*ethpb.PendingAttestation) error {
|
|
b.lock.Lock()
|
|
defer b.lock.Unlock()
|
|
|
|
if b.version != version.Phase0 {
|
|
return errNotSupported("SetCurrentEpochAttestations", b.version)
|
|
}
|
|
b.setCurrentEpochAttestations(a)
|
|
return nil
|
|
}
|