Skip to content
Draft
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 Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ init4-bin-base = { git = "https://github.com/init4tech/bin-base.git", branch = "
# signet-constants = { version = "0.15.0" }
# signet-sim = { version = "0.15.0" }
# signet-tx-cache = { version = "0.15.0" }
# signet-bundle = { version = "0.15.0" }
# signet-types = { version = "0.15.0" }
# signet-zenith = { version = "0.15.0" }

signet-constants = { git = "https://github.com/init4tech/signet-sdk.git", branch = "dylan/logs-sim-env-errors" }
signet-sim = { git = "https://github.com/init4tech/signet-sdk.git", branch = "dylan/logs-sim-env-errors" }
signet-tx-cache = { git = "https://github.com/init4tech/signet-sdk.git", branch = "dylan/logs-sim-env-errors" }
signet-bundle = { git = "https://github.com/init4tech/signet-sdk.git", branch = "dylan/logs-sim-env-errors" }
signet-types = { git = "https://github.com/init4tech/signet-sdk.git", branch = "dylan/logs-sim-env-errors" }
signet-zenith = { git = "https://github.com/init4tech/signet-sdk.git", branch = "dylan/logs-sim-env-errors" }

Expand Down
17 changes: 13 additions & 4 deletions bin/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,28 @@ use tokio::select;
async fn main() -> eyre::Result<()> {
let _guard = init4_bin_base::init4();
let init_span_guard = info_span!("builder initialization");
builder::config_from_env();
let config = builder::config_from_env();

let (host_provider, ru_provider, quincey) = tokio::try_join!(
config.connect_host_provider(),
config.connect_ru_provider(),
config.connect_quincey(),
)?;

// Set up env and metrics tasks
let (env_task, metrics_task) = tokio::try_join!(EnvTask::new(), MetricsTask::new())?;
let (env_task, metrics_task) = tokio::try_join!(
EnvTask::new(host_provider.clone(), ru_provider.clone(), quincey),
MetricsTask::new()
)?;

// Spawn the env and metrics tasks
let (block_env, env_jh) = env_task.spawn();
let (tx_channel, metrics_jh) = metrics_task.spawn();

// Set up the cache, submit, and simulator tasks
let cache_tasks = CacheTasks::new(block_env.clone());
let (submit_task, simulator_task) =
tokio::try_join!(FlashbotsTask::new(tx_channel.clone()), SimulatorTask::new(block_env),)?;
let submit_task = FlashbotsTask::new(tx_channel.clone()).await?;
let simulator_task = SimulatorTask::new(block_env, host_provider.clone(), ru_provider.clone());

// Spawn the cache, submit, and simulator tasks
let cache_system = cache_tasks.spawn();
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ pub mod utils;
pub mod test_utils;

use init4_bin_base::utils::from_env::FromEnv;

// Anonymous import suppresses warnings about unused imports.
use openssl as _;
use signet_bundle as _;
use signet_constants::SignetSystemConstants;
use std::sync::OnceLock;

Expand Down
13 changes: 6 additions & 7 deletions src/tasks/block/sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ pub struct SimulatorTask {
impl SimulatorTask {
/// Create a new `SimulatorTask` instance. This task must be spawned to
/// begin processing incoming block environments.
pub async fn new(envs: watch::Receiver<Option<SimEnv>>) -> eyre::Result<Self> {
pub fn new(
envs: watch::Receiver<Option<SimEnv>>,
host_provider: HostProvider,
ru_provider: RuProvider,
) -> Self {
let config = crate::config();

let (host_provider, ru_provider) =
tokio::try_join!(config.connect_host_provider(), config.connect_ru_provider())?;

Ok(Self { config, host_provider, ru_provider, envs })
Self { config, host_provider, ru_provider, envs }
}

/// Get the slot calculator.
Expand Down Expand Up @@ -220,7 +220,6 @@ impl SimulatorTask {
else {
continue;
};

span_debug!(span, tx_count = block.transactions().len(), "built simulated block");
let _ = submit_sender.send(SimResult { block, sim_env });
}
Expand Down
21 changes: 10 additions & 11 deletions src/tasks/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use signet_constants::SignetSystemConstants;
use signet_sim::{HostEnv, RollupEnv};
use tokio::{sync::watch, task::JoinHandle};
use tokio_stream::StreamExt;
use tracing::{Instrument, Span, info_span};
use tracing::{Instrument, Span, info_span, instrument};
use trevm::revm::{
context::BlockEnv,
context_interface::block::BlobExcessGasAndPrice,
Expand Down Expand Up @@ -202,20 +202,18 @@ pub struct EnvTask {

impl EnvTask {
/// Create a new [`EnvTask`] with the given config and providers.
pub async fn new() -> eyre::Result<Self> {
pub async fn new(
host_provider: HostProvider,
ru_provider: RuProvider,
quincey: Quincey,
) -> eyre::Result<Self> {
Comment on lines +205 to +209
Copy link
Contributor Author

Choose a reason for hiding this comment

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

NB: These are passed in at construction time for test purposes, but to improve here, we could make our tasks generic over Host and Rollup providers and make this a little bit more idiomatic.

let config = crate::config();

let (host_provider, quincey, ru_provider) = tokio::try_join!(
config.connect_host_provider(),
config.connect_quincey(),
config.connect_ru_provider(),
)?;

Ok(Self { config, host_provider, quincey, ru_provider })
}

/// Construct a [`BlockEnv`] for the next host block from the previous host header.
fn construct_host_env(&self, previous: Header) -> Environment {
#[instrument(skip(self, previous), fields(previous_number = %previous.number))]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made public for testing purposes.

pub fn construct_host_env(&self, previous: Header) -> Environment {
let env = BlockEnv {
number: U256::from(previous.number + 1),
beneficiary: self.config.builder_rewards_address,
Expand All @@ -236,7 +234,8 @@ impl EnvTask {
}

/// Construct a [`BlockEnv`] for the next rollup block from the previous block header.
fn construct_rollup_env(&self, previous: Header) -> Environment {
#[instrument(skip(self, previous), fields(previous_number = %previous.number))]
pub fn construct_rollup_env(&self, previous: Header) -> Environment {
let env = BlockEnv {
number: U256::from(previous.number + 1),
beneficiary: self.config.builder_rewards_address,
Expand Down
12 changes: 6 additions & 6 deletions src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn setup_test_config() -> &'static BuilderConfig {
flashbots_endpoint: "https://relay-sepolia.flashbots.net:443".parse().unwrap(),
quincey_url: "http://localhost:8080".into(),
sequencer_key: None,
builder_key: env::var("SEPOLIA_ETH_PRIV_KEY")
builder_key: env::var("BUILDER_KEY")
.unwrap_or_else(|_| B256::repeat_byte(0x42).to_string()),
builder_port: 8080,
builder_rewards_address: Address::default(),
Expand All @@ -52,7 +52,7 @@ pub fn setup_test_config() -> &'static BuilderConfig {
concurrency_limit: None, // NB: Defaults to available parallelism
slot_calculator: SlotCalculator::new(
1740681556, // pecorino start timestamp as sane default
0, 1,
0, 12,
),
block_query_cutoff_buffer: 3000,
max_host_gas_coefficient: Some(80),
Expand All @@ -64,14 +64,15 @@ pub fn setup_test_config() -> &'static BuilderConfig {
/// Returns a new signed test transaction with the provided nonce, value, and mpfpg.
pub fn new_signed_tx(
wallet: &PrivateKeySigner,
chain_id: u64,
nonce: u64,
value: U256,
mpfpg: u128,
) -> Result<TxEnvelope> {
let tx = TxEip1559 {
chain_id: 11155111,
chain_id,
nonce,
max_fee_per_gas: 10_000_000,
max_fee_per_gas: 50_000_000_000,
max_priority_fee_per_gas: mpfpg,
to: TxKind::Call(Address::from_str("0x0000000000000000000000000000000000000000").unwrap()),
value,
Expand All @@ -91,8 +92,7 @@ pub fn setup_logging() {
let _ = registry.try_init();
}

/// Returns a Pecorino block environment for simulation with the timestamp set to `finish_by`,
/// the block number set to latest + 1, system gas configs, and a beneficiary address.
/// Create a test BlockEnv with the provided parameters
pub fn test_block_env(number: u64, basefee: u64, timestamp: u64) -> BlockEnv {
let config = setup_test_config();
BlockEnv {
Expand Down
Loading