From b216f28c835364d63ea5a7e696ddeb87b81a64b5 Mon Sep 17 00:00:00 2001 From: Ori Newman Date: Fri, 28 Oct 2022 10:58:06 +0300 Subject: [PATCH] Stop allowing unused vars --- consensus/src/consensus/mod.rs | 2 +- consensus/src/consensus/test_consensus.rs | 2 +- consensus/src/lib.rs | 2 +- consensus/src/model/stores/reachability.rs | 1 - .../body_processor/body_validation_in_context.rs | 2 +- .../header_processor/post_pow_validation.rs | 16 ++++------------ .../header_processor/pre_ghostdag_validation.rs | 8 ++------ .../header_processor/pre_pow_validation.rs | 8 ++------ .../src/pipeline/virtual_processor/processor.rs | 1 - .../virtual_processor/utxo_validation.rs | 6 +++--- consensus/src/processes/parents_builder.rs | 5 +++-- consensus/src/processes/reachability/inquirer.rs | 4 ++-- .../transaction_validator_populated.rs | 16 +++++++--------- .../tx_validation_in_isolation.rs | 4 ++-- 14 files changed, 29 insertions(+), 48 deletions(-) diff --git a/consensus/src/consensus/mod.rs b/consensus/src/consensus/mod.rs index fb5d79a99..9fa56f672 100644 --- a/consensus/src/consensus/mod.rs +++ b/consensus/src/consensus/mod.rs @@ -359,7 +359,7 @@ impl Service for Consensus { "consensus" } - fn start(self: Arc, core: Arc) -> Vec> { + fn start(self: Arc, _core: Arc) -> Vec> { self.init() } diff --git a/consensus/src/consensus/test_consensus.rs b/consensus/src/consensus/test_consensus.rs index 666d10942..33708554b 100644 --- a/consensus/src/consensus/test_consensus.rs +++ b/consensus/src/consensus/test_consensus.rs @@ -162,7 +162,7 @@ impl Service for TestConsensus { "test-consensus" } - fn start(self: Arc, core: Arc) -> Vec> { + fn start(self: Arc, _core: Arc) -> Vec> { self.init() } diff --git a/consensus/src/lib.rs b/consensus/src/lib.rs index de990afec..506ccb14f 100644 --- a/consensus/src/lib.rs +++ b/consensus/src/lib.rs @@ -1,6 +1,6 @@ // Until the codebase stables up, we will have a lot of these -- ignore for now // TODO: remove this -#![allow(dead_code, unused_variables)] +#![allow(dead_code)] pub mod consensus; pub mod constants; diff --git a/consensus/src/model/stores/reachability.rs b/consensus/src/model/stores/reachability.rs index 9dd6b8550..6bcff6cb5 100644 --- a/consensus/src/model/stores/reachability.rs +++ b/consensus/src/model/stores/reachability.rs @@ -118,7 +118,6 @@ impl ReachabilityStore for DbReachabilityStore { fn insert_future_covering_item(&mut self, hash: Hash, fci: Hash, insertion_index: usize) -> Result<(), StoreError> { let mut data = self.cached_access.read(hash)?; - let height = data.height; let mut_data = Arc::make_mut(&mut data); Arc::make_mut(&mut mut_data.future_covering_set).insert(insertion_index, fci); self.cached_access.write(DirectDbWriter::new(&self.raw_db), hash, &data)?; diff --git a/consensus/src/pipeline/body_processor/body_validation_in_context.rs b/consensus/src/pipeline/body_processor/body_validation_in_context.rs index 16b0a891e..eebf084d5 100644 --- a/consensus/src/pipeline/body_processor/body_validation_in_context.rs +++ b/consensus/src/pipeline/body_processor/body_validation_in_context.rs @@ -15,7 +15,7 @@ impl BlockBodyProcessor { self.check_block_is_not_pruned(block) } - fn check_block_is_not_pruned(self: &Arc, block: &Block) -> BlockProcessResult<()> { + fn check_block_is_not_pruned(self: &Arc, _block: &Block) -> BlockProcessResult<()> { // TODO: In kaspad code it checks that the block is not in the past of the current tips. // We should decide what's the best indication that a block was pruned. Ok(()) diff --git a/consensus/src/pipeline/header_processor/post_pow_validation.rs b/consensus/src/pipeline/header_processor/post_pow_validation.rs index 51336b87f..574b6e832 100644 --- a/consensus/src/pipeline/header_processor/post_pow_validation.rs +++ b/consensus/src/pipeline/header_processor/post_pow_validation.rs @@ -15,8 +15,8 @@ impl HeaderProcessor { self.check_blue_score(ctx, header)?; self.check_blue_work(ctx, header)?; self.check_median_timestamp(ctx, header)?; - self.check_merge_size_limit(ctx, header)?; - self.check_bounded_merge_depth(ctx, header)?; + self.check_merge_size_limit(ctx)?; + self.check_bounded_merge_depth(ctx)?; self.check_pruning_point(ctx, header)?; self.check_indirect_parents(ctx, header) } @@ -36,11 +36,7 @@ impl HeaderProcessor { Ok(()) } - pub fn check_merge_size_limit( - self: &Arc, - ctx: &mut HeaderProcessingContext, - header: &Header, - ) -> BlockProcessResult<()> { + pub fn check_merge_size_limit(self: &Arc, ctx: &mut HeaderProcessingContext) -> BlockProcessResult<()> { let mergeset_size = ctx.ghostdag_data.as_ref().unwrap().mergeset_size() as u64; if mergeset_size > self.mergeset_size_limit { @@ -103,11 +99,7 @@ impl HeaderProcessor { Ok(()) } - pub fn check_bounded_merge_depth( - self: &Arc, - ctx: &mut HeaderProcessingContext, - header: &Header, - ) -> BlockProcessResult<()> { + pub fn check_bounded_merge_depth(self: &Arc, ctx: &mut HeaderProcessingContext) -> BlockProcessResult<()> { let gd_data = ctx.ghostdag_data.as_ref().unwrap(); let merge_depth_root = self.depth_manager.calc_merge_depth_root(gd_data, ctx.pruning_point()); let finality_point = self.depth_manager.calc_finality_point(gd_data, ctx.pruning_point()); diff --git a/consensus/src/pipeline/header_processor/pre_ghostdag_validation.rs b/consensus/src/pipeline/header_processor/pre_ghostdag_validation.rs index 5a86e10f2..655191c56 100644 --- a/consensus/src/pipeline/header_processor/pre_ghostdag_validation.rs +++ b/consensus/src/pipeline/header_processor/pre_ghostdag_validation.rs @@ -23,7 +23,7 @@ impl HeaderProcessor { self.validate_header_in_isolation(header)?; self.check_parents_exist(header)?; - self.check_parents_incest(ctx, header)?; + self.check_parents_incest(ctx)?; Ok(()) } @@ -92,11 +92,7 @@ impl HeaderProcessor { Ok(()) } - fn check_parents_incest( - self: &Arc, - ctx: &mut HeaderProcessingContext, - header: &Header, - ) -> BlockProcessResult<()> { + fn check_parents_incest(self: &Arc, ctx: &mut HeaderProcessingContext) -> BlockProcessResult<()> { let parents = ctx.get_non_pruned_parents(); for parent_a in parents.iter() { for parent_b in parents.iter() { diff --git a/consensus/src/pipeline/header_processor/pre_pow_validation.rs b/consensus/src/pipeline/header_processor/pre_pow_validation.rs index 15f17507f..6c9608d31 100644 --- a/consensus/src/pipeline/header_processor/pre_pow_validation.rs +++ b/consensus/src/pipeline/header_processor/pre_pow_validation.rs @@ -15,17 +15,13 @@ impl HeaderProcessor { return Ok(()); } - self.check_pruning_violation(ctx, header)?; + self.check_pruning_violation(ctx)?; self.check_pow_and_calc_block_level(ctx, header)?; self.check_difficulty_and_daa_score(ctx, header)?; Ok(()) } - fn check_pruning_violation( - self: &Arc, - ctx: &mut HeaderProcessingContext, - header: &Header, - ) -> BlockProcessResult<()> { + fn check_pruning_violation(self: &Arc, ctx: &mut HeaderProcessingContext) -> BlockProcessResult<()> { let non_pruned_parents = ctx.get_non_pruned_parents(); if non_pruned_parents.is_empty() { return Ok(()); diff --git a/consensus/src/pipeline/virtual_processor/processor.rs b/consensus/src/pipeline/virtual_processor/processor.rs index 995c071eb..ee2fbb67c 100644 --- a/consensus/src/pipeline/virtual_processor/processor.rs +++ b/consensus/src/pipeline/virtual_processor/processor.rs @@ -317,7 +317,6 @@ impl VirtualStateProcessor { let ghostdag_data = self.ghostdag_store.get_compact_data(virtual_sp).unwrap(); let pruning_read_guard = self.pruning_store.upgradable_read(); let current_pruning_info = pruning_read_guard.get().unwrap(); - let current_pp_bs = self.ghostdag_store.get_blue_score(current_pruning_info.pruning_point).unwrap(); let (new_pruning_points, new_candidate) = self.pruning_manager.next_pruning_points_and_candidate_by_ghostdag_data( ghostdag_data, None, diff --git a/consensus/src/pipeline/virtual_processor/utxo_validation.rs b/consensus/src/pipeline/virtual_processor/utxo_validation.rs index 76ec33560..810bb39fd 100644 --- a/consensus/src/pipeline/virtual_processor/utxo_validation.rs +++ b/consensus/src/pipeline/virtual_processor/utxo_validation.rs @@ -135,9 +135,9 @@ impl VirtualStateProcessor { fn verify_coinbase_transaction( self: &Arc, - coinbase_tx: &Transaction, - mergeset_data: &GhostdagData, - mergeset_fees: &BlockHashMap, + _coinbase_tx: &Transaction, + _mergeset_data: &GhostdagData, + _mergeset_fees: &BlockHashMap, ) -> BlockProcessResult<()> { // TODO: build expected coinbase using `mergeset_fees` and compare with the given tx // Return `Err(BadCoinbaseTransaction)` if the expected and actual defer diff --git a/consensus/src/processes/parents_builder.rs b/consensus/src/processes/parents_builder.rs index 193b21b67..26c95504a 100644 --- a/consensus/src/processes/parents_builder.rs +++ b/consensus/src/processes/parents_builder.rs @@ -56,7 +56,7 @@ impl .expect("at least one of the parents is expected to be in the future of the pruning point"); direct_parent_headers.swap(0, first_parent_in_future_of_pruning_point_index); - let mut candidates_by_level_to_reference_blocks_map = (0..self.max_block_level + 1).map(|level| HashMap::new()).collect_vec(); + let mut candidates_by_level_to_reference_blocks_map = (0..self.max_block_level + 1).map(|_| HashMap::new()).collect_vec(); // Direct parents are guaranteed to be in one other's anticones so add them all to // all the block levels they occupy. for direct_parent_header in direct_parent_headers.iter() { @@ -158,7 +158,6 @@ impl break; } - let level_blocks = reference_blocks_map.keys().copied().collect_vec(); parents.push(reference_blocks_map.keys().copied().collect_vec()); } @@ -220,6 +219,7 @@ mod tests { } } + #[allow(unused_variables)] impl HeaderStoreReader for HeaderStoreMock { fn get_daa_score(&self, hash: hashes::Hash) -> Result { todo!() @@ -254,6 +254,7 @@ mod tests { pub children: BlockHashes, } + #[allow(unused_variables)] impl RelationsStoreReader for RelationsStoreMock { fn get_parents(&self, hash: Hash) -> Result { todo!() diff --git a/consensus/src/processes/reachability/inquirer.rs b/consensus/src/processes/reachability/inquirer.rs index fc042f249..0cb9c5c76 100644 --- a/consensus/src/processes/reachability/inquirer.rs +++ b/consensus/src/processes/reachability/inquirer.rs @@ -136,8 +136,8 @@ pub(super) fn get_next_chain_ancestor_unchecked( ancestor: Hash, ) -> Result { match binary_search_descendant(store, store.get_children(ancestor)?.as_slice(), descendant)? { - SearchOutput::Found(hash, i) => Ok(hash), - SearchOutput::NotFound(i) => Err(ReachabilityError::BadQuery), + SearchOutput::Found(hash, _) => Ok(hash), + SearchOutput::NotFound(_) => Err(ReachabilityError::BadQuery), } } diff --git a/consensus/src/processes/transaction_validator/transaction_validator_populated.rs b/consensus/src/processes/transaction_validator/transaction_validator_populated.rs index 683710453..431847113 100644 --- a/consensus/src/processes/transaction_validator/transaction_validator_populated.rs +++ b/consensus/src/processes/transaction_validator/transaction_validator_populated.rs @@ -22,7 +22,7 @@ impl TransactionValidator { if let Some((index, (input, entry))) = tx .populated_inputs() .enumerate() - .find(|(index, (input, entry))| entry.is_coinbase && entry.block_daa_score + self.coinbase_maturity > pov_daa_score) + .find(|(_, (_, entry))| entry.is_coinbase && entry.block_daa_score + self.coinbase_maturity > pov_daa_score) { return Err(TxRuleError::ImmatureCoinbaseSpend( index, @@ -65,10 +65,8 @@ impl TransactionValidator { fn check_sequence_lock(tx: &PopulatedTransaction, pov_daa_score: u64) -> TxResult<()> { let pov_daa_score: i64 = pov_daa_score as i64; - if tx - .populated_inputs() - .filter(|(input, entry)| input.sequence & SEQUENCE_LOCK_TIME_DISABLED != SEQUENCE_LOCK_TIME_DISABLED) - .any(|(input, entry)| { + if tx.populated_inputs().filter(|(input, _)| input.sequence & SEQUENCE_LOCK_TIME_DISABLED != SEQUENCE_LOCK_TIME_DISABLED).any( + |(input, entry)| { // Given a sequence number, we apply the relative time lock // mask in order to obtain the time lock delta required before // this input can be spent. @@ -85,19 +83,19 @@ impl TransactionValidator { let lock_daa_score = entry.block_daa_score as i64 + relative_lock - 1; lock_daa_score >= pov_daa_score - }) - { + }, + ) { return Err(TxRuleError::SequenceLockConditionsAreNotMet); } Ok(()) } - fn check_sig_op_counts(tx: &PopulatedTransaction) -> TxResult<()> { + fn check_sig_op_counts(_tx: &PopulatedTransaction) -> TxResult<()> { // TODO: Implement this Ok(()) } - fn check_scripts(tx: &PopulatedTransaction) -> TxResult<()> { + fn check_scripts(_tx: &PopulatedTransaction) -> TxResult<()> { // TODO: Implement this Ok(()) } diff --git a/consensus/src/processes/transaction_validator/tx_validation_in_isolation.rs b/consensus/src/processes/transaction_validator/tx_validation_in_isolation.rs index 9f027b610..884b44a54 100644 --- a/consensus/src/processes/transaction_validator/tx_validation_in_isolation.rs +++ b/consensus/src/processes/transaction_validator/tx_validation_in_isolation.rs @@ -265,7 +265,7 @@ mod tests { assert_match!(tv.validate_tx_in_isolation(&tx), Err(TxRuleError::NoTxInputs)); let mut tx = valid_tx.clone(); - tx.inputs = (0..params.max_tx_inputs + 1).map(|i| valid_tx.inputs[0].clone()).collect(); + tx.inputs = (0..params.max_tx_inputs + 1).map(|_| valid_tx.inputs[0].clone()).collect(); assert_match!(tv.validate_tx_in_isolation(&tx), Err(TxRuleError::TooManyInputs(_, _))); let mut tx = valid_tx.clone(); @@ -273,7 +273,7 @@ mod tests { assert_match!(tv.validate_tx_in_isolation(&tx), Err(TxRuleError::TooBigSignatureScript(_, _))); let mut tx = valid_tx.clone(); - tx.outputs = (0..params.max_tx_outputs + 1).map(|i| valid_tx.outputs[0].clone()).collect(); + tx.outputs = (0..params.max_tx_outputs + 1).map(|_| valid_tx.outputs[0].clone()).collect(); assert_match!(tv.validate_tx_in_isolation(&tx), Err(TxRuleError::TooManyOutputs(_, _))); let mut tx = valid_tx.clone();