2019-01-09 23:49:50 +00:00
|
|
|
// Package randao contains libraries to update and proposer's RANDAO layer
|
|
|
|
// and mixes the RANDAO with the existing RANDAO value in state.
|
2018-12-19 05:18:42 +00:00
|
|
|
package randao
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
v "github.com/prysmaticlabs/prysm/beacon-chain/core/validators"
|
2018-12-23 22:51:04 +00:00
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
2018-12-28 05:19:32 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
2018-12-19 05:18:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// UpdateRandaoLayers increments the randao layer of the block proposer at the given slot.
|
2018-12-23 22:51:04 +00:00
|
|
|
func UpdateRandaoLayers(state *pb.BeaconState, slot uint64) (*pb.BeaconState, error) {
|
2019-01-05 03:58:19 +00:00
|
|
|
vreg := state.ValidatorRegistry
|
2019-01-16 05:52:57 +00:00
|
|
|
proposerIndex, err := v.BeaconProposerIdx(state, slot)
|
2018-12-19 05:18:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("unable to retrieve proposer index %v", err)
|
|
|
|
}
|
2019-01-01 17:17:44 +00:00
|
|
|
|
2018-12-19 05:18:42 +00:00
|
|
|
vreg[proposerIndex].RandaoLayers++
|
2018-12-23 22:51:04 +00:00
|
|
|
state.ValidatorRegistry = vreg
|
2018-12-28 05:19:32 +00:00
|
|
|
return state, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateRandaoMixes sets the beacon state's latest randao mixes according to the latest
|
|
|
|
// beacon slot.
|
|
|
|
func UpdateRandaoMixes(state *pb.BeaconState) *pb.BeaconState {
|
|
|
|
latestMixesLength := params.BeaconConfig().LatestRandaoMixesLength
|
2019-01-06 15:25:43 +00:00
|
|
|
prevMixes := state.LatestRandaoMixesHash32S[(state.Slot-1)%latestMixesLength]
|
|
|
|
state.LatestRandaoMixesHash32S[state.Slot%latestMixesLength] = prevMixes
|
|
|
|
return state
|
2018-12-19 05:18:42 +00:00
|
|
|
}
|