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
27 changes: 25 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ version: 2.1
# act's local cache is not reusable across these machines; Pages plumbing is skipped after the
# validation build. Lint and unit jobs are distributed; other workflows run up to four jobs.
#
# Excluded: pr-title.yml, label-pr.yml, and the privileged cyclops-audit.yml integration.
# Excluded: pr-title.yml, label-pr.yml, the privileged cyclops-audit.yml integration, and
# scan-github-actions.yml, whose reusable workflow needs a GitHub OIDC token.

jobs:
# Replaces lint.yml's `deny` job. That job calls a reusable workflow from tempoxyz, whose deny job
Expand Down Expand Up @@ -123,6 +124,27 @@ jobs:
' - run: echo "Service plumbing disabled under act"' \
' shell: bash' \
> /tmp/noop-action/action.yml
- run:
name: Stub unsupported secure-runner
# Stub tempoxyz's secure-runner: it fetches its policy with a GitHub OIDC token that act
# never receives, and it hardens GitHub-hosted runners, not these machines. act maps whole
# repositories, and this one also serves vendored actions the checks need, so replace only
# secure-runner in a copy at the sha the workflows pin, reusing the no-op action from the
# step above. When re-applying this CI patch, move TEMPOXYZ_GH_ACTIONS_SHA with that pin;
# the guard below names any mismatch.
command: |
readonly TEMPOXYZ_GH_ACTIONS_SHA="ee2960a6cc25d99bda45614135bfe1197d879bac"
if grep -rhoE 'tempoxyz/gh-actions/[^@ ]+@[0-9a-f]{40}' .github/workflows/ \
| grep -v "@${TEMPOXYZ_GH_ACTIONS_SHA}\$"; then
echo "workflows pin tempoxyz/gh-actions at a sha other than ${TEMPOXYZ_GH_ACTIONS_SHA}" >&2
exit 1
fi
git init --quiet /tmp/tempoxyz-gh-actions
git -C /tmp/tempoxyz-gh-actions fetch --quiet --depth 1 \
https://github.com/tempoxyz/gh-actions "${TEMPOXYZ_GH_ACTIONS_SHA}"
git -C /tmp/tempoxyz-gh-actions checkout --quiet --detach FETCH_HEAD
cp /tmp/noop-action/action.yml /tmp/tempoxyz-gh-actions/actions/secure-runner/action.yml
echo "export TEMPOXYZ_GH_ACTIONS_SHA=${TEMPOXYZ_GH_ACTIONS_SHA}" >> "$BASH_ENV"
- run:
name: Run << parameters.wf >> via act
no_output_timeout: 45m
Expand Down Expand Up @@ -176,7 +198,8 @@ jobs:
--local-repository "mozilla-actions/sccache-action@fc920bf0ec8de6ee65d409111f7ec508035751ba=/tmp/noop-action" \
--local-repository "Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6=/tmp/noop-action" \
--local-repository "actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d=/tmp/noop-action" \
--local-repository "actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9=/tmp/noop-action"
--local-repository "actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9=/tmp/noop-action" \
--local-repository "tempoxyz/gh-actions@${TEMPOXYZ_GH_ACTIONS_SHA}=/tmp/tempoxyz-gh-actions"

workflows:
reth-act:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/book.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
run: |
cd docs/vocs/
bun i
npx playwright install --with-deps chromium
npx playwright@1.64.1 install --with-deps chromium

- name: Install Rust nightly
uses: dtolnay/rust-toolchain@02cb101ec7c40f2c49e1d9714d64511d8e1b74de # v1
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions crates/e2e-test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ reth-db-common.workspace = true
reth-primitives-traits.workspace = true
reth-trie.workspace = true
reth-trie-db.workspace = true
reth-transaction-pool.workspace = true

revm.workspace = true
tempfile.workspace = true
Expand Down Expand Up @@ -70,6 +71,9 @@ serde_json.workspace = true
tracing.workspace = true
derive_more.workspace = true

[dev-dependencies]
reth-prune-types.workspace = true

