Clarify `get_randao_mix` accessor

We avoid a genesis underflow by taking the randao epoch in `generate_seed` to be `+ EPOCHS_PER_HISTORICAL_VECTOR`.

This conflicts with the expected epoch bounds noted  in `get_randao_mix` and this PR attempts to clarify the situation by leaving a note.
This commit is contained in:
Alex Stokes 2019-06-26 16:33:23 -06:00 committed by GitHub
parent d587c4fe61
commit 10e257490f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -737,7 +737,7 @@ def get_randao_mix(state: BeaconState,
epoch: Epoch) -> Hash: epoch: Epoch) -> Hash:
""" """
Return the randao mix at a recent ``epoch``. Return the randao mix at a recent ``epoch``.
``epoch`` expected to be between (current_epoch - EPOCHS_PER_HISTORICAL_VECTOR, current_epoch]. ``epoch`` expected to be between (current_epoch - EPOCHS_PER_HISTORICAL_VECTOR, current_epoch], unless otherwise noted at a call site.
""" """
return state.randao_mixes[epoch % EPOCHS_PER_HISTORICAL_VECTOR] return state.randao_mixes[epoch % EPOCHS_PER_HISTORICAL_VECTOR]
``` ```
@ -762,6 +762,8 @@ def generate_seed(state: BeaconState,
epoch: Epoch) -> Hash: epoch: Epoch) -> Hash:
""" """
Generate a seed for the given ``epoch``. Generate a seed for the given ``epoch``.
Note that avoiding the underflow on ``get_randao_mix`` here violates the epoch validity condition given in that function's comment.
""" """
return hash( return hash(
get_randao_mix(state, Epoch(epoch + EPOCHS_PER_HISTORICAL_VECTOR - MIN_SEED_LOOKAHEAD)) + get_randao_mix(state, Epoch(epoch + EPOCHS_PER_HISTORICAL_VECTOR - MIN_SEED_LOOKAHEAD)) +