-
Notifications
You must be signed in to change notification settings - Fork 2.2k
perf(anvil): optimize internal data passing in log queries #11896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() { | ||
|
@@ -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> { | ||
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(); | ||
|
@@ -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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. idt this change makes sense, using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The change avoids redundant |
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