Skip to content
Open
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
33 changes: 17 additions & 16 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ alloy-rpc-types = "1.0.41"
alloy-genesis = "1.0.41"
alloy-rpc-client = "1.0.41"
alloy-provider = "1.0.41"
op-alloy-network = "0.22.0"
op-alloy-rpc-types-engine = "0.22.0"
op-alloy-consensus = "0.22.0"
op-alloy-rpc-types = "0.22.0"
op-alloy-network = "0.22.3"
op-alloy-rpc-types-engine = "0.22.3"
op-alloy-consensus = "0.22.3"
op-alloy-rpc-types = "0.22.3"
tokio-tungstenite = { version = "0.26.2", features = ["native-tls"] }
testcontainers = "0.23"
testcontainers-modules = { version = "0.11", features = ["redis"] }
9 changes: 9 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,12 @@ build-debug:

kurtosis-spawn:
kurtosis run github.com/ethpandaops/optimism-package@452133367b693e3ba22214a6615c86c60a1efd5e --args-file ./scripts/ci/kurtosis-params.yaml --enclave op-rollup-boost

clippy:
cargo clippy --workspace -- -D warnings

fmt:
cargo fmt --all

test:
cargo nextest run --workspace
1 change: 1 addition & 0 deletions crates/flashblocks-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ alloy-provider.workspace = true
op-alloy-network.workspace = true
op-alloy-consensus.workspace = true
op-alloy-rpc-types.workspace = true
op-alloy-rpc-types-engine.workspace = true

tokio.workspace = true
tokio-tungstenite.workspace = true
Expand Down
59 changes: 30 additions & 29 deletions crates/flashblocks-rpc/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,36 @@ use op_alloy_rpc_types::Transaction;
use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_evm::extract_l1_info;
use reth_optimism_primitives::OpPrimitives;
use reth_optimism_primitives::{OpBlock, OpReceipt, OpTransactionSigned};
use reth_optimism_primitives::{OpBlock, OpTransactionSigned};
use reth_optimism_rpc::OpReceiptBuilder;
use reth_primitives::Recovered;
use reth_primitives_traits::block::body::BlockBody;

use op_alloy_rpc_types_engine::OpFlashblockPayload;
use reth_rpc_eth_api::transaction::ConvertReceiptInput;
use reth_rpc_eth_api::{RpcBlock, RpcReceipt};
use rollup_boost::{
FlashblockBuilder, FlashblocksPayloadV1, OpExecutionPayloadEnvelope, PayloadVersion,
};
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, str::FromStr, sync::Arc};

