mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47:18 +00:00
d077483577
* v3 import renamings * tidy * fmt * rev * Update beacon-chain/core/epoch/precompute/reward_penalty_test.go * Update beacon-chain/core/helpers/validators_test.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/iface/BUILD.bazel * Update beacon-chain/db/kv/kv.go * Update beacon-chain/db/kv/state.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/sync/initial-sync/service.go * fix deps * fix bad replacements * fix bad replacements * change back * gohashtree version * fix deps Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com>
69 lines
2.1 KiB
Go
69 lines
2.1 KiB
Go
package state_native
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
customtypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native/custom-types"
|
|
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"
|
|
)
|
|
|
|
// SetLatestBlockHeader in the beacon state.
|
|
func (b *BeaconState) SetLatestBlockHeader(val *ethpb.BeaconBlockHeader) error {
|
|
b.lock.Lock()
|
|
defer b.lock.Unlock()
|
|
|
|
b.latestBlockHeader = ethpb.CopyBeaconBlockHeader(val)
|
|
b.markFieldAsDirty(nativetypes.LatestBlockHeader)
|
|
return nil
|
|
}
|
|
|
|
// SetBlockRoots for the beacon state. Updates the entire
|
|
// list to a new value by overwriting the previous one.
|
|
func (b *BeaconState) SetBlockRoots(val [][]byte) error {
|
|
b.lock.Lock()
|
|
defer b.lock.Unlock()
|
|
|
|
b.sharedFieldReferences[nativetypes.BlockRoots].MinusRef()
|
|
b.sharedFieldReferences[nativetypes.BlockRoots] = stateutil.NewRef(1)
|
|
|
|
var rootsArr [fieldparams.BlockRootsLength][32]byte
|
|
for i := 0; i < len(rootsArr); i++ {
|
|
copy(rootsArr[i][:], val[i])
|
|
}
|
|
roots := customtypes.BlockRoots(rootsArr)
|
|
b.blockRoots = &roots
|
|
b.markFieldAsDirty(nativetypes.BlockRoots)
|
|
b.rebuildTrie[nativetypes.BlockRoots] = true
|
|
return nil
|
|
}
|
|
|
|
// UpdateBlockRootAtIndex for the beacon state. Updates the block root
|
|
// at a specific index to a new value.
|
|
func (b *BeaconState) UpdateBlockRootAtIndex(idx uint64, blockRoot [32]byte) error {
|
|
if uint64(len(b.blockRoots)) <= idx {
|
|
return fmt.Errorf("invalid index provided %d", idx)
|
|
}
|
|
b.lock.Lock()
|
|
defer b.lock.Unlock()
|
|
|
|
r := b.blockRoots
|
|
if ref := b.sharedFieldReferences[nativetypes.BlockRoots]; ref.Refs() > 1 {
|
|
// Copy elements in underlying array by reference.
|
|
roots := *b.blockRoots
|
|
rootsCopy := roots
|
|
r = &rootsCopy
|
|
ref.MinusRef()
|
|
b.sharedFieldReferences[nativetypes.BlockRoots] = stateutil.NewRef(1)
|
|
}
|
|
|
|
r[idx] = blockRoot
|
|
b.blockRoots = r
|
|
|
|
b.markFieldAsDirty(nativetypes.BlockRoots)
|
|
b.addDirtyIndices(nativetypes.BlockRoots, []uint64{idx})
|
|
return nil
|
|
}
|