2022-05-09 13:02:34 +00:00
|
|
|
package state_native
|
2022-01-13 11:23:53 +00:00
|
|
|
|
|
|
|
import (
|
2022-02-01 00:32:39 +00:00
|
|
|
"fmt"
|
2022-01-13 11:23:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// RandaoMixes of block proposers on the beacon chain.
|
|
|
|
func (b *BeaconState) RandaoMixes() [][]byte {
|
2022-02-01 00:32:39 +00:00
|
|
|
if b.randaoMixes == nil {
|
2022-01-13 11:23:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
b.lock.RLock()
|
|
|
|
defer b.lock.RUnlock()
|
|
|
|
|
2022-02-01 00:32:39 +00:00
|
|
|
return b.randaoMixes.Slice()
|
2022-01-13 11:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RandaoMixAtIndex retrieves a specific block root based on an
|
|
|
|
// input index value.
|
|
|
|
func (b *BeaconState) RandaoMixAtIndex(idx uint64) ([]byte, error) {
|
2022-02-01 00:32:39 +00:00
|
|
|
if b.randaoMixes == nil {
|
2022-01-13 11:23:53 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
b.lock.RLock()
|
|
|
|
defer b.lock.RUnlock()
|
|
|
|
|
2022-02-01 00:32:39 +00:00
|
|
|
m, err := b.randaoMixAtIndex(idx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return m[:], nil
|
2022-01-13 11:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// randaoMixAtIndex retrieves a specific block root based on an
|
|
|
|
// input index value.
|
|
|
|
// This assumes that a lock is already held on BeaconState.
|
2022-02-01 00:32:39 +00:00
|
|
|
func (b *BeaconState) randaoMixAtIndex(idx uint64) ([32]byte, error) {
|
|
|
|
if uint64(len(b.randaoMixes)) <= idx {
|
|
|
|
return [32]byte{}, fmt.Errorf("index %d out of range", idx)
|
2022-01-13 11:23:53 +00:00
|
|
|
}
|
|
|
|
|
2022-02-01 00:32:39 +00:00
|
|
|
return b.randaoMixes[idx], nil
|
2022-01-13 11:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RandaoMixesLength returns the length of the randao mixes slice.
|
|
|
|
func (b *BeaconState) RandaoMixesLength() int {
|
2022-02-01 00:32:39 +00:00
|
|
|
if b.randaoMixes == nil {
|
2022-01-13 11:23:53 +00:00
|
|
|
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 {
|
2022-02-01 00:32:39 +00:00
|
|
|
if b.randaoMixes == nil {
|
2022-01-13 11:23:53 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2022-02-01 00:32:39 +00:00
|
|
|
return len(b.randaoMixes)
|
2022-01-13 11:23:53 +00:00
|
|
|
}
|