mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 23:01:01 +00:00
deps: replace lru with schnellru (#1217)
* deps: replace lru with schnellru * bring the peace to the galaxy
This commit is contained in:
@@ -10,7 +10,7 @@ async-trait = "0.1.73"
|
||||
codec = { package = "parity-scale-codec", version = "3.0.0", features = [ "derive" ] }
|
||||
futures = "0.3.28"
|
||||
tracing = "0.1.37"
|
||||
lru = "0.10.0"
|
||||
schnellru = "0.2.1"
|
||||
|
||||
# Substrate
|
||||
sc-client-api = { path = "../../../../substrate/client/api" }
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
/// should be thrown out and which ones should be kept.
|
||||
use codec::Codec;
|
||||
use cumulus_client_consensus_common::ParachainBlockImportMarker;
|
||||
use lru::LruCache;
|
||||
use schnellru::{ByLength, LruMap};
|
||||
|
||||
use sc_consensus::{
|
||||
import_queue::{BasicQueue, Verifier as VerifierT},
|
||||
@@ -36,27 +36,28 @@ use sp_consensus_aura::{AuraApi, Slot, SlotDuration};
|
||||
use sp_core::crypto::Pair;
|
||||
use sp_inherents::{CreateInherentDataProviders, InherentDataProvider};
|
||||
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
|
||||
use std::{fmt::Debug, num::NonZeroUsize, sync::Arc};
|
||||
use std::{fmt::Debug, sync::Arc};
|
||||
|
||||
const LRU_WINDOW: usize = 256;
|
||||
const LRU_WINDOW: u32 = 256;
|
||||
const EQUIVOCATION_LIMIT: usize = 16;
|
||||
|
||||
struct NaiveEquivocationDefender {
|
||||
cache: LruCache<u64, usize>,
|
||||
cache: LruMap<u64, usize>,
|
||||
}
|
||||
|
||||
impl Default for NaiveEquivocationDefender {
|
||||
fn default() -> Self {
|
||||
NaiveEquivocationDefender {
|
||||
cache: LruCache::new(NonZeroUsize::new(LRU_WINDOW).expect("window > 0; qed")),
|
||||
}
|
||||
NaiveEquivocationDefender { cache: LruMap::new(ByLength::new(LRU_WINDOW)) }
|
||||
}
|
||||
}
|
||||
|
||||
impl NaiveEquivocationDefender {
|
||||
// return `true` if equivocation is beyond the limit.
|
||||
fn insert_and_check(&mut self, slot: Slot) -> bool {
|
||||
let val = self.cache.get_or_insert_mut(*slot, || 0);
|
||||
let val = self
|
||||
.cache
|
||||
.get_or_insert(*slot, || 0)
|
||||
.expect("insertion with ByLength limiter always succeeds; qed");
|
||||
if *val == EQUIVOCATION_LIMIT {
|
||||
true
|
||||
} else {
|
||||
|
||||
@@ -36,7 +36,7 @@ cumulus-relay-chain-rpc-interface = { path = "../relay-chain-rpc-interface" }
|
||||
cumulus-primitives-core = { path = "../../primitives/core" }
|
||||
|
||||
array-bytes = "6.1"
|
||||
lru = "0.11.0"
|
||||
schnellru = "0.2.1"
|
||||
tracing = "0.1.37"
|
||||
async-trait = "0.1.73"
|
||||
futures = "0.3.28"
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use futures::{select, StreamExt};
|
||||
use lru::LruCache;
|
||||
use schnellru::{ByLength, LruMap};
|
||||
use std::sync::Arc;
|
||||
|
||||
use polkadot_availability_recovery::AvailabilityRecoverySubsystem;
|
||||
@@ -157,7 +157,7 @@ fn build_overseer(
|
||||
.span_per_active_leaf(Default::default())
|
||||
.active_leaves(Default::default())
|
||||
.supports_parachains(runtime_client)
|
||||
.known_leaves(LruCache::new(KNOWN_LEAVES_CACHE_SIZE))
|
||||
.known_leaves(LruMap::new(ByLength::new(KNOWN_LEAVES_CACHE_SIZE)))
|
||||
.metrics(Metrics::register(registry)?)
|
||||
.spawner(spawner);
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ async-trait = "0.1.73"
|
||||
url = "2.4.0"
|
||||
serde_json = "1.0.105"
|
||||
serde = "1.0.183"
|
||||
lru = "0.11.0"
|
||||
schnellru = "0.2.1"
|
||||
smoldot = { version = "0.11.0", default_features = false, features = ["std"]}
|
||||
smoldot-light = { version = "0.9.0", default_features = false, features = ["std"] }
|
||||
either = "1.8.1"
|
||||
|
||||
@@ -31,10 +31,10 @@ use jsonrpsee::{
|
||||
},
|
||||
ws_client::WsClientBuilder,
|
||||
};
|
||||
use lru::LruCache;
|
||||
use sc_rpc_api::chain::ChainApiClient;
|
||||
use schnellru::{ByLength, LruMap};
|
||||
use sp_runtime::generic::SignedBlock;
|
||||
use std::{num::NonZeroUsize, sync::Arc};
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::mpsc::{
|
||||
channel as tokio_channel, Receiver as TokioReceiver, Sender as TokioSender,
|
||||
};
|
||||
@@ -307,8 +307,7 @@ impl ReconnectingWebsocketWorker {
|
||||
return
|
||||
};
|
||||
|
||||
let mut imported_blocks_cache =
|
||||
LruCache::new(NonZeroUsize::new(40).expect("40 is nonzero; qed."));
|
||||
let mut imported_blocks_cache = LruMap::new(ByLength::new(40));
|
||||
let mut should_reconnect = ConnectionStatus::Connected;
|
||||
let mut last_seen_finalized_num: RelayNumber = 0;
|
||||
loop {
|
||||
@@ -365,7 +364,7 @@ impl ReconnectingWebsocketWorker {
|
||||
match import_event {
|
||||
Some(Ok(header)) => {
|
||||
let hash = header.hash();
|
||||
if imported_blocks_cache.contains(&hash) {
|
||||
if imported_blocks_cache.peek(&hash).is_some() {
|
||||
tracing::debug!(
|
||||
target: LOG_TARGET,
|
||||
number = header.number,
|
||||
@@ -374,7 +373,7 @@ impl ReconnectingWebsocketWorker {
|
||||
);
|
||||
continue;
|
||||
}
|
||||
imported_blocks_cache.put(hash, ());
|
||||
imported_blocks_cache.insert(hash, ());
|
||||
distribute_header(header, &mut self.imported_header_listeners);
|
||||
},
|
||||
None => {
|
||||
|
||||
Reference in New Issue
Block a user