Skip to content

Commit def269d

Browse files
committed
tests: add load tests to the cache ingestion and simulation loop
1 parent 0788c93 commit def269d

7 files changed

Lines changed: 321 additions & 34 deletions

File tree

Cargo.lock

Lines changed: 28 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ url = "2.5.4"
6161
[dev-dependencies]
6262
alloy-hardforks = "0.4.0"
6363
alloy-chains = "0.2"
64+
signet-bundle = "0.16.0-rc.11"
6465

6566
# comment / uncomment for local dev
6667
# [patch.crates-io]

src/tasks/cache/task.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ impl CacheTask {
5151
basefee = sim_env.basefee;
5252
info!(
5353
basefee,
54-
block_env_number = sim_env.number.to::<u64>(), block_env_timestamp = sim_env.timestamp.to::<u64>(),
54+
block_env_number = sim_env.number.to::<u64>(),
55+
block_env_timestamp = sim_env.timestamp.to::<u64>(),
5556
"rollup block env changed, clearing cache"
5657
);
5758
cache.clean(

src/test_utils/block.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! for testing block simulation.
44
55
use super::{
6-
db::TestDb,
6+
db::{TestDb, TestStateSource},
77
env::{TestHostEnv, TestRollupEnv, TestSimEnvBuilder},
88
};
99
use signet_sim::{BlockBuild, BuiltBlock, SimCache};
@@ -12,7 +12,8 @@ use tokio::time::Instant;
1212
use trevm::revm::inspector::NoOpInspector;
1313

1414
/// Test block builder type using in-memory databases.
15-
pub type TestBlockBuild = BlockBuild<TestDb, TestDb, NoOpInspector, NoOpInspector>;
15+
pub type TestBlockBuild =
16+
BlockBuild<TestDb, TestDb, TestStateSource, TestStateSource, NoOpInspector, NoOpInspector>;
1617

1718
/// Builder for creating test `BlockBuild` instances.
1819
/// Configures all the parameters needed for block simulation
@@ -110,12 +111,13 @@ impl TestBlockBuildBuilder {
110111
/// This creates a `BlockBuild` ready for simulation.
111112
/// Call `.build().await` on the result to execute the simulation and get a `BuiltBlock`.
112113
pub fn build(self) -> TestBlockBuild {
114+
let builder = self.sim_env_builder.unwrap_or_default();
115+
let ru_state_source = TestStateSource::new(builder.rollup_db());
116+
let host_state_source = TestStateSource::new(builder.host_db());
117+
113118
let (rollup_env, host_env) = match (self.rollup_env, self.host_env) {
114119
(Some(rollup), Some(host)) => (rollup, host),
115-
_ => {
116-
let builder = self.sim_env_builder.unwrap_or_default();
117-
builder.build()
118-
}
120+
_ => builder.build(),
119121
};
120122

121123
let finish_by = Instant::now() + self.deadline_duration;
@@ -128,6 +130,8 @@ impl TestBlockBuildBuilder {
128130
self.sim_cache,
129131
self.max_gas,
130132
self.max_host_gas,
133+
ru_state_source,
134+
host_state_source,
131135
)
132136
}
133137
}

src/test_utils/db.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
//! for testing block simulation without requiring network access.
44
55
use alloy::primitives::{Address, B256, U256};
6+
use signet_sim::{AcctInfo, StateSource};
67
use trevm::revm::{
78
database::{CacheDB, EmptyDB},
9+
database_interface::DatabaseRef,
810
state::AccountInfo,
911
};
1012

@@ -14,6 +16,36 @@ use trevm::revm::{
1416
/// with `RollupEnv` and `HostEnv` for offline simulation testing.
1517
pub type TestDb = CacheDB<EmptyDB>;
1618

19+
/// A [`StateSource`] for testing backed by an in-memory [`TestDb`].
20+
/// Returns actual account info (nonce, balance) from the database,
21+
/// which is required for preflight validity checks during simulation.
22+
#[derive(Debug, Clone)]
23+
pub struct TestStateSource {
24+
db: TestDb,
25+
}
26+
27+
impl TestStateSource {
28+
/// Create a new `TestStateSource` backed by the given database.
29+
pub const fn new(db: TestDb) -> Self {
30+
Self { db }
31+
}
32+
}
33+
34+
impl StateSource for TestStateSource {
35+
type Error = std::convert::Infallible;
36+
37+
async fn account_details(&self, address: &Address) -> Result<AcctInfo, Self::Error> {
38+
match self.db.basic_ref(*address) {
39+
Ok(Some(info)) => Ok(AcctInfo {
40+
nonce: info.nonce,
41+
balance: info.balance,
42+
has_code: info.code_hash != trevm::revm::primitives::KECCAK_EMPTY,
43+
}),
44+
_ => Ok(AcctInfo { nonce: 0, balance: U256::ZERO, has_code: false }),
45+
}
46+
}
47+
}
48+
1749
/// Builder for creating pre-populated test databases.
1850
/// Use this builder to set up blockchain state (accounts, contracts, storage)
1951
/// before running simulations.

src/test_utils/env.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,16 @@ impl TestSimEnvBuilder {
117117
HostEnv::new(self.host_db.clone(), self.constants.clone(), &cfg, &self.host_block_env)
118118
}
119119

120+
/// Get a clone of the rollup database.
121+
pub fn rollup_db(&self) -> TestDb {
122+
self.rollup_db.clone()
123+
}
124+
125+
/// Get a clone of the host database.
126+
pub fn host_db(&self) -> TestDb {
127+
self.host_db.clone()
128+
}
129+
120130
/// Build both environments as a tuple.
121131
pub fn build(self) -> (TestRollupEnv, TestHostEnv) {
122132
let rollup = self.build_rollup_env();

0 commit comments

Comments
 (0)