mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 04:07:57 +00:00
backing: move the min votes threshold to the runtime (#1200)
* move min backing votes const to runtime also cache it per-session in the backing subsystem Signed-off-by: alindima <alin@parity.io> * add runtime migration * introduce api versioning for min_backing votes also enable it for rococo/versi for testing * also add min_backing_votes runtime calls to statement-distribution this dependency has been recently introduced by async backing * remove explicit version runtime API call this is not needed, as the RuntimeAPISubsystem already takes care of versioning and will return NotSupported if the version is not right. * address review comments - parametrise backing votes runtime API with session index - remove RuntimeInfo usage in backing subsystem, as runtime API caches the min backing votes by session index anyway. - move the logic for adjusting the configured needed backing votes with the size of the backing group to a primitives helper. - move the legacy min backing votes value to a primitives helper. - mark JoinMultiple error as fatal, since the Canceled (non-multiple) counterpart is also fatal. - make backing subsystem handle fatal errors for new leaves update. - add HostConfiguration consistency check for zeroed backing votes threshold - add cumulus accompanying change * fix cumulus test compilation * fix tests * more small fixes * fix merge * bump runtime api version for westend and rollback version for rococo --------- Signed-off-by: alindima <alin@parity.io> Co-authored-by: Javier Viola <javier@parity.io>
This commit is contained in:
@@ -65,6 +65,7 @@ pub(crate) struct RequestResultCache {
|
||||
LruMap<Hash, Vec<(SessionIndex, CandidateHash, vstaging::slashing::PendingSlashes)>>,
|
||||
key_ownership_proof:
|
||||
LruMap<(Hash, ValidatorId), Option<vstaging::slashing::OpaqueKeyOwnershipProof>>,
|
||||
minimum_backing_votes: LruMap<SessionIndex, u32>,
|
||||
|
||||
staging_para_backing_state: LruMap<(Hash, ParaId), Option<vstaging::BackingState>>,
|
||||
staging_async_backing_params: LruMap<Hash, vstaging::AsyncBackingParams>,
|
||||
@@ -97,6 +98,7 @@ impl Default for RequestResultCache {
|
||||
disputes: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
|
||||
unapplied_slashes: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
|
||||
key_ownership_proof: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
|
||||
minimum_backing_votes: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
|
||||
|
||||
staging_para_backing_state: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
|
||||
staging_async_backing_params: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
|
||||
@@ -434,6 +436,18 @@ impl RequestResultCache {
|
||||
None
|
||||
}
|
||||
|
||||
pub(crate) fn minimum_backing_votes(&mut self, session_index: SessionIndex) -> Option<u32> {
|
||||
self.minimum_backing_votes.get(&session_index).copied()
|
||||
}
|
||||
|
||||
pub(crate) fn cache_minimum_backing_votes(
|
||||
&mut self,
|
||||
session_index: SessionIndex,
|
||||
minimum_backing_votes: u32,
|
||||
) {
|
||||
self.minimum_backing_votes.insert(session_index, minimum_backing_votes);
|
||||
}
|
||||
|
||||
pub(crate) fn staging_para_backing_state(
|
||||
&mut self,
|
||||
key: (Hash, ParaId),
|
||||
@@ -469,6 +483,7 @@ pub(crate) enum RequestResult {
|
||||
// The structure of each variant is (relay_parent, [params,]*, result)
|
||||
Authorities(Hash, Vec<AuthorityDiscoveryId>),
|
||||
Validators(Hash, Vec<ValidatorId>),
|
||||
MinimumBackingVotes(Hash, SessionIndex, u32),
|
||||
ValidatorGroups(Hash, (Vec<Vec<ValidatorIndex>>, GroupRotationInfo)),
|
||||
AvailabilityCores(Hash, Vec<CoreState>),
|
||||
PersistedValidationData(Hash, ParaId, OccupiedCoreAssumption, Option<PersistedValidationData>),
|
||||
|
||||
@@ -101,6 +101,9 @@ where
|
||||
self.requests_cache.cache_authorities(relay_parent, authorities),
|
||||
Validators(relay_parent, validators) =>
|
||||
self.requests_cache.cache_validators(relay_parent, validators),
|
||||
MinimumBackingVotes(_, session_index, minimum_backing_votes) => self
|
||||
.requests_cache
|
||||
.cache_minimum_backing_votes(session_index, minimum_backing_votes),
|
||||
ValidatorGroups(relay_parent, groups) =>
|
||||
self.requests_cache.cache_validator_groups(relay_parent, groups),
|
||||
AvailabilityCores(relay_parent, cores) =>
|
||||
@@ -301,6 +304,15 @@ where
|
||||
Request::StagingAsyncBackingParams(sender) =>
|
||||
query!(staging_async_backing_params(), sender)
|
||||
.map(|sender| Request::StagingAsyncBackingParams(sender)),
|
||||
Request::MinimumBackingVotes(index, sender) => {
|
||||
if let Some(value) = self.requests_cache.minimum_backing_votes(index) {
|
||||
self.metrics.on_cached_request();
|
||||
let _ = sender.send(Ok(value));
|
||||
None
|
||||
} else {
|
||||
Some(Request::MinimumBackingVotes(index, sender))
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -551,6 +563,12 @@ where
|
||||
ver = Request::SUBMIT_REPORT_DISPUTE_LOST_RUNTIME_REQUIREMENT,
|
||||
sender
|
||||
),
|
||||
Request::MinimumBackingVotes(index, sender) => query!(
|
||||
MinimumBackingVotes,
|
||||
minimum_backing_votes(index),
|
||||
ver = Request::MINIMUM_BACKING_VOTES_RUNTIME_REQUIREMENT,
|
||||
sender
|
||||
),
|
||||
|
||||
Request::StagingParaBackingState(para, sender) => {
|
||||
query!(
|
||||
|
||||
@@ -264,6 +264,10 @@ impl RuntimeApiSubsystemClient for MockSubsystemClient {
|
||||
) -> Result<Option<vstaging::BackingState>, ApiError> {
|
||||
todo!("Not required for tests")
|
||||
}
|
||||
|
||||
async fn minimum_backing_votes(&self, _: Hash, _: SessionIndex) -> Result<u32, ApiError> {
|
||||
todo!("Not required for tests")
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user