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
2 changes: 2 additions & 0 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions cmd/ethrex/l2/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ pub enum Command {
#[arg(
long,
value_parser = parse_private_key,
env = "SEQUENCER_PRIVATE_KEY",
help = "The private key of the sequencer",
env = "SEQUENCER_PRIVATE_KEY",
help = "The private key of the sequencer",
help_heading = "Sequencer account options",
group = "sequencer_signing",
)]
Expand Down Expand Up @@ -289,7 +289,7 @@ impl Command {
} => {
create_dir_all(datadir.clone())?;

let eth_client = EthClient::new(l1_eth_rpc.as_str())?;
let eth_client = EthClient::new(l1_eth_rpc)?;
let beacon_client = BeaconClient::new(l1_beacon_rpc);

// Keep delay for finality
Expand Down Expand Up @@ -643,7 +643,7 @@ pub struct ContractCallOptions {

impl ContractCallOptions {
async fn call_contract(&self, selector: &str, params: Vec<Value>) -> eyre::Result<()> {
let client = EthClient::new(self.rpc_url.as_str())?;
let client = EthClient::new(self.rpc_url.clone())?;
let signer = parse_signer(
self.private_key,
self.remote_signer_url.clone(),
Expand Down
10 changes: 6 additions & 4 deletions cmd/ethrex/l2/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use clap::ArgAction;
use ethrex_common::H160;
use hex::FromHexError;
use secp256k1::SecretKey;
use url::Url;

use ethrex_config::networks::{
LOCAL_DEVNET_GENESIS_CONTENTS, LOCAL_DEVNET_PRIVATE_KEYS, LOCAL_DEVNETL2_GENESIS_CONTENTS,
Expand All @@ -48,7 +49,7 @@ pub struct DeployerOptions {
env = "ETHREX_ETH_RPC_URL",
help_heading = "Eth options"
)]
pub rpc_url: String,
pub rpc_url: Url,
#[arg(
long,
default_value = "10000000000",
Expand Down Expand Up @@ -338,7 +339,8 @@ pub struct DeployerOptions {
impl Default for DeployerOptions {
fn default() -> Self {
Self {
rpc_url: "http://localhost:8545".to_string(),
rpc_url: Url::parse("http://localhost:8545")
.expect("Unreachable error. URL is hardcoded"),
maximum_allowed_max_fee_per_gas: 10_000_000_000,
maximum_allowed_max_fee_per_blob_gas: 10_000_000_000,
max_number_of_retries: 10,
Expand Down Expand Up @@ -526,7 +528,7 @@ pub async fn deploy_l1_contracts(
let signer: Signer = LocalSigner::new(opts.private_key).into();

let eth_client = EthClient::new_with_config(
vec![&opts.rpc_url],
vec![opts.rpc_url.clone()],
opts.max_number_of_retries,
opts.backoff_factor,
opts.min_retry_delay,
Expand Down Expand Up @@ -706,7 +708,7 @@ fn deploy_tdx_contracts(
Command::new("make")
.arg("deploy-all")
.env("PRIVATE_KEY", hex::encode(opts.private_key.as_ref()))
.env("RPC_URL", &opts.rpc_url)
.env("RPC_URL", opts.rpc_url.as_str())
.env("ON_CHAIN_PROPOSER", format!("{on_chain_proposer:#x}"))
.current_dir("tee/contracts")
.stdout(Stdio::null())
Expand Down
6 changes: 4 additions & 2 deletions cmd/ethrex/l2/initializers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use tokio_util::{sync::CancellationToken, task::TaskTracker};
use tracing::{error, info, warn};
use tracing_subscriber::{EnvFilter, Registry, layer::SubscriberExt, reload};
use tui_logger::{LevelFilter, TuiTracingSubscriberLayer};
use url::Url;

#[allow(clippy::too_many_arguments)]
async fn init_rpc_api(
Expand Down Expand Up @@ -290,10 +291,11 @@ pub async fn init_l2(
l2_sequencer_cfg,
cancellation_token.clone(),
#[cfg(feature = "metrics")]
format!(
Url::parse(&format!(
"http://{}:{}",
opts.node_opts.http_addr, opts.node_opts.http_port
),
))
.map_err(|err| eyre::eyre!("Failed to parse L2 RPC URL: {err}"))?,
initial_checkpoint_store,
initial_checkpoint_blockchain,
genesis,
Expand Down
6 changes: 4 additions & 2 deletions cmd/ethrex/l2/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ pub struct EthOptions {
help_heading = "Eth options",
num_args = 1..
)]
pub rpc_url: Vec<String>,
pub rpc_url: Vec<Url>,
#[arg(
long = "eth.maximum-allowed-max-fee-per-gas",
default_value = "10000000000",
Expand Down Expand Up @@ -345,7 +345,9 @@ pub struct EthOptions {
impl Default for EthOptions {
fn default() -> Self {
Self {
rpc_url: vec!["http://localhost:8545".to_string()],
rpc_url: vec![
Url::parse("http://localhost:8545").expect("Unreachable error. URL is hardcoded"),
],
maximum_allowed_max_fee_per_gas: 10000000000,
maximum_allowed_max_fee_per_blob_gas: 10000000000,
max_number_of_retries: MAX_NUMBER_OF_RETRIES,
Expand Down
18 changes: 14 additions & 4 deletions crates/l2/monitor/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use ratatui::{
Terminal,
backend::{Backend, CrosstermBackend},
};
use reqwest::Url;
use spawned_concurrency::{
messages::Unused,
tasks::{
Expand Down Expand Up @@ -185,11 +186,20 @@ impl EthrexMonitorWidget {
rollup_store: StoreRollup,
cfg: &SequencerConfig,
) -> Result<Self, MonitorError> {
let eth_client = EthClient::new(cfg.eth.rpc_url.first().ok_or(MonitorError::RPCListEmpty)?)
.map_err(MonitorError::EthClientError)?;
let eth_client = EthClient::new(
cfg.eth
.rpc_url
.first()
.ok_or(MonitorError::RPCListEmpty)?
.clone(),
)
.map_err(MonitorError::EthClientError)?;
// TODO: De-hardcode the rollup client URL
let rollup_client =
EthClient::new("http://localhost:1729").map_err(MonitorError::EthClientError)?;
#[allow(clippy::expect_used)]
let rollup_client = EthClient::new(
Url::parse("http://localhost:1729").expect("Unreachable error. URL is hardcoded"),
)
.map_err(MonitorError::EthClientError)?;

let mut monitor_widget = EthrexMonitorWidget {
title: if cfg.based.enabled {
Expand Down
2 changes: 1 addition & 1 deletion crates/l2/sequencer/configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct CommitterConfig {

#[derive(Clone, Debug)]
pub struct EthConfig {
pub rpc_url: Vec<String>,
pub rpc_url: Vec<Url>,
pub maximum_allowed_max_fee_per_gas: u64,
pub maximum_allowed_max_fee_per_blob_gas: u64,
pub max_number_of_retries: u64,
Expand Down
2 changes: 1 addition & 1 deletion crates/l2/sequencer/l1_committer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl L1Committer {
checkpoints_dir: PathBuf,
) -> Result<Self, CommitterError> {
let eth_client = EthClient::new_with_config(
eth_config.rpc_url.iter().map(AsRef::as_ref).collect(),
eth_config.rpc_url.clone(),
eth_config.max_number_of_retries,
eth_config.backoff_factor,
eth_config.min_retry_delay,
Expand Down
2 changes: 1 addition & 1 deletion crates/l2/sequencer/l1_proof_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl L1ProofSender {
needed_proof_types: Vec<ProverType>,
) -> Result<Self, ProofSenderError> {
let eth_client = EthClient::new_with_config(
eth_cfg.rpc_url.iter().map(AsRef::as_ref).collect(),
eth_cfg.rpc_url.clone(),
eth_cfg.max_number_of_retries,
eth_cfg.backoff_factor,
eth_cfg.min_retry_delay,
Expand Down
2 changes: 1 addition & 1 deletion crates/l2/sequencer/l1_proof_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl L1ProofVerifier {
rollup_store: StoreRollup,
) -> Result<Self, ProofVerifierError> {
let eth_client = EthClient::new_with_config(
eth_cfg.rpc_url.iter().map(AsRef::as_ref).collect(),
eth_cfg.rpc_url.clone(),
eth_cfg.max_number_of_retries,
eth_cfg.backoff_factor,
eth_cfg.min_retry_delay,
Expand Down
7 changes: 6 additions & 1 deletion crates/l2/sequencer/l1_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use ethrex_rpc::{
types::receipt::RpcLogInfo,
};
use ethrex_storage::Store;
use reqwest::Url;
use serde::Serialize;
use spawned_concurrency::tasks::{
CallResponse, CastResponse, GenServer, GenServerHandle, InitResult, Success, send_after,
Expand Down Expand Up @@ -81,7 +82,11 @@ impl L1Watcher {
sequencer_state: SequencerState,
) -> Result<Self, L1WatcherError> {
let eth_client = EthClient::new_with_multiple_urls(eth_config.rpc_url.clone())?;
let l2_client = EthClient::new("http://localhost:1729")?;
// TODO: De-hardcode the rollup client URL
#[allow(clippy::expect_used)]
let l2_client = EthClient::new(
Url::parse("http://localhost:1729").expect("Unreachable error. URL is hardcoded"),
)?;
let last_block_fetched = U256::zero();
Ok(Self {
store,
Expand Down
7 changes: 4 additions & 3 deletions crates/l2/sequencer/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use ethrex_metrics::{
metrics_transactions::METRICS_TX,
};
use ethrex_rpc::clients::eth::EthClient;
use reqwest::Url;
use serde::Serialize;
use spawned_concurrency::tasks::{
CallResponse, CastResponse, GenServer, GenServerHandle, send_after,
Expand Down Expand Up @@ -52,10 +53,10 @@ impl MetricsGatherer {
rollup_store: StoreRollup,
committer_config: &CommitterConfig,
eth_config: &EthConfig,
l2_url: String,
l2_url: Url,
) -> Result<Self, MetricsGathererError> {
let l1_eth_client = EthClient::new_with_multiple_urls(eth_config.rpc_url.clone())?;
let l2_eth_client = EthClient::new(&l2_url)?;
let l2_eth_client = EthClient::new(l2_url)?;
Ok(Self {
l1_eth_client,
l2_eth_client,
Expand All @@ -68,7 +69,7 @@ impl MetricsGatherer {
pub async fn spawn(
cfg: &SequencerConfig,
rollup_store: StoreRollup,
l2_url: String,
l2_url: Url,
) -> Result<GenServerHandle<MetricsGatherer>, MetricsGathererError> {
let mut metrics = Self::new(rollup_store, &(cfg.l1_committer.clone()), &cfg.eth, l2_url)
.await?
Expand Down
4 changes: 3 additions & 1 deletion crates/l2/sequencer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use l1_watcher::L1Watcher;
#[cfg(feature = "metrics")]
use metrics::MetricsGatherer;
use proof_coordinator::ProofCoordinator;
#[cfg(feature = "metrics")]
use reqwest::Url;
use tokio_util::sync::CancellationToken;
use tracing::{error, info};
use utils::get_needed_proof_types;
Expand All @@ -45,7 +47,7 @@ pub async fn start_l2(
blockchain: Arc<Blockchain>,
cfg: SequencerConfig,
cancellation_token: CancellationToken,
#[cfg(feature = "metrics")] l2_url: String,
#[cfg(feature = "metrics")] l2_url: Url,
initial_checkpoint_store: Store,
initial_checkpoint_blockchain: Arc<Blockchain>,
genesis: Genesis,
Expand Down
2 changes: 1 addition & 1 deletion crates/l2/sequencer/proof_coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl ProofCoordinator {
needed_proof_types: Vec<ProverType>,
) -> Result<Self, ProofCoordinatorError> {
let eth_client = EthClient::new_with_config(
eth_config.rpc_url.iter().map(AsRef::as_ref).collect(),
eth_config.rpc_url.clone(),
eth_config.max_number_of_retries,
eth_config.backoff_factor,
eth_config.min_retry_delay,
Expand Down
3 changes: 2 additions & 1 deletion crates/l2/sequencer/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use ethrex_storage::Store;
use ethrex_storage::error::StoreError;
use ethrex_storage_rollup::{RollupStoreError, StoreRollup};
use rand::Rng;
use reqwest::Url;
use std::time::{Duration, SystemTime};
use std::{str::FromStr, time::UNIX_EPOCH};
use tokio::time::sleep;
Expand Down Expand Up @@ -83,7 +84,7 @@ pub async fn send_verify_tx(
}

pub async fn get_needed_proof_types(
rpc_urls: Vec<String>,
rpc_urls: Vec<Url>,
on_chain_proposer_address: Address,
) -> Result<Vec<ProverType>, EthClientError> {
let eth_client = EthClient::new_with_multiple_urls(rpc_urls)?;
Expand Down
3 changes: 2 additions & 1 deletion crates/l2/tests/state_reconstruct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use ethrex_common::{Address, U256};
use ethrex_l2_common::utils::get_address_from_secret_key;
use ethrex_rpc::{EthClient, types::block_identifier::BlockIdentifier};

use reqwest::Url;
use secp256k1::SecretKey;

const ETH_RPC_URL: &str = "http://localhost:1729";
Expand Down Expand Up @@ -87,7 +88,7 @@ async fn test_state_block(addresses: &[Address], block_number: u64, rich_account
}

async fn connect() -> EthClient {
let client = EthClient::new(ETH_RPC_URL).unwrap();
let client = EthClient::new(Url::parse(ETH_RPC_URL).unwrap()).unwrap();

let mut retries = 0;
while retries < 20 {
Expand Down
17 changes: 13 additions & 4 deletions crates/l2/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use ethrex_rpc::{
},
};
use hex::FromHexError;
use reqwest::Url;
use secp256k1::SecretKey;
use std::cmp::min;
use std::collections::{BTreeMap, HashMap};
Expand Down Expand Up @@ -2257,13 +2258,21 @@ async fn get_fees_details_l2(
}

fn l1_client() -> EthClient {
EthClient::new(&std::env::var("INTEGRATION_TEST_L1_RPC").unwrap_or(DEFAULT_L1_RPC.to_string()))
.unwrap()
EthClient::new(
std::env::var("INTEGRATION_TEST_L1_RPC")
.map(|val| Url::parse(&val).expect("Error parsing URL (INTEGRATION_TEST_L1_RPC)"))
.unwrap_or(Url::parse(DEFAULT_L1_RPC).unwrap()),
)
.unwrap()
}

fn l2_client() -> EthClient {
EthClient::new(&std::env::var("INTEGRATION_TEST_L2_RPC").unwrap_or(DEFAULT_L2_RPC.to_string()))
.unwrap()
EthClient::new(
std::env::var("INTEGRATION_TEST_L2_RPC")
.map(|val| Url::parse(&val).expect("Error parsing URL (INTEGRATION_TEST_L2_RPC)"))
.unwrap_or(Url::parse(DEFAULT_L2_RPC).unwrap()),
)
.unwrap()
}

fn coinbase() -> Address {
Expand Down
16 changes: 4 additions & 12 deletions crates/networking/rpc/clients/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub const MAX_RETRY_DELAY: u64 = 1800;
pub const ERROR_FUNCTION_SELECTOR: [u8; 4] = [0x08, 0xc3, 0x79, 0xa0];

impl EthClient {
pub fn new(url: &str) -> Result<EthClient, EthClientError> {
pub fn new(url: Url) -> Result<EthClient, EthClientError> {
Self::new_with_config(
vec![url],
MAX_NUMBER_OF_RETRIES,
Expand All @@ -93,22 +93,14 @@ impl EthClient {
}

pub fn new_with_config(
urls: Vec<&str>,
urls: Vec<Url>,
max_number_of_retries: u64,
backoff_factor: u64,
min_retry_delay: u64,
max_retry_delay: u64,
maximum_allowed_max_fee_per_gas: Option<u64>,
maximum_allowed_max_fee_per_blob_gas: Option<u64>,
) -> Result<Self, EthClientError> {
let urls = urls
.iter()
.map(|url| {
Url::parse(url)
.map_err(|_| EthClientError::ParseUrlError("Failed to parse urls".to_string()))
})
.collect::<Result<Vec<_>, _>>()?;

Ok(Self {
client: Client::new(),
urls,
Expand All @@ -121,9 +113,9 @@ impl EthClient {
})
}

pub fn new_with_multiple_urls(urls: Vec<String>) -> Result<EthClient, EthClientError> {
pub fn new_with_multiple_urls(urls: Vec<Url>) -> Result<EthClient, EthClientError> {
Self::new_with_config(
urls.iter().map(AsRef::as_ref).collect(),
urls,
MAX_NUMBER_OF_RETRIES,
BACKOFF_FACTOR,
MIN_RETRY_DELAY,
Expand Down
1 change: 1 addition & 0 deletions tooling/load_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ ethrex-l2-rpc.workspace = true
eyre.workspace = true
tokio = { workspace = true, features = ["full"] }
futures = "0.3"
url.workspace = true
Loading
Loading