[[test]]
name = "e2e_testsuite"
path = "tests/e2e-testsuite/main.rs"
Expand Down
106 changes: 96 additions & 10 deletions crates/e2e-test-utils/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use reth_rpc_api::TestingBuildBlockRequestV1;
use reth_rpc_builder::auth::AuthServerHandle;
use reth_rpc_eth_api::helpers::{EthApiSpec, EthTransactions, TraceExt};
use reth_stages_types::StageId;
use reth_transaction_pool::TransactionPool;
use std::{pin::Pin, sync::Arc, time::Duration};
use tokio_stream::StreamExt;
use url::Url;
Expand Down Expand Up @@ -168,6 +169,30 @@ where
})
}

/// Sets the timestamp of the next payload built by [`Self::new_payload`] and the methods
/// built on it, such as [`Self::advance_block`].
///
/// Later payloads continue from this timestamp, one second apart. The attributes generator is
/// called with the new timestamp, so fork-dependent attributes follow it.
///
/// Returns an error if the timestamp is not greater than the timestamp of the current latest
/// block, which is the parent of the next payload.
pub fn set_next_payload_timestamp(&mut self, timestamp: u64) -> eyre::Result<()> {
let latest = self
.inner
.provider
.sealed_header_by_number_or_tag(BlockNumberOrTag::Latest)?
.ok_or_else(|| eyre!("latest block not found"))?;
ensure!(
timestamp > latest.timestamp(),
"next payload timestamp {timestamp} must be greater than the latest block timestamp {}",
latest.timestamp()
);
// The payload context increments its timestamp before generating the next attributes.
self.payload.timestamp = timestamp - 1;
Ok(())
}

/// Creates a new payload from given attributes generator
/// expects a payload attribute event and waits until the payload is built.
///
Expand Down Expand Up @@ -199,16 +224,24 @@ where
Ok(payload)
}

/// Advances the node forward one block
/// Advances the node forward one block by building a payload and importing it with
/// [`Self::import_payload`].
pub async fn advance_block(&mut self) -> eyre::Result<Payload::BuiltPayload> {
let payload = self.build_and_submit_payload().await?;
let payload = self.new_payload().await?;

// trigger forkchoice update via engine api to commit the block to the blockchain
self.update_forkchoice(payload.block().hash(), payload.block().hash()).await?;
self.import_payload(payload.clone()).await?;

Ok(payload)
}

/// Advances the node forward one block like [`Self::advance_block`] and waits until the
/// transaction pool processed the new block, see [`Self::wait_for_pool_head`].
pub async fn advance_block_synced(&mut self) -> eyre::Result<Payload::BuiltPayload> {
let payload = self.advance_block().await?;
self.wait_for_pool_head(payload.block().hash()).await?;
Ok(payload)
}

/// Waits for block to be available on node.
///
/// Returns an error if the block is not available within [`WAIT_TIMEOUT`].
Expand Down Expand Up @@ -271,6 +304,29 @@ where
.await
}

/// Waits until the transaction pool of the node processed the canonical state update that made
/// the block with the given hash its head.
///
/// The pool maintenance task processes new heads in the background, so right after e.g. a
/// forkchoice update the pool can still contain the transactions mined in the new block or use
/// outdated sender nonces and pending fees. The pool updates its last seen block together with
/// these, so they are up to date once this returns. Exceptions are reorgs, after which the
/// maintenance task re-injects the transactions of the old chain only afterwards, so wait for
/// them with [`Self::wait_for_pool`], and commits deeper than the maximum update depth of the
/// maintenance task, e.g. after a long sync, which only update the last seen block.
///
/// Returns an error if the pool does not process the block within [`WAIT_TIMEOUT`], e.g.
/// because the block is not the canonical head, the pool already processed a newer head, or
/// the block was synced by backfill, which does not notify the pool.
pub async fn wait_for_pool_head(&self, hash: B256) -> eyre::Result<()> {
let pool = &self.inner.pool;
poll_until(format!("transaction pool to process block {hash}"), move || {
let ready = pool.block_info().last_seen_block_hash == hash;
async move { Ok(ready.then_some(())) }
})
.await
}

