Skip to content

Commit 1967610

Browse files
committed
wires up the block and submit task to use simulation
- adds the simulator task to the block building loop - feeds the submit channel to the simulator after in-progress block creation
1 parent 56d569f commit 1967610

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

bin/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use builder::tasks::metrics::MetricsTask;
77
use builder::tasks::oauth::Authenticator;
88
use builder::tasks::submit::SubmitTask;
99

10+
use builder::tasks::tx_poller;
1011
use tokio::select;
1112

1213
#[tokio::main]

src/tasks/block.rs

+26-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ use super::bundler::{Bundle, BundlePoller};
22
use super::oauth::Authenticator;
33
use super::tx_poller::TxPoller;
44
use crate::config::{BuilderConfig, WalletlessProvider};
5+
use crate::tasks::simulator::SimulatorFactory;
56
use alloy::{
67
consensus::{SidecarBuilder, SidecarCoder, TxEnvelope},
78
eips::eip2718::Decodable2718,
89
primitives::{keccak256, Bytes, B256},
910
providers::Provider as _,
1011
rlp::Buf,
1112
};
13+
use revm::db::{AlloyDB, CacheDB};
14+
use std::sync::Arc;
1215
use std::time::{SystemTime, UNIX_EPOCH};
1316
use std::{sync::OnceLock, time::Duration};
1417
use tokio::{sync::mpsc, task::JoinHandle};
@@ -238,13 +241,29 @@ impl BlockBuilder {
238241
tokio::time::sleep(Duration::from_secs(self.secs_to_next_target())).await;
239242
info!("beginning block build cycle");
240243

241-
// Build a block
242-
let mut in_progress = InProgressBlock::default();
243-
self.get_transactions(&mut in_progress).await;
244-
self.get_bundles(&mut in_progress).await;
245-
246-
// Filter confirmed transactions from the block
247-
self.filter_transactions(&mut in_progress).await;
244+
// Setup a simulator factory
245+
let ru_provider = self.ru_provider.clone();
246+
let latest = ru_provider.get_block_number().await.unwrap();
247+
let db = AlloyDB::new(
248+
ru_provider.into(),
249+
alloy_eips::BlockId::Number(latest.into()),
250+
);
251+
252+
// Calculate the simulation deadline
253+
let deadline = self.secs_to_next_target();
254+
255+
// Create a simulator instance
256+
if let Some(db) = db {
257+
let cache_db = CacheDB::new(Arc::new(db));
258+
let sim = SimulatorFactory::new(cache_db, ());
259+
260+
// TODO: Plumb the
261+
let in_progress =
262+
sim.spawn(inbound_tx, inbound_bundle, evaluator, deadline).await;
263+
outbound.send(in_progress);
264+
} else {
265+
todo!("handle failure to get a db")
266+
}
248267

249268
// submit the block if it has transactions
250269
if !in_progress.is_empty() {

src/tasks/simulator.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use alloy::primitives::U256;
44
use eyre::Result;
55
use revm::{db::CacheDB, primitives::CfgEnv, DatabaseRef};
66
use std::{convert::Infallible, sync::Arc};
7-
use tokio::{select, sync::mpsc::UnboundedReceiver, task::JoinSet};
7+
use tokio::{select, sync::mpsc::{Receiver, UnboundedReceiver}, task::JoinSet};
88
use trevm::{
99
db::sync::{ConcurrentState, ConcurrentStateInfo},
1010
revm::{
@@ -56,8 +56,8 @@ where
5656
/// * This function always returns whatever the latest finished in progress block is.
5757
pub fn spawn<T, F>(
5858
self,
59-
mut inbound_tx: UnboundedReceiver<Arc<TxEnvelope>>,
60-
_inbound_bundle: UnboundedReceiver<Arc<Vec<TxEnvelope>>>,
59+
mut inbound_tx: Receiver<Arc<TxEnvelope>>,
60+
_inbound_bundle: Receiver<Arc<Vec<TxEnvelope>>>,
6161
evaluator: Arc<F>,
6262
deadline: tokio::time::Instant,
6363
) -> tokio::task::JoinHandle<InProgressBlock>

0 commit comments

Comments
 (0)