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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Options:
--use-ots Whether to query Otterscan's `ots` namespace
--use-tempo Whether to query Tempo's `tempo` namespace
--minimal Whether either node runs with `--minimal` pruning
--skip-historical-state Skip transaction replays at the parent block (`eth_call`, `eth_estimateGas`, simulations and traced calls) and contract code and storage reads at the tested block
--ws1 <WS_URL1> WS URL of rpc1's node. Enables the `eth_subscribe` checks, which need `--ws2` too
--ws2 <WS_URL2> WS URL of rpc2's node
--ws-timeout <WS_TIMEOUT> Maximum time to wait for the next subscription message in seconds [default: 60]
Expand Down
9 changes: 9 additions & 0 deletions crates/rpc-tester-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ pub struct CliArgs {
#[arg(long)]
pub minimal: bool,

/// Skip transaction replays at the parent block (`eth_call`, `eth_estimateGas`, simulations
/// and traced calls) and contract code and storage reads at the tested block.
///
/// For a node whose history index may not cover accounts unchanged since before its earliest
/// changeset, such as one restored from a snapshot without its indices.
#[arg(long)]
pub skip_historical_state: bool,

/// WS URL of rpc1's node. Enables the `eth_subscribe` checks, which need `--ws2` too.
///
/// Heads, logs and receipts are collected for `--num-blocks` new blocks on both nodes and
Expand Down Expand Up @@ -152,6 +160,7 @@ async fn main() -> eyre::Result<()> {
.with_tempo(args.use_tempo)
.with_history_floor(history_floor)
.with_minimal(args.minimal)
.skip_historical_state(args.skip_historical_state)
.with_rate_limit(args.rate_limit)
.build();

Expand Down
25 changes: 21 additions & 4 deletions crates/rpc-tester/src/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ pub struct RpcTester<P: Provider<AnyNetwork>> {
/// and keeps receipts for only the newest 64 blocks, so lookups by hash and anything read from
/// receipts are skipped.
minimal: bool,
/// Whether to skip replaying transactions at their parent block and reading contract code and
/// storage at the tested block, which read account state at a past block.
skip_historical_state: bool,
/// Maximum requests per second for rate limiting.
rate_limit_rps: Option<u32>,
/// Last timestamp for rate limiting.
Expand Down Expand Up @@ -248,9 +251,12 @@ where
rpc_raw!(self, trace_call, JsonValue, parity_call_args),
rpc_raw!(self, tempo_simulateV1, JsonValue, tempo_simulate_args),
];
tests.extend(exec_calls);
// Replays and state reads at a past block are skipped with --skip-historical-state.
if !self.skip_historical_state {
tests.extend(exec_calls);
}

if self.use_tempo {
if self.use_tempo && !self.skip_historical_state {
// Replays with the transaction's own fees, fee token and authorizations, which
// the fee-free replays drop. Calls, estimates and traced calls still resolve
// and validate the fee token but skip fee collection, so only the simulation
Comment on lines +254 to 262

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Operators using --skip-historical-state still get mismatches, because block and transaction re-execution traces read the same parent-block state and stay enabled. Only the call replays and the contract eth_getCode/eth_getStorageAt are gated. trace_block, debug_trace_block_by_* with prestate_tracer_opts() and trace_replay_block_transactions (tester.rs:175-180) are not. debug_trace_transaction, trace_replayTransaction and ots_* (tester.rs:401-415) are not either. Fix: gate every check that runs the EVM on, or reads accounts from, a past block, or narrow the flag's doc and README to what it skips. [also at: crates/rpc-tester/src/tester.rs:389 - Tempo operators using --skip-historical-state still get past-block reads of untouched accounts, so the target node keeps reporting mismatches.]

Why this was flagged

The trigger is a node restored from a snapshot without its history indices, which the flag's doc at main.rs:77-82 names as its target, run with --skip-historical-state. The per-block list at tester.rs:151-181 always includes trace_block, trace_replay_block_transactions with StateDiff, and debug_trace_block_by_number with prestate_tracer_opts(). It also always includes eth_getBalance at the tested block hash. The per-tx tx_hash_calls at tester.rs:396-416 replay each transaction on its parent state, including the prestate and diff tracers. These replays load the same old, unchanged contracts that the skipped eth_call/trace_call at the parent block would load. So the history-index divergence still shows up in these traces, and the comparison still reports failures. The flag claims to skip 'anything that reads account state at a past block', but nothing in the diff guards these calls. Base behaviour is unchanged, but the flag does not give the clean run it is meant to provide.

Verification: Severity: normal. On a node restored from a snapshot without its indices, --skip-historical-state does not keep the comparison clean, because re-execution traces still read parent-block state. The per-block list at tester.rs:151-181 is extended with no condition (tests.extend(block_calls); at 183). tx_hash_calls at 396-416 is gated only on !self.minimal (394).

Expand Down Expand Up @@ -279,7 +285,7 @@ where
tests.extend(fee_calls);
}

if !self.skip_extended_eth {
if !self.skip_extended_eth && !self.skip_historical_state {
// Simulation builds a block around the call, with receipts, logs and
// synthetic transfer logs that `eth_call` does not return.
let simulate_args = (
Expand Down Expand Up @@ -312,7 +318,7 @@ where
.and_then(JsonValue::as_str)
.and_then(|to| to.parse().ok()),
};
if let Some(address) = state_address {
if let Some(address) = state_address.filter(|_| !self.skip_historical_state) {
#[rustfmt::skip]
let state_calls = vec![
rpc_with_block!(self, get_code_at, address; block_id),
Expand Down Expand Up @@ -1096,6 +1102,8 @@ pub struct RpcTesterBuilder<P: Provider<AnyNetwork>> {
history_floor: BlockNumber,
/// Whether either node runs with `--minimal` pruning.
minimal: bool,
/// Whether to skip calls that read account state at a past block.
skip_historical_state: bool,
/// Maximum requests per second for rate limiting.
rate_limit_rps: Option<u32>,
}
Expand All @@ -1116,6 +1124,7 @@ impl<P: Provider<AnyNetwork>> RpcTesterBuilder<P> {
use_tempo: false,
history_floor: 0,
minimal: false,
skip_historical_state: false,
rate_limit_rps: None,
}
}
Expand Down Expand Up @@ -1188,6 +1197,13 @@ impl<P: Provider<AnyNetwork>> RpcTesterBuilder<P> {
self
}

/// Enables or disables skipping transaction replays at the parent block and contract code and
/// storage reads at the tested block.
pub const fn skip_historical_state(mut self, skip: bool) -> Self {
self.skip_historical_state = skip;
self
}

/// Sets the rate limit in requests per second.
/// If None, no rate limiting is applied.
pub const fn with_rate_limit(mut self, rps: Option<u32>) -> Self {
Expand All @@ -1210,6 +1226,7 @@ impl<P: Provider<AnyNetwork>> RpcTesterBuilder<P> {
use_tempo: self.use_tempo,
history_floor: self.history_floor,
minimal: self.minimal,
skip_historical_state: self.skip_historical_state,
rate_limit_rps: self.rate_limit_rps,
last_request_time: tokio::sync::Mutex::new(std::time::Instant::now()),
}
Expand Down
Loading