Skip to content
Closed
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
277 changes: 162 additions & 115 deletions Cargo.lock

Large diffs are not rendered by default.

22 changes: 16 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ exclude = [".github/"]
members = [
"bin/reth-bench/",
"bin/reth/",
"crates/blockchain-tree-api/",
"crates/bitfinity-block-validator",
"crates/blockchain-tree/",
"crates/blockchain-tree-api/",
"crates/chain-state/",
"crates/chainspec/",
"crates/cli/cli/",
Expand Down Expand Up @@ -477,10 +478,10 @@ alloy-transport-ws = { version = "0.9.2", default-features = false }

# op
op-alloy-rpc-types = { version = "0.9.0", default-features = false }
op-alloy-rpc-types-engine = { version = "0.9.0", default-features = false }
op-alloy-rpc-jsonrpsee = { version = "0.9.0", default-features = false }
op-alloy-network = { version = "0.9.0", default-features = false }
op-alloy-consensus = { version = "0.9.0", default-features = false }
op-alloy-rpc-types-engine = { version = "0.9.0", default-features = false }
op-alloy-rpc-jsonrpsee = { version = "0.9.0", default-features = false }
op-alloy-network = { version = "0.9.0", default-features = false }
op-alloy-consensus = { version = "0.9.0", default-features = false }

# misc
aquamarine = "0.6"
Expand Down Expand Up @@ -520,7 +521,9 @@ rayon = "1.7"
rustc-hash = { version = "2.0", default-features = false }
schnellru = "0.2"
serde = { version = "1.0", default-features = false }
serde_json = { version = "1.0.94", default-features = false, features = ["alloc"] }
serde_json = { version = "1.0.94", default-features = false, features = [
"alloc",
] }
serde_with = { version = "3", default-features = false, features = ["macros"] }
sha2 = { version = "0.10", default-features = false }
shellexpand = "3.0.0"
Expand Down Expand Up @@ -647,6 +650,9 @@ tracy-client = "0.17.3"
# op-alloy-rpc-types = { git = "https://github.com/alloy-rs/op-alloy", rev = "debfc29" }
# op-alloy-rpc-types-engine = { git = "https://github.com/alloy-rs/op-alloy", rev = "debfc29" }

# Bitfinity crates
bitfinity-block-validator = { path = "crates/bitfinity-block-validator" }

# Bitfinity Deps
async-channel = "2"
candid = "0.10"
Expand All @@ -658,6 +664,10 @@ ethereum-json-rpc-client = { git = "https://github.com/bitfinity-network/bitfini
evm-canister-client = { git = "https://github.com/bitfinity-network/bitfinity-evm-sdk", package = "evm-canister-client", features = [
"ic-agent-client",
], tag = "v0.40.x" }
ic-agent = "0.39"
ic-canister-client = { git = "https://github.com/bitfinity-network/canister-sdk", package = "ic-canister-client", features = [
"ic-agent-client",
], tag = "v0.23.x" }
ic-cbor = "3"
ic-certificate-verification = "3"
ic-certification = "3"
Expand Down
14 changes: 7 additions & 7 deletions bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,16 @@ similar-asserts.workspace = true

# bitfinity dependencies
async-channel.workspace = true
bitfinity-block-validator.workspace = true
candid.workspace = true
did.workspace = true
evm-canister-client = { workspace = true, features = ["ic-agent-client"] }
hex.workspace = true
lightspeed_scheduler = { workspace = true, features = ["tracing"] }
# rlp = { workspace = true }

[dev-dependencies]
reth-discv4.workspace = true
tempfile.workspace = true

# bitfinity dev dependencies
Expand All @@ -127,20 +130,17 @@ default = ["jemalloc"]
dev = ["reth-cli-commands/arbitrary"]

asm-keccak = [
"reth-node-core/asm-keccak",
"reth-primitives/asm-keccak",
"alloy-primitives/asm-keccak"
"reth-node-core/asm-keccak",
"reth-primitives/asm-keccak",
"alloy-primitives/asm-keccak",
]

jemalloc = [
"reth-cli-util/jemalloc",
"reth-node-core/jemalloc",
"reth-node-metrics/jemalloc",
]
jemalloc-prof = [
"reth-cli-util/jemalloc",
"reth-cli-util/jemalloc-prof"
]
jemalloc-prof = ["reth-cli-util/jemalloc", "reth-cli-util/jemalloc-prof"]
tracy-allocator = ["reth-cli-util/tracy-allocator"]

min-error-logs = ["tracing/release_max_level_error"]
Expand Down
50 changes: 48 additions & 2 deletions bin/reth/src/commands/bitfinity_import.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! Command that initializes the node by importing a chain from a remote EVM node.

use crate::{dirs::DataDirPath, version::SHORT_VERSION};
use crate::dirs::DataDirPath;
use crate::version::SHORT_VERSION;
use bitfinity_block_validator::BitfinityBlockValidator;
use evm_canister_client::{EvmCanisterClient, IcAgentClient};
use futures::{Stream, StreamExt};
use lightspeed_scheduler::{job::Job, scheduler::Scheduler, JobExecutor};
use reth_beacon_consensus::EthBeaconConsensus;
Expand Down Expand Up @@ -128,6 +131,28 @@ impl BitfinityImportCommand {

/// Execute the import job.
async fn single_execution(&self) -> eyre::Result<()> {
let evmc_principal = candid::Principal::from_text(&self.bitfinity.evmc_principal)
.expect("Failed to parse principal");

// make block validation client if identity path is set
let evm_block_validator =
if let Some(identity) = self.bitfinity.validate_block_ic_identity_file_path.as_ref() {
let evm_client = EvmCanisterClient::new(
IcAgentClient::with_identity(
evmc_principal,
identity,
&self.bitfinity.evm_network,
Some(Duration::from_secs(30)),
)
.await
.expect("Failed to create agent client"),
);

Some(BitfinityBlockValidator::new(evm_client, self.provider_factory.clone()))
} else {
None
};

let consensus = Arc::new(EthBeaconConsensus::new(self.chain.clone()));
debug!(target: "reth::cli - BitfinityImportCommand", "Consensus engine initialized");
let provider_factory = self.provider_factory.clone();
Expand All @@ -144,6 +169,26 @@ impl BitfinityImportCommand {
retry_delay: Duration::from_secs(self.bitfinity.retry_delay_secs),
};

let ic_root_key = if self.bitfinity.fetch_ic_root_key {
let ic_identity_path = self
.bitfinity
.validate_block_ic_identity_file_path
.as_ref()
.expect("identity path not set");
let agent = evm_canister_client::agent::identity::init_agent(
&ic_identity_path,
&self.bitfinity.evm_network,
None,
)
.await?;

agent.fetch_root_key().await.expect("failed to fetch IC root key");
let root_key = agent.read_root_key();
hex::encode(root_key)
} else {
self.bitfinity.ic_root_key.clone()
};

let remote_client = Arc::new(
BitfinityEvmClient::from_rpc_url(
rpc_config,
Expand All @@ -153,8 +198,9 @@ impl BitfinityImportCommand {
self.bitfinity.max_fetch_blocks,
Some(CertificateCheckSettings {
evmc_principal: self.bitfinity.evmc_principal.clone(),
ic_root_key: self.bitfinity.ic_root_key.clone(),
ic_root_key,
}),
evm_block_validator,
)
.await?,
);
Expand Down
3 changes: 3 additions & 0 deletions bin/reth/tests/commands/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ pub async fn bitfinity_import_config_data(
backup_rpc_url: backup_evm_datasource_url,
max_retries: 3,
retry_delay_secs: 3,
validate_block_ic_identity_file_path: None,
evm_network: "ic".to_string(),
fetch_ic_root_key: false,
};

Ok((
Expand Down
47 changes: 47 additions & 0 deletions crates/bitfinity-block-validator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[package]
name = "bitfinity-block-validator"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true

[lints]
workspace = true

[dependencies]
alloy-consensus.workspace = true
alloy-primitives.workspace = true
async-trait.workspace = true
did.workspace = true
evm-canister-client.workspace = true
ic-agent.workspace = true
ic-canister-client.workspace = true
itertools.workspace = true
reth-chain-state.workspace = true
reth-chainspec.workspace = true
reth-db.workspace = true
reth-engine-tree.workspace = true
reth-evm.workspace = true
reth-evm-ethereum.workspace = true
reth-node-types.workspace = true
reth-provider.workspace = true
reth-primitives.workspace = true
reth-revm.workspace = true
reth-trie.workspace = true
reth-trie-db.workspace = true
tracing.workspace = true

[dev-dependencies]
alloy-consensus.workspace = true
alloy-genesis.workspace = true
alloy-signer.workspace = true
alloy-signer-local.workspace = true
async-trait.workspace = true
candid.workspace = true
ethereum-json-rpc-client = { workspace = true, features = ["reqwest"] }
reth-db-common.workspace = true
tokio.workspace = true
serde.workspace = true
tempfile.workspace = true
Loading
Loading