Skip to content
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

Merged
merged 22 commits into from
May 14, 2019
Merged

Answer queries #65

merged 22 commits into from
May 14, 2019

Conversation

marcio-diaz
Copy link

@marcio-diaz marcio-diaz commented May 8, 2019

Starting #10

This PR adds the HistoricalVotes struct, for saving votes in received order and indicating the moment of prevoting and precommiting.

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);
Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

HistoricalVotes {
seen: prevotes.chain(precommits).collect(),
prevote_idx: self.votes.prevote_idx(),
precommit_idx: self.votes.precommit_idx().map(|idx| idx + prevotes_len),
Copy link
Contributor

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.

Copy link
Author

@marcio-diaz marcio-diaz May 9, 2019

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.

@rphmeier
Copy link
Contributor

rphmeier commented May 8, 2019

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.

@marcio-diaz
Copy link
Author

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 HistoricalVotes and saving it in a appropriate format.

Then I'm not sure if the answering methods should be done here or in substrate. My guess is to add them in Environment.

@rphmeier
Copy link
Contributor

rphmeier commented May 9, 2019

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) => {
Copy link
Contributor

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?

Copy link
Contributor

@rphmeier rphmeier May 13, 2019

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

Copy link
Author

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) => {
Copy link
Contributor

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();
Copy link
Contributor

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?

Copy link
Contributor

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).

@@ -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.
Copy link
Contributor

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.

Copy link
Contributor

@andresilva andresilva left a 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());
Copy link
Contributor

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 };
Copy link
Contributor

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);
Copy link
Contributor

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.

Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants