Skip to content

Commit

Permalink
[Narwhal] avoid copying certificates
Browse files Browse the repository at this point in the history
  • Loading branch information
mwtian committed Jul 5, 2023
1 parent d0c78f3 commit 7588f4e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
9 changes: 7 additions & 2 deletions crates/sui-core/src/consensus_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,18 @@ impl<T: ParentSync + Send + Sync> ExecutionState for ConsensusHandler<T> {
.consensus_committed_subdags
.with_label_values(&[&leader_author.to_string()])
.inc();
for (cert, batches) in consensus_output.batches {
for (cert, batches) in consensus_output
.sub_dag
.certificates
.iter()
.zip(consensus_output.batches.iter())
{
let author = cert.header().author();
self.metrics
.consensus_committed_certificates
.with_label_values(&[&author.to_string()])
.inc();
let output_cert = Arc::new(cert);
let output_cert = Arc::new(cert.clone());
for batch in batches {
self.metrics.consensus_handler_processed_batches.inc();
for serialized_transaction in batch.transactions() {
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-core/src/unit_tests/narwhal_manager_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct NoOpExecutionState {
#[async_trait::async_trait]
impl ExecutionState for NoOpExecutionState {
async fn handle_consensus_output(&self, consensus_output: ConsensusOutput) {
for (_, batches) in consensus_output.batches {
for batches in consensus_output.batches {
for batch in batches {
for transaction in batch.transactions().iter() {
assert_eq!(
Expand Down
5 changes: 1 addition & 4 deletions narwhal/executor/src/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ impl Subscriber {
// consensus output
for cert in &sub_dag.certificates {
let mut output_batches = Vec::with_capacity(cert.header().payload().len());
let output_cert = cert.clone();

inner
.metrics
Expand All @@ -298,9 +297,7 @@ impl Subscriber {
);
output_batches.push(batch.clone());
}
subscriber_output
.batches
.push((output_cert, output_batches));
subscriber_output.batches.push(output_batches);
}
subscriber_output
}
Expand Down
2 changes: 1 addition & 1 deletion narwhal/node/src/execution_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl SimpleExecutionState {
#[async_trait]
impl ExecutionState for SimpleExecutionState {
async fn handle_consensus_output(&self, consensus_output: ConsensusOutput) {
for (_, batches) in consensus_output.batches {
for batches in consensus_output.batches {
for batch in batches {
for transaction in batch.transactions().iter() {
if let Err(err) = self
Expand Down
3 changes: 2 additions & 1 deletion narwhal/types/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ pub type SequenceNumber = u64;
/// It is sent to the the ExecutionState handle_consensus_transactions
pub struct ConsensusOutput {
pub sub_dag: Arc<CommittedSubDag>,
pub batches: Vec<(Certificate, Vec<Batch>)>,
/// Order of each Vec<Batch> item matches the order of certificates in the CommittedSubDag.
pub batches: Vec<Vec<Batch>>,
}

#[derive(Serialize, Deserialize, Clone, Debug, Default)]
Expand Down

0 comments on commit 7588f4e

Please sign in to comment.