Skip to content

Commit

Permalink
chore: fix tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
t00ts committed Sep 25, 2024
1 parent 32f49df commit 6959268
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 45 deletions.
30 changes: 17 additions & 13 deletions crates/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,11 @@ impl EthereumApi for EthereumClient {
let mut logs = Vec::new();
get_logs_recursive(&provider, &filter, from_block, to_block, &mut logs, 10_000).await?;

tracing::debug!(
"Fetched {} `L1ToL2MessageLog` logs from {} to {}",
logs.len(),
from_block,
to_block
tracing::trace!(
number_of_logs=%logs.len(),
%from_block,
%to_block,
"Fetched L1ToL2MessageLog logs"
);

let logs: Vec<L1ToL2MessageLog> = logs
Expand Down Expand Up @@ -447,7 +447,7 @@ fn get_logs_recursive<'a>(
logs.extend(new_logs);
}
Err(e) => {
tracing::debug!("Get logs error at block {}: {}", from_block, e);
tracing::debug!(%from_block, error=?e, "Get logs error at block");
if let Some(err) = e.as_error_resp() {
// Retry the request splitting the block range in half
//
Expand All @@ -457,9 +457,9 @@ fn get_logs_recursive<'a>(
// range is the best we can do.
if err.is_retry_err() {
tracing::debug!(
"Retrying request (splitting) at block {}: {}",
from_block,
err
%from_block,
error=?err,
"Retrying request (splitting) at block"
);
let mid_block = from_block + block_range / 2;
get_logs_recursive(
Expand All @@ -483,13 +483,17 @@ fn get_logs_recursive<'a>(
return Ok(());
} else {
tracing::error!(
"get_logs: Provider error at block {}: {}",
from_block,
err
%from_block,
error=?err,
"get_logs provider error"
);
}
} else {
tracing::error!("get_logs: Unknown error at block {}: {}", from_block, e);
tracing::error!(
%from_block,
error=?e,
"get_logs: Unknown error"
);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/pathfinder/src/state/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,14 +719,14 @@ async fn consumer(
}
}
L1ToL2Message(msg) => {
tracing::debug!("Got an L1ToL2Message: {:?}", msg.message_hash);
tracing::trace!(message_hash=%msg.message_hash, "Got an L1ToL2Message");
tokio::task::block_in_place(|| {
// Note: There's always an L1 tx hash and block number (hence the `expect`)
let l1_tx_hash = msg.l1_tx_hash.expect("missing l1 tx hash");
let l1_block_number = msg.l1_block_number.expect("missing l1 block number");

let tx = db_conn
.transaction()
.transaction_with_behavior(TransactionBehavior::Immediate)
.context("Creating database transaction")?;

// If we have an L2 tx hash for this message, we can associate the L1 handler tx
Expand All @@ -736,13 +736,13 @@ async fn consumer(
..
}) = tx.fetch_l1_to_l2_message_log(&msg.message_hash)?
{
tracing::debug!("Found L2 tx for L1 Tx {:?}", l1_tx_hash);
tracing::trace!(%l1_tx_hash, %l2_tx_hash, "Found L2 tx for L1 tx");
tx.insert_l1_handler_tx(l1_block_number, l1_tx_hash, l2_tx_hash)?;
tx.remove_l1_to_l2_message_log(&msg.message_hash)?;
}
// Otherwise, we insert the message log with an empty L2 tx hash
else {
tracing::debug!("L2 tx NOT found for L1 Tx {:?}", l1_tx_hash);
tracing::trace!(%l1_tx_hash, "L2 tx NOT found for L1 tx");
let msg_log = L1ToL2MessageLog {
message_hash: msg.message_hash,
l1_block_number: Some(l1_block_number),
Expand Down
10 changes: 5 additions & 5 deletions crates/pathfinder/src/state/sync/l1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ where
)
.await?;

tracing::debug!(
"Fetched {} L1 to L2 new message logs from {} to {}",
logs.len(),
last_synced_l1_handler_block,
state_update.block_number
tracing::trace!(
number_of_logs=%logs.len(),
from_block=%last_synced_l1_handler_block,
to_block=?state_update.l1_block_number.unwrap(),
"Fetched L1 to L2 message logs",
);

for log in logs {
Expand Down
23 changes: 9 additions & 14 deletions crates/storage/src/connection/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ impl Transaction<'_> {

if let Some(l2_tx_hash) = &message.l2_tx_hash {
tracing::debug!(
"Inserted L1 to L2 message log with L2 tx hash: {:?}",
l2_tx_hash
%l2_tx_hash,
"Inserted L1 to L2 message log with L2 tx hash"
);
} else if let Some(l1_tx_hash) = &message.l1_tx_hash {
tracing::debug!(
"Inserted L1 to L2 message log with L1 tx hash: {:?}",
l1_tx_hash
%l1_tx_hash,
"Inserted L1 to L2 message log with L1 tx hash"
);
}

Expand Down Expand Up @@ -62,17 +62,12 @@ impl Transaction<'_> {
.context("Querying L1 to L2 message log")?;

if let Some(data) = raw_data {
let debug_tx_str = match (&data.1, &data.2) {
(Some(_), None) => "[L1, X]",
(None, Some(_)) => "[X, L2]",
_ => "N/A",
};
tracing::debug!(
"Fetched (and found: {}) an L1 to L2 message log for {:?}",
debug_tx_str,
message_hash
tracing::trace!(
%message_hash,
l1_tx_hash=?data.1,
l2_tx_hash=?data.2,
"Fetched an L1 to L2 message log"
);

Ok(Some(L1ToL2MessageLog {
message_hash: *message_hash,
l1_block_number: data.0,
Expand Down
18 changes: 9 additions & 9 deletions crates/storage/src/connection/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ impl Transaction<'_> {
// transactions to satisfy `starknet_getMessagesStatus`
for (transaction, _) in transactions.iter() {
if let TransactionVariant::L1Handler(l1_handler_tx) = &transaction.variant {
tracing::debug!(
"Found an l1_handler variant while inserting transaction {:?}",
transaction.hash
tracing::trace!(
transaction_hash=%transaction.hash,
"Found an l1_handler variant while inserting transaction"
);

// Fetch the L1 to L2 message log for this transaction
Expand All @@ -202,7 +202,7 @@ impl Transaction<'_> {
}
}
// Otherwise, we insert the message log with an empty L1 tx hash
tracing::trace!("L1 tx not found for L2 Tx {:?}", transaction.hash);
tracing::trace!(transaction_hash=%transaction.hash, "L1 tx not found for L2 tx");
let msg_log = L1ToL2MessageLog {
message_hash: msg_hash,
l1_block_number: None,
Expand Down Expand Up @@ -237,11 +237,11 @@ impl Transaction<'_> {
":l2_tx_hash": &l2_tx_hash,
])?;

tracing::debug!(
"Saved l1_handler_tx: [{}] {:?} <-> {:?}",
l1_block_number,
l1_tx_hash,
l2_tx_hash
tracing::trace!(
%l1_block_number,
%l1_tx_hash,
%l2_tx_hash,
"Saved l1_handler_tx"
);

Ok(())
Expand Down

0 comments on commit 6959268

Please sign in to comment.