Skip to content
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
6 changes: 5 additions & 1 deletion bin/reth/tests/commands/bitfinity_node_it.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use reth::{
args::{DatadirArgs, RpcServerArgs},
dirs::{DataDirPath, MaybePlatformPath},
};
use reth_chainspec::bitfinity_spec::BitfinitySpec;
use reth_consensus::FullConsensus;
use reth_db::test_utils::TempDatabase;
use reth_db::DatabaseEnv;
Expand Down Expand Up @@ -339,7 +340,10 @@ pub async fn start_reth_node(
node_config.dev.dev = false;

let mut chain = node_config.chain.as_ref().clone();
chain.bitfinity_evm_url = bitfinity_evm_url;
chain.bitfinity_spec = BitfinitySpec {
rpc_url: bitfinity_evm_url.to_owned().unwrap_or_default(),
send_transaction_url: Some(bitfinity_evm_url.unwrap_or_default()),
};
let mut node_config = node_config.with_chain(chain);

let database = if let Some(import_data) = import_data {
Expand Down
8 changes: 8 additions & 0 deletions crates/chainspec/src/bitfinity_spec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/// Bitfinity specific configuration
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct BitfinitySpec {
/// URL of the Bitfinity EVM node
pub rpc_url: String,
/// Send transaction to the Bitfinity EVM node
pub send_transaction_url: Option<String>,
}
1 change: 1 addition & 0 deletions crates/chainspec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ extern crate alloc;

/// Chain specific constants
mod constants;
pub mod bitfinity_spec;
pub use constants::*;

mod api;
Expand Down
33 changes: 17 additions & 16 deletions crates/chainspec/src/spec.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub use alloy_eips::eip1559::BaseFeeParams;
use alloy_evm::eth::spec::EthExecutorSpec;

use crate::bitfinity_spec::BitfinitySpec;
use crate::{
constants::{MAINNET_DEPOSIT_CONTRACT, MAINNET_PRUNE_DELETE_LIMIT},
EthChainSpec,
Expand Down Expand Up @@ -113,7 +114,7 @@ pub static MAINNET: LazyLock<Arc<ChainSpec>> = LazyLock::new(|| {
base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()),
prune_delete_limit: MAINNET_PRUNE_DELETE_LIMIT,
blob_params: HardforkBlobParams::default(),
bitfinity_evm_url: Default::default(),
bitfinity_spec: Default::default(),
};
spec.genesis.config.dao_fork_support = true;
spec.into()
Expand Down Expand Up @@ -143,7 +144,7 @@ pub static SEPOLIA: LazyLock<Arc<ChainSpec>> = LazyLock::new(|| {
base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()),
prune_delete_limit: 10000,
blob_params: HardforkBlobParams::default(),
bitfinity_evm_url: Default::default(),
bitfinity_spec: Default::default(),
};
spec.genesis.config.dao_fork_support = true;
spec.into()
Expand Down Expand Up @@ -171,7 +172,7 @@ pub static HOLESKY: LazyLock<Arc<ChainSpec>> = LazyLock::new(|| {
base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()),
prune_delete_limit: 10000,
blob_params: HardforkBlobParams::default(),
bitfinity_evm_url: Default::default(),
bitfinity_spec: Default::default(),
};
spec.genesis.config.dao_fork_support = true;
spec.into()
Expand Down Expand Up @@ -201,7 +202,7 @@ pub static HOODI: LazyLock<Arc<ChainSpec>> = LazyLock::new(|| {
base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()),
prune_delete_limit: 10000,
blob_params: HardforkBlobParams::default(),
bitfinity_evm_url: Default::default(),
bitfinity_spec: Default::default(),
};
spec.genesis.config.dao_fork_support = true;
spec.into()
Expand Down Expand Up @@ -335,9 +336,9 @@ pub struct ChainSpec {

/// The settings passed for blob configurations for specific hardforks.
pub blob_params: HardforkBlobParams,
/// The URL of the Bitfinity EVM RPC endpoint
pub bitfinity_evm_url: Option<String>,

/// Bitfinity Specific Configuration
pub bitfinity_spec: BitfinitySpec,
}

impl Default for ChainSpec {
Expand All @@ -352,7 +353,7 @@ impl Default for ChainSpec {
base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()),
prune_delete_limit: MAINNET_PRUNE_DELETE_LIMIT,
blob_params: Default::default(),
bitfinity_evm_url: Default::default(),
bitfinity_spec: Default::default(),
}
}
}
Expand Down Expand Up @@ -423,7 +424,7 @@ impl ChainSpec {
// given timestamp.
for (fork, params) in bf_params.iter().rev() {
if self.hardforks.is_fork_active_at_timestamp(fork.clone(), timestamp) {
return *params
return *params;
}
}

Expand All @@ -442,7 +443,7 @@ impl ChainSpec {
// given timestamp.
for (fork, params) in bf_params.iter().rev() {
if self.hardforks.is_fork_active_at_block(fork.clone(), block_number) {
return *params
return *params;
}
}

Expand Down Expand Up @@ -516,8 +517,8 @@ impl ChainSpec {
// We filter out TTD-based forks w/o a pre-known block since those do not show up in the
// fork filter.
Some(match condition {
ForkCondition::Block(block) |
ForkCondition::TTD { fork_block: Some(block), .. } => ForkFilterKey::Block(block),
ForkCondition::Block(block)
| ForkCondition::TTD { fork_block: Some(block), .. } => ForkFilterKey::Block(block),
ForkCondition::Timestamp(time) => ForkFilterKey::Time(time),
_ => return None,
})
Expand All @@ -544,8 +545,8 @@ impl ChainSpec {
for (_, cond) in self.hardforks.forks_iter() {
// handle block based forks and the sepolia merge netsplit block edge case (TTD
// ForkCondition with Some(block))
if let ForkCondition::Block(block) |
ForkCondition::TTD { fork_block: Some(block), .. } = cond
if let ForkCondition::Block(block)
| ForkCondition::TTD { fork_block: Some(block), .. } = cond
{
if head.number >= block {
// skip duplicated hardforks: hardforks enabled at genesis block
Expand All @@ -556,7 +557,7 @@ impl ChainSpec {
} else {
// we can return here because this block fork is not active, so we set the
// `next` value
return ForkId { hash: forkhash, next: block }
return ForkId { hash: forkhash, next: block };
}
}
}
Expand All @@ -578,7 +579,7 @@ impl ChainSpec {
// can safely return here because we have already handled all block forks and
// have handled all active timestamp forks, and set the next value to the
// timestamp that is known but not active yet
return ForkId { hash: forkhash, next: timestamp }
return ForkId { hash: forkhash, next: timestamp };
}
}

Expand Down
3 changes: 2 additions & 1 deletion crates/cli/commands/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ impl<

let chain = {
let mut chain = reth_downloaders::bitfinity_evm_client::BitfinityEvmClient::fetch_chain_spec_with_fallback(bitfinity.rpc_url.to_owned(), bitfinity.backup_rpc_url.clone()).await?;

if let Some(send_raw_transaction_rpc_url) = &bitfinity.send_raw_transaction_rpc_url {
chain.bitfinity_evm_url = Some(send_raw_transaction_rpc_url.to_owned());
chain.bitfinity_spec.send_transaction_url = Some(send_raw_transaction_rpc_url.to_owned());
}
Arc::new(chain)
};
Expand Down
9 changes: 7 additions & 2 deletions crates/net/downloaders/src/bitfinity_evm_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ use ic_certificate_verification::VerifyCertificate;
use ic_certification::{Certificate, HashTree, LookupResult};
use itertools::Either;
use rayon::iter::{IntoParallelIterator, ParallelIterator as _};
use reth_chainspec::bitfinity_spec::BitfinitySpec;
use reth_chainspec::{
make_genesis_header, BaseFeeParams, BaseFeeParamsKind, Chain, ChainHardforks, ChainSpec, EthereumHardfork, Hardfork
make_genesis_header, BaseFeeParams, BaseFeeParamsKind, Chain, ChainHardforks, ChainSpec,
EthereumHardfork, Hardfork,
};

use alloy_rlp::Decodable;
Expand Down Expand Up @@ -429,7 +431,10 @@ impl BitfinityEvmClient {
base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()),
prune_delete_limit: 0,
blob_params: Default::default(),
bitfinity_evm_url: Some(rpc),
bitfinity_spec: BitfinitySpec {
rpc_url: rpc.clone(),
send_transaction_url: None,
},
};

tracing::info!("downloaders::bitfinity_evm_client - Bitfinity chain_spec: {:?}", spec);
Expand Down
37 changes: 25 additions & 12 deletions crates/rpc/rpc-eth-api/src/helpers/bitfinity_evm_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub trait BitfinityEvmRpc {
async move {
// TODO: Expecting that client node would be the active data sorce at this time
// it could be primary or backup URL
let (rpc_url, client) = get_client(&chain_spec)?;
let (rpc_url, client) = client(&chain_spec)?;

let block_number = client.get_block_number().await.map_err(|e| {
internal_rpc_err(format!(
Expand All @@ -46,7 +46,7 @@ pub trait BitfinityEvmRpc {
fn btf_gas_price(&self) -> impl Future<Output = RpcResult<U256>> + Send {
let chain_spec = self.chain_spec();
async move {
let (rpc_url, client) = get_client(&chain_spec)?;
let (rpc_url, client) = client(&chain_spec)?;

let gas_price = client.gas_price().await.map_err(|e| {
internal_rpc_err(format!(
Expand All @@ -63,7 +63,7 @@ pub trait BitfinityEvmRpc {
fn btf_max_priority_fee_per_gas(&self) -> impl Future<Output = RpcResult<U256>> + Send {
let chain_spec = self.chain_spec();
async move {
let (rpc_url, client) = get_client(&chain_spec)?;
let (rpc_url, client) = client(&chain_spec)?;

let priority_fee = client.max_priority_fee_per_gas().await.map_err(|e| {
internal_rpc_err(format!(
Expand All @@ -84,7 +84,7 @@ pub trait BitfinityEvmRpc {
let chain_spec = self.chain_spec();

async move {
let (rpc_url, client) = get_client(&chain_spec)?;
let (rpc_url, client) = client(&chain_spec)?;
let Some(tx) = client.get_transaction_by_hash(hash.into()).await.map_err(|e| {
internal_rpc_err(format!(
"failed to forward eth_transactionByHash request to {}: {}",
Expand All @@ -106,9 +106,10 @@ pub trait BitfinityEvmRpc {
.map_err(|e| internal_rpc_err(format!("failed to decode BitfinityEvmRpc::Transaction from received did::Transaction: {e}")))?;

let signer = self_tx.recover_signer().map_err(|err| {
internal_rpc_err(
format!("failed to recover signer from decoded BitfinityEvmRpc::Transaction: {:?}", err)
)
internal_rpc_err(format!(
"failed to recover signer from decoded BitfinityEvmRpc::Transaction: {:?}",
err
))
})?;
let recovered_tx = Recovered::new_unchecked(self_tx, signer);

Expand All @@ -135,7 +136,7 @@ pub trait BitfinityEvmRpc {
fn btf_send_raw_transaction(&self, tx: Bytes) -> impl Future<Output = RpcResult<B256>> + Send {
let chain_spec = self.chain_spec();
async move {
let (rpc_url, client) = get_client(&chain_spec)?;
let (rpc_url, client) = send_transaction_client(&chain_spec)?;

let tx_hash = client.send_raw_transaction_bytes(&tx).await.map_err(|e| {
internal_rpc_err(format!(
Expand All @@ -152,7 +153,7 @@ pub trait BitfinityEvmRpc {
fn get_genesis_balances(&self) -> impl Future<Output = RpcResult<Vec<(Address, U256)>>> + Send {
let chain_spec = self.chain_spec();
async move {
let (rpc_url, client) = get_client(&chain_spec)?;
let (rpc_url, client) = client(&chain_spec)?;

let balances = client.get_genesis_balances().await.map_err(|e| {
internal_rpc_err(format!(
Expand All @@ -171,7 +172,7 @@ pub trait BitfinityEvmRpc {
) -> impl Future<Output = RpcResult<CertifiedResult<Block<H256>>>> + Send {
let chain_spec = self.chain_spec();
async move {
let (rpc_url, client) = get_client(&chain_spec)?;
let (rpc_url, client) = client(&chain_spec)?;

let certified_block = client.get_last_certified_block().await.map_err(|e| {
internal_rpc_err(format!(
Expand All @@ -186,8 +187,20 @@ pub trait BitfinityEvmRpc {
}

/// Returns a client for the Bitfinity EVM RPC.
fn get_client(chain_spec: &ChainSpec) -> RpcResult<(&String, EthJsonRpcClient<ReqwestClient>)> {
let Some(rpc_url) = &chain_spec.bitfinity_evm_url else {
fn client(chain_spec: &ChainSpec) -> RpcResult<(&String, EthJsonRpcClient<ReqwestClient>)> {
let rpc_url = &chain_spec.bitfinity_spec.rpc_url;

let client = ethereum_json_rpc_client::EthJsonRpcClient::new(
ethereum_json_rpc_client::reqwest::ReqwestClient::new(rpc_url.to_string()),
);

Ok((&rpc_url, client))
}

fn send_transaction_client(
chain_spec: &ChainSpec,
) -> RpcResult<(&String, EthJsonRpcClient<ReqwestClient>)> {
let Some(rpc_url) = &chain_spec.bitfinity_spec.send_transaction_url else {
return Err(internal_rpc_err("bitfinity_evm_url not found in chain spec"));
};

Expand Down
Loading