2018-12-19 05:18:42 +00:00
|
|
|
package randao
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2018-12-23 22:51:04 +00:00
|
|
|
"github.com/gogo/protobuf/proto"
|
2018-12-19 05:18:42 +00:00
|
|
|
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-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) {
|
|
|
|
newState := proto.Clone(state).(*pb.BeaconState)
|
|
|
|
vreg := newState.GetValidatorRegistry()
|
2018-12-19 05:18:42 +00:00
|
|
|
|
2018-12-23 22:51:04 +00:00
|
|
|
proposerIndex, err := v.BeaconProposerIndex(newState, slot)
|
2018-12-19 05:18:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("unable to retrieve proposer index %v", err)
|
|
|
|
}
|
|
|
|
vreg[proposerIndex].RandaoLayers++
|
2018-12-23 22:51:04 +00:00
|
|
|
state.ValidatorRegistry = vreg
|
|
|
|
return newState, nil
|
2018-12-19 05:18:42 +00:00
|
|
|
}
|