Skip to content

Commit

Permalink
chore: fix for better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
fakedev9999 committed Feb 4, 2025
1 parent 1d373f2 commit 7b32736
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 41 deletions.
56 changes: 28 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 20 additions & 11 deletions fault_proof/bin/proposer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use fault_proof::{
DisputeGameFactory, DisputeGameFactory::DisputeGameFactoryInstance, GameStatus,
OPSuccinctFaultDisputeGame, ProposalStatus,
},
utils::setup_logging,
FactoryTrait, L1Provider, L1ProviderWithWallet, L2Provider, L2ProviderTrait,
};

Expand Down Expand Up @@ -81,7 +82,15 @@ where
.get_receipt()
.await?;

tracing::info!("New game created at tx: {:?}", receipt.transaction_hash);
let game_address = receipt.inner.logs()[0].address();

tracing::info!(
"New game \x1B]8;;https://sepolia.etherscan.io/address/{:?}\x07{:?}\x1B]8;;\x07 created: \x1B]8;;https://sepolia.etherscan.io/tx/{:?}\x07{:?}\x1B]8;;\x07",
game_address,
game_address,
receipt.transaction_hash,
receipt.transaction_hash
);

Ok(())
}
Expand Down Expand Up @@ -218,13 +227,15 @@ where
loop {
interval.tick().await;

let _span = tracing::info_span!("[[Proposing]]").entered();

let safe_l2_head_block_number = self
.l2_provider
.get_l2_block_by_number(BlockNumberOrTag::Safe)
.await?
.header
.number;
tracing::info!("Safe L2 head block number: {:?}", safe_l2_head_block_number);
tracing::debug!("Safe L2 head block number: {:?}", safe_l2_head_block_number);

let latest_valid_proposal = self
.factory
Expand Down Expand Up @@ -261,27 +272,25 @@ where
.await?;
}

drop(_span);

// Only attempt game resolution if enabled
if self.config.enable_game_resolution {
let _span = tracing::info_span!("[[Resolving]]").entered();

if let Err(e) = self.resolve_unchallenged_games().await {
tracing::warn!("Failed to resolve unchallenged games: {:?}", e);
}

drop(_span);
}
}
}
}

#[tokio::main]
async fn main() {
// Initialize logging using RUST_LOG environment variable, defaulting to INFO level
tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::try_from_env("RUST_LOG").unwrap_or_else(|_| {
tracing_subscriber::EnvFilter::from_default_env()
.add_directive(tracing::Level::INFO.into())
}),
)
.init();
setup_logging();

dotenv::from_filename(".env.proposer").ok();

Expand Down
9 changes: 7 additions & 2 deletions fault_proof/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod config;
pub mod sol;
pub mod utils;

use alloy::{
eips::BlockNumberOrTag,
Expand Down Expand Up @@ -165,7 +166,11 @@ where
let game_address = self.fetch_game_address_by_index(game_index).await?;
let game = OPSuccinctFaultDisputeGame::new(game_address, l1_provider.clone());
block_number = game.l2BlockNumber().call().await?.l2BlockNumber_;
tracing::info!("Checking if proposal for block {:?} is valid", block_number);
tracing::debug!(
"Checking if game {:?} at block {:?} is valid",
game_address,
block_number
);
let game_claim = game.rootClaim().call().await?.rootClaim_;

let output_root = l2_provider
Expand All @@ -183,7 +188,7 @@ where

// If we've reached index 0 and still haven't found a valid proposal
if game_index == U256::ZERO {
tracing::warn!("No valid proposals found after checking all games");
tracing::info!("No valid proposals found after checking all games");
return Ok(None);
}

Expand Down
21 changes: 21 additions & 0 deletions fault_proof/src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use tracing_subscriber::{fmt, EnvFilter};

// In your main function or setup:
pub fn setup_logging() {
let format = fmt::format()
.with_level(true)
.with_target(false)
.with_thread_ids(false)
.with_thread_names(false)
.with_file(false)
.with_line_number(false)
.with_ansi(true);

// Initialize logging using RUST_LOG environment variable, defaulting to INFO level
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::try_from_env("RUST_LOG").unwrap_or_else(|_| {
EnvFilter::from_default_env().add_directive(tracing::Level::INFO.into())
}))
.event_format(format)
.init();
}

0 comments on commit 7b32736

Please sign in to comment.