mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-29 17:18:08 -05:00
perf: read ChainInfo from in-memory canonical block (#2669)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use parking_lot::RwLock;
|
||||
use reth_primitives::{BlockNumHash, SealedHeader};
|
||||
use reth_primitives::{BlockNumHash, ChainInfo, SealedHeader};
|
||||
use std::{sync::Arc, time::Instant};
|
||||
|
||||
/// Tracks the chain info: canonical head, safe block, finalized block.
|
||||
@@ -21,6 +21,12 @@ impl ChainInfoTracker {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the [ChainInfo] for the canonical head.
|
||||
pub(crate) fn chain_info(&self) -> ChainInfo {
|
||||
let inner = self.inner.canonical_head.read();
|
||||
ChainInfo { best_hash: inner.hash(), best_number: inner.number }
|
||||
}
|
||||
|
||||
/// Update the timestamp when we received a forkchoice update.
|
||||
pub(crate) fn on_forkchoice_update_received(&self) {
|
||||
self.inner.last_forkchoice_update.write().replace(Instant::now());
|
||||
|
||||
@@ -120,7 +120,7 @@ where
|
||||
Tree: BlockchainTreeViewer + Send + Sync,
|
||||
{
|
||||
fn chain_info(&self) -> Result<ChainInfo> {
|
||||
self.database.chain_info()
|
||||
Ok(self.chain_info.chain_info())
|
||||
}
|
||||
|
||||
fn best_block_number(&self) -> Result<BlockNumber> {
|
||||
|
||||
Reference in New Issue
Block a user