Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(l2): restart processes with the proposed API #1234

Merged
merged 26 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f3563bc
Refactor processes to handle errors at the top
jrchatruc Nov 21, 2024
fbc2bf9
Remove comment
jrchatruc Nov 21, 2024
d1a180f
move retry tx logic into eth_client
fborello-lambda Nov 22, 2024
a282b35
fix: pass tx as ref
fborello-lambda Nov 22, 2024
0b89602
fix tx estimate_gas
fborello-lambda Nov 22, 2024
04fd3d0
add help msg
fborello-lambda Nov 22, 2024
74d0af5
fix compilation
fborello-lambda Nov 22, 2024
e0f6009
Merge branch 'main' into process-refactor
fborello-lambda Nov 22, 2024
8c74c2e
block_producer: error handling
fborello-lambda Nov 22, 2024
7134c81
l1_watcher: error handling
fborello-lambda Nov 22, 2024
cfe9870
prover_server: error handling
fborello-lambda Nov 22, 2024
7ec6d98
pr_comments: implement comments
fborello-lambda Nov 22, 2024
469aae7
prover_server: remove expects
fborello-lambda Nov 22, 2024
59161f9
prover_server: bubble up handler_sigint errors
fborello-lambda Nov 22, 2024
8ad1d09
prover_server: wip not working
fborello-lambda Nov 22, 2024
95dcec7
prover_server: fix sigint handler
fborello-lambda Nov 22, 2024
45f8d3a
prover_server: separate dev logic
fborello-lambda Nov 25, 2024
a9fd832
eth_client: fix get_address_from_secret_key
fborello-lambda Nov 25, 2024
1680ca5
contracts: add comments implement issue #1164
fborello-lambda Nov 25, 2024
e266fa4
eth_client: auto bump transaction when building
fborello-lambda Nov 25, 2024
915627b
eth_client: bump when sending if 'already known' or 'transaction unde…
fborello-lambda Nov 25, 2024
80e2be9
rm: comments
fborello-lambda Nov 25, 2024
6fa0a4c
ci: fix lint
fborello-lambda Nov 25, 2024
fa94818
l1_watcher: bubble up errors
fborello-lambda Nov 25, 2024
f88f0b2
Merge branch 'main' into l2/restart_processes
fborello-lambda Nov 25, 2024
f57146f
Improve logs
jrchatruc Nov 26, 2024
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: 2 additions & 4 deletions cmd/ethrex_l2/src/commands/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ async fn transfer_from(
let tx = client
.build_eip1559_transaction(
to_address,
address,
Bytes::new(),
Overrides {
chain_id: Some(cfg.network.l2_chain_id),
Expand All @@ -103,10 +104,7 @@ async fn transfer_from(
.await
.unwrap();

while let Err(e) = client
.send_eip1559_transaction(tx.clone(), &private_key)
.await
{
while let Err(e) = client.send_eip1559_transaction(&tx, &private_key).await {
println!("Transaction failed (PK: {pk} - Nonce: {}): {e}", tx.nonce);
retries += 1;
sleep(std::time::Duration::from_secs(2));
Expand Down
12 changes: 8 additions & 4 deletions cmd/ethrex_l2/src/commands/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ impl Command {
let tx = eth_client
.build_eip1559_transaction(
cfg.contracts.common_bridge,
cfg.wallet.address,
claim_withdrawal_data.into(),
Overrides {
chain_id: Some(cfg.network.l1_chain_id),
Expand All @@ -350,7 +351,7 @@ impl Command {
)
.await?;
let tx_hash = eth_client
.send_eip1559_transaction(tx, &cfg.wallet.private_key)
.send_eip1559_transaction(&tx, &cfg.wallet.private_key)
.await?;

println!("Withdrawal claim sent: {tx_hash:#x}");
Expand All @@ -377,6 +378,7 @@ impl Command {
let transfer_tx = client
.build_eip1559_transaction(
to,
cfg.wallet.address,
Bytes::new(),
Overrides {
value: Some(amount),
Expand All @@ -394,7 +396,7 @@ impl Command {
.await?;

let tx_hash = client
.send_eip1559_transaction(transfer_tx, &cfg.wallet.private_key)
.send_eip1559_transaction(&transfer_tx, &cfg.wallet.private_key)
.await?;

println!(
Expand All @@ -418,6 +420,7 @@ impl Command {
.build_privileged_transaction(
PrivilegedTxType::Withdrawal,
to.unwrap_or(cfg.wallet.address),
to.unwrap_or(cfg.wallet.address),
Bytes::new(),
Overrides {
nonce,
Expand All @@ -431,7 +434,7 @@ impl Command {
.await?;

let tx_hash = rollup_client
.send_privileged_l2_transaction(withdraw_transaction, &cfg.wallet.private_key)
.send_privileged_l2_transaction(&withdraw_transaction, &cfg.wallet.private_key)
.await?;

println!("Withdrawal sent: {tx_hash:#x}");
Expand Down Expand Up @@ -470,6 +473,7 @@ impl Command {
let tx = client
.build_eip1559_transaction(
to,
cfg.wallet.address,
calldata,
Overrides {
value: Some(value),
Expand All @@ -490,7 +494,7 @@ impl Command {
)
.await?;
let tx_hash = client
.send_eip1559_transaction(tx, &cfg.wallet.private_key)
.send_eip1559_transaction(&tx, &cfg.wallet.private_key)
.await?;

println!(
Expand Down
2 changes: 1 addition & 1 deletion crates/l2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ rm_dev_libmdbx_l2: ## 🛑 Removes the Libmdbx DB used by the L2

# CI Testing

test:
test: ## 🚧 Runs the L2's integration test
docker compose -f ${ethrex_L2_DOCKER_COMPOSE_PATH} down
docker compose -f ${ethrex_L2_DOCKER_COMPOSE_PATH} up -d --build
BRIDGE_ADDRESS=$$(grep 'L1_WATCHER_BRIDGE_ADDRESS' .env | cut -d= -f2) ON_CHAIN_PROPOSER_ADDRESS=$$(grep 'COMMITTER_ON_CHAIN_PROPOSER_ADDRESS' .env | cut -d= -f2) cargo test --release testito -- --nocapture
Expand Down
65 changes: 13 additions & 52 deletions crates/l2/contracts/deployer.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use bytes::Bytes;
use colored::Colorize;
use ethereum_types::{Address, H160, H256};
use ethrex_core::{
types::{GAS_LIMIT_ADJUSTMENT_FACTOR, GAS_LIMIT_MINIMUM},
U256,
};
use ethrex_core::U256;
use ethrex_l2::utils::{
config::{read_env_as_lines, read_env_file, write_env},
eth_client::{eth_sender::Overrides, EthClient},
Expand Down Expand Up @@ -220,18 +217,6 @@ async fn deploy_contracts(
eth_client: &EthClient,
contracts_path: &Path,
) -> (Address, Address) {
let gas_price = if eth_client.url.contains("localhost:8545") {
Some(1_000_000_000)
} else {
Some(eth_client.get_gas_price().await.unwrap().as_u64() * 2)
};

let overrides = Overrides {
gas_limit: Some(GAS_LIMIT_MINIMUM * GAS_LIMIT_ADJUSTMENT_FACTOR),
gas_price,
..Default::default()
};

let deploy_frames = spinner!(["📭❱❱", "❱📬❱", "❱❱📫"], 220);

let mut spinner = Spinner::new(
Expand All @@ -241,14 +226,7 @@ async fn deploy_contracts(
);

let (on_chain_proposer_deployment_tx_hash, on_chain_proposer_address) =
deploy_on_chain_proposer(
deployer,
deployer_private_key,
overrides.clone(),
eth_client,
contracts_path,
)
.await;
deploy_on_chain_proposer(deployer, deployer_private_key, eth_client, contracts_path).await;

let msg = format!(
"OnChainProposer:\n\tDeployed at address {} with tx hash {}",
Expand All @@ -258,14 +236,8 @@ async fn deploy_contracts(
spinner.success(&msg);

let mut spinner = Spinner::new(deploy_frames, "Deploying CommonBridge", Color::Cyan);
let (bridge_deployment_tx_hash, bridge_address) = deploy_bridge(
deployer,
deployer_private_key,
overrides,
eth_client,
contracts_path,
)
.await;
let (bridge_deployment_tx_hash, bridge_address) =
deploy_bridge(deployer, deployer_private_key, eth_client, contracts_path).await;

let msg = format!(
"CommonBridge:\n\tDeployed at address {} with tx hash {}",
Expand All @@ -280,7 +252,6 @@ async fn deploy_contracts(
async fn deploy_on_chain_proposer(
deployer: Address,
deployer_private_key: SecretKey,
overrides: Overrides,
eth_client: &EthClient,
contracts_path: &Path,
) -> (H256, Address) {
Expand All @@ -295,7 +266,6 @@ async fn deploy_on_chain_proposer(
deployer,
deployer_private_key,
&on_chain_proposer_init_code,
overrides,
eth_client,
)
.await;
Expand All @@ -306,7 +276,6 @@ async fn deploy_on_chain_proposer(
async fn deploy_bridge(
deployer: Address,
deployer_private_key: SecretKey,
overrides: Overrides,
eth_client: &EthClient,
contracts_path: &Path,
) -> (H256, Address) {
Expand All @@ -329,7 +298,6 @@ async fn deploy_bridge(
deployer,
deployer_private_key,
&bridge_init_code.into(),
overrides,
eth_client,
)
.await;
Expand All @@ -341,24 +309,21 @@ async fn create2_deploy(
deployer: Address,
deployer_private_key: SecretKey,
init_code: &Bytes,
overrides: Overrides,
eth_client: &EthClient,
) -> (H256, Address) {
let calldata = [SALT.lock().unwrap().as_bytes(), init_code].concat();
let deploy_tx = eth_client
.build_eip1559_transaction(
DETERMINISTIC_CREATE2_ADDRESS,
deployer,
calldata.into(),
Overrides {
from: Some(deployer),
..overrides
},
Overrides::default(),
)
.await
.expect("Failed to build create2 deploy tx");

let deploy_tx_hash = eth_client
.send_eip1559_transaction(deploy_tx, &deployer_private_key)
.send_eip1559_transaction(&deploy_tx, &deployer_private_key)
.await
.expect("Failed to send create2 deploy tx");

Expand Down Expand Up @@ -493,16 +458,14 @@ async fn initialize_on_chain_proposer(
let initialize_tx = eth_client
.build_eip1559_transaction(
on_chain_proposer,
deployer,
on_chain_proposer_initialization_calldata.into(),
Overrides {
from: Some(deployer),
..Default::default()
},
Overrides::default(),
)
.await
.expect("Failed to build initialize transaction");
let initialize_tx_hash = eth_client
.send_eip1559_transaction(initialize_tx, &deployer_private_key)
.send_eip1559_transaction(&initialize_tx, &deployer_private_key)
.await
.expect("Failed to send initialize transaction");

Expand Down Expand Up @@ -537,16 +500,14 @@ async fn initialize_bridge(
let initialize_tx = eth_client
.build_eip1559_transaction(
bridge,
deployer,
bridge_initialization_calldata.into(),
Overrides {
from: Some(deployer),
..Default::default()
},
Overrides::default(),
)
.await
.expect("Failed to build initialize transaction");
let initialize_tx_hash = eth_client
.send_eip1559_transaction(initialize_tx, &deployer_private_key)
.send_eip1559_transaction(&initialize_tx, &deployer_private_key)
.await
.expect("Failed to send initialize transaction");

Expand Down
2 changes: 2 additions & 0 deletions crates/l2/proposer/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ pub enum CommitterError {
FailedToReExecuteBlock(#[from] EvmError),
#[error("Committer failed to send transaction: {0}")]
FailedToSendCommitment(String),
#[error("Withdrawal transaction was invalid")]
InvalidWithdrawalTransaction,
}

#[derive(Debug, thiserror::Error)]
Expand Down
Loading
Loading