mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
active block sharing
This commit is contained in:
@ -29,6 +29,7 @@ use tokio::sync::Mutex;
|
||||
use tracing::{debug, info};
|
||||
|
||||
use crate::serialized::{BlockAndReceipts, EvmBlock};
|
||||
use crate::share_blocks::ShareBlocks;
|
||||
use crate::spot_meta::erc20_contract_to_spot_token;
|
||||
|
||||
/// Poll interval when tailing an *open* hourly file.
|
||||
@ -41,6 +42,7 @@ pub(crate) struct BlockIngest {
|
||||
pub local_ingest_dir: Option<PathBuf>,
|
||||
pub local_blocks_cache: Arc<Mutex<BTreeMap<u64, BlockAndReceipts>>>, // height → block
|
||||
pub precompiles_cache: PrecompilesCache,
|
||||
pub hlfs: Option<ShareBlocks>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@ -155,9 +157,20 @@ impl BlockIngest {
|
||||
if let Some(block) = self.try_collect_local_block(height).await {
|
||||
info!("Returning locally synced block for @ Height [{height}]");
|
||||
return Some(block);
|
||||
} else {
|
||||
self.try_collect_s3_block(height)
|
||||
}
|
||||
|
||||
if let Some(hlfs) = &self.hlfs {
|
||||
let u_cache = self.local_blocks_cache.lock().await;
|
||||
let head = u_cache.keys().next_back().copied().unwrap_or(0);
|
||||
if hlfs.try_fetch_one(height, head).await.ok().flatten().is_some() {
|
||||
if let Some(block) = self.try_collect_local_block(height).await {
|
||||
info!("Returning HLFS-fetched block @[{height}]");
|
||||
return Some(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.try_collect_s3_block(height)
|
||||
}
|
||||
|
||||
pub(crate) fn try_collect_s3_block(&self, height: u64) -> Option<BlockAndReceipts> {
|
||||
|
||||
@ -92,15 +92,23 @@ fn main() {
|
||||
.await?;
|
||||
|
||||
// start HLFS (serve + peer-backed backfill) using the node's network
|
||||
if ext_args.hlfs.share_blocks {
|
||||
let net = handle.node.network.clone(); // returns a FullNetwork (NetworkHandle under the hood)
|
||||
// keep handle alive for the whole process
|
||||
let _hlfs =
|
||||
share_blocks::ShareBlocks::start_with_network(&ext_args.hlfs, net).await?;
|
||||
}
|
||||
let hlfs = if ext_args.hlfs.share_blocks {
|
||||
let net = handle.node.network.clone();
|
||||
Some(
|
||||
crate::share_blocks::ShareBlocks::start_with_network(&ext_args.hlfs, net)
|
||||
.await?,
|
||||
)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let ingest =
|
||||
BlockIngest { ingest_dir, local_ingest_dir, local_blocks_cache, precompiles_cache };
|
||||
let ingest = BlockIngest {
|
||||
ingest_dir,
|
||||
local_ingest_dir,
|
||||
local_blocks_cache,
|
||||
precompiles_cache,
|
||||
hlfs,
|
||||
};
|
||||
ingest.run(handle.node).await.unwrap();
|
||||
handle.node_exit_future.await
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user