github.com/prysmaticlabs/prysm@v1.4.4/beacon-chain/state/v1/getters_randao.go (about) 1 package v1 2 3 // RandaoMixes of block proposers on the beacon chain. 4 func (b *BeaconState) RandaoMixes() [][]byte { 5 if !b.hasInnerState() { 6 return nil 7 } 8 if b.state.RandaoMixes == nil { 9 return nil 10 } 11 12 b.lock.RLock() 13 defer b.lock.RUnlock() 14 15 return b.randaoMixes() 16 } 17 18 // randaoMixes of block proposers on the beacon chain. 19 // This assumes that a lock is already held on BeaconState. 20 func (b *BeaconState) randaoMixes() [][]byte { 21 if !b.hasInnerState() { 22 return nil 23 } 24 25 return b.safeCopy2DByteSlice(b.state.RandaoMixes) 26 } 27 28 // RandaoMixAtIndex retrieves a specific block root based on an 29 // input index value. 30 func (b *BeaconState) RandaoMixAtIndex(idx uint64) ([]byte, error) { 31 if !b.hasInnerState() { 32 return nil, ErrNilInnerState 33 } 34 if b.state.RandaoMixes == nil { 35 return nil, nil 36 } 37 38 b.lock.RLock() 39 defer b.lock.RUnlock() 40 41 return b.randaoMixAtIndex(idx) 42 } 43 44 // randaoMixAtIndex retrieves a specific block root based on an 45 // input index value. 46 // This assumes that a lock is already held on BeaconState. 47 func (b *BeaconState) randaoMixAtIndex(idx uint64) ([]byte, error) { 48 if !b.hasInnerState() { 49 return nil, ErrNilInnerState 50 } 51 52 return b.safeCopyBytesAtIndex(b.state.RandaoMixes, idx) 53 } 54 55 // RandaoMixesLength returns the length of the randao mixes slice. 56 func (b *BeaconState) RandaoMixesLength() int { 57 if !b.hasInnerState() { 58 return 0 59 } 60 if b.state.RandaoMixes == nil { 61 return 0 62 } 63 64 b.lock.RLock() 65 defer b.lock.RUnlock() 66 67 return b.randaoMixesLength() 68 } 69 70 // randaoMixesLength returns the length of the randao mixes slice. 71 // This assumes that a lock is already held on BeaconState. 72 func (b *BeaconState) randaoMixesLength() int { 73 if !b.hasInnerState() { 74 return 0 75 } 76 if b.state.RandaoMixes == nil { 77 return 0 78 } 79 80 return len(b.state.RandaoMixes) 81 }