Skip to content

Commit

Permalink
Merge pull request #721 from chainbound/lore/chore/send-raw-devnet
Browse files Browse the repository at this point in the history
chore(cli, justfile): send preconfs also via `eth_sendRawTransaction`
  • Loading branch information
merklefruit authored Jan 22, 2025
2 parents 6f7bc36 + 85e2ea8 commit d859b5b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 25 deletions.
4 changes: 4 additions & 0 deletions bolt-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Url>,

/// Toggle for using `eth_sendRawTransaction` instead of `bolt_requestInclusion`
#[clap(long, env = "RAW", default_value_t = false)]
pub raw: bool,
}

#[derive(Debug, Clone, Parser)]
Expand Down
67 changes: 50 additions & 17 deletions bolt-cli/src/commands/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<String>,
tx_hashes: Vec<B256>,
target_slot: u64,
Expand Down Expand Up @@ -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<B256>,
target_slot: u64,
Expand Down
20 changes: 12 additions & 8 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand All @@ -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) \
Expand All @@ -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) \
Expand All @@ -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) \
Expand All @@ -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:
Expand Down

0 comments on commit d859b5b

Please sign in to comment.