-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[dag] cache votes without re-counting #11808
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,12 +30,13 @@ use aptos_types::{ | |
validator_txn::ValidatorTransaction, | ||
validator_verifier::ValidatorVerifier, | ||
}; | ||
use futures_channel::oneshot; | ||
use serde::{Deserialize, Serialize}; | ||
use std::{ | ||
cmp::min, | ||
collections::HashSet, | ||
fmt::{Display, Formatter}, | ||
ops::Deref, | ||
ops::{Deref, DerefMut}, | ||
sync::Arc, | ||
}; | ||
|
||
|
@@ -343,7 +344,7 @@ impl Node { | |
} | ||
} | ||
|
||
#[derive(Serialize, Deserialize, PartialEq, Debug, Eq, Hash, Clone)] | ||
#[derive(Serialize, Deserialize, PartialEq, Debug, Eq, Hash, Clone, PartialOrd, Ord)] | ||
pub struct NodeId { | ||
epoch: u64, | ||
round: Round, | ||
|
@@ -534,47 +535,65 @@ impl TryFrom<DAGRpcResult> for Vote { | |
|
||
pub struct SignatureBuilder { | ||
metadata: NodeMetadata, | ||
partial_signatures: Mutex<PartialSignatures>, | ||
inner: Mutex<(PartialSignatures, Option<oneshot::Sender<NodeCertificate>>)>, | ||
epoch_state: Arc<EpochState>, | ||
} | ||
|
||
impl SignatureBuilder { | ||
pub fn new(metadata: NodeMetadata, epoch_state: Arc<EpochState>) -> Arc<Self> { | ||
pub fn new( | ||
metadata: NodeMetadata, | ||
epoch_state: Arc<EpochState>, | ||
tx: oneshot::Sender<NodeCertificate>, | ||
) -> Arc<Self> { | ||
Arc::new(Self { | ||
metadata, | ||
partial_signatures: Mutex::new(PartialSignatures::empty()), | ||
inner: Mutex::new((PartialSignatures::empty(), Some(tx))), | ||
epoch_state, | ||
}) | ||
} | ||
} | ||
|
||
impl BroadcastStatus<DAGMessage, DAGRpcResult> for Arc<SignatureBuilder> { | ||
type Aggregated = NodeCertificate; | ||
type Aggregated = (); | ||
type Message = Node; | ||
type Response = Vote; | ||
|
||
/// Processes the [Vote]s received for a given [Node]. Once a supermajority voting power | ||
/// is reached, this method sends [NodeCertificate] into a channel. It will only return | ||
/// successfully when [Vote]s are received from all the peers. | ||
fn add(&self, peer: Author, ack: Self::Response) -> anyhow::Result<Option<Self::Aggregated>> { | ||
ensure!(self.metadata == ack.metadata, "Digest mismatch"); | ||
ack.verify(peer, &self.epoch_state.verifier)?; | ||
debug!(LogSchema::new(LogEvent::ReceiveVote) | ||
.remote_peer(peer) | ||
.round(self.metadata.round())); | ||
let mut signatures_lock = self.partial_signatures.lock(); | ||
signatures_lock.add_signature(peer, ack.signature); | ||
Ok(self | ||
.epoch_state | ||
.verifier | ||
.check_voting_power(signatures_lock.signatures().keys(), true) | ||
.ok() | ||
.map(|_| { | ||
let aggregated_signature = self | ||
.epoch_state | ||
.verifier | ||
.aggregate_signatures(&signatures_lock) | ||
.expect("Signature aggregation should succeed"); | ||
observe_node(self.metadata.timestamp(), NodeStage::CertAggregated); | ||
NodeCertificate::new(self.metadata.clone(), aggregated_signature) | ||
})) | ||
let mut guard = self.inner.lock(); | ||
let (partial_signatures, tx) = guard.deref_mut(); | ||
partial_signatures.add_signature(peer, ack.signature); | ||
|
||
if tx.is_some() | ||
&& self | ||
.epoch_state | ||
.verifier | ||
.check_voting_power(partial_signatures.signatures().keys(), true) | ||
.is_ok() | ||
{ | ||
let aggregated_signature = self | ||
.epoch_state | ||
.verifier | ||
.aggregate_signatures(partial_signatures) | ||
.expect("Signature aggregation should succeed"); | ||
observe_node(self.metadata.timestamp(), NodeStage::CertAggregated); | ||
let certificate = NodeCertificate::new(self.metadata.clone(), aggregated_signature); | ||
|
||
_ = tx.take().expect("must exist").send(certificate); | ||
} | ||
|
||
if partial_signatures.signatures().len() == self.epoch_state.verifier.len() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add some comments here to explain why the aggregation is through a channel? I assume it's because we want to keep the rb alive even after cert? |
||
Ok(Some(())) | ||
} else { | ||
Ok(None) | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
just add another expect here instead of unreachable below?
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.
we need a mutable reference to node_status. If i expect, then I wont get a reference to the Option in BTreeMap.