From 10312920b558c81be0d8458f71b670da49c4bec6 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Tue, 12 Dec 2017 17:57:03 +0100 Subject: [PATCH] import availability votes --- substrate/candidate-agreement/src/table.rs | 46 +++++++++++++++++----- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/substrate/candidate-agreement/src/table.rs b/substrate/candidate-agreement/src/table.rs index eb77166840..31bc805fe2 100644 --- a/substrate/candidate-agreement/src/table.rs +++ b/substrate/candidate-agreement/src/table.rs @@ -142,6 +142,7 @@ struct CandidateData { group_id: C::GroupId, candidate: C::Candidate, validity_votes: HashMap, + availability_votes: HashSet, indicated_bad_by: Vec, } @@ -236,6 +237,7 @@ impl Table { group_id: group, candidate: candidate, validity_votes: HashMap::new(), + availability_votes: HashSet::new(), indicated_bad_by: Vec::new(), }); } @@ -252,15 +254,6 @@ impl Table { valid: bool, signature: C::Signature, ) -> Option> { - let statement = SignedStatement { - signature: signature.clone(), - statement: if valid { - Statement::Valid(digest.clone()) - } else { - Statement::Invalid(digest.clone()) - } - }; - let votes = match self.candidate_votes.get_mut(&digest) { None => return None, // TODO: queue up but don't get DoS'ed Some(votes) => votes, @@ -269,7 +262,14 @@ impl Table { // check that this validator actually can vote in this group. if !context.is_member_of(&from, &votes.group_id) { return Some(Misbehavior::UnauthorizedStatement(UnauthorizedStatement { - statement + statement: SignedStatement { + signature: signature.clone(), + statement: if valid { + Statement::Valid(digest.clone()) + } else { + Statement::Invalid(digest.clone()) + } + } })); } @@ -298,4 +298,30 @@ impl Table { None } + + fn availability_vote( + &mut self, + context: &C, + from: C::ValidatorId, + digest: C::Digest, + signature: C::Signature, + ) -> Option> { + let votes = match self.candidate_votes.get_mut(&digest) { + None => return None, // TODO: queue up but don't get DoS'ed + Some(votes) => votes, + }; + + // check that this validator actually can vote in this group. + if !context.is_availability_guarantor_of(&from, &votes.group_id) { + return Some(Misbehavior::UnauthorizedStatement(UnauthorizedStatement { + statement: SignedStatement { + signature: signature.clone(), + statement: Statement::Available(digest), + } + })); + } + + votes.availability_votes.insert(from); + None + } }