Sitelet https://github.com/init4tech/builder/commit/dd232a0db6af39cf4a80d744573846d77dc8ae1f
Skip to content

Commit dd232a0

Browse files
committed
update to match changes in bin-base
1 parent 2405577 commit dd232a0

4 files changed

Lines changed: 74 additions & 54 deletions

File tree

‎bin/builder.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ async fn main() -> eyre::Result<()> {
5858
}
5959

6060
let config = builder::config_from_env();
61-
let _guard = init4_bin_base::init(config.tracing.clone(), config.metrics);
6261
let init_span_guard = info_span!("builder initialization").entered();
6362

6463
info!(pkg_version = PKG_VERSION, git_commit = GIT_COMMIT, "starting builder");
@@ -89,7 +88,7 @@ async fn main() -> eyre::Result<()> {
8988
let build_jh = simulator_task.spawn_simulator_task(cache_system.sim_cache, submit_channel);
9089

9190
// Start the healthcheck server
92-
let server = serve_builder(([0, 0, 0, 0], builder::config().builder_port));
91+
let server = serve_builder(([0, 0, 0, 0], config.builder_port));
9392

9493
// We have finished initializing the builder, so we can drop the init span
9594
// guard.

‎src/config.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use alloy::{
1212
};
1313
use eyre::Result;
1414
use init4_bin_base::{
15+
Init4Config,
1516
perms::{Authenticator, OAuthConfig, SharedToken, pylon},
1617
utils::{
1718
calc::SlotCalculator,
@@ -196,6 +197,16 @@ pub struct BuilderConfig {
196197
pub metrics: MetricsConfig,
197198
}
198199

200+
impl Init4Config for BuilderConfig {
201+
fn tracing(&self) -> &TracingConfig {
202+
&self.tracing
203+
}
204+
205+
fn metrics(&self) -> &MetricsConfig {
206+
&self.metrics
207+
}
208+
}
209+
199210
impl BuilderConfig {
200211
/// Sanitizes URL fields to ensure consistent behavior with `url.join()`.
201212
///

‎src/lib.rs‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,33 @@ pub mod utils;
3434
/// Test utilitites
3535
pub mod test_utils;
3636

37-
use init4_bin_base::utils::from_env::FromEnv;
3837
// Anonymous imports suppress warnings about unused crate dependencies.
3938
use git_version as _;
39+
use init4_bin_base::ConfigAndGuard;
4040
use openssl as _;
4141
use signet_constants::SignetSystemConstants;
4242
use std::sync::OnceLock;
4343

44-
/// Global static configuration for the Builder binary.
45-
pub static CONFIG: OnceLock<config::BuilderConfig> = OnceLock::new();
44+
/// Global static configuration and OTLP guard for the Builder binary. The
45+
/// guard is kept alive for the lifetime of the process.
46+
static CONFIG_AND_GUARD: OnceLock<ConfigAndGuard<config::BuilderConfig>> = OnceLock::new();
4647

47-
/// Load the Builder configuration from the environment and store it in the
48-
/// global static CONFIG variable. Returns a reference to the configuration.
48+
/// Load the Builder configuration from the environment, initialize tracing and
49+
/// metrics, and store the config in the global static. Returns a reference to
50+
/// the configuration.
4951
///
5052
/// # Panics
5153
///
52-
/// Panics if the configuration cannot be loaded from the environment AND no
53-
/// other configuration has been previously initialized.
54+
/// Panics if the configuration cannot be loaded from the environment.
5455
pub fn config_from_env() -> &'static config::BuilderConfig {
55-
CONFIG.get_or_init(|| {
56-
config::BuilderConfig::from_env().expect("Failed to load Builder config").sanitize()
57-
})
56+
&CONFIG_AND_GUARD
57+
.get_or_init(|| {
58+
let mut config_and_guard = init4_bin_base::init::<config::BuilderConfig>()
59+
.expect("Failed to load Builder config");
60+
config_and_guard.config = config_and_guard.config.sanitize();
61+
config_and_guard
62+
})
63+
.config
5864
}
5965

6066
/// Get a reference to the global Builder configuration.
@@ -63,7 +69,7 @@ pub fn config_from_env() -> &'static config::BuilderConfig {
6369
///
6470
/// Panics if the configuration has not been initialized.
6571
pub fn config() -> &'static config::BuilderConfig {
66-
CONFIG.get().expect("Builder config not initialized")
72+
&CONFIG_AND_GUARD.get().expect("Builder config not initialized").config
6773
}
6874

6975
/// Get a reference to the Signet system constants from the global Builder

‎src/test_utils.rs‎

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use alloy::{
99
use core::str::FromStr;
1010
use eyre::Result;
1111
use init4_bin_base::{
12+
ConfigAndGuard,
1213
deps::tracing_subscriber::{
1314
EnvFilter, Layer, fmt, layer::SubscriberExt, registry, util::SubscriberInitExt,
1415
},
@@ -24,47 +25,50 @@ use trevm::revm::{context::BlockEnv, context_interface::block::BlobExcessGasAndP
2425

2526
/// Set up a block builder with test values
2627
pub fn setup_test_config() -> &'static BuilderConfig {
27-
crate::CONFIG.get_or_init(|| {
28-
BuilderConfig {
29-
host_rpc: "ws://host-rpc.pecorino.signet.sh"
30-
.parse::<BuiltInConnectionString>()
31-
.map(ProviderConfig::new)
32-
.unwrap(),
33-
ru_rpc: "ws://rpc.pecorino.signet.sh"
34-
.parse::<BuiltInConnectionString>()
35-
.unwrap()
36-
.try_into()
37-
.unwrap(),
38-
flashbots_endpoint: "https://relay-sepolia.flashbots.net:443".parse().unwrap(),
39-
quincey_url: "http://localhost:8080".into(),
40-
sequencer_key: None,
41-
builder_key: env::var("SEPOLIA_ETH_PRIV_KEY")
42-
.unwrap_or_else(|_| B256::repeat_byte(0x42).to_string()),
43-
builder_port: 8080,
44-
builder_rewards_address: Address::default(),
45-
rollup_block_gas_limit: 3_000_000_000,
46-
tx_pool_url: "http://localhost:9000/".parse().unwrap(),
47-
oauth: OAuthConfig {
48-
oauth_client_id: "some_client_id".into(),
49-
oauth_client_secret: "some_client_secret".into(),
50-
oauth_authenticate_url: "http://localhost:8080".parse().unwrap(),
51-
oauth_token_url: "http://localhost:8080".parse().unwrap(),
52-
oauth_token_refresh_interval: 300, // 5 minutes
53-
},
54-
concurrency_limit: None, // NB: Defaults to available parallelism
55-
slot_calculator: SlotCalculator::new(
56-
1740681556, // pecorino start timestamp as sane default
57-
0, 1,
58-
),
59-
block_query_cutoff_buffer: Default::default(),
60-
submit_deadline_buffer: Default::default(),
61-
max_host_gas_coefficient: Default::default(),
62-
constants: SignetSystemConstants::parmigiana(),
63-
pylon_url: "http://localhost:8081".parse().unwrap(),
64-
tracing: TracingConfig::default(),
65-
metrics: MetricsConfig::default(),
66-
}
67-
})
28+
&crate::CONFIG_AND_GUARD
29+
.get_or_init(|| {
30+
let config = BuilderConfig {
31+
host_rpc: "ws://host-rpc.pecorino.signet.sh"
32+
.parse::<BuiltInConnectionString>()
33+
.map(ProviderConfig::new)
34+
.unwrap(),
35+
ru_rpc: "ws://rpc.pecorino.signet.sh"
36+
.parse::<BuiltInConnectionString>()
37+
.unwrap()
38+
.try_into()
39+
.unwrap(),
40+
flashbots_endpoint: "https://relay-sepolia.flashbots.net:443".parse().unwrap(),
41+
quincey_url: "http://localhost:8080".into(),
42+
sequencer_key: None,
43+
builder_key: env::var("SEPOLIA_ETH_PRIV_KEY")
44+
.unwrap_or_else(|_| B256::repeat_byte(0x42).to_string()),
45+
builder_port: 8080,
46+
builder_rewards_address: Address::default(),
47+
rollup_block_gas_limit: 3_000_000_000,
48+
tx_pool_url: "http://localhost:9000/".parse().unwrap(),
49+
oauth: OAuthConfig {
50+
oauth_client_id: "some_client_id".into(),
51+
oauth_client_secret: "some_client_secret".into(),
52+
oauth_authenticate_url: "http://localhost:8080".parse().unwrap(),
53+
oauth_token_url: "http://localhost:8080".parse().unwrap(),
54+
oauth_token_refresh_interval: 300, // 5 minutes
55+
},
56+
concurrency_limit: None, // NB: Defaults to available parallelism
57+
slot_calculator: SlotCalculator::new(
58+
1740681556, // pecorino start timestamp as sane default
59+
0, 1,
60+
),
61+
block_query_cutoff_buffer: Default::default(),
62+
submit_deadline_buffer: Default::default(),
63+
max_host_gas_coefficient: Default::default(),
64+
constants: SignetSystemConstants::parmigiana(),
65+
pylon_url: "http://localhost:8081".parse().unwrap(),
66+
tracing: TracingConfig::default(),
67+
metrics: MetricsConfig::default(),
68+
};
69+
ConfigAndGuard { config, guard: None }
70+
})
71+
.config
6872
}
6973

7074
/// Returns a new signed test transaction with the provided nonce, value, and mpfpg.

0 commit comments

Comments
 (0)