From d52ce4455aa540c5cdb6c042806038f8ec402395 Mon Sep 17 00:00:00 2001 From: D-Stacks <78099568+D-Stacks@users.noreply.github.com> Date: Mon, 25 Nov 2024 19:43:40 +0100 Subject: [PATCH] shorten the find. --- .../body_validation_in_isolation.rs | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/consensus/src/pipeline/body_processor/body_validation_in_isolation.rs b/consensus/src/pipeline/body_processor/body_validation_in_isolation.rs index a31b74428..18fc5ef2f 100644 --- a/consensus/src/pipeline/body_processor/body_validation_in_isolation.rs +++ b/consensus/src/pipeline/body_processor/body_validation_in_isolation.rs @@ -85,8 +85,8 @@ impl BlockBodyProcessor { storage_mass_activated, Arc::new(self.mass_calculator.clone()), ); + Self::check_input_double_spends(bbvc)?; Self::check_duplicate_transactions(bbvc, block)?; - Self::check_input_double_spends(bbvc, block)?; Self::check_transactions_full(self, bbvc, block)?; Self::check_block_mass(bbvc, block)?; Ok(bbvc.total_calculated_mass) @@ -169,21 +169,10 @@ impl BlockBodyProcessor { tx.inputs.iter().try_for_each(|input| Self::check_no_chained_inputs(bbvc, input)) } - fn check_input_double_spends(bbvc: &Arc, block: &Block) -> BlockProcessResult<()> { + fn check_input_double_spends(bbvc: &Arc) -> BlockProcessResult<()> { if bbvc.existing_outpoints_count.len() < bbvc.number_of_input_outpoints { return Err(RuleError::DoubleSpendInSameBlock( - block - .transactions - .iter() - .find_map(|tx| { - let res = tx - .inputs - .iter() - .find(|input| bbvc.existing_outpoints_count[&input.previous_outpoint] > 1) - .map(|input| input.previous_outpoint); - res - }) - .unwrap(), + *bbvc.existing_outpoints_count.iter().find(|(_, count)| **count > 1).unwrap().0, )); } Ok(())