Skip to content

Commit 2d758c6

Browse files
committed
Merge branch 'develop' of https://github.com/stacks-network/stacks-core into fix/clippy-ci-stacks-lib-needless-borrow
2 parents 215ed4c + 11823df commit 2d758c6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+704
-808
lines changed

clarity/src/vm/representations.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ guarded_string!(
8484
);
8585

8686
impl StacksMessageCodec for ClarityName {
87+
#[allow(clippy::needless_as_bytes)] // as_bytes isn't necessary, but verbosity is preferable in the codec impls
8788
fn consensus_serialize<W: Write>(&self, fd: &mut W) -> Result<(), codec_error> {
8889
// ClarityName can't be longer than vm::representations::MAX_STRING_LEN, which itself is
8990
// a u8, so we should be good here.
@@ -124,6 +125,7 @@ impl StacksMessageCodec for ClarityName {
124125
}
125126

126127
impl StacksMessageCodec for ContractName {
128+
#[allow(clippy::needless_as_bytes)] // as_bytes isn't necessary, but verbosity is preferable in the codec impls
127129
fn consensus_serialize<W: Write>(&self, fd: &mut W) -> Result<(), codec_error> {
128130
if self.as_bytes().len() < CONTRACT_MIN_NAME_LENGTH
129131
|| self.as_bytes().len() > CONTRACT_MAX_NAME_LENGTH

libsigner/src/v0/messages.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ pub struct PeerInfo {
283283
}
284284

285285
impl StacksMessageCodec for PeerInfo {
286+
#[allow(clippy::needless_as_bytes)] // as_bytes isn't necessary, but verbosity is preferable in the codec impls
286287
fn consensus_serialize<W: Write>(&self, fd: &mut W) -> Result<(), CodecError> {
287288
write_next(fd, &self.burn_block_height)?;
288289
write_next(fd, self.stacks_tip_consensus_hash.as_bytes())?;

pox-locking/src/events.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ use clarity::vm::costs::LimitedCostTracker;
2020
use clarity::vm::errors::Error as ClarityError;
2121
use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, ResponseData, TupleData};
2222
use clarity::vm::Value;
23-
#[cfg(test)]
23+
#[cfg(any(test, feature = "testing"))]
2424
use slog::slog_debug;
2525
use slog::slog_error;
26-
#[cfg(test)]
26+
#[cfg(any(test, feature = "testing"))]
2727
use stacks_common::debug;
2828
use stacks_common::types::StacksEpochId;
2929
use stacks_common::{error, test_debug};

pox-locking/src/events_24.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ use clarity::vm::contexts::GlobalContext;
1919
use clarity::vm::errors::Error as ClarityError;
2020
use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, TupleData};
2121
use clarity::vm::Value;
22-
#[cfg(test)]
22+
#[cfg(any(test, feature = "testing"))]
2323
use slog::slog_debug;
2424
use slog::slog_error;
25-
#[cfg(test)]
25+
#[cfg(any(test, feature = "testing"))]
2626
use stacks_common::debug;
2727
use stacks_common::{error, test_debug};
2828

stackslib/src/burnchains/affirmation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ fn inner_find_heaviest_block_commit_ptr(
937937
pub fn find_heaviest_block_commit<B: BurnchainHeaderReader>(
938938
burnchain_tx: &BurnchainDBTransaction,
939939
indexer: &B,
940-
prepare_phase_ops: &Vec<Vec<LeaderBlockCommitOp>>,
940+
prepare_phase_ops: &[Vec<LeaderBlockCommitOp>],
941941
anchor_threshold: u32,
942942
) -> Result<Option<(LeaderBlockCommitOp, Vec<Vec<bool>>, u64, u64)>, DBError> {
943943
let (pox_anchor_ptr, ancestors) =

stackslib/src/burnchains/bitcoin/bits.rs

Lines changed: 16 additions & 16 deletions
Large diffs are not rendered by default.

stackslib/src/burnchains/bitcoin/blocks.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl BitcoinMessageHandler for BitcoinBlockDownloader {
150150
None => panic!("No block header set"),
151151
Some(ref ipc_header) => {
152152
let block_hash = ipc_header.block_header.header.bitcoin_hash().clone();
153-
indexer.send_getdata(&vec![block_hash]).map(|_r| true)
153+
indexer.send_getdata(&[block_hash]).map(|_r| true)
154154
}
155155
}
156156
}
@@ -191,7 +191,7 @@ impl BitcoinMessageHandler for BitcoinBlockDownloader {
191191
);
192192

193193
// try again
194-
indexer.send_getdata(&vec![ipc_header.block_header.header.bitcoin_hash()])?;
194+
indexer.send_getdata(&[ipc_header.block_header.header.bitcoin_hash()])?;
195195
return Ok(true);
196196
}
197197

@@ -598,14 +598,14 @@ mod tests {
598598
})
599599
}
600600

601-
fn to_txid(inp: &Vec<u8>) -> Txid {
601+
fn to_txid(inp: &[u8]) -> Txid {
602602
let mut ret = [0; 32];
603603
let bytes = &inp[..inp.len()];
604604
ret.copy_from_slice(bytes);
605605
Txid(ret)
606606
}
607607

608-
fn to_block_hash(inp: &Vec<u8>) -> BurnchainHeaderHash {
608+
fn to_block_hash(inp: &[u8]) -> BurnchainHeaderHash {
609609
let mut ret = [0; 32];
610610
let bytes = &inp[..inp.len()];
611611
ret.copy_from_slice(bytes);

stackslib/src/burnchains/bitcoin/indexer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3151,7 +3151,7 @@ mod test {
31513151
assert_eq!(total_work_before, total_work_before_idempotent);
31523152

31533153
// fake block headers for mainnet 40319-40320, which is on a difficulty adjustment boundary
3154-
let bad_headers = vec![
3154+
let bad_headers = [
31553155
LoneBlockHeader {
31563156
header: BlockHeader {
31573157
version: 1,

stackslib/src/burnchains/bitcoin/network.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ impl BitcoinIndexer {
354354
}
355355

356356
/// Send a GetData message
357-
pub fn send_getdata(&mut self, block_hashes: &Vec<Sha256dHash>) -> Result<(), btc_error> {
357+
pub fn send_getdata(&mut self, block_hashes: &[Sha256dHash]) -> Result<(), btc_error> {
358358
assert!(!block_hashes.is_empty());
359359
let getdata_invs = block_hashes
360360
.iter()

stackslib/src/burnchains/bitcoin/spv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ impl SpvClient {
526526
/// * headers must be contiguous
527527
fn validate_header_integrity(
528528
start_height: u64,
529-
headers: &Vec<LoneBlockHeader>,
529+
headers: &[LoneBlockHeader],
530530
check_txcount: bool,
531531
) -> Result<(), btc_error> {
532532
if headers.is_empty() {

stackslib/src/burnchains/burnchain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl BurnchainStateTransition {
151151
sort_tx: &mut SortitionHandleTx,
152152
burnchain: &Burnchain,
153153
parent_snapshot: &BlockSnapshot,
154-
block_ops: &Vec<BlockstackOperationType>,
154+
block_ops: &[BlockstackOperationType],
155155
missed_commits: &[MissedBlockCommit],
156156
) -> Result<BurnchainStateTransition, burnchain_error> {
157157
// block commits discovered in this block.
@@ -976,7 +976,7 @@ impl Burnchain {
976976
}
977977

978978
/// Sanity check -- a list of checked ops is sorted and all vtxindexes are unique
979-
pub fn ops_are_sorted(ops: &Vec<BlockstackOperationType>) -> bool {
979+
pub fn ops_are_sorted(ops: &[BlockstackOperationType]) -> bool {
980980
if ops.len() > 1 {
981981
for i in 0..ops.len() - 1 {
982982
if ops[i].vtxindex() >= ops[i + 1].vtxindex() {

stackslib/src/burnchains/tests/burnchain.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ fn test_process_block_ops() {
271271
vec![BlockstackOperationType::LeaderKeyRegister(
272272
leader_key_3.clone(),
273273
)];
274-
let block_opshash_121 = OpsHash::from_txids(&vec![leader_key_3.txid.clone()]);
274+
let block_opshash_121 = OpsHash::from_txids(&[leader_key_3.txid.clone()]);
275275
let block_prev_chs_121 =
276276
vec![ConsensusHash::from_hex("0000000000000000000000000000000000000000").unwrap()];
277277
let mut block_121_snapshot = BlockSnapshot {
@@ -316,7 +316,7 @@ fn test_process_block_ops() {
316316
let block_ops_122 = vec![BlockstackOperationType::LeaderKeyRegister(
317317
leader_key_2.clone(),
318318
)];
319-
let block_opshash_122 = OpsHash::from_txids(&vec![leader_key_2.txid.clone()]);
319+
let block_opshash_122 = OpsHash::from_txids(&[leader_key_2.txid.clone()]);
320320
let block_prev_chs_122 = vec![
321321
block_121_snapshot.consensus_hash.clone(),
322322
ConsensusHash::from_hex("0000000000000000000000000000000000000000").unwrap(),
@@ -365,7 +365,7 @@ fn test_process_block_ops() {
365365
let block_ops_123 = vec![BlockstackOperationType::LeaderKeyRegister(
366366
leader_key_1.clone(),
367367
)];
368-
let block_opshash_123 = OpsHash::from_txids(&vec![
368+
let block_opshash_123 = OpsHash::from_txids(&[
369369
// notably, the user burns here _wont_ be included in the consensus hash
370370
leader_key_1.txid.clone(),
371371
]);
@@ -417,7 +417,7 @@ fn test_process_block_ops() {
417417

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

737737
for i in 0..32 {
738738
let mut block_ops = vec![];
739-
let burn_block_hash = BurnchainHeaderHash::from_bytes(&vec![
739+
let burn_block_hash = BurnchainHeaderHash::from_bytes(&[
740740
i + 1,
741741
i + 1,
742742
0,
@@ -780,12 +780,12 @@ fn test_burn_snapshot_sequence() {
780780
sunset_burn: 0,
781781
treatment: vec![],
782782
commit_outs: vec![],
783-
block_header_hash: BlockHeaderHash::from_bytes(&vec![
783+
block_header_hash: BlockHeaderHash::from_bytes(&[
784784
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,
785785
0, 0, 0, 0, 0, 0,
786786
])
787787
.unwrap(),
788-
new_seed: VRFSeed::from_bytes(&vec![
788+
new_seed: VRFSeed::from_bytes(&[
789789
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,
790790
0, 0, 0, 0, 0, 0,
791791
])
@@ -811,7 +811,7 @@ fn test_burn_snapshot_sequence() {
811811
.unwrap()],
812812
),
813813

814-
txid: Txid::from_bytes(&vec![
814+
txid: Txid::from_bytes(&[
815815
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,
816816
0, 0, 0, 0, 0, i,
817817
])
@@ -844,7 +844,7 @@ fn test_burn_snapshot_sequence() {
844844
.unwrap(),
845845
memo: vec![0, 0, 0, 0, i],
846846

847-
txid: Txid::from_bytes(&vec![
847+
txid: Txid::from_bytes(&[
848848
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,
849849
0, 0, 0, 0,
850850
])
@@ -891,15 +891,15 @@ fn test_burn_snapshot_sequence() {
891891
assert_eq!(snapshot.total_burn, expected_burn_total);
892892
assert_eq!(
893893
snapshot.winning_block_txid,
894-
Txid::from_bytes(&vec![
894+
Txid::from_bytes(&[
895895
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,
896896
0, 0, 0, 0, 0, i
897897
])
898898
.unwrap()
899899
);
900900
assert_eq!(
901901
snapshot.winning_stacks_block_hash,
902-
BlockHeaderHash::from_bytes(&vec![
902+
BlockHeaderHash::from_bytes(&[
903903
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,
904904
0, 0, 0, 0, 0, 0
905905
])

stackslib/src/burnchains/tests/mod.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ pub struct TestMinerFactory {
135135
impl TestMiner {
136136
pub fn new(
137137
burnchain: &Burnchain,
138-
privks: &Vec<StacksPrivateKey>,
138+
privks: Vec<StacksPrivateKey>,
139139
num_sigs: u16,
140140
hash_mode: &AddressHashMode,
141141
chain_id: u32,
142142
) -> TestMiner {
143143
TestMiner {
144144
burnchain: burnchain.clone(),
145-
privks: privks.clone(),
145+
privks,
146146
num_sigs,
147147
hash_mode: hash_mode.clone(),
148148
microblock_privks: vec![],
@@ -342,7 +342,7 @@ impl TestMinerFactory {
342342
}
343343

344344
test_debug!("New miner: {:?} {}:{:?}", &hash_mode, num_sigs, &keys);
345-
let mut m = TestMiner::new(burnchain, &keys, num_sigs, &hash_mode, self.chain_id);
345+
let mut m = TestMiner::new(burnchain, keys, num_sigs, &hash_mode, self.chain_id);
346346
m.id = self.next_miner_id;
347347
self.next_miner_id += 1;
348348
m
@@ -838,9 +838,9 @@ impl TestBurnchainNode {
838838
fn process_next_sortition(
839839
node: &mut TestBurnchainNode,
840840
fork: &mut TestBurnchainFork,
841-
miners: &mut Vec<TestMiner>,
842-
prev_keys: &Vec<LeaderKeyRegisterOp>,
843-
block_hashes: &Vec<BlockHeaderHash>,
841+
miners: &mut [TestMiner],
842+
prev_keys: &[LeaderKeyRegisterOp],
843+
block_hashes: &[BlockHeaderHash],
844844
) -> (
845845
BlockSnapshot,
846846
Vec<LeaderKeyRegisterOp>,
@@ -892,7 +892,7 @@ fn process_next_sortition(
892892
(tip_snapshot, next_prev_keys, next_commits)
893893
}
894894

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

913-
fn verify_commits_accepted(
914-
node: &TestBurnchainNode,
915-
next_block_commits: &Vec<LeaderBlockCommitOp>,
916-
) {
913+
fn verify_commits_accepted(node: &TestBurnchainNode, next_block_commits: &[LeaderBlockCommitOp]) {
917914
// all commits accepted
918915
for commit in next_block_commits.iter() {
919916
let tx_opt =

stackslib/src/chainstate/burn/db/processing.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ impl SortitionHandleTx<'_> {
116116
burnchain: &Burnchain,
117117
parent_snapshot: &BlockSnapshot,
118118
block_header: &BurnchainBlockHeader,
119-
this_block_ops: &Vec<BlockstackOperationType>,
120-
missed_commits: &Vec<MissedBlockCommit>,
119+
this_block_ops: &[BlockstackOperationType],
120+
missed_commits: &[MissedBlockCommit],
121121
next_pox_info: Option<RewardCycleInfo>,
122122
parent_pox: PoxId,
123123
reward_info: Option<&RewardSetInfo>,
@@ -428,7 +428,7 @@ mod tests {
428428
let snapshot = test_append_snapshot(
429429
&mut db,
430430
BurnchainHeaderHash([0x01; 32]),
431-
&vec![BlockstackOperationType::LeaderKeyRegister(leader_key)],
431+
&[BlockstackOperationType::LeaderKeyRegister(leader_key)],
432432
);
433433

434434
let next_block_header = BurnchainBlockHeader {

0 commit comments

Comments
 (0)