Skip to content

Commit 2d08270

Browse files
committed
Update to use op-alloy flashblock types
1 parent 272d462 commit 2d08270

File tree

4 files changed

+46
-34
lines changed

4 files changed

+46
-34
lines changed

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,11 @@ rollup-boost = { git = "https://github.com/flashbots/rollup-boost", tag = "v0.7.
167167
# optimism
168168
alloy-op-evm = { version = "0.23.0", default-features = false }
169169
alloy-op-hardforks = "0.4.4"
170-
op-alloy-rpc-types = { version = "0.22.0", default-features = false }
171-
op-alloy-rpc-types-engine = { version = "0.22.0", default-features = false }
172-
op-alloy-rpc-jsonrpsee = { version = "0.22.0", default-features = false }
173-
op-alloy-network = { version = "0.22.0", default-features = false }
174-
op-alloy-consensus = { version = "0.22.0", default-features = false }
170+
op-alloy-rpc-types = { version = "0.22.4", default-features = false }
171+
op-alloy-rpc-types-engine = { version = "0.22.4", default-features = false }
172+
op-alloy-rpc-jsonrpsee = { version = "0.22.4", default-features = false }
173+
op-alloy-network = { version = "0.22.4", default-features = false }
174+
op-alloy-consensus = { version = "0.22.4", default-features = false }
175175
op-alloy-flz = { version = "0.13.1", default-features = false }
176176

177177
async-trait = { version = "0.1.83" }

crates/op-rbuilder/src/builders/flashblocks/payload.rs

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,24 @@ use alloy_consensus::{
1616
BlockBody, EMPTY_OMMER_ROOT_HASH, Header, constants::EMPTY_WITHDRAWALS, proofs,
1717
};
1818
use alloy_eips::{Encodable2718, eip7685::EMPTY_REQUESTS_HASH, merge::BEACON_NONCE};
19-
use alloy_primitives::{Address, B256, U256, map::foldhash::HashMap};
19+
use alloy_primitives::{Address, B256, U256};
2020
use core::time::Duration;
2121
use eyre::WrapErr as _;
22+
use op_alloy_rpc_types_engine::{
23+
OpFlashblockPayload, OpFlashblockPayloadBase, OpFlashblockPayloadDelta,
24+
OpFlashblockPayloadMetadata,
25+
};
2226
use reth::payload::PayloadBuilderAttributes;
2327
use reth_basic_payload_builder::BuildOutcome;
2428
use reth_chain_state::ExecutedBlock;
2529
use reth_chainspec::EthChainSpec;
2630
use reth_evm::{ConfigureEvm, execute::BlockBuilder};
27-
use reth_node_api::{Block, NodePrimitives, PayloadBuilderError};
31+
use reth_node_api::{Block, PayloadBuilderError};
2832
use reth_optimism_consensus::{calculate_receipt_root_no_memo_optimism, isthmus};
2933
use reth_optimism_evm::{OpEvmConfig, OpNextBlockEnvAttributes};
3034
use reth_optimism_forks::OpHardforks;
3135
use reth_optimism_node::{OpBuiltPayload, OpPayloadBuilderAttributes};
32-
use reth_optimism_primitives::{OpPrimitives, OpReceipt, OpTransactionSigned};
36+
use reth_optimism_primitives::{OpReceipt, OpTransactionSigned};
3337
use reth_payload_util::BestPayloadTransactions;
3438
use reth_primitives_traits::RecoveredBlock;
3539
use reth_provider::{
@@ -42,11 +46,8 @@ use reth_revm::{
4246
use reth_transaction_pool::TransactionPool;
4347
use reth_trie::{HashedPostState, updates::TrieUpdates};
4448
use revm::Database;
45-
use rollup_boost::{
46-
ExecutionPayloadBaseV1, ExecutionPayloadFlashblockDeltaV1, FlashblocksPayloadV1,
47-
};
48-
use serde::{Deserialize, Serialize};
4949
use std::{
50+
collections::BTreeMap,
5051
ops::{Div, Rem},
5152
sync::Arc,
5253
time::Instant,
@@ -55,6 +56,24 @@ use tokio::sync::mpsc;
5556
use tokio_util::sync::CancellationToken;
5657
use tracing::{debug, error, info, metadata::Level, span, warn};
5758

59+
/// Converts a reth OpReceipt to an op-alloy OpReceipt
60+
/// TODO: remove this once reth updates to use the op-alloy defined type as well.
61+
fn convert_receipt(receipt: &OpReceipt) -> op_alloy_consensus::OpReceipt {
62+
match receipt {
63+
OpReceipt::Legacy(r) => op_alloy_consensus::OpReceipt::Legacy(r.clone()),
64+
OpReceipt::Eip2930(r) => op_alloy_consensus::OpReceipt::Eip2930(r.clone()),
65+
OpReceipt::Eip1559(r) => op_alloy_consensus::OpReceipt::Eip1559(r.clone()),
66+
OpReceipt::Eip7702(r) => op_alloy_consensus::OpReceipt::Eip7702(r.clone()),
67+
OpReceipt::Deposit(r) => {
68+
op_alloy_consensus::OpReceipt::Deposit(op_alloy_consensus::OpDepositReceipt {
69+
inner: r.inner.clone(),
70+
deposit_nonce: r.deposit_nonce,
71+
deposit_receipt_version: r.deposit_receipt_version,
72+
})
73+
}
74+
}
75+
}
76+
5877
type NextBestFlashblocksTxs<Pool> = BestFlashblocksTxs<
5978
<Pool as TransactionPool>::Transaction,
6079
Box<
@@ -939,13 +958,6 @@ where
939958
}
940959
}
941960

942-
#[derive(Debug, Serialize, Deserialize)]
943-
struct FlashblocksMetadata {
944-
receipts: HashMap<B256, <OpPrimitives as NodePrimitives>::Receipt>,
945-
new_account_balances: HashMap<Address, U256>,
946-
block_number: u64,
947-
}
948-
949961
fn execute_pre_steps<DB, ExtraCtx>(
950962
state: &mut State<DB>,
951963
ctx: &OpPayloadBuilderCtx<ExtraCtx>,
@@ -971,7 +983,7 @@ pub(super) fn build_block<DB, P, ExtraCtx>(
971983
ctx: &OpPayloadBuilderCtx<ExtraCtx>,
972984
info: &mut ExecutionInfo<FlashblocksExecutionInfo>,
973985
calculate_state_root: bool,
974-
) -> Result<(OpBuiltPayload, FlashblocksPayloadV1), PayloadBuilderError>
986+
) -> Result<(OpBuiltPayload, OpFlashblockPayload), PayloadBuilderError>
975987
where
976988
DB: Database<Error = ProviderError> + AsRef<P>,
977989
P: StateRootProvider + HashedPostStateProvider + StorageRootProvider,
@@ -1138,16 +1150,16 @@ where
11381150
let receipts_with_hash = new_transactions
11391151
.iter()
11401152
.zip(new_receipts.iter())
1141-
.map(|(tx, receipt)| (tx.tx_hash(), receipt.clone()))
1142-
.collect::<HashMap<B256, OpReceipt>>();
1153+
.map(|(tx, receipt)| (tx.tx_hash(), convert_receipt(receipt)))
1154+
.collect::<BTreeMap<B256, op_alloy_consensus::OpReceipt>>();
11431155
let new_account_balances = state
11441156
.bundle_state
11451157
.state
11461158
.iter()
11471159
.filter_map(|(address, account)| account.info.as_ref().map(|info| (*address, info.balance)))
1148-
.collect::<HashMap<Address, U256>>();
1160+
.collect::<BTreeMap<Address, U256>>();
11491161

1150-
let metadata: FlashblocksMetadata = FlashblocksMetadata {
1162+
let metadata = OpFlashblockPayloadMetadata {
11511163
receipts: receipts_with_hash,
11521164
new_account_balances,
11531165
block_number: ctx.parent().number + 1,
@@ -1156,10 +1168,10 @@ where
11561168
let (_, blob_gas_used) = ctx.blob_fields(info);
11571169

11581170
// Prepare the flashblocks message
1159-
let fb_payload = FlashblocksPayloadV1 {
1171+
let fb_payload = OpFlashblockPayload {
11601172
payload_id: ctx.payload_id(),
11611173
index: 0,
1162-
base: Some(ExecutionPayloadBaseV1 {
1174+
base: Some(OpFlashblockPayloadBase {
11631175
parent_beacon_block_root: ctx
11641176
.attributes()
11651177
.payload_attributes
@@ -1172,9 +1184,9 @@ where
11721184
gas_limit: ctx.block_gas_limit(),
11731185
timestamp: ctx.attributes().payload_attributes.timestamp,
11741186
extra_data: ctx.extra_data()?,
1175-
base_fee_per_gas: ctx.base_fee().try_into().unwrap(),
1187+
base_fee_per_gas: U256::from(ctx.base_fee()),
11761188
}),
1177-
diff: ExecutionPayloadFlashblockDeltaV1 {
1189+
diff: OpFlashblockPayloadDelta {
11781190
state_root,
11791191
receipts_root,
11801192
logs_bloom,
@@ -1185,7 +1197,7 @@ where
11851197
withdrawals_root: withdrawals_root.unwrap_or_default(),
11861198
blob_gas_used,
11871199
},
1188-
metadata: serde_json::to_value(&metadata).unwrap_or_default(),
1200+
metadata,
11891201
};
11901202

11911203
// We clean bundle and place initial state transaction back

crates/op-rbuilder/src/builders/flashblocks/payload_handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use alloy_evm::eth::receipt_builder::ReceiptBuilderCtx;
99
use alloy_primitives::B64;
1010
use eyre::{WrapErr as _, bail};
1111
use op_alloy_consensus::OpTxEnvelope;
12+
use op_alloy_rpc_types_engine::OpFlashblockPayload;
1213
use reth::revm::{State, database::StateProviderDatabase};
1314
use reth_basic_payload_builder::PayloadConfig;
1415
use reth_evm::FromRecoveredTx;
@@ -19,7 +20,6 @@ use reth_optimism_node::{OpEngineTypes, OpPayloadBuilderAttributes};
1920
use reth_optimism_payload_builder::OpBuiltPayload;
2021
use reth_optimism_primitives::{OpReceipt, OpTransactionSigned};
2122
use reth_payload_builder::EthPayloadBuilderAttributes;
22-
use rollup_boost::FlashblocksPayloadV1;
2323
use std::sync::Arc;
2424
use tokio::sync::mpsc;
2525
use tracing::warn;
@@ -135,7 +135,7 @@ fn execute_flashblock<Client>(
135135
ctx: OpPayloadSyncerCtx,
136136
client: Client,
137137
cancel: tokio_util::sync::CancellationToken,
138-
) -> eyre::Result<(OpBuiltPayload, FlashblocksPayloadV1)>
138+
) -> eyre::Result<(OpBuiltPayload, OpFlashblockPayload)>
139139
where
140140
Client: ClientBounds,
141141
{

crates/op-rbuilder/src/builders/flashblocks/wspub.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use core::{
55
};
66
use futures::SinkExt;
77
use futures_util::StreamExt;
8-
use rollup_boost::FlashblocksPayloadV1;
8+
use op_alloy_rpc_types_engine::OpFlashblockPayload;
99
use std::{io, net::TcpListener, sync::Arc};
1010
use tokio::{
1111
net::TcpStream,
@@ -25,7 +25,7 @@ use crate::metrics::OpRBuilderMetrics;
2525
/// A WebSockets publisher that accepts connections from client websockets and broadcasts to them
2626
/// updates about new flashblocks. It maintains a count of sent messages and active subscriptions.
2727
///
28-
/// This is modelled as a `futures::Sink` that can be used to send `FlashblocksPayloadV1` messages.
28+
/// This is modelled as a `futures::Sink` that can be used to send `OpFlashblockPayload` messages.
2929
pub(super) struct WebSocketPublisher {
3030
sent: Arc<AtomicUsize>,
3131
subs: Arc<AtomicUsize>,
@@ -59,7 +59,7 @@ impl WebSocketPublisher {
5959
})
6060
}
6161

62-
pub(super) fn publish(&self, payload: &FlashblocksPayloadV1) -> io::Result<usize> {
62+
pub(super) fn publish(&self, payload: &OpFlashblockPayload) -> io::Result<usize> {
6363
// Serialize the payload to a UTF-8 string
6464
// serialize only once, then just copy around only a pointer
6565
// to the serialized data for each subscription.

0 commit comments

Comments
 (0)