#[derive(Debug, Deserialize, Serialize, Clone, Default)]
pub struct Metadata {
pub receipts: HashMap<String, OpReceipt>,
pub new_account_balances: HashMap<String, String>, // Address -> Balance (hex)
pub block_number: u64,
use rollup_boost::{FlashblockBuilder, OpExecutionPayloadEnvelope, PayloadVersion};
use std::{collections::HashMap, sync::Arc};

/// Convert op_alloy_consensus::OpReceipt to reth_optimism_primitives::OpReceipt
fn convert_receipt(receipt: &op_alloy_consensus::OpReceipt) -> reth_optimism_primitives::OpReceipt {
match receipt {
op_alloy_consensus::OpReceipt::Legacy(r) => {
reth_optimism_primitives::OpReceipt::Legacy(r.clone())
}
op_alloy_consensus::OpReceipt::Eip2930(r) => {
reth_optimism_primitives::OpReceipt::Eip2930(r.clone())
}
op_alloy_consensus::OpReceipt::Eip1559(r) => {
reth_optimism_primitives::OpReceipt::Eip1559(r.clone())
}
op_alloy_consensus::OpReceipt::Eip7702(r) => {
reth_optimism_primitives::OpReceipt::Eip7702(r.clone())
}
op_alloy_consensus::OpReceipt::Deposit(r) => {
reth_optimism_primitives::OpReceipt::Deposit(r.clone())
}
}
}

#[derive(Clone)]
Expand Down Expand Up @@ -65,7 +77,7 @@ impl FlashblocksCache {
ArcSwap::load(&self.inner).get_receipt(tx_hash)
}

pub fn process_payload(&self, payload: FlashblocksPayloadV1) -> eyre::Result<()> {
pub fn process_payload(&self, payload: OpFlashblockPayload) -> eyre::Result<()> {
let mut new_state = FlashblocksCacheInner::clone(&self.inner.load_full());
new_state.process_payload(payload)?;
self.inner.store(Arc::new(new_state));
Expand Down Expand Up @@ -147,14 +159,8 @@ impl FlashblocksCacheInner {
self.receipts_cache.clear();
}

pub fn process_payload(&mut self, payload: FlashblocksPayloadV1) -> eyre::Result<()> {
// Convert metadata with error handling
let metadata: Metadata = match serde_json::from_value(payload.metadata.clone()) {
Ok(m) => m,
Err(e) => {
return Err(eyre::eyre!("Failed to deserialize metadata: {}", e));
}
};
pub fn process_payload(&mut self, payload: OpFlashblockPayload) -> eyre::Result<()> {
let metadata = payload.metadata.clone();

if payload.index == 0 {
self.reset();
Expand Down Expand Up @@ -190,7 +196,7 @@ impl FlashblocksCacheInner {
// update the receipts
let receipt = metadata
.receipts
.get(&tx.tx_hash().to_string())
.get(&tx.tx_hash())
.expect("Receipt should exist");

all_receipts.push(receipt.clone());
Expand Down Expand Up @@ -226,7 +232,7 @@ impl FlashblocksCacheInner {
timestamp,
};
let input: ConvertReceiptInput<'_, OpPrimitives> = ConvertReceiptInput {
receipt: receipt.clone(),
receipt: convert_receipt(receipt),
tx: tx.try_to_recovered_ref()?,
gas_used: receipt.cumulative_gas_used() - gas_used,
next_log_index,
Expand All @@ -250,12 +256,7 @@ impl FlashblocksCacheInner {

// Store account balances
for (address, balance) in metadata.new_account_balances.iter() {
let address = Address::from_str(address)
.map_err(|e| eyre::eyre!("Failed to parse address: {}", e))?;
let balance = U256::from_str(balance)
.map_err(|e| eyre::eyre!("Failed to parse balance: {}", e))?;

self.balance_cache.insert(address, balance);
self.balance_cache.insert(*address, *balance);
}

Ok(())
Expand Down
10 changes: 5 additions & 5 deletions crates/flashblocks-rpc/src/flashblocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use alloy_primitives::{Address, TxHash, U256};
use futures_util::StreamExt;
use jsonrpsee::core::async_trait;
use op_alloy_network::Optimism;
use op_alloy_rpc_types_engine::OpFlashblockPayload;
use reth_optimism_chainspec::OpChainSpec;
use reth_rpc_eth_api::{RpcBlock, RpcReceipt};
use rollup_boost::FlashblocksPayloadV1;
use std::{io::Read, sync::Arc};
use tokio::sync::mpsc;
use tokio_tungstenite::{connect_async, tungstenite::Message};
Expand Down Expand Up @@ -101,19 +101,19 @@ impl FlashblocksOverlay {
Ok(())
}

pub fn process_payload(&self, payload: FlashblocksPayloadV1) -> eyre::Result<()> {
pub fn process_payload(&self, payload: OpFlashblockPayload) -> eyre::Result<()> {
self.cache.process_payload(payload)
}
}

enum InternalMessage {
NewPayload(FlashblocksPayloadV1),
NewPayload(OpFlashblockPayload),
}

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

let payload: FlashblocksPayloadV1 = match serde_json::from_str(&text) {
let payload: OpFlashblockPayload = match serde_json::from_str(&text) {
Ok(m) => m,
Err(e) => {
return Err(eyre::eyre!("failed to parse message: {}", e));
Expand Down
Loading
Loading