Skip to content
Merged
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
928 changes: 160 additions & 768 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,13 @@ base-reth-cli = { path = "crates/cli" }
base-reth-rpc = { path = "crates/rpc" }
base-tracex = { path = "crates/tracex" }
base-reth-runner = { path = "crates/runner" }
base-flashtypes = { path = "crates/flashtypes" }
base-reth-test-utils = { path = "crates/test-utils" }
base-reth-flashblocks = { path = "crates/flashblocks" }

# base/tips
tips-core = { git = "https://github.com/base/tips", rev = "b1dfde6a5c8f603f19f9309ca6dc015bad260b44" }

# rollup-boost
rollup-boost = { git = "http://github.com/flashbots/rollup-boost", rev = "v0.7.11" }

# reth
reth = { git = "https://github.com/paradigmxyz/reth", tag = "v1.9.3" }
reth-ipc = { git = "https://github.com/paradigmxyz/reth", tag = "v1.9.3" }
Expand Down
4 changes: 2 additions & 2 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ lychee:
@command -v lychee >/dev/null 2>&1 || cargo install lychee
lychee --config ./lychee.toml .

# Checks formatting, clippy, and tests
check: check-format check-clippy test
# Checks formatting, udeps, clippy, and tests
check: check-format check-udeps check-clippy test

# Fixes formatting and clippy issues
fix: format-fix clippy-fix zepter-fix
Expand Down
12 changes: 3 additions & 9 deletions crates/flashblocks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ repository.workspace = true
workspace = true

[dependencies]
# workspace
base-flashtypes.workspace = true

# reth
reth.workspace = true
reth-evm.workspace = true
Expand All @@ -37,9 +40,6 @@ op-alloy-network.workspace = true
op-alloy-rpc-types.workspace = true
op-alloy-consensus.workspace = true

# rollup-boost
rollup-boost.workspace = true

# tokio
tokio.workspace = true
tokio-tungstenite.workspace = true
Expand All @@ -50,19 +50,13 @@ futures-util.workspace = true
# misc
url.workspace = true
eyre.workspace = true
bytes.workspace = true
serde.workspace = true
brotli.workspace = true
tracing.workspace = true
metrics.workspace = true
arc-swap.workspace = true
serde_json.workspace = true
metrics-derive.workspace = true
derive_more = { workspace = true, features = ["display", "error"] }

