2021-06-30 15:06:19 +00:00
|
|
|
package v1
|
2021-04-12 14:23:55 +00:00
|
|
|
|
2021-08-23 16:53:50 +00:00
|
|
|
import (
|
2021-09-23 15:23:37 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
2021-08-23 16:53:50 +00:00
|
|
|
)
|
|
|
|
|
2021-04-12 14:23:55 +00:00
|
|
|
// RandaoMixes of block proposers on the beacon chain.
|
|
|
|
func (b *BeaconState) RandaoMixes() [][]byte {
|
|
|
|
if !b.hasInnerState() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if b.state.RandaoMixes == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
b.lock.RLock()
|
|
|
|
defer b.lock.RUnlock()
|
|
|
|
|
|
|
|
return b.randaoMixes()
|
|
|
|
}
|
|
|
|
|
|
|
|
// randaoMixes of block proposers on the beacon chain.
|
|
|
|
// This assumes that a lock is already held on BeaconState.
|
|
|
|
func (b *BeaconState) randaoMixes() [][]byte {
|
|
|
|
if !b.hasInnerState() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-08-23 16:53:50 +00:00
|
|
|
return bytesutil.SafeCopy2dBytes(b.state.RandaoMixes)
|
2021-04-12 14:23:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RandaoMixAtIndex retrieves a specific block root based on an
|
|
|
|
// input index value.
|
|
|
|
func (b *BeaconState) RandaoMixAtIndex(idx uint64) ([]byte, error) {
|
|
|
|
if !b.hasInnerState() {
|
|
|
|
return nil, ErrNilInnerState
|
|
|
|
}
|
|
|
|
if b.state.RandaoMixes == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
b.lock.RLock()
|
|
|
|
defer b.lock.RUnlock()
|
|
|
|
|
|
|
|
return b.randaoMixAtIndex(idx)
|
|
|
|
}
|
|
|
|
|
|
|
|
// randaoMixAtIndex retrieves a specific block root based on an
|
|
|
|
// input index value.
|
|
|
|
// This assumes that a lock is already held on BeaconState.
|
|
|
|
func (b *BeaconState) randaoMixAtIndex(idx uint64) ([]byte, error) {
|
|
|
|
if !b.hasInnerState() {
|
|
|
|
return nil, ErrNilInnerState
|
|
|
|
}
|
|
|
|
|
2021-08-23 16:53:50 +00:00
|
|
|
return bytesutil.SafeCopyRootAtIndex(b.state.RandaoMixes, idx)
|
2021-04-12 14:23:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RandaoMixesLength returns the length of the randao mixes slice.
|
|
|
|
func (b *BeaconState) RandaoMixesLength() int {
|
|
|
|
if !b.hasInnerState() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
if b.state.RandaoMixes == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
b.lock.RLock()
|
|
|
|
defer b.lock.RUnlock()
|
|
|
|
|
|
|
|
return b.randaoMixesLength()
|
|
|
|
}
|
|
|
|
|
|
|
|
// randaoMixesLength returns the length of the randao mixes slice.
|
|
|
|
// This assumes that a lock is already held on BeaconState.
|
|
|
|
func (b *BeaconState) randaoMixesLength() int {
|
|
|
|
if !b.hasInnerState() {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
if b.state.RandaoMixes == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
return len(b.state.RandaoMixes)
|
|
|
|
}
|