Skip to content

Commit f9fc929

Browse files
ipatkamattsse
andauthored
Add check for post merge and don't add difficulty (#5236)
* account for merge * overwrite * fix * follow naming convention * skip set post merge * rustfmt --------- Co-authored-by: Matthias Seitz <[email protected]>
1 parent ac5d367 commit f9fc929

File tree

1 file changed

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

1 file changed

+11
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,11 @@ impl Backend {
508508
(self.spec_id() as u8) >= (SpecId::LONDON as u8)
509509
}
510510

511+
/// Returns true for post Merge
512+
pub fn is_eip3675(&self) -> bool {
513+
(self.spec_id() as u8) >= (SpecId::MERGE as u8)
514+
}
515+
511516
/// Returns true for post Berlin
512517
pub fn is_eip2930(&self) -> bool {
513518
(self.spec_id() as u8) >= (SpecId::BERLIN as u8)
@@ -842,7 +847,12 @@ impl Backend {
842847
// update block metadata
843848
storage.best_number = block_number;
844849
storage.best_hash = block_hash;
845-
storage.total_difficulty = storage.total_difficulty.saturating_add(header.difficulty);
850+
// Difficulty is removed and not used after Paris (aka TheMerge). Value is replaced with
851+
// prevrandao. https://github.com/bluealloy/revm/blob/1839b3fce8eaeebb85025576f2519b80615aca1e/crates/interpreter/src/instructions/host_env.rs#L27
852+
if !self.is_eip3675() {
853+
storage.total_difficulty =
854+
storage.total_difficulty.saturating_add(header.difficulty);
855+
}
846856

847857
storage.blocks.insert(block_hash, block);
848858
storage.hashes.insert(block_number, block_hash);

0 commit comments

Comments
 (0)