diff --git a/stackslib/src/chainstate/nakamoto/shadow.rs b/stackslib/src/chainstate/nakamoto/shadow.rs index dad10f62e0..9c80b2b6d4 100644 --- a/stackslib/src/chainstate/nakamoto/shadow.rs +++ b/stackslib/src/chainstate/nakamoto/shadow.rs @@ -632,8 +632,8 @@ impl NakamotoBlockBuilder { )) })?; - if naka_tip_header.anchored_header.height() + 1 - <= naka_tip_tenure_start_header.anchored_header.height() + if naka_tip_header.anchored_header.height() + < naka_tip_tenure_start_header.anchored_header.height() { return Err(Error::InvalidStacksBlock( "Nakamoto tip is lower than its tenure-start block".into(), diff --git a/stackslib/src/chainstate/stacks/index/trie.rs b/stackslib/src/chainstate/stacks/index/trie.rs index 251c363561..eabaf95ed0 100644 --- a/stackslib/src/chainstate/stacks/index/trie.rs +++ b/stackslib/src/chainstate/stacks/index/trie.rs @@ -375,13 +375,8 @@ impl Trie { // append the new leaf and the end of the file. let new_leaf_disk_ptr = storage.last_ptr()?; let new_leaf_chr = cursor.path[cursor.tell()]; // NOTE: this is safe because !cursor.eop() - let new_leaf_path = cursor.path[(if cursor.tell() + 1 <= cursor.path.len() { - cursor.tell() + 1 - } else { - cursor.path.len() - })..] - .to_vec(); - new_leaf_data.path = new_leaf_path; + new_leaf_data.path = + cursor.path[std::cmp::min(cursor.tell() + 1, cursor.path.len())..].to_vec(); let new_leaf_hash = get_leaf_hash(new_leaf_data); // put new leaf at the end of this Trie diff --git a/stackslib/src/chainstate/stacks/tests/block_construction.rs b/stackslib/src/chainstate/stacks/tests/block_construction.rs index bcf7611695..8978d4e780 100644 --- a/stackslib/src/chainstate/stacks/tests/block_construction.rs +++ b/stackslib/src/chainstate/stacks/tests/block_construction.rs @@ -2327,7 +2327,7 @@ fn test_build_anchored_blocks_invalid() { eprintln!("\n\nat resume parent tenure:\nlast_parent: {:?}\nlast_parent_tip: {:?}\n\n", &last_parent, &last_parent_tip); } - else if tenure_id >= bad_block_tenure + 1 { + else if tenure_id > bad_block_tenure { last_parent = None; last_parent_tip = None; } diff --git a/stackslib/src/net/relay.rs b/stackslib/src/net/relay.rs index 9121bac2c9..28d7c5a30c 100644 --- a/stackslib/src/net/relay.rs +++ b/stackslib/src/net/relay.rs @@ -286,7 +286,7 @@ impl RelayerStats { let mut to_remove = vec![]; for (ts, old_addr) in self.relay_updates.iter() { self.relay_stats.remove(old_addr); - if self.relay_stats.len() <= MAX_RELAYER_STATS - 1 { + if self.relay_stats.len() < MAX_RELAYER_STATS { break; } to_remove.push(*ts); @@ -342,7 +342,7 @@ impl RelayerStats { let mut to_remove = vec![]; for (ts, old_nk) in self.recent_updates.iter() { self.recent_messages.remove(old_nk); - if self.recent_messages.len() <= MAX_RELAYER_STATS - 1 { + if self.recent_messages.len() < MAX_RELAYER_STATS { break; } to_remove.push(*ts);