mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-09 07:17:56 -05:00
fix(rpc): fix eth_config impl (#18744)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
committed by
Alexey Shekhirin
parent
611c307213
commit
12794769c1
@@ -323,7 +323,7 @@ async fn test_eth_config() -> eyre::Result<()> {
|
||||
|
||||
let config = provider.client().request_noparams::<EthConfig>("eth_config").await?;
|
||||
|
||||
assert_eq!(config.last.unwrap().activation_time, 0);
|
||||
assert_eq!(config.last.unwrap().activation_time, osaka_timestamp);
|
||||
assert_eq!(config.current.activation_time, prague_timestamp);
|
||||
assert_eq!(config.next.unwrap().activation_time, osaka_timestamp);
|
||||
|
||||
|
||||
@@ -12,8 +12,7 @@ use reth_node_api::NodePrimitives;
|
||||
use reth_revm::db::EmptyDB;
|
||||
use reth_rpc_eth_types::EthApiError;
|
||||
use reth_storage_api::BlockReaderIdExt;
|
||||
use revm::precompile::PrecompileId;
|
||||
use std::{borrow::Borrow, collections::BTreeMap};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
#[cfg_attr(not(feature = "client"), rpc(server, namespace = "eth"))]
|
||||
#[cfg_attr(feature = "client", rpc(server, client, namespace = "eth"))]
|
||||
@@ -100,6 +99,7 @@ where
|
||||
|
||||
let mut fork_timestamps =
|
||||
chain_spec.forks_iter().filter_map(|(_, cond)| cond.as_timestamp()).collect::<Vec<_>>();
|
||||
fork_timestamps.sort_unstable();
|
||||
fork_timestamps.dedup();
|
||||
|
||||
let (current_fork_idx, current_fork_timestamp) = fork_timestamps
|
||||
@@ -116,26 +116,9 @@ where
|
||||
|
||||
let mut config = EthConfig { current, next: None, last: None };
|
||||
|
||||
if let Some(last_fork_idx) = current_fork_idx.checked_sub(1) &&
|
||||
let Some(last_fork_timestamp) = fork_timestamps.get(last_fork_idx).copied()
|
||||
{
|
||||
let fake_header = {
|
||||
let mut header = latest.clone();
|
||||
header.timestamp = last_fork_timestamp;
|
||||
header
|
||||
};
|
||||
let last_precompiles = evm_to_precompiles_map(
|
||||
self.evm_config
|
||||
.evm_for_block(EmptyDB::default(), &fake_header)
|
||||
.map_err(RethError::other)?,
|
||||
);
|
||||
|
||||
config.last = self.build_fork_config_at(last_fork_timestamp, last_precompiles);
|
||||
}
|
||||
|
||||
if let Some(next_fork_timestamp) = fork_timestamps.get(current_fork_idx + 1).copied() {
|
||||
let fake_header = {
|
||||
let mut header = latest;
|
||||
let mut header = latest.clone();
|
||||
header.timestamp = next_fork_timestamp;
|
||||
header
|
||||
};
|
||||
@@ -146,8 +129,25 @@ where
|
||||
);
|
||||
|
||||
config.next = self.build_fork_config_at(next_fork_timestamp, next_precompiles);
|
||||
} else {
|
||||
// If there is no fork scheduled, there is no "last" or "final" fork scheduled.
|
||||
return Ok(config);
|
||||
}
|
||||
|
||||
let last_fork_timestamp = fork_timestamps.last().copied().unwrap();
|
||||
let fake_header = {
|
||||
let mut header = latest;
|
||||
header.timestamp = last_fork_timestamp;
|
||||
header
|
||||
};
|
||||
let last_precompiles = evm_to_precompiles_map(
|
||||
self.evm_config
|
||||
.evm_for_block(EmptyDB::default(), &fake_header)
|
||||
.map_err(RethError::other)?,
|
||||
);
|
||||
|
||||
config.last = self.build_fork_config_at(last_fork_timestamp, last_precompiles);
|
||||
|
||||
Ok(config)
|
||||
}
|
||||
}
|
||||
@@ -171,33 +171,7 @@ fn evm_to_precompiles_map(
|
||||
precompiles
|
||||
.addresses()
|
||||
.filter_map(|address| {
|
||||
Some((precompile_to_str(precompiles.get(address)?.precompile_id()), *address))
|
||||
Some((precompiles.get(address)?.precompile_id().name().to_string(), *address))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
// TODO: move
|
||||
fn precompile_to_str(id: &PrecompileId) -> String {
|
||||
let str = match id {
|
||||
PrecompileId::EcRec => "ECREC",
|
||||
PrecompileId::Sha256 => "SHA256",
|
||||
PrecompileId::Ripemd160 => "RIPEMD160",
|
||||
PrecompileId::Identity => "ID",
|
||||
PrecompileId::ModExp => "MODEXP",
|
||||
PrecompileId::Bn254Add => "BN254_ADD",
|
||||
PrecompileId::Bn254Mul => "BN254_MUL",
|
||||
PrecompileId::Bn254Pairing => "BN254_PAIRING",
|
||||
PrecompileId::Blake2F => "BLAKE2F",
|
||||
PrecompileId::KzgPointEvaluation => "KZG_POINT_EVALUATION",
|
||||
PrecompileId::Bls12G1Add => "BLS12_G1ADD",
|
||||
PrecompileId::Bls12G1Msm => "BLS12_G1MSM",
|
||||
PrecompileId::Bls12G2Add => "BLS12_G2ADD",
|
||||
PrecompileId::Bls12G2Msm => "BLS12_G2MSM",
|
||||
PrecompileId::Bls12Pairing => "BLS12_PAIRING_CHECK",
|
||||
PrecompileId::Bls12MapFpToGp1 => "BLS12_MAP_FP_TO_G1",
|
||||
PrecompileId::Bls12MapFp2ToGp2 => "BLS12_MAP_FP2_TO_G2",
|
||||
PrecompileId::P256Verify => "P256_VERIFY",
|
||||
PrecompileId::Custom(custom) => custom.borrow(),
|
||||
};
|
||||
str.to_owned()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user