From 1a994f09e4bbb7f095c317dde91c804fd7db146e Mon Sep 17 00:00:00 2001 From: Gustavo Inacio Date: Fri, 27 Dec 2024 18:02:46 +0100 Subject: [PATCH] perf: add rayon to verify signatures process Signed-off-by: Gustavo Inacio --- tap_aggregator/Cargo.toml | 2 +- tap_aggregator/src/aggregator.rs | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/tap_aggregator/Cargo.toml b/tap_aggregator/Cargo.toml index aca71e5d..1765ea88 100644 --- a/tap_aggregator/Cargo.toml +++ b/tap_aggregator/Cargo.toml @@ -39,11 +39,11 @@ tower = { version = "0.4", features = ["util", "steer"] } tonic = { version = "0.12.3", features = ["transport", "zstd"] } prost = "0.13.3" hyper = { version = "1", features = ["full"] } +rayon = "1.10.0" [build-dependencies] tonic-build = "0.12.3" - [dev-dependencies] jsonrpsee = { workspace = true, features = ["http-client", "jsonrpsee-core"] } rand.workspace = true diff --git a/tap_aggregator/src/aggregator.rs b/tap_aggregator/src/aggregator.rs index a6e4cb6d..1fe15262 100644 --- a/tap_aggregator/src/aggregator.rs +++ b/tap_aggregator/src/aggregator.rs @@ -8,7 +8,7 @@ use alloy::{ sol_types::SolStruct, }; use anyhow::{bail, Ok, Result}; - +use rayon::prelude::*; use tap_core::{ rav::ReceiptAggregateVoucher, receipt::Receipt, @@ -25,18 +25,14 @@ pub fn check_and_aggregate_receipts( check_signatures_unique(receipts)?; // Check that the receipts are signed by an accepted signer address - receipts.iter().try_for_each(|receipt| { - check_signature_is_from_one_of_addresses( - receipt.clone(), - domain_separator, - accepted_addresses, - ) + receipts.par_iter().try_for_each(|receipt| { + check_signature_is_from_one_of_addresses(receipt, domain_separator, accepted_addresses) })?; // Check that the previous rav is signed by an accepted signer address if let Some(previous_rav) = &previous_rav { check_signature_is_from_one_of_addresses( - previous_rav.clone(), + previous_rav, domain_separator, accepted_addresses, )?; @@ -74,7 +70,7 @@ pub fn check_and_aggregate_receipts( } fn check_signature_is_from_one_of_addresses( - message: EIP712SignedMessage, + message: &EIP712SignedMessage, domain_separator: &Eip712Domain, accepted_addresses: &HashSet
, ) -> Result<()> {