Skip to content
Draft
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
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ signet-genesis = { git = "https://github.com/init4tech/node-components", tag = "

trevm = { version = "0.31.2", features = ["concurrent-db", "test-utils"] }

alloy = { version = "=1.0.35", features = [
alloy = { version = "1.0.40", features = [
"full",
"json-rpc",
"signer-aws",
Expand Down
21 changes: 15 additions & 6 deletions src/tasks/submit/flashbots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ use crate::{
tasks::{block::sim::SimResult, submit::SubmitPrep},
};
use alloy::{
eips::Encodable2718,
consensus::{EthereumTxEnvelope, TxEip4844Variant},
eips::{Encodable2718, eip7594::BlobTransactionSidecarEip7594},
primitives::{Bytes, TxHash},
providers::ext::MevApi,
rpc::types::mev::EthSendBundle,
};
use eyre::OptionExt;
use init4_bin_base::{deps::metrics::counter, utils::signer::LocalOrAws};
use tokio::{sync::mpsc, task::JoinHandle};
use tracing::{Instrument, debug, debug_span, error, instrument};

/// Type alias for a EIP 7594 compatible blob sidecar transaction envelope.
type SubmitEnvelope7594 = EthereumTxEnvelope<TxEip4844Variant<BlobTransactionSidecarEip7594>>;

/// Handles preparation and submission of simulated rollup blocks to the
/// Flashbots relay as MEV bundles.
#[derive(Debug)]
Expand Down Expand Up @@ -84,7 +87,6 @@ impl FlashbotsTask {
let txs = self.build_bundle_body(sim_result, tx_bytes);

// Create the MEV bundle (valid only in the specific host block)

Ok(EthSendBundle {
txs,
block_number: sim_result.host_block_number(),
Expand All @@ -100,7 +102,7 @@ impl FlashbotsTask {
async fn prepare_signed_transaction(
&self,
sim_result: &SimResult,
) -> eyre::Result<alloy::consensus::TxEnvelope> {
) -> eyre::Result<SubmitEnvelope7594> {
let prep = SubmitPrep::new(
&sim_result.block,
self.host_provider(),
Expand All @@ -114,15 +116,22 @@ impl FlashbotsTask {
.fill(tx.into_request())
.instrument(tracing::debug_span!("fill_tx").or_current())
.await?;
debug!(?sendable, "prepared signed rollup block transaction");

let tx_envelope = sendable
.try_into_envelope()?
.try_into_7594()
.map_err(|e| eyre::eyre!("failed to map 4844 to 7594: {e:?}"))?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use wrap_err. The current code will erase context

debug!(?tx_envelope, "prepared signed rollup block transaction envelope");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't trace out the envelope, it'll be 100kb+ i think


sendable.as_envelope().ok_or_eyre("failed to get envelope from filled tx").cloned()
Ok(tx_envelope)
}

/// Tracks the outbound transaction hash and increments submission metrics.
///
/// Sends the transaction hash to the outbound channel for monitoring.
/// Logs a debug message if the channel is closed.
fn track_outbound_tx(&self, envelope: &alloy::consensus::TxEnvelope) {
fn track_outbound_tx(&self, envelope: &SubmitEnvelope7594) {
counter!("signet.builder.flashbots.").increment(1);
let hash = *envelope.tx_hash();
if self.outbound.send(hash).is_err() {
Expand Down
20 changes: 10 additions & 10 deletions src/tasks/submit/prep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
utils,
};
use alloy::{
consensus::{Header, SimpleCoder},
consensus::{BlobTransactionSidecar, Header, SimpleCoder},
network::{TransactionBuilder, TransactionBuilder4844},
primitives::{B256, Bytes, U256},
providers::{Provider, WalletProvider},
Expand Down Expand Up @@ -92,8 +92,8 @@ impl<'a> SubmitPrep<'a> {
self.quincey_resp().await.map(|resp| &resp.sig).map(utils::extract_signature_components)
}

/// Encodes the sidecar and then builds the 4844 blob transaction from the provided header and signature values.
async fn build_blob_tx(&self) -> eyre::Result<TransactionRequest> {
/// Build the sidecar and input data for the transaction.
async fn build_sidecar_and_data(&self) -> eyre::Result<(BlobTransactionSidecar, Vec<u8>)> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's break these into two functions rather than return s tuple

let (v, r, s) = self.quincey_signature().await?;

let header = Zenith::BlockHeader {
Expand All @@ -106,24 +106,24 @@ impl<'a> SubmitPrep<'a> {
debug!(?header.hostBlockNumber, "built zenith block header");

let data = Zenith::submitBlockCall { header, v, r, s, _4: Bytes::new() }.abi_encode();

let sidecar = self.block.encode_blob::<SimpleCoder>().build()?;

Ok(TransactionRequest::default().with_blob_sidecar(sidecar).with_input(data))
Ok((sidecar, data))
}

/// Create a new transaction request for the host chain.
async fn new_tx_request(&self) -> eyre::Result<TransactionRequest> {
let nonce =
self.provider.get_transaction_count(self.provider.default_signer_address()).await?;

debug!(nonce, "assigned nonce to rollup block transaction");

// Create a blob transaction with the blob header and signature values and return it
let tx = self
.build_blob_tx()
.await?
let (sidecar, data) = self.build_sidecar_and_data().await?;
let tx = TransactionRequest::default()
.with_blob_sidecar(sidecar)
.with_input(data)
.with_to(self.config.constants.host_zenith())
.with_nonce(nonce);
debug!(?tx, "constructed rollup block transaction request");

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't trace the tx same reason as above

Ok(tx)
}
Expand Down