Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add bound to banned transactions.
  • Loading branch information
tomusdrw committed Aug 23, 2018
commit 030c68ccf142df929b47a74e24eec4fd8ce6c67d
14 changes: 13 additions & 1 deletion polkadot/transaction-pool/src/rotator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ use parking_lot::RwLock;
use primitives::Hash;
use VerifiedTransaction;

/// Expected size of the banned extrinsics cache.
const EXPECTED_SIZE: usize = 2048;

/// Pool rotator is responsible to only keep fresh extrinsics in the pool.
///
/// Extrinsics that occupy the pool for too long are culled and temporarily banned from entering
Expand Down Expand Up @@ -61,7 +64,16 @@ impl PoolRotator {
return false;
}

self.banned_until.write().insert(*tx.hash(), *now + self.ban_time);
let mut banned = self.banned_until.write();
banned.insert(*tx.hash(), *now + self.ban_time);
if banned.len() > 2 * EXPECTED_SIZE {
while banned.len() > EXPECTED_SIZE {
if let Ok(key) = banned.keys().next().cloned() {
banned.remove(&key);
}
}
}

true
}

Expand Down