Skip to content

Commit

Permalink
fix comment and rewrote the assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
shayzluf committed Apr 29, 2019
1 parent bfdc337 commit 8f3dc56
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions beacon-chain/core/helpers/randao.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,21 @@ import (
// GenerateSeed generates the randao seed of a given epoch.
//
// Spec pseudocode definition:
// def generate_seed(state: BeaconState,
// epoch: Epoch) -> Bytes32:
// """
// Generate a seed for the given ``epoch``.
// """
// return hash(
// get_randao_mix(state, epoch - MIN_SEED_LOOKAHEAD) +
// get_active_index_root(state, epoch) +
// int_to_bytes32(epoch)
// )
// def generate_seed(state: BeaconState,
// epoch: Epoch) -> Bytes32:
// """
// Generate a seed for the given ``epoch``.
// """
// return hash(
// get_randao_mix(state, epoch - MIN_SEED_LOOKAHEAD) +
// get_active_index_root(state, epoch) +
// int_to_bytes32(epoch)
// )
func GenerateSeed(state *pb.BeaconState, wantedEpoch uint64) ([32]byte, error) {
var wantedEpochM uint64
if wantedEpoch >= params.BeaconConfig().MinSeedLookahead {
wantedEpochM = wantedEpoch - params.BeaconConfig().MinSeedLookahead
} else {
if wantedEpoch < params.BeaconConfig().MinSeedLookahead {
return [32]byte{}, fmt.Errorf("can't generate seed for epoch: %d that is smaller then MIN_SEED_LOOKAHEAD: %d", wantedEpoch, params.BeaconConfig().MinSeedLookahead)
}
randaoMix, err := RandaoMix(state, wantedEpochM)
randaoMix, err := RandaoMix(state, wantedEpoch-params.BeaconConfig().MinSeedLookahead)
if err != nil {
return [32]byte{}, err
}
Expand Down

0 comments on commit 8f3dc56

Please sign in to comment.