Struct pallet_babe::ParentBlockRandomness
source · pub struct ParentBlockRandomness<T>(_);
Expand description
Randomness produced semi-freshly with each block, but inherits limitations of
RandomnessFromTwoEpochsAgo
from which it derives.
All randomness is relative to commitments to any other inputs to the computation: If Alice samples randomness near perfectly using radioactive decay, but then afterwards Eve selects an arbitrary value with which to xor Alice’s randomness, then Eve always wins whatever game they play.
As with RandomnessFromTwoEpochsAgo
, all input commitments combined with
ParentBlockRandomness
should come from at least two epoch ago, except preferably
not near epoch ending, and thus ideally three epochs ago.
Almost all users learn this randomness for a given block by the time they receive it’s
parent block, which makes this randomness appear fresh enough. Yet, the block producer
themselves learned this randomness at the beginning of epoch current_epoch - 2
, at
the same time as they learn RandomnessFromTwoEpochsAgo
.
Aside from just biasing RandomnessFromTwoEpochsAgo
, adversaries could also bias
ParentBlockRandomness
by never announcing their block if doing so yields an
unfavorable randomness. As such, ParentBlockRandomness
should be considered weaker
than both other randomness sources provided by BABE, but ParentBlockRandomness
remains constrained by declared staking, while a randomness source like block hash is
only constrained by adversaries’ unknowable computational power.
As an example use, parachains could assign block production slots based upon the
ParentBlockRandomness
of their relay parent or relay parent’s parent, provided the
parachain registers collators but avoids censorship sensitive functionality like
slashing. Any parachain with slashing could operate BABE itself or perhaps better yet
a BABE-like approach that derives its ParentBlockRandomness
, and authorizes block
production, based upon the relay parent’s ParentBlockRandomness
or more likely the
relay parent’s RandomnessFromTwoEpochsAgo
.
NOTE: there is some nuance here regarding what is current and parent randomness. If
you are using this trait from within the runtime (i.e. as part of block execution)
then the randomness provided here will always be generated from the parent block. If
instead you are using this randomness externally, i.e. after block execution, then
this randomness will be provided by the “current” block (this stems from the fact that
we process VRF outputs on block execution finalization, i.e. on_finalize
).
Trait Implementations§
source§impl<T: Config> Randomness<Option<<T as Config>::Hash>, <<<T as Config>::Block as HeaderProvider>::HeaderT as Header>::Number> for ParentBlockRandomness<T>
impl<T: Config> Randomness<Option<<T as Config>::Hash>, <<<T as Config>::Block as HeaderProvider>::HeaderT as Header>::Number> for ParentBlockRandomness<T>
source§fn random(subject: &[u8]) -> (Option<T::Hash>, BlockNumberFor<T>)
fn random(subject: &[u8]) -> (Option<T::Hash>, BlockNumberFor<T>)
source§fn random_seed() -> (Output, BlockNumber)
fn random_seed() -> (Output, BlockNumber)
Auto Trait Implementations§
impl<T> RefUnwindSafe for ParentBlockRandomness<T>where T: RefUnwindSafe,
impl<T> Send for ParentBlockRandomness<T>where T: Send,
impl<T> Sync for ParentBlockRandomness<T>where T: Sync,
impl<T> Unpin for ParentBlockRandomness<T>where T: Unpin,
impl<T> UnwindSafe for ParentBlockRandomness<T>where T: UnwindSafe,
Blanket Implementations§
source§impl<T> CheckedConversion for T
impl<T> CheckedConversion for T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T, Outer> IsWrappedBy<Outer> for Twhere
Outer: AsRef<T> + AsMut<T> + From<T>,
T: From<Outer>,
impl<T, Outer> IsWrappedBy<Outer> for Twhere Outer: AsRef<T> + AsMut<T> + From<T>, T: From<Outer>,
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
source§fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Selfwhere Self: UniqueSaturatedFrom<T>,
source§fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> Twhere Self: UniqueSaturatedInto<T>,
T
. Read more§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.source§impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere T: UncheckedFrom<S>,
source§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
unchecked_from
.source§impl<T, S> UniqueSaturatedInto<T> for Swhere
T: Bounded,
S: TryInto<T>,
impl<T, S> UniqueSaturatedInto<T> for Swhere T: Bounded, S: TryInto<T>,
source§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
T
.