Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
fix approval import and add more rep logs
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Sandu <[email protected]>
  • Loading branch information
sandreim committed Aug 23, 2023
1 parent 4619a2b commit 8a4a2db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
26 changes: 9 additions & 17 deletions node/network/approval-distribution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(),
Expand Down
5 changes: 5 additions & 0 deletions node/subsystem-util/src/reputation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PeerId, i32>;

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8a4a2db

Please sign in to comment.