Skip to content

Commit cae4263

Browse files
apollo_batcher: improve transaction execution result logging (#9864)
1 parent 5cd17f3 commit cae4263

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

crates/apollo_batcher/src/batcher.rs

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::collections::HashMap;
2+
use std::fmt::Write;
23
use std::sync::Arc;
34

45
use apollo_batcher_config::config::BatcherConfig;
@@ -924,25 +925,36 @@ fn log_txs_execution_result(
924925
proposal_id: ProposalId,
925926
result: &Result<BlockExecutionArtifacts, Arc<BlockBuilderError>>,
926927
) {
927-
// Constructing log message.
928928
if let Ok(block_artifacts) = result {
929-
let mut log_msg = format!(
929+
let execution_infos = &block_artifacts.execution_data.execution_infos;
930+
let rejected_hashes = &block_artifacts.execution_data.rejected_tx_hashes;
931+
932+
// Estimate capacity: base message + (hash + status) per transaction
933+
// TransactionHash is 66 chars (0x + 64 hex), status is ~12 chars, separator is 4 chars
934+
// Total per transaction: ~82 chars
935+
const CHARS_PER_TX: usize = 82;
936+
const BASE_CAPACITY: usize = 80; // Base message length
937+
let total_txs = execution_infos.len() + rejected_hashes.len();
938+
let estimated_capacity = BASE_CAPACITY + total_txs * CHARS_PER_TX;
939+
940+
let mut log_msg = String::with_capacity(estimated_capacity);
941+
let _ = write!(
942+
&mut log_msg,
930943
"Finished generating proposal {} with {} transactions",
931944
proposal_id,
932-
block_artifacts.execution_data.execution_infos.len(),
945+
execution_infos.len(),
933946
);
934-
block_artifacts.execution_data.execution_infos.iter().for_each(|(tx_hash, info)| {
935-
log_msg.push_str(&format!(", {tx_hash}:"));
936-
if info.revert_error.is_some() {
937-
log_msg.push_str(" Reverted");
938-
} else {
939-
log_msg.push_str(" Successful");
940-
}
941-
});
942-
block_artifacts.execution_data.rejected_tx_hashes.iter().for_each(|tx_hash| {
943-
log_msg.push_str(&format!(", {tx_hash}: Rejected"));
944-
});
945-
info!(log_msg);
947+
948+
for (tx_hash, info) in execution_infos {
949+
let status = if info.revert_error.is_some() { "Reverted" } else { "Successful" };
950+
let _ = write!(&mut log_msg, ", {tx_hash}: {status}");
951+
}
952+
953+
for tx_hash in rejected_hashes {
954+
let _ = write!(&mut log_msg, ", {tx_hash}: Rejected");
955+
}
956+
957+
info!("{}", log_msg);
946958
}
947959
}
948960

0 commit comments

Comments
 (0)