Skip to content

Commit b6cef11

Browse files
committed
patched with in memory database as workaround for now
1 parent 2b55dc0 commit b6cef11

File tree

3 files changed

+18
-103
lines changed

3 files changed

+18
-103
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ signet-bundle = { git = "https://github.com/init4tech/signet-sdk", branch = "mai
2828
signet-types = { git = "https://github.com/init4tech/signet-sdk", branch = "main" }
2929
signet-zenith = { git = "https://github.com/init4tech/signet-sdk", branch = "main" }
3030

31-
trevm = { version = "0.20.4", features = [ "concurrent-db", "test-utils" ]}
31+
# trevm = { version = "0.20.4", features = [ "concurrent-db", "test-utils" ]}
32+
trevm = { path = "../trevm", features = [ "concurrent-db", "test-utils" ]}
3233

3334
alloy = { version = "0.12.6", features = [
3435
"full",

src/tasks/simulator.rs

Lines changed: 2 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use eyre::Result;
55
use std::sync::Arc;
66
use tokio::{select, sync::mpsc::UnboundedReceiver, task::JoinSet};
77
use trevm::{
8-
db::{cow::CacheOnWrite, sync::{ConcurrentState, ConcurrentStateInfo}}, helpers::Ctx, revm::{
8+
db::sync::{ConcurrentState, ConcurrentStateInfo}, helpers::Ctx, revm::{
99
context::{
1010
result::{EVMError, ExecutionResult, ResultAndState}, CfgEnv
1111
}, primitives::address, state::Account, Database, DatabaseCommit, DatabaseRef, Inspector
12-
}, BlockDriver, Cfg, DbConnect, EvmFactory, NoopBlock, TrevmBuilder, TrevmBuilderError, Tx
12+
}, Cfg, DbConnect, EvmFactory, NoopBlock, TrevmBuilder, TrevmBuilderError, Tx
1313
};
1414

1515
/// Tracks the EVM state, score, and result of an EVM execution.
@@ -210,74 +210,6 @@ where
210210
}
211211
}
212212

213-
pub trait BlockExtractor<Insp, Db>
214-
where
215-
Db: Database + DatabaseCommit,
216-
Insp: Inspector<Ctx<Db>>,
217-
{
218-
/// BlockDriver runs the transactions over the provided trevm instance.
219-
type Driver: BlockDriver<Insp, Error<Db>: core::error::Error>;
220-
221-
/// Instantiate an configure a new [`trevm`] instance.
222-
fn trevm(&self, db: Db) -> trevm::EvmNeedsBlock<Db, Insp>;
223-
224-
/// Extracts transactions from the source.
225-
///
226-
/// Extraction is infallible. Worst case it should return a no-op driver.
227-
fn extract(&mut self, bytes: &[u8]) -> Self::Driver;
228-
}
229-
230-
impl<Insp> BlockDriver<Insp> for InProgressBlock {
231-
type Block = NoopBlock;
232-
233-
type Error<Db: Database + DatabaseCommit> = Error<Db>;
234-
235-
fn block(&self) -> &Self::Block {
236-
&NoopBlock
237-
}
238-
239-
/// Loops through the transactions in the block and runs them, accepting the state at the end
240-
/// if it was successful and returning and erroring out otherwise.
241-
fn run_txns<Db: Database + DatabaseCommit>(
242-
&mut self,
243-
mut trevm: trevm::EvmNeedsTx<Db, Insp>,
244-
) -> trevm::RunTxResult<Db, Insp, Self>
245-
where
246-
Insp: Inspector<Ctx<Db>>,
247-
{
248-
for tx in self.transactions().iter() {
249-
if tx.recover_signer().is_ok() {
250-
let sender = tx.recover_signer().unwrap();
251-
tracing::info!(sender = ?sender, tx_hash = ?tx.tx_hash(), "simulating transaction");
252-
253-
let t = match trevm.run_tx(tx) {
254-
Ok(t) => t,
255-
Err(e) => {
256-
if e.is_transaction_error() {
257-
return Ok(e.discard_error());
258-
} else {
259-
return Err(e.err_into());
260-
}
261-
}
262-
};
263-
264-
(_, trevm) = t.accept();
265-
}
266-
}
267-
Ok(trevm)
268-
}
269-
270-
fn post_block<Db: Database + DatabaseCommit>(
271-
&mut self,
272-
_trevm: &trevm::EvmNeedsBlock<Db, Insp>,
273-
) -> Result<(), Self::Error<Db>>
274-
where
275-
Insp: Inspector<Ctx<Db>>,
276-
{
277-
Ok(())
278-
}
279-
}
280-
281213
/// Defines the CfgEnv for Pecorino Network
282214
#[derive(Debug, Clone, Copy)]
283215
pub struct PecorinoCfg;

tests/simulator_test.rs

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,52 @@
11
use alloy::{
22
consensus::{SignableTransaction as _, TxEip1559, TxEnvelope},
3-
eips::BlockId,
4-
network::Ethereum,
53
primitives::U256,
6-
providers::{Provider, ProviderBuilder},
74
signers::SignerSync as _,
85
signers::local::PrivateKeySigner,
96
};
10-
use builder::{config::WalletlessProvider, tasks::simulator::SimulatorFactory};
7+
use builder::tasks::simulator::SimulatorFactory;
118
use std::sync::Arc;
129
use tokio::{
1310
sync::mpsc,
1411
time::{Duration, Instant},
1512
};
1613
use trevm::{
17-
db::{
18-
cow::CacheOnWrite,
19-
sync::{ConcurrentState, ConcurrentStateInfo},
20-
},
14+
db::cow::CacheOnWrite,
2115
revm::{
2216
context::result::{ExecutionResult, ResultAndState},
23-
database::{CacheDB, Database, DatabaseCommit, DatabaseRef, AlloyDB, WrapDatabaseAsync},
24-
primitives::{TxKind, address},
17+
database::InMemoryDB,
2518
inspector::NoOpInspector,
19+
primitives::{address, TxKind},
2620
state::Account,
2721
},
2822
};
2923

30-
// Define a type alias for the database used with SimulatorFactory.
31-
type Db = WrapDatabaseAsync<AlloyDB<Ethereum, WalletlessProvider>>;
32-
3324
#[tokio::test(flavor = "multi_thread")]
3425
async fn test_spawn() {
3526
// Setup transaction pipeline plumbing
3627
let (tx_sender, tx_receiver) = mpsc::unbounded_channel::<TxEnvelope>();
37-
let (_bundle_sender, bundle_receiver) = mpsc::unbounded_channel::<Vec<TxEnvelope>>();
28+
let (_bundle_sender, _bundle_receiver) = mpsc::unbounded_channel::<Vec<TxEnvelope>>();
3829
let deadline = Instant::now() + Duration::from_secs(2);
3930

40-
// Create a new anvil instance
31+
// Create a new anvil instance and test wallets
4132
let anvil =
4233
alloy::node_bindings::Anvil::new().block_time(1).chain_id(14174).try_spawn().unwrap();
43-
44-
// Create a test wallet from the anvil keys
4534
let keys = anvil.keys();
4635
let test_wallet = &PrivateKeySigner::from(keys[0].clone());
4736

48-
// Create a root provider on that anvil instance
49-
let root_provider = ProviderBuilder::new().on_http(anvil.endpoint_url());
50-
let latest = root_provider.get_block_number().await.unwrap();
51-
52-
// Create an alloyDB from the provider at the latest height
53-
let alloy_db: AlloyDB<Ethereum, WalletlessProvider> =
54-
AlloyDB::new(root_provider.clone(), BlockId::from(latest));
55-
56-
let wrapped_db = WrapDatabaseAsync::new(alloy_db).unwrap();
57-
let concurrent_db = ConcurrentState::new(wrapped_db, ConcurrentStateInfo::default());
58-
59-
// Define the evaluator function
37+
// Create a evaluator
6038
let evaluator = Arc::new(test_evaluator);
6139

62-
// Create a simulation factory with the provided DB
63-
let sim_factory = SimulatorFactory::new(concurrent_db, NoOpInspector);
40+
// Create a database
41+
let db = CacheOnWrite::new(InMemoryDB::default());
42+
43+
// Create a new simulator factory with the given database and inspector
44+
let sim_factory = SimulatorFactory::new(db, NoOpInspector);
6445

46+
// Spawn the simulator actor
6547
let handle = sim_factory.spawn(tx_receiver, evaluator, deadline);
6648

67-
// Send some transactions
49+
// Send transactions to the simulator
6850
for count in 0..2 {
6951
let test_tx = new_test_tx(test_wallet, count).unwrap();
7052
tx_sender.send(test_tx).unwrap();

0 commit comments

Comments
 (0)