/// Asserts that a new block has been added to the blockchain and the tx has been included in
/// the block, at any position.
///
Expand Down Expand Up @@ -344,10 +400,10 @@ where
.await
.map_err(|_| eyre!("timed out syncing to block {block}"))??;

// Hack to make sure that all components have time to process canonical state update.
// Otherwise, this might result in e.g "nonce too low" errors when advancing chain further,
// making tests flaky.
tokio::time::sleep(Duration::from_millis(1000)).await;
// The transaction pool processes the canonical state update in the background, and
// advancing the chain before it did can fail with e.g. "nonce too low" errors. Blocks
// synced by backfill don't notify the pool, so wait for at most a second.
let _ = tokio::time::timeout(Duration::from_secs(1), self.wait_for_pool_head(block)).await;

Ok(())
}
Expand Down Expand Up @@ -390,6 +446,30 @@ where
Ok(block_hash)
}

/// Submits a payload to the engine and makes its block the canonical head, returning the block
/// hash.
///
/// The forkchoice update marks the block as head, safe, and finalized block, like
/// [`Self::advance_block`] does, so the node can't reorg to a chain without the block
/// afterwards. The engine only reports the forkchoice update valid after making the head
/// canonical, so the block is the latest block of the node once this returns. The transaction
/// pool processes the new block in the background, see [`Self::wait_for_pool`].
///
/// The parent of the payload must be known to the node, e.g. to import a payload built by
/// another node into its peers. Returns an error if the engine does not report the forkchoice
/// update valid, e.g. because the payload is invalid.
pub async fn import_payload(&self, payload: Payload::BuiltPayload) -> eyre::Result<B256> {
let block_hash = self.submit_payload(payload).await?;
let updated = self.update_forkchoice(block_hash, block_hash).await?;
ensure!(
updated.is_valid(),
"forkchoice update to block {block_hash} is not valid: {}",
updated.payload_status.status
);

Ok(block_hash)
}

