Skip to content

Commit ab02cb1

Browse files
committed
add time logs
1 parent e0a8b67 commit ab02cb1

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

crates/batcher/src/lib.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ impl Batcher {
794794
client_msg: Box<SubmitProofMessage>,
795795
ws_conn_sink: WsMessageSink,
796796
) -> Result<(), Error> {
797+
let start_time = std::time::Instant::now();
797798
let msg_nonce = client_msg.verification_data.nonce;
798799
debug!("Received message with nonce: {msg_nonce:?}");
799800
self.metrics.received_proofs.inc();
@@ -820,6 +821,8 @@ impl Batcher {
820821
// All check functions sends the error to the metrics server and logs it
821822
// if they return false
822823

824+
let validation_start = std::time::Instant::now();
825+
823826
if !self.msg_chain_id_is_valid(&client_msg, &ws_conn_sink).await {
824827
return Ok(());
825828
}
@@ -844,6 +847,8 @@ impl Batcher {
844847
else {
845848
return Ok(());
846849
};
850+
851+
warn!("Message validations completed for {:?} in {:?}", addr_in_msg, validation_start.elapsed());
847852

848853
let addr;
849854
let signature = client_msg.signature;
@@ -870,6 +875,7 @@ impl Batcher {
870875
}
871876

872877
info!("Handling message, locking user state");
878+
let user_state_start = std::time::Instant::now();
873879

874880
// We acquire the lock first only to query if the user is already present and the lock is dropped.
875881
// If it was not present, then the user nonce is queried to the Aligned contract.
@@ -905,9 +911,12 @@ impl Batcher {
905911
send_message(ws_conn_sink.clone(), SubmitProofResponseMessage::ServerBusy).await;
906912
return Ok(());
907913
};
914+
915+
warn!("User lock acquired for {:?} in {:?}", addr, user_state_start.elapsed());
908916

909917
// If the user state was not present, we need to get the nonce from the Ethereum contract and update the dummy user state
910918
if !is_user_in_state {
919+
let nonce_fetch_start = std::time::Instant::now();
911920
let ethereum_user_nonce = match self.get_user_nonce_from_ethereum(addr).await {
912921
Ok(ethereum_user_nonce) => ethereum_user_nonce,
913922
Err(e) => {
@@ -923,6 +932,7 @@ impl Batcher {
923932
return Ok(());
924933
}
925934
};
935+
warn!("Ethereum nonce fetched for {:?} in {:?}", addr, nonce_fetch_start.elapsed());
926936
// Update the dummy user state with the correct nonce
927937
user_state_guard.nonce = ethereum_user_nonce;
928938
}
@@ -931,6 +941,7 @@ impl Batcher {
931941
// * Perform validations over user state *
932942
// * ---------------------------------------------------*
933943

944+
let balance_validation_start = std::time::Instant::now();
934945
let Some(user_balance) = self.get_user_balance(&addr).await else {
935946
error!("Could not get balance for address {addr:?}");
936947
send_message(
@@ -1001,7 +1012,10 @@ impl Batcher {
10011012
self.metrics.user_error(&["invalid_max_fee", ""]);
10021013
return Ok(());
10031014
}
1015+
1016+
warn!("Balance and nonce validations completed for {:?} in {:?}", addr, balance_validation_start.elapsed());
10041017

1018+
let proof_verification_start = std::time::Instant::now();
10051019
if !self
10061020
.verify_proof_if_enabled(
10071021
&nonced_verification_data.verification_data,
@@ -1011,11 +1025,13 @@ impl Batcher {
10111025
{
10121026
return Ok(());
10131027
}
1028+
warn!("Proof verification completed for {:?} in {:?}", addr, proof_verification_start.elapsed());
10141029

10151030
// * ---------------------------------------------------------------------*
10161031
// * Perform validation over batcher queue *
10171032
// * ---------------------------------------------------------------------*
10181033

1034+
let queue_management_start = std::time::Instant::now();
10191035
let Some(mut batch_state_lock) = self
10201036
.try_batch_lock_with_timeout(self.batch_state.lock())
10211037
.await
@@ -1119,11 +1135,14 @@ impl Batcher {
11191135
return Ok(());
11201136
}
11211137
}
1138+
1139+
warn!("Queue management and eviction logic completed for {:?} in {:?}", addr, queue_management_start.elapsed());
11221140

11231141
// * ---------------------------------------------------------------------*
11241142
// * Add message data into the queue and update user state *
11251143
// * ---------------------------------------------------------------------*
11261144

1145+
let add_to_batch_start = std::time::Instant::now();
11271146
if let Err(e) = self
11281147
.add_to_batch(
11291148
batch_state_lock,
@@ -1147,8 +1166,10 @@ impl Batcher {
11471166
user_state_guard.last_max_fee_limit = max_fee;
11481167
user_state_guard.proofs_in_batch += 1;
11491168
user_state_guard.total_fees_in_queue += max_fee;
1169+
1170+
warn!("Add to batch and user state update completed for {:?} in {:?}", addr, add_to_batch_start.elapsed());
11501171

1151-
info!("Verification data message handled");
1172+
warn!("Verification data message handled for {:?} - total time: {:?}", addr, start_time.elapsed());
11521173
Ok(())
11531174
}
11541175

0 commit comments

Comments
 (0)