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

Bump lru from 0.7.8 to 0.8.0 #6060

Merged
merged 6 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
22 changes: 11 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node/core/approval-voting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ futures-timer = "3.0.2"
parity-scale-codec = { version = "3.1.5", default-features = false, features = ["bit-vec", "derive"] }
gum = { package = "tracing-gum", path = "../../gum" }
bitvec = { version = "1.0.0", default-features = false, features = ["alloc"] }
lru = "0.7"
lru = "0.8"
merlin = "2.0"
schnorrkel = "0.9.1"
kvdb = "0.11.0"
Expand Down
6 changes: 4 additions & 2 deletions node/core/approval-voting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ use std::{
collections::{
btree_map::Entry as BTMEntry, hash_map::Entry as HMEntry, BTreeMap, HashMap, HashSet,
},
num::NonZeroUsize,
sync::Arc,
time::Duration,
};
Expand Down Expand Up @@ -104,7 +105,7 @@ const APPROVAL_CHECKING_TIMEOUT: Duration = Duration::from_secs(120);
/// Value rather arbitrarily: Should not be hit in practice, it exists to more easily diagnose dead
/// lock issues for example.
const WAIT_FOR_SIGS_TIMEOUT: Duration = Duration::from_millis(500);
const APPROVAL_CACHE_SIZE: usize = 1024;
const APPROVAL_CACHE_SIZE: Option<NonZeroUsize> = NonZeroUsize::new(1024);
const TICK_TOO_FAR_IN_FUTURE: Tick = 20; // 10 seconds.
const APPROVAL_DELAY: Tick = 2;
const LOG_TARGET: &str = "parachain::approval-voting";
Expand Down Expand Up @@ -737,7 +738,8 @@ where

let mut wakeups = Wakeups::default();
let mut currently_checking_set = CurrentlyCheckingSet::default();
let mut approvals_cache = lru::LruCache::new(APPROVAL_CACHE_SIZE);
let mut approvals_cache =
lru::LruCache::new(APPROVAL_CACHE_SIZE.expect("Approval cache size should not be 0."));

