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
13 changes: 12 additions & 1 deletion rust/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ rust-review base='':

############################ no_std #################################

# Check no_std compatibility for proof, protocol, alloy, and op-alloy crates
# Check no_std compatibility for proof, protocol, alloy, and op-alloy crates, plus the host-target
# no_std build of op-reth's evm crate, whose reth dependencies do not build for riscv.
check-no-std:
#!/usr/bin/env bash
set -euo pipefail
Expand Down Expand Up @@ -454,6 +455,16 @@ check-no-std:
echo "Successfully checked no_std build for: $package"
done

host_no_std_packages=(
reth-optimism-evm
)

for package in "${host_no_std_packages[@]}"; do
echo "Checking host-target no_std build for: $package"
cargo check -p "$package" --no-default-features
echo "Successfully checked host-target no_std build for: $package"
done

########################### Benchmarks ##############################

# Run benchmarks (compile only)
Expand Down
19 changes: 16 additions & 3 deletions rust/op-reth/crates/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ use alloy_op_evm::{
block::{OpTxEnv, receipt_builder::OpReceiptBuilder},
evm_env_for_op_block, evm_env_for_op_next_block,
};
use alloy_primitives::B256;
use core::fmt::Debug;
use op_alloy_consensus::{
EIP1559ParamError, OpTransaction as OpConsensusTransaction,
parse_post_exec_payload_from_transactions,
EIP1559ParamError, OpTransaction as OpConsensusTransaction, PostExecPayloadValidationError,
parse_post_exec_payload_from_transactions, validate_post_exec_entry_count,
};
use op_revm::OpSpecId;
use reth_chainspec::EthChainSpec;
Expand All @@ -45,7 +46,6 @@ use {
#[cfg(feature = "std")]
use {
alloy_op_evm::evm_env_for_op_payload,
op_alloy_consensus::{PostExecPayloadValidationError, validate_post_exec_entry_count},
reth_evm::{ConfigureEngineEvm, ExecutableTxIterator},
};

Expand Down Expand Up @@ -80,6 +80,7 @@ mod post_exec_ext;
pub use post_exec_ext::*;

mod sdm_metrics;
pub use sdm_metrics::report_post_exec_validation_failure;

/// Optimism-related EVM configuration.
#[derive(Debug)]
Expand Down Expand Up @@ -189,6 +190,18 @@ pub(crate) fn preflight_post_exec_payload(
})
}

/// Runs the encoded-transaction preflight for payload-builder attributes
/// (`forkchoiceUpdated` with transactions); a rejection is logged against the parent block hash
/// and counted under the failed rule and as a failed validation.
pub fn validate_post_exec_attributes(
Comment thread
einar-oplabs marked this conversation as resolved.
Resolved
transactions: &[Bytes],
parent_hash: B256,
) -> Result<(), PostExecPayloadValidationError> {
validate_post_exec_entry_count(transactions).inspect_err(|error| {
sdm_metrics::report_post_exec_attributes_rejection(parent_hash, *error);
})
}

impl<ChainSpec, N, R, EvmFactory> OpEvmConfig<ChainSpec, N, R, EvmFactory>
where
ChainSpec: OpHardforks,
Expand Down
74 changes: 59 additions & 15 deletions rust/op-reth/crates/evm/src/sdm_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
//! dashboard can show SDM validation activity rather than inferring it from generic block
//! validation.
//!
//! Recorded from the execution-context builders and the Engine API payload preflight. Beyond
//! Recorded from the execution-context builders, the Engine API payload preflight, and the
//! payload-builder attributes preflight. Attributes count once per conversion into builder
//! attributes, so a rejection repeats only when a builder reconverts the same attributes, and a
//! replay of attributes through the debug RPC namespace counts like an engine delivery. Beyond
//! live import, several paths re-execute stored canonical blocks that already passed this check:
//! RPC replays, the proofs ExEx's periodic re-execution, and pipeline or backfill sync.
//! Re-execution cannot inflate the failure counters, but every pass recounts `ok` — on a
Expand Down Expand Up @@ -88,9 +91,9 @@ pub(crate) fn report_post_exec_validation_ok() {
result_counter(RESULT_OK).increment(1);
}

