mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-04 00:44:27 +00:00
34 lines
1.2 KiB
Go
34 lines
1.2 KiB
Go
// Package randao contains libraries to update and proposer's RANDAO layer
|
|
// and mixes the RANDAO with the existing RANDAO value in state.
|
|
package randao
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
v "github.com/prysmaticlabs/prysm/beacon-chain/core/validators"
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
)
|
|
|
|
// UpdateRandaoLayers increments the randao layer of the block proposer at the given slot.
|
|
func UpdateRandaoLayers(state *pb.BeaconState, slot uint64) (*pb.BeaconState, error) {
|
|
vreg := state.ValidatorRegistry
|
|
proposerIndex, err := v.BeaconProposerIndex(state, slot)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("unable to retrieve proposer index %v", err)
|
|
}
|
|
|
|
vreg[proposerIndex].RandaoLayers++
|
|
state.ValidatorRegistry = vreg
|
|
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
|
|
prevMixes := state.LatestRandaoMixesHash32S[(state.Slot-1)%latestMixesLength]
|
|
state.LatestRandaoMixesHash32S[state.Slot%latestMixesLength] = prevMixes
|
|
return state
|
|
}
|