[dev-dependencies]
rand.workspace = true
rstest.workspace = true
reth-db.workspace = true
once_cell.workspace = true
reth-provider.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions crates/flashblocks/benches/pending_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ use alloy_consensus::Receipt;
use alloy_eips::{BlockHashOrNumber, Encodable2718};
use alloy_primitives::{Address, B256, BlockNumber, Bytes, U256, b256, bytes, hex::FromHex};
use alloy_rpc_types_engine::PayloadId;
use base_reth_flashblocks::{
Flashblock, FlashblocksAPI, FlashblocksReceiver, FlashblocksState, Metadata,
use base_flashtypes::{
ExecutionPayloadBaseV1, ExecutionPayloadFlashblockDeltaV1, Flashblock, Metadata,
};
use base_reth_flashblocks::{FlashblocksAPI, FlashblocksReceiver, FlashblocksState};
use base_reth_test_utils::{LocalNodeProvider, TestAccounts, TestHarness};
use criterion::{BatchSize, Criterion, Throughput, criterion_group, criterion_main};
use op_alloy_consensus::OpDepositReceipt;
Expand All @@ -22,7 +23,6 @@ use reth::{
};
use reth_optimism_primitives::{OpBlock, OpReceipt, OpTransactionSigned};
use reth_primitives_traits::{Block as BlockT, RecoveredBlock};
use rollup_boost::{ExecutionPayloadBaseV1, ExecutionPayloadFlashblockDeltaV1};
use tokio::{runtime::Runtime, time::sleep};
use tracing_subscriber::{EnvFilter, filter::LevelFilter};

Expand Down
3 changes: 0 additions & 3 deletions crates/flashblocks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,3 @@ pub use subscription::FlashblocksSubscriber;

mod traits;
pub use traits::{FlashblocksAPI, FlashblocksReceiver, PendingBlocksAPI};

mod blocks;
pub use blocks::{Flashblock, FlashblockDecodeError, Metadata};
3 changes: 2 additions & 1 deletion crates/flashblocks/src/pending_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ use alloy_provider::network::TransactionResponse;
use alloy_rpc_types::{BlockTransactions, state::StateOverride};
use alloy_rpc_types_eth::{Filter, Header as RPCHeader, Log};
use arc_swap::Guard;
use base_flashtypes::Flashblock;
use eyre::eyre;
use op_alloy_network::Optimism;
use op_alloy_rpc_types::{OpTransactionReceipt, Transaction};
use reth::revm::{db::Cache, state::EvmState};
use reth_rpc_convert::RpcTransaction;
use reth_rpc_eth_api::{RpcBlock, RpcReceipt};

use crate::{Flashblock, PendingBlocksAPI};
use crate::PendingBlocksAPI;

/// Builder for [`PendingBlocks`].
#[derive(Debug)]
Expand Down
3 changes: 2 additions & 1 deletion crates/flashblocks/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use alloy_rpc_types::{TransactionTrait, Withdrawal};
use alloy_rpc_types_engine::{ExecutionPayloadV1, ExecutionPayloadV2, ExecutionPayloadV3};
use alloy_rpc_types_eth::state::StateOverride;
use arc_swap::ArcSwapOption;
use base_flashtypes::Flashblock;
use eyre::eyre;
use op_alloy_consensus::OpTxEnvelope;
use op_alloy_network::TransactionResponse;
Expand All @@ -38,7 +39,7 @@ use reth_rpc_convert::transaction::ConvertReceiptInput;
use tokio::sync::{Mutex, broadcast::Sender, mpsc::UnboundedReceiver};
use tracing::{debug, error, info, warn};

use crate::{Flashblock, Metrics, PendingBlocks, PendingBlocksBuilder};
use crate::{Metrics, PendingBlocks, PendingBlocksBuilder};

/// Messages consumed by the state processor.
#[derive(Debug, Clone)]
Expand Down
3 changes: 2 additions & 1 deletion crates/flashblocks/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::sync::Arc;

use alloy_consensus::Header;
use arc_swap::{ArcSwapOption, Guard};
use base_flashtypes::Flashblock;
use reth::{
chainspec::{ChainSpecProvider, EthChainSpec},
providers::{BlockReaderIdExt, StateProviderFactory},
Expand All @@ -19,7 +20,7 @@ use tokio::sync::{
use tracing::{error, info};

use crate::{
Flashblock, FlashblocksAPI, FlashblocksReceiver, PendingBlocks,
FlashblocksAPI, FlashblocksReceiver, PendingBlocks,
processor::{StateProcessor, StateUpdate},
};

Expand Down
3 changes: 2 additions & 1 deletion crates/flashblocks/src/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

use std::{sync::Arc, time::Duration};

use base_flashtypes::Flashblock;
use futures_util::{SinkExt as _, StreamExt};
use tokio::{sync::mpsc, time::interval};
use tokio_tungstenite::{connect_async, tungstenite::protocol::Message};
use tracing::{error, info, trace, warn};
use url::Url;

use crate::{Flashblock, FlashblocksReceiver, Metrics};
use crate::{FlashblocksReceiver, Metrics};

// Simplify actor messages to just handle shutdown
#[derive(Debug)]
Expand Down
3 changes: 2 additions & 1 deletion crates/flashblocks/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ use alloy_eips::BlockNumberOrTag;
use alloy_primitives::{Address, TxHash, U256};
use alloy_rpc_types_eth::{Filter, Log, state::StateOverride};
use arc_swap::Guard;
use base_flashtypes::Flashblock;
use op_alloy_network::Optimism;
use reth_rpc_convert::RpcTransaction;
use reth_rpc_eth_api::{RpcBlock, RpcReceipt};
use tokio::sync::broadcast;

use crate::{Flashblock, PendingBlocks};
use crate::PendingBlocks;

/// Trait for receiving flashblock updates.
pub trait FlashblocksReceiver {
Expand Down
6 changes: 3 additions & 3 deletions crates/flashblocks/tests/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ use alloy_primitives::{
Address, B256, BlockNumber, Bytes, U256, hex::FromHex, map::foldhash::HashMap,
};
use alloy_rpc_types_engine::PayloadId;
use base_reth_flashblocks::{
Flashblock, FlashblocksAPI, FlashblocksState, Metadata, PendingBlocksAPI,
use base_flashtypes::{
ExecutionPayloadBaseV1, ExecutionPayloadFlashblockDeltaV1, Flashblock, Metadata,
};
use base_reth_flashblocks::{FlashblocksAPI, FlashblocksState, PendingBlocksAPI};
use base_reth_test_utils::{
FlashblocksHarness, L1_BLOCK_INFO_DEPOSIT_TX, L1_BLOCK_INFO_DEPOSIT_TX_HASH, LocalNodeProvider,
TestAccounts,
Expand All @@ -25,7 +26,6 @@ use reth::{
use reth_optimism_primitives::{OpBlock, OpReceipt, OpTransactionSigned};
use reth_primitives_traits::{Account, Block as BlockT, RecoveredBlock};
use reth_provider::{ChainSpecProvider, StateProviderFactory};
use rollup_boost::{ExecutionPayloadBaseV1, ExecutionPayloadFlashblockDeltaV1};
use tokio::time::sleep;
// The amount of time to wait (in milliseconds) after sending a new flashblock or canonical block
// so it can be processed by the state processor
Expand Down
32 changes: 32 additions & 0 deletions crates/flashtypes/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "base-flashtypes"
description = "Flashblocks Primitive Types"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true

[lints]
workspace = true

[dependencies]
# alloy
alloy-serde.workspace = true
alloy-primitives.workspace = true
alloy-rpc-types-eth.workspace = true
alloy-rpc-types-engine.workspace = true

# reth
reth-optimism-primitives.workspace = true

# misc
bytes.workspace = true
serde.workspace = true
brotli.workspace = true
serde_json.workspace = true
derive_more.workspace = true

[dev-dependencies]
rstest.workspace = true
3 changes: 3 additions & 0 deletions crates/flashtypes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `base-flashtypes`

Low-level primitive types for `flashblocks`.
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
//! Contains the [`Flashblock`] and [`Metadata`] types used in Flashblocks.
//! Contains the [`Flashblock`] type used in Flashblocks.

use std::io::Read;

use alloy_primitives::{Address, B256, U256, map::foldhash::HashMap};
use alloy_rpc_types_engine::PayloadId;
use bytes::Bytes;
use derive_more::{Display, Error};
use reth_optimism_primitives::OpReceipt;
use rollup_boost::{
ExecutionPayloadBaseV1, ExecutionPayloadFlashblockDeltaV1, FlashblocksPayloadV1,
};
use serde::{Deserialize, Serialize};

/// Metadata associated with a flashblock.
#[derive(Debug, Deserialize, Serialize, Clone, Default)]
pub struct Metadata {
/// Transaction receipts indexed by hash.
pub receipts: HashMap<B256, OpReceipt>,
/// Updated account balances.
pub new_account_balances: HashMap<Address, U256>,
/// Block number this flashblock belongs to.
pub block_number: u64,
}
use crate::{
ExecutionPayloadBaseV1, ExecutionPayloadFlashblockDeltaV1, FlashblockDecodeError,
FlashblocksPayloadV1, Metadata,
};

/// A flashblock containing partial block data.
#[derive(Debug, Clone)]
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
pub struct Flashblock {
/// Unique payload identifier.
pub payload_id: PayloadId,
Expand Down Expand Up @@ -74,28 +62,11 @@ impl Flashblock {
}
}

/// Errors that can occur while decoding a flashblock payload.
#[derive(Debug, Display, Error)]
pub enum FlashblockDecodeError {
/// Failed to deserialize the flashblock payload JSON into the expected struct.
#[display("failed to parse flashblock payload JSON: {_0}")]
PayloadParse(serde_json::Error),
/// Failed to deserialize the flashblock metadata into the expected struct.
#[display("failed to parse flashblock metadata: {_0}")]
MetadataParse(serde_json::Error),
/// Brotli decompression failed.
#[display("failed to decompress brotli payload: {_0}")]
Decompress(std::io::Error),
/// The decompressed payload was not valid UTF-8 JSON.
#[display("decompressed payload is not valid UTF-8 JSON: {_0}")]
Utf8(std::string::FromUtf8Error),
}

#[cfg(test)]
mod tests {
use std::io::Write;

use alloy_primitives::{Address, Bloom, Bytes as PrimitiveBytes, U256};
use alloy_primitives::{Address, B256, Bloom, Bytes as PrimitiveBytes, U256};
use rstest::rstest;
use serde_json::json;

Expand Down
43 changes: 43 additions & 0 deletions crates/flashtypes/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//! Contains error types relating to primitive flashblock type functionality.

use derive_more::{Display, Error};

/// Errors that can occur while decoding a flashblock payload.
#[derive(Debug, Display, Error)]
pub enum FlashblockDecodeError {
/// Failed to deserialize the flashblock payload JSON into the expected struct.
#[display("failed to parse flashblock payload JSON: {_0}")]
PayloadParse(serde_json::Error),
/// Failed to deserialize the flashblock metadata into the expected struct.
#[display("failed to parse flashblock metadata: {_0}")]
MetadataParse(serde_json::Error),
/// Brotli decompression failed.
#[display("failed to decompress brotli payload: {_0}")]
Decompress(std::io::Error),
/// The decompressed payload was not valid UTF-8 JSON.
#[display("decompressed payload is not valid UTF-8 JSON: {_0}")]
Utf8(std::string::FromUtf8Error),
}

#[cfg(test)]
mod tests {
use rstest::rstest;
use serde::de::Error as _;

use super::*;

#[rstest]
#[case::payload_parse(FlashblockDecodeError::PayloadParse(serde_json::Error::custom("test")))]
#[case::metadata_parse(FlashblockDecodeError::MetadataParse(serde_json::Error::custom(
"test"
)))]
#[case::decompress(FlashblockDecodeError::Decompress(std::io::Error::new(
std::io::ErrorKind::Other,
"test"
)))]
#[case::utf8(FlashblockDecodeError::Utf8(String::from_utf8(vec![0xff, 0xfe]).unwrap_err()))]
fn test_flashblock_decode_error_display(#[case] error: FlashblockDecodeError) {
let display = format!("{}", error);
assert!(!display.is_empty());
}
}
18 changes: 18 additions & 0 deletions crates/flashtypes/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#![doc = include_str!("../README.md")]
#![doc(issue_tracker_base_url = "https://github.com/base/node-reth/issues/")]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]

mod block;
pub use block::Flashblock;

mod metadata;
pub use metadata::Metadata;

mod error;
pub use error::FlashblockDecodeError;

mod payload;
pub use payload::{
ExecutionPayloadBaseV1, ExecutionPayloadFlashblockDeltaV1, FlashblocksPayloadV1,
};
16 changes: 16 additions & 0 deletions crates/flashtypes/src/metadata.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//! Contains the [`Metadata`] type used in Flashblocks.

use alloy_primitives::{Address, B256, U256, map::foldhash::HashMap};
use reth_optimism_primitives::OpReceipt;
use serde::{Deserialize, Serialize};

/// Metadata associated with a flashblock.
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Default)]
pub struct Metadata {
/// Transaction receipts indexed by hash.
pub receipts: HashMap<B256, OpReceipt>,
/// Updated account balances.
pub new_account_balances: HashMap<Address, U256>,
/// Block number this flashblock belongs to.
pub block_number: u64,
}
Loading