Skip to content

Commit

Permalink
chore: share provider on find_canonical_header (paradigmxyz#3122)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshieDo authored Jun 13, 2023
1 parent 790b443 commit e15805d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions crates/blockchain-tree/src/blockchain_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ impl<DB: Database, C: Consensus, EF: ExecutorFactory> BlockchainTree<DB, C, EF>
// https://github.com/paradigmxyz/reth/issues/1713

let (block_status, chain) = {
let db = self.externals.database();
let provider = db
let factory = self.externals.database();
let provider = factory
.provider()
.map_err(|err| InsertBlockError::new(block.block.clone(), err.into()))?;

Expand Down Expand Up @@ -829,17 +829,20 @@ impl<DB: Database, C: Consensus, EF: ExecutorFactory> BlockchainTree<DB, C, EF>
// canonical, but in the db. If it is in a sidechain, it is not canonical. If it is not in
// the db, then it is not canonical.

let factory = self.externals.database();
let provider = factory.provider()?;

let mut header = None;
if let Some(num) = self.block_indices.get_canonical_block_number(hash) {
header = self.externals.database().provider()?.header_by_number(num)?;
header = provider.header_by_number(num)?;
}

if header.is_none() && self.is_block_hash_inside_chain(*hash) {
return Ok(None)
}

if header.is_none() {
header = self.externals.database().provider()?.header(hash)?
header = provider.header(hash)?
}

Ok(header.map(|header| header.seal(*hash)))
Expand Down

0 comments on commit e15805d

Please sign in to comment.