mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 15:11:03 +00:00
deps: replace lru with schnellru (#1217)
* deps: replace lru with schnellru * bring the peace to the galaxy
This commit is contained in:
@@ -20,7 +20,7 @@ sp-keystore = { path = "../../../../substrate/primitives/keystore" }
|
||||
thiserror = "1.0.31"
|
||||
rand = "0.8.5"
|
||||
derive_more = "0.99.17"
|
||||
lru = "0.11.0"
|
||||
schnellru = "0.2.1"
|
||||
fatality = "0.0.6"
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@@ -14,10 +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::HashSet, num::NonZeroUsize};
|
||||
use std::collections::HashSet;
|
||||
|
||||
use lru::LruCache;
|
||||
use rand::{seq::SliceRandom, thread_rng};
|
||||
use schnellru::{ByLength, LruMap};
|
||||
|
||||
use polkadot_node_subsystem::overseer;
|
||||
use polkadot_node_subsystem_util::runtime::RuntimeInfo;
|
||||
@@ -37,7 +37,7 @@ pub struct SessionCache {
|
||||
/// Note: Performance of fetching is really secondary here, but we need to ensure we are going
|
||||
/// to get any existing cache entry, before fetching new information, as we should not mess up
|
||||
/// the order of validators in `SessionInfo::validator_groups`.
|
||||
session_info_cache: LruCache<SessionIndex, SessionInfo>,
|
||||
session_info_cache: LruMap<SessionIndex, SessionInfo>,
|
||||
}
|
||||
|
||||
/// Localized session information, tailored for the needs of availability distribution.
|
||||
@@ -83,7 +83,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(NonZeroUsize::new(2).unwrap()),
|
||||
session_info_cache: LruMap::new(ByLength::new(2)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ impl SessionCache {
|
||||
gum::trace!(target: LOG_TARGET, session_index, "Calling `with_info`");
|
||||
let r = with_info(&info);
|
||||
gum::trace!(target: LOG_TARGET, session_index, "Storing session info in lru!");
|
||||
self.session_info_cache.put(session_index, info);
|
||||
self.session_info_cache.insert(session_index, info);
|
||||
Ok(Some(r))
|
||||
} else {
|
||||
Ok(None)
|
||||
@@ -142,7 +142,7 @@ impl SessionCache {
|
||||
/// will be put at the beginning of the group.
|
||||
pub fn report_bad(&mut self, report: BadValidators) -> Result<()> {
|
||||
let available_sessions = self.session_info_cache.iter().map(|(k, _)| *k).collect();
|
||||
let session = self.session_info_cache.get_mut(&report.session_index).ok_or(
|
||||
let session = self.session_info_cache.get(&report.session_index).ok_or(
|
||||
Error::NoSuchCachedSession {
|
||||
available_sessions,
|
||||
missing_session: report.session_index,
|
||||
|
||||
@@ -7,7 +7,7 @@ license.workspace = true
|
||||
|
||||
[dependencies]
|
||||
futures = "0.3.21"
|
||||
lru = "0.11.0"
|
||||
schnellru = "0.2.1"
|
||||
rand = "0.8.5"
|
||||
fatality = "0.0.6"
|
||||
thiserror = "1.0.31"
|
||||
|
||||
@@ -35,8 +35,8 @@ use futures::{
|
||||
stream::{FuturesUnordered, StreamExt},
|
||||
task::{Context, Poll},
|
||||
};
|
||||
use lru::LruCache;
|
||||
use rand::seq::SliceRandom;
|
||||
use schnellru::{ByLength, LruMap};
|
||||
|
||||
use fatality::Nested;
|
||||
use polkadot_erasure_coding::{
|
||||
@@ -82,10 +82,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: NonZeroUsize = match NonZeroUsize::new(16) {
|
||||
Some(cap) => cap,
|
||||
None => panic!("Availability-recovery cache size must be non-zero."),
|
||||
};
|
||||
const LRU_SIZE: u32 = 16;
|
||||
|
||||
const COST_INVALID_REQUEST: Rep = Rep::CostMajor("Peer sent unparsable request");
|
||||
|
||||
@@ -927,7 +924,7 @@ struct State {
|
||||
live_block: (BlockNumber, Hash),
|
||||
|
||||
/// An LRU cache of recently recovered data.
|
||||
availability_lru: LruCache<CandidateHash, CachedRecovery>,
|
||||
availability_lru: LruMap<CandidateHash, CachedRecovery>,
|
||||
}
|
||||
|
||||
impl Default for State {
|
||||
@@ -935,7 +932,7 @@ impl Default for State {
|
||||
Self {
|
||||
ongoing_recoveries: FuturesUnordered::new(),
|
||||
live_block: (0, Hash::default()),
|
||||
availability_lru: LruCache::new(LRU_SIZE),
|
||||
availability_lru: LruMap::new(ByLength::new(LRU_SIZE)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1152,7 +1149,7 @@ async fn query_chunk_size<Context>(
|
||||
|
||||
#[overseer::contextbounds(AvailabilityRecovery, prefix = self::overseer)]
|
||||
impl AvailabilityRecoverySubsystem {
|
||||
/// Create a new instance of `AvailabilityRecoverySubsystem` which never requests the
|
||||
/// Create a new instance of `AvailabilityRecoverySubsystem` which never requests the
|
||||
/// `AvailabilityStoreSubsystem` subsystem.
|
||||
pub fn with_availability_store_skip(
|
||||
req_receiver: IncomingRequestReceiver<request_v1::AvailableDataFetchingRequest>,
|
||||
@@ -1334,7 +1331,7 @@ impl AvailabilityRecoverySubsystem {
|
||||
output = state.ongoing_recoveries.select_next_some() => {
|
||||
if let Some((candidate_hash, result)) = output {
|
||||
if let Ok(recovery) = CachedRecovery::try_from(result) {
|
||||
state.availability_lru.put(candidate_hash, recovery);
|
||||
state.availability_lru.insert(candidate_hash, recovery);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ sp-application-crypto = { path = "../../../../substrate/primitives/application-c
|
||||
sp-keystore = { path = "../../../../substrate/primitives/keystore" }
|
||||
thiserror = "1.0.31"
|
||||
fatality = "0.0.6"
|
||||
lru = "0.11.0"
|
||||
schnellru = "0.2.1"
|
||||
indexmap = "1.9.1"
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
//! 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, time::Duration};
|
||||
use std::time::Duration;
|
||||
|
||||
use futures::{channel::mpsc, FutureExt, StreamExt, TryFutureExt};
|
||||
|
||||
@@ -165,8 +165,7 @@ where
|
||||
) -> Self {
|
||||
let runtime = RuntimeInfo::new_with_config(runtime::Config {
|
||||
keystore: Some(keystore),
|
||||
session_cache_lru_size: NonZeroUsize::new(DISPUTE_WINDOW.get() as usize)
|
||||
.expect("Dispute window can not be 0; qed"),
|
||||
session_cache_lru_size: DISPUTE_WINDOW.get(),
|
||||
});
|
||||
let (tx, sender_rx) = NestingSender::new_root(1);
|
||||
let disputes_sender = DisputeSender::new(tx, metrics.clone());
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::{
|
||||
num::NonZeroUsize,
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
time::Duration,
|
||||
@@ -161,8 +160,7 @@ where
|
||||
) -> Self {
|
||||
let runtime = RuntimeInfo::new_with_config(runtime::Config {
|
||||
keystore: None,
|
||||
session_cache_lru_size: NonZeroUsize::new(DISPUTE_WINDOW.get() as usize)
|
||||
.expect("Dispute window can not be 0; qed"),
|
||||
session_cache_lru_size: DISPUTE_WINDOW.get(),
|
||||
});
|
||||
Self {
|
||||
runtime,
|
||||
|
||||
Reference in New Issue
Block a user