Skip to content

Commit 4f8f6ae

Browse files
authored
fix: use new sdk (#81)
* fix: use new sdk * refactor: normalize tracing imports (#76) * refactor: update config to use derive * fix: not optional * refactor: normalize tracing imports
1 parent 26fb35c commit 4f8f6ae

14 files changed

+88
-114
lines changed

Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ hex = { package = "const-hex", version = "1", default-features = false, features
4949
] }
5050

5151
serde = { version = "1.0.197", features = ["derive"] }
52-
tracing = "0.1.40"
5352

5453
axum = "0.7.5"
5554
eyre = "0.6.12"
@@ -61,5 +60,4 @@ tokio = { version = "1.36.0", features = ["full", "macros", "rt-multi-thread"] }
6160

6261
async-trait = "0.1.80"
6362
oauth2 = "4.4.2"
64-
tracing-subscriber = "0.3.19"
6563
chrono = "0.4.41"

bin/builder.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use builder::{
88
};
99
use init4_bin_base::{deps::tracing, utils::from_env::FromEnv};
1010
use signet_sim::SimCache;
11+
use signet_types::constants::SignetSystemConstants;
1112
use std::sync::Arc;
1213
use tokio::select;
1314
use tracing::info_span;
@@ -20,7 +21,7 @@ async fn main() -> eyre::Result<()> {
2021
let init_span_guard = info_span!("builder initialization");
2122

2223
let config = BuilderConfig::from_env()?.clone();
23-
let constants = config.load_pecorino_constants();
24+
let constants = SignetSystemConstants::pecorino();
2425
let authenticator = Authenticator::new(&config)?;
2526

2627
let (host_provider, sequencer_signer) =

bin/submit_transaction.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ use alloy::{
77
};
88
use builder::config::HostProvider;
99
use init4_bin_base::{
10-
deps::metrics::{counter, histogram},
10+
deps::{
11+
metrics::{counter, histogram},
12+
tracing,
13+
},
1114
init4,
1215
utils::from_env::FromEnv,
1316
};
@@ -45,11 +48,10 @@ impl Config {
4548

4649
#[tokio::main]
4750
async fn main() {
48-
init4();
49-
50-
tracing::trace!("connecting to provider");
51+
let _guard = init4();
5152

5253
let config = Config::from_env().unwrap();
54+
tracing::trace!("connecting to provider");
5355
let provider = config.provider().await;
5456
let recipient_address = config.recipient_address;
5557
let sleep_time = config.sleep_time;

src/config.rs

+1-31
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use crate::{
2-
constants,
3-
signer::{LocalOrAws, SignerError},
4-
};
1+
use crate::signer::{LocalOrAws, SignerError};
52
use alloy::{
63
network::{Ethereum, EthereumWallet},
74
primitives::Address,
@@ -16,7 +13,6 @@ use alloy::{
1613
use eyre::Result;
1714
use init4_bin_base::utils::{calc::SlotCalculator, from_env::FromEnv};
1815
use oauth2::url;
19-
use signet_types::config::{HostConfig, PredeployTokens, RollupConfig, SignetSystemConstants};
2016
use signet_zenith::Zenith;
2117
use std::borrow::Cow;
2218

@@ -210,30 +206,4 @@ impl BuilderConfig {
210206
pub const fn connect_zenith(&self, provider: HostProvider) -> ZenithInstance {
211207
Zenith::new(self.zenith_address, provider)
212208
}
213-
214-
/// Loads the Signet system constants for Pecorino.
215-
pub const fn load_pecorino_constants(&self) -> SignetSystemConstants {
216-
let host = HostConfig::new(
217-
self.host_chain_id,
218-
constants::PECORINO_DEPLOY_HEIGHT,
219-
self.zenith_address,
220-
constants::HOST_ORDERS,
221-
constants::HOST_PASSAGE,
222-
constants::HOST_TRANSACTOR,
223-
PredeployTokens::new(constants::HOST_USDC, constants::HOST_USDT, constants::HOST_WBTC),
224-
);
225-
let rollup = RollupConfig::new(
226-
self.ru_chain_id,
227-
constants::ROLLUP_ORDERS,
228-
constants::ROLLUP_PASSAGE,
229-
constants::BASE_FEE_RECIPIENT,
230-
PredeployTokens::new(
231-
constants::ROLLUP_USDC,
232-
constants::ROLLUP_USDT,
233-
constants::ROLLUP_WBTC,
234-
),
235-
);
236-
237-
SignetSystemConstants::new(host, rollup)
238-
}
239209
}

src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,3 @@ pub mod test_utils;
3535

3636
// Anonymous import suppresses warnings about unused imports.
3737
use openssl as _;
38-
use tracing_subscriber as _;

src/service.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use axum::{
44
response::{IntoResponse, Response},
55
routing::get,
66
};
7+
use init4_bin_base::deps::tracing::error;
78
use std::net::SocketAddr;
89

910
/// Return a 404 Not Found response
@@ -25,11 +26,11 @@ pub fn serve_builder(socket: impl Into<SocketAddr>) -> tokio::task::JoinHandle<(
2526
match tokio::net::TcpListener::bind(&addr).await {
2627
Ok(listener) => {
2728
if let Err(err) = axum::serve(listener, router).await {
28-
tracing::error!(%err, "serve failed");
29+
error!(%err, "serve failed");
2930
}
3031
}
3132
Err(err) => {
32-
tracing::error!(%err, "failed to bind to the address");
33+
error!(%err, "failed to bind to the address");
3334
}
3435
};
3536
})

src/tasks/block.rs

+27-24
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ use alloy::{
1515
};
1616
use chrono::{DateTime, Utc};
1717
use eyre::Report;
18-
use init4_bin_base::utils::calc::SlotCalculator;
18+
use init4_bin_base::{
19+
deps::tracing::{debug, error, info, warn},
20+
utils::calc::SlotCalculator,
21+
};
1922
use signet_sim::{BlockBuild, BuiltBlock, SimCache};
20-
use signet_types::config::SignetSystemConstants;
23+
use signet_types::constants::SignetSystemConstants;
2124
use std::{
2225
sync::{
2326
Arc,
@@ -118,7 +121,7 @@ impl Simulator {
118121
);
119122

120123
let block = block_build.build().await;
121-
tracing::debug!(block = ?block, "finished block simulation");
124+
debug!(block = ?block, "finished block simulation");
122125

123126
Ok(block)
124127
}
@@ -142,7 +145,7 @@ impl Simulator {
142145
bundle_receiver: mpsc::UnboundedReceiver<Bundle>,
143146
cache: SimCache,
144147
) -> (JoinHandle<()>, JoinHandle<()>) {
145-
tracing::debug!("starting up cache handler");
148+
debug!("starting up cache handler");
146149

147150
let basefee_price = Arc::new(AtomicU64::new(0_u64));
148151
let basefee_reader = Arc::clone(&basefee_price);
@@ -170,13 +173,13 @@ impl Simulator {
170173
///
171174
/// - `price`: A shared `Arc<AtomicU64>` used to store the updated basefee value.
172175
async fn basefee_updater(self: Arc<Self>, price: Arc<AtomicU64>) {
173-
tracing::debug!("starting basefee updater");
176+
debug!("starting basefee updater");
174177
loop {
175178
// calculate start of next slot plus a small buffer
176179
let time_remaining = self.slot_calculator.slot_duration()
177180
- self.slot_calculator.current_timepoint_within_slot()
178181
+ 1;
179-
tracing::debug!(time_remaining = ?time_remaining, "basefee updater sleeping until next slot");
182+
debug!(time_remaining = ?time_remaining, "basefee updater sleeping until next slot");
180183

181184
// wait until that point in time
182185
sleep(Duration::from_secs(time_remaining)).await;
@@ -199,15 +202,15 @@ impl Simulator {
199202
/// - `price`: A shared `Arc<AtomicU64>` used to store the updated basefee.
200203
async fn check_basefee(&self, price: &Arc<AtomicU64>) {
201204
let resp = self.ru_provider.get_block_by_number(Latest).await.inspect_err(|e| {
202-
tracing::error!(error = %e, "RPC error during basefee update");
205+
error!(error = %e, "RPC error during basefee update");
203206
});
204207

205208
if let Ok(Some(block)) = resp {
206209
let basefee = block.header.base_fee_per_gas.unwrap_or(0);
207210
price.store(basefee, Ordering::Relaxed);
208-
tracing::debug!(basefee = basefee, "basefee updated");
211+
debug!(basefee = basefee, "basefee updated");
209212
} else {
210-
tracing::warn!("get basefee failed - an error likely occurred");
213+
warn!("get basefee failed - an error likely occurred");
211214
}
212215
}
213216

@@ -229,7 +232,7 @@ impl Simulator {
229232
cache: SimCache,
230233
submit_sender: mpsc::UnboundedSender<BuiltBlock>,
231234
) -> JoinHandle<()> {
232-
tracing::debug!("starting builder task");
235+
debug!("starting builder task");
233236

234237
tokio::spawn(async move { self.run_simulator(constants, cache, submit_sender).await })
235238
}
@@ -261,19 +264,19 @@ impl Simulator {
261264
let block_env = match self.next_block_env(finish_by).await {
262265
Ok(block) => block,
263266
Err(err) => {
264-
tracing::error!(err = %err, "failed to configure next block");
267+
error!(err = %err, "failed to configure next block");
265268
break;
266269
}
267270
};
268-
tracing::info!(block_env = ?block_env, "created block");
271+
info!(block_env = ?block_env, "created block");
269272

270273
match self.handle_build(constants, sim_cache, finish_by, block_env).await {
271274
Ok(block) => {
272-
tracing::debug!(block = ?block, "built block");
275+
debug!(block = ?block, "built block");
273276
let _ = submit_sender.send(block);
274277
}
275278
Err(e) => {
276-
tracing::error!(err = %e, "failed to build block");
279+
error!(err = %e, "failed to build block");
277280
continue;
278281
}
279282
}
@@ -306,7 +309,7 @@ impl Simulator {
306309
let latest = match self.ru_provider.get_block_number().await {
307310
Ok(block_number) => block_number,
308311
Err(e) => {
309-
tracing::error!(error = %e, "failed to get latest block number");
312+
error!(error = %e, "failed to get latest block number");
310313
return None;
311314
}
312315
};
@@ -336,27 +339,27 @@ impl Simulator {
336339
let remaining = finish_by.duration_since(Instant::now());
337340
let finish_time = SystemTime::now() + remaining;
338341
let deadline: DateTime<Utc> = finish_time.into();
339-
tracing::debug!(deadline = %deadline, "preparing block env");
342+
debug!(deadline = %deadline, "preparing block env");
340343

341344
// Fetch the latest block number and increment it by 1
342345
let latest_block_number = match self.ru_provider.get_block_number().await {
343346
Ok(num) => num,
344347
Err(err) => {
345-
tracing::error!(error = %err, "RPC error during block build");
348+
error!(error = %err, "RPC error during block build");
346349
return Err(SimulatorError::Rpc(Report::new(err)));
347350
}
348351
};
349-
tracing::debug!(next_block_num = latest_block_number + 1, "preparing block env");
352+
debug!(next_block_num = latest_block_number + 1, "preparing block env");
350353

351354
// Fetch the basefee from previous block to calculate gas for this block
352355
let basefee = match self.get_basefee().await? {
353356
Some(basefee) => basefee,
354357
None => {
355-
tracing::warn!("get basefee failed - RPC error likely occurred");
358+
warn!("get basefee failed - RPC error likely occurred");
356359
BASEFEE_DEFAULT
357360
}
358361
};
359-
tracing::debug!(basefee = basefee, "setting basefee");
362+
debug!(basefee = basefee, "setting basefee");
360363

361364
// Craft the Block environment to pass to the simulator
362365
let block_env = PecorinoBlockEnv::new(
@@ -365,7 +368,7 @@ impl Simulator {
365368
deadline.timestamp() as u64,
366369
basefee,
367370
);
368-
tracing::debug!(block_env = ?block_env, "prepared block env");
371+
debug!(block_env = ?block_env, "prepared block env");
369372

370373
Ok(block_env)
371374
}
@@ -380,7 +383,7 @@ impl Simulator {
380383
match self.ru_provider.get_block_by_number(Latest).await {
381384
Ok(maybe_block) => match maybe_block {
382385
Some(block) => {
383-
tracing::debug!(basefee = ?block.header.base_fee_per_gas, "basefee found");
386+
debug!(basefee = ?block.header.base_fee_per_gas, "basefee found");
384387
Ok(block.header.base_fee_per_gas)
385388
}
386389
None => Ok(None),
@@ -414,13 +417,13 @@ async fn cache_updater(
414417
select! {
415418
maybe_tx = tx_receiver.recv() => {
416419
if let Some(tx) = maybe_tx {
417-
tracing::debug!(tx = ?tx.hash(), "received transaction");
420+
debug!(tx = ?tx.hash(), "received transaction");
418421
cache.add_item(tx, p);
419422
}
420423
}
421424
maybe_bundle = bundle_receiver.recv() => {
422425
if let Some(bundle) = maybe_bundle {
423-
tracing::debug!(bundle = ?bundle.id, "received bundle");
426+
debug!(bundle = ?bundle.id, "received bundle");
424427
cache.add_item(bundle.bundle, p);
425428
}
426429
}

src/tasks/bundler.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
//! Bundler service responsible for fetching bundles and sending them to the simulator.
2-
use crate::tasks::oauth::SharedToken;
2+
use crate::{config::BuilderConfig, tasks::oauth::SharedToken};
3+
use init4_bin_base::deps::tracing::{Instrument, debug, debug_span, error, trace, warn};
34
use oauth2::TokenResponse;
45
use reqwest::{Client, Url};
56
use serde::{Deserialize, Serialize};
67
use signet_bundle::SignetEthBundle;
78
use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender, unbounded_channel};
89
use tokio::task::JoinHandle;
910
use tokio::time;
10-
use tracing::{Instrument, debug, trace, warn};
11-
12-
pub use crate::config::BuilderConfig;
1311

1412
/// Holds a bundle from the cache with a unique ID and a Zenith bundle.
1513
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -80,7 +78,7 @@ impl BundlePoller {
8078

8179
async fn task_future(mut self, outbound: UnboundedSender<Bundle>) {
8280
loop {
83-
let span = tracing::debug_span!("BundlePoller::loop", url = %self.config.tx_pool_url);
81+
let span = debug_span!("BundlePoller::loop", url = %self.config.tx_pool_url);
8482

8583
// Enter the span for the next check.
8684
let _guard = span.enter();
@@ -96,10 +94,10 @@ impl BundlePoller {
9694

9795
match self.check_bundle_cache().instrument(span.clone()).await {
9896
Ok(bundles) => {
99-
tracing::debug!(count = ?bundles.len(), "found bundles");
97+
debug!(count = ?bundles.len(), "found bundles");
10098
for bundle in bundles.into_iter() {
10199
if let Err(err) = outbound.send(bundle) {
102-
tracing::error!(err = ?err, "Failed to send bundle - channel is dropped");
100+
error!(err = ?err, "Failed to send bundle - channel is dropped");
103101
}
104102
}
105103
}

src/tasks/metrics.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use crate::config::HostProvider;
22
use alloy::{primitives::TxHash, providers::Provider as _};
3-
use init4_bin_base::deps::metrics::{counter, histogram};
3+
use init4_bin_base::deps::{
4+
metrics::{counter, histogram},
5+
tracing::{debug, error},
6+
};
47
use std::time::Instant;
58
use tokio::{sync::mpsc, task::JoinHandle};
6-
use tracing::{debug, error};
79

810
/// Collects metrics on transactions sent by the Builder
911
#[derive(Debug, Clone)]
@@ -68,7 +70,7 @@ impl MetricsTask {
6870
debug!("logged tx metrics");
6971
});
7072
} else {
71-
tracing::debug!("upstream task gone");
73+
debug!("upstream task gone");
7274
break;
7375
}
7476
}

src/tasks/oauth.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Service responsible for authenticating with the cache with Oauth tokens.
22
//! This authenticator periodically fetches a new token every set amount of seconds.
33
use crate::config::BuilderConfig;
4+
use init4_bin_base::deps::tracing::{error, info};
45
use oauth2::{
56
AuthUrl, ClientId, ClientSecret, EmptyExtraTokenFields, StandardTokenResponse, TokenUrl,
67
basic::{BasicClient, BasicTokenType},
@@ -93,13 +94,13 @@ impl Authenticator {
9394

9495
let handle: JoinHandle<()> = tokio::spawn(async move {
9596
loop {
96-
tracing::info!("Refreshing oauth token");
97+
info!("Refreshing oauth token");
9798
match self.authenticate().await {
9899
Ok(_) => {
99-
tracing::info!("Successfully refreshed oauth token");
100+
info!("Successfully refreshed oauth token");
100101
}
101102
Err(e) => {
102-
tracing::error!(%e, "Failed to refresh oauth token");
103+
error!(%e, "Failed to refresh oauth token");
103104
}
104105
};
105106
let _sleep = tokio::time::sleep(tokio::time::Duration::from_secs(interval)).await;

0 commit comments

Comments
 (0)