diff --git a/narwhal/worker/Cargo.toml b/narwhal/worker/Cargo.toml index b65b363089e61..c8ceb27d25c84 100644 --- a/narwhal/worker/Cargo.toml +++ b/narwhal/worker/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" async-trait = "0.1.57" bincode = "1.3.3" blake2 = "0.9" +byteorder = "1.4.3" bytes = "1.2.1" futures = "0.3.24" multiaddr = "0.14.0" diff --git a/narwhal/worker/src/batch_maker.rs b/narwhal/worker/src/batch_maker.rs index 6f5bc04bd0c2c..5da676d81fc71 100644 --- a/narwhal/worker/src/batch_maker.rs +++ b/narwhal/worker/src/batch_maker.rs @@ -2,6 +2,8 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 use crate::metrics::WorkerMetrics; +#[cfg(feature = "benchmark")] +use byteorder::{BigEndian, ReadBytesExt}; use config::Committee; #[cfg(feature = "benchmark")] use std::convert::TryInto; @@ -123,16 +125,6 @@ impl BatchMaker { async fn seal(&mut self, timeout: bool) { let size = self.current_batch_size; - // Look for sample txs (they all start with 0) and gather their txs id (the next 8 bytes). - #[cfg(feature = "benchmark")] - let tx_ids: Vec<_> = self - .current_batch - .0 - .iter() - .filter(|tx| tx[0] == 0u8 && tx.len() > 8) - .filter_map(|tx| tx[1..9].try_into().ok()) - .collect(); - // Serialize the batch. self.current_batch_size = 0; let batch: Batch = Batch(self.current_batch.0.drain(..).collect()); @@ -145,6 +137,14 @@ impl BatchMaker { // NOTE: This is one extra hash that is only needed to print the following log entries. if let Ok(digest) = types::serialized_batch_digest(&serialized) { + // Look for sample txs (they all start with 0) and gather their txs id (the next 8 bytes). + let tx_ids: Vec<_> = batch + .0 + .iter() + .filter(|tx| tx[0] == 0u8 && tx.len() > 8) + .filter_map(|tx| tx[1..9].try_into().ok()) + .collect(); + for id in tx_ids { // NOTE: This log entry is used to compute performance. tracing::info!( @@ -154,6 +154,27 @@ impl BatchMaker { ); } + // The first 8 bytes of each transaction message is reserved for an identifier + // that's useful for debugging and tracking the lifetime of messages between + // Narwhal and clients. + let tracking_ids: Vec<_> = batch + .0 + .iter() + .map(|tx| { + let len = tx.len(); + if len >= 8 { + (&tx[0..8]).read_u64::().unwrap_or_default() + } else { + 0 + } + }) + .collect(); + tracing::debug!( + "Tracking IDs of transactions in the Batch {:?}: {:?}", + digest, + tracking_ids + ); + // NOTE: This log entry is used to compute performance. tracing::info!("Batch {:?} contains {} B", digest, size); }