Skip to content

Commit 22aa42d

Browse files
authored
Merge pull request #68 from bitfinity-network/feat/fix-send-raw-transaction-url
feat: Add bitfinity spec
2 parents 6c809a3 + 7625a1a commit 22aa42d

File tree

7 files changed

+65
-32
lines changed

7 files changed

+65
-32
lines changed

bin/reth/tests/commands/bitfinity_node_it.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use reth::{
1414
args::{DatadirArgs, RpcServerArgs},
1515
dirs::{DataDirPath, MaybePlatformPath},
1616
};
17+
use reth_chainspec::bitfinity_spec::BitfinitySpec;
1718
use reth_consensus::FullConsensus;
1819
use reth_db::test_utils::TempDatabase;
1920
use reth_db::DatabaseEnv;
@@ -339,7 +340,10 @@ pub async fn start_reth_node(
339340
node_config.dev.dev = false;
340341

341342
let mut chain = node_config.chain.as_ref().clone();
342-
chain.bitfinity_evm_url = bitfinity_evm_url;
343+
chain.bitfinity_spec = BitfinitySpec {
344+
rpc_url: bitfinity_evm_url.to_owned().unwrap_or_default(),
345+
send_transaction_url: Some(bitfinity_evm_url.unwrap_or_default()),
346+
};
343347
let mut node_config = node_config.with_chain(chain);
344348

345349
let database = if let Some(import_data) = import_data {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// Bitfinity specific configuration
2+
#[derive(Debug, Clone, PartialEq, Eq, Default)]
3+
pub struct BitfinitySpec {
4+
/// URL of the Bitfinity EVM node
5+
pub rpc_url: String,
6+
/// Send transaction to the Bitfinity EVM node
7+
pub send_transaction_url: Option<String>,
8+
}

crates/chainspec/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ extern crate alloc;
1313

1414
/// Chain specific constants
1515
mod constants;
16+
pub mod bitfinity_spec;
1617
pub use constants::*;
1718

1819
mod api;

crates/chainspec/src/spec.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub use alloy_eips::eip1559::BaseFeeParams;
22
use alloy_evm::eth::spec::EthExecutorSpec;
33

4+
use crate::bitfinity_spec::BitfinitySpec;
45
use crate::{
56
constants::{MAINNET_DEPOSIT_CONTRACT, MAINNET_PRUNE_DELETE_LIMIT},
67
EthChainSpec,
@@ -113,7 +114,7 @@ pub static MAINNET: LazyLock<Arc<ChainSpec>> = LazyLock::new(|| {
113114
base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()),
114115
prune_delete_limit: MAINNET_PRUNE_DELETE_LIMIT,
115116
blob_params: HardforkBlobParams::default(),
116-
bitfinity_evm_url: Default::default(),
117+
bitfinity_spec: Default::default(),
117118
};
118119
spec.genesis.config.dao_fork_support = true;
119120
spec.into()
@@ -143,7 +144,7 @@ pub static SEPOLIA: LazyLock<Arc<ChainSpec>> = LazyLock::new(|| {
143144
base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()),
144145
prune_delete_limit: 10000,
145146
blob_params: HardforkBlobParams::default(),
146-
bitfinity_evm_url: Default::default(),
147+
bitfinity_spec: Default::default(),
147148
};
148149
spec.genesis.config.dao_fork_support = true;
149150
spec.into()
@@ -171,7 +172,7 @@ pub static HOLESKY: LazyLock<Arc<ChainSpec>> = LazyLock::new(|| {
171172
base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()),
172173
prune_delete_limit: 10000,
173174
blob_params: HardforkBlobParams::default(),
174-
bitfinity_evm_url: Default::default(),
175+
bitfinity_spec: Default::default(),
175176
};
176177
spec.genesis.config.dao_fork_support = true;
177178
spec.into()
@@ -201,7 +202,7 @@ pub static HOODI: LazyLock<Arc<ChainSpec>> = LazyLock::new(|| {
201202
base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()),
202203
prune_delete_limit: 10000,
203204
blob_params: HardforkBlobParams::default(),
204-
bitfinity_evm_url: Default::default(),
205+
bitfinity_spec: Default::default(),
205206
};
206207
spec.genesis.config.dao_fork_support = true;
207208
spec.into()
@@ -335,9 +336,9 @@ pub struct ChainSpec {
335336

336337
/// The settings passed for blob configurations for specific hardforks.
337338
pub blob_params: HardforkBlobParams,
338-
339-
/// The URL of the Bitfinity EVM RPC endpoint
340-
pub bitfinity_evm_url: Option<String>,
339+
340+
/// Bitfinity Specific Configuration
341+
pub bitfinity_spec: BitfinitySpec,
341342
}
342343

343344
impl Default for ChainSpec {
@@ -352,7 +353,7 @@ impl Default for ChainSpec {
352353
base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()),
353354
prune_delete_limit: MAINNET_PRUNE_DELETE_LIMIT,
354355
blob_params: Default::default(),
355-
bitfinity_evm_url: Default::default(),
356+
bitfinity_spec: Default::default(),
356357
}
357358
}
358359
}
@@ -423,7 +424,7 @@ impl ChainSpec {
423424
// given timestamp.
424425
for (fork, params) in bf_params.iter().rev() {
425426
if self.hardforks.is_fork_active_at_timestamp(fork.clone(), timestamp) {
426-
return *params
427+
return *params;
427428
}
428429
}
429430

@@ -442,7 +443,7 @@ impl ChainSpec {
442443
// given timestamp.
443444
for (fork, params) in bf_params.iter().rev() {
444445
if self.hardforks.is_fork_active_at_block(fork.clone(), block_number) {
445-
return *params
446+
return *params;
446447
}
447448
}
448449

@@ -516,8 +517,8 @@ impl ChainSpec {
516517
// We filter out TTD-based forks w/o a pre-known block since those do not show up in the
517518
// fork filter.
518519
Some(match condition {
519-
ForkCondition::Block(block) |
520-
ForkCondition::TTD { fork_block: Some(block), .. } => ForkFilterKey::Block(block),
520+
ForkCondition::Block(block)
521+
| ForkCondition::TTD { fork_block: Some(block), .. } => ForkFilterKey::Block(block),
521522
ForkCondition::Timestamp(time) => ForkFilterKey::Time(time),
522523
_ => return None,
523524
})
@@ -544,8 +545,8 @@ impl ChainSpec {
544545
for (_, cond) in self.hardforks.forks_iter() {
545546
// handle block based forks and the sepolia merge netsplit block edge case (TTD
546547
// ForkCondition with Some(block))
547-
if let ForkCondition::Block(block) |
548-
ForkCondition::TTD { fork_block: Some(block), .. } = cond
548+
if let ForkCondition::Block(block)
549+
| ForkCondition::TTD { fork_block: Some(block), .. } = cond
549550
{
550551
if head.number >= block {
551552
// skip duplicated hardforks: hardforks enabled at genesis block
@@ -556,7 +557,7 @@ impl ChainSpec {
556557
} else {
557558
// we can return here because this block fork is not active, so we set the
558559
// `next` value
559-
return ForkId { hash: forkhash, next: block }
560+
return ForkId { hash: forkhash, next: block };
560561
}
561562
}
562563
}
@@ -578,7 +579,7 @@ impl ChainSpec {
578579
// can safely return here because we have already handled all block forks and
579580
// have handled all active timestamp forks, and set the next value to the
580581
// timestamp that is known but not active yet
581-
return ForkId { hash: forkhash, next: timestamp }
582+
return ForkId { hash: forkhash, next: timestamp };
582583
}
583584
}
584585

crates/cli/commands/src/node.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ impl<
176176

177177
let chain = {
178178
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?;
179+
179180
if let Some(send_raw_transaction_rpc_url) = &bitfinity.send_raw_transaction_rpc_url {
180-
chain.bitfinity_evm_url = Some(send_raw_transaction_rpc_url.to_owned());
181+
chain.bitfinity_spec.send_transaction_url = Some(send_raw_transaction_rpc_url.to_owned());
181182
}
182183
Arc::new(chain)
183184
};

crates/net/downloaders/src/bitfinity_evm_client.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ use ic_certificate_verification::VerifyCertificate;
1010
use ic_certification::{Certificate, HashTree, LookupResult};
1111
use itertools::Either;
1212
use rayon::iter::{IntoParallelIterator, ParallelIterator as _};
13+
use reth_chainspec::bitfinity_spec::BitfinitySpec;
1314
use reth_chainspec::{
14-
make_genesis_header, BaseFeeParams, BaseFeeParamsKind, Chain, ChainHardforks, ChainSpec, EthereumHardfork, Hardfork
15+
make_genesis_header, BaseFeeParams, BaseFeeParamsKind, Chain, ChainHardforks, ChainSpec,
16+
EthereumHardfork, Hardfork,
1517
};
1618

1719
use alloy_rlp::Decodable;
@@ -429,7 +431,10 @@ impl BitfinityEvmClient {
429431
base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()),
430432
prune_delete_limit: 0,
431433
blob_params: Default::default(),
432-
bitfinity_evm_url: Some(rpc),
434+
bitfinity_spec: BitfinitySpec {
435+
rpc_url: rpc.clone(),
436+
send_transaction_url: None,
437+
},
433438
};
434439

435440
tracing::info!("downloaders::bitfinity_evm_client - Bitfinity chain_spec: {:?}", spec);

crates/rpc/rpc-eth-api/src/helpers/bitfinity_evm_rpc.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub trait BitfinityEvmRpc {
2929
async move {
3030
// TODO: Expecting that client node would be the active data sorce at this time
3131
// it could be primary or backup URL
32-
let (rpc_url, client) = get_client(&chain_spec)?;
32+
let (rpc_url, client) = client(&chain_spec)?;
3333

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

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

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

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

108108
let signer = self_tx.recover_signer().map_err(|err| {
109-
internal_rpc_err(
110-
format!("failed to recover signer from decoded BitfinityEvmRpc::Transaction: {:?}", err)
111-
)
109+
internal_rpc_err(format!(
110+
"failed to recover signer from decoded BitfinityEvmRpc::Transaction: {:?}",
111+
err
112+
))
112113
})?;
113114
let recovered_tx = Recovered::new_unchecked(self_tx, signer);
114115

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

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

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

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

188189
/// Returns a client for the Bitfinity EVM RPC.
189-
fn get_client(chain_spec: &ChainSpec) -> RpcResult<(&String, EthJsonRpcClient<ReqwestClient>)> {
190-
let Some(rpc_url) = &chain_spec.bitfinity_evm_url else {
190+
fn client(chain_spec: &ChainSpec) -> RpcResult<(&String, EthJsonRpcClient<ReqwestClient>)> {
191+
let rpc_url = &chain_spec.bitfinity_spec.rpc_url;
192+
193+
let client = ethereum_json_rpc_client::EthJsonRpcClient::new(
194+
ethereum_json_rpc_client::reqwest::ReqwestClient::new(rpc_url.to_string()),
195+
);
196+
197+
Ok((&rpc_url, client))
198+
}
199+
200+
fn send_transaction_client(
201+
chain_spec: &ChainSpec,
202+
) -> RpcResult<(&String, EthJsonRpcClient<ReqwestClient>)> {
203+
let Some(rpc_url) = &chain_spec.bitfinity_spec.send_transaction_url else {
191204
return Err(internal_rpc_err("bitfinity_evm_url not found in chain spec"));
192205
};
193206

0 commit comments

Comments
 (0)