/// Logs a block rejected for its post-exec transaction and, with `std`, counts it under the
/// failed rule and as a failed validation.
pub(crate) fn report_post_exec_validation_failure(
/// Logs a block rejected for its post-exec transaction, whether imported or being built, and
/// with `std` counts it under the failed rule and as a failed validation.
pub fn report_post_exec_validation_failure(
block_number: u64,
error: PostExecPayloadValidationError,
) {
Expand All @@ -101,11 +104,34 @@ pub(crate) fn report_post_exec_validation_failure(
%error,
"block rejected: post-exec transaction failed structural validation"
);
count_post_exec_failure(reason);
}

/// Counts one failed validation under its rule; a no-op without `std`.
fn count_post_exec_failure(reason: &'static str) {
#[cfg(feature = "std")]
{
failure_counter(reason).increment(1);
result_counter(RESULT_FAIL).increment(1);
}
#[cfg(not(feature = "std"))]
let _ = reason;
}

/// Logs payload-builder attributes rejected for their post-exec transaction and counts the
/// rejection like [`report_post_exec_validation_failure`], attributed to the parent block hash.
pub(crate) fn report_post_exec_attributes_rejection(
Comment thread
einar-oplabs marked this conversation as resolved.
Resolved
parent_hash: alloy_primitives::B256,
error: PostExecPayloadValidationError,
) {
let reason = error.as_reason();
tracing::warn!(
%parent_hash,
reason,
%error,
"payload attributes rejected: post-exec transaction failed structural validation"
);
count_post_exec_failure(reason);
}

#[cfg(all(test, feature = "std"))]
Expand Down Expand Up @@ -244,13 +270,29 @@ mod tests {
assert_results(&exposition, /* ok */ 0.0, /* fail */ 1.0);
}

/// Drives the Engine API preflight helper with raw encoded transactions against a recorder
/// private to the test, returning the result alongside the rendered exposition.
fn preflight(transactions: Vec<alloy_primitives::Bytes>) -> (Result<(), ()>, String) {
/// The two encoded-transaction preflights, which share one set of counters.
#[derive(Clone, Copy, Debug)]
enum Preflight {
EngineApi,
Attributes,
}

/// Drives one preflight with raw encoded transactions against a recorder private to the
/// test, returning the result alongside the rendered exposition.
fn preflight(
entry: Preflight,
transactions: Vec<alloy_primitives::Bytes>,
) -> (Result<(), ()>, String) {
let (recorder, handle) = recorder();
let result = with_local_recorder(&recorder, || {
super::register_sdm_metrics_at_zero();
crate::preflight_post_exec_payload(&transactions, BLOCK)
match entry {
Preflight::EngineApi => crate::preflight_post_exec_payload(&transactions, BLOCK),
Preflight::Attributes => crate::validate_post_exec_attributes(
&transactions,
alloy_primitives::B256::ZERO,
),
}
});
(result.map_err(drop), handle.render())
}
Expand Down Expand Up @@ -287,13 +329,14 @@ mod tests {
#[case::too_many_entries(vec![filler(), encoded_post_exec(2)], "too_many_gas_refund_entries")]
#[case::malformed(vec![bare_post_exec()], "malformed_post_exec_payload")]
#[case::unsupported_version(vec![filler(), versioned_post_exec(2)], "unsupported_post_exec_payload_version")]
fn rejected_payload_counts_on_the_engine_api_path(
fn rejected_transactions_count_at_every_preflight(
#[values(Preflight::EngineApi, Preflight::Attributes)] entry: Preflight,
#[case] transactions: Vec<alloy_primitives::Bytes>,
#[case] reason: &str,
) {
let (result, exposition) = preflight(transactions);
let (result, exposition) = preflight(entry, transactions);

assert!(result.is_err(), "preflight rejects");
assert!(result.is_err(), "{entry:?} preflight rejects");
assert_failures(&exposition, Some(reason));
assert_results(&exposition, /* ok */ 0.0, /* fail */ 1.0);
}
Expand Down Expand Up @@ -323,17 +366,18 @@ mod tests {
assert_results(&exposition, /* ok */ 0.0, /* fail */ 1.0);
}

/// The preflight does not count `ok`: a pass is not yet a validated post-exec transaction —
/// A preflight does not count `ok`: a pass is not yet a validated post-exec transaction —
/// the parse on the decoded transactions counts that.
#[rstest]
#[case::with_post_exec(vec![filler(), encoded_post_exec(1)])]
#[case::without_post_exec(vec![filler()])]
fn accepted_payload_counts_nothing_at_preflight(
fn accepted_transactions_count_nothing_at_any_preflight(
#[values(Preflight::EngineApi, Preflight::Attributes)] entry: Preflight,
#[case] transactions: Vec<alloy_primitives::Bytes>,
) {
let (result, exposition) = preflight(transactions);
let (result, exposition) = preflight(entry, transactions);

assert!(result.is_ok(), "preflight passes");
assert!(result.is_ok(), "{entry:?} preflight passes");
assert_failures(&exposition, None);
assert_results(&exposition, /* ok */ 0.0, /* fail */ 0.0);
}
Expand Down
2 changes: 1 addition & 1 deletion rust/op-reth/crates/flashblocks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ workspace = true
[dependencies]
# reth
reth-optimism-primitives = { workspace = true, features = ["serde"] }
reth-optimism-evm.workspace = true
reth-optimism-evm = { workspace = true, features = ["std"] }
reth-chain-state = { workspace = true, features = ["serde"] }
reth-primitives-traits = { workspace = true, features = ["serde"] }
reth-engine-primitives = { workspace = true, features = ["std"] }
Expand Down
2 changes: 1 addition & 1 deletion rust/op-reth/crates/payload/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ reth-payload-validator.workspace = true
reth-metrics.workspace = true

# op-reth
reth-optimism-evm.workspace = true
reth-optimism-evm = { workspace = true, features = ["std"] }
Comment thread
einar-oplabs marked this conversation as resolved.
Resolved
reth-optimism-forks.workspace = true
reth-optimism-primitives = { workspace = true, features = ["reth-codec"] }
reth-optimism-txpool.workspace = true
Expand Down
8 changes: 7 additions & 1 deletion rust/op-reth/crates/payload/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@ where

/// Converts `BuildArguments` from [`OpPayloadAttrs`](crate::payload::OpPayloadAttrs) to
/// [`OpPayloadBuilderAttributes`], decoding the RPC transaction bytes into typed transactions.
///
/// Counts a rejected post-exec transaction once per call, so a job that converts the same
/// attributes more than once counts each conversion.
fn convert_build_args<N: OpPayloadPrimitives>(
args: BuildArguments<crate::payload::OpPayloadAttrs, OpBuiltPayload<N>>,
) -> Result<
Expand Down Expand Up @@ -908,7 +911,7 @@ where
///
/// Returns `Ok(None)` when no such tx is present; errors if the embedded payload is
/// structurally invalid (present before SDM activation, duplicated, not last, or anchored
/// to the wrong block number).
/// to the wrong block number), logging and counting the rejection under its failed rule.
fn parse_embedded_post_exec(
&self,
) -> Result<Option<ParsedPostExecPayload>, PayloadBuilderError> {
Expand All @@ -922,6 +925,9 @@ where
next_block_number,
sdm_active,
)
.inspect_err(|error| {
reth_optimism_evm::report_post_exec_validation_failure(next_block_number, *error);
})
.map_err(PayloadBuilderError::other)
}

Expand Down
64 changes: 64 additions & 0 deletions rust/op-reth/crates/payload/src/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,70 @@ fn execute_best_transactions_excludes_interop_txs_when_failsafe_active() {
assert_eq!(build(&failsafe), vec![normal_hash, interop_hash]);
}

/// Builds a ctx rebuilding a derived block whose embedded `0x7D` tx anchors to
/// `post_exec_anchor`. The parent is block 0, so block 1 is the only valid anchor, and Lagoon is
/// either active from genesis or not at all.
fn derived_ctx(
lagoon_active: bool,
post_exec_anchor: u64,
) -> OpPayloadBuilderCtx<
OpEvmConfig<OpChainSpec, OpPrimitives>,
OpChainSpec,
OpPayloadBuilderAttributes<OpTransactionSigned>,
> {
let spec = OpChainSpecBuilder::optimism_mainnet();
let spec = if lagoon_active { spec.lagoon_activated() } else { spec };
let chain_spec = Arc::new(spec.build());
let parent = SealedHeader::seal_slow(Header { number: 0, timestamp: 0, ..Default::default() });
let attributes = OpPayloadBuilderAttributes {
no_tx_pool: true,
timestamp: 1,
transactions: vec![
deposit_with_encoded(),
post_exec_with_encoded(post_exec_anchor, entries(&[(0, 1)])),
],
..Default::default()
};

OpPayloadBuilderCtx {
evm_config: OpEvmConfig::optimism(chain_spec.clone()),
builder_config: OpBuilderConfig::default(),
chain_spec,
config: PayloadConfig {
parent_header: Arc::new(parent),
parent_block_info: None,
payload_id: attributes.id,
attributes,
},
cancel: Default::default(),
best_payload: None,
}
}

/// The rules the encoded-transaction preflight cannot check — activation and the anchor — are
/// applied when the builder parses the decoded attributes, and a rejection there reaches the
/// same counters.
#[rstest]
#[case::wrong_anchor(/* lagoon_active */ true, /* post_exec_anchor */ 2, "block_number_mismatch")]
#[case::before_activation(/* lagoon_active */ false, /* post_exec_anchor */ 1, "unexpected_post_exec_tx")]
fn rejected_embedded_post_exec_counts_under_the_failed_rule(
#[case] lagoon_active: bool,
#[case] post_exec_anchor: u64,
#[case] reason: &str,
) {
use crate::sdm_metrics::test_support::{FAILURES, RESULTS, recorder, series};

let (recorder, handle) = recorder();
let result = with_local_recorder(&recorder, || {
derived_ctx(lagoon_active, post_exec_anchor).post_exec_mode()
});
let exposition = handle.render();

assert!(result.is_err(), "the embedded post-exec tx is rejected");
assert_eq!(series(&exposition, FAILURES, "reason", reason), Some(1.0), "{exposition}");
assert_eq!(series(&exposition, RESULTS, "result", "fail"), Some(1.0), "{exposition}");
}

#[derive(Debug, thiserror::Error)]
#[error("unrelated executor failure")]
struct UnrelatedExecutionError;
Expand Down
Loading
Loading