Skip to content

Commit 58297d3

Browse files
authored
perf: find latest block for next-base-fee. replaces #10505 (#10511)
* perf: find latest block for next-base-fee. replaces #10505 * wip
1 parent 0a7b3f0 commit 58297d3

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

crates/anvil/src/eth/backend/mem/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,8 +1006,8 @@ impl Backend {
10061006
}
10071007
}
10081008

1009-
if let Some(block) = state.blocks.last() {
1010-
let header = &block.header;
1009+
if let Some(latest) = state.blocks.iter().max_by_key(|b| b.header.number) {
1010+
let header = &latest.header;
10111011
let next_block_base_fee = self.fees.get_next_block_base_fee_per_gas(
10121012
header.gas_used as u128,
10131013
header.gas_limit as u128,

crates/anvil/src/eth/backend/mem/storage.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -409,13 +409,7 @@ impl BlockchainStorage {
409409
}
410410

411411
pub fn serialized_blocks(&self) -> Vec<SerializableBlock> {
412-
let mut blocks = self
413-
.blocks
414-
.values()
415-
.map(|block| block.clone().into())
416-
.collect::<Vec<SerializableBlock>>();
417-
blocks.sort_by_key(|block| block.header.number);
418-
blocks
412+
self.blocks.values().map(|block| block.clone().into()).collect()
419413
}
420414

421415
pub fn serialized_transactions(&self) -> Vec<SerializableTransaction> {

0 commit comments

Comments
 (0)