From 71c08a40c00201846fdfc983fa58d1d5b2efbaac Mon Sep 17 00:00:00 2001 From: Alexandru Gheorghe Date: Wed, 23 Aug 2023 20:38:17 +0300 Subject: [PATCH] Fixup sending approvals more than once Signed-off-by: Alexandru Gheorghe --- node/network/approval-distribution/src/lib.rs | 48 ++++++++++++++----- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/node/network/approval-distribution/src/lib.rs b/node/network/approval-distribution/src/lib.rs index bcdae2570681..919ec7ffc961 100644 --- a/node/network/approval-distribution/src/lib.rs +++ b/node/network/approval-distribution/src/lib.rs @@ -1518,6 +1518,7 @@ impl State { ) .await; metrics.on_approval_invalid_block(); + } else { metrics.on_approval_recent_outdated(); } @@ -1836,7 +1837,7 @@ impl State { let _timer = metrics.time_unify_with_peer(); let mut assignments_to_send = Vec::new(); - let mut approvals_to_send = Vec::new(); + let mut approvals_to_send = HashMap::new(); let view_finalized_number = view.finalized_number; for head in view.into_iter() { @@ -1930,8 +1931,21 @@ impl State { (should_forward_approval, new_covered_approvals) }, ); + if should_forward_approval { - approvals_to_send.push(approval_message); + if !approvals_to_send.contains_key(&( + approval_message.validator, + approval_message.candidate_indices.clone(), + )) { + approvals_to_send.insert( + ( + approval_message.validator, + approval_message.candidate_indices.clone(), + ), + approval_message, + ); + } + candidates_covered_by_approvals.into_iter().for_each( |(approval_knowledge, message_kind)| { peer_knowledge.sent.insert(approval_knowledge, message_kind); @@ -1971,8 +1985,12 @@ impl State { "Sending approvals to unified peer", ); - send_approvals_batched(sender, approvals_to_send, &vec![(peer_id, protocol_version)]) - .await; + send_approvals_batched( + sender, + approvals_to_send.into_values().collect_vec(), + &vec![(peer_id, protocol_version)], + ) + .await; } } @@ -2242,19 +2260,25 @@ async fn adjust_required_routing_and_propagate