babe: make secondary slot randomness available on-chain#7053
Conversation
| Initialized::put(maybe_randomness); | ||
| let maybe_primary_randomness = maybe_randomness.filter(|_| is_primary); | ||
|
|
||
| Initialized::put(maybe_primary_randomness); |
There was a problem hiding this comment.
I would find this cleaner to read just as a single if is_primary { Initializer:put(maybe_randomness) }
There was a problem hiding this comment.
Note that this is not exactly the same as what the existing version does, which puts a None when there is no randomness
There was a problem hiding this comment.
You could do
Initialized::put(if is_primary { maybe_randomness } else { None });There was a problem hiding this comment.
The base value of Initialized is None, so it logically doesn't make a difference. But yeah, the second option is more exact
There was a problem hiding this comment.
I tried the suggested approach of if is_primary { Initialized::put(maybe_randomness) } but got assertion failures here
substrate/frame/babe/src/lib.rs
Line 464 in e65a60c
| digest | ||
| .vrf_output() | ||
| .and_then(|vrf_output| { | ||
| // place the VRF output into the `Initialized` storage item |
There was a problem hiding this comment.
This comment is now outdated. Seems like it should move to below.
rphmeier
left a comment
There was a problem hiding this comment.
looks fine except for nits. thanks!
andresilva
left a comment
There was a problem hiding this comment.
lgtm. just minor nits.
| // once we've decided which epoch this block is in. | ||
| Initialized::put(if is_primary { maybe_randomness } else { None }); | ||
|
|
||
| // Place the both primary and secondary VRF output into the |
There was a problem hiding this comment.
| // Place the both primary and secondary VRF output into the | |
| // Place either the primary or secondary VRF output into the |
| /// Temporary value (cleared at block finalization) which is `Some` if we | ||
| /// have generated VRF randomness. |
There was a problem hiding this comment.
| /// Temporary value (cleared at block finalization) which is `Some` if we | |
| /// have generated VRF randomness. | |
| /// Temporary value (cleared at block finalization) that includes the VRF randomness generated at this block. | |
| /// This field should always be populated during block processing unless secondary plain slots are enabled | |
| /// (which don't contain a VRF proof). |
| .map(|inout| { | ||
| inout.make_bytes(&sp_consensus_babe::BABE_VRF_INOUT_CONTEXT) | ||
| }) | ||
| }) |
|
|
||
| /// Temporary value (cleared at block finalization) which is `Some` if we | ||
| /// have generated VRF randomness. | ||
| AuthorVrfRandomness get(fn author_vrf_randomness): Option<MaybeRandomness>; |
There was a problem hiding this comment.
I know that this is not related to this PR, but we're essentially declaring this as Option<Option<Randomness>> (same for Initialized). Do we really need the double option wrapping or was it just an oversight? Both keys are supposed to be cleared before block execution finishes.
There was a problem hiding this comment.
Well for Initialized the outer Option seems to have a specific meaning? See for example
substrate/frame/babe/src/lib.rs
Line 464 in e65a60c
However for AuthorVrfRandomness yes probably the outer Option can be removed
There was a problem hiding this comment.
Yeah right the semantics for Initialized require both options since the outer signals that we have done the initialization procedure (regardless of whether there was a primary VRF to extract or not). For AuthorVrfRandomness I think we could do with removing it and just use MaybeRandomness.
| }) | ||
| } | ||
|
|
||
| fn make_vrf_output( |
There was a problem hiding this comment.
ocd: maybe move to mock.rs next to the other utility functions?
| (vrf_output, vrf_proof, vrf_randomness) | ||
| } | ||
|
|
||
| #[test] |
There was a problem hiding this comment.
Most of the duplication in the tests below could be factored out, but won't block merge on this.
|
bot merge |
|
Waiting for commit status. |
|
bot merge cancel |
|
Merge cancelled. |
|
The PR has been reviewed and looks good but should not be merged until it is audited. |
|
@octol The audit is done and no issues were found. Can you merge master to fix the conflicts (I believe it's only about the increased |
Conflicts: bin/node/runtime/src/lib.rs
|
bot merge |
|
Trying merge. |
Make secondary slot randomness available on-chain: #7046
TODO