-
Notifications
You must be signed in to change notification settings - Fork 1.6k
runtime/parachains: Keep track of included candidates and historical babe vrfs in shared
module
#3558
runtime/parachains: Keep track of included candidates and historical babe vrfs in shared
module
#3558
Conversation
session: SessionIndex, | ||
candidate_hash: CandidateHash, | ||
included_in: T::BlockNumber, | ||
revert_to: T::BlockNumber, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not exactly revert_to, though, because I think we revert to included_in - 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we rename it to revert_tail
, since it's the tail of the chain that gets removed in reversion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not an expert thus can't give good terminology advice, but seems like included_in
was a beteter name, when there's a clear document saying we revert to included_in - 1 when ...
.
79eaf7c
to
9f33380
Compare
9f33380
to
9bf8442
Compare
shared
module
@@ -565,7 +553,9 @@ impl<T: Config> Pallet<T> { | |||
dispute.concluded_at = Some(now); | |||
<Disputes<T>>::insert(session_index, candidate_hash, &dispute); | |||
|
|||
if <Included<T>>::contains_key(&session_index, &candidate_hash) { | |||
let is_local = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: not clear why you want this variable.
if <Included<T>>::contains_key(&session_index, &candidate_hash) { | ||
let is_local = | ||
<shared::Pallet<T>>::is_included_candidate(&session_index, &candidate_hash); | ||
if is_local { | ||
// Local disputes don't count towards spam. | ||
|
||
weight += T::DbWeight::get().reads_writes(1, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use saturating math here.
// removed over the course of many block inclusions. | ||
shared::Pallet::<T>::mark_session_pruneable(to_prune); | ||
// TODO(ladi): remove this call, currently allows unit tests to pass. Need to | ||
// figure out how to invoke paras_inherent::enter in run_to_block. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why can't you call this in your run_to_block
? enter
is a dispatchable and is public
CoreIndex(0), | ||
) { | ||
Pallet::<Test>::process_included(session, candidate_hash.clone(), revert_to); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what should happen in else
?
/// transitioning to a new session. | ||
#[pallet::storage] | ||
#[pallet::getter(fn pruneable_sessions)] | ||
pub(super) type PruneableSessions<T: Config> = StorageMap<_, Twox64Concat, SessionIndex, ()>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thiolliere if this pattern is legit, it would be easy to abstract it behind a StorageSet
.
included_in: T::BlockNumber, | ||
core_index: CoreIndex, | ||
) -> Option<T::BlockNumber> { | ||
if included_in.is_zero() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when does this happen?
<IncludedCandidates<T>>::get(session, candidate_hash) | ||
} | ||
|
||
#[cfg(test)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this code not in the mod tests
?
This PR attempts to take the first step in adding incentive structures to the Approval Voting system, c.f. #3463
Closes #3469
The goal is three-fold:
CandidateHash
esCandidateHash
->CoreIndex
mapping for some historicalCandidateHash
esCandidateHash
es for a historical session over the course of an ongoing sessionSpecifically, we add a StorageDoubleMap to the shared module. This StorageDoubleMap maintains the (SessionIndex, CandidateHash) -> Coreindex mapping (Note that we also include the BlockNumber in the value of the Map).
The additional indirection of maintaining the Session allows to implement more coherent pruning logic.
Pruning is currently simplified in that we prune a fixed number of Candidates at a time. This is achieved by prefix-query for a particular SessionIndex in the DoubleMap, thereby pruning CandidateHashes over time until a SessionIndex is exhausted.
Closes #3470
In addition, this PR also adds a StorageDoubleMap to the shared module which keeps track of historical Babe VRFs for the purpose of comparing these VRFs against the Approval Assignments that are issued throughout the Approval Voting process.
The pruning algorithm for Historical VRFs is modified from the above pruning logic for candidates. Within every invocation of the pruning function, we remove one block's worth of historical VRFs for a single pruneable session. However, if all Candidates for a specfic Session have been exhausted, then all Historical VRFs across all blocks in that session are pruned.
The parameter for how many candidates to prune per invocation of the pruning function should be more adaptive in order to ensure we prune all blocks (and historical VRFs) in a session approximately as quickly as we prune all candidates in a session.