prysm-pulse/beacon-chain/core/randao/randao.go
terence tsao 463cd58171
Implement Process Penalties and Exit Logic (#1291)
* implemented process pentalties and exit logic

* tests

* add MaxWithdrawalsPerEpoch to config

* preston's feedback, replaced index with idx

* s/e/penalizedEpoch

* removed blank line
2019-01-15 21:52:57 -08:00

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.BeaconProposerIdx(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
}