/// Returns the RPC URL.
pub fn rpc_url(&self) -> Url {
let addr = self.inner.rpc_server_handle().http_local_addr().unwrap();
Expand Down Expand Up @@ -522,20 +602,26 @@ where
mod tests {
use super::*;
use crate::NodeHelperType;
use reth_node_ethereum::EthereumNode;
use reth_node_ethereum::{EthEngineTypes, EthereumNode};

fn assert_send<T: Send>(_: T) {}

/// Tests of downstream nodes await these helpers in spawned tasks, so their futures must be
/// `Send`.
#[expect(dead_code)]
fn test_helper_futures_are_send(node: &mut NodeHelperType<EthereumNode>) {
fn test_helper_futures_are_send(
node: &mut NodeHelperType<EthereumNode>,
payload: <EthEngineTypes as PayloadTypes>::BuiltPayload,
) {
assert_send(node.advance_block());
assert_send(node.advance_block_synced());
assert_send(node.inject_and_advance(Bytes::new()));
assert_send(node.wait_block(0, B256::ZERO, false));
assert_send(node.wait_unwind(0));
assert_send(node.wait_for_pool(|_| true));
assert_send(node.wait_for_pool_head(B256::ZERO));
assert_send(node.assert_new_block(B256::ZERO, B256::ZERO, 0));
assert_send(node.sync_to(B256::ZERO));
assert_send(node.import_payload(payload));
}
}
7 changes: 7 additions & 0 deletions crates/e2e-test-utils/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ use tokio_stream::wrappers::BroadcastStream;
pub struct PayloadTestContext<T: PayloadTypes> {
pub payload_event_stream: BroadcastStream<Events<T>>,
payload_builder: PayloadBuilderHandle<T>,
/// Timestamp of the last generated payload attributes, or the starting point if none were
/// generated yet.
///
/// [`Self::next_attributes`] increments it before generating the next attributes. Prefer
/// [`NodeTestContext::set_next_payload_timestamp`] over setting it directly.
///
/// [`NodeTestContext::set_next_payload_timestamp`]: crate::node::NodeTestContext::set_next_payload_timestamp
pub timestamp: u64,
#[debug(skip)]
attributes_generator: Box<dyn Fn(u64) -> T::PayloadAttributes + Send + Sync>,
Expand Down
46 changes: 42 additions & 4 deletions crates/e2e-test-utils/tests/rocksdb/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use reth_chainspec::EthereumHardfork;
use reth_db::tables;
use reth_e2e_test_utils::{transaction::TransactionTestContext, wait::poll_until, E2ETestSetupExt};
use reth_node_ethereum::EthereumNode;
use reth_provider::RocksDBProviderFactory;
use reth_provider::{PruneCheckpointReader, RocksDBProviderFactory};
use reth_prune_types::PruneSegment;
use std::time::Duration;

/// Polls RPC until the given `tx_hash` is visible as pending (not yet mined).
Expand Down Expand Up @@ -40,6 +41,25 @@ async fn poll_tx_in_rocksdb<P: RocksDBProviderFactory>(provider: &P, tx_hash: B2
.await
}

/// Polls until the pruner has pruned `segment` up to at least `block`.
///
/// The persistence service acknowledges saved blocks before it runs the pruner in a separate
/// commit, so a block being visible in `RocksDB` does not mean the pruner has run for it yet.
async fn wait_for_prune_checkpoint<P: PruneCheckpointReader>(
provider: &P,
segment: PruneSegment,
block: u64,
) -> Result<()> {
poll_until(format!("{segment} to be pruned up to block {block}"), || async move {
let checkpoint = provider.get_prune_checkpoint(segment)?;
Ok(checkpoint
.and_then(|checkpoint| checkpoint.block_number)
.is_some_and(|n| n >= block)
.then_some(()))
})
.await
}

/// Smoke test: node boots with `RocksDB` routing enabled.
#[tokio::test]
async fn test_rocksdb_node_startup() -> Result<()> {
Expand Down Expand Up @@ -665,12 +685,21 @@ async fn test_rocksdb_account_history_pruning() -> Result<()> {
let payload = node.advance_block().await?;
assert_eq!(payload.block().number(), nonce + 1);

// Let the persistence cycle (save_blocks → pruner → commit) complete before
// producing the next block, so each cycle processes exactly one block. The
// transaction becomes visible in RocksDB with the commit.
// Wait for the block's save to commit before producing the next block, so each save
// processes exactly one block. The transaction becomes visible in RocksDB with the
// commit, and the persistence service runs the pruner before it handles the next save.
poll_tx_in_rocksdb(&node.inner.provider, tx_hash).await?;
}

// The pruner runs after the save of the last block is acknowledged, so wait for it to prune
// the blocks outside the retention window.
wait_for_prune_checkpoint(
&node.inner.provider,
PruneSegment::AccountHistory,
TOTAL_BLOCKS - PRUNE_DISTANCE,
)
.await?;

// Read the AccountsHistory shard for `sender` directly from RocksDB.
// This is the data structure corrupted by the race.
let rocksdb = node.inner.provider.rocksdb_provider();
Expand Down Expand Up @@ -843,6 +872,15 @@ async fn test_rocksdb_storage_history_pruning() -> Result<()> {
poll_tx_in_rocksdb(&node.inner.provider, tx_hash).await?;
}

// The pruner runs after the save of the last block is acknowledged, so wait for it to prune
// the blocks outside the retention window.
wait_for_prune_checkpoint(
&node.inner.provider,
PruneSegment::StorageHistory,
TOTAL_BLOCKS - PRUNE_DISTANCE,
)
.await?;

// Read StoragesHistory shard for (contract_address, slot 0) directly from RocksDB
let rocksdb = node.inner.provider.rocksdb_provider();
let shards = rocksdb.storage_history_shards(contract_address, storage_slot).unwrap();
Expand Down
Loading