From 8f39e383c98742b40358a5bd8c90f8828b2109b7 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 4 Mar 2024 15:37:23 +0100 Subject: [PATCH 1/2] perf: process batch proposal transmissions using rayon Signed-off-by: ljedrz --- node/bft/src/primary.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/node/bft/src/primary.rs b/node/bft/src/primary.rs index f5e5758b9a..6271d5582d 100644 --- a/node/bft/src/primary.rs +++ b/node/bft/src/primary.rs @@ -58,6 +58,7 @@ use colored::Colorize; use futures::stream::{FuturesUnordered, StreamExt}; use indexmap::{IndexMap, IndexSet}; use parking_lot::{Mutex, RwLock}; +use rayon::prelude::*; use std::{ collections::{HashMap, HashSet}, future::Future, @@ -572,12 +573,12 @@ impl Primary { let mut transmissions = self.sync_with_batch_header_from_peer(peer_ip, &batch_header).await?; // Check that the transmission ids match and are not fee transactions. - for (transmission_id, transmission) in transmissions.iter_mut() { + if let Err(err) = transmissions.par_iter_mut().try_for_each(|(transmission_id, transmission)| { // If the transmission is not well-formed, then return early. - if let Err(err) = self.ledger.ensure_transmission_is_well_formed(*transmission_id, transmission) { - debug!("Batch propose from '{peer_ip}' contains an invalid transmission - {err}",); - return Ok(()); - } + self.ledger.ensure_transmission_is_well_formed(*transmission_id, transmission) + }) { + debug!("Batch propose from '{peer_ip}' contains an invalid transmission - {err}",); + return Ok(()); } // Ensure the batch is for the current round. From fc66ecf0f109c03bbf35326c1ba1e5f526967b0a Mon Sep 17 00:00:00 2001 From: ljedrz Date: Wed, 6 Mar 2024 13:09:02 +0100 Subject: [PATCH 2/2] feat: use cfg_iter_mut instead of par_iter_mut Signed-off-by: ljedrz --- node/bft/src/primary.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/bft/src/primary.rs b/node/bft/src/primary.rs index 6271d5582d..5e438e8f9c 100644 --- a/node/bft/src/primary.rs +++ b/node/bft/src/primary.rs @@ -573,7 +573,7 @@ impl Primary { let mut transmissions = self.sync_with_batch_header_from_peer(peer_ip, &batch_header).await?; // Check that the transmission ids match and are not fee transactions. - if let Err(err) = transmissions.par_iter_mut().try_for_each(|(transmission_id, transmission)| { + if let Err(err) = cfg_iter_mut!(transmissions).try_for_each(|(transmission_id, transmission)| { // If the transmission is not well-formed, then return early. self.ledger.ensure_transmission_is_well_formed(*transmission_id, transmission) }) {