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

improve: Relax the signature check in BatchVote #170

Merged
merged 5 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions node/actors/network/src/gossip/batch_votes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ impl BatchVotes {
/// (all entries verified so far are added).
///
/// Returns statistics about new entries added.
///
/// For now it doesn't return an error if a vote with an invalid signature
/// is encountered, so that the node doesn't disconnect from peer if it
/// happens to have a new field in `Batch`. This is only until the feature
/// is stabilized.
pub(super) fn update(
&mut self,
attesters: &attester::Committee,
Expand Down Expand Up @@ -125,10 +130,12 @@ impl BatchVotes {
}

// Check the signature before insertion.
d.verify()?;

self.add(d.clone(), weight);
stats.added(d.msg.number, weight);
if let Err(e) = d.verify() {
tracing::error!(error =? e, "failed to verify batch vote: {e:#}");
} else {
aakoshh marked this conversation as resolved.
Show resolved Hide resolved
self.add(d.clone(), weight);
stats.added(d.msg.number, weight);
}
}

Ok(stats)
Expand Down
5 changes: 3 additions & 2 deletions node/actors/network/src/gossip/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ async fn test_batch_votes() {
votes.update(&attesters, &genesis, &update).await.unwrap();
assert_eq!(want.0, sub.borrow_and_update().votes);

// Invalid signature, should be rejected.
// Invalid signature, should be ignored.
let mut k0v3 = mk_batch(
rng,
&keys[1],
Expand All @@ -612,7 +612,8 @@ async fn test_batch_votes() {
assert!(votes
.update(&attesters, &genesis, &[Arc::new(k0v3)])
.await
.is_err());
.is_ok());
assert_eq!(want.0, sub.borrow_and_update().votes);

// Invalid genesis, should be rejected.
let other_genesis = rng.gen();
Expand Down
Loading