perf: read ChainInfo from in-memory canonical block (#2669)

This commit is contained in:
Matthias Seitz
2023-05-15 15:45:13 +02:00
committed by GitHub
parent 5d99b126ee
commit 7292384913
2 changed files with 8 additions and 2 deletions

View File

@@ -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());

View File

@@ -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> {