Skip to content

Commit bd72b05

Browse files
authored
fix: set next block timestamp as late as possible (#8311)
1 parent 21c40c7 commit bd72b05

File tree

1 file changed

+6
-1
lines changed
  • crates/anvil/src/eth/backend/mem

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,6 @@ impl Backend {
939939
env.block.number = env.block.number.saturating_add(U256::from(1));
940940
env.block.basefee = U256::from(current_base_fee);
941941
env.block.blob_excess_gas_and_price = current_excess_blob_gas_and_price;
942-
env.block.timestamp = U256::from(self.time.next_timestamp());
943942

944943
// pick a random value for prevrandao
945944
env.block.prevrandao = Some(B256::random());
@@ -954,6 +953,12 @@ impl Backend {
954953

955954
let (executed_tx, block_hash) = {
956955
let mut db = self.db.write().await;
956+
957+
// finally set the next block timestamp, this is done just before execution, because
958+
// there can be concurrent requests that can delay acquiring the db lock and we want
959+
// to ensure the timestamp is as close as possible to the actual execution.
960+
env.block.timestamp = U256::from(self.time.next_timestamp());
961+
957962
let executor = TransactionExecutor {
958963
db: &mut *db,
959964
validator: self,

0 commit comments

Comments
 (0)