Skip to content

Commit 50d3ee4

Browse files
committed
Update to use op-alloy flashblock types
1 parent 196237b commit 50d3ee4

File tree

12 files changed

+146
-226
lines changed

12 files changed

+146
-226
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ alloy-rpc-types = "1.0.41"
4040
alloy-genesis = "1.0.41"
4141
alloy-rpc-client = "1.0.41"
4242
alloy-provider = "1.0.41"
43-
op-alloy-network = "0.22.0"
44-
op-alloy-rpc-types-engine = "0.22.0"
45-
op-alloy-consensus = "0.22.0"
46-
op-alloy-rpc-types = "0.22.0"
43+
op-alloy-network = "0.22.3"
44+
op-alloy-rpc-types-engine = "0.22.3"
45+
op-alloy-consensus = "0.22.3"
46+
op-alloy-rpc-types = "0.22.3"
4747
tokio-tungstenite = { version = "0.26.2", features = ["native-tls"] }
4848
testcontainers = "0.23"
4949
testcontainers-modules = { version = "0.11", features = ["redis"] }

Justfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,12 @@ build-debug:
1818

1919
kurtosis-spawn:
2020
kurtosis run github.com/ethpandaops/optimism-package@452133367b693e3ba22214a6615c86c60a1efd5e --args-file ./scripts/ci/kurtosis-params.yaml --enclave op-rollup-boost
21+
22+
clippy:
23+
cargo clippy --workspace -- -D warnings
24+
25+
fmt:
26+
cargo fmt --all
27+
28+
test:
29+
cargo nextest run --workspace

crates/flashblocks-rpc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ alloy-provider.workspace = true
4242
op-alloy-network.workspace = true
4343
op-alloy-consensus.workspace = true
4444
op-alloy-rpc-types.workspace = true
45+
op-alloy-rpc-types-engine.workspace = true
4546

4647
tokio.workspace = true
4748
tokio-tungstenite.workspace = true

crates/flashblocks-rpc/src/cache.rs

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,36 @@ use op_alloy_rpc_types::Transaction;
1414
use reth_optimism_chainspec::OpChainSpec;
1515
use reth_optimism_evm::extract_l1_info;
1616
use reth_optimism_primitives::OpPrimitives;
17-
use reth_optimism_primitives::{OpBlock, OpReceipt, OpTransactionSigned};
17+
use reth_optimism_primitives::{OpBlock, OpTransactionSigned};
1818
use reth_optimism_rpc::OpReceiptBuilder;
1919
use reth_primitives::Recovered;
2020
use reth_primitives_traits::block::body::BlockBody;
2121

