From 85e2ea8f7a54b4c8e204ed66797c390ae32a427c Mon Sep 17 00:00:00 2001 From: thedevbirb Date: Wed, 22 Jan 2025 10:59:16 +0100 Subject: [PATCH] chore(cli, justfile): send preconfs also via eth_sendRawTransaction --- bolt-cli/src/cli.rs | 4 +++ bolt-cli/src/commands/send.rs | 67 ++++++++++++++++++++++++++--------- justfile | 20 ++++++----- 3 files changed, 66 insertions(+), 25 deletions(-) diff --git a/bolt-cli/src/cli.rs b/bolt-cli/src/cli.rs index 2712c8896..4cafd2e28 100644 --- a/bolt-cli/src/cli.rs +++ b/bolt-cli/src/cli.rs @@ -155,6 +155,10 @@ pub struct SendCommand { /// The URL of the devnet sidecar for sending transactions #[clap(long = "devnet.sidecar_url", hide = true)] pub devnet_sidecar_url: Option, + + /// Toggle for using `eth_sendRawTransaction` instead of `bolt_requestInclusion` + #[clap(long, env = "RAW", default_value_t = false)] + pub raw: bool, } #[derive(Debug, Clone, Parser)] diff --git a/bolt-cli/src/commands/send.rs b/bolt-cli/src/commands/send.rs index e5feb5b4f..943bf9409 100644 --- a/bolt-cli/src/commands/send.rs +++ b/bolt-cli/src/commands/send.rs @@ -96,14 +96,18 @@ impl SendCommand { } }; - send_rpc_request( - vec![hex::encode(&raw_tx)], - vec![tx_hash], - target_slot, - target_url.clone(), - &wallet, - ) - .await?; + if self.raw { + send_raw_transaction(hex::encode(&raw_tx), tx_hash, target_url.clone()).await?; + } else { + send_bolt_request_inclusion( + vec![hex::encode(&raw_tx)], + vec![tx_hash], + target_slot, + target_url.clone(), + &wallet, + ) + .await?; + } // Sleep for a bit to avoid spamming tokio::time::sleep(Duration::from_millis(200)).await; @@ -149,14 +153,18 @@ impl SendCommand { } }; - send_rpc_request( - vec![hex::encode(&raw_tx)], - vec![tx_hash], - slot + 2, - sidecar_url.clone(), - &wallet, - ) - .await?; + if self.raw { + send_raw_transaction(hex::encode(&raw_tx), tx_hash, sidecar_url.clone()).await?; + } else { + send_bolt_request_inclusion( + vec![hex::encode(&raw_tx)], + vec![tx_hash], + slot + 2, + sidecar_url.clone(), + &wallet, + ) + .await?; + } // Sleep for a bit to avoid spamming tokio::time::sleep(Duration::from_millis(200)).await; @@ -188,7 +196,7 @@ fn create_tx_request(to: Address, with_blob: bool) -> TransactionRequest { req } -async fn send_rpc_request( +async fn send_bolt_request_inclusion( txs_rlp: Vec, tx_hashes: Vec, target_slot: u64, @@ -223,6 +231,31 @@ async fn send_rpc_request( Ok(()) } +async fn send_raw_transaction( + tx_rlp: String, + tx_hash: B256, + target_sidecar_url: Url, +) -> Result<()> { + let request = prepare_rpc_request("eth_sendRawTransaction", serde_json::json!(tx_rlp)); + + info!(?tx_hash, %target_sidecar_url); + + let response = reqwest::Client::new() + .post(target_sidecar_url) + .header("content-type", "application/json") + .body(serde_json::to_string(&request)?) + .send() + .await + .wrap_err("failed to send POST request")?; + + let response = response.text().await?; + + // strip out long series of zeros in the response (to avoid spamming blob contents) + let response = response.replace(&"0".repeat(32), ".").replace(&".".repeat(4), ""); + info!("Response: {:?}", response); + Ok(()) +} + async fn sign_request( tx_hashes: Vec, target_slot: u64, diff --git a/justfile b/justfile index ec2b8d6ec..49f159f4b 100644 --- a/justfile +++ b/justfile @@ -139,7 +139,7 @@ grafana: fi # manually send a preconfirmation to the bolt devnet -send-preconf count='1': +send-preconf count='1' raw="": cd bolt-cli && RUST_LOG=info cargo run -- send \ --devnet \ --devnet.execution_url $(kurtosis port print bolt-devnet el-1-geth-lighthouse rpc) \ @@ -148,9 +148,10 @@ send-preconf count='1': --private-key 53321db7c1e331d93a11a41d16f004d7ff63972ec8ec7c25db329728ceeb1710 \ --max-fee 4 \ --priority-fee 3 \ - --count {{count}} + --count {{count}} \ + {{ if raw == "true" { "--raw" } else { "" } }} -send-preconf-rpc count='1' rpc='http://127.0.0.1:8015/rpc': +send-preconf-rpc count='1' raw="" rpc='http://127.0.0.1:8015/rpc': cd bolt-cli && RUST_LOG=info cargo run -- send \ --devnet \ --devnet.execution_url $(kurtosis port print bolt-devnet el-1-geth-lighthouse rpc) \ @@ -159,10 +160,11 @@ send-preconf-rpc count='1' rpc='http://127.0.0.1:8015/rpc': --private-key 53321db7c1e331d93a11a41d16f004d7ff63972ec8ec7c25db329728ceeb1710 \ --max-fee 4 \ --priority-fee 3 \ - --count {{count}} + --count {{count}} \ + {{ if raw == "true" { "--raw" } else { "" } }} # manually send a blob preconfirmation to the bolt devnet -send-blob-preconf count='1': +send-blob-preconf count='1' raw="": cd bolt-cli && RUST_LOG=info cargo run -- send \ --devnet \ --devnet.execution_url $(kurtosis port print bolt-devnet el-1-geth-lighthouse rpc) \ @@ -172,9 +174,10 @@ send-blob-preconf count='1': --blob \ --max-fee 4 \ --priority-fee 3 \ - --count {{count}} + --count {{count}} \ + {{ if raw == "true" { "--raw" } else { "" } }} -send-blob-preconf-rpc count='1' rpc='http://127.0.0.1:8015/rpc': +send-blob-preconf-rpc count='1' raw="" rpc='http://127.0.0.1:8015/rpc': cd bolt-cli && RUST_LOG=info cargo run -- send \ --devnet \ --devnet.execution_url $(kurtosis port print bolt-devnet el-1-geth-lighthouse rpc) \ @@ -184,7 +187,8 @@ send-blob-preconf-rpc count='1' rpc='http://127.0.0.1:8015/rpc': --blob \ --max-fee 4 \ --priority-fee 3 \ - --count {{count}} + --count {{count}} \ + {{ if raw == "true" { "--raw" } else { "" } }} # build all the docker images locally build-local-images: