Skip to content

fix: use new sdk #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 8, 2025
Merged
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
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ hex = { package = "const-hex", version = "1", default-features = false, features
] }

serde = { version = "1.0.197", features = ["derive"] }
tracing = "0.1.40"

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

async-trait = "0.1.80"
oauth2 = "4.4.2"
tracing-subscriber = "0.3.19"
chrono = "0.4.41"
3 changes: 2 additions & 1 deletion bin/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use builder::{
};
use init4_bin_base::{deps::tracing, utils::from_env::FromEnv};
use signet_sim::SimCache;
use signet_types::constants::SignetSystemConstants;
use std::sync::Arc;
use tokio::select;
use tracing::info_span;
Expand All @@ -20,7 +21,7 @@ async fn main() -> eyre::Result<()> {
let init_span_guard = info_span!("builder initialization");

let config = BuilderConfig::from_env()?.clone();
let constants = config.load_pecorino_constants();
let constants = SignetSystemConstants::pecorino();
let authenticator = Authenticator::new(&config)?;

let (host_provider, sequencer_signer) =
Expand Down
10 changes: 6 additions & 4 deletions bin/submit_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use alloy::{
};
use builder::config::HostProvider;
use init4_bin_base::{
deps::metrics::{counter, histogram},
deps::{
metrics::{counter, histogram},
tracing,
},
init4,
utils::from_env::FromEnv,
};
Expand Down Expand Up @@ -45,11 +48,10 @@ impl Config {

#[tokio::main]
async fn main() {
init4();

tracing::trace!("connecting to provider");
let _guard = init4();

let config = Config::from_env().unwrap();
tracing::trace!("connecting to provider");
let provider = config.provider().await;
let recipient_address = config.recipient_address;
let sleep_time = config.sleep_time;
Expand Down
32 changes: 1 addition & 31 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
constants,
signer::{LocalOrAws, SignerError},
};
use crate::signer::{LocalOrAws, SignerError};
use alloy::{
network::{Ethereum, EthereumWallet},
primitives::Address,
Expand All @@ -16,7 +13,6 @@ use alloy::{
use eyre::Result;
use init4_bin_base::utils::{calc::SlotCalculator, from_env::FromEnv};
use oauth2::url;
use signet_types::config::{HostConfig, PredeployTokens, RollupConfig, SignetSystemConstants};
use signet_zenith::Zenith;
use std::borrow::Cow;

Expand Down Expand Up @@ -210,30 +206,4 @@ impl BuilderConfig {
pub const fn connect_zenith(&self, provider: HostProvider) -> ZenithInstance {
Zenith::new(self.zenith_address, provider)
}

/// Loads the Signet system constants for Pecorino.
pub const fn load_pecorino_constants(&self) -> SignetSystemConstants {
let host = HostConfig::new(
self.host_chain_id,
constants::PECORINO_DEPLOY_HEIGHT,
self.zenith_address,
constants::HOST_ORDERS,
constants::HOST_PASSAGE,
constants::HOST_TRANSACTOR,
PredeployTokens::new(constants::HOST_USDC, constants::HOST_USDT, constants::HOST_WBTC),
);
let rollup = RollupConfig::new(
self.ru_chain_id,
constants::ROLLUP_ORDERS,
constants::ROLLUP_PASSAGE,
constants::BASE_FEE_RECIPIENT,
PredeployTokens::new(
constants::ROLLUP_USDC,
constants::ROLLUP_USDT,
constants::ROLLUP_WBTC,
),
);

SignetSystemConstants::new(host, rollup)
}
}
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ pub mod test_utils;

// Anonymous import suppresses warnings about unused imports.
use openssl as _;
use tracing_subscriber as _;
5 changes: 3 additions & 2 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use axum::{
response::{IntoResponse, Response},
routing::get,
};
use init4_bin_base::deps::tracing::error;
use std::net::SocketAddr;

/// Return a 404 Not Found response
Expand All @@ -25,11 +26,11 @@ pub fn serve_builder(socket: impl Into<SocketAddr>) -> tokio::task::JoinHandle<(
match tokio::net::TcpListener::bind(&addr).await {
Ok(listener) => {
if let Err(err) = axum::serve(listener, router).await {
tracing::error!(%err, "serve failed");
error!(%err, "serve failed");
}
}
Err(err) => {
tracing::error!(%err, "failed to bind to the address");
error!(%err, "failed to bind to the address");
}
};
})
Expand Down
51 changes: 27 additions & 24 deletions src/tasks/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ use alloy::{
};
use chrono::{DateTime, Utc};
use eyre::Report;
use init4_bin_base::utils::calc::SlotCalculator;
use init4_bin_base::{
deps::tracing::{debug, error, info, warn},
utils::calc::SlotCalculator,
};
use signet_sim::{BlockBuild, BuiltBlock, SimCache};
use signet_types::config::SignetSystemConstants;
use signet_types::constants::SignetSystemConstants;
use std::{
sync::{
Arc,
Expand Down Expand Up @@ -118,7 +121,7 @@ impl Simulator {
);

let block = block_build.build().await;
tracing::debug!(block = ?block, "finished block simulation");
debug!(block = ?block, "finished block simulation");

Ok(block)
}
Expand All @@ -142,7 +145,7 @@ impl Simulator {
bundle_receiver: mpsc::UnboundedReceiver<Bundle>,
cache: SimCache,
) -> (JoinHandle<()>, JoinHandle<()>) {
tracing::debug!("starting up cache handler");
debug!("starting up cache handler");

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

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

if let Ok(Some(block)) = resp {
let basefee = block.header.base_fee_per_gas.unwrap_or(0);
price.store(basefee, Ordering::Relaxed);
tracing::debug!(basefee = basefee, "basefee updated");
debug!(basefee = basefee, "basefee updated");
} else {
tracing::warn!("get basefee failed - an error likely occurred");
warn!("get basefee failed - an error likely occurred");
}
}

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

tokio::spawn(async move { self.run_simulator(constants, cache, submit_sender).await })
}
Expand Down Expand Up @@ -261,19 +264,19 @@ impl Simulator {
let block_env = match self.next_block_env(finish_by).await {
Ok(block) => block,
Err(err) => {
tracing::error!(err = %err, "failed to configure next block");
error!(err = %err, "failed to configure next block");
break;
}
};
tracing::info!(block_env = ?block_env, "created block");
info!(block_env = ?block_env, "created block");

match self.handle_build(constants, sim_cache, finish_by, block_env).await {
Ok(block) => {
tracing::debug!(block = ?block, "built block");
debug!(block = ?block, "built block");
let _ = submit_sender.send(block);
}
Err(e) => {
tracing::error!(err = %e, "failed to build block");
error!(err = %e, "failed to build block");
continue;
}
}
Expand Down Expand Up @@ -306,7 +309,7 @@ impl Simulator {
let latest = match self.ru_provider.get_block_number().await {
Ok(block_number) => block_number,
Err(e) => {
tracing::error!(error = %e, "failed to get latest block number");
error!(error = %e, "failed to get latest block number");
return None;
}
};
Expand Down Expand Up @@ -336,27 +339,27 @@ impl Simulator {
let remaining = finish_by.duration_since(Instant::now());
let finish_time = SystemTime::now() + remaining;
let deadline: DateTime<Utc> = finish_time.into();
tracing::debug!(deadline = %deadline, "preparing block env");
debug!(deadline = %deadline, "preparing block env");

// Fetch the latest block number and increment it by 1
let latest_block_number = match self.ru_provider.get_block_number().await {
Ok(num) => num,
Err(err) => {
tracing::error!(error = %err, "RPC error during block build");
error!(error = %err, "RPC error during block build");
return Err(SimulatorError::Rpc(Report::new(err)));
}
};
tracing::debug!(next_block_num = latest_block_number + 1, "preparing block env");
debug!(next_block_num = latest_block_number + 1, "preparing block env");

// Fetch the basefee from previous block to calculate gas for this block
let basefee = match self.get_basefee().await? {
Some(basefee) => basefee,
None => {
tracing::warn!("get basefee failed - RPC error likely occurred");
warn!("get basefee failed - RPC error likely occurred");
BASEFEE_DEFAULT
}
};
tracing::debug!(basefee = basefee, "setting basefee");
debug!(basefee = basefee, "setting basefee");

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

Ok(block_env)
}
Expand All @@ -380,7 +383,7 @@ impl Simulator {
match self.ru_provider.get_block_by_number(Latest).await {
Ok(maybe_block) => match maybe_block {
Some(block) => {
tracing::debug!(basefee = ?block.header.base_fee_per_gas, "basefee found");
debug!(basefee = ?block.header.base_fee_per_gas, "basefee found");
Ok(block.header.base_fee_per_gas)
}
None => Ok(None),
Expand Down Expand Up @@ -414,13 +417,13 @@ async fn cache_updater(
select! {
maybe_tx = tx_receiver.recv() => {
if let Some(tx) = maybe_tx {
tracing::debug!(tx = ?tx.hash(), "received transaction");
debug!(tx = ?tx.hash(), "received transaction");
cache.add_item(tx, p);
}
}
maybe_bundle = bundle_receiver.recv() => {
if let Some(bundle) = maybe_bundle {
tracing::debug!(bundle = ?bundle.id, "received bundle");
debug!(bundle = ?bundle.id, "received bundle");
cache.add_item(bundle.bundle, p);
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/tasks/bundler.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
//! Bundler service responsible for fetching bundles and sending them to the simulator.
use crate::tasks::oauth::SharedToken;
use crate::{config::BuilderConfig, tasks::oauth::SharedToken};
use init4_bin_base::deps::tracing::{Instrument, debug, debug_span, error, trace, warn};
use oauth2::TokenResponse;
use reqwest::{Client, Url};
use serde::{Deserialize, Serialize};
use signet_bundle::SignetEthBundle;
use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender, unbounded_channel};
use tokio::task::JoinHandle;
use tokio::time;
use tracing::{Instrument, debug, trace, warn};

pub use crate::config::BuilderConfig;

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

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

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

match self.check_bundle_cache().instrument(span.clone()).await {
Ok(bundles) => {
tracing::debug!(count = ?bundles.len(), "found bundles");
debug!(count = ?bundles.len(), "found bundles");
for bundle in bundles.into_iter() {
if let Err(err) = outbound.send(bundle) {
tracing::error!(err = ?err, "Failed to send bundle - channel is dropped");
error!(err = ?err, "Failed to send bundle - channel is dropped");
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/tasks/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use crate::config::HostProvider;
use alloy::{primitives::TxHash, providers::Provider as _};
use init4_bin_base::deps::metrics::{counter, histogram};
use init4_bin_base::deps::{
metrics::{counter, histogram},
tracing::{debug, error},
};
use std::time::Instant;
use tokio::{sync::mpsc, task::JoinHandle};
use tracing::{debug, error};

/// Collects metrics on transactions sent by the Builder
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -68,7 +70,7 @@ impl MetricsTask {
debug!("logged tx metrics");
});
} else {
tracing::debug!("upstream task gone");
debug!("upstream task gone");
break;
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/tasks/oauth.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Service responsible for authenticating with the cache with Oauth tokens.
//! This authenticator periodically fetches a new token every set amount of seconds.
use crate::config::BuilderConfig;
use init4_bin_base::deps::tracing::{error, info};
use oauth2::{
AuthUrl, ClientId, ClientSecret, EmptyExtraTokenFields, StandardTokenResponse, TokenUrl,
basic::{BasicClient, BasicTokenType},
Expand Down Expand Up @@ -93,13 +94,13 @@ impl Authenticator {

let handle: JoinHandle<()> = tokio::spawn(async move {
loop {
tracing::info!("Refreshing oauth token");
info!("Refreshing oauth token");
match self.authenticate().await {
Ok(_) => {
tracing::info!("Successfully refreshed oauth token");
info!("Successfully refreshed oauth token");
}
Err(e) => {
tracing::error!(%e, "Failed to refresh oauth token");
error!(%e, "Failed to refresh oauth token");
}
};
let _sleep = tokio::time::sleep(tokio::time::Duration::from_secs(interval)).await;
Expand Down
Loading