22+
use op_alloy_rpc_types_engine::OpFlashblockPayload;
2223
use reth_rpc_eth_api::transaction::ConvertReceiptInput;
2324
use reth_rpc_eth_api::{RpcBlock, RpcReceipt};
24-
use rollup_boost::{
25-
FlashblockBuilder, FlashblocksPayloadV1, OpExecutionPayloadEnvelope, PayloadVersion,
26-
};
27-
use serde::{Deserialize, Serialize};
28-
use std::{collections::HashMap, str::FromStr, sync::Arc};
29-
30-
#[derive(Debug, Deserialize, Serialize, Clone, Default)]
31-
pub struct Metadata {
32-
pub receipts: HashMap<String, OpReceipt>,
33-
pub new_account_balances: HashMap<String, String>, // Address -> Balance (hex)
34-
pub block_number: u64,
25+
use rollup_boost::{FlashblockBuilder, OpExecutionPayloadEnvelope, PayloadVersion};
26+
use std::{collections::HashMap, sync::Arc};
27+
28+
/// Convert op_alloy_consensus::OpReceipt to reth_optimism_primitives::OpReceipt
29+
fn convert_receipt(receipt: &op_alloy_consensus::OpReceipt) -> reth_optimism_primitives::OpReceipt {
30+
match receipt {
31+
op_alloy_consensus::OpReceipt::Legacy(r) => {
32+
reth_optimism_primitives::OpReceipt::Legacy(r.clone())
33+
}
34+
op_alloy_consensus::OpReceipt::Eip2930(r) => {
35+
reth_optimism_primitives::OpReceipt::Eip2930(r.clone())
36+
}
37+
op_alloy_consensus::OpReceipt::Eip1559(r) => {
38+
reth_optimism_primitives::OpReceipt::Eip1559(r.clone())
39+
}
40+
op_alloy_consensus::OpReceipt::Eip7702(r) => {
41+
reth_optimism_primitives::OpReceipt::Eip7702(r.clone())
42+
}
43+
op_alloy_consensus::OpReceipt::Deposit(r) => {
44+
reth_optimism_primitives::OpReceipt::Deposit(r.clone())
45+
}
46+
}
3547
}
3648

3749
#[derive(Clone)]
@@ -65,7 +77,7 @@ impl FlashblocksCache {
6577
ArcSwap::load(&self.inner).get_receipt(tx_hash)
6678
}
6779

68-
pub fn process_payload(&self, payload: FlashblocksPayloadV1) -> eyre::Result<()> {
80+
pub fn process_payload(&self, payload: OpFlashblockPayload) -> eyre::Result<()> {
6981
let mut new_state = FlashblocksCacheInner::clone(&self.inner.load_full());
7082
new_state.process_payload(payload)?;
7183
self.inner.store(Arc::new(new_state));
@@ -147,14 +159,8 @@ impl FlashblocksCacheInner {
147159
self.receipts_cache.clear();
148160
}
149161

150-
pub fn process_payload(&mut self, payload: FlashblocksPayloadV1) -> eyre::Result<()> {
151-
// Convert metadata with error handling
152-
let metadata: Metadata = match serde_json::from_value(payload.metadata.clone()) {
153-
Ok(m) => m,
154-
Err(e) => {
155-
return Err(eyre::eyre!("Failed to deserialize metadata: {}", e));
156-
}
157-
};
162+
pub fn process_payload(&mut self, payload: OpFlashblockPayload) -> eyre::Result<()> {
163+
let metadata = payload.metadata.clone();
158164

159165
if payload.index == 0 {
160166
self.reset();
@@ -190,7 +196,7 @@ impl FlashblocksCacheInner {
190196
// update the receipts
191197
let receipt = metadata
192198
.receipts
193-
.get(&tx.tx_hash().to_string())
199+
.get(&tx.tx_hash())
194200
.expect("Receipt should exist");
195201

196202
all_receipts.push(receipt.clone());
@@ -226,7 +232,7 @@ impl FlashblocksCacheInner {
226232
timestamp,
227233
};
228234
let input: ConvertReceiptInput<'_, OpPrimitives> = ConvertReceiptInput {
229-
receipt: receipt.clone(),
235+
receipt: convert_receipt(receipt),
230236
tx: tx.try_to_recovered_ref()?,
231237
gas_used: receipt.cumulative_gas_used() - gas_used,
232238
next_log_index,
@@ -250,12 +256,7 @@ impl FlashblocksCacheInner {
250256

251257
// Store account balances
252258
for (address, balance) in metadata.new_account_balances.iter() {
253-
let address = Address::from_str(address)
254-
.map_err(|e| eyre::eyre!("Failed to parse address: {}", e))?;
255-
let balance = U256::from_str(balance)
256-
.map_err(|e| eyre::eyre!("Failed to parse balance: {}", e))?;
257-
258-
self.balance_cache.insert(address, balance);
259+
self.balance_cache.insert(*address, *balance);
259260
}
260261

261262
Ok(())

crates/flashblocks-rpc/src/flashblocks.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use alloy_primitives::{Address, TxHash, U256};
33
use futures_util::StreamExt;
44
use jsonrpsee::core::async_trait;
55
use op_alloy_network::Optimism;
6+
use op_alloy_rpc_types_engine::OpFlashblockPayload;
67
use reth_optimism_chainspec::OpChainSpec;
78
use reth_rpc_eth_api::{RpcBlock, RpcReceipt};
8-
use rollup_boost::FlashblocksPayloadV1;
99
use std::{io::Read, sync::Arc};
1010
use tokio::sync::mpsc;
1111
use tokio_tungstenite::{connect_async, tungstenite::Message};
@@ -101,19 +101,19 @@ impl FlashblocksOverlay {
101101
Ok(())
102102
}
103103

104-
pub fn process_payload(&self, payload: FlashblocksPayloadV1) -> eyre::Result<()> {
104+
pub fn process_payload(&self, payload: OpFlashblockPayload) -> eyre::Result<()> {
105105
self.cache.process_payload(payload)
106106
}
107107
}
108108

109109
enum InternalMessage {
110-
NewPayload(FlashblocksPayloadV1),
110+
NewPayload(OpFlashblockPayload),
111111
}
112112

113-
fn try_decode_message(bytes: &[u8]) -> eyre::Result<FlashblocksPayloadV1> {
113+
fn try_decode_message(bytes: &[u8]) -> eyre::Result<OpFlashblockPayload> {
114114
let text = try_parse_message(bytes)?;
115115

116-
let payload: FlashblocksPayloadV1 = match serde_json::from_str(&text) {
116+
let payload: OpFlashblockPayload = match serde_json::from_str(&text) {
117117
Ok(m) => m,
118118
Err(e) => {
119119
return Err(eyre::eyre!("failed to parse message: {}", e));

0 commit comments

Comments
 (0)