|
1 | 1 | use std::collections::HashMap; |
| 2 | +use std::fmt::Write; |
2 | 3 | use std::sync::Arc; |
3 | 4 |
|
4 | 5 | use apollo_batcher_config::config::BatcherConfig; |
@@ -924,25 +925,36 @@ fn log_txs_execution_result( |
924 | 925 | proposal_id: ProposalId, |
925 | 926 | result: &Result<BlockExecutionArtifacts, Arc<BlockBuilderError>>, |
926 | 927 | ) { |
927 | | - // Constructing log message. |
928 | 928 | 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, |
930 | 943 | "Finished generating proposal {} with {} transactions", |
931 | 944 | proposal_id, |
932 | | - block_artifacts.execution_data.execution_infos.len(), |
| 945 | + execution_infos.len(), |
933 | 946 | ); |
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); |
946 | 958 | } |
947 | 959 | } |
948 | 960 |
|
|
0 commit comments