diff --git a/Cargo.lock b/Cargo.lock index d89fef3..2317f13 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -97,9 +97,9 @@ checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" [[package]] name = "alloy" -version = "1.0.35" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d8f4cc1a6f6e5d3adf05f93123932bfd5168078a556d90dd9897bc0a75dee24" +checksum = "f07655fedc35188f3c50ff8fc6ee45703ae14ef1bc7ae7d80e23a747012184e3" dependencies = [ "alloy-consensus", "alloy-contract", @@ -2440,7 +2440,7 @@ dependencies = [ [[package]] name = "builder" -version = "0.6.2" +version = "1.0.0-rc.0" dependencies = [ "alloy", "alloy-chains", diff --git a/Cargo.toml b/Cargo.toml index e36b70c..c58eb5c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "builder" -version = "0.6.2" +version = "1.0.0-rc.0" description = "signet builder example" edition = "2024" @@ -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", diff --git a/src/tasks/submit/flashbots.rs b/src/tasks/submit/flashbots.rs index 70e5744..3c4fd8b 100644 --- a/src/tasks/submit/flashbots.rs +++ b/src/tasks/submit/flashbots.rs @@ -6,16 +6,20 @@ 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 eyre::Context; 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 TxEnvelope7594 = EthereumTxEnvelope>; + /// Handles preparation and submission of simulated rollup blocks to the /// Flashbots relay as MEV bundles. #[derive(Debug)] @@ -84,7 +88,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(), @@ -100,7 +103,7 @@ impl FlashbotsTask { async fn prepare_signed_transaction( &self, sim_result: &SimResult, - ) -> eyre::Result { + ) -> eyre::Result { let prep = SubmitPrep::new( &sim_result.block, self.host_provider(), @@ -115,14 +118,18 @@ impl FlashbotsTask { .instrument(tracing::debug_span!("fill_tx").or_current()) .await?; - sendable.as_envelope().ok_or_eyre("failed to get envelope from filled tx").cloned() + let tx_envelope = + sendable.try_into_envelope()?.try_into_7594().wrap_err("failed to map 4844 to 7594")?; + debug!(tx_hash = ?tx_envelope.hash(), "prepared signed rollup block transaction envelope"); + + 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: &TxEnvelope7594) { counter!("signet.builder.flashbots.").increment(1); let hash = *envelope.tx_hash(); if self.outbound.send(hash).is_err() { diff --git a/src/tasks/submit/prep.rs b/src/tasks/submit/prep.rs index 4be2941..179188f 100644 --- a/src/tasks/submit/prep.rs +++ b/src/tasks/submit/prep.rs @@ -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}, @@ -15,6 +15,7 @@ use init4_bin_base::deps::metrics::counter; use signet_sim::BuiltBlock; use signet_types::{SignRequest, SignResponse}; use signet_zenith::Zenith; +use tokio::try_join; use tracing::{Instrument, debug, instrument}; /// Preparation logic for transactions issued to the host chain by the @@ -92,8 +93,15 @@ 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 { + /// Encodes the rollup block into a sidecar. + async fn build_sidecar(&self) -> eyre::Result { + let sidecar = self.block.encode_blob::().build()?; + + Ok(sidecar) + } + + /// Build a signature and header input for the host chain transaction. + async fn build_input(&self) -> eyre::Result> { let (v, r, s) = self.quincey_signature().await?; let header = Zenith::BlockHeader { @@ -107,21 +115,19 @@ impl<'a> SubmitPrep<'a> { let data = Zenith::submitBlockCall { header, v, r, s, _4: Bytes::new() }.abi_encode(); - let sidecar = self.block.encode_blob::().build()?; - - Ok(TransactionRequest::default().with_blob_sidecar(sidecar).with_input(data)) + Ok(data) } + /// Create a new transaction request for the host chain. async fn new_tx_request(&self) -> eyre::Result { let nonce = self.provider.get_transaction_count(self.provider.default_signer_address()).await?; - debug!(nonce, "assigned nonce to rollup block transaction"); + let (sidecar, input) = try_join!(self.build_sidecar(), self.build_input())?; - // Create a blob transaction with the blob header and signature values and return it - let tx = self - .build_blob_tx() - .await? + let tx = TransactionRequest::default() + .with_blob_sidecar(sidecar) + .with_input(input) .with_to(self.config.constants.host_zenith()) .with_nonce(nonce);