Skip to content

Commit

Permalink
fix for sending preconfs in devnet
Browse files Browse the repository at this point in the history
  • Loading branch information
merklefruit committed Oct 25, 2024
1 parent 4f02c6e commit efedd73
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
49 changes: 36 additions & 13 deletions bolt-cli/src/commands/send.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::time::Duration;

use alloy::{
consensus::{BlobTransactionSidecar, SidecarBuilder, SimpleCoder},
consensus::{BlobTransactionSidecar, SidecarBuilder, SimpleCoder, Transaction},
eips::eip2718::Encodable2718,
network::{EthereumWallet, TransactionBuilder, TransactionBuilder4844},
primitives::{keccak256, Address, B256, U256},
Expand Down Expand Up @@ -66,15 +68,22 @@ impl SendCommand {
let target_slot = lookahead_res[0].slot;
info!("Target slot: {}", target_slot);

// Send the transactions to the Bolt sidecar
let mut next_nonce = None;
for _ in 0..self.count {
// generate a simple self-transfer of ETH
let req = create_tx_request(wallet.address(), self.blob);
let mut req = create_tx_request(wallet.address(), self.blob);
if let Some(next_nonce) = next_nonce {
req.set_nonce(next_nonce);
}

let raw_tx = match provider.fill(req).await.wrap_err("failed to fill transaction")? {
let (raw_tx, tx_hash) = match provider.fill(req).await.wrap_err("failed to fill")? {
SendableTx::Builder(_) => bail!("expected a raw transaction"),
SendableTx::Envelope(raw) => raw.encoded_2718(),
SendableTx::Envelope(raw) => {
next_nonce = Some(raw.nonce() + 1);
(raw.encoded_2718(), *raw.tx_hash())
}
};
let tx_hash = B256::from(keccak256(&raw_tx));

send_rpc_request(
vec![hex::encode(&raw_tx)],
Expand All @@ -84,6 +93,9 @@ impl SendCommand {
wallet,
)
.await?;

// Sleep for a bit to avoid spamming
tokio::time::sleep(Duration::from_millis(200)).await;
}

Ok(())
Expand All @@ -104,14 +116,21 @@ impl SendCommand {
// Fetch the current slot from the devnet beacon node
let slot = request_current_slot_number(&cl_url).await?;

// Send the transaction to the devnet sidecar
// Send the transactions to the devnet sidecar
let mut next_nonce = None;
for _ in 0..self.count {
let req = create_tx_request(wallet.address(), self.blob);
let raw_tx = match provider.fill(req).await.wrap_err("failed to fill transaction")? {
let mut req = create_tx_request(wallet.address(), self.blob);
if let Some(next_nonce) = next_nonce {
req.set_nonce(next_nonce);
}

let (raw_tx, tx_hash) = match provider.fill(req).await.wrap_err("failed to fill")? {
SendableTx::Builder(_) => bail!("expected a raw transaction"),
SendableTx::Envelope(raw) => raw.encoded_2718(),
SendableTx::Envelope(raw) => {
next_nonce = Some(raw.nonce() + 1);
(raw.encoded_2718(), *raw.tx_hash())
}
};
let tx_hash = B256::from(keccak256(&raw_tx));

send_rpc_request(
vec![hex::encode(&raw_tx)],
Expand All @@ -121,6 +140,9 @@ impl SendCommand {
wallet,
)
.await?;

// Sleep for a bit to avoid spamming
tokio::time::sleep(Duration::from_millis(200)).await;
}

Ok(())
Expand All @@ -130,8 +152,8 @@ impl SendCommand {
async fn request_current_slot_number(beacon_url: &Url) -> Result<u64> {
let res = reqwest::get(beacon_url.join("eth/v1/beacon/headers/head")?).await?;
let res = res.json::<Value>().await?;
let slot = res.pointer("/header/message/slot").wrap_err("missing slot")?;
slot.as_u64().wrap_err("slot is not a number")
let slot = res.pointer("/data/header/message/slot").wrap_err("missing slot")?;
Ok(slot.as_u64().unwrap_or(slot.as_str().wrap_err("invalid slot type")?.parse()?))
}

fn create_tx_request(to: Address, with_blob: bool) -> TransactionRequest {
Expand All @@ -142,7 +164,8 @@ fn create_tx_request(to: Address, with_blob: bool) -> TransactionRequest {
if with_blob {
let sidecar = SidecarBuilder::<SimpleCoder>::from_slice(b"Blobs are fun!");
let sidecar: BlobTransactionSidecar = sidecar.build().unwrap();
req = req.with_blob_sidecar(sidecar)
req = req.with_blob_sidecar(sidecar);
req = req.with_max_fee_per_blob_gas(3_000_000);
}

req
Expand Down
8 changes: 4 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,22 @@ grafana:

# manually send a preconfirmation to the bolt devnet
send-preconf count='1':
cd bolt-cli && RUST_LOG=info cargo run -- \
cd bolt-cli && RUST_LOG=info cargo run -- send \
--devnet \
--devnet.execution_url $(kurtosis port print bolt-devnet el-1-geth-lighthouse rpc) \
--devnet.beacon_url $(kurtosis port print bolt-devnet cl-1-lighthouse-geth http) \
--devnet.sidecar_url http://$(kurtosis port print bolt-devnet bolt-sidecar-1-lighthouse-geth api) \
--private_key 53321db7c1e331d93a11a41d16f004d7ff63972ec8ec7c25db329728ceeb1710 \
--private-key 53321db7c1e331d93a11a41d16f004d7ff63972ec8ec7c25db329728ceeb1710 \
--count {{count}}

# manually send a blob preconfirmation to the bolt devnet
send-blob-preconf count='1':
cd bolt-cli && RUST_LOG=info cargo run -- \
cd bolt-cli && RUST_LOG=info cargo run -- send \
--devnet \
--devnet.execution_url $(kurtosis port print bolt-devnet el-1-geth-lighthouse rpc) \
--devnet.beacon_url $(kurtosis port print bolt-devnet cl-1-lighthouse-geth http) \
--devnet.sidecar_url http://$(kurtosis port print bolt-devnet bolt-sidecar-1-lighthouse-geth api) \
--private_key 53321db7c1e331d93a11a41d16f004d7ff63972ec8ec7c25db329728ceeb1710 \
--private-key 53321db7c1e331d93a11a41d16f004d7ff63972ec8ec7c25db329728ceeb1710 \
--blob \
--count {{count}}

Expand Down

0 comments on commit efedd73

Please sign in to comment.