Skip to content

Commit 2dffd30

Browse files
authored
fix: update to eip 7594 blob handling (#202)
* fix: update to eip 7954 blob handling * logs * moar logs * clippy * deps: unpin and update alloy to 1.0.40 * address reviews * comments * deps: bump builder version to 1.0.0-rc.0
1 parent a940e5a commit 2dffd30

File tree

4 files changed

+35
-22
lines changed

4 files changed

+35
-22
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "builder"
3-
version = "0.6.2"
3+
version = "1.0.0-rc.0"
44
description = "signet builder example"
55

66
edition = "2024"
@@ -30,7 +30,7 @@ signet-genesis = { git = "https://github.com/init4tech/node-components", tag = "
3030

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

33-
alloy = { version = "=1.0.35", features = [
33+
alloy = { version = "1.0.40", features = [
3434
"full",
3535
"json-rpc",
3636
"signer-aws",

src/tasks/submit/flashbots.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@ use crate::{
66
tasks::{block::sim::SimResult, submit::SubmitPrep},
77
};
88
use alloy::{
9-
eips::Encodable2718,
9+
consensus::{EthereumTxEnvelope, TxEip4844Variant},
10+
eips::{Encodable2718, eip7594::BlobTransactionSidecarEip7594},
1011
primitives::{Bytes, TxHash},
1112
providers::ext::MevApi,
1213
rpc::types::mev::EthSendBundle,
1314
};
14-
use eyre::OptionExt;
15+
use eyre::Context;
1516
use init4_bin_base::{deps::metrics::counter, utils::signer::LocalOrAws};
1617
use tokio::{sync::mpsc, task::JoinHandle};
1718
use tracing::{Instrument, debug, debug_span, error, instrument};
1819

20+
/// Type alias for a EIP 7594 compatible blob sidecar transaction envelope.
21+
type TxEnvelope7594 = EthereumTxEnvelope<TxEip4844Variant<BlobTransactionSidecarEip7594>>;
22+
1923
/// Handles preparation and submission of simulated rollup blocks to the
2024
/// Flashbots relay as MEV bundles.
2125
#[derive(Debug)]
@@ -84,7 +88,6 @@ impl FlashbotsTask {
8488
let txs = self.build_bundle_body(sim_result, tx_bytes);
8589

8690
// Create the MEV bundle (valid only in the specific host block)
87-
8891
Ok(EthSendBundle {
8992
txs,
9093
block_number: sim_result.host_block_number(),
@@ -100,7 +103,7 @@ impl FlashbotsTask {
100103
async fn prepare_signed_transaction(
101104
&self,
102105
sim_result: &SimResult,
103-
) -> eyre::Result<alloy::consensus::TxEnvelope> {
106+
) -> eyre::Result<TxEnvelope7594> {
104107
let prep = SubmitPrep::new(
105108
&sim_result.block,
106109
self.host_provider(),
@@ -115,14 +118,18 @@ impl FlashbotsTask {
115118
.instrument(tracing::debug_span!("fill_tx").or_current())
116119
.await?;
117120

118-
sendable.as_envelope().ok_or_eyre("failed to get envelope from filled tx").cloned()
121+
let tx_envelope =
122+
sendable.try_into_envelope()?.try_into_7594().wrap_err("failed to map 4844 to 7594")?;
123+
debug!(tx_hash = ?tx_envelope.hash(), "prepared signed rollup block transaction envelope");
124+
125+
Ok(tx_envelope)
119126
}
120127

121128
/// Tracks the outbound transaction hash and increments submission metrics.
122129
///
123130
/// Sends the transaction hash to the outbound channel for monitoring.
124131
/// Logs a debug message if the channel is closed.
125-
fn track_outbound_tx(&self, envelope: &alloy::consensus::TxEnvelope) {
132+
fn track_outbound_tx(&self, envelope: &TxEnvelope7594) {
126133
counter!("signet.builder.flashbots.").increment(1);
127134
let hash = *envelope.tx_hash();
128135
if self.outbound.send(hash).is_err() {

src/tasks/submit/prep.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
utils,
55
};
66
use alloy::{
7-
consensus::{Header, SimpleCoder},
7+
consensus::{BlobTransactionSidecar, Header, SimpleCoder},
88
network::{TransactionBuilder, TransactionBuilder4844},
99
primitives::{B256, Bytes, U256},
1010
providers::{Provider, WalletProvider},
@@ -15,6 +15,7 @@ use init4_bin_base::deps::metrics::counter;
1515
use signet_sim::BuiltBlock;
1616
use signet_types::{SignRequest, SignResponse};
1717
use signet_zenith::Zenith;
18+
use tokio::try_join;
1819
use tracing::{Instrument, debug, error, instrument, warn};
1920

2021
/// Preparation logic for transactions issued to the host chain by the
@@ -101,8 +102,15 @@ impl<'a> SubmitPrep<'a> {
101102
self.quincey_resp().await.map(|resp| &resp.sig).map(utils::extract_signature_components)
102103
}
103104

104-
/// Encodes the sidecar and then builds the 4844 blob transaction from the provided header and signature values.
105-
async fn build_blob_tx(&self) -> eyre::Result<TransactionRequest> {
105+
/// Encodes the rollup block into a sidecar.
106+
async fn build_sidecar(&self) -> eyre::Result<BlobTransactionSidecar> {
107+
let sidecar = self.block.encode_blob::<SimpleCoder>().build()?;
108+
109+
Ok(sidecar)
110+
}
111+
112+
/// Build a signature and header input for the host chain transaction.
113+
async fn build_input(&self) -> eyre::Result<Vec<u8>> {
106114
let (v, r, s) = self.quincey_signature().await?;
107115

108116
let header = Zenith::BlockHeader {
@@ -116,21 +124,19 @@ impl<'a> SubmitPrep<'a> {
116124

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

119-
let sidecar = self.block.encode_blob::<SimpleCoder>().build()?;
120-
121-
Ok(TransactionRequest::default().with_blob_sidecar(sidecar).with_input(data))
127+
Ok(data)
122128
}
123129

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

128-
debug!(nonce, "assigned nonce to rollup block transaction");
135+
let (sidecar, input) = try_join!(self.build_sidecar(), self.build_input())?;
129136

130-
// Create a blob transaction with the blob header and signature values and return it
131-
let tx = self
132-
.build_blob_tx()
133-
.await?
137+
let tx = TransactionRequest::default()
138+
.with_blob_sidecar(sidecar)
139+
.with_input(input)
134140
.with_to(self.config.constants.host_zenith())
135141
.with_nonce(nonce);
136142

0 commit comments

Comments
 (0)