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

Commit

Permalink
Sensible limits for known blocks and extrinsics (#4094)
Browse files Browse the repository at this point in the history
  • Loading branch information
arkpar authored and gavofyork committed Nov 12, 2019
1 parent b0bc705 commit a36b648
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions core/network/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ const TICK_TIMEOUT: time::Duration = time::Duration::from_millis(1100);
/// Interval at which we propagate exstrinsics;
const PROPAGATE_TIMEOUT: time::Duration = time::Duration::from_millis(2900);

/// Maximim number of known block hashes to keep for a peer.
const MAX_KNOWN_BLOCKS: usize = 1024; // ~32kb per peer + LruHashSet overhead
/// Maximim number of known extrinsic hashes to keep for a peer.
const MAX_KNOWN_EXTRINSICS: usize = 4096; // ~128kb per peer + overhead

/// Current protocol version.
pub(crate) const CURRENT_VERSION: u32 = 5;
/// Lowest version we support
Expand Down Expand Up @@ -973,8 +978,6 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
}
}

let cache_limit = NonZeroUsize::new(1_000_000).expect("1_000_000 > 0; qed");

let info = match self.handshaking_peers.remove(&who) {
Some(_handshaking) => {
PeerInfo {
Expand All @@ -993,8 +996,10 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
let peer = Peer {
info,
block_request: None,
known_extrinsics: LruHashSet::new(cache_limit),
known_blocks: LruHashSet::new(cache_limit),
known_extrinsics: LruHashSet::new(NonZeroUsize::new(MAX_KNOWN_EXTRINSICS)
.expect("Constant is nonzero")),
known_blocks: LruHashSet::new(NonZeroUsize::new(MAX_KNOWN_BLOCKS)
.expect("Constant is nonzero")),
next_request_id: 0,
obsolete_requests: HashMap::new(),
};
Expand Down

0 comments on commit a36b648

Please sign in to comment.