Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix useless-vec warnings throughout stackslib #5629

Merged
merged 7 commits into from
Jan 14, 2025
2 changes: 1 addition & 1 deletion stackslib/src/burnchains/affirmation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ fn inner_find_heaviest_block_commit_ptr(
pub fn find_heaviest_block_commit<B: BurnchainHeaderReader>(
burnchain_tx: &BurnchainDBTransaction,
indexer: &B,
prepare_phase_ops: &Vec<Vec<LeaderBlockCommitOp>>,
prepare_phase_ops: &[Vec<LeaderBlockCommitOp>],
anchor_threshold: u32,
) -> Result<Option<(LeaderBlockCommitOp, Vec<Vec<bool>>, u64, u64)>, DBError> {
let (pox_anchor_ptr, ancestors) =
Expand Down
32 changes: 16 additions & 16 deletions stackslib/src/burnchains/bitcoin/bits.rs

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions stackslib/src/burnchains/bitcoin/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ impl BitcoinMessageHandler for BitcoinBlockDownloader {
None => panic!("No block header set"),
Some(ref ipc_header) => {
let block_hash = ipc_header.block_header.header.bitcoin_hash().clone();
indexer
.send_getdata(&vec![block_hash])
.and_then(|_r| Ok(true))
indexer.send_getdata(&[block_hash]).and_then(|_r| Ok(true))
jbencin marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down Expand Up @@ -193,7 +191,7 @@ impl BitcoinMessageHandler for BitcoinBlockDownloader {
);

// try again
indexer.send_getdata(&vec![ipc_header.block_header.header.bitcoin_hash()])?;
indexer.send_getdata(&[ipc_header.block_header.header.bitcoin_hash()])?;
return Ok(true);
}

Expand Down Expand Up @@ -601,14 +599,14 @@ mod tests {
})
}

fn to_txid(inp: &Vec<u8>) -> Txid {
fn to_txid(inp: &[u8]) -> Txid {
let mut ret = [0; 32];
let bytes = &inp[..inp.len()];
ret.copy_from_slice(bytes);
Txid(ret)
}

fn to_block_hash(inp: &Vec<u8>) -> BurnchainHeaderHash {
fn to_block_hash(inp: &[u8]) -> BurnchainHeaderHash {
let mut ret = [0; 32];
let bytes = &inp[..inp.len()];
ret.copy_from_slice(bytes);
Expand Down
2 changes: 1 addition & 1 deletion stackslib/src/burnchains/bitcoin/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3151,7 +3151,7 @@ mod test {
assert_eq!(total_work_before, total_work_before_idempotent);

// fake block headers for mainnet 40319-40320, which is on a difficulty adjustment boundary
let bad_headers = vec![
let bad_headers = [
LoneBlockHeader {
header: BlockHeader {
version: 1,
Expand Down
2 changes: 1 addition & 1 deletion stackslib/src/burnchains/bitcoin/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ impl BitcoinIndexer {
}

/// Send a GetData message
pub fn send_getdata(&mut self, block_hashes: &Vec<Sha256dHash>) -> Result<(), btc_error> {
pub fn send_getdata(&mut self, block_hashes: &[Sha256dHash]) -> Result<(), btc_error> {
assert!(block_hashes.len() > 0);
let getdata_invs = block_hashes
.iter()
Expand Down
2 changes: 1 addition & 1 deletion stackslib/src/burnchains/bitcoin/spv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ impl SpvClient {
/// * headers must be contiguous
fn validate_header_integrity(
start_height: u64,
headers: &Vec<LoneBlockHeader>,
headers: &[LoneBlockHeader],
check_txcount: bool,
) -> Result<(), btc_error> {
if headers.len() == 0 {
Expand Down
4 changes: 2 additions & 2 deletions stackslib/src/burnchains/burnchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl BurnchainStateTransition {
sort_tx: &mut SortitionHandleTx,
burnchain: &Burnchain,
parent_snapshot: &BlockSnapshot,
block_ops: &Vec<BlockstackOperationType>,
block_ops: &[BlockstackOperationType],
missed_commits: &[MissedBlockCommit],
) -> Result<BurnchainStateTransition, burnchain_error> {
// block commits discovered in this block.
Expand Down Expand Up @@ -976,7 +976,7 @@ impl Burnchain {
}

/// Sanity check -- a list of checked ops is sorted and all vtxindexes are unique
pub fn ops_are_sorted(ops: &Vec<BlockstackOperationType>) -> bool {
pub fn ops_are_sorted(ops: &[BlockstackOperationType]) -> bool {
if ops.len() > 1 {
for i in 0..ops.len() - 1 {
if ops[i].vtxindex() >= ops[i + 1].vtxindex() {
Expand Down
24 changes: 12 additions & 12 deletions stackslib/src/burnchains/tests/burnchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ fn test_process_block_ops() {
vec![BlockstackOperationType::LeaderKeyRegister(
leader_key_3.clone(),
)];
let block_opshash_121 = OpsHash::from_txids(&vec![leader_key_3.txid.clone()]);
let block_opshash_121 = OpsHash::from_txids(&[leader_key_3.txid.clone()]);
let block_prev_chs_121 =
vec![ConsensusHash::from_hex("0000000000000000000000000000000000000000").unwrap()];
let mut block_121_snapshot = BlockSnapshot {
Expand Down Expand Up @@ -316,7 +316,7 @@ fn test_process_block_ops() {
let block_ops_122 = vec![BlockstackOperationType::LeaderKeyRegister(
leader_key_2.clone(),
)];
let block_opshash_122 = OpsHash::from_txids(&vec![leader_key_2.txid.clone()]);
let block_opshash_122 = OpsHash::from_txids(&[leader_key_2.txid.clone()]);
let block_prev_chs_122 = vec![
block_121_snapshot.consensus_hash.clone(),
ConsensusHash::from_hex("0000000000000000000000000000000000000000").unwrap(),
Expand Down Expand Up @@ -365,7 +365,7 @@ fn test_process_block_ops() {
let block_ops_123 = vec![BlockstackOperationType::LeaderKeyRegister(
leader_key_1.clone(),
)];
let block_opshash_123 = OpsHash::from_txids(&vec![
let block_opshash_123 = OpsHash::from_txids(&[
// notably, the user burns here _wont_ be included in the consensus hash
leader_key_1.txid.clone(),
]);
Expand Down Expand Up @@ -417,7 +417,7 @@ fn test_process_block_ops() {

// multiple possibilities for block 124 -- we'll reorg the chain each time back to 123 and
// re-try block 124 to test them all.
let block_ops_124_possibilities = vec![
let block_ops_124_possibilities = [
vec![BlockstackOperationType::LeaderBlockCommit(
block_commit_1.clone(),
)],
Expand Down Expand Up @@ -658,7 +658,7 @@ fn test_process_block_ops() {
// There should only be two -- the winning block at height 124, and the genesis
// sentinel block hash. This is because epochs 121, 122, and 123 don't have any block
// commits.
let expected_winning_hashes = vec![
let expected_winning_hashes = [
BlockHeaderHash([0u8; 32]),
block_124_winners[scenario_idx].block_header_hash.clone(),
];
Expand Down Expand Up @@ -742,7 +742,7 @@ fn test_burn_snapshot_sequence() {

for i in 0..32 {
let mut block_ops = vec![];
let burn_block_hash = BurnchainHeaderHash::from_bytes(&vec![
let burn_block_hash = BurnchainHeaderHash::from_bytes(&[
i + 1,
i + 1,
0,
Expand Down Expand Up @@ -786,12 +786,12 @@ fn test_burn_snapshot_sequence() {
sunset_burn: 0,
treatment: vec![],
commit_outs: vec![],
block_header_hash: BlockHeaderHash::from_bytes(&vec![
block_header_hash: BlockHeaderHash::from_bytes(&[
i, i, i, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
])
.unwrap(),
new_seed: VRFSeed::from_bytes(&vec![
new_seed: VRFSeed::from_bytes(&[
i, i, i, i, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
])
Expand All @@ -817,7 +817,7 @@ fn test_burn_snapshot_sequence() {
.unwrap()],
),

txid: Txid::from_bytes(&vec![
txid: Txid::from_bytes(&[
i, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, i,
])
Expand Down Expand Up @@ -850,7 +850,7 @@ fn test_burn_snapshot_sequence() {
.unwrap(),
memo: vec![0, 0, 0, 0, i],

txid: Txid::from_bytes(&vec![
txid: Txid::from_bytes(&[
i, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0,
])
Expand Down Expand Up @@ -897,15 +897,15 @@ fn test_burn_snapshot_sequence() {
assert_eq!(snapshot.total_burn, expected_burn_total);
assert_eq!(
snapshot.winning_block_txid,
Txid::from_bytes(&vec![
Txid::from_bytes(&[
i, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, i
])
.unwrap()
);
assert_eq!(
snapshot.winning_stacks_block_hash,
BlockHeaderHash::from_bytes(&vec![
BlockHeaderHash::from_bytes(&[
i, i, i, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0
])
Expand Down
19 changes: 8 additions & 11 deletions stackslib/src/burnchains/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ pub struct TestMinerFactory {
impl TestMiner {
pub fn new(
burnchain: &Burnchain,
privks: &Vec<StacksPrivateKey>,
privks: Vec<StacksPrivateKey>,
num_sigs: u16,
hash_mode: &AddressHashMode,
chain_id: u32,
) -> TestMiner {
TestMiner {
burnchain: burnchain.clone(),
privks: privks.clone(),
privks,
num_sigs,
hash_mode: hash_mode.clone(),
microblock_privks: vec![],
Expand Down Expand Up @@ -342,7 +342,7 @@ impl TestMinerFactory {
}

test_debug!("New miner: {:?} {}:{:?}", &hash_mode, num_sigs, &keys);
let mut m = TestMiner::new(burnchain, &keys, num_sigs, &hash_mode, self.chain_id);
let mut m = TestMiner::new(burnchain, keys, num_sigs, &hash_mode, self.chain_id);
m.id = self.next_miner_id;
self.next_miner_id += 1;
m
Expand Down Expand Up @@ -838,9 +838,9 @@ impl TestBurnchainNode {
fn process_next_sortition(
node: &mut TestBurnchainNode,
fork: &mut TestBurnchainFork,
miners: &mut Vec<TestMiner>,
prev_keys: &Vec<LeaderKeyRegisterOp>,
block_hashes: &Vec<BlockHeaderHash>,
miners: &mut [TestMiner],
prev_keys: &[LeaderKeyRegisterOp],
block_hashes: &[BlockHeaderHash],
) -> (
BlockSnapshot,
Vec<LeaderKeyRegisterOp>,
Expand Down Expand Up @@ -892,7 +892,7 @@ fn process_next_sortition(
(tip_snapshot, next_prev_keys, next_commits)
}

fn verify_keys_accepted(node: &mut TestBurnchainNode, prev_keys: &Vec<LeaderKeyRegisterOp>) {
fn verify_keys_accepted(node: &mut TestBurnchainNode, prev_keys: &[LeaderKeyRegisterOp]) {
// all keys accepted
for key in prev_keys.iter() {
let tx_opt = SortitionDB::get_burnchain_transaction(node.sortdb.conn(), &key.txid).unwrap();
Expand All @@ -910,10 +910,7 @@ fn verify_keys_accepted(node: &mut TestBurnchainNode, prev_keys: &Vec<LeaderKeyR
}
}

fn verify_commits_accepted(
node: &TestBurnchainNode,
next_block_commits: &Vec<LeaderBlockCommitOp>,
) {
fn verify_commits_accepted(node: &TestBurnchainNode, next_block_commits: &[LeaderBlockCommitOp]) {
// all commits accepted
for commit in next_block_commits.iter() {
let tx_opt =
Expand Down
6 changes: 3 additions & 3 deletions stackslib/src/chainstate/burn/db/processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ impl SortitionHandleTx<'_> {
burnchain: &Burnchain,
parent_snapshot: &BlockSnapshot,
block_header: &BurnchainBlockHeader,
this_block_ops: &Vec<BlockstackOperationType>,
missed_commits: &Vec<MissedBlockCommit>,
this_block_ops: &[BlockstackOperationType],
missed_commits: &[MissedBlockCommit],
next_pox_info: Option<RewardCycleInfo>,
parent_pox: PoxId,
reward_info: Option<&RewardSetInfo>,
Expand Down Expand Up @@ -428,7 +428,7 @@ mod tests {
let snapshot = test_append_snapshot(
&mut db,
BurnchainHeaderHash([0x01; 32]),
&vec![BlockstackOperationType::LeaderKeyRegister(leader_key)],
&[BlockstackOperationType::LeaderKeyRegister(leader_key)],
);

let next_block_header = BurnchainBlockHeader {
Expand Down
Loading
Loading