mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 14:01:06 +00:00
Bump lru from 0.7.8 to 0.8.0 (#6060)
* Bump lru from 0.7.8 to 0.8.0 Bumps [lru](https://github.com/jeromefroe/lru-rs) from 0.7.8 to 0.8.0. - [Release notes](https://github.com/jeromefroe/lru-rs/releases) - [Changelog](https://github.com/jeromefroe/lru-rs/blob/master/CHANGELOG.md) - [Commits](https://github.com/jeromefroe/lru-rs/compare/0.7.8...0.8.0) --- updated-dependencies: - dependency-name: lru dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * Change `LruCache` paramerter to `NonZeroUsize` * Change type of `session_cache_lru_size` to `NonZeroUsize` * Add expects instead of unwrap Co-authored-by: Bastian Köcher <info@kchr.de> * Use match to get rid of expects Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sebastian Kunert <skunert49@gmail.com> Co-authored-by: Bastian Köcher <info@kchr.de>
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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};
|
||||
@@ -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()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
use std::{
|
||||
collections::{HashMap, VecDeque},
|
||||
num::NonZeroUsize,
|
||||
pin::Pin,
|
||||
time::Duration,
|
||||
};
|
||||
@@ -77,7 +78,10 @@ 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: NonZeroUsize = match NonZeroUsize::new(16) {
|
||||
Some(cap) => cap,
|
||||
None => panic!("Availability-recovery cache size must be non-zero."),
|
||||
};
|
||||
|
||||
const COST_INVALID_REQUEST: Rep = Rep::CostMajor("Peer sent unparsable request");
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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;
|
||||
@@ -145,7 +147,8 @@ 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)
|
||||
.expect("Dispute window can not be 0; qed"),
|
||||
});
|
||||
let (tx, sender_rx) = mpsc::channel(1);
|
||||
let disputes_sender = DisputeSender::new(tx, metrics.clone());
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
num::NonZeroUsize,
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
@@ -61,6 +62,11 @@ const COST_NOT_A_VALIDATOR: Rep = Rep::CostMajor("Reporting peer was not a valid
|
||||
/// How many statement imports we want to issue in parallel:
|
||||
pub const MAX_PARALLEL_IMPORTS: usize = 10;
|
||||
|
||||
const BANNED_PEERS_CACHE_SIZE: NonZeroUsize = match NonZeroUsize::new(MAX_PARALLEL_IMPORTS) {
|
||||
Some(cap) => cap,
|
||||
None => panic!("Banned peers cache size should not be 0."),
|
||||
};
|
||||
|
||||
/// State for handling incoming `DisputeRequest` messages.
|
||||
///
|
||||
/// This is supposed to run as its own task in order to easily impose back pressure on the incoming
|
||||
@@ -146,7 +152,8 @@ 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)
|
||||
.expect("Dispute window can not be 0; qed"),
|
||||
});
|
||||
Self {
|
||||
runtime,
|
||||
@@ -156,7 +163,7 @@ 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(BANNED_PEERS_CACHE_SIZE),
|
||||
metrics,
|
||||
}
|
||||
}
|
||||
@@ -222,7 +229,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."))?;
|
||||
|
||||
Reference in New Issue
Block a user