mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: replace lru with schnellru (#1688)
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -4487,12 +4487,12 @@ dependencies = [
|
||||
"data-encoding",
|
||||
"enr",
|
||||
"linked_hash_set",
|
||||
"lru 0.9.0",
|
||||
"parking_lot 0.12.1",
|
||||
"reth-net-common",
|
||||
"reth-primitives",
|
||||
"reth-rlp",
|
||||
"reth-tracing",
|
||||
"schnellru",
|
||||
"secp256k1 0.24.3",
|
||||
"serde",
|
||||
"serde_with",
|
||||
|
||||
@ -32,7 +32,7 @@ trust-dns-resolver = "0.22"
|
||||
data-encoding = "2"
|
||||
async-trait = "0.1"
|
||||
linked_hash_set = "0.1"
|
||||
lru = "0.9"
|
||||
schnellru = "0.2"
|
||||
thiserror = "1.0"
|
||||
tracing = "0.1"
|
||||
parking_lot = "0.12"
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
use crate::tree::LinkEntry;
|
||||
use std::{collections::HashSet, num::NonZeroUsize, time::Duration};
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
num::{NonZeroU32, NonZeroUsize},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -21,7 +25,7 @@ pub struct DnsDiscoveryConfig {
|
||||
/// Default: 30min
|
||||
pub recheck_interval: Duration,
|
||||
/// Maximum number of cached DNS records.
|
||||
pub dns_record_cache_limit: NonZeroUsize,
|
||||
pub dns_record_cache_limit: NonZeroU32,
|
||||
/// Links to the DNS networks to bootstrap.
|
||||
pub bootstrap_dns_networks: Option<HashSet<LinkEntry>>,
|
||||
}
|
||||
@ -32,7 +36,7 @@ impl Default for DnsDiscoveryConfig {
|
||||
lookup_timeout: Duration::from_secs(5),
|
||||
max_requests_per_sec: NonZeroUsize::new(3).unwrap(),
|
||||
recheck_interval: Duration::from_secs(60 * 30),
|
||||
dns_record_cache_limit: NonZeroUsize::new(1_000).unwrap(),
|
||||
dns_record_cache_limit: NonZeroU32::new(1_000).unwrap(),
|
||||
bootstrap_dns_networks: Some(Default::default()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,8 +16,8 @@ use crate::{
|
||||
pub use config::DnsDiscoveryConfig;
|
||||
use enr::Enr;
|
||||
use error::ParseDnsEntryError;
|
||||
use lru::LruCache;
|
||||
use reth_primitives::{ForkId, NodeRecord, PeerId};
|
||||
use schnellru::{ByLength, LruMap};
|
||||
use secp256k1::SecretKey;
|
||||
use std::{
|
||||
collections::{hash_map::Entry, HashMap, HashSet, VecDeque},
|
||||
@ -95,7 +95,7 @@ pub struct DnsDiscoveryService<R: Resolver = DnsResolver> {
|
||||
/// All queries currently in progress
|
||||
queries: QueryPool<R, SecretKey>,
|
||||
/// Cached dns records
|
||||
dns_record_cache: LruCache<String, DnsEntry<SecretKey>>,
|
||||
dns_record_cache: LruMap<String, DnsEntry<SecretKey>>,
|
||||
/// all buffered events
|
||||
queued_events: VecDeque<DnsDiscoveryEvent>,
|
||||
/// The rate at which trees should be updated.
|
||||
@ -133,7 +133,7 @@ impl<R: Resolver> DnsDiscoveryService<R> {
|
||||
node_record_listeners: Default::default(),
|
||||
trees: Default::default(),
|
||||
queries,
|
||||
dns_record_cache: LruCache::new(dns_record_cache_limit),
|
||||
dns_record_cache: LruMap::new(ByLength::new(dns_record_cache_limit.get())),
|
||||
queued_events: Default::default(),
|
||||
recheck_interval,
|
||||
bootstrap_dns_networks: bootstrap_dns_networks.unwrap_or_default(),
|
||||
@ -250,7 +250,7 @@ impl<R: Resolver> DnsDiscoveryService<R> {
|
||||
}
|
||||
Some(Ok(entry)) => {
|
||||
// cache entry
|
||||
self.dns_record_cache.push(hash.clone(), entry.clone());
|
||||
self.dns_record_cache.insert(hash.clone(), entry.clone());
|
||||
|
||||
match entry {
|
||||
DnsEntry::Root(root) => {
|
||||
|
||||
Reference in New Issue
Block a user