mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 04:27: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:
@@ -30,7 +30,10 @@ use std::{
|
||||
hash::Hash,
|
||||
};
|
||||
|
||||
use primitives::{ValidatorSignature, ValidityAttestation as PrimitiveValidityAttestation};
|
||||
use primitives::{
|
||||
effective_minimum_backing_votes, ValidatorSignature,
|
||||
ValidityAttestation as PrimitiveValidityAttestation,
|
||||
};
|
||||
|
||||
use parity_scale_codec::{Decode, Encode};
|
||||
|
||||
@@ -57,8 +60,8 @@ pub trait Context {
|
||||
/// Members are meant to submit candidates and vote on validity.
|
||||
fn is_member_of(&self, authority: &Self::AuthorityId, group: &Self::GroupId) -> bool;
|
||||
|
||||
/// requisite number of votes for validity from a group.
|
||||
fn requisite_votes(&self, group: &Self::GroupId) -> usize;
|
||||
/// Get a validator group size.
|
||||
fn get_group_size(&self, group: &Self::GroupId) -> Option<usize>;
|
||||
}
|
||||
|
||||
/// Table configuration.
|
||||
@@ -319,9 +322,12 @@ impl<Ctx: Context> Table<Ctx> {
|
||||
&self,
|
||||
digest: &Ctx::Digest,
|
||||
context: &Ctx,
|
||||
minimum_backing_votes: u32,
|
||||
) -> Option<AttestedCandidate<Ctx::GroupId, Ctx::Candidate, Ctx::AuthorityId, Ctx::Signature>> {
|
||||
self.candidate_votes.get(digest).and_then(|data| {
|
||||
let v_threshold = context.requisite_votes(&data.group_id);
|
||||
let v_threshold = context.get_group_size(&data.group_id).map_or(usize::MAX, |len| {
|
||||
effective_minimum_backing_votes(len, minimum_backing_votes)
|
||||
});
|
||||
data.attested(v_threshold)
|
||||
})
|
||||
}
|
||||
@@ -636,16 +642,13 @@ mod tests {
|
||||
self.authorities.get(authority).map(|v| v == group).unwrap_or(false)
|
||||
}
|
||||
|
||||
fn requisite_votes(&self, id: &GroupId) -> usize {
|
||||
let mut total_validity = 0;
|
||||
|
||||
for validity in self.authorities.values() {
|
||||
if validity == id {
|
||||
total_validity += 1
|
||||
}
|
||||
fn get_group_size(&self, group: &Self::GroupId) -> Option<usize> {
|
||||
let count = self.authorities.values().filter(|g| *g == group).count();
|
||||
if count == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(count)
|
||||
}
|
||||
|
||||
total_validity / 2 + 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -910,7 +913,7 @@ mod tests {
|
||||
table.import_statement(&context, statement);
|
||||
|
||||
assert!(!table.detected_misbehavior.contains_key(&AuthorityId(1)));
|
||||
assert!(table.attested_candidate(&candidate_digest, &context).is_none());
|
||||
assert!(table.attested_candidate(&candidate_digest, &context, 2).is_none());
|
||||
|
||||
let vote = SignedStatement {
|
||||
statement: Statement::Valid(candidate_digest),
|
||||
@@ -920,7 +923,7 @@ mod tests {
|
||||
|
||||
table.import_statement(&context, vote);
|
||||
assert!(!table.detected_misbehavior.contains_key(&AuthorityId(2)));
|
||||
assert!(table.attested_candidate(&candidate_digest, &context).is_some());
|
||||
assert!(table.attested_candidate(&candidate_digest, &context, 2).is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user