-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Answer queries #65
Answer queries #65
Conversation
…y-grandpa into marcio/answer-queries
src/round.rs
Outdated
/// Set the length of prevotes received at the moment of prevoting. | ||
pub fn set_prevote_idx(&mut self) -> bool { | ||
self.prevote.voted_at = Some(self.prevote.votes().len()); | ||
println!("set prevote idx to {:?}", self.prevote.voted_at); |
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.
stray println
src/round.rs
Outdated
/// Set the length of precommits received at the moment of precommiting. | ||
pub fn set_precommit_idx(&mut self) -> bool { | ||
self.precommit.voted_at = Some(self.precommit.votes().len()); | ||
println!("set precommit idx to {:?}", self.precommit.voted_at); |
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.
ditto
src/voter/voting_round.rs
Outdated
HistoricalVotes { | ||
seen: prevotes.chain(precommits).collect(), | ||
prevote_idx: self.votes.prevote_idx(), | ||
precommit_idx: self.votes.precommit_idx().map(|idx| idx + prevotes_len), |
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.
I don't think this logic is right. There is no guarantee that we see all prevotes before seeing any precommits. Since the estimate logic depends on both prevotes and precommits, we need an interleaved list where the indices are those we've voted at.
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.
Ok, I'll fix it. I thought it shouldn't invalidate the votes. But it's ugly and not what was asked anyway.
The main difficulty with this feature isn't necessarily answering the queries, but persisting them to the disk so that we can answer queries after restarts and even for old rounds. |
The persistence should be done in substrate, right? I'll make a PR there, receiving the Then I'm not sure if the answering methods should be done here or in substrate. My guess is to add them in |
Ideally we can have the functionality in this crate which is generic over some trait that provides the persistence, with the implementation living in Substrate. |
@@ -332,6 +335,8 @@ impl<Id, H, N, Signature> Round<Id, H, N, Signature> where | |||
chain, | |||
)?; | |||
|
|||
self.historical_votes.seen.push(Message::Prevote(vote.clone())); | |||
|
|||
None | |||
} | |||
VoteMultiplicity::Equivocated(ref first, ref second) => { |
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.
Don't we need to store equivocated votes as well?
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.
At the very least, the first equivocation of a type from a given voter
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.
Fixed.
@@ -409,6 +414,8 @@ impl<Id, H, N, Signature> Round<Id, H, N, Signature> where | |||
chain, | |||
)?; | |||
|
|||
self.historical_votes.seen.push(Message::Precommit(vote.clone())); | |||
|
|||
None | |||
} | |||
VoteMultiplicity::Equivocated(ref first, ref second) => { |
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.
Same as above.
@@ -370,6 +377,7 @@ impl<H, N, E: Environment<H, N>> VotingRound<H, N, E> where | |||
if let Some(prevote) = self.construct_prevote(last_round_state)? { | |||
debug!(target: "afg", "Casting prevote for round {}", self.votes.number()); | |||
self.env.prevoted(self.round_number(), prevote.clone())?; | |||
self.votes.set_prevoted_index(); |
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.
Isn't this going to race? Is it guaranteed that the next vote we process will be our own?
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.
Nevermind, I understand the semantics of this are to mark what we had seen so far when we prevoted/precommited (regardless of whether we'll eval our own vote before/after other new votes).
src/voter/voting_round.rs
Outdated
@@ -255,7 +256,7 @@ impl<H, N, E: Environment<H, N>> VotingRound<H, N, E> where | |||
self.best_finalized.as_ref() | |||
} | |||
|
|||
/// Return all imported votes for the round (prevotes and precommits). | |||
/// Return all imported votes for the round (prevotes and precommits) unordered. |
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.
This is probably unused now.
5c2cfe1
to
0e104ac
Compare
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.
Minor grumbles. Overall lgtm.
src/round.rs
Outdated
@@ -414,7 +422,9 @@ impl<Id, H, N, Signature> Round<Id, H, N, Signature> where | |||
chain, | |||
)?; | |||
|
|||
self.historical_votes.seen.push(Message::Precommit(vote.clone())); | |||
let message = Message::Precommit(vote.clone()); |
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.
Is this clone necessary?
src/round.rs
Outdated
@@ -414,7 +422,9 @@ impl<Id, H, N, Signature> Round<Id, H, N, Signature> where | |||
chain, | |||
)?; | |||
|
|||
self.historical_votes.seen.push(Message::Precommit(vote.clone())); | |||
let message = Message::Precommit(vote.clone()); | |||
let signed_message = SignedMessage { id: signer.clone(), signature, message }; |
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.
Unnecessary clone?
// Push the vote into HistoricalVotes. | ||
let message = Message::Prevote(vote); | ||
let signed_message = SignedMessage { id: signer.clone(), signature, message }; | ||
self.historical_votes.push_vote(signed_message); |
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.
Maybe only add if vote == second
? Or maybe if vote == first || vote == second
just to be safe wrt ordering.
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.
This is not needed since we early-exit after we've already seen an equivocation.
// Push the vote into HistoricalVotes. | ||
let message = Message::Precommit(vote); | ||
let signed_message = SignedMessage { id: signer.clone(), signature, message }; | ||
self.historical_votes.push_vote(signed_message); |
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.
Same as above.
Starting #10
This PR adds the
HistoricalVotes
struct, for saving votes in received order and indicating the moment of prevoting and precommiting.