Skip to content
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

fix: total difficulty fallback for remote blocks #697

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mighty-turtles-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nomicfoundation/edr": patch
---

Fix panic due to remote nodes not returning total difficulty
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/edr_defaults/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.3.5"
edition = "2021"

[dependencies]
ruint = "1.12.3"

[lints]
workspace = true
5 changes: 5 additions & 0 deletions crates/edr_defaults/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use ruint::aliases::U256;

/// The default secret keys from which the local accounts will be derived.
pub const SECRET_KEYS: [&str; 20] = [
// these were taken from the standard output of a run of `hardhat node`
Expand Down Expand Up @@ -36,3 +38,6 @@ pub const MIX_HASH_SEED: &str = "randomMixHashSeed";

/// Seed value for the generator of state root hashes.
pub const STATE_ROOT_HASH_SEED: &str = "seed";

/// Terminal total difficulty for the Merge on main net
pub const TERMINAL_TOTAL_DIFFICULTY: U256 = ruint::uint!(58750000000000000000000_U256);
12 changes: 10 additions & 2 deletions crates/edr_evm/src/blockchain/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,13 @@ where
.get_block_by_hash_with_transaction_data(*hash)
.await?
{
// Geth has recently removed the total difficulty field from block RPC
// responses, so we fall back to the terminal total difficulty of main net to
// provide backwards compatibility.
// TODO https://github.com/NomicFoundation/edr/issues/696
let total_difficulty = *block
.total_difficulty()
.expect("Must be present as this is not a pending transaction");
.unwrap_or(&edr_defaults::TERMINAL_TOTAL_DIFFICULTY);

self.fetch_and_cache_block(cache, block).await?;

Expand All @@ -227,9 +231,13 @@ where
cache: RwLockUpgradableReadGuard<'_, SparseBlockchainStorage<BlockT, ChainSpecT>>,
block: ChainSpecT::RpcBlock<ChainSpecT::RpcTransaction>,
) -> Result<BlockT, ForkedBlockchainError> {
// Geth has recently removed the total difficulty field from block RPC
// responses, so we fall back to the terminal total difficulty of main net to
// provide backwards compatibility.
// TODO https://github.com/NomicFoundation/edr/issues/696
let total_difficulty = *block
.total_difficulty()
.expect("Must be present as this is not a pending block");
.unwrap_or(&edr_defaults::TERMINAL_TOTAL_DIFFICULTY);

let block: RemoteBlock<ChainSpecT> =
block.into_remote_block(self.client.clone(), self.runtime.clone())?;
Expand Down
Loading