github.com/prysmaticlabs/prysm@v1.4.4/beacon-chain/state/v1/setters_eth1.go (about) 1 package v1 2 3 import ( 4 "github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil" 5 ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1" 6 ) 7 8 // SetEth1Data for the beacon state. 9 func (b *BeaconState) SetEth1Data(val *ethpb.Eth1Data) error { 10 if !b.hasInnerState() { 11 return ErrNilInnerState 12 } 13 b.lock.Lock() 14 defer b.lock.Unlock() 15 16 b.state.Eth1Data = val 17 b.markFieldAsDirty(eth1Data) 18 return nil 19 } 20 21 // SetEth1DataVotes for the beacon state. Updates the entire 22 // list to a new value by overwriting the previous one. 23 func (b *BeaconState) SetEth1DataVotes(val []*ethpb.Eth1Data) error { 24 if !b.hasInnerState() { 25 return ErrNilInnerState 26 } 27 b.lock.Lock() 28 defer b.lock.Unlock() 29 30 b.sharedFieldReferences[eth1DataVotes].MinusRef() 31 b.sharedFieldReferences[eth1DataVotes] = stateutil.NewRef(1) 32 33 b.state.Eth1DataVotes = val 34 b.markFieldAsDirty(eth1DataVotes) 35 b.rebuildTrie[eth1DataVotes] = true 36 return nil 37 } 38 39 // SetEth1DepositIndex for the beacon state. 40 func (b *BeaconState) SetEth1DepositIndex(val uint64) error { 41 if !b.hasInnerState() { 42 return ErrNilInnerState 43 } 44 b.lock.Lock() 45 defer b.lock.Unlock() 46 47 b.state.Eth1DepositIndex = val 48 b.markFieldAsDirty(eth1DepositIndex) 49 return nil 50 } 51 52 // AppendEth1DataVotes for the beacon state. Appends the new value 53 // to the the end of list. 54 func (b *BeaconState) AppendEth1DataVotes(val *ethpb.Eth1Data) error { 55 if !b.hasInnerState() { 56 return ErrNilInnerState 57 } 58 b.lock.Lock() 59 defer b.lock.Unlock() 60 61 votes := b.state.Eth1DataVotes 62 if b.sharedFieldReferences[eth1DataVotes].Refs() > 1 { 63 // Copy elements in underlying array by reference. 64 votes = make([]*ethpb.Eth1Data, len(b.state.Eth1DataVotes)) 65 copy(votes, b.state.Eth1DataVotes) 66 b.sharedFieldReferences[eth1DataVotes].MinusRef() 67 b.sharedFieldReferences[eth1DataVotes] = stateutil.NewRef(1) 68 } 69 70 b.state.Eth1DataVotes = append(votes, val) 71 b.markFieldAsDirty(eth1DataVotes) 72 b.addDirtyIndices(eth1DataVotes, []uint64{uint64(len(b.state.Eth1DataVotes) - 1)}) 73 return nil 74 }