Skip to content

Commit

Permalink
feat(tree): introduce executed_block_by_hash
Browse files Browse the repository at this point in the history
  • Loading branch information
Rjected committed Aug 27, 2024
1 parent 82af0cf commit aa176ea
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ impl TreeState {
self.blocks_by_hash.len()
}

/// Returns the [`ExecutedBlock`] by hash.
fn executed_block_by_hash(&self, hash: B256) -> Option<&ExecutedBlock> {
self.blocks_by_hash.get(&hash)
}

/// Returns the block by hash.
fn block_by_hash(&self, hash: B256) -> Option<Arc<SealedBlock>> {
self.blocks_by_hash.get(&hash).map(|b| b.block.clone())
Expand Down Expand Up @@ -1363,6 +1368,25 @@ where
.remove_persisted_blocks(self.persistence_state.last_persisted_block_number);
}

/// Return an [`ExecutedBlock`] from database or in-memory state by hash.
fn executed_block_by_hash(&self, hash: B256) -> ProviderResult<Option<ExecutedBlock>> {
// check memory first
let block = self
.state
.tree_state
.executed_block_by_hash(hash)
// TODO: clone for compatibility. should we return an Arc here?
.cloned();

if block.is_some() {
Ok(block)
} else if let Some(_block_num) = self.provider.block_number(hash)? {
unimplemented!("fetching on-disk executed blocks is not supported yet")
} else {
Ok(None)
}
}

/// Return sealed block from database or in-memory state by hash.
fn sealed_header_by_hash(&self, hash: B256) -> ProviderResult<Option<SealedHeader>> {
// check memory first
Expand Down Expand Up @@ -1731,7 +1755,7 @@ where
///
/// This is invoked on a valid forkchoice update, or if we can make the target block canonical.
fn on_canonical_chain_update(&mut self, chain_update: NewCanonicalChain) {
trace!(target: "engine", new_blocks = %chain_update.new_block_count(), reorged_blocks = %chain_update.reorged_block_count() ,"applying new chain update");
trace!(target: "engine", new_blocks = %chain_update.new_block_count(), reorged_blocks = %chain_update.reorged_block_count(), "applying new chain update");
let start = Instant::now();

// update the tracked canonical head
Expand Down

0 comments on commit aa176ea

Please sign in to comment.