let mut last_finalized_height: Option<BlockNumber> = {
let (tx, rx) = oneshot::channel();
Expand Down
2 changes: 1 addition & 1 deletion node/core/dispute-coordinator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ gum = { package = "tracing-gum", path = "../../gum" }
parity-scale-codec = "3.1.5"
kvdb = "0.11.0"
thiserror = "1.0.31"
lru = "0.7.7"
lru = "0.8.0"
fatality = "0.0.6"

polkadot-primitives = { path = "../../../primitives" }
Expand Down
11 changes: 8 additions & 3 deletions node/core/dispute-coordinator/src/scraping/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use std::collections::{BTreeMap, HashSet};
use std::{
collections::{BTreeMap, HashSet},
num::NonZeroUsize,
};

use futures::channel::oneshot;
use lru::LruCache;
Expand Down Expand Up @@ -44,7 +47,7 @@ mod tests;
/// `last_observed_blocks` LRU. This means, this value should the very least be as large as the
/// number of expected forks for keeping chain scraping efficient. Making the LRU much larger than
/// that has very limited use.
const LRU_OBSERVED_BLOCKS_CAPACITY: usize = 20;
const LRU_OBSERVED_BLOCKS_CAPACITY: Option<NonZeroUsize> = NonZeroUsize::new(20);
bkchr marked this conversation as resolved.
Show resolved Hide resolved

/// Chain scraper
///
Expand Down Expand Up @@ -92,7 +95,9 @@ impl ChainScraper {
let mut s = Self {
included_candidates: HashSet::new(),
candidates_by_block_number: BTreeMap::new(),
last_observed_blocks: LruCache::new(LRU_OBSERVED_BLOCKS_CAPACITY),
last_observed_blocks: LruCache::new(
LRU_OBSERVED_BLOCKS_CAPACITY.expect("Observed blocks cache size should not be 0."),
),
bkchr marked this conversation as resolved.
Show resolved Hide resolved
};
let update =
ActiveLeavesUpdate { activated: Some(initial_head), deactivated: Default::default() };
Expand Down
2 changes: 1 addition & 1 deletion node/network/availability-distribution/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "maste
thiserror = "1.0.31"
rand = "0.8.5"
derive_more = "0.99.17"
lru = "0.7.7"
lru = "0.8.0"
fatality = "0.0.6"

[dev-dependencies]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use std::collections::HashSet;
use std::{collections::HashSet, num::NonZeroUsize};

use lru::LruCache;
use rand::{seq::SliceRandom, thread_rng};
Expand Down Expand Up @@ -85,7 +85,7 @@ impl SessionCache {
pub fn new() -> Self {
SessionCache {
// We need to cache the current and the last session the most:
session_info_cache: LruCache::new(2),
session_info_cache: LruCache::new(NonZeroUsize::new(2).unwrap()),
}
}

Expand Down
2 changes: 1 addition & 1 deletion node/network/availability-recovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"

[dependencies]
futures = "0.3.21"
lru = "0.7.7"
lru = "0.8.0"
rand = "0.8.5"
fatality = "0.0.6"
thiserror = "1.0.31"
Expand Down
7 changes: 5 additions & 2 deletions node/network/availability-recovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use std::{
collections::{HashMap, VecDeque},
num::NonZeroUsize,
pin::Pin,
time::Duration,
};
Expand Down Expand Up @@ -77,7 +78,7 @@ const LOG_TARGET: &str = "parachain::availability-recovery";
const N_PARALLEL: usize = 50;

// Size of the LRU cache where we keep recovered data.
const LRU_SIZE: usize = 16;
const LRU_SIZE: Option<NonZeroUsize> = NonZeroUsize::new(16);
bkchr marked this conversation as resolved.
Show resolved Hide resolved

const COST_INVALID_REQUEST: Rep = Rep::CostMajor("Peer sent unparsable request");

Expand Down Expand Up @@ -797,7 +798,9 @@ impl Default for State {
Self {
ongoing_recoveries: FuturesUnordered::new(),
live_block: (0, Hash::default()),
availability_lru: LruCache::new(LRU_SIZE),
availability_lru: LruCache::new(
LRU_SIZE.expect("Availability Recovery cache size should not be 0."),
),
bkchr marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion node/network/dispute-distribution/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ sp-application-crypto = { git = "https://github.com/paritytech/substrate", branc
sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" }
thiserror = "1.0.31"
fatality = "0.0.6"
lru = "0.7.7"
lru = "0.8.0"

[dev-dependencies]
async-trait = "0.1.57"
Expand Down
4 changes: 3 additions & 1 deletion node/network/dispute-distribution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
//! The sender is responsible for getting our vote out, see [`sender`]. The receiver handles
//! incoming [`DisputeRequest`]s and offers spam protection, see [`receiver`].

use std::num::NonZeroUsize;

use futures::{channel::mpsc, FutureExt, StreamExt, TryFutureExt};

use polkadot_node_network_protocol::authority_discovery::AuthorityDiscovery;
Expand Down Expand Up @@ -145,7 +147,7 @@ where
) -> Self {
let runtime = RuntimeInfo::new_with_config(runtime::Config {
keystore: Some(keystore),
session_cache_lru_size: DISPUTE_WINDOW.get() as usize,
session_cache_lru_size: NonZeroUsize::new(DISPUTE_WINDOW.get() as usize).unwrap(),
skunert marked this conversation as resolved.
Show resolved Hide resolved
});
let (tx, sender_rx) = mpsc::channel(1);
let disputes_sender = DisputeSender::new(tx, metrics.clone());
Expand Down
10 changes: 7 additions & 3 deletions node/network/dispute-distribution/src/receiver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use std::{
collections::HashSet,
num::NonZeroUsize,
pin::Pin,
task::{Context, Poll},
};
Expand Down Expand Up @@ -146,7 +147,7 @@ where
) -> Self {
let runtime = RuntimeInfo::new_with_config(runtime::Config {
keystore: None,
session_cache_lru_size: DISPUTE_WINDOW.get() as usize,
session_cache_lru_size: NonZeroUsize::new(DISPUTE_WINDOW.get() as usize).unwrap(),
skunert marked this conversation as resolved.
Show resolved Hide resolved
});
Self {
runtime,
Expand All @@ -156,7 +157,10 @@ where
pending_imports: PendingImports::new(),
// Size of MAX_PARALLEL_IMPORTS ensures we are going to immediately get rid of any
// malicious requests still pending in the incoming queue.
banned_peers: LruCache::new(MAX_PARALLEL_IMPORTS),
banned_peers: LruCache::new(
NonZeroUsize::new(MAX_PARALLEL_IMPORTS)
bkchr marked this conversation as resolved.
Show resolved Hide resolved
.expect("Banned peer cache size should not be 0."),
),
metrics,
}
}
Expand Down Expand Up @@ -222,7 +226,7 @@ where
}

// Wait for a free slot:
if self.pending_imports.len() >= MAX_PARALLEL_IMPORTS as usize {
if self.pending_imports.len() >= MAX_PARALLEL_IMPORTS {
// Wait for one to finish:
let r = self.pending_imports.next().await;
self.ban_bad_peer(r.expect("pending_imports.len() is greater 0. qed."))?;
Expand Down
2 changes: 1 addition & 1 deletion node/overseer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ polkadot-node-metrics = { path = "../metrics" }
polkadot-primitives = { path = "../../primitives" }
orchestra = { path = "../orchestra" }
gum = { package = "tracing-gum", path = "../gum" }
lru = "0.7"
lru = "0.8"
parity-util-mem = { version = "0.11.0", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
async-trait = "0.1.57"
Expand Down
4 changes: 3 additions & 1 deletion node/overseer/src/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ where
.activation_external_listeners(Default::default())
.span_per_active_leaf(Default::default())
.active_leaves(Default::default())
.known_leaves(LruCache::new(KNOWN_LEAVES_CACHE_SIZE))
.known_leaves(LruCache::new(
KNOWN_LEAVES_CACHE_SIZE.expect("Known leaves cache size should not be 0."),
))
bkchr marked this conversation as resolved.
Show resolved Hide resolved
.leaves(Default::default())
.spawner(SpawnGlue(spawner))
.metrics(metrics)
Expand Down
3 changes: 2 additions & 1 deletion node/overseer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
use std::{
collections::{hash_map, HashMap},
fmt::{self, Debug},
num::NonZeroUsize,
pin::Pin,
sync::Arc,
time::Duration,
Expand Down Expand Up @@ -112,7 +113,7 @@ pub use orchestra::{

/// Store 2 days worth of blocks, not accounting for forks,
/// in the LRU cache. Assumes a 6-second block time.
pub const KNOWN_LEAVES_CACHE_SIZE: usize = 2 * 24 * 3600 / 6;
pub const KNOWN_LEAVES_CACHE_SIZE: Option<NonZeroUsize> = NonZeroUsize::new(2 * 24 * 3600 / 6);
bkchr marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to avoid this pesky expects, it might be nicer to do a match

pub const VALIDATORS_BUFFER_CAPACITY: NonZeroUsize = match NonZeroUsize::new(3) {
Some(cap) => cap,
None => panic!("buffer capacity must be non-zero"),
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better, thanks 👍


#[cfg(test)]
mod tests;
Expand Down
2 changes: 1 addition & 1 deletion node/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ kvdb = "0.11.0"
kvdb-rocksdb = { version = "0.15.2", optional = true }
parity-db = { version = "0.3.16", optional = true }
async-trait = "0.1.57"
lru = "0.7"
lru = "0.8"

# Polkadot
polkadot-node-core-parachains-inherent = { path = "../core/parachains-inherent" }
Expand Down
4 changes: 3 additions & 1 deletion node/service/src/overseer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,9 @@ where
.span_per_active_leaf(Default::default())
.active_leaves(Default::default())
.supports_parachains(runtime_client)
.known_leaves(LruCache::new(KNOWN_LEAVES_CACHE_SIZE))
.known_leaves(LruCache::new(
KNOWN_LEAVES_CACHE_SIZE.expect("Known leaves cache size should not be 0."),
))
.metrics(metrics)
.spawner(spawner);

Expand Down
2 changes: 1 addition & 1 deletion node/subsystem-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ thiserror = "1.0.31"
fatality = "0.0.6"
gum = { package = "tracing-gum", path = "../gum" }
derive_more = "0.99.17"
lru = "0.7.7"
lru = "0.8.0"

polkadot-node-subsystem = {path = "../subsystem" }
polkadot-node-jaeger = { path = "../jaeger" }
Expand Down
Loading