Conversation
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); |
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); |
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.
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.
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. |
|
|
||
| None | ||
| } | ||
| VoteMultiplicity::Equivocated(ref first, ref second) => { |
There was a problem hiding this comment.
Don't we need to store equivocated votes as well?
There was a problem hiding this comment.
At the very least, the first equivocation of a type from a given voter
|
|
||
| None | ||
| } | ||
| VoteMultiplicity::Equivocated(ref first, ref second) => { |
| 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.
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.
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
| } | ||
|
|
||
| /// 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.
This is probably unused now.
5c2cfe1 to
0e104ac
Compare
andresilva
left a comment
There was a problem hiding this comment.
Minor grumbles. Overall lgtm.
src/round.rs
Outdated
| )?; | ||
|
|
||
| self.historical_votes.seen.push(Message::Precommit(vote.clone())); | ||
| let message = Message::Precommit(vote.clone()); |
There was a problem hiding this comment.
Is this clone necessary?
src/round.rs
Outdated
|
|
||
| self.historical_votes.seen.push(Message::Precommit(vote.clone())); | ||
| let message = Message::Precommit(vote.clone()); | ||
| let signed_message = SignedMessage { id: signer.clone(), signature, message }; |
| // 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.
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.
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); |
Starting #10
This PR adds the
HistoricalVotesstruct, for saving votes in received order and indicating the moment of prevoting and precommiting.