Skip to content

Commit 04a611e

Browse files
committed
log -> tracing
1 parent 4f31297 commit 04a611e

File tree

12 files changed

+129
-134
lines changed

12 files changed

+129
-134
lines changed

.env.example

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
# Example configuration for Sepolia + Celestia Mocha.
22
TENDERMINT_RPC_URL=https://rpc.celestia-mocha.com/
3-
CHAIN_ID=11155111
4-
RPC_URL=https://ethereum-sepolia.publicnode.com/
5-
CONTRACT_ADDRESS=
3+
64
# Key for relaying to the contract.
75
PRIVATE_KEY=
86

9-
NETWORK_PRIVATE_KEY=
107
# Optional: Set if you're using a custom RPC URL.
11-
NETWORK_RPC_URL=
8+
NETWORK_RPC_URL=
9+
NETWORK_PRIVATE_KEY=
10+
11+
BLOCK_UPDATE_INTERVAL=
12+
LOOP_INTERVAL_MINS=
13+
14+
# Optional: Set if you're using the KMS relayer.
15+
SECURE_RELAYER_API_KEY=
16+
SECURE_RELAYER_ENDPOINT=
17+
USE_KMS_RELAYER=

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ pgo-data.profdata
1919
.idea
2020

2121
filtered_transactions/**.csv
22-
filtered_transactions
22+
filtered_transactions
23+
24+
chains.json

Cargo.lock

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

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ dotenv = "0.15.0"
2020
subtle-encoding = "0.5.1"
2121
anyhow = "1.0.82"
2222
clap = { version = "4.0", features = ["derive", "env"] }
23-
log = "0.4.21"
2423
hex = "0.4.3"
2524
futures = "0.3.30"
26-
env_logger = "0.11.3"
2725
serde_json = "1"
2826
chrono = "0.4.38"
2927
csv = "1.3.1"

script/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ dotenv = { workspace = true }
3939
subtle-encoding = { workspace = true }
4040
anyhow.workspace = true
4141
clap = { workspace = true }
42-
log = { workspace = true }
4342
hex = { workspace = true }
4443
futures = { workspace = true }
45-
env_logger = { workspace = true }
4644
serde_json = { workspace = true }
4745
chrono = { workspace = true }
4846
csv = { workspace = true }
4947
async-trait = "0.1.86"
48+
tracing = "0.1.41"
49+
tracing-subscriber = "0.3.19"
5050

5151
[build-dependencies]
5252
sp1-build = "4.0.0-rc.8"

script/bin/costs.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use clap::Parser;
1515
use futures::StreamExt;
1616
use reqwest::Url;
1717
use std::{cmp::Ordering, collections::HashMap, env, fs, str::FromStr};
18+
use tracing_subscriber::EnvFilter;
1819

1920
#[derive(Parser, Debug, Clone)]
2021
#[command(about = "Get transaction costs for an address in a given month")]
@@ -153,7 +154,11 @@ async fn get_receipts_for_chain(
153154
async fn main() -> Result<()> {
154155
env::set_var("RUST_LOG", "info");
155156
dotenv::dotenv().ok();
156-
env_logger::init();
157+
158+
// Setup tracing.
159+
tracing_subscriber::fmt::fmt()
160+
.with_env_filter(EnvFilter::from_default_env())
161+
.init();
157162

158163
let args = CostScriptArgs::parse();
159164

script/bin/genesis.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
//!
99
1010
use clap::Parser;
11-
use log::info;
1211
use sp1_blobstream_script::util::*;
1312
use sp1_blobstream_script::TendermintRPCClient;
1413
use sp1_sdk::{HashableKey, Prover, ProverClient};
1514
use std::env;
15+
use tracing::info;
16+
use tracing_subscriber::EnvFilter;
1617
const BLOBSTREAMX_ELF: &[u8] = include_bytes!("../../elf/blobstream-elf");
1718

1819
#[derive(Parser, Debug, Clone)]
@@ -26,7 +27,12 @@ pub struct GenesisArgs {
2627
pub async fn main() {
2728
env::set_var("RUST_LOG", "info");
2829
dotenv::dotenv().ok();
29-
env_logger::init();
30+
31+
// Setup tracing.
32+
tracing_subscriber::fmt::fmt()
33+
.with_env_filter(EnvFilter::from_default_env())
34+
.init();
35+
3036
let data_fetcher = TendermintRPCClient::default();
3137
let args = GenesisArgs::parse();
3238

script/bin/operator.rs

Lines changed: 30 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
use alloy::{
2-
consensus::SignableTransaction,
3-
network::{EthereumWallet, Network, ReceiptResponse, TxSigner},
2+
network::{EthereumWallet, Network, ReceiptResponse},
43
primitives::{Address, B256},
54
providers::{Provider, ProviderBuilder},
6-
signers::{local::PrivateKeySigner, Signer},
5+
signers::local::PrivateKeySigner,
76
sol,
87
transports::Transport,
98
};
109
use anyhow::Result;
11-
use log::{error, info};
1210
use sp1_blobstream_primitives::get_header_update_verdict;
1311
use sp1_blobstream_script::util::{
1412
fetch_input_for_blobstream_proof, find_block_to_request, get_latest_block_height,
@@ -22,8 +20,10 @@ use sp1_sdk::{
2220
use std::{env, sync::Arc};
2321
use std::{marker::PhantomData, time::Duration};
2422
use tendermint_light_client_verifier::Verdict;
23+
use tracing::{error, info, Instrument};
24+
use tracing_subscriber::EnvFilter;
2525

26-
use signer::MaybeSigner;
26+
use sp1_blobstream_script::util::signer::MaybeWallet;
2727

2828
sol! {
2929
#[allow(missing_docs)]
@@ -69,7 +69,6 @@ impl<P: Provider<T, N>, T: Transport + Clone, N: Network> SP1BlobstreamOperator<
6969
///
7070
/// # Panics
7171
/// - If the chain id cannot be retrieved from the provider.
72-
/// - If the signer is not provided and were not using the KMS relayer.
7372
pub async fn new(
7473
provider: P,
7574
contract_address: Address,
@@ -288,7 +287,7 @@ impl ChainConfig {
288287
///
289288
/// If neither are set, it will try to use [`Self::from_env`].
290289
fn fetch() -> Result<Vec<Self>> {
291-
const DEFAULT_PATH: &str = "../chains.json";
290+
const DEFAULT_PATH: &str = "chains.json";
292291

293292
let path = env::var("CHAINS_PATH").unwrap_or(DEFAULT_PATH.to_string());
294293

@@ -297,13 +296,16 @@ impl ChainConfig {
297296

298297
/// Tries to read from the `CHAINS` environment variable.
299298
fn from_env() -> Result<Vec<Self>> {
300-
let chains = env::var("CHAINS").expect("CHAINS not set.");
299+
let chains = env::var("CHAINS")?;
301300

302301
Ok(serde_json::from_str(&chains)?)
303302
}
304303

305304
fn from_file(path: &str) -> Result<Vec<Self>> {
306-
let file = std::fs::read_to_string(path)?;
305+
tracing::debug!("Reading chains from file: {}", path);
306+
307+
let file = std::fs::read_to_string(path)
308+
.inspect_err(|e| println!("Error reading file: {:?}", e))?;
307309

308310
Ok(serde_json::from_str(&file)?)
309311
}
@@ -312,29 +314,35 @@ impl ChainConfig {
312314
#[tokio::main]
313315
async fn main() {
314316
dotenv::dotenv().ok();
315-
env_logger::init();
316317

317-
let prover = ProverClient::builder().cpu().build();
318-
let (pk, vk) = prover.setup(TENDERMINT_ELF);
319-
let pk = Arc::new(pk);
318+
// Setup tracing.
319+
tracing_subscriber::fmt::fmt()
320+
.with_env_filter(EnvFilter::from_default_env())
321+
.init();
320322

321323
// Succinct deployments use the `CHAINS` environment variable.
322-
let config = ChainConfig::from_env().expect("Failed to fetch chain config.");
324+
let config = ChainConfig::fetch().expect("Failed to fetch chain config");
323325
let maybe_private_key: Option<PrivateKeySigner> = env::var("PRIVATE_KEY")
324326
.ok()
325327
.map(|s| s.parse().expect("Failed to parse PRIVATE_KEY"));
326328

329+
// Setup the KMS relayer config.
327330
let use_kms_relayer: bool = env::var("USE_KMS_RELAYER")
328331
.map(|s| s.parse().expect("USE_KMS_RELAYER failed to parse"))
329-
.expect("USE_KMS_RELAYER not set.");
332+
.expect("USE_KMS_RELAYER not set");
330333

331334
// Ensure we have a signer if we're not using the KMS relayer.
332335
if !use_kms_relayer && maybe_private_key.is_none() {
333336
panic!("PRIVATE_KEY is not set but USE_KMS_RELAYER is false.");
334337
}
335338

336339
// Setup our signer.
337-
let signer = EthereumWallet::new(MaybeSigner::new(maybe_private_key));
340+
let signer = MaybeWallet::new(maybe_private_key.map(EthereumWallet::new));
341+
342+
// Setup the prover and program keys.
343+
let prover = ProverClient::builder().cpu().build();
344+
let (pk, vk) = prover.setup(TENDERMINT_ELF);
345+
let pk = Arc::new(pk);
338346

339347
// Setup all the tasks.
340348
// These futures should never resolve, so we just await them in the main thread.
@@ -348,6 +356,8 @@ async fn main() {
348356
let vk = vk.clone();
349357

350358
tokio::task::spawn(async move {
359+
tracing::info!("Starting operator for chain {}", c.name);
360+
351361
let operator = SP1BlobstreamOperator::new(
352362
provider,
353363
c.blobstream_address,
@@ -359,12 +369,13 @@ async fn main() {
359369

360370
loop {
361371
let request_interval_mins = get_loop_interval_mins();
372+
362373
tokio::select! {
363374
_ = tokio::time::sleep(tokio::time::Duration::from_secs(60 * LOOP_TIMEOUT_MINS)) => {
364-
log::error!("Operator took longer than {} minutes to run.", LOOP_TIMEOUT_MINS);
375+
tracing::error!("Operator took longer than {} minutes to run.", LOOP_TIMEOUT_MINS);
365376
continue;
366377
}
367-
e = operator.run() => {
378+
e = operator.run().instrument(tracing::span!(tracing::Level::INFO, "operator", chain = c.name)) => {
368379
if let Err(e) = e {
369380
// Sleep for less time on errors.
370381
error!("Error running operator: {:?}", e);
@@ -383,50 +394,5 @@ async fn main() {
383394
// Run all the tasks.
384395
futures::future::try_join_all(handles).await.unwrap();
385396

386-
error!("All operators finished.");
387-
}
388-
389-
mod signer {
390-
use alloy::{consensus::SignableTransaction, network::TxSigner, primitives::Address};
391-
use std::marker::PhantomData;
392-
393-
/// A signer than panics if called and not set.
394-
pub struct MaybeSigner<Sig, S> {
395-
signer: Option<S>,
396-
_phantom: PhantomData<Sig>,
397-
}
398-
399-
impl<Sig, S> MaybeSigner<Sig, S> {
400-
pub fn new(signer: Option<S>) -> Self {
401-
Self {
402-
signer,
403-
_phantom: PhantomData,
404-
}
405-
}
406-
}
407-
408-
#[async_trait::async_trait]
409-
impl<Sig, S> TxSigner<Sig> for MaybeSigner<Sig, S>
410-
where
411-
S: TxSigner<Sig> + Send + Sync,
412-
Sig: Send + Sync,
413-
{
414-
fn address(&self) -> Address {
415-
self.signer
416-
.as_ref()
417-
.expect("Signer should be set")
418-
.address()
419-
}
420-
421-
async fn sign_transaction(
422-
&self,
423-
tx: &mut dyn SignableTransaction<Sig>,
424-
) -> alloy::signers::Result<Sig> {
425-
self.signer
426-
.as_ref()
427-
.expect("Signer should be set")
428-
.sign_transaction(tx)
429-
.await
430-
}
431-
}
397+
info!("All operators finished.");
432398
}

script/bin/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use clap::Parser;
2-
use log::debug;
32
use sp1_blobstream_script::util::fetch_input_for_blobstream_proof;
43
use sp1_blobstream_script::{TendermintRPCClient, TENDERMINT_ELF};
54
use sp1_sdk::{ProverClient, SP1Stdin};
65
use tokio::runtime;
6+
use tracing::debug;
77

88
#[derive(Parser, Debug)]
99
#[clap(author, version, about, long_about = None)]

script/src/relay.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use alloy::primitives::B256;
22
use anyhow::Result;
3-
use log::info;
43
use serde::{Deserialize, Serialize};
54
use std::{env, str::FromStr, time::Duration};
5+
use tracing::info;
66

77
#[derive(Serialize, Deserialize)]
88
pub enum KMSRelayStatus {
@@ -48,7 +48,7 @@ pub async fn relay_with_kms(args: &KMSRelayRequest, num_retries: u32) -> Result<
4848
let error_message = response
4949
.message
5050
.expect("KMS request always returns a message");
51-
log::warn!("KMS relay attempt {} failed: {}", attempt, error_message);
51+
tracing::warn!("KMS relay attempt {} failed: {}", attempt, error_message);
5252
if attempt == num_retries {
5353
return Err(anyhow::anyhow!(
5454
"Failed to relay transaction: {}",

0 commit comments

Comments
 (0)