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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jemalloc = ["rblib/jemalloc"]
debug = ["tokio/full", "tokio/tracing", "dep:console-subscriber"]

[dependencies]
rblib = { git = "https://github.com/flashbots/rblib", rev = "5dea87ce8e9ea61692d5d3e05545b62d01671e1e" }
rblib = { git = "https://github.com/flashbots/rblib", rev = "c9625fa451b13452cce68ce86580745a6fba8d76" }

futures = "0.3"
tokio = "1.46"
Expand Down Expand Up @@ -74,7 +74,7 @@ reth-provider = { git = "https://github.com/paradigmxyz/reth", tag = "v1.8.2" }
console-subscriber = { version = "0.4", optional = true }

[dev-dependencies]
rblib = { git = "https://github.com/flashbots/rblib", rev = "5dea87ce8e9ea61692d5d3e05545b62d01671e1e", features = [
rblib = { git = "https://github.com/flashbots/rblib", rev = "c9625fa451b13452cce68ce86580745a6fba8d76", features = [
"test-utils",
] }

Expand Down
8 changes: 4 additions & 4 deletions src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,16 @@ impl Bundle<Flashblocks> for FlashblocksBundle {
/// hash reverts. Otherwise, returns false and it signals that this
/// transaction must have a successful (non-revert and non-fail) for the
/// bundle to be eligible for inclusion in a block.
fn is_allowed_to_fail(&self, tx: TxHash) -> bool {
self.reverting_tx_hashes.contains(&tx)
fn is_allowed_to_fail(&self, tx: &TxHash) -> bool {
self.reverting_tx_hashes.contains(tx)
}

/// Returns true if the bundle will be valid if a transaction with the given
/// hash is removed from this bundle. Otherwise, returns false and it signals
/// that this transaction might not be removed from the bundle e.g. during
/// revert protection.
fn is_optional(&self, tx: TxHash) -> bool {
self.dropping_tx_hashes.contains(&tx)
fn is_optional(&self, tx: &TxHash) -> bool {
self.dropping_tx_hashes.contains(tx)
}

fn hash(&self) -> B256 {
Expand Down
9 changes: 4 additions & 5 deletions src/platform.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use {
crate::bundle::FlashblocksBundle,
rblib::prelude::*,
rblib::{prelude::*, reth::providers::StateProvider},
serde::{Deserialize, Serialize},
std::sync::Arc,
};
Expand Down Expand Up @@ -44,15 +44,14 @@ impl Platform for Flashblocks {
)
}

fn build_payload<P, Provider>(
fn build_payload<P>(
payload: Checkpoint<P>,
provider: &Provider,
provider: &dyn StateProvider,
) -> Result<types::BuiltPayload<P>, PayloadBuilderError>
where
P: traits::PlatformExecBounds<Self>,
Provider: traits::ProviderBounds<Self>,
{
Optimism::build_payload::<P, Provider>(payload, provider)
Optimism::build_payload::<P>(payload, provider)
}
}

Expand Down
73 changes: 20 additions & 53 deletions src/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ use {
futures::{SinkExt, StreamExt},
parking_lot::RwLock,
rblib::{
alloy::{
consensus::BlockHeader,
eips::Encodable2718,
primitives::{B256, Bloom, U256},
},
alloy::{consensus::BlockHeader, eips::Encodable2718, primitives::U256},
prelude::*,
},
reth_node_builder::PayloadBuilderAttributes,
Expand Down Expand Up @@ -72,16 +68,14 @@ pub struct PublishFlashblock {
/// information is used to produce some of the metrics.
times: Times,

/// Should we calculate the state root for each flashblock
pub calculate_state_root: bool,

max_flashblocks: Arc<AtomicU64>,
}

impl PublishFlashblock {
pub fn new(
sink: &Arc<WebSocketSink>,
calculate_state_root: bool,
// TODO: Will be implemented later
_calculate_state_root: bool,
max_flashblocks: Arc<AtomicU64>,
) -> Self {
Self {
Expand All @@ -90,7 +84,6 @@ impl PublishFlashblock {
block_base: RwLock::new(None),
metrics: Metrics::default(),
times: Times::default(),
calculate_state_root,
max_flashblocks,
}
}
Expand Down Expand Up @@ -121,16 +114,27 @@ impl Step<Flashblocks> for PublishFlashblock {
// increment flashblock number
let index = self.flashblock_number.fetch_add(1, Ordering::SeqCst);

let base = self.block_base.read().clone();
let sealed_block = payload.build_payload();
if let Err(e) = sealed_block {
tracing::error!("Failed to build sealed block: {:?}", e);
return ControlFlow::Break(payload);
}
let sealed_block = sealed_block.expect("sealed block is ok");
// TODO: .take() is a bit strange here, we will move out base flashblocks
// into it's own step
let base = self.block_base.write().take();
let diff = ExecutionPayloadFlashblockDeltaV1 {
state_root: self.compute_state_root(&payload, &ctx),
receipts_root: B256::ZERO, // TODO: compute receipts root
logs_bloom: Bloom::default(), // TODO
state_root: sealed_block.block().state_root,
receipts_root: sealed_block.block().receipts_root,
logs_bloom: sealed_block.block().logs_bloom,
gas_used: payload.cumulative_gas_used(),
block_hash: B256::ZERO, // TODO: compute block hash
block_hash: sealed_block.block().hash(),
transactions,
withdrawals: vec![],
withdrawals_root: B256::ZERO, // TODO: compute withdrawals root
withdrawals_root: sealed_block
.block()
.withdrawals_root()
.expect("withdrawals_root is present"),
};

// Push the contents of the payload
Expand Down Expand Up @@ -242,37 +246,6 @@ impl PublishFlashblock {
}
}

fn compute_state_root(
&self,
payload: &Checkpoint<Flashblocks>,
ctx: &StepContext<Flashblocks>,
) -> B256 {
if !self.calculate_state_root {
return B256::ZERO;
}

let state_root_start_time = Instant::now();

let state_provider = ctx.block().base_state();
let hashed_state =
state_provider.hashed_post_state(payload.state().unwrap());
let (state_root, _trie_output) = state_provider
.state_root_with_updates(hashed_state)
.unwrap();

let state_root_calculation_time = state_root_start_time.elapsed();
self
.metrics
.state_root_calculation_duration
.record(state_root_calculation_time);
self
.metrics
.state_root_calculation_gauge
.set(state_root_calculation_time);

state_root
}

/// Called for each flashblock to capture metrics about the produced
/// flashblock contents.
fn capture_payload_metrics(&self, span: &Span<Flashblocks>) {
Expand Down Expand Up @@ -336,12 +309,6 @@ struct Metrics {

/// The number of failures on the websocket transport layer.
pub websocket_publish_errors_total: Counter,

/// Histogram of state root calculation duration
pub state_root_calculation_duration: Histogram,

/// Latest state root calculation duration
pub state_root_calculation_gauge: Gauge,
}

/// Used to track timing information for metrics.
Expand Down
Loading