diff --git a/crates/engine/local/src/miner.rs b/crates/engine/local/src/miner.rs index 604965d3ca3..46d2ee49c38 100644 --- a/crates/engine/local/src/miner.rs +++ b/crates/engine/local/src/miner.rs @@ -13,6 +13,7 @@ use reth_payload_primitives::{ use reth_provider::BlockReader; use reth_transaction_pool::TransactionPool; use std::{ + collections::VecDeque, future::Future, pin::Pin, task::{Context, Poll}, @@ -108,7 +109,7 @@ pub struct LocalMiner { /// Timestamp for the next block. last_timestamp: u64, /// Stores latest mined blocks. - last_block_hashes: Vec, + last_block_hashes: VecDeque, } impl LocalMiner @@ -134,7 +135,7 @@ where mode, payload_builder, last_timestamp: latest_header.timestamp(), - last_block_hashes: vec![latest_header.hash()], + last_block_hashes: VecDeque::from([latest_header.hash()]), } } @@ -162,7 +163,7 @@ where /// Returns current forkchoice state. fn forkchoice_state(&self) -> ForkchoiceState { ForkchoiceState { - head_block_hash: *self.last_block_hashes.last().expect("at least 1 block exists"), + head_block_hash: *self.last_block_hashes.back().expect("at least 1 block exists"), safe_block_hash: *self .last_block_hashes .get(self.last_block_hashes.len().saturating_sub(32)) @@ -230,11 +231,10 @@ where } self.last_timestamp = timestamp; - self.last_block_hashes.push(block.hash()); + self.last_block_hashes.push_back(block.hash()); // ensure we keep at most 64 blocks if self.last_block_hashes.len() > 64 { - self.last_block_hashes = - self.last_block_hashes.split_off(self.last_block_hashes.len() - 64); + self.last_block_hashes.pop_front(); } Ok(())