mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
fix: hit database first for lookups (#4127)
This commit is contained in:
@ -209,12 +209,12 @@ where
|
||||
fn find_block_by_hash(&self, hash: H256, source: BlockSource) -> Result<Option<Block>> {
|
||||
let block = match source {
|
||||
BlockSource::Any => {
|
||||
// check pending source first
|
||||
// Note: it's fine to return the unsealed block because the caller already has the
|
||||
// hash
|
||||
let mut block = self.tree.block_by_hash(hash).map(|block| block.unseal());
|
||||
// check database first
|
||||
let mut block = self.database.provider()?.block_by_hash(hash)?;
|
||||
if block.is_none() {
|
||||
block = self.database.provider()?.block_by_hash(hash)?;
|
||||
// Note: it's fine to return the unsealed block because the caller already has
|
||||
// the hash
|
||||
block = self.tree.block_by_hash(hash).map(|block| block.unseal());
|
||||
}
|
||||
block
|
||||
}
|
||||
@ -541,14 +541,17 @@ where
|
||||
|
||||
fn state_by_block_hash(&self, block: BlockHash) -> Result<StateProviderBox<'_>> {
|
||||
trace!(target: "providers::blockchain", ?block, "Getting state by block hash");
|
||||
let mut state = self.history_by_block_hash(block);
|
||||
|
||||
// check tree first
|
||||
if let Some(pending) = self.tree.find_pending_state_provider(block) {
|
||||
trace!(target: "providers::blockchain", "Returning pending state provider");
|
||||
return self.pending_with_provider(pending)
|
||||
// we failed to get the state by hash, from disk, hash block be the pending block
|
||||
if state.is_err() {
|
||||
if let Ok(Some(pending)) = self.pending_state_by_hash(block) {
|
||||
// we found pending block by hash
|
||||
state = Ok(pending)
|
||||
}
|
||||
}
|
||||
// not found in tree, check database
|
||||
self.history_by_block_hash(block)
|
||||
|
||||
state
|
||||
}
|
||||
|
||||
/// Storage provider for pending state.
|
||||
@ -658,6 +661,10 @@ where
|
||||
self.tree.find_canonical_ancestor(hash)
|
||||
}
|
||||
|
||||
fn is_canonical(&self, hash: BlockHash) -> std::result::Result<bool, Error> {
|
||||
self.tree.is_canonical(hash)
|
||||
}
|
||||
|
||||
fn lowest_buffered_ancestor(&self, hash: BlockHash) -> Option<SealedBlockWithSenders> {
|
||||
self.tree.lowest_buffered_ancestor(hash)
|
||||
}
|
||||
@ -666,10 +673,6 @@ where
|
||||
self.tree.canonical_tip()
|
||||
}
|
||||
|
||||
fn is_canonical(&self, hash: BlockHash) -> std::result::Result<bool, Error> {
|
||||
self.tree.is_canonical(hash)
|
||||
}
|
||||
|
||||
fn pending_blocks(&self) -> (BlockNumber, Vec<BlockHash>) {
|
||||
self.tree.pending_blocks()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user