2022-05-09 13:02:34 +00:00
|
|
|
package state_native
|
2022-01-13 11:23:53 +00:00
|
|
|
|
|
|
|
import (
|
2023-03-17 18:52:56 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v4/beacon-chain/state/state-native/types"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/beacon-chain/state/stateutil"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
2022-01-13 11:23:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// SetEth1Data for the beacon state.
|
|
|
|
func (b *BeaconState) SetEth1Data(val *ethpb.Eth1Data) error {
|
|
|
|
b.lock.Lock()
|
|
|
|
defer b.lock.Unlock()
|
|
|
|
|
2022-02-01 00:32:39 +00:00
|
|
|
b.eth1Data = val
|
2023-01-26 14:40:12 +00:00
|
|
|
b.markFieldAsDirty(types.Eth1Data)
|
2022-01-13 11:23:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetEth1DataVotes for the beacon state. Updates the entire
|
|
|
|
// list to a new value by overwriting the previous one.
|
|
|
|
func (b *BeaconState) SetEth1DataVotes(val []*ethpb.Eth1Data) error {
|
|
|
|
b.lock.Lock()
|
|
|
|
defer b.lock.Unlock()
|
|
|
|
|
2023-01-26 14:40:12 +00:00
|
|
|
b.sharedFieldReferences[types.Eth1DataVotes].MinusRef()
|
|
|
|
b.sharedFieldReferences[types.Eth1DataVotes] = stateutil.NewRef(1)
|
2022-01-13 11:23:53 +00:00
|
|
|
|
2022-02-01 00:32:39 +00:00
|
|
|
b.eth1DataVotes = val
|
2023-01-26 14:40:12 +00:00
|
|
|
b.markFieldAsDirty(types.Eth1DataVotes)
|
|
|
|
b.rebuildTrie[types.Eth1DataVotes] = true
|
2022-01-13 11:23:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetEth1DepositIndex for the beacon state.
|
|
|
|
func (b *BeaconState) SetEth1DepositIndex(val uint64) error {
|
|
|
|
b.lock.Lock()
|
|
|
|
defer b.lock.Unlock()
|
|
|
|
|
2022-02-01 00:32:39 +00:00
|
|
|
b.eth1DepositIndex = val
|
2023-01-26 14:40:12 +00:00
|
|
|
b.markFieldAsDirty(types.Eth1DepositIndex)
|
2022-01-13 11:23:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// AppendEth1DataVotes for the beacon state. Appends the new value
|
|
|
|
// to the the end of list.
|
|
|
|
func (b *BeaconState) AppendEth1DataVotes(val *ethpb.Eth1Data) error {
|
|
|
|
b.lock.Lock()
|
|
|
|
defer b.lock.Unlock()
|
|
|
|
|
2022-02-01 00:32:39 +00:00
|
|
|
votes := b.eth1DataVotes
|
2023-01-26 14:40:12 +00:00
|
|
|
if b.sharedFieldReferences[types.Eth1DataVotes].Refs() > 1 {
|
2022-01-13 11:23:53 +00:00
|
|
|
// Copy elements in underlying array by reference.
|
2022-02-01 00:32:39 +00:00
|
|
|
votes = make([]*ethpb.Eth1Data, len(b.eth1DataVotes))
|
|
|
|
copy(votes, b.eth1DataVotes)
|
2023-01-26 14:40:12 +00:00
|
|
|
b.sharedFieldReferences[types.Eth1DataVotes].MinusRef()
|
|
|
|
b.sharedFieldReferences[types.Eth1DataVotes] = stateutil.NewRef(1)
|
2022-01-13 11:23:53 +00:00
|
|
|
}
|
|
|
|
|
2022-02-01 00:32:39 +00:00
|
|
|
b.eth1DataVotes = append(votes, val)
|
2023-01-26 14:40:12 +00:00
|
|
|
b.markFieldAsDirty(types.Eth1DataVotes)
|
|
|
|
b.addDirtyIndices(types.Eth1DataVotes, []uint64{uint64(len(b.eth1DataVotes) - 1)})
|
2022-01-13 11:23:53 +00:00
|
|
|
return nil
|
|
|
|
}
|