From 570911114444a4ebe5c285c86c86ff8860efd613 Mon Sep 17 00:00:00 2001 From: Boog900 <54e72d8a-345f-4599-bd90-c6b9bc7d0ec5@aleeas.com> Date: Thu, 1 Aug 2024 21:05:15 +0100 Subject: [PATCH] fix merge --- consensus/rules/src/hard_forks/tests.rs | 4 ++-- consensus/rules/src/transactions/ring_ct.rs | 4 ++-- consensus/src/context/difficulty.rs | 6 +----- consensus/src/context/hardforks.rs | 8 ++------ consensus/src/context/weight.rs | 10 ++-------- consensus/src/tests/context/difficulty.rs | 2 +- consensus/src/tests/mock_db.rs | 4 ++-- consensus/src/transactions.rs | 11 ++++------- p2p/p2p/src/block_downloader/block_queue.rs | 2 +- p2p/p2p/src/block_downloader/chain_tracker.rs | 3 --- storage/blockchain/src/ops/blockchain.rs | 2 ++ 11 files changed, 19 insertions(+), 37 deletions(-) diff --git a/consensus/rules/src/hard_forks/tests.rs b/consensus/rules/src/hard_forks/tests.rs index 7b5111cd..00dd0360 100644 --- a/consensus/rules/src/hard_forks/tests.rs +++ b/consensus/rules/src/hard_forks/tests.rs @@ -35,9 +35,9 @@ prop_compose! { fn arb_full_hf_votes() ( // we can't use HardFork as for some reason it overflows the stack, so we use u8. - votes in any::<[u8; TEST_WINDOW_SIZE as usize]>() + votes in any::<[u8; TEST_WINDOW_SIZE]>() ) -> HFVotes { - let mut vote_count = HFVotes::new(TEST_WINDOW_SIZE as usize); + let mut vote_count = HFVotes::new(TEST_WINDOW_SIZE); for vote in votes { vote_count.add_vote_for_hf(&HardFork::from_vote(vote % 17)); } diff --git a/consensus/rules/src/transactions/ring_ct.rs b/consensus/rules/src/transactions/ring_ct.rs index 6801a67e..62f71ddf 100644 --- a/consensus/rules/src/transactions/ring_ct.rs +++ b/consensus/rules/src/transactions/ring_ct.rs @@ -130,10 +130,10 @@ pub(crate) fn ring_ct_semantic_checks( let rct_type = proofs.rct_type(); check_rct_type(&rct_type, *hf, tx_hash)?; - check_output_range_proofs(&proofs, verifier)?; + check_output_range_proofs(proofs, verifier)?; if rct_type != RctType::AggregateMlsagBorromean { - simple_type_balances(&proofs)?; + simple_type_balances(proofs)?; } Ok(()) diff --git a/consensus/src/context/difficulty.rs b/consensus/src/context/difficulty.rs index 31f1f21c..bdb79445 100644 --- a/consensus/src/context/difficulty.rs +++ b/consensus/src/context/difficulty.rs @@ -135,11 +135,7 @@ impl DifficultyCache { numb_blocks: usize, database: D, ) -> Result<(), ExtendedConsensusError> { - let Some(retained_blocks) = self - .timestamps - .len() - .checked_sub(usize::try_from(numb_blocks).unwrap()) - else { + let Some(retained_blocks) = self.timestamps.len().checked_sub(numb_blocks) else { // More blocks to pop than we have in the cache, so just restart a new cache. *self = Self::init_from_chain_height( self.last_accounted_height - numb_blocks + 1, diff --git a/consensus/src/context/hardforks.rs b/consensus/src/context/hardforks.rs index ceafc5cd..e47c10ff 100644 --- a/consensus/src/context/hardforks.rs +++ b/consensus/src/context/hardforks.rs @@ -79,12 +79,8 @@ impl HardForkState { let block_start = chain_height.saturating_sub(config.window); - let votes = get_votes_in_range( - database.clone(), - block_start..chain_height, - usize::try_from(config.window).unwrap(), - ) - .await?; + let votes = + get_votes_in_range(database.clone(), block_start..chain_height, config.window).await?; if chain_height > config.window { debug_assert_eq!(votes.total_votes(), config.window) diff --git a/consensus/src/context/weight.rs b/consensus/src/context/weight.rs index ba5c7ede..730571bd 100644 --- a/consensus/src/context/weight.rs +++ b/consensus/src/context/weight.rs @@ -101,17 +101,11 @@ impl BlockWeightsCache { Ok(BlockWeightsCache { short_term_block_weights: rayon_spawn_async(move || { - RollingMedian::from_vec( - short_term_block_weights, - usize::try_from(config.short_term_window).unwrap(), - ) + RollingMedian::from_vec(short_term_block_weights, config.short_term_window) }) .await, long_term_weights: rayon_spawn_async(move || { - RollingMedian::from_vec( - long_term_weights, - usize::try_from(config.long_term_window).unwrap(), - ) + RollingMedian::from_vec(long_term_weights, config.long_term_window) }) .await, tip_height: chain_height - 1, diff --git a/consensus/src/tests/context/difficulty.rs b/consensus/src/tests/context/difficulty.rs index 2cf01faf..e7d472d5 100644 --- a/consensus/src/tests/context/difficulty.rs +++ b/consensus/src/tests/context/difficulty.rs @@ -65,7 +65,7 @@ async fn calculate_diff_3000000_3002000() -> Result<(), tower::BoxError> { let mut db_builder = DummyDatabaseBuilder::default(); for (cum_dif, timestamp) in DIF_3000000_3002000 .iter() - .take(cfg.total_block_count() as usize) + .take(cfg.total_block_count()) { db_builder.add_block( DummyBlockExtendedHeader::default().with_difficulty_info(*timestamp, *cum_dif), diff --git a/consensus/src/tests/mock_db.rs b/consensus/src/tests/mock_db.rs index 8e8809ee..8dc97e60 100644 --- a/consensus/src/tests/mock_db.rs +++ b/consensus/src/tests/mock_db.rs @@ -173,8 +173,8 @@ impl Service for DummyDatabase { BCResponse::BlockHash(hash) } BCReadRequest::BlockExtendedHeaderInRange(range, _) => { - let mut end = usize::try_from(range.end).unwrap(); - let mut start = usize::try_from(range.start).unwrap(); + let mut end = range.end; + let mut start = range.start; if let Some(dummy_height) = dummy_height { let block_len = blocks.read().unwrap().len(); diff --git a/consensus/src/transactions.rs b/consensus/src/transactions.rs index 3accd7f6..5d12c330 100644 --- a/consensus/src/transactions.rs +++ b/consensus/src/transactions.rs @@ -130,13 +130,10 @@ impl TransactionVerificationData { match &tx { Transaction::V1 { prefix, .. } => { for input in &prefix.inputs { - match input { - Input::ToKey { amount, .. } => { - fee = fee - .checked_add(amount.unwrap_or(0)) - .ok_or(TransactionError::InputsOverflow)?; - } - _ => (), + if let Input::ToKey { amount, .. } = input { + fee = fee + .checked_add(amount.unwrap_or(0)) + .ok_or(TransactionError::InputsOverflow)?; } } diff --git a/p2p/p2p/src/block_downloader/block_queue.rs b/p2p/p2p/src/block_downloader/block_queue.rs index 8c4ace4f..5a92f493 100644 --- a/p2p/p2p/src/block_downloader/block_queue.rs +++ b/p2p/p2p/src/block_downloader/block_queue.rs @@ -131,7 +131,7 @@ mod tests { start_height, block_batch: BlockBatch { blocks: vec![], - size: start_height as usize, + size: start_height, peer_handle, }, } diff --git a/p2p/p2p/src/block_downloader/chain_tracker.rs b/p2p/p2p/src/block_downloader/chain_tracker.rs index 7fbfc96d..aacb1633 100644 --- a/p2p/p2p/src/block_downloader/chain_tracker.rs +++ b/p2p/p2p/src/block_downloader/chain_tracker.rs @@ -171,15 +171,12 @@ impl ChainTracker { // - index of the next pruned block for this seed let end_idx = min( min(entry.ids.len(), max_blocks), - usize::try_from( pruning_seed .get_next_pruned_block(self.first_height, CRYPTONOTE_MAX_BLOCK_HEIGHT) .expect("We use local values to calculate height which should be below the sanity limit") // Use a big value as a fallback if the seed does no pruning. .unwrap_or(CRYPTONOTE_MAX_BLOCK_HEIGHT) - self.first_height, - ) - .unwrap(), ); if end_idx == 0 { diff --git a/storage/blockchain/src/ops/blockchain.rs b/storage/blockchain/src/ops/blockchain.rs index 3ccf4896..65d9ca26 100644 --- a/storage/blockchain/src/ops/blockchain.rs +++ b/storage/blockchain/src/ops/blockchain.rs @@ -25,6 +25,7 @@ use crate::{ pub fn chain_height( table_block_heights: &impl DatabaseRo, ) -> Result { + #[allow(clippy::cast_possible_truncation)] // we enforce 64-bit table_block_heights.len().map(|height| height as usize) } @@ -47,6 +48,7 @@ pub fn top_block_height( ) -> Result { match table_block_heights.len()? { 0 => Err(RuntimeError::KeyNotFound), + #[allow(clippy::cast_possible_truncation)] // we enforce 64-bit height => Ok(height as usize - 1), } }