From 8a4a2dbd0ed7fdf91c259f5502ca81733b231818 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Wed, 23 Aug 2023 15:33:38 +0300 Subject: [PATCH] fix approval import and add more rep logs Signed-off-by: Andrei Sandu --- node/network/approval-distribution/src/lib.rs | 26 +++++++------------ node/subsystem-util/src/reputation.rs | 5 ++++ 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/node/network/approval-distribution/src/lib.rs b/node/network/approval-distribution/src/lib.rs index 1c75bf6ed6cc..746a4b4dab5c 100644 --- a/node/network/approval-distribution/src/lib.rs +++ b/node/network/approval-distribution/src/lib.rs @@ -485,22 +485,6 @@ impl BlockEntry { .or_insert(entry) } - // Returns `true` if we have an approval for `candidate_index` from validator - // `validator_index`. - pub fn contains_approval_entry( - &self, - candidate_index: CandidateIndex, - validator_index: ValidatorIndex, - ) -> bool { - self.candidates - .get(candidate_index as usize) - .map_or(None, |candidate_entry| candidate_entry.messages.get(&validator_index)) - .map_or(false, |candidate_indices| { - self.approval_entries - .contains_key(&(validator_index, candidate_indices.clone())) - }) - } - // Returns a mutable reference of `ApprovalEntry` for `candidate_index` from validator // `validator_index`. pub fn approval_entry( @@ -1383,10 +1367,18 @@ impl State { let candidate_index = vote.candidate_index; let entry = match self.blocks.get_mut(&block_hash) { - Some(entry) if entry.contains_approval_entry(candidate_index, validator_index) => entry, + Some(entry) if entry.candidates.get(candidate_index as usize).is_some() => entry, _ => { if let Some(peer_id) = source.peer_id() { if !self.recent_outdated_blocks.is_recent_outdated(&block_hash) { + gum::debug!( + target: LOG_TARGET, + ?peer_id, + ?block_hash, + ?validator_index, + ?candidate_index, + "Approval from a peer is out of view", + ); modify_reputation( &mut self.reputation, ctx.sender(), diff --git a/node/subsystem-util/src/reputation.rs b/node/subsystem-util/src/reputation.rs index 89e3eb64df9b..35746dd5fef3 100644 --- a/node/subsystem-util/src/reputation.rs +++ b/node/subsystem-util/src/reputation.rs @@ -25,6 +25,7 @@ use std::{collections::HashMap, time::Duration}; /// Default delay for sending reputation changes pub const REPUTATION_CHANGE_INTERVAL: Duration = Duration::from_secs(30); +const LOG_TARGET: &'static str = "parachain::reputation-aggregator"; type BatchReputationChange = HashMap; @@ -75,6 +76,10 @@ impl ReputationAggregator { peer_id: PeerId, rep: UnifiedReputationChange, ) { + if rep.cost_or_benefit() < 0 { + gum::debug!(target: LOG_TARGET, peer = ?peer_id, ?rep, "Modify reputation"); + } + if (self.send_immediately_if)(rep) { self.single_send(sender, peer_id, rep).await; } else {