Skip to content

Commit

Permalink
fix merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Boog900 committed Aug 1, 2024
1 parent 2b8bc4d commit 5709111
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 37 deletions.
4 changes: 2 additions & 2 deletions consensus/rules/src/hard_forks/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
4 changes: 2 additions & 2 deletions consensus/rules/src/transactions/ring_ct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
6 changes: 1 addition & 5 deletions consensus/src/context/difficulty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 2 additions & 6 deletions consensus/src/context/hardforks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 2 additions & 8 deletions consensus/src/context/weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/tests/context/difficulty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions consensus/src/tests/mock_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ impl Service<BCReadRequest> 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();
Expand Down
11 changes: 4 additions & 7 deletions consensus/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
}

Expand Down
2 changes: 1 addition & 1 deletion p2p/p2p/src/block_downloader/block_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ mod tests {
start_height,
block_batch: BlockBatch {
blocks: vec![],
size: start_height as usize,
size: start_height,
peer_handle,
},
}
Expand Down
3 changes: 0 additions & 3 deletions p2p/p2p/src/block_downloader/chain_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,12 @@ impl<N: NetworkZone> ChainTracker<N> {
// - 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 {
Expand Down
2 changes: 2 additions & 0 deletions storage/blockchain/src/ops/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::{
pub fn chain_height(
table_block_heights: &impl DatabaseRo<BlockHeights>,
) -> Result<BlockHeight, RuntimeError> {
#[allow(clippy::cast_possible_truncation)] // we enforce 64-bit
table_block_heights.len().map(|height| height as usize)
}

Expand All @@ -47,6 +48,7 @@ pub fn top_block_height(
) -> Result<BlockHeight, RuntimeError> {
match table_block_heights.len()? {
0 => Err(RuntimeError::KeyNotFound),
#[allow(clippy::cast_possible_truncation)] // we enforce 64-bit
height => Ok(height as usize - 1),
}
}
Expand Down

0 comments on commit 5709111

Please sign in to comment.