2022-05-09 13:02:34 +00:00
|
|
|
package state_native
|
2022-01-13 11:23:53 +00:00
|
|
|
|
|
|
|
import (
|
2022-08-16 12:20:13 +00:00
|
|
|
nativetypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native/types"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stateutil"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/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
|
2022-05-09 13:02:34 +00:00
|
|
|
b.markFieldAsDirty(nativetypes.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()
|
|
|
|
|
2022-05-09 13:02:34 +00:00
|
|
|
b.sharedFieldReferences[nativetypes.Eth1DataVotes].MinusRef()
|
|
|
|
b.sharedFieldReferences[nativetypes.Eth1DataVotes] = stateutil.NewRef(1)
|
2022-01-13 11:23:53 +00:00
|
|
|
|
2022-02-01 00:32:39 +00:00
|
|
|
b.eth1DataVotes = val
|
2022-05-09 13:02:34 +00:00
|
|
|
b.markFieldAsDirty(nativetypes.Eth1DataVotes)
|
|
|
|
b.rebuildTrie[nativetypes.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
|
2022-05-09 13:02:34 +00:00
|
|
|
b.markFieldAsDirty(nativetypes.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
|
2022-05-09 13:02:34 +00:00
|
|
|
if b.sharedFieldReferences[nativetypes.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)
|
2022-05-09 13:02:34 +00:00
|
|
|
b.sharedFieldReferences[nativetypes.Eth1DataVotes].MinusRef()
|
|
|
|
b.sharedFieldReferences[nativetypes.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)
|
2022-05-09 13:02:34 +00:00
|
|
|
b.markFieldAsDirty(nativetypes.Eth1DataVotes)
|
|
|
|
b.addDirtyIndices(nativetypes.Eth1DataVotes, []uint64{uint64(len(b.eth1DataVotes) - 1)})
|
2022-01-13 11:23:53 +00:00
|
|
|
return nil
|
|
|
|
}
|