Skip to content

Commit 2144a3f

Browse files
committed
refactor: constants into config
1 parent fe3e828 commit 2144a3f

File tree

11 files changed

+22
-38
lines changed

11 files changed

+22
-38
lines changed

Cargo.lock

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

bin/builder.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use init4_bin_base::{
1010
deps::tracing::{info, info_span},
1111
utils::from_env::FromEnv,
1212
};
13-
use signet_types::constants::SignetSystemConstants;
1413
use tokio::select;
1514

1615
// Note: Must be set to `multi_thread` to support async tasks.
@@ -22,19 +21,14 @@ async fn main() -> eyre::Result<()> {
2221

2322
// Pull the configuration from the environment
2423
let config = BuilderConfig::from_env()?.clone();
25-
let constants = SignetSystemConstants::pecorino();
2624

2725
// We connect the WS greedily, so we can fail early if the connection is
2826
// invalid.
2927
let ru_provider = config.connect_ru_provider().await?;
3028

3129
// Spawn the EnvTask
32-
let env_task = EnvTask::new(
33-
config.clone(),
34-
constants.clone(),
35-
config.connect_host_provider().await?,
36-
ru_provider.clone(),
37-
);
30+
let env_task =
31+
EnvTask::new(config.clone(), config.connect_host_provider().await?, ru_provider.clone());
3832
let (block_env, env_jh) = env_task.spawn();
3933

4034
// Spawn the cache system
@@ -55,7 +49,6 @@ async fn main() -> eyre::Result<()> {
5549
zenith,
5650
quincey,
5751
config: config.clone(),
58-
constants: constants.clone(),
5952
outbound_tx_channel: tx_channel,
6053
};
6154

@@ -64,7 +57,8 @@ async fn main() -> eyre::Result<()> {
6457

6558
// Set up the simulator
6659
let sim = Simulator::new(&config, ru_provider.clone(), block_env);
67-
let build_jh = sim.spawn_simulator_task(constants, cache_system.sim_cache, submit_channel);
60+
let build_jh =
61+
sim.spawn_simulator_task(config.constants.clone(), cache_system.sim_cache, submit_channel);
6862

6963
// Start the healthcheck server
7064
let server = serve_builder(([0, 0, 0, 0], config.builder_port));

src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use init4_bin_base::{
2121
signer::{LocalOrAws, SignerError},
2222
},
2323
};
24+
use signet_constants::SignetSystemConstants;
2425
use signet_zenith::Zenith;
2526
use std::borrow::Cow;
2627
use tokio::join;
@@ -159,6 +160,9 @@ pub struct BuilderConfig {
159160

160161
/// The slot calculator for the builder.
161162
pub slot_calculator: SlotCalculator,
163+
164+
/// The signet system constants.
165+
pub constants: SignetSystemConstants,
162166
}
163167

164168
impl BuilderConfig {

src/tasks/env.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use alloy::{
66
providers::Provider,
77
};
88
use init4_bin_base::deps::tracing::{Instrument, debug, error, info_span};
9-
use signet_constants::SignetSystemConstants;
109
use tokio::{sync::watch, task::JoinHandle};
1110
use tokio_stream::StreamExt;
1211
use tracing::warn;
@@ -18,9 +17,6 @@ pub struct EnvTask {
1817
/// Builder configuration values.
1918
config: BuilderConfig,
2019

21-
/// Signet system constants.
22-
constants: SignetSystemConstants,
23-
2420
/// Host provider is used to get the latest host block header for
2521
/// constructing the next block environment.
2622
host_provider: HostProvider,
@@ -69,11 +65,10 @@ impl EnvTask {
6965
/// Create a new [`EnvTask`] with the given config and providers.
7066
pub const fn new(
7167
config: BuilderConfig,
72-
constants: SignetSystemConstants,
7368
host_provider: HostProvider,
7469
ru_provider: RuProvider,
7570
) -> Self {
76-
Self { config, constants, host_provider, ru_provider }
71+
Self { config, host_provider, ru_provider }
7772
}
7873

7974
/// Construct a [`BlockEnv`] by from the previous block header.
@@ -115,7 +110,7 @@ impl EnvTask {
115110
headers.next().instrument(info_span!("EnvTask::task_fut::stream")).await
116111
{
117112
let host_block_number =
118-
self.constants.rollup_block_to_host_block_num(rollup_header.number);
113+
self.config.constants.rollup_block_to_host_block_num(rollup_header.number);
119114

120115
let span = info_span!("SimEnv", %host_block_number, %rollup_header.hash, %rollup_header.number);
121116

src/tasks/submit/builder_helper.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use init4_bin_base::deps::{
1919
metrics::{counter, histogram},
2020
tracing::{Instrument, debug, debug_span, error, info, warn},
2121
};
22-
use signet_constants::SignetSystemConstants;
2322
use std::{ops::Range, time::Instant};
2423
use tokio::{sync::mpsc, task::JoinHandle};
2524

@@ -81,8 +80,6 @@ pub struct BuilderHelperTask {
8180
pub zenith: ZenithInstance,
8281
/// Quincey
8382
pub quincey: Quincey,
84-
/// Constants
85-
pub constants: SignetSystemConstants,
8683
/// Config
8784
pub config: crate::config::BuilderConfig,
8885
/// Channel over which to send pending transactions
@@ -287,7 +284,6 @@ impl BuilderHelperTask {
287284
self.provider().clone(),
288285
self.quincey.clone(),
289286
self.config.clone(),
290-
self.constants.clone(),
291287
);
292288
let bumpable = res_unwrap_or_continue!(
293289
prep.prep_transaction(&sim_result.sim_env.prev_host)

src/tasks/submit/flashbots.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,12 @@ impl FlashbotsTask {
6464
outbound: mpsc::UnboundedSender<TxHash>,
6565
bundle_helper: bool,
6666
) -> eyre::Result<FlashbotsTask> {
67-
let flashbots = config.flashbots_provider().await?;
68-
let quincey = config.connect_quincey().await?;
69-
let host_provider = config.connect_host_provider().await?;
67+
let (flashbots, quincey, host_provider) = tokio::try_join!(
68+
config.flashbots_provider(),
69+
config.connect_quincey(),
70+
config.connect_host_provider(),
71+
)?;
72+
7073
let zenith = config.connect_zenith(host_provider);
7174

7275
Ok(Self {
@@ -105,7 +108,6 @@ impl FlashbotsTask {
105108
self.host_provider(),
106109
self.quincey.clone(),
107110
self.config.clone(),
108-
self.constants.clone(),
109111
);
110112

111113
let tx = prep.prep_transaction(&sim_result.sim_env.prev_header).await.map_err(|err| {

src/tasks/submit/prep.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use alloy::{
1212
sol_types::SolCall,
1313
};
1414
use init4_bin_base::deps::tracing::debug;
15-
use signet_constants::SignetSystemConstants;
1615
use signet_sim::BuiltBlock;
1716
use signet_types::{SignRequest, SignResponse};
1817
use signet_zenith::BundleHelper;
@@ -31,7 +30,6 @@ pub struct SubmitPrep<'a> {
3130
provider: HostProvider,
3231
quincey: Quincey,
3332
config: BuilderConfig,
34-
constants: SignetSystemConstants,
3533

3634
// Memoized quincey request and response
3735
sig_request: std::sync::OnceLock<SignRequest>,
@@ -45,7 +43,6 @@ impl<'a> SubmitPrep<'a> {
4543
provider: HostProvider,
4644
quincey: Quincey,
4745
config: BuilderConfig,
48-
constants: SignetSystemConstants,
4946
) -> Self {
5047
Self {
5148
block,
@@ -54,15 +51,14 @@ impl<'a> SubmitPrep<'a> {
5451
provider,
5552
quincey,
5653
config,
57-
constants,
5854
}
5955
}
6056

6157
/// Construct a quincey signature request for the block.
6258
fn sig_request(&self) -> &SignRequest {
6359
self.sig_request.get_or_init(|| {
6460
let host_block_number =
65-
self.constants.rollup_block_to_host_block_num(self.block.block_number());
61+
self.config.constants.rollup_block_to_host_block_num(self.block.block_number());
6662

6763
SignRequest {
6864
host_block_number: U256::from(host_block_number),
@@ -102,7 +98,7 @@ impl<'a> SubmitPrep<'a> {
10298
// Build the block header
10399
let header = BundleHelper::BlockHeader {
104100
hostBlockNumber: self.sig_request().host_block_number,
105-
rollupChainId: U256::from(self.constants.ru_chain_id()),
101+
rollupChainId: U256::from(self.config.constants.ru_chain_id()),
106102
gasLimit: self.sig_request().gas_limit,
107103
rewardAddress: self.sig_request().ru_reward_address,
108104
blockDataHash: *self.block.contents_hash(),

src/test_utils.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use init4_bin_base::{
1414
perms::OAuthConfig,
1515
utils::{calc::SlotCalculator, flashbots::FlashbotsConfig, provider::ProviderConfig},
1616
};
17+
use signet_constants::SignetSystemConstants;
1718
use std::env;
1819
use std::str::FromStr;
1920
use trevm::revm::{context::BlockEnv, context_interface::block::BlobExcessGasAndPrice};
@@ -61,6 +62,7 @@ pub fn setup_test_config() -> Result<BuilderConfig> {
6162
1740681556, // pecorino start timestamp as sane default
6263
0, 1,
6364
),
65+
constants: SignetSystemConstants::pecorino(),
6466
};
6567
Ok(config)
6668
}

tests/block_builder_test.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ async fn test_handle_build() {
4444

4545
let block_env = EnvTask::new(
4646
config.clone(),
47-
constants.clone(),
4847
config.connect_host_provider().await.unwrap(),
4948
ru_provider.clone(),
5049
)

tests/cache.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use builder::{
33
test_utils::{setup_logging, setup_test_config},
44
};
55
use init4_bin_base::deps::tracing::warn;
6-
use signet_constants::SignetSystemConstants;
76
use std::time::Duration;
87

98
#[ignore = "integration test. This test will take >12 seconds to run, and requires Authz configuration env vars."]
@@ -15,7 +14,6 @@ async fn test_bundle_poller_roundtrip() -> eyre::Result<()> {
1514

1615
let (block_env, _jh) = EnvTask::new(
1716
config.clone(),
18-
SignetSystemConstants::pecorino(),
1917
config.connect_host_provider().await?,
2018
config.connect_ru_provider().await?,
2119
)

0 commit comments

Comments
 (0)