Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2093,7 +2093,7 @@ impl Backend {
hash: B256,
) -> Result<Vec<Log>, BlockchainError> {
if let Some(block) = self.blockchain.get_block_by_hash(&hash) {
return Ok(self.mined_logs_for_block(filter, block));
return Ok(self.mined_logs_for_block(filter, block, hash));
}

if let Some(fork) = self.get_fork() {
Expand All @@ -2104,9 +2104,8 @@ impl Backend {
}

/// Returns all `Log`s mined by the node that were emitted in the `block` and match the `Filter`
fn mined_logs_for_block(&self, filter: Filter, block: Block) -> Vec<Log> {
fn mined_logs_for_block(&self, filter: Filter, block: Block, block_hash: B256) -> Vec<Log> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

let mut all_logs = Vec::new();
let block_hash = block.header.hash_slow();
let mut block_log_index = 0u32;

let storage = self.blockchain.storage.read();
Expand Down Expand Up @@ -2167,8 +2166,12 @@ impl Backend {
}

for number in from..=to {
if let Some(block) = self.get_block(number) {
all_logs.extend(self.mined_logs_for_block(filter.clone(), block));
let storage = self.blockchain.storage.read();
if let Some(&block_hash) = storage.hashes.get(&number)
&& let Some(block) = storage.blocks.get(&block_hash).cloned()
{
drop(storage);
all_logs.extend(self.mined_logs_for_block(filter.clone(), block, block_hash));
Copy link
Contributor

@onbjerg onbjerg Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idt this change makes sense, using get_block is fine, what is the reasoning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change avoids redundant hash_slow() calls. get_block(number) internally does hashes.get(&number) + blocks.get(&hash) but discards the hash, forcing mined_logs_for_block to recompute it via expensive RLP encoding + Keccak256.

}
}

Expand Down
Loading