mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 07:41:08 +00:00
Add some magic to signed statements and approval votes (#2585)
* add a magic number to backing statements encoded * fix fallout in statement table * fix some fallout in backing * add magic to approval votes * remove last references to Candidate variant * update size-hint
This commit is contained in:
committed by
GitHub
parent
d859734ed9
commit
30e4a67f0c
@@ -697,7 +697,9 @@ fn approval_signing_payload(
|
||||
approval_vote: ApprovalVote,
|
||||
session_index: SessionIndex,
|
||||
) -> Vec<u8> {
|
||||
(approval_vote, session_index).encode()
|
||||
const MAGIC: [u8; 4] = *b"APPR";
|
||||
|
||||
(MAGIC, approval_vote, session_index).encode()
|
||||
}
|
||||
|
||||
// `Option::cmp` treats `None` as less than `Some`.
|
||||
|
||||
@@ -195,7 +195,7 @@ struct InvalidErasureRoot;
|
||||
// the code. So this does the necessary conversion.
|
||||
fn primitive_statement_to_table(s: &SignedFullStatement) -> TableSignedStatement {
|
||||
let statement = match s.payload() {
|
||||
Statement::Seconded(c) => TableStatement::Candidate(c.clone()),
|
||||
Statement::Seconded(c) => TableStatement::Seconded(c.clone()),
|
||||
Statement::Valid(h) => TableStatement::Valid(h.clone()),
|
||||
Statement::Invalid(h) => TableStatement::Invalid(h.clone()),
|
||||
};
|
||||
@@ -1239,7 +1239,7 @@ mod tests {
|
||||
statement: TableStatement,
|
||||
) -> Statement {
|
||||
match statement {
|
||||
TableStatement::Candidate(committed_candidate_receipt) => Statement::Seconded(committed_candidate_receipt),
|
||||
TableStatement::Seconded(committed_candidate_receipt) => Statement::Seconded(committed_candidate_receipt),
|
||||
TableStatement::Valid(candidate_hash) => Statement::Valid(candidate_hash),
|
||||
TableStatement::Invalid(candidate_hash) => Statement::Invalid(candidate_hash),
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ impl PeerRelayParentKnowledge {
|
||||
}
|
||||
|
||||
let new_known = match fingerprint.0 {
|
||||
CompactStatement::Candidate(ref h) => {
|
||||
CompactStatement::Seconded(ref h) => {
|
||||
self.seconded_counts.entry(fingerprint.1)
|
||||
.or_default()
|
||||
.note_local(h.clone());
|
||||
@@ -224,7 +224,7 @@ impl PeerRelayParentKnowledge {
|
||||
}
|
||||
|
||||
let candidate_hash = match fingerprint.0 {
|
||||
CompactStatement::Candidate(ref h) => {
|
||||
CompactStatement::Seconded(ref h) => {
|
||||
let allowed_remote = self.seconded_counts.entry(fingerprint.1)
|
||||
.or_insert_with(Default::default)
|
||||
.note_remote(h.clone());
|
||||
@@ -437,7 +437,7 @@ impl ActiveHeadData {
|
||||
};
|
||||
|
||||
match comparator.compact {
|
||||
CompactStatement::Candidate(h) => {
|
||||
CompactStatement::Seconded(h) => {
|
||||
let seconded_so_far = self.seconded_counts.entry(validator_index).or_insert(0);
|
||||
if *seconded_so_far >= VC_THRESHOLD {
|
||||
return NotedStatement::NotUseful;
|
||||
@@ -1241,8 +1241,8 @@ mod tests {
|
||||
assert!(knowledge.received_message_count.is_empty());
|
||||
|
||||
// Make the peer aware of the candidate.
|
||||
assert_eq!(knowledge.send(&(CompactStatement::Candidate(hash_a), ValidatorIndex(0))), Some(true));
|
||||
assert_eq!(knowledge.send(&(CompactStatement::Candidate(hash_a), ValidatorIndex(1))), Some(false));
|
||||
assert_eq!(knowledge.send(&(CompactStatement::Seconded(hash_a), ValidatorIndex(0))), Some(true));
|
||||
assert_eq!(knowledge.send(&(CompactStatement::Seconded(hash_a), ValidatorIndex(1))), Some(false));
|
||||
assert!(knowledge.known_candidates.contains(&hash_a));
|
||||
assert_eq!(knowledge.sent_statements.len(), 2);
|
||||
assert!(knowledge.received_statements.is_empty());
|
||||
@@ -1263,8 +1263,8 @@ mod tests {
|
||||
let mut knowledge = PeerRelayParentKnowledge::default();
|
||||
|
||||
let hash_a = CandidateHash([1; 32].into());
|
||||
assert!(knowledge.receive(&(CompactStatement::Candidate(hash_a), ValidatorIndex(0)), 3).unwrap());
|
||||
assert!(knowledge.send(&(CompactStatement::Candidate(hash_a), ValidatorIndex(0))).is_none());
|
||||
assert!(knowledge.receive(&(CompactStatement::Seconded(hash_a), ValidatorIndex(0)), 3).unwrap());
|
||||
assert!(knowledge.send(&(CompactStatement::Seconded(hash_a), ValidatorIndex(0))).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1279,7 +1279,7 @@ mod tests {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
knowledge.receive(&(CompactStatement::Candidate(hash_a), ValidatorIndex(0)), 3),
|
||||
knowledge.receive(&(CompactStatement::Seconded(hash_a), ValidatorIndex(0)), 3),
|
||||
Ok(true),
|
||||
);
|
||||
|
||||
@@ -1312,12 +1312,12 @@ mod tests {
|
||||
let hash_c = CandidateHash([3; 32].into());
|
||||
|
||||
assert_eq!(
|
||||
knowledge.receive(&(CompactStatement::Candidate(hash_b), ValidatorIndex(0)), 3),
|
||||
knowledge.receive(&(CompactStatement::Seconded(hash_b), ValidatorIndex(0)), 3),
|
||||
Ok(true),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
knowledge.receive(&(CompactStatement::Candidate(hash_c), ValidatorIndex(0)), 3),
|
||||
knowledge.receive(&(CompactStatement::Seconded(hash_c), ValidatorIndex(0)), 3),
|
||||
Err(COST_UNEXPECTED_STATEMENT),
|
||||
);
|
||||
|
||||
@@ -1328,7 +1328,7 @@ mod tests {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
knowledge.receive(&(CompactStatement::Candidate(hash_b), ValidatorIndex(0)), 3),
|
||||
knowledge.receive(&(CompactStatement::Seconded(hash_b), ValidatorIndex(0)), 3),
|
||||
Err(COST_DUPLICATE_STATEMENT),
|
||||
);
|
||||
}
|
||||
@@ -1451,7 +1451,7 @@ mod tests {
|
||||
|
||||
assert!(c_knowledge.known_candidates.contains(&candidate_hash));
|
||||
assert!(c_knowledge.sent_statements.contains(
|
||||
&(CompactStatement::Candidate(candidate_hash), ValidatorIndex(0))
|
||||
&(CompactStatement::Seconded(candidate_hash), ValidatorIndex(0))
|
||||
));
|
||||
assert!(c_knowledge.sent_statements.contains(
|
||||
&(CompactStatement::Valid(candidate_hash), ValidatorIndex(1))
|
||||
|
||||
@@ -71,7 +71,7 @@ impl Statement {
|
||||
/// of the candidate.
|
||||
pub fn to_compact(&self) -> CompactStatement {
|
||||
match *self {
|
||||
Statement::Seconded(ref c) => CompactStatement::Candidate(c.hash()),
|
||||
Statement::Seconded(ref c) => CompactStatement::Seconded(c.hash()),
|
||||
Statement::Valid(hash) => CompactStatement::Valid(hash),
|
||||
Statement::Invalid(hash) => CompactStatement::Invalid(hash),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user