mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 02:49:55 +00:00
fix: Do not use LruMap
LruMap does not support backfill.
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
use std::{
|
use std::{
|
||||||
|
collections::HashMap,
|
||||||
io::{BufRead, BufReader, Read, Seek, SeekFrom},
|
io::{BufRead, BufReader, Read, Seek, SeekFrom},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
@ -6,7 +7,6 @@ use std::{
|
|||||||
|
|
||||||
use eyre::Context;
|
use eyre::Context;
|
||||||
use futures::future::BoxFuture;
|
use futures::future::BoxFuture;
|
||||||
use reth_network::cache::LruMap;
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use time::{format_description, Duration, OffsetDateTime};
|
use time::{format_description, Duration, OffsetDateTime};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
@ -20,11 +20,8 @@ use super::{BlockSource, BlockSourceBoxed};
|
|||||||
const TAIL_INTERVAL: std::time::Duration = std::time::Duration::from_millis(25);
|
const TAIL_INTERVAL: std::time::Duration = std::time::Duration::from_millis(25);
|
||||||
/// Sub‑directory that contains day folders (inside `local_ingest_dir`).
|
/// Sub‑directory that contains day folders (inside `local_ingest_dir`).
|
||||||
const HOURLY_SUBDIR: &str = "hourly";
|
const HOURLY_SUBDIR: &str = "hourly";
|
||||||
/// Maximum number of blocks to cache blocks from hl-node.
|
|
||||||
/// In normal situation, 0~1 blocks will be cached.
|
|
||||||
const CACHE_SIZE: u32 = 1000;
|
|
||||||
|
|
||||||
type LocalBlocksCache = Arc<Mutex<LruMap<u64, BlockAndReceipts>>>;
|
type LocalBlocksCache = Arc<Mutex<HashMap<u64, BlockAndReceipts>>>;
|
||||||
|
|
||||||
/// Block source that monitors the local ingest directory for the HL node.
|
/// Block source that monitors the local ingest directory for the HL node.
|
||||||
///
|
///
|
||||||
@ -223,7 +220,10 @@ impl HlNodeBlockSource {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
warn!("Failed to parse last line of file, fallback to slow path: {:?}", subfile);
|
warn!(
|
||||||
|
"Failed to parse last line of file, fallback to slow path: {:?}",
|
||||||
|
subfile
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let ScanResult { next_expected_height, new_blocks } =
|
let ScanResult { next_expected_height, new_blocks } =
|
||||||
@ -308,11 +308,15 @@ impl HlNodeBlockSource {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn new(fallback: BlockSourceBoxed, local_ingest_dir: PathBuf, next_block_number: u64) -> Self {
|
pub async fn new(
|
||||||
|
fallback: BlockSourceBoxed,
|
||||||
|
local_ingest_dir: PathBuf,
|
||||||
|
next_block_number: u64,
|
||||||
|
) -> Self {
|
||||||
let block_source = HlNodeBlockSource {
|
let block_source = HlNodeBlockSource {
|
||||||
fallback,
|
fallback,
|
||||||
local_ingest_dir,
|
local_ingest_dir,
|
||||||
local_blocks_cache: Arc::new(Mutex::new(LruMap::new(CACHE_SIZE))),
|
local_blocks_cache: Arc::new(Mutex::new(HashMap::new())),
|
||||||
};
|
};
|
||||||
block_source.run(next_block_number).await.unwrap();
|
block_source.run(next_block_number).await.unwrap();
|
||||||
block_source
|
block_source
|
||||||
|
|||||||
Reference in New Issue
Block a user