From 1d37306ce4833ba87de468dfa5360f216080b6b5 Mon Sep 17 00:00:00 2001 From: Jacinta Ferrant Date: Tue, 31 Dec 2024 15:18:47 -0500 Subject: [PATCH 1/3] Fix useless-vec warnings throughout stackslib Signed-off-by: Jacinta Ferrant --- stackslib/src/burnchains/affirmation.rs | 2 +- stackslib/src/burnchains/bitcoin/bits.rs | 32 ++-- stackslib/src/burnchains/bitcoin/blocks.rs | 10 +- stackslib/src/burnchains/bitcoin/indexer.rs | 2 +- stackslib/src/burnchains/bitcoin/network.rs | 2 +- stackslib/src/burnchains/bitcoin/spv.rs | 2 +- stackslib/src/burnchains/burnchain.rs | 4 +- stackslib/src/burnchains/tests/burnchain.rs | 24 +-- stackslib/src/burnchains/tests/mod.rs | 14 +- .../src/chainstate/burn/db/processing.rs | 6 +- stackslib/src/chainstate/burn/db/sortdb.rs | 118 +++++++------- stackslib/src/chainstate/burn/distribution.rs | 4 +- stackslib/src/chainstate/burn/mod.rs | 4 +- .../burn/operations/delegate_stx.rs | 2 +- .../burn/operations/leader_block_commit.rs | 10 +- .../burn/operations/leader_key_register.rs | 6 +- .../src/chainstate/burn/operations/mod.rs | 2 +- .../chainstate/burn/operations/stack_stx.rs | 2 +- .../burn/operations/transfer_stx.rs | 2 +- .../burn/operations/vote_for_aggregate_key.rs | 2 +- stackslib/src/chainstate/burn/sortition.rs | 2 +- stackslib/src/chainstate/coordinator/tests.rs | 42 ++--- .../src/chainstate/nakamoto/tests/mod.rs | 45 +++--- stackslib/src/chainstate/stacks/address.rs | 2 +- stackslib/src/chainstate/stacks/auth.rs | 54 +++---- stackslib/src/chainstate/stacks/block.rs | 22 +-- .../src/chainstate/stacks/boot/pox_4_tests.rs | 2 +- .../src/chainstate/stacks/db/accounts.rs | 10 +- stackslib/src/chainstate/stacks/db/blocks.rs | 42 ++--- stackslib/src/chainstate/stacks/db/mod.rs | 7 +- .../src/chainstate/stacks/db/transactions.rs | 12 +- .../src/chainstate/stacks/db/unconfirmed.rs | 6 +- stackslib/src/chainstate/stacks/index/bits.rs | 6 +- .../src/chainstate/stacks/index/cache.rs | 6 +- stackslib/src/chainstate/stacks/index/marf.rs | 18 +-- stackslib/src/chainstate/stacks/index/node.rs | 4 +- .../src/chainstate/stacks/index/proofs.rs | 8 +- .../src/chainstate/stacks/index/test/cache.rs | 6 +- .../src/chainstate/stacks/index/test/file.rs | 4 +- .../src/chainstate/stacks/index/test/marf.rs | 76 ++++----- .../src/chainstate/stacks/index/test/mod.rs | 12 +- .../src/chainstate/stacks/index/test/node.rs | 114 ++++++------- .../chainstate/stacks/index/test/storage.rs | 4 +- .../src/chainstate/stacks/index/test/trie.rs | 142 ++++++++-------- stackslib/src/chainstate/stacks/index/trie.rs | 4 +- .../src/chainstate/stacks/tests/accounting.rs | 10 +- .../stacks/tests/block_construction.rs | 10 +- .../stacks/tests/chain_histories.rs | 6 +- stackslib/src/chainstate/stacks/tests/mod.rs | 8 +- .../src/chainstate/stacks/transaction.rs | 8 +- .../src/clarity_vm/tests/epoch_switch.rs | 2 +- stackslib/src/clarity_vm/tests/events.rs | 2 +- stackslib/src/clarity_vm/tests/forking.rs | 4 +- stackslib/src/core/tests/mod.rs | 4 +- .../src/cost_estimates/tests/fee_medians.rs | 6 +- stackslib/src/net/api/tests/mod.rs | 4 +- stackslib/src/net/chat.rs | 152 +++++++++--------- stackslib/src/net/codec.rs | 38 ++--- stackslib/src/net/db.rs | 110 +++++-------- stackslib/src/net/dns.rs | 2 +- stackslib/src/net/http/tests.rs | 4 +- stackslib/src/net/mod.rs | 10 +- stackslib/src/net/neighbors/db.rs | 4 +- stackslib/src/net/p2p.rs | 10 +- stackslib/src/net/stackerdb/tests/sync.rs | 6 +- stackslib/src/net/tests/convergence.rs | 8 +- stackslib/src/net/tests/download/epoch2x.rs | 2 +- stackslib/src/net/tests/download/nakamoto.rs | 4 +- stackslib/src/net/tests/httpcore.rs | 4 +- stackslib/src/net/tests/inv/epoch2x.rs | 4 +- stackslib/src/net/tests/mod.rs | 12 +- stackslib/src/net/tests/relay/epoch2x.rs | 26 ++- stackslib/src/util_lib/bloom.rs | 4 +- stackslib/src/util_lib/db.rs | 4 +- stackslib/src/util_lib/strings.rs | 4 +- 75 files changed, 635 insertions(+), 737 deletions(-) diff --git a/stackslib/src/burnchains/affirmation.rs b/stackslib/src/burnchains/affirmation.rs index fc7398c9ff..ea2fe33787 100644 --- a/stackslib/src/burnchains/affirmation.rs +++ b/stackslib/src/burnchains/affirmation.rs @@ -933,7 +933,7 @@ fn inner_find_heaviest_block_commit_ptr( pub fn find_heaviest_block_commit( burnchain_tx: &BurnchainDBTransaction, indexer: &B, - prepare_phase_ops: &Vec>, + prepare_phase_ops: &[Vec], anchor_threshold: u32, ) -> Result>, u64, u64)>, DBError> { let (pox_anchor_ptr, ancestors) = diff --git a/stackslib/src/burnchains/bitcoin/bits.rs b/stackslib/src/burnchains/bitcoin/bits.rs index afeaefc0dc..c05385ac89 100644 --- a/stackslib/src/burnchains/bitcoin/bits.rs +++ b/stackslib/src/burnchains/bitcoin/bits.rs @@ -48,7 +48,7 @@ pub fn parse_script<'a>(script: &'a Script) -> Vec> { impl BitcoinTxInputStructured { /// Parse a script instruction stream encoding a p2pkh scritpsig into a BitcoinTxInput pub fn from_bitcoin_p2pkh_script_sig( - instructions: &Vec, + instructions: &[Instruction], input_txid: (Txid, u32), ) -> Option { if instructions.len() != 2 { @@ -277,7 +277,7 @@ impl BitcoinTxInputStructured { /// parse a p2sh scriptsig fn from_bitcoin_p2sh_multisig_script_sig( - instructions: &Vec, + instructions: &[Instruction], input_txid: (Txid, u32), ) -> Option { // format: OP_0 ... OP_m ... OP_n OP_CHECKMULTISIG @@ -328,8 +328,8 @@ impl BitcoinTxInputStructured { /// parse p2wpkh-over-p2sh public keys, given p2sh scriptsig as hash of witness fn from_bitcoin_p2wpkh_p2sh_script_sig( - instructions: &Vec, - witness: &Vec>, + instructions: &[Instruction], + witness: &[Vec], input_txid: (Txid, u32), ) -> Option { // redeem script format: OP_PUSHDATA <20-byte witness hash> @@ -378,8 +378,8 @@ impl BitcoinTxInputStructured { /// parse a p2wsh-over-p2sh multisig redeem script fn from_bitcoin_p2wsh_p2sh_multisig_script_sig( - instructions: &Vec, - witness: &Vec>, + instructions: &[Instruction], + witness: &[Vec], input_txid: (Txid, u32), ) -> Option { // redeem script format: OP_PUSHDATA <32-byte witness hash> @@ -461,7 +461,7 @@ impl BitcoinTxInputStructured { /// script. fn from_bitcoin_witness_script_sig( script_sig: &Script, - witness: &Vec>, + witness: &[Vec], input_txid: (Txid, u32), ) -> Option { let instructions = parse_script(script_sig); @@ -1062,47 +1062,47 @@ mod tests { // 0-of-0 multisig // taken from 970b435253b69cde8207b3245d7723bb24861fd7ab3cfe361f45ae8de085ac52 script: Builder::from(hex_bytes("00000001ae").unwrap()).into_script(), - result: Some(BitcoinTxInputRaw::from_hex_parts("00000001ae", &vec![])), + result: Some(BitcoinTxInputRaw::from_hex_parts("00000001ae", &[])), }, ScriptFixture { // segwit p2sh p2wsh redeem script by itself script: Builder::from(hex_bytes("2200200db5e96eaf886fab2f1a20f00528f293e9fc9fb202d2c68c2f57a41eba47b5bf").unwrap()).into_script(), - result: Some(BitcoinTxInputRaw::from_hex_parts("2200200db5e96eaf886fab2f1a20f00528f293e9fc9fb202d2c68c2f57a41eba47b5bf", &vec![])), + result: Some(BitcoinTxInputRaw::from_hex_parts("2200200db5e96eaf886fab2f1a20f00528f293e9fc9fb202d2c68c2f57a41eba47b5bf", &[])), }, ScriptFixture { // segwit p2sh p2wpkh redeem script by itself script: Builder::from(hex_bytes("160014751e76e8199196d454941c45d1b3a323f1433bd6").unwrap()).into_script(), - result: Some(BitcoinTxInputRaw::from_hex_parts("160014751e76e8199196d454941c45d1b3a323f1433bd6", &vec![])), + result: Some(BitcoinTxInputRaw::from_hex_parts("160014751e76e8199196d454941c45d1b3a323f1433bd6", &[])), }, ScriptFixture { // nonsensical 4-of-3 multisig, wth 2 signatures script: Builder::from(hex_bytes("004730440220338862b4a13d67415fdaac35d408bd2a6d86e4c3be03b7abc92ee769b254dbe1022043ba94f304aff774fdb957af078c9b302425976370cc66f42ae05382c84ea5ea014730440220338862b4a13d67415fdaac35d408bd2a6d86e4c3be03b7abc92ee769b254dbe1022043ba94f304aff774fdb957af078c9b302425976370cc66f42ae05382c84ea5ea014c69542103310188e911026cf18c3ce274e0ebb5f95b007f230d8cb7d09879d96dbeab1aff210243930746e6ed6552e03359db521b088134652905bd2d1541fa9124303a41e95621029e03a901b85534ff1e92c43c74431f7ce72046060fcf7a95c37e148f78c7725553ae").unwrap()).into_script(), - result: Some(BitcoinTxInputRaw::from_hex_parts("004730440220338862b4a13d67415fdaac35d408bd2a6d86e4c3be03b7abc92ee769b254dbe1022043ba94f304aff774fdb957af078c9b302425976370cc66f42ae05382c84ea5ea014730440220338862b4a13d67415fdaac35d408bd2a6d86e4c3be03b7abc92ee769b254dbe1022043ba94f304aff774fdb957af078c9b302425976370cc66f42ae05382c84ea5ea014c69542103310188e911026cf18c3ce274e0ebb5f95b007f230d8cb7d09879d96dbeab1aff210243930746e6ed6552e03359db521b088134652905bd2d1541fa9124303a41e95621029e03a901b85534ff1e92c43c74431f7ce72046060fcf7a95c37e148f78c7725553ae", &vec![])), + result: Some(BitcoinTxInputRaw::from_hex_parts("004730440220338862b4a13d67415fdaac35d408bd2a6d86e4c3be03b7abc92ee769b254dbe1022043ba94f304aff774fdb957af078c9b302425976370cc66f42ae05382c84ea5ea014730440220338862b4a13d67415fdaac35d408bd2a6d86e4c3be03b7abc92ee769b254dbe1022043ba94f304aff774fdb957af078c9b302425976370cc66f42ae05382c84ea5ea014c69542103310188e911026cf18c3ce274e0ebb5f95b007f230d8cb7d09879d96dbeab1aff210243930746e6ed6552e03359db521b088134652905bd2d1541fa9124303a41e95621029e03a901b85534ff1e92c43c74431f7ce72046060fcf7a95c37e148f78c7725553ae", &[])), }, ScriptFixture { // nonsensical 4-of-3 multisig, with 3 signatures script: Builder::from(hex_bytes("004730440220338862b4a13d67415fdaac35d408bd2a6d86e4c3be03b7abc92ee769b254dbe1022043ba94f304aff774fdb957af078c9b302425976370cc66f42ae05382c84ea5ea014730440220338862b4a13d67415fdaac35d408bd2a6d86e4c3be03b7abc92ee769b254dbe1022043ba94f304aff774fdb957af078c9b302425976370cc66f42ae05382c84ea5ea01483045022100be57031bf2c095945ba2876e97b3f86ee051643a29b908f22ed45ccf58620103022061e056e5f48c5a51c66604a1ca28e4bfaabab1478424c9bbb396cc6afe5c222e014c69542103310188e911026cf18c3ce274e0ebb5f95b007f230d8cb7d09879d96dbeab1aff210243930746e6ed6552e03359db521b088134652905bd2d1541fa9124303a41e95621029e03a901b85534ff1e92c43c74431f7ce72046060fcf7a95c37e148f78c7725553ae").unwrap()).into_script(), - result: Some(BitcoinTxInputRaw::from_hex_parts("004730440220338862b4a13d67415fdaac35d408bd2a6d86e4c3be03b7abc92ee769b254dbe1022043ba94f304aff774fdb957af078c9b302425976370cc66f42ae05382c84ea5ea014730440220338862b4a13d67415fdaac35d408bd2a6d86e4c3be03b7abc92ee769b254dbe1022043ba94f304aff774fdb957af078c9b302425976370cc66f42ae05382c84ea5ea01483045022100be57031bf2c095945ba2876e97b3f86ee051643a29b908f22ed45ccf58620103022061e056e5f48c5a51c66604a1ca28e4bfaabab1478424c9bbb396cc6afe5c222e014c69542103310188e911026cf18c3ce274e0ebb5f95b007f230d8cb7d09879d96dbeab1aff210243930746e6ed6552e03359db521b088134652905bd2d1541fa9124303a41e95621029e03a901b85534ff1e92c43c74431f7ce72046060fcf7a95c37e148f78c7725553ae", &vec![])) + result: Some(BitcoinTxInputRaw::from_hex_parts("004730440220338862b4a13d67415fdaac35d408bd2a6d86e4c3be03b7abc92ee769b254dbe1022043ba94f304aff774fdb957af078c9b302425976370cc66f42ae05382c84ea5ea014730440220338862b4a13d67415fdaac35d408bd2a6d86e4c3be03b7abc92ee769b254dbe1022043ba94f304aff774fdb957af078c9b302425976370cc66f42ae05382c84ea5ea01483045022100be57031bf2c095945ba2876e97b3f86ee051643a29b908f22ed45ccf58620103022061e056e5f48c5a51c66604a1ca28e4bfaabab1478424c9bbb396cc6afe5c222e014c69542103310188e911026cf18c3ce274e0ebb5f95b007f230d8cb7d09879d96dbeab1aff210243930746e6ed6552e03359db521b088134652905bd2d1541fa9124303a41e95621029e03a901b85534ff1e92c43c74431f7ce72046060fcf7a95c37e148f78c7725553ae", &[])) }, ScriptFixture { // nonsensical 4-of-3 multisig, with 4 signatures script: Builder::from(hex_bytes("004730440220338862b4a13d67415fdaac35d408bd2a6d86e4c3be03b7abc92ee769b254dbe1022043ba94f304aff774fdb957af078c9b302425976370cc66f42ae05382c84ea5ea014730440220338862b4a13d67415fdaac35d408bd2a6d86e4c3be03b7abc92ee769b254dbe1022043ba94f304aff774fdb957af078c9b302425976370cc66f42ae05382c84ea5ea01483045022100be57031bf2c095945ba2876e97b3f86ee051643a29b908f22ed45ccf58620103022061e056e5f48c5a51c66604a1ca28e4bfaabab1478424c9bbb396cc6afe5c222e01483045022100fd9c04b330810694cb4bfef793b193f9cbfaa07325700f217b9cb03e5207005302202f07e7c9c6774c5619a043752444f6da6fd81b9d9d008ec965796d87271598de014c69542103310188e911026cf18c3ce274e0ebb5f95b007f230d8cb7d09879d96dbeab1aff210243930746e6ed6552e03359db521b088134652905bd2d1541fa9124303a41e95621029e03a901b85534ff1e92c43c74431f7ce72046060fcf7a95c37e148f78c7725553ae").unwrap()).into_script(), - result: Some(BitcoinTxInputRaw::from_hex_parts("004730440220338862b4a13d67415fdaac35d408bd2a6d86e4c3be03b7abc92ee769b254dbe1022043ba94f304aff774fdb957af078c9b302425976370cc66f42ae05382c84ea5ea014730440220338862b4a13d67415fdaac35d408bd2a6d86e4c3be03b7abc92ee769b254dbe1022043ba94f304aff774fdb957af078c9b302425976370cc66f42ae05382c84ea5ea01483045022100be57031bf2c095945ba2876e97b3f86ee051643a29b908f22ed45ccf58620103022061e056e5f48c5a51c66604a1ca28e4bfaabab1478424c9bbb396cc6afe5c222e01483045022100fd9c04b330810694cb4bfef793b193f9cbfaa07325700f217b9cb03e5207005302202f07e7c9c6774c5619a043752444f6da6fd81b9d9d008ec965796d87271598de014c69542103310188e911026cf18c3ce274e0ebb5f95b007f230d8cb7d09879d96dbeab1aff210243930746e6ed6552e03359db521b088134652905bd2d1541fa9124303a41e95621029e03a901b85534ff1e92c43c74431f7ce72046060fcf7a95c37e148f78c7725553ae", &vec![])), + result: Some(BitcoinTxInputRaw::from_hex_parts("004730440220338862b4a13d67415fdaac35d408bd2a6d86e4c3be03b7abc92ee769b254dbe1022043ba94f304aff774fdb957af078c9b302425976370cc66f42ae05382c84ea5ea014730440220338862b4a13d67415fdaac35d408bd2a6d86e4c3be03b7abc92ee769b254dbe1022043ba94f304aff774fdb957af078c9b302425976370cc66f42ae05382c84ea5ea01483045022100be57031bf2c095945ba2876e97b3f86ee051643a29b908f22ed45ccf58620103022061e056e5f48c5a51c66604a1ca28e4bfaabab1478424c9bbb396cc6afe5c222e01483045022100fd9c04b330810694cb4bfef793b193f9cbfaa07325700f217b9cb03e5207005302202f07e7c9c6774c5619a043752444f6da6fd81b9d9d008ec965796d87271598de014c69542103310188e911026cf18c3ce274e0ebb5f95b007f230d8cb7d09879d96dbeab1aff210243930746e6ed6552e03359db521b088134652905bd2d1541fa9124303a41e95621029e03a901b85534ff1e92c43c74431f7ce72046060fcf7a95c37e148f78c7725553ae", &[])), }, ScriptFixture { // pushdata 64-byte 0's script: Builder::from(hex_bytes("4e404000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap()).into_script(), - result: Some(BitcoinTxInputRaw::from_hex_parts("4e404000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", &vec![])), + result: Some(BitcoinTxInputRaw::from_hex_parts("4e404000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", &[])), }, ScriptFixture { // scriptsig from mainnet transaction 09f691b2263260e71f363d1db51ff3100d285956a40cc0e4f8c8c2c4a80559b1 script: Builder::from(hex_bytes("4c500100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a29ab5f49ffff001d1dac2b7c").unwrap()).into_script(), - result: Some(BitcoinTxInputRaw::from_hex_parts("4c500100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a29ab5f49ffff001d1dac2b7c", &vec![])) + result: Some(BitcoinTxInputRaw::from_hex_parts("4c500100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a29ab5f49ffff001d1dac2b7c", &[])) }, ScriptFixture { // scriptsig from mainnet transaction 8d31992805518fd62daa3bdd2a5c4fd2cd3054c9b3dca1d78055e9528cff6adc script: Builder::from(hex_bytes("4d4001255044462d312e330a25e2e3cfd30a0a0a312030206f626a0a3c3c2f57696474682032203020522f4865696768742033203020522f547970652034203020522f537562747970652035203020522f46696c7465722036203020522f436f6c6f7253706163652037203020522f4c656e6774682038203020522f42697473506572436f6d706f6e656e7420383e3e0a73747265616d0affd8fffe00245348412d3120697320646561642121212121852fec092339759c39b1a1c63c4c97e1fffe017f46dc93a6b67e013b029aaa1db2560b45ca67d688c7f84b8c4c791fe02b3df614f86db1690901c56b45c1530afedfb76038e972722fe7ad728f0e4904e046c230570fe9d41398abe12ef5bc942be33542a4802d98b5d70f2a332ec37fac3514e74ddc0f2cc1a874cd0c78305a21566461309789606bd0bf3f98cda8044629a14d4001255044462d312e330a25e2e3cfd30a0a0a312030206f626a0a3c3c2f57696474682032203020522f4865696768742033203020522f547970652034203020522f537562747970652035203020522f46696c7465722036203020522f436f6c6f7253706163652037203020522f4c656e6774682038203020522f42697473506572436f6d706f6e656e7420383e3e0a73747265616d0affd8fffe00245348412d3120697320646561642121212121852fec092339759c39b1a1c63c4c97e1fffe017346dc9166b67e118f029ab621b2560ff9ca67cca8c7f85ba84c79030c2b3de218f86db3a90901d5df45c14f26fedfb3dc38e96ac22fe7bd728f0e45bce046d23c570feb141398bb552ef5a0a82be331fea48037b8b5d71f0e332edf93ac3500eb4ddc0decc1a864790c782c76215660dd309791d06bd0af3f98cda4bc4629b1086e879169a77ca787").unwrap()).into_script(), - result: Some(BitcoinTxInputRaw::from_hex_parts("4d4001255044462d312e330a25e2e3cfd30a0a0a312030206f626a0a3c3c2f57696474682032203020522f4865696768742033203020522f547970652034203020522f537562747970652035203020522f46696c7465722036203020522f436f6c6f7253706163652037203020522f4c656e6774682038203020522f42697473506572436f6d706f6e656e7420383e3e0a73747265616d0affd8fffe00245348412d3120697320646561642121212121852fec092339759c39b1a1c63c4c97e1fffe017f46dc93a6b67e013b029aaa1db2560b45ca67d688c7f84b8c4c791fe02b3df614f86db1690901c56b45c1530afedfb76038e972722fe7ad728f0e4904e046c230570fe9d41398abe12ef5bc942be33542a4802d98b5d70f2a332ec37fac3514e74ddc0f2cc1a874cd0c78305a21566461309789606bd0bf3f98cda8044629a14d4001255044462d312e330a25e2e3cfd30a0a0a312030206f626a0a3c3c2f57696474682032203020522f4865696768742033203020522f547970652034203020522f537562747970652035203020522f46696c7465722036203020522f436f6c6f7253706163652037203020522f4c656e6774682038203020522f42697473506572436f6d706f6e656e7420383e3e0a73747265616d0affd8fffe00245348412d3120697320646561642121212121852fec092339759c39b1a1c63c4c97e1fffe017346dc9166b67e118f029ab621b2560ff9ca67cca8c7f85ba84c79030c2b3de218f86db3a90901d5df45c14f26fedfb3dc38e96ac22fe7bd728f0e45bce046d23c570feb141398bb552ef5a0a82be331fea48037b8b5d71f0e332edf93ac3500eb4ddc0decc1a864790c782c76215660dd309791d06bd0af3f98cda4bc4629b1086e879169a77ca787", &vec![])) + result: Some(BitcoinTxInputRaw::from_hex_parts("4d4001255044462d312e330a25e2e3cfd30a0a0a312030206f626a0a3c3c2f57696474682032203020522f4865696768742033203020522f547970652034203020522f537562747970652035203020522f46696c7465722036203020522f436f6c6f7253706163652037203020522f4c656e6774682038203020522f42697473506572436f6d706f6e656e7420383e3e0a73747265616d0affd8fffe00245348412d3120697320646561642121212121852fec092339759c39b1a1c63c4c97e1fffe017f46dc93a6b67e013b029aaa1db2560b45ca67d688c7f84b8c4c791fe02b3df614f86db1690901c56b45c1530afedfb76038e972722fe7ad728f0e4904e046c230570fe9d41398abe12ef5bc942be33542a4802d98b5d70f2a332ec37fac3514e74ddc0f2cc1a874cd0c78305a21566461309789606bd0bf3f98cda8044629a14d4001255044462d312e330a25e2e3cfd30a0a0a312030206f626a0a3c3c2f57696474682032203020522f4865696768742033203020522f547970652034203020522f537562747970652035203020522f46696c7465722036203020522f436f6c6f7253706163652037203020522f4c656e6774682038203020522f42697473506572436f6d706f6e656e7420383e3e0a73747265616d0affd8fffe00245348412d3120697320646561642121212121852fec092339759c39b1a1c63c4c97e1fffe017346dc9166b67e118f029ab621b2560ff9ca67cca8c7f85ba84c79030c2b3de218f86db3a90901d5df45c14f26fedfb3dc38e96ac22fe7bd728f0e45bce046d23c570feb141398bb552ef5a0a82be331fea48037b8b5d71f0e332edf93ac3500eb4ddc0decc1a864790c782c76215660dd309791d06bd0af3f98cda4bc4629b1086e879169a77ca787", &[])) } ]; diff --git a/stackslib/src/burnchains/bitcoin/blocks.rs b/stackslib/src/burnchains/bitcoin/blocks.rs index 0cee9e60e6..959389b60b 100644 --- a/stackslib/src/burnchains/bitcoin/blocks.rs +++ b/stackslib/src/burnchains/bitcoin/blocks.rs @@ -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)) } } } @@ -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); } @@ -601,14 +599,14 @@ mod tests { }) } - fn to_txid(inp: &Vec) -> 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) -> BurnchainHeaderHash { + fn to_block_hash(inp: &[u8]) -> BurnchainHeaderHash { let mut ret = [0; 32]; let bytes = &inp[..inp.len()]; ret.copy_from_slice(bytes); diff --git a/stackslib/src/burnchains/bitcoin/indexer.rs b/stackslib/src/burnchains/bitcoin/indexer.rs index 3361301675..5263d68b34 100644 --- a/stackslib/src/burnchains/bitcoin/indexer.rs +++ b/stackslib/src/burnchains/bitcoin/indexer.rs @@ -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, diff --git a/stackslib/src/burnchains/bitcoin/network.rs b/stackslib/src/burnchains/bitcoin/network.rs index 3e8bf9340c..44aad7f6d0 100644 --- a/stackslib/src/burnchains/bitcoin/network.rs +++ b/stackslib/src/burnchains/bitcoin/network.rs @@ -354,7 +354,7 @@ impl BitcoinIndexer { } /// Send a GetData message - pub fn send_getdata(&mut self, block_hashes: &Vec) -> 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() diff --git a/stackslib/src/burnchains/bitcoin/spv.rs b/stackslib/src/burnchains/bitcoin/spv.rs index 82cbb7b7f6..f225f1af28 100644 --- a/stackslib/src/burnchains/bitcoin/spv.rs +++ b/stackslib/src/burnchains/bitcoin/spv.rs @@ -526,7 +526,7 @@ impl SpvClient { /// * headers must be contiguous fn validate_header_integrity( start_height: u64, - headers: &Vec, + headers: &[LoneBlockHeader], check_txcount: bool, ) -> Result<(), btc_error> { if headers.len() == 0 { diff --git a/stackslib/src/burnchains/burnchain.rs b/stackslib/src/burnchains/burnchain.rs index b688097d70..e2962f97ec 100644 --- a/stackslib/src/burnchains/burnchain.rs +++ b/stackslib/src/burnchains/burnchain.rs @@ -151,7 +151,7 @@ impl BurnchainStateTransition { sort_tx: &mut SortitionHandleTx, burnchain: &Burnchain, parent_snapshot: &BlockSnapshot, - block_ops: &Vec, + block_ops: &[BlockstackOperationType], missed_commits: &[MissedBlockCommit], ) -> Result { // block commits discovered in this block. @@ -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) -> 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() { diff --git a/stackslib/src/burnchains/tests/burnchain.rs b/stackslib/src/burnchains/tests/burnchain.rs index 8d72d4efa9..cd05752874 100644 --- a/stackslib/src/burnchains/tests/burnchain.rs +++ b/stackslib/src/burnchains/tests/burnchain.rs @@ -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 { @@ -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(), @@ -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(), ]); @@ -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(), )], @@ -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(), ]; @@ -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, @@ -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, ]) @@ -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, ]) @@ -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, ]) @@ -897,7 +897,7 @@ 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 ]) @@ -905,7 +905,7 @@ fn test_burn_snapshot_sequence() { ); 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 ]) diff --git a/stackslib/src/burnchains/tests/mod.rs b/stackslib/src/burnchains/tests/mod.rs index c8543b1142..287b6f6b10 100644 --- a/stackslib/src/burnchains/tests/mod.rs +++ b/stackslib/src/burnchains/tests/mod.rs @@ -135,14 +135,14 @@ pub struct TestMinerFactory { impl TestMiner { pub fn new( burnchain: &Burnchain, - privks: &Vec, + privks: &[StacksPrivateKey], num_sigs: u16, hash_mode: &AddressHashMode, chain_id: u32, ) -> TestMiner { TestMiner { burnchain: burnchain.clone(), - privks: privks.clone(), + privks: privks.to_vec(), num_sigs, hash_mode: hash_mode.clone(), microblock_privks: vec![], @@ -840,9 +840,9 @@ impl TestBurnchainNode { fn process_next_sortition( node: &mut TestBurnchainNode, fork: &mut TestBurnchainFork, - miners: &mut Vec, - prev_keys: &Vec, - block_hashes: &Vec, + miners: &mut [TestMiner], + prev_keys: &[LeaderKeyRegisterOp], + block_hashes: &[BlockHeaderHash], ) -> ( BlockSnapshot, Vec, @@ -894,7 +894,7 @@ fn process_next_sortition( (tip_snapshot, next_prev_keys, next_commits) } -fn verify_keys_accepted(node: &mut TestBurnchainNode, prev_keys: &Vec) -> () { +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(); @@ -914,7 +914,7 @@ fn verify_keys_accepted(node: &mut TestBurnchainNode, prev_keys: &Vec, + next_block_commits: &[LeaderBlockCommitOp], ) -> () { // all commits accepted for commit in next_block_commits.iter() { diff --git a/stackslib/src/chainstate/burn/db/processing.rs b/stackslib/src/chainstate/burn/db/processing.rs index 0aacd2816a..0a7e214e6d 100644 --- a/stackslib/src/chainstate/burn/db/processing.rs +++ b/stackslib/src/chainstate/burn/db/processing.rs @@ -116,8 +116,8 @@ impl<'a> SortitionHandleTx<'a> { burnchain: &Burnchain, parent_snapshot: &BlockSnapshot, block_header: &BurnchainBlockHeader, - this_block_ops: &Vec, - missed_commits: &Vec, + this_block_ops: &[BlockstackOperationType], + missed_commits: &[MissedBlockCommit], next_pox_info: Option, parent_pox: PoxId, reward_info: Option<&RewardSetInfo>, @@ -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 { diff --git a/stackslib/src/chainstate/burn/db/sortdb.rs b/stackslib/src/chainstate/burn/db/sortdb.rs index e399121e07..9352bcd34a 100644 --- a/stackslib/src/chainstate/burn/db/sortdb.rs +++ b/stackslib/src/chainstate/burn/db/sortdb.rs @@ -1233,7 +1233,7 @@ impl<'a> SortitionHandleTx<'a> { pub fn get_consumed_leader_keys( &mut self, parent_tip: &BlockSnapshot, - block_candidates: &Vec, + block_candidates: &[LeaderBlockCommitOp], ) -> Result, db_error> { // get the set of VRF keys consumed by these commits let mut leader_keys = vec![]; @@ -4120,7 +4120,7 @@ impl SortitionDB { mut after: G, ) -> Result<(), BurnchainError> where - F: FnMut(&mut SortitionDBTx, &BurnchainHeaderHash, &Vec) -> (), + F: FnMut(&mut SortitionDBTx, &BurnchainHeaderHash, &[BurnchainHeaderHash]) -> (), G: FnMut(&mut SortitionDBTx) -> (), { let mut db_tx = self.tx_begin()?; @@ -5237,7 +5237,7 @@ impl SortitionDB { /// Merge the result of get_stacks_header_hashes() into a BlockHeaderCache pub fn merge_block_header_cache( cache: &mut BlockHeaderCache, - header_data: &Vec<(ConsensusHash, Option)>, + header_data: &[(ConsensusHash, Option)], ) -> () { if header_data.len() > 0 { let mut i = header_data.len() - 1; @@ -5403,8 +5403,8 @@ impl<'a> SortitionHandleTx<'a> { &mut self, parent_snapshot: &BlockSnapshot, snapshot: &BlockSnapshot, - block_ops: &Vec, - missed_commits: &Vec, + block_ops: &[BlockstackOperationType], + missed_commits: &[MissedBlockCommit], next_pox_info: Option, reward_info: Option<&RewardSetInfo>, initialize_bonus: Option, @@ -6773,14 +6773,8 @@ pub mod tests { let mut first_sn = first_snapshot.clone(); first_sn.sortition_id = SortitionId::sentinel(); - let (index_root, pox_payout) = db_tx.index_add_fork_info( - &mut first_sn, - &first_snapshot, - &vec![], - None, - None, - None, - )?; + let (index_root, pox_payout) = + db_tx.index_add_fork_info(&mut first_sn, &first_snapshot, &[], None, None, None)?; first_snapshot.index_root = index_root; // manually insert the first block snapshot in instantiate_v1 testing code, because @@ -7003,7 +6997,7 @@ pub mod tests { pub fn test_append_snapshot_with_winner( db: &mut SortitionDB, next_hash: BurnchainHeaderHash, - block_ops: &Vec, + block_ops: &[BlockstackOperationType], parent_sn: Option, winning_block_commit: Option, ) -> BlockSnapshot { @@ -7030,7 +7024,7 @@ pub mod tests { } let index_root = tx - .append_chain_tip_snapshot(&sn_parent, &sn, block_ops, &vec![], None, None, None) + .append_chain_tip_snapshot(&sn_parent, &sn, block_ops, &[], None, None, None) .unwrap(); sn.index_root = index_root; @@ -7042,7 +7036,7 @@ pub mod tests { pub fn test_append_snapshot( db: &mut SortitionDB, next_hash: BurnchainHeaderHash, - block_ops: &Vec, + block_ops: &[BlockstackOperationType], ) -> BlockSnapshot { test_append_snapshot_with_winner(db, next_hash, block_ops, None, None) } @@ -7083,7 +7077,7 @@ pub mod tests { let snapshot = test_append_snapshot( &mut db, BurnchainHeaderHash([0x01; 32]), - &vec![BlockstackOperationType::LeaderKeyRegister( + &[BlockstackOperationType::LeaderKeyRegister( leader_key.clone(), )], ); @@ -7101,7 +7095,7 @@ pub mod tests { assert_eq!(leader_key_opt.unwrap(), leader_key); } - let new_snapshot = test_append_snapshot(&mut db, BurnchainHeaderHash([0x02; 32]), &vec![]); + let new_snapshot = test_append_snapshot(&mut db, BurnchainHeaderHash([0x02; 32]), &[]); { let ic = db.index_conn(); @@ -7204,7 +7198,7 @@ pub mod tests { let snapshot = test_append_snapshot( &mut db, BurnchainHeaderHash([0x01; 32]), - &vec![BlockstackOperationType::LeaderKeyRegister( + &[BlockstackOperationType::LeaderKeyRegister( leader_key.clone(), )], ); @@ -7221,7 +7215,7 @@ pub mod tests { let snapshot_consumed = test_append_snapshot( &mut db, BurnchainHeaderHash([0x03; 32]), - &vec![BlockstackOperationType::LeaderBlockCommit( + &[BlockstackOperationType::LeaderBlockCommit( block_commit.clone(), )], ); @@ -7235,8 +7229,7 @@ pub mod tests { } // advance and get parent - let empty_snapshot = - test_append_snapshot(&mut db, BurnchainHeaderHash([0x05; 32]), &vec![]); + let empty_snapshot = test_append_snapshot(&mut db, BurnchainHeaderHash([0x05; 32]), &[]); // test get_block_commit_parent() { @@ -7331,7 +7324,7 @@ pub mod tests { sn.consensus_hash = ConsensusHash([0x23; 20]); let index_root = tx - .append_chain_tip_snapshot(&sn_parent, &sn, &vec![], &vec![], None, None, None) + .append_chain_tip_snapshot(&sn_parent, &sn, &[], &[], None, None, None) .unwrap(); sn.index_root = index_root; @@ -7383,8 +7376,7 @@ pub mod tests { let mut db = SortitionDB::connect_test(block_height, &first_burn_hash).unwrap(); - let no_key_snapshot = - test_append_snapshot(&mut db, BurnchainHeaderHash([0x01; 32]), &vec![]); + let no_key_snapshot = test_append_snapshot(&mut db, BurnchainHeaderHash([0x01; 32]), &[]); let has_key_before = { let mut ic = SortitionHandleTx::begin(&mut db, &no_key_snapshot.sortition_id).unwrap(); @@ -7396,7 +7388,7 @@ pub mod tests { let key_snapshot = test_append_snapshot( &mut db, BurnchainHeaderHash([0x03; 32]), - &vec![BlockstackOperationType::LeaderKeyRegister( + &[BlockstackOperationType::LeaderKeyRegister( leader_key.clone(), )], ); @@ -7564,8 +7556,8 @@ pub mod tests { .append_chain_tip_snapshot( &last_snapshot, &snapshot_row, - &vec![], - &vec![], + &[], + &[], None, None, None, @@ -7814,8 +7806,8 @@ pub mod tests { .append_chain_tip_snapshot( &last_snapshot, &snapshot_row, - &vec![], - &vec![], + &[], + &[], None, None, None, @@ -7923,7 +7915,7 @@ pub mod tests { let key_snapshot = test_append_snapshot( &mut db, BurnchainHeaderHash([0x01; 32]), - &vec![BlockstackOperationType::LeaderKeyRegister( + &[BlockstackOperationType::LeaderKeyRegister( leader_key.clone(), )], ); @@ -7931,7 +7923,7 @@ pub mod tests { let commit_snapshot = test_append_snapshot( &mut db, BurnchainHeaderHash([0x03; 32]), - &vec![BlockstackOperationType::LeaderBlockCommit( + &[BlockstackOperationType::LeaderBlockCommit( block_commit.clone(), )], ); @@ -8121,8 +8113,8 @@ pub mod tests { tx.append_chain_tip_snapshot( &chain_tip, &snapshot_without_sortition, - &vec![], - &vec![], + &[], + &[], None, None, None, @@ -8150,8 +8142,8 @@ pub mod tests { tx.append_chain_tip_snapshot( &chain_tip, &snapshot_with_sortition, - &vec![], - &vec![], + &[], + &[], None, None, None, @@ -8346,8 +8338,8 @@ pub mod tests { tx.append_chain_tip_snapshot( &last_snapshot, &next_snapshot, - &vec![], - &vec![], + &[], + &[], None, None, None, @@ -8491,8 +8483,8 @@ pub mod tests { .append_chain_tip_snapshot( &last_snapshot, &next_snapshot, - &vec![], - &vec![], + &[], + &[], None, None, None, @@ -8578,8 +8570,8 @@ pub mod tests { .append_chain_tip_snapshot( &last_snapshot, &next_snapshot, - &vec![], - &vec![], + &[], + &[], None, None, None, @@ -8619,8 +8611,8 @@ pub mod tests { .append_chain_tip_snapshot( &last_snapshot, &next_snapshot, - &vec![], - &vec![], + &[], + &[], None, None, None, @@ -8822,8 +8814,8 @@ pub mod tests { .append_chain_tip_snapshot( &last_snapshot, &snapshot_row, - &vec![], - &vec![], + &[], + &[], None, None, None, @@ -9073,8 +9065,8 @@ pub mod tests { .append_chain_tip_snapshot( &last_snapshot, &snapshot, - &vec![], - &vec![], + &[], + &[], None, None, None, @@ -9711,7 +9703,7 @@ pub mod tests { 3, &BurnchainHeaderHash([0u8; 32]), 0, - &vec![ + &[ StacksEpoch { epoch_id: StacksEpochId::Epoch10, start_height: 0, @@ -9757,7 +9749,7 @@ pub mod tests { } cur_snapshot = - test_append_snapshot(&mut db, BurnchainHeaderHash([((i + 1) as u8); 32]), &vec![]); + test_append_snapshot(&mut db, BurnchainHeaderHash([((i + 1) as u8); 32]), &[]); } } @@ -9773,7 +9765,7 @@ pub mod tests { 3, &BurnchainHeaderHash([0u8; 32]), 0, - &vec![ + &[ StacksEpoch { epoch_id: StacksEpochId::Epoch10, start_height: 0, @@ -9827,7 +9819,7 @@ pub mod tests { } cur_snapshot = - test_append_snapshot(&mut db, BurnchainHeaderHash([((i + 1) as u8); 32]), &vec![]); + test_append_snapshot(&mut db, BurnchainHeaderHash([((i + 1) as u8); 32]), &[]); } } @@ -9847,7 +9839,7 @@ pub mod tests { 3, &BurnchainHeaderHash([0u8; 32]), 0, - &vec![ + &[ StacksEpoch { epoch_id: StacksEpochId::Epoch10, start_height: 0, @@ -9893,7 +9885,7 @@ pub mod tests { 3, &BurnchainHeaderHash([0u8; 32]), 0, - &vec![ + &[ StacksEpoch { epoch_id: StacksEpochId::Epoch10, start_height: 0, @@ -9939,7 +9931,7 @@ pub mod tests { 3, &BurnchainHeaderHash([0u8; 32]), 0, - &vec![ + &[ StacksEpoch { epoch_id: StacksEpochId::Epoch10, start_height: 1, @@ -9985,7 +9977,7 @@ pub mod tests { 3, &BurnchainHeaderHash([0u8; 32]), 0, - &vec![ + &[ StacksEpoch { epoch_id: StacksEpochId::Epoch10, start_height: 0, @@ -10031,7 +10023,7 @@ pub mod tests { 3, &BurnchainHeaderHash([0u8; 32]), 0, - &vec![ + &[ StacksEpoch { epoch_id: StacksEpochId::Epoch10, start_height: 0, @@ -10269,7 +10261,7 @@ pub mod tests { let key_snapshot = test_append_snapshot( &mut db, BurnchainHeaderHash([0x01; 32]), - &vec![BlockstackOperationType::LeaderKeyRegister( + &[BlockstackOperationType::LeaderKeyRegister( leader_key.clone(), )], ); @@ -10277,7 +10269,7 @@ pub mod tests { let genesis_commit_snapshot = test_append_snapshot_with_winner( &mut db, BurnchainHeaderHash([0x03; 32]), - &vec![BlockstackOperationType::LeaderBlockCommit( + &[BlockstackOperationType::LeaderBlockCommit( genesis_block_commit.clone(), )], None, @@ -10287,7 +10279,7 @@ pub mod tests { let first_block_commit_snapshot = test_append_snapshot_with_winner( &mut db, BurnchainHeaderHash([0x04; 32]), - &vec![BlockstackOperationType::LeaderBlockCommit( + &[BlockstackOperationType::LeaderBlockCommit( block_commit_1.clone(), )], None, @@ -10297,7 +10289,7 @@ pub mod tests { let second_block_commit_snapshot = test_append_snapshot_with_winner( &mut db, BurnchainHeaderHash([0x05; 32]), - &vec![BlockstackOperationType::LeaderBlockCommit( + &[BlockstackOperationType::LeaderBlockCommit( block_commit_1_1.clone(), )], None, @@ -10307,7 +10299,7 @@ pub mod tests { let third_block_commit_snapshot = test_append_snapshot_with_winner( &mut db, BurnchainHeaderHash([0x06; 32]), - &vec![BlockstackOperationType::LeaderBlockCommit( + &[BlockstackOperationType::LeaderBlockCommit( block_commit_2.clone(), )], None, @@ -10458,7 +10450,7 @@ pub mod tests { let first_burn_hash = BurnchainHeaderHash([0x00; 32]); let mut db = SortitionDB::connect_test(block_height, &first_burn_hash).unwrap(); for i in 1..11 { - test_append_snapshot(&mut db, BurnchainHeaderHash([i as u8; 32]), &vec![]); + test_append_snapshot(&mut db, BurnchainHeaderHash([i as u8; 32]), &[]); } // typical diff --git a/stackslib/src/chainstate/burn/distribution.rs b/stackslib/src/chainstate/burn/distribution.rs index 59c335cd58..57f7eacb17 100644 --- a/stackslib/src/chainstate/burn/distribution.rs +++ b/stackslib/src/chainstate/burn/distribution.rs @@ -114,8 +114,8 @@ impl BurnSamplePoint { fn sanity_check_window( miner_commitment_window: u8, - block_commits: &Vec>, - missed_commits: &Vec>, + block_commits: &[Vec], + missed_commits: &[Vec], ) { assert!( block_commits.len() <= usize::try_from(miner_commitment_window).expect("infallible") diff --git a/stackslib/src/chainstate/burn/mod.rs b/stackslib/src/chainstate/burn/mod.rs index 4552210f44..a8625f4fd7 100644 --- a/stackslib/src/chainstate/burn/mod.rs +++ b/stackslib/src/chainstate/burn/mod.rs @@ -532,8 +532,8 @@ mod tests { .append_chain_tip_snapshot( &prev_snapshot, &snapshot_row, - &vec![], - &vec![], + &[], + &[], None, None, None, diff --git a/stackslib/src/chainstate/burn/operations/delegate_stx.rs b/stackslib/src/chainstate/burn/operations/delegate_stx.rs index 130a42784b..e158323ab3 100644 --- a/stackslib/src/chainstate/burn/operations/delegate_stx.rs +++ b/stackslib/src/chainstate/burn/operations/delegate_stx.rs @@ -31,7 +31,7 @@ impl DelegateStxOp { ) } - fn parse_data(data: &Vec) -> Option { + fn parse_data(data: &[u8]) -> Option { /* Wire format: diff --git a/stackslib/src/chainstate/burn/operations/leader_block_commit.rs b/stackslib/src/chainstate/burn/operations/leader_block_commit.rs index a752131668..4d95887385 100644 --- a/stackslib/src/chainstate/burn/operations/leader_block_commit.rs +++ b/stackslib/src/chainstate/burn/operations/leader_block_commit.rs @@ -2043,7 +2043,7 @@ mod tests { StacksEpoch::all(0, 0, first_block_height), ) .unwrap(); - let block_ops = vec![ + let block_ops = [ // 122 vec![], // 123 @@ -2129,7 +2129,7 @@ mod tests { &prev_snapshot, &snapshot_row, &block_ops[i], - &vec![], + &[], None, None, None, @@ -2578,7 +2578,7 @@ mod tests { }; let mut db = SortitionDB::connect_test(first_block_height, &first_burn_hash).unwrap(); - let block_ops = vec![ + let block_ops = [ // 122 vec![], // 123 @@ -2664,7 +2664,7 @@ mod tests { &prev_snapshot, &snapshot_row, &block_ops[i], - &vec![], + &[], None, None, None, @@ -3515,7 +3515,7 @@ mod tests { first_block_height, &first_burn_hash, get_epoch_time_secs(), - &vec![ + &[ StacksEpoch { epoch_id: StacksEpochId::Epoch10, start_height: 0, diff --git a/stackslib/src/chainstate/burn/operations/leader_key_register.rs b/stackslib/src/chainstate/burn/operations/leader_key_register.rs index 5608b6739d..2647d25f4a 100644 --- a/stackslib/src/chainstate/burn/operations/leader_key_register.rs +++ b/stackslib/src/chainstate/burn/operations/leader_key_register.rs @@ -85,7 +85,7 @@ impl LeaderKeyRegisterOp { self.memo[0..20].copy_from_slice(&pubkey_hash160.0); } - fn parse_data(data: &Vec) -> Option { + fn parse_data(data: &[u8]) -> Option { /* Wire format: @@ -503,7 +503,7 @@ pub mod tests { burn_header_hash: block_123_hash.clone(), }; - let block_ops = vec![ + let block_ops = [ // 122 vec![], // 123 @@ -598,7 +598,7 @@ pub mod tests { &prev_snapshot, &snapshot_row, &block_ops[i as usize], - &vec![], + &[], None, None, None, diff --git a/stackslib/src/chainstate/burn/operations/mod.rs b/stackslib/src/chainstate/burn/operations/mod.rs index 0843e03b1e..5688fa4983 100644 --- a/stackslib/src/chainstate/burn/operations/mod.rs +++ b/stackslib/src/chainstate/burn/operations/mod.rs @@ -360,7 +360,7 @@ pub enum BlockstackOperationType { } // serialization helpers for blockstack_op_to_json function -pub fn memo_serialize(memo: &Vec) -> String { +pub fn memo_serialize(memo: &[u8]) -> String { let hex_inst = to_hex(memo); format!("0x{}", hex_inst) } diff --git a/stackslib/src/chainstate/burn/operations/stack_stx.rs b/stackslib/src/chainstate/burn/operations/stack_stx.rs index c4c54b9737..fec477a06b 100644 --- a/stackslib/src/chainstate/burn/operations/stack_stx.rs +++ b/stackslib/src/chainstate/burn/operations/stack_stx.rs @@ -183,7 +183,7 @@ impl StackStxOp { // TODO: add tests from mutation testing results #4850 #[cfg_attr(test, mutants::skip)] - fn parse_data(data: &Vec) -> Option { + fn parse_data(data: &[u8]) -> Option { /* Wire format: 0 2 3 19 20 53 69 73 diff --git a/stackslib/src/chainstate/burn/operations/transfer_stx.rs b/stackslib/src/chainstate/burn/operations/transfer_stx.rs index 9d1d562d9c..4e26479c41 100644 --- a/stackslib/src/chainstate/burn/operations/transfer_stx.rs +++ b/stackslib/src/chainstate/burn/operations/transfer_stx.rs @@ -65,7 +65,7 @@ impl TransferStxOp { } } - fn parse_data(data: &Vec) -> Option { + fn parse_data(data: &[u8]) -> Option { /* Wire format: 0 2 3 19 80 diff --git a/stackslib/src/chainstate/burn/operations/vote_for_aggregate_key.rs b/stackslib/src/chainstate/burn/operations/vote_for_aggregate_key.rs index 648859abc6..b94342b107 100644 --- a/stackslib/src/chainstate/burn/operations/vote_for_aggregate_key.rs +++ b/stackslib/src/chainstate/burn/operations/vote_for_aggregate_key.rs @@ -53,7 +53,7 @@ impl VoteForAggregateKeyOp { ) } - fn parse_data(data: &Vec) -> Option { + fn parse_data(data: &[u8]) -> Option { /* Wire format: diff --git a/stackslib/src/chainstate/burn/sortition.rs b/stackslib/src/chainstate/burn/sortition.rs index ff71b0cf10..e721e7cec4 100644 --- a/stackslib/src/chainstate/burn/sortition.rs +++ b/stackslib/src/chainstate/burn/sortition.rs @@ -1133,7 +1133,7 @@ mod test { test_append_snapshot_with_winner( &mut db, header.block_hash.clone(), - &vec![BlockstackOperationType::LeaderBlockCommit( + &[BlockstackOperationType::LeaderBlockCommit( commit_winner.clone(), )], Some(tip), diff --git a/stackslib/src/chainstate/coordinator/tests.rs b/stackslib/src/chainstate/coordinator/tests.rs index f203ea5e28..1dcdcfaaaf 100644 --- a/stackslib/src/chainstate/coordinator/tests.rs +++ b/stackslib/src/chainstate/coordinator/tests.rs @@ -1185,7 +1185,7 @@ fn missed_block_commits_2_05() { &mut burnchain, &burnchain_tip.block_hash, vec![], - vec![].iter_mut(), + [].iter_mut(), ); } else { // produce a block with one good op, @@ -1202,7 +1202,7 @@ fn missed_block_commits_2_05() { &mut burnchain, &burnchain_tip.block_hash, ops, - vec![].iter_mut(), + [].iter_mut(), ); } // handle the sortition @@ -1514,7 +1514,7 @@ fn missed_block_commits_2_1() { &mut burnchain, &burnchain_tip.block_hash, vec![], - vec![].iter_mut(), + [].iter_mut(), ); } else { // produce a block with one good op, @@ -1531,7 +1531,7 @@ fn missed_block_commits_2_1() { &mut burnchain, &burnchain_tip.block_hash, ops, - vec![].iter_mut(), + [].iter_mut(), ); } // handle the sortition @@ -1857,7 +1857,7 @@ fn late_block_commits_2_1() { &mut burnchain, &burnchain_tip.block_hash, vec![], - vec![].iter_mut(), + [].iter_mut(), ); } else { // produce a block with one good op, @@ -1874,7 +1874,7 @@ fn late_block_commits_2_1() { &mut burnchain, &burnchain_tip.block_hash, ops, - vec![].iter_mut(), + [].iter_mut(), ); } // handle the sortition @@ -2434,7 +2434,7 @@ fn test_sortition_with_reward_set() { &mut burnchain, &burnchain_tip.block_hash, ops, - vec![].iter_mut(), + [].iter_mut(), ); // handle the sortition coord.handle_new_burnchain_block().unwrap(); @@ -2680,7 +2680,7 @@ fn test_sortition_with_burner_reward_set() { &mut burnchain, &burnchain_tip.block_hash, ops, - vec![].iter_mut(), + [].iter_mut(), ); // handle the sortition coord.handle_new_burnchain_block().unwrap(); @@ -2963,7 +2963,7 @@ fn test_pox_btc_ops() { &mut burnchain, &burnchain_tip.block_hash, ops, - vec![].iter_mut(), + [].iter_mut(), ); // handle the sortition coord.handle_new_burnchain_block().unwrap(); @@ -3310,7 +3310,7 @@ fn test_stx_transfer_btc_ops() { &mut burnchain, &burnchain_tip.block_hash, ops, - vec![].iter_mut(), + [].iter_mut(), ); // handle the sortition coord.handle_new_burnchain_block().unwrap(); @@ -3666,7 +3666,7 @@ fn test_delegate_stx_btc_ops() { &mut burnchain, &burnchain_tip.block_hash, ops, - vec![].iter_mut(), + [].iter_mut(), ); // handle the sortition coord.handle_new_burnchain_block().unwrap(); @@ -3843,7 +3843,7 @@ fn test_initial_coinbase_reward_distributions() { &mut burnchain, &burnchain_tip.block_hash, vec![], - vec![].iter_mut(), + [].iter_mut(), ); // handle the sortition coord.handle_new_burnchain_block().unwrap(); @@ -3883,7 +3883,7 @@ fn test_initial_coinbase_reward_distributions() { &mut burnchain, &burnchain_tip.block_hash, vec![], - vec![].iter_mut(), + [].iter_mut(), ); coord.handle_new_burnchain_block().unwrap(); } else { @@ -3934,7 +3934,7 @@ fn test_initial_coinbase_reward_distributions() { &mut burnchain, &burnchain_tip.block_hash, ops, - vec![].iter_mut(), + [].iter_mut(), ); // handle the sortition coord.handle_new_burnchain_block().unwrap(); @@ -4131,7 +4131,7 @@ fn test_epoch_switch_cost_contract_instantiation() { &mut burnchain, &burnchain_tip.block_hash, ops, - vec![].iter_mut(), + [].iter_mut(), ); // handle the sortition coord.handle_new_burnchain_block().unwrap(); @@ -4334,7 +4334,7 @@ fn test_epoch_switch_pox_2_contract_instantiation() { &mut burnchain, &burnchain_tip.block_hash, ops, - vec![].iter_mut(), + [].iter_mut(), ); // handle the sortition coord.handle_new_burnchain_block().unwrap(); @@ -4540,7 +4540,7 @@ fn test_epoch_switch_pox_3_contract_instantiation() { &mut burnchain, &burnchain_tip.block_hash, ops, - vec![].iter_mut(), + [].iter_mut(), ); // handle the sortition coord.handle_new_burnchain_block().unwrap(); @@ -4835,7 +4835,7 @@ fn atlas_stop_start() { &mut burnchain, &burnchain_tip.block_hash, ops, - vec![].iter_mut(), + [].iter_mut(), ); // handle the sortition coord.handle_new_burnchain_block().unwrap(); @@ -5158,7 +5158,7 @@ fn test_epoch_verify_active_pox_contract() { &mut burnchain, &burnchain_tip.block_hash, ops, - vec![].iter_mut(), + [].iter_mut(), ); // handle the sortition coord.handle_new_burnchain_block().unwrap(); @@ -5478,7 +5478,7 @@ fn test_sortition_with_sunset() { &mut burnchain, &burnchain_tip.block_hash, ops, - vec![].iter_mut(), + [].iter_mut(), ); // handle the sortition coord.handle_new_burnchain_block().unwrap(); @@ -5819,7 +5819,7 @@ fn test_sortition_with_sunset_and_epoch_switch() { &mut burnchain, &burnchain_tip.block_hash, ops, - vec![].iter_mut(), + [].iter_mut(), ); // handle the sortition coord.handle_new_burnchain_block().unwrap(); diff --git a/stackslib/src/chainstate/nakamoto/tests/mod.rs b/stackslib/src/chainstate/nakamoto/tests/mod.rs index 94ef81c077..090bc76005 100644 --- a/stackslib/src/chainstate/nakamoto/tests/mod.rs +++ b/stackslib/src/chainstate/nakamoto/tests/mod.rs @@ -2191,7 +2191,7 @@ fn test_make_miners_stackerdb_config() { &last_snapshot, &snapshot, &winning_ops, - &vec![], + &[], None, None, None, @@ -3058,7 +3058,7 @@ pub mod nakamoto_block_signatures { use super::*; /// Helper function make a reward set with (PrivateKey, weight) tuples - fn make_reward_set(signers: Vec<(Secp256k1PrivateKey, u32)>) -> RewardSet { + fn make_reward_set(signers: &[(Secp256k1PrivateKey, u32)]) -> RewardSet { let mut reward_set = RewardSet::empty(); reward_set.signers = Some( signers @@ -3084,12 +3084,12 @@ pub mod nakamoto_block_signatures { #[test] // Test that signatures succeed with exactly 70% of the votes pub fn test_exactly_enough_votes() { - let signers = vec![ + let signers = [ (Secp256k1PrivateKey::default(), 35), (Secp256k1PrivateKey::default(), 35), (Secp256k1PrivateKey::default(), 30), ]; - let reward_set = make_reward_set(signers.clone()); + let reward_set = make_reward_set(&signers); let mut header = NakamotoBlockHeader::empty(); @@ -3111,12 +3111,12 @@ pub mod nakamoto_block_signatures { #[test] /// Test that signatures fail with just under 70% of the votes pub fn test_just_not_enough_votes() { - let signers = vec![ + let signers = [ (Secp256k1PrivateKey::default(), 3500), (Secp256k1PrivateKey::default(), 3499), (Secp256k1PrivateKey::default(), 3001), ]; - let reward_set = make_reward_set(signers.clone()); + let reward_set = make_reward_set(&signers); let mut header = NakamotoBlockHeader::empty(); @@ -3142,13 +3142,14 @@ pub mod nakamoto_block_signatures { #[test] /// Base success case - 3 signers of equal weight, all signing the block pub fn test_nakamoto_block_verify_signatures() { - let signers = vec![ + let signers = [ Secp256k1PrivateKey::default(), Secp256k1PrivateKey::default(), Secp256k1PrivateKey::default(), ]; - let reward_set = make_reward_set(signers.iter().map(|s| (s.clone(), 100)).collect()); + let reward_set = + make_reward_set(&signers.iter().map(|s| (s.clone(), 100)).collect::>()); let mut header = NakamotoBlockHeader::empty(); @@ -3171,12 +3172,12 @@ pub mod nakamoto_block_signatures { #[test] /// Fully signed block, but not in order fn test_out_of_order_signer_signatures() { - let signers = vec![ + let signers = [ (Secp256k1PrivateKey::default(), 100), (Secp256k1PrivateKey::default(), 100), (Secp256k1PrivateKey::default(), 100), ]; - let reward_set = make_reward_set(signers.clone()); + let reward_set = make_reward_set(&signers); let mut header = NakamotoBlockHeader::empty(); @@ -3202,12 +3203,12 @@ pub mod nakamoto_block_signatures { #[test] // Test with 3 equal signers, and only two sign fn test_insufficient_signatures() { - let signers = vec![ + let signers = [ (Secp256k1PrivateKey::default(), 100), (Secp256k1PrivateKey::default(), 100), (Secp256k1PrivateKey::default(), 100), ]; - let reward_set = make_reward_set(signers.clone()); + let reward_set = make_reward_set(&signers); let mut header = NakamotoBlockHeader::empty(); @@ -3234,13 +3235,13 @@ pub mod nakamoto_block_signatures { // Test with 4 signers, but one has 75% weight. Only the whale signs // and the block is valid fn test_single_signature_threshold() { - let signers = vec![ + let signers = [ (Secp256k1PrivateKey::default(), 75), (Secp256k1PrivateKey::default(), 10), (Secp256k1PrivateKey::default(), 5), (Secp256k1PrivateKey::default(), 10), ]; - let reward_set = make_reward_set(signers.clone()); + let reward_set = make_reward_set(&signers); let mut header = NakamotoBlockHeader::empty(); @@ -3262,9 +3263,9 @@ pub mod nakamoto_block_signatures { #[test] // Test with a signature that didn't come from the signer set fn test_invalid_signer() { - let signers = vec![(Secp256k1PrivateKey::default(), 100)]; + let signers = [(Secp256k1PrivateKey::default(), 100)]; - let reward_set = make_reward_set(signers.clone()); + let reward_set = make_reward_set(&signers); let mut header = NakamotoBlockHeader::empty(); @@ -3295,12 +3296,12 @@ pub mod nakamoto_block_signatures { #[test] fn test_duplicate_signatures() { - let signers = vec![ + let signers = [ (Secp256k1PrivateKey::default(), 100), (Secp256k1PrivateKey::default(), 100), (Secp256k1PrivateKey::default(), 100), ]; - let reward_set = make_reward_set(signers.clone()); + let reward_set = make_reward_set(&signers); let mut header = NakamotoBlockHeader::empty(); @@ -3335,14 +3336,14 @@ pub mod nakamoto_block_signatures { #[test] // Test where a signature used a different message fn test_signature_invalid_message() { - let signers = vec![ + let signers = [ (Secp256k1PrivateKey::default(), 100), (Secp256k1PrivateKey::default(), 100), (Secp256k1PrivateKey::default(), 100), (Secp256k1PrivateKey::default(), 100), ]; - let reward_set = make_reward_set(signers.clone()); + let reward_set = make_reward_set(&signers); let mut header = NakamotoBlockHeader::empty(); @@ -3376,14 +3377,14 @@ pub mod nakamoto_block_signatures { #[test] // Test where a signature is not recoverable fn test_unrecoverable_signature() { - let signers = vec![ + let signers = [ (Secp256k1PrivateKey::default(), 100), (Secp256k1PrivateKey::default(), 100), (Secp256k1PrivateKey::default(), 100), (Secp256k1PrivateKey::default(), 100), ]; - let reward_set = make_reward_set(signers.clone()); + let reward_set = make_reward_set(&signers); let mut header = NakamotoBlockHeader::empty(); diff --git a/stackslib/src/chainstate/stacks/address.rs b/stackslib/src/chainstate/stacks/address.rs index c3706a2565..c7d02b98a4 100644 --- a/stackslib/src/chainstate/stacks/address.rs +++ b/stackslib/src/chainstate/stacks/address.rs @@ -560,7 +560,7 @@ mod test { version: 1, bytes: Hash160([0xff; 20]), }; - let addr_bytes = vec![ + let addr_bytes = [ // version 0x01, // bytes 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, diff --git a/stackslib/src/chainstate/stacks/auth.rs b/stackslib/src/chainstate/stacks/auth.rs index 06cf64d037..7cf6c0b0a6 100644 --- a/stackslib/src/chainstate/stacks/auth.rs +++ b/stackslib/src/chainstate/stacks/auth.rs @@ -1478,11 +1478,11 @@ mod test { 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, ]; - let spending_conditions = vec![ + let spending_conditions = [ spending_condition_p2pkh_compressed, spending_condition_p2pkh_uncompressed, ]; - let spending_conditions_bytes = vec![ + let spending_conditions_bytes = [ spending_condition_p2pkh_compressed_bytes, spending_condition_p2pkh_uncompressed_bytes, ]; @@ -1589,11 +1589,11 @@ mod test { 0x00, 0x02, ]; - let spending_conditions = vec![ + let spending_conditions = [ spending_condition_p2sh_compressed, spending_condition_p2sh_uncompressed, ]; - let spending_conditions_bytes = vec![ + let spending_conditions_bytes = [ spending_condition_p2sh_compressed_bytes, spending_condition_p2sh_uncompressed_bytes, ]; @@ -1700,11 +1700,11 @@ mod test { 0x00, 0x02, ]; - let spending_conditions = vec![ + let spending_conditions = [ spending_condition_order_independent_p2sh_compressed, spending_condition_order_independent_p2sh_uncompressed, ]; - let spending_conditions_bytes = vec![ + let spending_conditions_bytes = [ spending_condition_order_independent_p2sh_compressed_bytes, spending_condition_order_independent_p2sh_uncompressed_bytes, ]; @@ -1743,15 +1743,10 @@ mod test { 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, ]; - let spending_conditions = vec![spending_condition_p2wpkh_compressed]; - let spending_conditions_bytes = vec![spending_condition_p2wpkh_compressed_bytes]; - - for i in 0..spending_conditions.len() { - check_codec_and_corruption::( - &spending_conditions[i], - &spending_conditions_bytes[i], - ); - } + check_codec_and_corruption::( + &spending_condition_p2wpkh_compressed, + &spending_condition_p2wpkh_compressed_bytes, + ); } #[test] @@ -1807,15 +1802,10 @@ mod test { 0x00, 0x02, ]; - let spending_conditions = vec![spending_condition_p2wsh]; - let spending_conditions_bytes = vec![spending_condition_p2wsh_bytes]; - - for i in 0..spending_conditions.len() { - check_codec_and_corruption::( - &spending_conditions[i], - &spending_conditions_bytes[i], - ); - } + check_codec_and_corruption::( + &spending_condition_p2wsh, + &spending_condition_p2wsh_bytes, + ); } #[test] @@ -1986,7 +1976,7 @@ mod test { #[test] fn tx_stacks_invalid_spending_conditions() { - let bad_hash_mode_bytes = vec![ + let bad_hash_mode_bytes = [ // singlesig // hash mode 0xff, @@ -2002,7 +1992,7 @@ mod test { 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, ]; - let bad_hash_mode_multisig_bytes = vec![ + let bad_hash_mode_multisig_bytes = [ // hash mode MultisigHashMode::P2SH as u8, // signer @@ -2017,7 +2007,7 @@ mod test { 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, ]; - let bad_hash_mode_order_independent_multisig_bytes = vec![ + let bad_hash_mode_order_independent_multisig_bytes = [ // hash mode OrderIndependentMultisigHashMode::P2SH as u8, // signer @@ -2035,7 +2025,7 @@ mod test { // this will parse into a singlesig spending condition, but data will still remain. // the reason it parses is because the public keys length field encodes a valid 2-byte // prefix of a public key, and the parser will lump it into a public key - let bad_hash_mode_singlesig_bytes_parseable = vec![ + let bad_hash_mode_singlesig_bytes_parseable = [ // hash mode SinglesigHashMode::P2PKH as u8, // signer @@ -2317,28 +2307,28 @@ mod test { ) .unwrap(); - let keys = vec![ + let keys = [ privk.clone(), privk.clone(), privk_uncompressed.clone(), privk_uncompressed.clone(), ]; - let key_modes = vec![ + let key_modes = [ TransactionPublicKeyEncoding::Compressed, TransactionPublicKeyEncoding::Compressed, TransactionPublicKeyEncoding::Uncompressed, TransactionPublicKeyEncoding::Uncompressed, ]; - let auth_flags = vec![ + let auth_flags = [ TransactionAuthFlags::AuthStandard, TransactionAuthFlags::AuthSponsored, TransactionAuthFlags::AuthStandard, TransactionAuthFlags::AuthSponsored, ]; - let tx_fees = vec![123, 456, 123, 456]; + let tx_fees = [123, 456, 123, 456]; let nonces: Vec = vec![1, 2, 3, 4]; diff --git a/stackslib/src/chainstate/stacks/block.rs b/stackslib/src/chainstate/stacks/block.rs index 85bfcc5576..f4391d7c4d 100644 --- a/stackslib/src/chainstate/stacks/block.rs +++ b/stackslib/src/chainstate/stacks/block.rs @@ -460,7 +460,7 @@ impl StacksBlock { } /// verify all txs are same mainnet/testnet - pub fn validate_transactions_network(txs: &Vec, mainnet: bool) -> bool { + pub fn validate_transactions_network(txs: &[StacksTransaction], mainnet: bool) -> bool { for tx in txs { if mainnet && !tx.is_mainnet() { warn!("Tx {} is not mainnet", tx.txid()); @@ -474,7 +474,7 @@ impl StacksBlock { } /// verify all txs are same chain ID - pub fn validate_transactions_chain_id(txs: &Vec, chain_id: u32) -> bool { + pub fn validate_transactions_chain_id(txs: &[StacksTransaction], chain_id: u32) -> bool { for tx in txs { if tx.chain_id != chain_id { warn!( @@ -490,7 +490,7 @@ impl StacksBlock { } /// verify anchor modes - pub fn validate_anchor_mode(txs: &Vec, anchored: bool) -> bool { + pub fn validate_anchor_mode(txs: &[StacksTransaction], anchored: bool) -> bool { for tx in txs { match (anchored, tx.anchor_mode) { (true, TransactionAnchorMode::OffChainOnly) => { @@ -1500,8 +1500,8 @@ mod test { let txs_bad_anchor = vec![tx_coinbase.clone(), tx_invalid_anchor.clone()]; let txs_dup = vec![tx_coinbase.clone(), tx_dup.clone(), tx_dup.clone()]; - let get_tx_root = |txs: &Vec| { - let txid_vecs = txs.iter().map(|tx| tx.txid().as_bytes().to_vec()).collect(); + let get_tx_root = |txs: &[StacksTransaction]| { + let txid_vecs: Vec<_> = txs.iter().map(|tx| tx.txid().as_bytes().to_vec()).collect(); let merkle_tree = MerkleTree::::new(&txid_vecs); let tx_merkle_root = merkle_tree.root(); @@ -1524,7 +1524,7 @@ mod test { block_header_dup_tx.tx_merkle_root = get_tx_root(&txs_dup); let mut block_header_empty = header.clone(); - block_header_empty.tx_merkle_root = get_tx_root(&vec![]); + block_header_empty.tx_merkle_root = get_tx_root(&[]); let invalid_blocks = vec![ ( @@ -1627,8 +1627,8 @@ mod test { let txs_bad_anchor = vec![tx_invalid_anchor.clone()]; let txs_dup = vec![tx_dup.clone(), tx_dup.clone()]; - let get_tx_root = |txs: &Vec| { - let txid_vecs = txs.iter().map(|tx| tx.txid().as_bytes().to_vec()).collect(); + let get_tx_root = |txs: &[StacksTransaction]| { + let txid_vecs: Vec<_> = txs.iter().map(|tx| tx.txid().as_bytes().to_vec()).collect(); let merkle_tree = MerkleTree::::new(&txid_vecs); let tx_merkle_root = merkle_tree.root(); @@ -1648,7 +1648,7 @@ mod test { block_header_dup_tx.tx_merkle_root = get_tx_root(&txs_dup); let mut block_header_empty = header.clone(); - block_header_empty.tx_merkle_root = get_tx_root(&vec![]); + block_header_empty.tx_merkle_root = get_tx_root(&[]); let invalid_blocks = vec![ ( @@ -1717,8 +1717,8 @@ mod test { StacksEpochId::Epoch25, StacksEpochId::Epoch30, ]; - let get_tx_root = |txs: &Vec| { - let txid_vecs = txs.iter().map(|tx| tx.txid().as_bytes().to_vec()).collect(); + let get_tx_root = |txs: &[StacksTransaction]| { + let txid_vecs: Vec<_> = txs.iter().map(|tx| tx.txid().as_bytes().to_vec()).collect(); let merkle_tree = MerkleTree::::new(&txid_vecs); let tx_merkle_root = merkle_tree.root(); diff --git a/stackslib/src/chainstate/stacks/boot/pox_4_tests.rs b/stackslib/src/chainstate/stacks/boot/pox_4_tests.rs index 14dc9e75ab..453667eb9d 100644 --- a/stackslib/src/chainstate/stacks/boot/pox_4_tests.rs +++ b/stackslib/src/chainstate/stacks/boot/pox_4_tests.rs @@ -2962,7 +2962,7 @@ fn pox_4_revoke_delegate_stx_events() { } fn verify_signer_key_sig( - signature: &Vec, + signature: &[u8], signing_key: &Secp256k1PublicKey, pox_addr: &PoxAddress, peer: &mut TestPeer, diff --git a/stackslib/src/chainstate/stacks/db/accounts.rs b/stackslib/src/chainstate/stacks/db/accounts.rs index bf84cc1362..15d9481904 100644 --- a/stackslib/src/chainstate/stacks/db/accounts.rs +++ b/stackslib/src/chainstate/stacks/db/accounts.rs @@ -1387,7 +1387,7 @@ mod test { StacksEpochId::Epoch2_05, &participant, &participant, - &vec![], + &[], &MinerPaymentSchedule::genesis(true), None, ); @@ -1418,7 +1418,7 @@ mod test { StacksEpochId::Epoch2_05, &participant, &participant, - &vec![], + &[], &MinerPaymentSchedule::genesis(true), None, ); @@ -1461,7 +1461,7 @@ mod test { StacksEpochId::Epoch2_05, &miner, &miner, - &vec![user.clone()], + &[user.clone()], &MinerPaymentSchedule::genesis(true), None, ); @@ -1470,7 +1470,7 @@ mod test { StacksEpochId::Epoch2_05, &user, &miner, - &vec![user.clone()], + &[user.clone()], &MinerPaymentSchedule::genesis(true), None, ); @@ -1511,7 +1511,7 @@ mod test { StacksEpochId::Epoch2_05, &participant, &participant, - &vec![], + &[], &parent_participant, None, ); diff --git a/stackslib/src/chainstate/stacks/db/blocks.rs b/stackslib/src/chainstate/stacks/db/blocks.rs index 233a9d5978..86ea802d41 100644 --- a/stackslib/src/chainstate/stacks/db/blocks.rs +++ b/stackslib/src/chainstate/stacks/db/blocks.rs @@ -670,7 +670,7 @@ impl StacksChainState { ) -> Result<(), Error> { let block_path = StacksChainState::make_block_dir(blocks_path, consensus_hash, &block_hash)?; - StacksChainState::atomic_file_write(&block_path, &vec![]) + StacksChainState::atomic_file_write(&block_path, &[]) } /// Mark a block in the filesystem as invalid @@ -2559,7 +2559,7 @@ impl StacksChainState { StacksChainState::free_block(blocks_path, consensus_hash, anchored_block_hash); } Err(_) => { - StacksChainState::atomic_file_write(&block_path, &vec![])?; + StacksChainState::atomic_file_write(&block_path, &[])?; } } @@ -3584,7 +3584,7 @@ impl StacksChainState { sort_ic: &SortitionDBConn, snapshot: &BlockSnapshot, block: &StacksBlock, - microblocks: &Vec, + microblocks: &[StacksMicroblock], ) -> Result<(), Error> { let parent_sn = match SortitionDB::get_block_snapshot_for_winning_stacks_block( sort_ic, @@ -5048,7 +5048,7 @@ impl StacksChainState { burn_tip_height: u32, parent_consensus_hash: ConsensusHash, parent_header_hash: BlockHeaderHash, - parent_microblocks: &Vec, + parent_microblocks: &[StacksMicroblock], mainnet: bool, miner_id_opt: Option, ) -> Result, Error> { @@ -5401,7 +5401,7 @@ impl StacksChainState { chain_tip_burn_header_timestamp: u64, block: &StacksBlock, block_size: u64, - microblocks: &Vec, // parent microblocks + microblocks: &[StacksMicroblock], // parent microblocks burnchain_commit_burn: u64, burnchain_sortition_burn: u64, affirmation_weight: u64, @@ -7165,7 +7165,7 @@ pub mod test { all_txs[3 * i + 2].clone(), ]; - let txid_vecs = txs.iter().map(|tx| tx.txid().as_bytes().to_vec()).collect(); + let txid_vecs: Vec<_> = txs.iter().map(|tx| tx.txid().as_bytes().to_vec()).collect(); let merkle_tree = MerkleTree::::new(&txid_vecs); let tx_merkle_root = merkle_tree.root(); @@ -7205,7 +7205,7 @@ pub mod test { } fn resign_microblocks( - microblocks: &mut Vec, + microblocks: &mut [StacksMicroblock], privk: &StacksPrivateKey, ) -> BlockHeaderHash { for i in 0..microblocks.len() { @@ -8618,7 +8618,7 @@ pub mod test { let res = StacksChainState::validate_parent_microblock_stream( &block.header, &child_block_header_empty, - &vec![], + &[], true, ); assert!(res.is_some()); @@ -8846,7 +8846,7 @@ pub mod test { conflicting_microblock.txs.push(extra_tx); - let txid_vecs = conflicting_microblock + let txid_vecs: Vec<_> = conflicting_microblock .txs .iter() .map(|tx| tx.txid().as_bytes().to_vec()) @@ -8907,14 +8907,14 @@ pub mod test { block_3.header.parent_block = block_2.block_hash(); block_4.header.parent_block = block_3.block_hash(); - let consensus_hashes = vec![ + let consensus_hashes = [ ConsensusHash([2u8; 20]), ConsensusHash([3u8; 20]), ConsensusHash([4u8; 20]), ConsensusHash([5u8; 20]), ]; - let parent_consensus_hashes = vec![ + let parent_consensus_hashes = [ FIRST_BURNCHAIN_CONSENSUS_HASH, ConsensusHash([2u8; 20]), ConsensusHash([3u8; 20]), @@ -9043,14 +9043,14 @@ pub mod test { block_3.header.parent_block = block_2.block_hash(); block_4.header.parent_block = block_3.block_hash(); - let consensus_hashes = vec![ + let consensus_hashes = [ ConsensusHash([2u8; 20]), ConsensusHash([3u8; 20]), ConsensusHash([4u8; 20]), ConsensusHash([5u8; 20]), ]; - let parent_consensus_hashes = vec![ + let parent_consensus_hashes = [ FIRST_BURNCHAIN_CONSENSUS_HASH, ConsensusHash([2u8; 20]), ConsensusHash([3u8; 20]), @@ -9188,14 +9188,14 @@ pub mod test { block_3.header.parent_block = block_1.block_hash(); block_4.header.parent_block = block_3.block_hash(); - let consensus_hashes = vec![ + let consensus_hashes = [ ConsensusHash([2u8; 20]), ConsensusHash([3u8; 20]), ConsensusHash([4u8; 20]), ConsensusHash([5u8; 20]), ]; - let parent_consensus_hashes = vec![ + let parent_consensus_hashes = [ FIRST_BURNCHAIN_CONSENSUS_HASH, ConsensusHash([2u8; 20]), ConsensusHash([3u8; 20]), @@ -9380,7 +9380,7 @@ pub mod test { block_4.header.parent_microblock = mblocks[2].block_hash(); block_4.header.parent_microblock_sequence = mblocks[2].header.sequence; - let consensus_hashes = vec![ + let consensus_hashes = [ ConsensusHash([2u8; 20]), ConsensusHash([3u8; 20]), ConsensusHash([4u8; 20]), @@ -9511,14 +9511,14 @@ pub mod test { microblocks.push(mblocks); } - let consensus_hashes = vec![ + let consensus_hashes = [ ConsensusHash([2u8; 20]), ConsensusHash([3u8; 20]), ConsensusHash([4u8; 20]), ConsensusHash([5u8; 20]), ]; - let parent_consensus_hashes = vec![ + let parent_consensus_hashes = [ ConsensusHash([1u8; 20]), ConsensusHash([2u8; 20]), ConsensusHash([3u8; 20]), @@ -9935,9 +9935,9 @@ pub mod test { } } - pub fn decode_microblock_stream(mblock_bytes: &Vec) -> Vec { + pub fn decode_microblock_stream(mblock_bytes: &[u8]) -> Vec { // decode stream - let mut mblock_ptr = mblock_bytes.as_slice(); + let mut mblock_ptr = mblock_bytes; let mut mblocks = vec![]; loop { test_debug!("decoded {}", mblocks.len()); @@ -10637,7 +10637,7 @@ pub mod test { block_3.header.parent_microblock = mblocks_2[2].block_hash(); block_3.header.parent_microblock_sequence = mblocks_2[2].header.sequence; - let consensus_hashes = vec![ + let consensus_hashes = [ ConsensusHash([2u8; 20]), ConsensusHash([3u8; 20]), ConsensusHash([4u8; 20]), diff --git a/stackslib/src/chainstate/stacks/db/mod.rs b/stackslib/src/chainstate/stacks/db/mod.rs index ffdea5a7dd..6448142fa3 100644 --- a/stackslib/src/chainstate/stacks/db/mod.rs +++ b/stackslib/src/chainstate/stacks/db/mod.rs @@ -1705,8 +1705,7 @@ impl StacksChainState { &first_index_hash ); - let first_root_hash = - tx.put_indexed_all(&parent_hash, &first_index_hash, &vec![], &vec![])?; + let first_root_hash = tx.put_indexed_all(&parent_hash, &first_index_hash, &[], &[])?; test_debug!( "Boot code headers index_commit {}-{}", @@ -2643,8 +2642,8 @@ impl StacksChainState { let root_hash = headers_tx.put_indexed_all( &parent_hash, &new_tip.index_block_hash(new_consensus_hash), - &vec![], - &vec![], + &[], + &[], )?; let index_block_hash = new_tip.index_block_hash(&new_consensus_hash); test_debug!( diff --git a/stackslib/src/chainstate/stacks/db/transactions.rs b/stackslib/src/chainstate/stacks/db/transactions.rs index 3df99ea886..f4f049dfd8 100644 --- a/stackslib/src/chainstate/stacks/db/transactions.rs +++ b/stackslib/src/chainstate/stacks/db/transactions.rs @@ -574,7 +574,7 @@ impl StacksChainState { /// Return true if they all pass. /// Return false if at least one fails. fn check_transaction_postconditions( - post_conditions: &Vec, + post_conditions: &[TransactionPostCondition], post_condition_mode: &TransactionPostConditionMode, origin_account: &StacksAccount, asset_map: &AssetMap, @@ -2234,15 +2234,15 @@ pub mod test { &BlockHeaderHash([(dbi + 1) as u8; 32]), ); - let contracts = vec![ + let contracts = [ contract_correct, contract_correct, contract_syntax_error, // should still be mined, even though analysis fails ]; - let expected_behavior = vec![true, false, true]; + let expected_behavior = [true, false, true]; - let contract_names = vec!["hello-world-0", "hello-world-0", "hello-world-1"]; + let contract_names = ["hello-world-0", "hello-world-0", "hello-world-1"]; let mut next_nonce = 0; for i in 0..contracts.len() { @@ -2433,13 +2433,13 @@ pub mod test { &BlockHeaderHash([(dbi + 1) as u8; 32]), ); - let contracts = vec![ + let contracts = [ contract_correct, contract_runtime_error_definition, contract_runtime_error_bare_code, ]; - let contract_names = vec!["hello-world-0", "hello-world-1", "hello-world-2"]; + let contract_names = ["hello-world-0", "hello-world-1", "hello-world-2"]; for i in 0..contracts.len() { let contract_name = contract_names[i].to_string(); diff --git a/stackslib/src/chainstate/stacks/db/unconfirmed.rs b/stackslib/src/chainstate/stacks/db/unconfirmed.rs index 6f7a9fe9ea..0e7f178cc3 100644 --- a/stackslib/src/chainstate/stacks/db/unconfirmed.rs +++ b/stackslib/src/chainstate/stacks/db/unconfirmed.rs @@ -767,7 +767,7 @@ mod test { last_block = Some(stacks_block.clone()); let (_, _, consensus_hash) = peer.next_burnchain_block(burn_ops.clone()); - peer.process_stacks_epoch_at_tip(&stacks_block, &vec![]); + peer.process_stacks_epoch_at_tip(&stacks_block, &[]); let canonical_tip = StacksBlockId::new(&consensus_hash, &stacks_block.block_hash()); @@ -1004,7 +1004,7 @@ mod test { last_block = Some(stacks_block.clone()); let (_, _, consensus_hash) = peer.next_burnchain_block(burn_ops.clone()); - peer.process_stacks_epoch_at_tip(&stacks_block, &vec![]); + peer.process_stacks_epoch_at_tip(&stacks_block, &[]); let canonical_tip = StacksBlockId::new(&consensus_hash, &stacks_block.block_hash()); @@ -1299,7 +1299,7 @@ mod test { last_block = Some(stacks_block.clone()); let (_, _, consensus_hash) = peer.next_burnchain_block(burn_ops.clone()); - peer.process_stacks_epoch_at_tip(&stacks_block, &vec![]); + peer.process_stacks_epoch_at_tip(&stacks_block, &[]); let canonical_tip = StacksBlockHeader::make_index_block_hash( &consensus_hash, diff --git a/stackslib/src/chainstate/stacks/index/bits.rs b/stackslib/src/chainstate/stacks/index/bits.rs index 6397cee3a3..8b48d29b74 100644 --- a/stackslib/src/chainstate/stacks/index/bits.rs +++ b/stackslib/src/chainstate/stacks/index/bits.rs @@ -36,7 +36,7 @@ use crate::chainstate::stacks::index::{BlockMap, Error, MarfTrieId, TrieLeaf}; /// Get the size of a Trie path (note that a Trie path is 32 bytes long, and can definitely _not_ /// be over 255 bytes). -pub fn get_path_byte_len(p: &Vec) -> usize { +pub fn get_path_byte_len(p: &[u8]) -> usize { assert!(p.len() < 255); let path_len_byte_len = 1; path_len_byte_len + p.len() @@ -157,7 +157,7 @@ pub fn ptrs_from_bytes( /// Calculate the hash of a TrieNode, given its childrens' hashes. pub fn get_node_hash + std::fmt::Debug>( node: &T, - child_hashes: &Vec, + child_hashes: &[TrieHash], map: &mut M, ) -> TrieHash { let mut hasher = TrieHasher::new(); @@ -200,7 +200,7 @@ pub fn get_leaf_hash(node: &TrieLeaf) -> TrieHash { pub fn get_nodetype_hash_bytes( node: &TrieNodeType, - child_hash_bytes: &Vec, + child_hash_bytes: &[TrieHash], map: &mut M, ) -> TrieHash { match node { diff --git a/stackslib/src/chainstate/stacks/index/cache.rs b/stackslib/src/chainstate/stacks/index/cache.rs index 7547fd6d80..d5ba5ae5f6 100644 --- a/stackslib/src/chainstate/stacks/index/cache.rs +++ b/stackslib/src/chainstate/stacks/index/cache.rs @@ -414,14 +414,14 @@ pub mod test { if batch_size > 0 { for b in (0..block_data.len()).step_by(batch_size) { let batch = &block_data[b..cmp::min(block_data.len(), b + batch_size)]; - let keys = batch.iter().map(|(k, _)| k.clone()).collect(); + let keys: Vec<_> = batch.iter().map(|(k, _)| k.clone()).collect(); let values = batch.iter().map(|(_, v)| v.clone()).collect(); marf.insert_batch(&keys, values).unwrap(); } } else { for (key, value) in block_data.iter() { let path = TrieHash::from_key(key); - let leaf = TrieLeaf::from_value(&vec![], value.clone()); + let leaf = TrieLeaf::from_value(&[], value.clone()); marf.insert_raw(path, leaf).unwrap(); } } @@ -444,7 +444,7 @@ pub mod test { test_debug!("Read block {}", i); for (key, value) in block_data.iter() { let path = TrieHash::from_key(key); - let marf_leaf = TrieLeaf::from_value(&vec![], value.clone()); + let marf_leaf = TrieLeaf::from_value(&[], value.clone()); let read_time = SystemTime::now(); let leaf = MARF::get_path( diff --git a/stackslib/src/chainstate/stacks/index/marf.rs b/stackslib/src/chainstate/stacks/index/marf.rs index a4082627fd..85a3380be3 100644 --- a/stackslib/src/chainstate/stacks/index/marf.rs +++ b/stackslib/src/chainstate/stacks/index/marf.rs @@ -514,11 +514,7 @@ impl<'a, T: MarfTrieId> MarfTransaction<'a, T> { /// Insert a batch of key/value pairs. More efficient than inserting them individually, since /// the trie root hash will only be calculated once (which is an O(log B) operation). - pub fn insert_batch( - &mut self, - keys: &Vec, - values: Vec, - ) -> Result<(), Error> { + pub fn insert_batch(&mut self, keys: &[String], values: Vec) -> Result<(), Error> { if self.storage.readonly() { return Err(Error::ReadOnlyError); } @@ -789,7 +785,7 @@ impl MARF { trace!("Brand new storage -- start with {:?}", new_bhh); storage.extend_to_block(new_bhh)?; let node = TrieNode256::new(&[]); - let hash = get_node_hash(&node, &vec![], storage.deref_mut()); + let hash = get_node_hash(&node, &[], storage.deref_mut()); let root_ptr = storage.root_ptr(); storage.write_nodetype(root_ptr, &TrieNodeType::Node256(Box::new(node)), hash)?; Ok(()) @@ -1028,7 +1024,7 @@ impl MARF { storage.format()?; storage.extend_to_block(first_block_hash)?; let node = TrieNode256::new(&[]); - let hash = get_node_hash(&node, &vec![], storage.deref_mut()); + let hash = get_node_hash(&node, &[], storage.deref_mut()); let root_ptr = storage.root_ptr(); let node_type = TrieNodeType::Node256(Box::new(node)); storage.write_nodetype(root_ptr, &node_type, hash) @@ -1343,7 +1339,7 @@ impl MARF { fn inner_insert_batch( conn: &mut TrieStorageTransaction, block_hash: &T, - keys: &Vec, + keys: &[String], values: Vec, ) -> Result<(), Error> { assert_eq!(keys.len(), values.len()); @@ -1441,11 +1437,7 @@ impl MARF { /// Insert a batch of key/value pairs. More efficient than inserting them individually, since /// the trie root hash will only be calculated once (which is an O(log B) operation). - pub fn insert_batch( - &mut self, - keys: &Vec, - values: Vec, - ) -> Result<(), Error> { + pub fn insert_batch(&mut self, keys: &[String], values: Vec) -> Result<(), Error> { if self.storage.readonly() { return Err(Error::ReadOnlyError); } diff --git a/stackslib/src/chainstate/stacks/index/node.rs b/stackslib/src/chainstate/stacks/index/node.rs index da9fc8bbd2..7d6a9d651c 100644 --- a/stackslib/src/chainstate/stacks/index/node.rs +++ b/stackslib/src/chainstate/stacks/index/node.rs @@ -584,7 +584,7 @@ impl PartialEq for TrieLeaf { } impl TrieLeaf { - pub fn new(path: &[u8], data: &Vec) -> TrieLeaf { + pub fn new(path: &[u8], data: &[u8]) -> TrieLeaf { assert!(data.len() <= 40); let mut bytes = [0u8; 40]; bytes.copy_from_slice(&data[..]); @@ -1144,7 +1144,7 @@ impl TrieNode for TrieLeaf { } fn empty() -> TrieLeaf { - TrieLeaf::new(&[], &[0u8; 40].to_vec()) + TrieLeaf::new(&[], &[0u8; 40]) } fn walk(&self, _chr: u8) -> Option { diff --git a/stackslib/src/chainstate/stacks/index/proofs.rs b/stackslib/src/chainstate/stacks/index/proofs.rs index 85e91ebefb..446e437717 100644 --- a/stackslib/src/chainstate/stacks/index/proofs.rs +++ b/stackslib/src/chainstate/stacks/index/proofs.rs @@ -369,7 +369,7 @@ impl TrieMerkleProof { fn make_proof_hashes( node: &TrieNodeType, - all_hashes: &Vec, + all_hashes: &[TrieHash], chr: u8, ) -> Result, Error> { let mut hashes = vec![]; @@ -834,7 +834,7 @@ impl TrieMerkleProof { /// Given a list of non-backptr ptrs and a root block header hash, calculate a Merkle proof. fn make_segment_proof( storage: &mut TrieStorageConnection, - ptrs: &Vec, + ptrs: &[TriePtr], starting_chr: u8, ) -> Result>, Error> { trace!("make_segment_proof: ptrs = {:?}", &ptrs); @@ -1003,7 +1003,7 @@ impl TrieMerkleProof { /// * segment proof i+1 must be a prefix of segment proof i /// * segment proof 0 must end in a leaf /// * all segment proofs must end in a Node256 (a root) - fn is_proof_well_formed(proof: &Vec>, expected_path: &TrieHash) -> bool { + fn is_proof_well_formed(proof: &[TrieMerkleProofType], expected_path: &TrieHash) -> bool { if proof.len() == 0 { trace!("Proof is empty"); return false; @@ -1119,7 +1119,7 @@ impl TrieMerkleProof { /// headers. /// NOTE: Trie root hashes are globally unique by design, even if they represent the same contents, so the root_to_block map is bijective with high probability. pub fn verify_proof( - proof: &Vec>, + proof: &[TrieMerkleProofType], path: &TrieHash, value: &MARFValue, root_hash: &TrieHash, diff --git a/stackslib/src/chainstate/stacks/index/test/cache.rs b/stackslib/src/chainstate/stacks/index/test/cache.rs index 1abd0e741a..93f57e8511 100644 --- a/stackslib/src/chainstate/stacks/index/test/cache.rs +++ b/stackslib/src/chainstate/stacks/index/test/cache.rs @@ -99,14 +99,14 @@ fn test_marf_with_cache( if batch_size > 0 { for b in (0..block_data.len()).step_by(batch_size) { let batch = &block_data[b..cmp::min(block_data.len(), b + batch_size)]; - let keys = batch.iter().map(|(k, _)| k.clone()).collect(); + let keys: Vec<_> = batch.iter().map(|(k, _)| k.clone()).collect(); let values = batch.iter().map(|(_, v)| v.clone()).collect(); marf.insert_batch(&keys, values).unwrap(); } } else { for (key, value) in block_data.iter() { let path = TrieHash::from_key(key); - let leaf = TrieLeaf::from_value(&vec![], value.clone()); + let leaf = TrieLeaf::from_value(&[], value.clone()); marf.insert_raw(path, leaf).unwrap(); } } @@ -129,7 +129,7 @@ fn test_marf_with_cache( test_debug!("Read block {}", i); for (key, value) in block_data.iter() { let path = TrieHash::from_key(key); - let marf_leaf = TrieLeaf::from_value(&vec![], value.clone()); + let marf_leaf = TrieLeaf::from_value(&[], value.clone()); let read_time = SystemTime::now(); let leaf = MARF::get_path( diff --git a/stackslib/src/chainstate/stacks/index/test/file.rs b/stackslib/src/chainstate/stacks/index/test/file.rs index 19ac5e60e4..423292b5c6 100644 --- a/stackslib/src/chainstate/stacks/index/test/file.rs +++ b/stackslib/src/chainstate/stacks/index/test/file.rs @@ -107,7 +107,7 @@ fn test_migrate_existing_trie_blobs() { for (key, value) in block_data.iter() { let path = TrieHash::from_key(key); - let leaf = TrieLeaf::from_value(&vec![], value.clone()); + let leaf = TrieLeaf::from_value(&[], value.clone()); marf.insert_raw(path, leaf).unwrap(); } marf.commit().unwrap(); @@ -148,7 +148,7 @@ fn test_migrate_existing_trie_blobs() { for (i, block_data) in data.iter().enumerate() { for (key, value) in block_data.iter() { let path = TrieHash::from_key(key); - let marf_leaf = TrieLeaf::from_value(&vec![], value.clone()); + let marf_leaf = TrieLeaf::from_value(&[], value.clone()); let leaf = MARF::get_path( &mut marf.borrow_storage_backend(), diff --git a/stackslib/src/chainstate/stacks/index/test/marf.rs b/stackslib/src/chainstate/stacks/index/test/marf.rs index e7535e9553..8bab9c7dbc 100644 --- a/stackslib/src/chainstate/stacks/index/test/marf.rs +++ b/stackslib/src/chainstate/stacks/index/test/marf.rs @@ -53,7 +53,7 @@ fn marf_insert_different_leaf_same_block_100() { let path = TrieHash::from_bytes(&path_bytes).unwrap(); for i in 0..100 { - let value = TrieLeaf::new(&vec![], &[i as u8; 40].to_vec()); + let value = TrieLeaf::new(&[], &[i as u8; 40]); marf.insert_raw(path.clone(), value).unwrap(); } @@ -61,7 +61,7 @@ fn marf_insert_different_leaf_same_block_100() { debug!("MARF gets"); debug!("---------"); - let value = TrieLeaf::new(&vec![], &[99; 40].to_vec()); + let value = TrieLeaf::new(&[], &[99; 40]); let leaf = MARF::get_path(&mut marf.borrow_storage_backend(), &block_header, &path) .unwrap() .unwrap(); @@ -116,7 +116,7 @@ fn marf_insert_different_leaf_different_path_different_block_100() { marf.begin(&BlockHeaderHash::sentinel(), &block_header) .unwrap(); let path = TrieHash::from_bytes(&path_bytes).unwrap(); - let value = TrieLeaf::new(&vec![], &[i as u8; 40].to_vec()); + let value = TrieLeaf::new(&[], &[i as u8; 40]); marf.insert_raw(path, value).unwrap(); } @@ -140,7 +140,7 @@ fn marf_insert_different_leaf_different_path_different_block_100() { ]; let path = TrieHash::from_bytes(&path_bytes).unwrap(); - let value = TrieLeaf::new(&vec![], &[i as u8; 40].to_vec()); + let value = TrieLeaf::new(&[], &[i as u8; 40]); let leaf = MARF::get_path(&mut marf.borrow_storage_backend(), &block_header, &path) .unwrap() .unwrap(); @@ -191,12 +191,12 @@ fn marf_insert_same_leaf_different_block_100() { for i in 0..100 { let next_block_header = BlockHeaderHash::from_bytes(&[i + 1 as u8; 32]).unwrap(); - let value = TrieLeaf::new(&vec![], &[i as u8; 40].to_vec()); + let value = TrieLeaf::new(&[], &[i as u8; 40]); marf.commit().unwrap(); marf.begin(&BlockHeaderHash::sentinel(), &next_block_header) .unwrap(); let path = TrieHash::from_bytes(&path_bytes).unwrap(); - let value = TrieLeaf::new(&vec![], &[i as u8; 40].to_vec()); + let value = TrieLeaf::new(&[], &[i as u8; 40]); marf.insert_raw(path, value).unwrap(); } @@ -214,7 +214,7 @@ fn marf_insert_same_leaf_different_block_100() { for i in 0..100 { let next_block_header = BlockHeaderHash::from_bytes(&[i + 1 as u8; 32]).unwrap(); - let value = TrieLeaf::new(&vec![], &[i as u8; 40].to_vec()); + let value = TrieLeaf::new(&[], &[i as u8; 40]); let leaf = MARF::get_path( &mut marf.borrow_storage_backend(), &next_block_header, @@ -275,7 +275,7 @@ fn marf_insert_leaf_sequence_2() { marf.commit().unwrap(); marf.begin(&prior_block_header, &next_block_header).unwrap(); - let value = TrieLeaf::new(&vec![], &[i as u8; 40].to_vec()); + let value = TrieLeaf::new(&[], &[i as u8; 40]); marf.insert_raw(path, value).unwrap(); } @@ -294,7 +294,7 @@ fn marf_insert_leaf_sequence_2() { ]; let path = TrieHash::from_bytes(&path_bytes).unwrap(); - let value = TrieLeaf::new(&vec![], &[i as u8; 40].to_vec()); + let value = TrieLeaf::new(&[], &[i as u8; 40]); let leaf = MARF::get_path( &mut marf.borrow_storage_backend(), &last_block_header, @@ -353,7 +353,7 @@ fn marf_insert_leaf_sequence_100() { marf.begin(&last_block_header, &next_block_header).unwrap(); last_block_header = next_block_header; - let value = TrieLeaf::new(&vec![], &[i as u8; 40].to_vec()); + let value = TrieLeaf::new(&[], &[i as u8; 40]); marf.insert_raw(path, value).unwrap(); } marf.commit().unwrap(); @@ -372,7 +372,7 @@ fn marf_insert_leaf_sequence_100() { ]; let path = TrieHash::from_bytes(&path_bytes).unwrap(); - let value = TrieLeaf::new(&vec![], &[i as u8; 40].to_vec()); + let value = TrieLeaf::new(&[], &[i as u8; 40]); eprintln!("Finding value inserted at {}", &next_block_header); let leaf = MARF::get_path(&mut f, &last_block_header, &path) .unwrap() @@ -566,7 +566,7 @@ where let next_path = path_gen(i, path.clone()); let triepath = TrieHash::from_bytes(&next_path[..]).unwrap(); - let value = TrieLeaf::new(&vec![], &[i as u8; 40].to_vec()); + let value = TrieLeaf::new(&[], &[i as u8; 40]); debug!("----------------"); debug!("insert"); @@ -811,7 +811,7 @@ fn marf_merkle_verify_backptrs() { (vec![26, 27, 28, 29, 30], 31), ]; - let path = vec![ + let path = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, ]; @@ -833,7 +833,7 @@ fn marf_merkle_verify_backptrs() { let mut marf = MARF::from_storage(f_store); let block_header_2 = BlockHeaderHash::from_bytes(&[1u8; 32]).unwrap(); - let path_2 = vec![ + let path_2 = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, ]; @@ -846,7 +846,7 @@ fn marf_merkle_verify_backptrs() { marf.begin(&block_header_1, &block_header_2).unwrap(); marf.insert_raw( TrieHash::from_bytes(&path_2[..]).unwrap(), - TrieLeaf::new(&vec![], &[20 as u8; 40].to_vec()), + TrieLeaf::new(&[], &[20 as u8; 40]), ) .unwrap(); @@ -864,7 +864,7 @@ fn marf_merkle_verify_backptrs() { marf.begin(&block_header_2, &block_header_3).unwrap(); marf.insert_raw( TrieHash::from_bytes(&path_3[..]).unwrap(), - TrieLeaf::new(&vec![], &[21 as u8; 40].to_vec()), + TrieLeaf::new(&[], &[21 as u8; 40]), ) .unwrap(); @@ -922,12 +922,11 @@ where let triepath = TrieHash::from_bytes(&path[..]).unwrap(); let value = TrieLeaf::new( - &vec![], + &[], &[ 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, 0, 0, 0, 0, 0, 0, 0, i0 as u8, i1 as u8, - ] - .to_vec(), + ], ); if let Some(next_block_header) = next_block_header { @@ -998,12 +997,11 @@ where let triepath = TrieHash::from_bytes(&path[..]).unwrap(); let value = TrieLeaf::new( - &vec![], + &[], &[ 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, 0, 0, 0, 0, 0, 0, 0, i0 as u8, i1 as u8, - ] - .to_vec(), + ], ); let read_value = MARF::get_path( @@ -1138,7 +1136,7 @@ fn marf_split_leaf_path() { let path = [0u8; 32]; let triepath = TrieHash::from_bytes(&path[..]).unwrap(); - let value = TrieLeaf::new(&vec![], &[0u8; 40].to_vec()); + let value = TrieLeaf::new(&[], &[0u8; 40]); debug!("----------------"); debug!( @@ -1160,7 +1158,7 @@ fn marf_split_leaf_path() { 1, 1, ]; let triepath_2 = TrieHash::from_bytes(&path_2[..]).unwrap(); - let value_2 = TrieLeaf::new(&vec![], &[1u8; 40].to_vec()); + let value_2 = TrieLeaf::new(&[], &[1u8; 40]); debug!("----------------"); debug!( @@ -1602,12 +1600,11 @@ fn marf_read_random_1048576_4096_file_storage() { let triepath = TrieHash::from_bytes(&path[..]).unwrap(); let value = TrieLeaf::new( - &vec![], + &[], &[ 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, 0, 0, 0, 0, 0, 0, i0 as u8, i1 as u8, i2 as u8, - ] - .to_vec(), + ], ); let read_value = MARF::get_path( @@ -1896,12 +1893,11 @@ fn marf_insert_flush_to_different_block() { let triepath = TrieHash::from_bytes(&path[..]).unwrap(); let value = TrieLeaf::new( - &vec![], + &[], &[ 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, 0, 0, 0, 0, 0, 0, 0, i0 as u8, i1 as u8, - ] - .to_vec(), + ], ); if let Some(next_block_header) = next_block_header { @@ -2017,12 +2013,11 @@ fn marf_insert_flush_to_different_block() { let triepath = TrieHash::from_bytes(&path[..]).unwrap(); let value = TrieLeaf::new( - &vec![], + &[], &[ 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, 0, 0, 0, 0, 0, 0, 0, i0 as u8, i1 as u8, - ] - .to_vec(), + ], ); // all but the final value are dangling off of block_header. @@ -2074,12 +2069,11 @@ fn test_marf_read_only() { ]; let triepath = TrieHash::from_bytes(&path[..]).unwrap(); let leaf = TrieLeaf::new( - &vec![], + &[], &[ 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ] - .to_vec(), + ], ); let value = MARFValue::from(0x1234); @@ -2099,7 +2093,7 @@ fn test_marf_read_only() { assert!(false); } if let Err(Error::ReadOnlyError) = - ro_marf.insert_batch(&vec!["foo".to_string()], vec![value.clone()]) + ro_marf.insert_batch(&["foo".to_string()], vec![value.clone()]) { } else { assert!(false); @@ -2144,8 +2138,8 @@ fn test_marf_begin_from_sentinel_twice() { ]; let triepath_2 = TrieHash::from_bytes(&path_2[..]).unwrap(); - let value_1 = TrieLeaf::new(&vec![], &vec![1u8; 40]); - let value_2 = TrieLeaf::new(&vec![], &vec![2u8; 40]); + let value_1 = TrieLeaf::new(&[], &[1u8; 40]); + let value_2 = TrieLeaf::new(&[], &[2u8; 40]); marf.begin(&BlockHeaderHash::sentinel(), &block_header_1) .unwrap(); @@ -2209,14 +2203,14 @@ fn test_marf_unconfirmed() { 25, 26, 27, 28, 29, 30, 31, ]; let triepath_1 = TrieHash::from_bytes(&path_1[..]).unwrap(); - let value_1 = TrieLeaf::new(&vec![], &vec![1u8; 40]); + let value_1 = TrieLeaf::new(&[], &[1u8; 40]); let path_2 = [ 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, ]; let triepath_2 = TrieHash::from_bytes(&path_2[..]).unwrap(); - let value_2 = TrieLeaf::new(&vec![], &vec![2u8; 40]); + let value_2 = TrieLeaf::new(&[], &[2u8; 40]); let block_header = StacksBlockId([0x33u8; 32]); diff --git a/stackslib/src/chainstate/stacks/index/test/mod.rs b/stackslib/src/chainstate/stacks/index/test/mod.rs index 0ccdffa78b..09cfae4c9e 100644 --- a/stackslib/src/chainstate/stacks/index/test/mod.rs +++ b/stackslib/src/chainstate/stacks/index/test/mod.rs @@ -102,8 +102,8 @@ where pub fn merkle_test( s: &mut TrieStorageConnection, - path: &Vec, - value: &Vec, + path: &[u8], + value: &[u8], ) -> () { let (_, root_hash) = Trie::read_root(s).unwrap(); let triepath = TrieHash::from_bytes(&path[..]).unwrap(); @@ -130,8 +130,8 @@ pub fn merkle_test( pub fn merkle_test_marf( s: &mut TrieStorageConnection, header: &BlockHeaderHash, - path: &Vec, - value: &Vec, + path: &[u8], + value: &[u8], root_to_block: Option>, ) -> HashMap { test_debug!("---------"); @@ -208,7 +208,7 @@ pub fn merkle_test_marf_key_value( pub fn make_node_path( s: &mut TrieStorageConnection, node_id: u8, - path_segments: &Vec<(Vec, u8)>, + path_segments: &[(Vec, u8)], leaf_data: Vec, ) -> (Vec, Vec, Vec) { // make a fully-fleshed-out path of node's to a leaf @@ -335,7 +335,7 @@ pub fn make_node_path( pub fn make_node4_path( s: &mut TrieStorageConnection, - path_segments: &Vec<(Vec, u8)>, + path_segments: &[(Vec, u8)], leaf_data: Vec, ) -> (Vec, Vec, Vec) { make_node_path(s, TrieNodeID::Node4 as u8, path_segments, leaf_data) diff --git a/stackslib/src/chainstate/stacks/index/test/node.rs b/stackslib/src/chainstate/stacks/index/test/node.rs index 227adda439..3bd7e67b01 100644 --- a/stackslib/src/chainstate/stacks/index/test/node.rs +++ b/stackslib/src/chainstate/stacks/index/test/node.rs @@ -44,7 +44,7 @@ fn trieptr_to_bytes() { #[test] fn trie_node4_to_bytes() { - let mut node4 = TrieNode4::new(&vec![ + let mut node4 = TrieNode4::new(&[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ]); for i in 0..3 { @@ -131,7 +131,7 @@ fn trie_node4_to_bytes() { #[test] fn trie_node4_to_consensus_bytes() { - let mut node4 = TrieNode4::new(&vec![ + let mut node4 = TrieNode4::new(&[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ]); for i in 0..3 { @@ -312,7 +312,7 @@ fn trie_node4_to_consensus_bytes() { #[test] fn trie_node16_to_bytes() { - let mut node16 = TrieNode16::new(&vec![ + let mut node16 = TrieNode16::new(&[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ]); for i in 0..15 { @@ -519,7 +519,7 @@ fn trie_node16_to_bytes() { #[test] fn trie_node16_to_consensus_bytes() { - let mut node16 = TrieNode16::new(&vec![ + let mut node16 = TrieNode16::new(&[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ]); for i in 0..15 { @@ -1106,7 +1106,7 @@ fn trie_node16_to_consensus_bytes() { #[test] fn trie_node48_to_bytes() { - let mut node48 = TrieNode48::new(&vec![ + let mut node48 = TrieNode48::new(&[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ]); for i in 0..47 { @@ -1892,7 +1892,7 @@ fn trie_node48_to_bytes() { #[test] fn trie_node48_to_consensus_bytes() { - let mut node48 = TrieNode48::new(&vec![ + let mut node48 = TrieNode48::new(&[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ]); for i in 0..47 { @@ -3568,7 +3568,7 @@ fn trie_node48_to_consensus_bytes() { #[test] fn trie_node256_to_bytes() { - let mut node256 = TrieNode256::new(&vec![ + let mut node256 = TrieNode256::new(&[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ]); for i in 0..255 { @@ -3632,7 +3632,7 @@ fn trie_node256_to_bytes() { #[test] fn trie_node256_to_consensus_bytes() { - let mut node256 = TrieNode256::new(&vec![ + let mut node256 = TrieNode256::new(&[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ]); for i in 0..255 { @@ -3741,10 +3741,10 @@ fn trie_node256_to_consensus_bytes() { #[test] fn trie_leaf_to_bytes() { let leaf = TrieLeaf::new( - &vec![ + &[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ], - &vec![ + &[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, ], @@ -3826,7 +3826,7 @@ fn trie_leaf_to_bytes() { #[test] fn read_write_node4() { - let mut node4 = TrieNode4::new(&vec![ + let mut node4 = TrieNode4::new(&[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ]); for i in 0..3 { @@ -3855,7 +3855,7 @@ fn read_write_node4() { #[test] fn read_write_node16() { - let mut node16 = TrieNode16::new(&vec![ + let mut node16 = TrieNode16::new(&[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ]); for i in 0..16 { @@ -3885,7 +3885,7 @@ fn read_write_node16() { #[test] fn read_write_node48() { - let mut node48 = TrieNode48::new(&vec![ + let mut node48 = TrieNode48::new(&[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ]); for i in 0..48 { @@ -3915,7 +3915,7 @@ fn read_write_node48() { #[test] fn read_write_node256() { - let mut node256 = TrieNode256::new(&vec![ + let mut node256 = TrieNode256::new(&[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ]); for i in 0..256 { @@ -3947,10 +3947,10 @@ fn read_write_node256() { #[test] fn read_write_leaf() { let leaf = TrieLeaf::new( - &vec![ + &[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, ], - &vec![ + &[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, ], @@ -3982,7 +3982,7 @@ fn read_write_node4_hashes() { .extend_to_block(&BlockHeaderHash([0u8; 32])) .unwrap(); - let mut node4 = TrieNode4::new(&vec![ + let mut node4 = TrieNode4::new(&[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, ]); let hash = TrieHash::from_data(&[0u8; 32]); @@ -3990,10 +3990,10 @@ fn read_write_node4_hashes() { let mut child_hashes = vec![]; for i in 0..3 { let child = TrieLeaf::new( - &vec![ + &[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, i as u8, ], - &vec![i as u8; 40], + &[i as u8; 40], ); let child_hash = get_leaf_hash(&child); @@ -4026,7 +4026,7 @@ fn read_write_node16_hashes() { .extend_to_block(&BlockHeaderHash([0u8; 32])) .unwrap(); - let mut node16 = TrieNode16::new(&vec![ + let mut node16 = TrieNode16::new(&[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, ]); let hash = TrieHash::from_data(&[0u8; 32]); @@ -4034,10 +4034,10 @@ fn read_write_node16_hashes() { let mut child_hashes = vec![]; for i in 0..15 { let child = TrieLeaf::new( - &vec![ + &[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, i as u8, ], - &vec![i as u8; 40], + &[i as u8; 40], ); let child_hash = get_leaf_hash(&child); @@ -4072,7 +4072,7 @@ fn read_write_node48_hashes() { .extend_to_block(&BlockHeaderHash([0u8; 32])) .unwrap(); - let mut node48 = TrieNode48::new(&vec![ + let mut node48 = TrieNode48::new(&[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, ]); let hash = TrieHash::from_data(&[0u8; 32]); @@ -4080,10 +4080,10 @@ fn read_write_node48_hashes() { let mut child_hashes = vec![]; for i in 0..47 { let child = TrieLeaf::new( - &vec![ + &[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, i as u8, ], - &vec![i as u8; 40], + &[i as u8; 40], ); let child_hash = get_leaf_hash(&child); @@ -4118,7 +4118,7 @@ fn read_write_node256_hashes() { .extend_to_block(&BlockHeaderHash([0u8; 32])) .unwrap(); - let mut node256 = TrieNode256::new(&vec![ + let mut node256 = TrieNode256::new(&[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, ]); let hash = TrieHash::from_data(&[0u8; 32]); @@ -4126,10 +4126,10 @@ fn read_write_node256_hashes() { let mut child_hashes = vec![]; for i in 0..255 { let child = TrieLeaf::new( - &vec![ + &[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, i as u8, ], - &vec![i as u8; 40], + &[i as u8; 40], ); let child_hash = get_leaf_hash(&child); @@ -4198,7 +4198,7 @@ fn trie_cursor_walk_full() { (vec![], 30), (vec![], 31), ]; - let path = vec![ + let path = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, ]; @@ -4253,7 +4253,7 @@ fn trie_cursor_walk_full() { assert_eq!(ptr, node_ptrs[31]); assert_eq!( node, - TrieNodeType::Leaf(TrieLeaf::new(&vec![], &[31u8; 40].to_vec())) + TrieNodeType::Leaf(TrieLeaf::new(&[], &[31u8; 40].to_vec())) ); assert_eq!(hash, hashes[31]); @@ -4296,7 +4296,7 @@ fn trie_cursor_walk_1() { (vec![28], 29), (vec![30], 31), ]; - let path = vec![ + let path = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, ]; @@ -4349,10 +4349,7 @@ fn trie_cursor_walk_1() { let (ptr, node, hash) = fields_opt.unwrap(); assert_eq!(ptr, node_ptrs[15]); - assert_eq!( - node, - TrieNodeType::Leaf(TrieLeaf::new(&vec![30], &[31u8; 40].to_vec())) - ); + assert_eq!(node, TrieNodeType::Leaf(TrieLeaf::new(&[30], &[31u8; 40]))); assert_eq!(hash, hashes[15]); // cursor's last-visited node points at the penultimate node (the last node4), @@ -4389,7 +4386,7 @@ fn trie_cursor_walk_2() { (vec![27, 28], 29), (vec![30], 31), ]; - let path = vec![ + let path = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, ]; @@ -4442,10 +4439,7 @@ fn trie_cursor_walk_2() { let (ptr, node, hash) = fields_opt.unwrap(); assert_eq!(ptr, node_ptrs[10]); - assert_eq!( - node, - TrieNodeType::Leaf(TrieLeaf::new(&vec![30], &[31u8; 40].to_vec())) - ); + assert_eq!(node, TrieNodeType::Leaf(TrieLeaf::new(&[30], &[31u8; 40]))); assert_eq!(hash, hashes[10]); // cursor's last-visited node points at the penultimate node (the last node4), @@ -4479,7 +4473,7 @@ fn trie_cursor_walk_3() { (vec![24, 25, 26], 27), (vec![28, 29, 30], 31), ]; - let path = vec![ + let path = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, ]; @@ -4534,7 +4528,7 @@ fn trie_cursor_walk_3() { assert_eq!(ptr, node_ptrs[7]); assert_eq!( node, - TrieNodeType::Leaf(TrieLeaf::new(&vec![28, 29, 30], &[31u8; 40].to_vec())) + TrieNodeType::Leaf(TrieLeaf::new(&[28, 29, 30], &[31u8; 40])) ); assert_eq!(hash, hashes[7]); @@ -4568,7 +4562,7 @@ fn trie_cursor_walk_4() { (vec![25, 26, 27, 28], 29), (vec![30], 31), ]; - let path = vec![ + let path = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, ]; @@ -4621,10 +4615,7 @@ fn trie_cursor_walk_4() { let (ptr, node, hash) = fields_opt.unwrap(); assert_eq!(ptr, node_ptrs[6]); - assert_eq!( - node, - TrieNodeType::Leaf(TrieLeaf::new(&vec![30], &[31u8; 40].to_vec())) - ); + assert_eq!(node, TrieNodeType::Leaf(TrieLeaf::new(&[30], &[31u8; 40]))); assert_eq!(hash, hashes[6]); // cursor's last-visited node points at the penultimate node (the last node4), @@ -4656,7 +4647,7 @@ fn trie_cursor_walk_5() { (vec![24, 25, 26, 27, 28], 29), (vec![30], 31), ]; - let path = vec![ + let path = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, ]; @@ -4709,10 +4700,7 @@ fn trie_cursor_walk_5() { let (ptr, node, hash) = fields_opt.unwrap(); assert_eq!(ptr, node_ptrs[5]); - assert_eq!( - node, - TrieNodeType::Leaf(TrieLeaf::new(&vec![30], &[31u8; 40].to_vec())) - ); + assert_eq!(node, TrieNodeType::Leaf(TrieLeaf::new(&[30], &[31u8; 40]))); assert_eq!(hash, hashes[5]); // cursor's last-visited node points at the penultimate node (the last node4), @@ -4743,7 +4731,7 @@ fn trie_cursor_walk_6() { (vec![21, 22, 23, 24, 25, 26], 27), (vec![28, 29, 30], 31), ]; - let path = vec![ + let path = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, ]; @@ -4798,7 +4786,7 @@ fn trie_cursor_walk_6() { assert_eq!(ptr, node_ptrs[4]); assert_eq!( node, - TrieNodeType::Leaf(TrieLeaf::new(&vec![28, 29, 30], &[31u8; 40].to_vec())) + TrieNodeType::Leaf(TrieLeaf::new(&[28, 29, 30], &[31u8; 40])) ); assert_eq!(hash, hashes[4]); @@ -4828,7 +4816,7 @@ fn trie_cursor_walk_10() { (vec![11, 12, 13, 14, 15, 16, 17, 18, 19, 20], 21), (vec![22, 23, 24, 25, 26, 27, 28, 29, 30], 31), ]; - let path = vec![ + let path = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, ]; @@ -4884,8 +4872,8 @@ fn trie_cursor_walk_10() { assert_eq!( node, TrieNodeType::Leaf(TrieLeaf::new( - &vec![22, 23, 24, 25, 26, 27, 28, 29, 30], - &[31u8; 40].to_vec() + &[22, 23, 24, 25, 26, 27, 28, 29, 30], + &[31u8; 40] )) ); assert_eq!(hash, hashes[2]); @@ -4920,7 +4908,7 @@ fn trie_cursor_walk_20() { ), (vec![21, 22, 23, 24, 25, 26, 27, 28, 29, 30], 31), ]; - let path = vec![ + let path = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, ]; @@ -4976,8 +4964,8 @@ fn trie_cursor_walk_20() { assert_eq!( node, TrieNodeType::Leaf(TrieLeaf::new( - &vec![21, 22, 23, 24, 25, 26, 27, 28, 29, 30], - &[31u8; 40].to_vec() + &[21, 22, 23, 24, 25, 26, 27, 28, 29, 30], + &[31u8; 40] )) ); assert_eq!(hash, hashes[1]); @@ -5011,7 +4999,7 @@ fn trie_cursor_walk_32() { ], 31, )]; - let path = vec![ + let path = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, ]; @@ -5045,11 +5033,11 @@ fn trie_cursor_walk_32() { assert_eq!( node, TrieNodeType::Leaf(TrieLeaf::new( - &vec![ + &[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 ], - &[31u8; 40].to_vec() + &[31u8; 40] )) ); assert_eq!(hash, hashes[0]); diff --git a/stackslib/src/chainstate/stacks/index/test/storage.rs b/stackslib/src/chainstate/stacks/index/test/storage.rs index fdd3e30191..0df503a79e 100644 --- a/stackslib/src/chainstate/stacks/index/test/storage.rs +++ b/stackslib/src/chainstate/stacks/index/test/storage.rs @@ -165,7 +165,7 @@ fn load_store_trie_m_n_same(m: u64, n: u64, same: bool) { path_bytes[24..32].copy_from_slice(&i.to_be_bytes()); let path = TrieHash::from_bytes(&path_bytes).unwrap(); - let value = TrieLeaf::new(&vec![], &[i as u8; 40].to_vec()); + let value = TrieLeaf::new(&[], &[i as u8; 40]); confirmed_marf.insert_raw(path.clone(), value).unwrap(); } @@ -236,7 +236,7 @@ fn load_store_trie_m_n_same(m: u64, n: u64, same: bool) { } let path = TrieHash::from_bytes(&path_bytes).unwrap(); - let value = TrieLeaf::new(&vec![], &[(i + 128) as u8; 40].to_vec()); + let value = TrieLeaf::new(&[], &[(i + 128) as u8; 40]); new_inserted.push((path.clone(), value.clone())); diff --git a/stackslib/src/chainstate/stacks/index/test/trie.rs b/stackslib/src/chainstate/stacks/index/test/trie.rs index 9bac45508c..4b8daf52f8 100644 --- a/stackslib/src/chainstate/stacks/index/test/trie.rs +++ b/stackslib/src/chainstate/stacks/index/test/trie.rs @@ -146,7 +146,7 @@ fn trie_cursor_try_attach_leaf() { let ptr_opt_res = Trie::test_try_attach_leaf( &mut f, &mut c, - &mut TrieLeaf::new(&vec![], &[i as u8; 40].to_vec()), + &mut TrieLeaf::new(&[], &[i as u8; 40]), &mut node, ); assert!(ptr_opt_res.is_ok()); @@ -172,14 +172,11 @@ fn trie_cursor_try_attach_leaf() { assert!(leaf_opt.is_some()); let leaf = leaf_opt.unwrap(); - assert_eq!( - leaf, - TrieLeaf::new(&path[i + 1..].to_vec(), &[i as u8; 40].to_vec()) - ); + assert_eq!(leaf, TrieLeaf::new(&path[i + 1..].to_vec(), &[i as u8; 40])); // without a MARF commit, merkle tests will fail in deferred mode if f.hash_calculation_mode != TrieHashCalculationMode::Deferred { - merkle_test(&mut f, &path, &[i as u8; 40].to_vec()); + merkle_test(&mut f, &path, &[i as u8; 40]); } } @@ -202,14 +199,11 @@ fn trie_cursor_try_attach_leaf() { assert!(leaf_opt.is_some()); let leaf = leaf_opt.unwrap(); - assert_eq!( - leaf, - TrieLeaf::new(&path[i + 1..].to_vec(), &[i as u8; 40].to_vec()) - ); + assert_eq!(leaf, TrieLeaf::new(&path[i + 1..], &[i as u8; 40])); // without a MARF commit, merkle tests will fail in deferred mode if f.hash_calculation_mode != TrieHashCalculationMode::Deferred { - merkle_test(&mut f, &path, &[i as u8; 40].to_vec()); + merkle_test(&mut f, &path, &[i as u8; 40]); } } @@ -264,7 +258,7 @@ fn trie_cursor_promote_leaf_to_node4() { Trie::test_try_attach_leaf( &mut f, &mut c, - &mut TrieLeaf::new(&vec![], &[128; 40].to_vec()), + &mut TrieLeaf::new(&[], &[128; 40]), &mut node, ) .unwrap() @@ -284,11 +278,11 @@ fn trie_cursor_promote_leaf_to_node4() { .unwrap() .unwrap(), TrieLeaf::new( - &vec![ + &[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 ], - &[128; 40].to_vec() + &[128; 40] ) ); @@ -299,9 +293,8 @@ fn trie_cursor_promote_leaf_to_node4() { &[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - ] - .to_vec(), - &[128; 40].to_vec(), + ], + &[128; 40], ); } @@ -331,7 +324,7 @@ fn trie_cursor_promote_leaf_to_node4() { &mut f, &mut c, &mut leaf_data, - &mut TrieLeaf::new(&vec![], &[(i + 128) as u8; 40].to_vec()), + &mut TrieLeaf::new(&[], &[(i + 128) as u8; 40]), ) .unwrap(); ptrs.push(ptr); @@ -350,14 +343,11 @@ fn trie_cursor_promote_leaf_to_node4() { assert!(leaf_opt.is_some()); let leaf = leaf_opt.unwrap(); - assert_eq!( - leaf, - TrieLeaf::new(&path[i + 1..].to_vec(), &[(i + 128) as u8; 40].to_vec()) - ); + assert_eq!(leaf, TrieLeaf::new(&path[i + 1..], &[(i + 128) as u8; 40])); // without a MARF commit, merkle tests will fail in deferred mode if f.hash_calculation_mode != TrieHashCalculationMode::Deferred { - merkle_test(&mut f, &path, &[(i + 128) as u8; 40].to_vec()); + merkle_test(&mut f, &path, &[(i + 128) as u8; 40]); } } @@ -380,14 +370,11 @@ fn trie_cursor_promote_leaf_to_node4() { assert!(leaf_opt.is_some()); let leaf = leaf_opt.unwrap(); - assert_eq!( - leaf, - TrieLeaf::new(&path[i + 1..].to_vec(), &[(i + 128) as u8; 40].to_vec()) - ); + assert_eq!(leaf, TrieLeaf::new(&path[i + 1..], &[(i + 128) as u8; 40])); // without a MARF commit, merkle tests will fail in deferred mode if f.hash_calculation_mode != TrieHashCalculationMode::Deferred { - merkle_test(&mut f, &path, &[(i + 128) as u8; 40].to_vec()); + merkle_test(&mut f, &path, &[(i + 128) as u8; 40]); } } @@ -474,7 +461,7 @@ fn trie_cursor_promote_node4_to_node16() { Trie::test_try_attach_leaf( &mut f, &mut c, - &mut TrieLeaf::new(&vec![], &[128 + j as u8; 40].to_vec()), + &mut TrieLeaf::new(&[], &[128 + j as u8; 40]), &mut node, ) .unwrap() @@ -490,12 +477,12 @@ fn trie_cursor_promote_node4_to_node16() { ) .unwrap() .unwrap(), - TrieLeaf::new(&path[k + 1..].to_vec(), &[128 + j as u8; 40].to_vec()) + TrieLeaf::new(&path[k + 1..], &[128 + j as u8; 40]) ); // without a MARF commit, merkle tests will fail in deferred mode if f.hash_calculation_mode != TrieHashCalculationMode::Deferred { - merkle_test(&mut f, &path.to_vec(), &[(j + 128) as u8; 40].to_vec()); + merkle_test(&mut f, &path, &[(j + 128) as u8; 40]); } } } @@ -523,7 +510,7 @@ fn trie_cursor_promote_node4_to_node16() { let new_ptr = Trie::test_insert_leaf( &mut f, &mut c, - &mut TrieLeaf::new(&vec![], &[192 + k as u8; 40].to_vec()), + &mut TrieLeaf::new(&[], &[192 + k as u8; 40]), &mut node, ) .unwrap(); @@ -540,12 +527,12 @@ fn trie_cursor_promote_node4_to_node16() { ) .unwrap() .unwrap(), - TrieLeaf::new(&path[k + 1..].to_vec(), &[192 + k as u8; 40].to_vec()) + TrieLeaf::new(&path[k + 1..], &[192 + k as u8; 40]) ); // without a MARF commit, merkle tests will fail in deferred mode if f.hash_calculation_mode != TrieHashCalculationMode::Deferred { - merkle_test(&mut f, &path.to_vec(), &[(k + 192) as u8; 40].to_vec()); + merkle_test(&mut f, &path, &[(k + 192) as u8; 40]); } } @@ -635,7 +622,7 @@ fn trie_cursor_promote_node16_to_node48() { Trie::test_try_attach_leaf( &mut f, &mut c, - &mut TrieLeaf::new(&vec![], &[128 + j as u8; 40].to_vec()), + &mut TrieLeaf::new(&[], &[128 + j as u8; 40]), &mut node, ) .unwrap() @@ -652,12 +639,12 @@ fn trie_cursor_promote_node16_to_node48() { ) .unwrap() .unwrap(), - TrieLeaf::new(&path[k + 1..].to_vec(), &[128 + j as u8; 40].to_vec()) + TrieLeaf::new(&path[k + 1..], &[128 + j as u8; 40]) ); // without a MARF commit, merkle tests will fail in deferred mode if f.hash_calculation_mode != TrieHashCalculationMode::Deferred { - merkle_test(&mut f, &path.to_vec(), &[(j + 128) as u8; 40].to_vec()); + merkle_test(&mut f, &path, &[(j + 128) as u8; 40]); } } } @@ -685,7 +672,7 @@ fn trie_cursor_promote_node16_to_node48() { let new_ptr = Trie::test_insert_leaf( &mut f, &mut c, - &mut TrieLeaf::new(&vec![], &[192 + k as u8; 40].to_vec()), + &mut TrieLeaf::new(&[], &[192 + k as u8; 40]), &mut node, ) .unwrap(); @@ -702,12 +689,12 @@ fn trie_cursor_promote_node16_to_node48() { ) .unwrap() .unwrap(), - TrieLeaf::new(&path[k + 1..].to_vec(), &[192 + k as u8; 40].to_vec()) + TrieLeaf::new(&path[k + 1..], &[192 + k as u8; 40]) ); // without a MARF commit, merkle tests will fail in deferred mode if f.hash_calculation_mode != TrieHashCalculationMode::Deferred { - merkle_test(&mut f, &path.to_vec(), &[(k + 192) as u8; 40].to_vec()); + merkle_test(&mut f, &path, &[(k + 192) as u8; 40]); } } @@ -742,7 +729,7 @@ fn trie_cursor_promote_node16_to_node48() { Trie::test_try_attach_leaf( &mut f, &mut c, - &mut TrieLeaf::new(&vec![], &[128 + j as u8; 40].to_vec()), + &mut TrieLeaf::new(&[], &[128 + j as u8; 40]), &mut node, ) .unwrap() @@ -759,12 +746,12 @@ fn trie_cursor_promote_node16_to_node48() { ) .unwrap() .unwrap(), - TrieLeaf::new(&path[k + 1..].to_vec(), &[128 + j as u8; 40].to_vec()) + TrieLeaf::new(&path[k + 1..], &[128 + j as u8; 40]) ); // without a MARF commit, merkle tests will fail in deferred mode if f.hash_calculation_mode != TrieHashCalculationMode::Deferred { - merkle_test(&mut f, &path.to_vec(), &[(j + 128) as u8; 40].to_vec()); + merkle_test(&mut f, &path, &[(j + 128) as u8; 40]); } } } @@ -793,7 +780,7 @@ fn trie_cursor_promote_node16_to_node48() { let new_ptr = Trie::test_insert_leaf( &mut f, &mut c, - &mut TrieLeaf::new(&vec![], &[192 + k as u8; 40].to_vec()), + &mut TrieLeaf::new(&[], &[192 + k as u8; 40]), &mut node, ) .unwrap(); @@ -810,12 +797,12 @@ fn trie_cursor_promote_node16_to_node48() { ) .unwrap() .unwrap(), - TrieLeaf::new(&path[k + 1..].to_vec(), &[192 + k as u8; 40].to_vec()) + TrieLeaf::new(&path[k + 1..], &[192 + k as u8; 40]) ); // without a MARF commit, merkle tests will fail in deferred mode if f.hash_calculation_mode != TrieHashCalculationMode::Deferred { - merkle_test(&mut f, &path.to_vec(), &[(k + 192) as u8; 40].to_vec()); + merkle_test(&mut f, &path, &[(k + 192) as u8; 40]); } } @@ -905,7 +892,7 @@ fn trie_cursor_promote_node48_to_node256() { Trie::test_try_attach_leaf( &mut f, &mut c, - &mut TrieLeaf::new(&vec![], &[128 + j as u8; 40].to_vec()), + &mut TrieLeaf::new(&[], &[128 + j as u8; 40]), &mut node, ) .unwrap() @@ -922,12 +909,12 @@ fn trie_cursor_promote_node48_to_node256() { ) .unwrap() .unwrap(), - TrieLeaf::new(&path[k + 1..].to_vec(), &[128 + j as u8; 40].to_vec()) + TrieLeaf::new(&path[k + 1..], &[128 + j as u8; 40]) ); // without a MARF commit, merkle tests will fail in deferred mode if f.hash_calculation_mode != TrieHashCalculationMode::Deferred { - merkle_test(&mut f, &path.to_vec(), &[(j + 128) as u8; 40].to_vec()); + merkle_test(&mut f, &path, &[(j + 128) as u8; 40]); } } } @@ -955,7 +942,7 @@ fn trie_cursor_promote_node48_to_node256() { let new_ptr = Trie::test_insert_leaf( &mut f, &mut c, - &mut TrieLeaf::new(&vec![], &[192 + k as u8; 40].to_vec()), + &mut TrieLeaf::new(&[], &[192 + k as u8; 40]), &mut node, ) .unwrap(); @@ -972,12 +959,12 @@ fn trie_cursor_promote_node48_to_node256() { ) .unwrap() .unwrap(), - TrieLeaf::new(&path[k + 1..].to_vec(), &[192 + k as u8; 40].to_vec()) + TrieLeaf::new(&path[k + 1..], &[192 + k as u8; 40]) ); // without a MARF commit, merkle tests will fail in deferred mode if f.hash_calculation_mode != TrieHashCalculationMode::Deferred { - merkle_test(&mut f, &path.to_vec(), &[(k + 192) as u8; 40].to_vec()); + merkle_test(&mut f, &path, &[(k + 192) as u8; 40]); } } @@ -1012,7 +999,7 @@ fn trie_cursor_promote_node48_to_node256() { Trie::test_try_attach_leaf( &mut f, &mut c, - &mut TrieLeaf::new(&vec![], &[128 + j as u8; 40].to_vec()), + &mut TrieLeaf::new(&[], &[128 + j as u8; 40]), &mut node, ) .unwrap() @@ -1028,12 +1015,12 @@ fn trie_cursor_promote_node48_to_node256() { ) .unwrap() .unwrap(), - TrieLeaf::new(&path[k + 1..].to_vec(), &[128 + j as u8; 40].to_vec()) + TrieLeaf::new(&path[k + 1..], &[128 + j as u8; 40]) ); // without a MARF commit, merkle tests will fail in deferred mode if f.hash_calculation_mode != TrieHashCalculationMode::Deferred { - merkle_test(&mut f, &path.to_vec(), &[(j + 128) as u8; 40].to_vec()); + merkle_test(&mut f, &path, &[(j + 128) as u8; 40]); } } } @@ -1061,7 +1048,7 @@ fn trie_cursor_promote_node48_to_node256() { let new_ptr = Trie::test_insert_leaf( &mut f, &mut c, - &mut TrieLeaf::new(&vec![], &[192 + k as u8; 40].to_vec()), + &mut TrieLeaf::new(&[], &[192 + k as u8; 40]), &mut node, ) .unwrap(); @@ -1078,12 +1065,12 @@ fn trie_cursor_promote_node48_to_node256() { ) .unwrap() .unwrap(), - TrieLeaf::new(&path[k + 1..].to_vec(), &[192 + k as u8; 40].to_vec()) + TrieLeaf::new(&path[k + 1..], &[192 + k as u8; 40]) ); // without a MARF commit, merkle tests will fail in deferred mode if f.hash_calculation_mode != TrieHashCalculationMode::Deferred { - merkle_test(&mut f, &path.to_vec(), &[(k + 192) as u8; 40].to_vec()); + merkle_test(&mut f, &path, &[(k + 192) as u8; 40]); } } @@ -1118,7 +1105,7 @@ fn trie_cursor_promote_node48_to_node256() { Trie::test_try_attach_leaf( &mut f, &mut c, - &mut TrieLeaf::new(&vec![], &[128 + j as u8; 40].to_vec()), + &mut TrieLeaf::new(&[], &[128 + j as u8; 40]), &mut node, ) .unwrap() @@ -1135,12 +1122,12 @@ fn trie_cursor_promote_node48_to_node256() { ) .unwrap() .unwrap(), - TrieLeaf::new(&path[k + 1..].to_vec(), &[128 + j as u8; 40].to_vec()) + TrieLeaf::new(&path[k + 1..], &[128 + j as u8; 40]) ); // without a MARF commit, merkle tests will fail in deferred mode if f.hash_calculation_mode != TrieHashCalculationMode::Deferred { - merkle_test(&mut f, &path.to_vec(), &[(j + 128) as u8; 40].to_vec()); + merkle_test(&mut f, &path, &[(j + 128) as u8; 40]); } } } @@ -1168,7 +1155,7 @@ fn trie_cursor_promote_node48_to_node256() { let new_ptr = Trie::test_insert_leaf( &mut f, &mut c, - &mut TrieLeaf::new(&vec![], &[192 + k as u8; 40].to_vec()), + &mut TrieLeaf::new(&[], &[192 + k as u8; 40]), &mut node, ) .unwrap(); @@ -1185,12 +1172,12 @@ fn trie_cursor_promote_node48_to_node256() { ) .unwrap() .unwrap(), - TrieLeaf::new(&path[k + 1..].to_vec(), &[192 + k as u8; 40].to_vec()) + TrieLeaf::new(&path[k + 1..], &[192 + k as u8; 40]) ); // without a MARF commit, merkle tests will fail in deferred mode if f.hash_calculation_mode != TrieHashCalculationMode::Deferred { - merkle_test(&mut f, &path.to_vec(), &[(k + 192) as u8; 40].to_vec()); + merkle_test(&mut f, &path, &[(k + 192) as u8; 40]); } } @@ -1270,7 +1257,7 @@ fn trie_cursor_splice_leaf_4() { let new_ptr = Trie::test_splice_leaf( &mut f, &mut c, - &mut TrieLeaf::new(&vec![], &[192 + k as u8; 40].to_vec()), + &mut TrieLeaf::new(&[], &[192 + k as u8; 40]), &mut node, ) .unwrap(); @@ -1287,12 +1274,12 @@ fn trie_cursor_splice_leaf_4() { ) .unwrap() .unwrap(), - TrieLeaf::new(&path[5 * k + 3..].to_vec(), &[192 + k as u8; 40].to_vec()) + TrieLeaf::new(&path[5 * k + 3..], &[192 + k as u8; 40]) ); // without a MARF commit, merkle tests will fail in deferred mode if f.hash_calculation_mode != TrieHashCalculationMode::Deferred { - merkle_test(&mut f, &path.to_vec(), &[(k + 192) as u8; 40].to_vec()); + merkle_test(&mut f, &path, &[(k + 192) as u8; 40]); } } @@ -1359,7 +1346,7 @@ fn trie_cursor_splice_leaf_2() { let new_ptr = Trie::test_splice_leaf( &mut f, &mut c, - &mut TrieLeaf::new(&vec![], &[192 + k as u8; 40].to_vec()), + &mut TrieLeaf::new(&[], &[192 + k as u8; 40]), &mut node, ) .unwrap(); @@ -1376,13 +1363,13 @@ fn trie_cursor_splice_leaf_2() { ) .unwrap() .unwrap(), - TrieLeaf::new(&path[3 * k + 2..].to_vec(), &[192 + k as u8; 40].to_vec()) + TrieLeaf::new(&path[3 * k + 2..], &[192 + k as u8; 40]) ); // proofs should still work // without a MARF commit, merkle tests will fail in deferred mode if f.hash_calculation_mode != TrieHashCalculationMode::Deferred { - merkle_test(&mut f, &path.to_vec(), &[(k + 192) as u8; 40].to_vec()); + merkle_test(&mut f, &path, &[(k + 192) as u8; 40]); } } @@ -1415,7 +1402,7 @@ where let path = path_gen(i); let triepath = TrieHash::from_bytes(&path).unwrap(); let value = TrieLeaf::new( - &vec![], + &[], &[ 0, 0, @@ -1457,8 +1444,7 @@ where 0, (i / 256) as u8, (i % 256) as u8, - ] - .to_vec(), + ], ); marf.insert_raw(triepath, value).unwrap(); @@ -1469,7 +1455,7 @@ where { merkle_test( &mut marf.borrow_storage_backend(), - &path.to_vec(), + &path, &[ 0, 0, @@ -1511,8 +1497,7 @@ where 0, (i / 256) as u8, (i % 256) as u8, - ] - .to_vec(), + ], ); } } @@ -1577,7 +1562,7 @@ where { merkle_test( &mut marf.borrow_storage_backend(), - &path.to_vec(), + &path, &[ 0, 0, @@ -1619,8 +1604,7 @@ where 0, (i / 256) as u8, (i % 256) as u8, - ] - .to_vec(), + ], ); } } diff --git a/stackslib/src/chainstate/stacks/index/trie.rs b/stackslib/src/chainstate/stacks/index/trie.rs index 65e41cf3ed..4b3bbe1b33 100644 --- a/stackslib/src/chainstate/stacks/index/trie.rs +++ b/stackslib/src/chainstate/stacks/index/trie.rs @@ -400,7 +400,7 @@ impl Trie { let node4_hash = get_node_hash( &node4_data, - &vec![ + &[ cur_leaf_hash, new_leaf_hash, TrieHash::from_data(&[]), @@ -652,7 +652,7 @@ impl Trie { let new_node_hash = get_node_hash( &new_node4, - &vec![ + &[ leaf_hash, new_cur_node_hash, TrieHash::from_data(&[]), diff --git a/stackslib/src/chainstate/stacks/tests/accounting.rs b/stackslib/src/chainstate/stacks/tests/accounting.rs index 9ca3016a1b..5cf29d6993 100644 --- a/stackslib/src/chainstate/stacks/tests/accounting.rs +++ b/stackslib/src/chainstate/stacks/tests/accounting.rs @@ -337,7 +337,7 @@ fn test_bad_microblock_fees_pre_v210() { // should always succeed let (_, _, consensus_hash) = peer.next_burnchain_block(burn_ops.clone()); - peer.process_stacks_epoch_at_tip_checked(&stacks_block, &vec![]) + peer.process_stacks_epoch_at_tip_checked(&stacks_block, &[]) .unwrap(); block_ids.push(StacksBlockHeader::make_index_block_hash( @@ -660,7 +660,7 @@ fn test_bad_microblock_fees_fix_transition() { // should always succeed let (_, _, consensus_hash) = peer.next_burnchain_block(burn_ops.clone()); - peer.process_stacks_epoch_at_tip_checked(&stacks_block, &vec![]) + peer.process_stacks_epoch_at_tip_checked(&stacks_block, &[]) .unwrap(); block_ids.push(StacksBlockHeader::make_index_block_hash( @@ -1016,7 +1016,7 @@ fn test_get_block_info_v210() { // should always succeed peer.next_burnchain_block(burn_ops.clone()); - peer.process_stacks_epoch_at_tip_checked(&stacks_block, &vec![]) + peer.process_stacks_epoch_at_tip_checked(&stacks_block, &[]) .unwrap(); } @@ -1320,7 +1320,7 @@ fn test_get_block_info_v210_no_microblocks() { // should always succeed peer.next_burnchain_block(burn_ops.clone()); - peer.process_stacks_epoch_at_tip_checked(&stacks_block, &vec![]) + peer.process_stacks_epoch_at_tip_checked(&stacks_block, &[]) .unwrap(); } @@ -1787,7 +1787,7 @@ fn test_coinbase_pay_to_alt_recipient_v210(pay_to_contract: bool) { // should always succeed peer.next_burnchain_block(burn_ops.clone()); - peer.process_stacks_epoch_at_tip_checked(&stacks_block, &vec![]) + peer.process_stacks_epoch_at_tip_checked(&stacks_block, &[]) .unwrap(); } diff --git a/stackslib/src/chainstate/stacks/tests/block_construction.rs b/stackslib/src/chainstate/stacks/tests/block_construction.rs index 90fc7f1705..edcbacad53 100644 --- a/stackslib/src/chainstate/stacks/tests/block_construction.rs +++ b/stackslib/src/chainstate/stacks/tests/block_construction.rs @@ -823,7 +823,7 @@ fn test_build_anchored_blocks_connected_by_microblocks_across_epoch() { // should always succeed peer.next_burnchain_block(burn_ops.clone()); - peer.process_stacks_epoch_at_tip_checked(&stacks_block, &vec![]) + peer.process_stacks_epoch_at_tip_checked(&stacks_block, &[]) .unwrap(); } @@ -1089,12 +1089,12 @@ fn test_build_anchored_blocks_connected_by_microblocks_across_epoch_invalid() { if tenure_id != 5 { // should always succeed - peer.process_stacks_epoch_at_tip_checked(&stacks_block, &vec![]) + peer.process_stacks_epoch_at_tip_checked(&stacks_block, &[]) .unwrap(); } else { // should fail at first, since the block won't be available // (since validate_anchored_block_burnchain() will fail) - if let Err(e) = peer.process_stacks_epoch_at_tip_checked(&stacks_block, &vec![]) { + if let Err(e) = peer.process_stacks_epoch_at_tip_checked(&stacks_block, &[]) { match e { CoordinatorError::ChainstateError(ChainstateError::InvalidStacksBlock(_)) => {} x => { @@ -1126,7 +1126,7 @@ fn test_build_anchored_blocks_connected_by_microblocks_across_epoch_invalid() { // should run to completion, but the block should *not* be processed // (this tests append_block()) - peer.process_stacks_epoch_at_tip_checked(&stacks_block, &vec![]) + peer.process_stacks_epoch_at_tip_checked(&stacks_block, &[]) .unwrap(); } @@ -3912,7 +3912,7 @@ fn test_contract_call_across_clarity_versions() { // should always succeed peer.next_burnchain_block(burn_ops.clone()); - peer.process_stacks_epoch_at_tip_checked(&stacks_block, &vec![]) + peer.process_stacks_epoch_at_tip_checked(&stacks_block, &[]) .unwrap(); } diff --git a/stackslib/src/chainstate/stacks/tests/chain_histories.rs b/stackslib/src/chainstate/stacks/tests/chain_histories.rs index 4e1b774ba7..4e5cfe8b59 100644 --- a/stackslib/src/chainstate/stacks/tests/chain_histories.rs +++ b/stackslib/src/chainstate/stacks/tests/chain_histories.rs @@ -83,7 +83,7 @@ where usize, Option<&StacksMicroblockHeader>, ) -> (StacksBlock, Vec), - G: FnMut(&StacksBlock, &Vec) -> bool, + G: FnMut(&StacksBlock, &[StacksMicroblock]) -> bool, { let full_test_name = format!("{}-1_fork_1_miner_1_burnchain", test_name); let mut burn_node = TestBurnchainNode::new(); @@ -2646,7 +2646,7 @@ fn miner_trace_replay_randomized(miner_trace: &mut TestMinerTrace) { &mut miner_trace.burn_node, &fork_snapshot, &stacks_block, - &vec![], + &[], &block_commit_op, ); @@ -2657,7 +2657,7 @@ fn miner_trace_replay_randomized(miner_trace: &mut TestMinerTrace) { &mut miner_trace.burn_node, &fork_snapshot, &stacks_block, - &vec![mblock.clone()], + &[mblock.clone()], &block_commit_op, ); diff --git a/stackslib/src/chainstate/stacks/tests/mod.rs b/stackslib/src/chainstate/stacks/tests/mod.rs index 9a6a84507e..561438fb10 100644 --- a/stackslib/src/chainstate/stacks/tests/mod.rs +++ b/stackslib/src/chainstate/stacks/tests/mod.rs @@ -555,13 +555,13 @@ impl TestStacksNode { burn_block: &mut TestBurnchainBlock, miner: &mut TestMiner, stacks_block: &StacksBlock, - microblocks: &Vec, + microblocks: &[StacksMicroblock], burn_amount: u64, miner_key: &LeaderKeyRegisterOp, parent_block_snapshot_opt: Option<&BlockSnapshot>, ) -> LeaderBlockCommitOp { self.anchored_blocks.push(stacks_block.clone()); - self.microblocks.push(microblocks.clone()); + self.microblocks.push(microblocks.to_vec()); test_debug!( "Miner {}: Commit to stacks block {} (work {},{})", @@ -721,7 +721,7 @@ pub fn preprocess_stacks_block_data( burn_node: &mut TestBurnchainNode, fork_snapshot: &BlockSnapshot, stacks_block: &StacksBlock, - stacks_microblocks: &Vec, + stacks_microblocks: &[StacksMicroblock], block_commit_op: &LeaderBlockCommitOp, ) -> Option { let block_hash = stacks_block.block_hash(); @@ -837,7 +837,7 @@ pub fn check_mining_reward( clarity_tx: &mut ClarityTx, miner: &mut TestMiner, block_height: u64, - prev_block_rewards: &Vec>, + prev_block_rewards: &[Vec], ) -> bool { let mut block_rewards = HashMap::new(); let mut stream_rewards = HashMap::new(); diff --git a/stackslib/src/chainstate/stacks/transaction.rs b/stackslib/src/chainstate/stacks/transaction.rs index c45b212b68..7db4d29b86 100644 --- a/stackslib/src/chainstate/stacks/transaction.rs +++ b/stackslib/src/chainstate/stacks/transaction.rs @@ -3479,7 +3479,7 @@ mod test { version: 1, bytes: Hash160([0xff; 20]), }; - let addr_bytes = vec![ + let addr_bytes = [ // version 0x01, // bytes 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, @@ -3641,7 +3641,7 @@ mod test { ]); let pcs = vec![stx_pc, fungible_pc, nonfungible_pc]; - let pc_bytes = vec![stx_pc_bytes, fungible_pc_bytes, nonfungible_pc_bytes]; + let pc_bytes = [stx_pc_bytes, fungible_pc_bytes, nonfungible_pc_bytes]; for i in 0..3 { check_codec_and_corruption::(&pcs[i], &pc_bytes[i]); } @@ -3727,7 +3727,7 @@ mod test { FungibleConditionCode::SentGt as u8, ]); - let bad_pc_bytes = vec![ + let bad_pc_bytes = [ stx_pc_bytes_bad_condition, fungible_pc_bytes_bad_condition, nonfungible_pc_bytes_bad_condition, @@ -3807,7 +3807,7 @@ mod test { FungibleConditionCode::SentGt as u8, ]); - let bad_pc_bytes = vec![ + let bad_pc_bytes = [ stx_pc_bytes_bad_principal, fungible_pc_bytes_bad_principal, nonfungible_pc_bytes_bad_principal, diff --git a/stackslib/src/clarity_vm/tests/epoch_switch.rs b/stackslib/src/clarity_vm/tests/epoch_switch.rs index 25d01c4905..f4549431b2 100644 --- a/stackslib/src/clarity_vm/tests/epoch_switch.rs +++ b/stackslib/src/clarity_vm/tests/epoch_switch.rs @@ -124,7 +124,7 @@ fn test_vm_epoch_switch() { let mut end_height = 0; for i in 0..20 { cur_snapshot = - test_append_snapshot(&mut db, BurnchainHeaderHash([((i + 1) as u8); 32]), &vec![]); + test_append_snapshot(&mut db, BurnchainHeaderHash([((i + 1) as u8); 32]), &[]); end_height = cur_snapshot.block_height as u32; } diff --git a/stackslib/src/clarity_vm/tests/events.rs b/stackslib/src/clarity_vm/tests/events.rs index 7037e8dcf3..61fac57f41 100644 --- a/stackslib/src/clarity_vm/tests/events.rs +++ b/stackslib/src/clarity_vm/tests/events.rs @@ -110,7 +110,7 @@ fn helper_execute_epoch( owned_env.stx_faucet(&sender, 10); let (value, _, events) = owned_env - .execute_transaction(sender, None, contract_id, method, &vec![]) + .execute_transaction(sender, None, contract_id, method, &[]) .unwrap(); (value, events) } diff --git a/stackslib/src/clarity_vm/tests/forking.rs b/stackslib/src/clarity_vm/tests/forking.rs index c74cb0c8b0..7dc7850d51 100644 --- a/stackslib/src/clarity_vm/tests/forking.rs +++ b/stackslib/src/clarity_vm/tests/forking.rs @@ -95,7 +95,7 @@ fn test_at_block_mutations(#[case] version: ClarityVersion, #[case] epoch: Stack } owned_env - .execute_transaction(p1, None, c, to_exec, &vec![]) + .execute_transaction(p1, None, c, to_exec, &[]) .map(|(x, _, _)| x) } @@ -174,7 +174,7 @@ fn test_at_block_good(#[case] version: ClarityVersion, #[case] epoch: StacksEpoc } owned_env - .execute_transaction(p1, None, c, to_exec, &vec![]) + .execute_transaction(p1, None, c, to_exec, &[]) .map(|(x, _, _)| x) } diff --git a/stackslib/src/core/tests/mod.rs b/stackslib/src/core/tests/mod.rs index a209ef0677..5802dbcb93 100644 --- a/stackslib/src/core/tests/mod.rs +++ b/stackslib/src/core/tests/mod.rs @@ -142,8 +142,8 @@ pub fn make_block( .put_indexed_all( &StacksBlockId::new(&parent.0, &parent.1), &new_index_hash, - &vec![], - &vec![], + &[], + &[], ) .unwrap(); diff --git a/stackslib/src/cost_estimates/tests/fee_medians.rs b/stackslib/src/cost_estimates/tests/fee_medians.rs index dbeef43582..102140e86b 100644 --- a/stackslib/src/cost_estimates/tests/fee_medians.rs +++ b/stackslib/src/cost_estimates/tests/fee_medians.rs @@ -286,7 +286,7 @@ fn test_window_size_forget_something() { #[test] fn test_fee_rate_estimate_5_vs_95() { assert_eq!( - fee_rate_estimate_from_sorted_weighted_fees(&vec![ + fee_rate_estimate_from_sorted_weighted_fees(&[ FeeRateAndWeight { fee_rate: 1f64, weight: 5u64, @@ -307,7 +307,7 @@ fn test_fee_rate_estimate_5_vs_95() { #[test] fn test_fee_rate_estimate_50_vs_50() { assert_eq!( - fee_rate_estimate_from_sorted_weighted_fees(&vec![ + fee_rate_estimate_from_sorted_weighted_fees(&[ FeeRateAndWeight { fee_rate: 1f64, weight: 50u64, @@ -328,7 +328,7 @@ fn test_fee_rate_estimate_50_vs_50() { #[test] fn test_fee_rate_estimate_95_vs_5() { assert_eq!( - fee_rate_estimate_from_sorted_weighted_fees(&vec![ + fee_rate_estimate_from_sorted_weighted_fees(&[ FeeRateAndWeight { fee_rate: 1f64, weight: 95u64, diff --git a/stackslib/src/net/api/tests/mod.rs b/stackslib/src/net/api/tests/mod.rs index c6c62dd1fe..069586e8b6 100644 --- a/stackslib/src/net/api/tests/mod.rs +++ b/stackslib/src/net/api/tests/mod.rs @@ -487,8 +487,8 @@ impl<'a> TestRPC<'a> { let (_, _, consensus_hash) = peer_1.next_burnchain_block(burn_ops.clone()); peer_2.next_burnchain_block(burn_ops.clone()); - peer_1.process_stacks_epoch_at_tip(&stacks_block, &vec![]); - peer_2.process_stacks_epoch_at_tip(&stacks_block, &vec![]); + peer_1.process_stacks_epoch_at_tip(&stacks_block, &[]); + peer_2.process_stacks_epoch_at_tip(&stacks_block, &[]); // build 1-block microblock stream with the contract-call and the unconfirmed contract let microblock = { diff --git a/stackslib/src/net/chat.rs b/stackslib/src/net/chat.rs index 1d8e5d10d2..cf054fe234 100644 --- a/stackslib/src/net/chat.rs +++ b/stackslib/src/net/chat.rs @@ -3106,8 +3106,8 @@ mod test { network_id: u32, key_expires: u64, data_url: UrlString, - asn4_entries: &Vec, - initial_neighbors: &Vec, + asn4_entries: &[ASEntry4], + initial_neighbors: &[Neighbor], services: u16, ) -> (PeerDB, SortitionDB, StackerDBs, PoxId, StacksChainState) { let test_path = format!("/tmp/stacks-test-databases-{}", testname); @@ -3139,9 +3139,7 @@ mod test { data_url.clone(), &asn4_entries, Some(&initial_neighbors), - &vec![ - QualifiedContractIdentifier::parse("SP000000000000000000002Q6VF78.sbtc").unwrap(), - ], + &[QualifiedContractIdentifier::parse("SP000000000000000000002Q6VF78.sbtc").unwrap()], ) .unwrap(); let sortdb = SortitionDB::connect( @@ -3287,8 +3285,8 @@ mod test { .append_chain_tip_snapshot( &prev_snapshot, &next_snapshot, - &vec![], - &vec![], + &[], + &[], None, None, None, @@ -3410,8 +3408,8 @@ mod test { 0x9abcdef0, 12350, "http://peer1.com".into(), - &vec![], - &vec![], + &[], + &[], peer_1_services, ); let (mut peerdb_2, mut sortdb_2, stackerdbs_2, pox_id_2, mut chainstate_2) = @@ -3421,8 +3419,8 @@ mod test { 0x9abcdef0, 12351, "http://peer2.com".into(), - &vec![], - &vec![], + &[], + &[], peer_2_services, ); @@ -3737,8 +3735,8 @@ mod test { 0x9abcdef0, 12350, "http://peer1.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); let (mut peerdb_2, mut sortdb_2, stackerdbs_2, pox_id_2, mut chainstate_2) = @@ -3748,8 +3746,8 @@ mod test { 0x9abcdef0, 12351, "http://peer2.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); @@ -3917,8 +3915,8 @@ mod test { 0x9abcdef0, 12350, "http://peer1.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); let (mut peerdb_2, mut sortdb_2, stackerdbs_2, pox_id_2, mut chainstate_2) = @@ -3928,8 +3926,8 @@ mod test { 0x9abcdef0, 12351, "http://peer2.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); @@ -4062,8 +4060,8 @@ mod test { 0x9abcdef0, 12350, "http://peer1.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); let (mut peerdb_2, mut sortdb_2, stackerdbs_2, pox_id_2, mut chainstate_2) = @@ -4073,8 +4071,8 @@ mod test { 0x9abcdef0, 12351, "http://peer2.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); @@ -4206,8 +4204,8 @@ mod test { 0x9abcdef0, 12350, "http://peer1.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); let (mut peerdb_2, mut sortdb_2, stackerdbs_2, pox_id_2, mut chainstate_2) = @@ -4217,8 +4215,8 @@ mod test { 0x9abcdef0, 12351, "http://peer2.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); @@ -4363,8 +4361,8 @@ mod test { 0x9abcdef0, 12350, "http://peer1.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); let (mut peerdb_2, mut sortdb_2, stackerdbs_2, pox_id_2, mut chainstate_2) = @@ -4374,8 +4372,8 @@ mod test { 0x9abcdef0, 12351, "http://peer2.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); @@ -4562,8 +4560,8 @@ mod test { 0x9abcdef0, 12350, "http://peer1.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); let (mut peerdb_2, mut sortdb_2, stackerdbs_2, pox_id_2, mut chainstate_2) = @@ -4573,8 +4571,8 @@ mod test { 0x9abcdef0, 12351, "http://peer2.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); @@ -4706,8 +4704,8 @@ mod test { 0x9abcdef0, 12350, "http://peer1.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); let (mut peerdb_2, mut sortdb_2, stackerdbs_2, pox_id_2, mut chainstate_2) = @@ -4717,8 +4715,8 @@ mod test { 0x9abcdef0, 12351, "http://peer2.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); @@ -4882,8 +4880,8 @@ mod test { 0x9abcdef0, 12350, "http://peer1.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); let (mut peerdb_2, mut sortdb_2, stackerdbs_2, pox_id_2, mut chainstate_2) = @@ -4893,8 +4891,8 @@ mod test { 0x9abcdef0, 12351, "http://peer2.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); @@ -5109,8 +5107,8 @@ mod test { 0x9abcdef0, 12350, "http://peer1.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); let (mut peerdb_2, mut sortdb_2, stackerdbs_2, pox_id_2, mut chainstate_2) = @@ -5120,8 +5118,8 @@ mod test { 0x9abcdef0, 12351, "http://peer2.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); @@ -5259,8 +5257,8 @@ mod test { 0x9abcdef0, 12350, "http://peer1.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); let (mut peerdb_2, mut sortdb_2, stackerdbs_2, pox_id_2, mut chainstate_2) = @@ -5270,8 +5268,8 @@ mod test { 0x9abcdef0, 12351, "http://peer2.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); @@ -5430,8 +5428,8 @@ mod test { 0x9abcdef0, 12350, "http://peer1.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); let (mut peerdb_2, mut sortdb_2, stackerdbs_2, pox_id_2, mut chainstate_2) = @@ -5441,8 +5439,8 @@ mod test { 0x9abcdef0, 12351, "http://peer2.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); @@ -5709,8 +5707,8 @@ mod test { 0x9abcdef0, 12350, "http://peer1.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); let (mut peerdb_2, mut sortdb_2, stackerdbs_2, pox_id_2, mut chainstate_2) = @@ -5720,8 +5718,8 @@ mod test { 0x9abcdef0, 12351, "http://peer2.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); @@ -5989,8 +5987,8 @@ mod test { 0x9abcdef0, 12352, "http://peer1.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); let (mut peerdb_2, mut sortdb_2, stackerdbs_2, pox_id_2, mut chainstate_2) = @@ -6000,8 +5998,8 @@ mod test { 0x9abcdef0, 12353, "http://peer2.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); @@ -6124,8 +6122,8 @@ mod test { 0x9abcdef0, 12352, "http://peer1.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); @@ -6792,8 +6790,8 @@ mod test { 0x9abcdef0, 12352, "http://peer1.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); @@ -6910,8 +6908,8 @@ mod test { 0x9abcdef0, 12352, "http://peer1.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); @@ -6977,8 +6975,8 @@ mod test { 0x9abcdef0, 12352, "http://peer1.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); @@ -7111,8 +7109,8 @@ mod test { 0x9abcdef0, 12352, "http://peer1.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); @@ -7245,8 +7243,8 @@ mod test { 0x9abcdef0, 12352, "http://peer1.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); @@ -7379,8 +7377,8 @@ mod test { 0x9abcdef0, 12352, "http://peer1.com".into(), - &vec![], - &vec![], + &[], + &[], DEFAULT_SERVICES, ); diff --git a/stackslib/src/net/codec.rs b/stackslib/src/net/codec.rs index bd8154e414..fe0820effe 100644 --- a/stackslib/src/net/codec.rs +++ b/stackslib/src/net/codec.rs @@ -276,7 +276,7 @@ impl BlocksInvData { } } - pub fn compress_bools(bits: &Vec) -> Vec { + pub fn compress_bools(bits: &[bool]) -> Vec { let bvl: u16 = bits .len() .try_into() @@ -1665,7 +1665,7 @@ pub mod test { pub fn check_codec_and_corruption( obj: &T, - bytes: &Vec, + bytes: &[u8], ) -> () { // obj should serialize to bytes let mut write_buf: Vec = Vec::with_capacity(bytes.len()); @@ -1718,43 +1718,43 @@ pub mod test { #[test] fn codec_primitive_types() { - check_codec_and_corruption::(&0x01, &vec![0x01]); - check_codec_and_corruption::(&0x0203, &vec![0x02, 0x03]); - check_codec_and_corruption::(&0x04050607, &vec![0x04, 0x05, 0x06, 0x07]); + check_codec_and_corruption::(&0x01, &[0x01]); + check_codec_and_corruption::(&0x0203, &[0x02, 0x03]); + check_codec_and_corruption::(&0x04050607, &[0x04, 0x05, 0x06, 0x07]); check_codec_and_corruption::( &0x08090a0b0c0d0e0f, - &vec![0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f], + &[0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f], ); } #[test] fn codec_primitive_vector() { - check_codec_and_corruption::>(&vec![], &vec![0x00, 0x00, 0x00, 0x00]); + check_codec_and_corruption::>(&vec![], &[0x00, 0x00, 0x00, 0x00]); check_codec_and_corruption::>( &vec![0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09], - &vec![ + &[ 0x00, 0x00, 0x00, 0x0a, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, ], ); - check_codec_and_corruption::>(&vec![], &vec![0x00, 0x00, 0x00, 0x00]); + check_codec_and_corruption::>(&vec![], &[0x00, 0x00, 0x00, 0x00]); check_codec_and_corruption::>( &vec![ 0xf000, 0xf101, 0xf202, 0xf303, 0xf404, 0xf505, 0xf606, 0xf707, 0xf808, 0xf909, ], - &vec![ + &[ 0x00, 0x00, 0x00, 0x0a, 0xf0, 0x00, 0xf1, 0x01, 0xf2, 0x02, 0xf3, 0x03, 0xf4, 0x04, 0xf5, 0x05, 0xf6, 0x06, 0xf7, 0x07, 0xf8, 0x08, 0xf9, 0x09, ], ); - check_codec_and_corruption::>(&vec![], &vec![0x00, 0x00, 0x00, 0x00]); + check_codec_and_corruption::>(&vec![], &[0x00, 0x00, 0x00, 0x00]); check_codec_and_corruption::>( &vec![ 0xa0b0f000, 0xa1b1f101, 0xa2b2f202, 0xa3b3f303, 0xa4b4f404, 0xa5b5f505, 0xa6b6f606, 0xa7b7f707, 0xa8b8f808, 0xa9b9f909, ], - &vec![ + &[ 0x00, 0x00, 0x00, 0x0a, 0xa0, 0xb0, 0xf0, 0x00, 0xa1, 0xb1, 0xf1, 0x01, 0xa2, 0xb2, 0xf2, 0x02, 0xa3, 0xb3, 0xf3, 0x03, 0xa4, 0xb4, 0xf4, 0x04, 0xa5, 0xb5, 0xf5, 0x05, 0xa6, 0xb6, 0xf6, 0x06, 0xa7, 0xb7, 0xf7, 0x07, 0xa8, 0xb8, 0xf8, 0x08, 0xa9, 0xb9, @@ -1762,7 +1762,7 @@ pub mod test { ], ); - check_codec_and_corruption::>(&vec![], &vec![0x00, 0x00, 0x00, 0x00]); + check_codec_and_corruption::>(&vec![], &[0x00, 0x00, 0x00, 0x00]); check_codec_and_corruption::>( &vec![ 0x1020304050607080, @@ -1775,7 +1775,7 @@ pub mod test { 0x1727374757677787, 0x1828384858687888, ], - &vec![ + &[ 0x00, 0x00, 0x00, 0x09, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71, 0x81, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72, 0x82, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73, 0x83, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, @@ -1924,7 +1924,7 @@ pub mod test { bitlen: 0, pox_bitvec: vec![], }; - let empty_inv_bytes = vec![ + let empty_inv_bytes = [ // bitlen 0x00, 0x00, 0x00, 0x00, // bitvec 0x00, 0x00, 0x00, 0x00, @@ -1999,7 +1999,7 @@ pub mod test { block_bitvec: vec![], microblocks_bitvec: vec![], }; - let empty_inv_bytes = vec![ + let empty_inv_bytes = [ // bitlen 0x00, 0x00, 0x00, 0x00, // bitvec 0x00, 0x00, 0x00, 0x00, // microblock bitvec @@ -2451,7 +2451,7 @@ pub mod test { .unwrap(), }; - let nakamoto_inv_bytes = vec![ + let nakamoto_inv_bytes = [ // bitlen 0x00, 0x40, // vec len 0x00, 0x00, 0x00, 0x08, // bits @@ -2461,7 +2461,7 @@ pub mod test { check_codec_and_corruption::(&nakamoto_inv, &nakamoto_inv_bytes); // should fail - let nakamoto_inv_bytes = vec![ + let nakamoto_inv_bytes = [ // bitlen 0x00, 0x20, // vec len 0x00, 0x00, 0x00, 0x05, // bits @@ -2471,7 +2471,7 @@ pub mod test { let _ = NakamotoInvData::consensus_deserialize(&mut &nakamoto_inv_bytes[..]).unwrap_err(); // should fail - let nakamoto_inv_bytes = vec![ + let nakamoto_inv_bytes = [ // bitlen 0x00, 0x21, // vec len 0x00, 0x00, 0x00, 0x04, // bits diff --git a/stackslib/src/net/db.rs b/stackslib/src/net/db.rs index ff6b5a9a05..7f42fd38aa 100644 --- a/stackslib/src/net/db.rs +++ b/stackslib/src/net/db.rs @@ -1991,15 +1991,9 @@ mod test { out_degree: 1, }; - let mut db = PeerDB::connect_memory( - 0x9abcdef0, - 12345, - 0, - "http://foo.com".into(), - &vec![], - &vec![], - ) - .unwrap(); + let mut db = + PeerDB::connect_memory(0x9abcdef0, 12345, 0, "http://foo.com".into(), &[], &[]) + .unwrap(); let neighbor_before_opt = PeerDB::get_peer( db.conn(), @@ -2051,15 +2045,9 @@ mod test { /// IDs. New peers' contract IDs get added, and dropped peers' contract IDs get removed. #[test] fn test_insert_or_replace_stacker_dbs() { - let mut db = PeerDB::connect_memory( - 0x9abcdef0, - 12345, - 0, - "http://foo.com".into(), - &vec![], - &vec![], - ) - .unwrap(); + let mut db = + PeerDB::connect_memory(0x9abcdef0, 12345, 0, "http://foo.com".into(), &[], &[]) + .unwrap(); // the neighbors to whom this DB corresponds let neighbor_1 = Neighbor { @@ -2219,15 +2207,9 @@ mod test { out_degree: 1, }; - let mut db = PeerDB::connect_memory( - 0x9abcdef0, - 12345, - 0, - "http://foo.com".into(), - &vec![], - &vec![], - ) - .unwrap(); + let mut db = + PeerDB::connect_memory(0x9abcdef0, 12345, 0, "http://foo.com".into(), &[], &[]) + .unwrap(); { let tx = db.tx_begin().unwrap(); @@ -2351,7 +2333,7 @@ mod test { PeerAddress::from_ipv4(127, 0, 0, 1), 12345, UrlString::try_from("http://foo.com").unwrap(), - &vec![], + &[], None, &[], ) @@ -2552,7 +2534,7 @@ mod test { PeerAddress::from_ipv4(127, 0, 0, 1), 12345, UrlString::try_from("http://foo.com").unwrap(), - &vec![], + &[], None, &[], ) @@ -2860,7 +2842,7 @@ mod test { }); } - fn are_present(ne: &Vec, nei: &Vec) -> bool { + fn are_present(ne: &[Neighbor], nei: &[Neighbor]) -> bool { for n in ne { let mut found = false; for ni in nei { @@ -2881,7 +2863,7 @@ mod test { 12345, 0, "http://foo.com".into(), - &vec![], + &[], &initial_neighbors, ) .unwrap(); @@ -2965,7 +2947,7 @@ mod test { }); } - fn are_present(ne: &Vec, nei: &Vec) -> bool { + fn are_present(ne: &[Neighbor], nei: &[Neighbor]) -> bool { for n in ne { let mut found = false; for ni in nei { @@ -2987,7 +2969,7 @@ mod test { 12345, 0, "http://foo.com".into(), - &vec![], + &[], &initial_neighbors, ) .unwrap(); @@ -3075,7 +3057,7 @@ mod test { 0, "http://foo.com".into(), &asn4_table, - &vec![], + &[], ) .unwrap(); @@ -3134,15 +3116,9 @@ mod test { /// `denied` and `allowed` columns appropriately. #[test] fn test_peer_preemptive_deny_allow() { - let mut db = PeerDB::connect_memory( - 0x9abcdef0, - 12345, - 0, - "http://foo.com".into(), - &vec![], - &vec![], - ) - .unwrap(); + let mut db = + PeerDB::connect_memory(0x9abcdef0, 12345, 0, "http://foo.com".into(), &[], &[]) + .unwrap(); { let tx = db.tx_begin().unwrap(); PeerDB::set_deny_peer(&tx, 0x9abcdef0, &PeerAddress([0x1; 16]), 12345, 10000000) @@ -3167,15 +3143,9 @@ mod test { /// PeerDB::get_allowed_cidrs() correctly store and load CIDR prefixes #[test] fn test_peer_cidr_lists() { - let mut db = PeerDB::connect_memory( - 0x9abcdef0, - 12345, - 0, - "http://foo.com".into(), - &vec![], - &vec![], - ) - .unwrap(); + let mut db = + PeerDB::connect_memory(0x9abcdef0, 12345, 0, "http://foo.com".into(), &[], &[]) + .unwrap(); { let tx = db.tx_begin().unwrap(); PeerDB::add_cidr_prefix(&tx, "denied_prefixes", &PeerAddress([0x1; 16]), 64).unwrap(); @@ -3194,15 +3164,9 @@ mod test { /// Tests PeerDB::is_address_denied() #[test] fn test_peer_is_denied() { - let mut db = PeerDB::connect_memory( - 0x9abcdef0, - 12345, - 0, - "http://foo.com".into(), - &vec![], - &vec![], - ) - .unwrap(); + let mut db = + PeerDB::connect_memory(0x9abcdef0, 12345, 0, "http://foo.com".into(), &[], &[]) + .unwrap(); { let tx = db.tx_begin().unwrap(); PeerDB::add_deny_cidr( @@ -3334,8 +3298,8 @@ mod test { 12345, 0, "http://foo.com".into(), - &vec![], - &vec![neighbor_1.clone(), neighbor_2.clone()], + &[], + &[neighbor_1.clone(), neighbor_2.clone()], ) .unwrap(); @@ -3483,8 +3447,8 @@ mod test { 12345, 0, "http://foo.com".into(), - &vec![], - &vec![neighbor_1.clone(), neighbor_2.clone()], + &[], + &[neighbor_1.clone(), neighbor_2.clone()], ) .unwrap(); { @@ -3570,7 +3534,7 @@ mod test { PeerAddress::from_ipv4(127, 0, 0, 1), 12345, UrlString::try_from("http://foo.com").unwrap(), - &vec![], + &[], None, &[], ) @@ -3590,7 +3554,7 @@ mod test { PeerAddress::from_ipv4(127, 0, 0, 1), 12345, UrlString::try_from("http://foo.com").unwrap(), - &vec![], + &[], None, &[], ) @@ -3608,7 +3572,7 @@ mod test { PeerAddress::from_ipv4(127, 0, 0, 1), 12345, UrlString::try_from("http://foo.com").unwrap(), - &vec![], + &[], None, &[], ) @@ -3637,7 +3601,7 @@ mod test { PeerAddress::from_ipv4(127, 0, 0, 1), 12345, UrlString::try_from("http://foo.com").unwrap(), - &vec![], + &[], None, &[], ) @@ -3663,13 +3627,13 @@ mod test { PeerAddress::from_ipv4(127, 0, 0, 1), 12345, UrlString::try_from("http://foo.com").unwrap(), - &vec![], + &[], None, &[], ) .unwrap(); - let private_addrbytes = vec![ + let private_addrbytes = [ PeerAddress::from_ipv4(127, 0, 0, 1), PeerAddress::from_ipv4(192, 168, 0, 1), PeerAddress::from_ipv4(172, 16, 0, 1), @@ -3684,7 +3648,7 @@ mod test { ]), ]; - let public_addrbytes = vec![ + let public_addrbytes = [ PeerAddress::from_ipv4(1, 2, 3, 4), PeerAddress([ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, @@ -3810,7 +3774,7 @@ mod test { PeerAddress::from_ipv4(127, 0, 0, 1), 12345, UrlString::try_from("http://foo.com").unwrap(), - &vec![], + &[], None, &[], ) diff --git a/stackslib/src/net/dns.rs b/stackslib/src/net/dns.rs index aedb73bd62..64052ab9f5 100644 --- a/stackslib/src/net/dns.rs +++ b/stackslib/src/net/dns.rs @@ -399,7 +399,7 @@ mod test { #[test] fn dns_resolve_10_names() { let (mut client, thread_handle) = dns_thread_start(100); - let names = vec![ + let names = [ "www.google.com", "www.facebook.com", "www.twitter.com", diff --git a/stackslib/src/net/http/tests.rs b/stackslib/src/net/http/tests.rs index a17635bc59..71a9e7e3f7 100644 --- a/stackslib/src/net/http/tests.rs +++ b/stackslib/src/net/http/tests.rs @@ -566,7 +566,7 @@ fn test_http_request_version_keep_alive() { // (have 'connection' header?, have 'keep-alive' value?) let requests_connection_expected = - vec![(true, true), (false, false), (false, false), (true, false)]; + [(true, true), (false, false), (false, false), (true, false)]; for (r, (has_connection, is_keep_alive)) in requests.iter().zip(requests_connection_expected.iter()) @@ -594,7 +594,7 @@ fn test_http_request_version_keep_alive() { #[test] fn test_http_response_version_keep_alive() { // (version, explicit keep-alive?) - let responses_args = vec![ + let responses_args = [ (HttpVersion::Http10, true), (HttpVersion::Http10, false), (HttpVersion::Http11, true), diff --git a/stackslib/src/net/mod.rs b/stackslib/src/net/mod.rs index 4af4d2a397..df9d227a75 100644 --- a/stackslib/src/net/mod.rs +++ b/stackslib/src/net/mod.rs @@ -3850,7 +3850,7 @@ pub mod test { /// Validate them and store them to staging. pub fn preprocess_stacks_microblocks( &mut self, - microblocks: &Vec, + microblocks: &[StacksMicroblock], ) -> Result { assert!(microblocks.len() > 0); let sortdb = self.sortdb.take().unwrap(); @@ -3903,7 +3903,7 @@ pub mod test { pub fn process_stacks_epoch_at_tip( &mut self, block: &StacksBlock, - microblocks: &Vec, + microblocks: &[StacksMicroblock], ) -> () { let sortdb = self.sortdb.take().unwrap(); let mut node = self.stacks_node.take().unwrap(); @@ -3940,7 +3940,7 @@ pub mod test { sortdb: &SortitionDB, node: &mut TestStacksNode, block: &StacksBlock, - microblocks: &Vec, + microblocks: &[StacksMicroblock], ) -> Result<(), coordinator_error> { { let ic = sortdb.index_conn(); @@ -3970,7 +3970,7 @@ pub mod test { pub fn process_stacks_epoch_at_tip_checked( &mut self, block: &StacksBlock, - microblocks: &Vec, + microblocks: &[StacksMicroblock], ) -> Result<(), coordinator_error> { let sortdb = self.sortdb.take().unwrap(); let mut node = self.stacks_node.take().unwrap(); @@ -3987,7 +3987,7 @@ pub mod test { &mut self, block: &StacksBlock, consensus_hash: &ConsensusHash, - microblocks: &Vec, + microblocks: &[StacksMicroblock], ) -> () { let sortdb = self.sortdb.take().unwrap(); let mut node = self.stacks_node.take().unwrap(); diff --git a/stackslib/src/net/neighbors/db.rs b/stackslib/src/net/neighbors/db.rs index 0289875f11..1da186acd8 100644 --- a/stackslib/src/net/neighbors/db.rs +++ b/stackslib/src/net/neighbors/db.rs @@ -110,7 +110,7 @@ pub trait NeighborWalkDB { fn lookup_stale_neighbors( &self, network: &PeerNetwork, - addrs: &Vec, + addrs: &[NeighborAddress], ) -> Result<(HashMap, Vec), net_error>; /// Add a neighbor to the DB, or if there's no slot available for it, schedule it to be @@ -320,7 +320,7 @@ impl NeighborWalkDB for PeerDBNeighborWalk { fn lookup_stale_neighbors( &self, network: &PeerNetwork, - addrs: &Vec, + addrs: &[NeighborAddress], ) -> Result<(HashMap, Vec), net_error> { let network_id = network.bound_neighbor_key().network_id; let block_height = network.get_chain_view().burn_block_height; diff --git a/stackslib/src/net/p2p.rs b/stackslib/src/net/p2p.rs index 13f7ad7fac..41b60e883f 100644 --- a/stackslib/src/net/p2p.rs +++ b/stackslib/src/net/p2p.rs @@ -1286,7 +1286,7 @@ impl PeerNetwork { /// connection to the same neighbor, only one connection will be used. fn sample_broadcast_peers( &self, - relay_hints: &Vec, + relay_hints: &[RelayData], payload: &R, ) -> Result, net_error> { // coalesce @@ -5383,7 +5383,7 @@ mod test { neighbor } - fn make_test_p2p_network(initial_neighbors: &Vec) -> PeerNetwork { + fn make_test_p2p_network(initial_neighbors: &[Neighbor]) -> PeerNetwork { let mut conn_opts = ConnectionOptions::default(); conn_opts.inbox_maxlen = 5; conn_opts.outbox_maxlen = 5; @@ -5423,7 +5423,7 @@ mod test { 0, 23456, "http://test-p2p.com".into(), - &vec![], + &[], initial_neighbors, ) .unwrap(); @@ -5453,7 +5453,7 @@ mod test { fn test_event_id_no_connecting_leaks() { with_timeout(100, || { let neighbor = make_test_neighbor(2300); - let mut p2p = make_test_p2p_network(&vec![]); + let mut p2p = make_test_p2p_network(&[]); use std::net::TcpListener; let listener = TcpListener::bind("127.0.0.1:2300").unwrap(); @@ -5614,7 +5614,7 @@ mod test { with_timeout(100, || { let neighbor = make_test_neighbor(2200); - let mut p2p = make_test_p2p_network(&vec![]); + let mut p2p = make_test_p2p_network(&[]); let mut h = p2p.new_handle(1); diff --git a/stackslib/src/net/stackerdb/tests/sync.rs b/stackslib/src/net/stackerdb/tests/sync.rs index 5f6e8a7bed..83a49a3c61 100644 --- a/stackslib/src/net/stackerdb/tests/sync.rs +++ b/stackslib/src/net/stackerdb/tests/sync.rs @@ -887,8 +887,8 @@ fn test_stackerdb_push_relayer_late_chunks() { let mut peer_1_nonce = 0; let mut peer_2_nonce = 0; let mut peer_3_nonce = 0; - peer_1.tenure_with_txs(&vec![], &mut peer_1_nonce); - peer_2.tenure_with_txs(&vec![], &mut peer_2_nonce); + peer_1.tenure_with_txs(&[], &mut peer_1_nonce); + peer_2.tenure_with_txs(&[], &mut peer_2_nonce); // sanity check -- peer 1 and 2 are at the same tip, but not 3 let sn1 = SortitionDB::get_canonical_burn_chain_tip(peer_1.sortdb().conn()).unwrap(); @@ -1043,7 +1043,7 @@ fn test_stackerdb_push_relayer_late_chunks() { if num_pending >= 10 && !advanced_tenure { debug!("======= Advancing peer 3 tenure ========"); - peer_3.tenure_with_txs(&vec![], &mut peer_3_nonce); + peer_3.tenure_with_txs(&[], &mut peer_3_nonce); advanced_tenure = true; } } diff --git a/stackslib/src/net/tests/convergence.rs b/stackslib/src/net/tests/convergence.rs index 8494f4ea46..69430e08a1 100644 --- a/stackslib/src/net/tests/convergence.rs +++ b/stackslib/src/net/tests/convergence.rs @@ -757,7 +757,7 @@ fn test_walk_inbound_line(peer_configs: &mut Vec) -> Vec| { + |peers: &[TestPeer]| { let mut done = true; for i in 0..peer_count { // only check "public" peers @@ -840,7 +840,7 @@ fn test_walk_inbound_line_15() { }) } -fn dump_peers(peers: &Vec) -> () { +fn dump_peers(peers: &[TestPeer]) -> () { test_debug!("\n=== PEER DUMP ==="); for i in 0..peers.len() { let mut neighbor_index = vec![]; @@ -870,7 +870,7 @@ fn dump_peers(peers: &Vec) -> () { test_debug!("\n"); } -fn dump_peer_histograms(peers: &Vec) -> () { +fn dump_peer_histograms(peers: &[TestPeer]) -> () { let mut outbound_hist: HashMap = HashMap::new(); let mut inbound_hist: HashMap = HashMap::new(); let mut all_hist: HashMap = HashMap::new(); @@ -943,7 +943,7 @@ fn run_topology_test_ex( use_finished_check: bool, ) -> () where - F: FnMut(&Vec) -> bool, + F: FnMut(&[TestPeer]) -> bool, { let peer_count = peers.len(); diff --git a/stackslib/src/net/tests/download/epoch2x.rs b/stackslib/src/net/tests/download/epoch2x.rs index 2d53c89f9a..78a1d832c8 100644 --- a/stackslib/src/net/tests/download/epoch2x.rs +++ b/stackslib/src/net/tests/download/epoch2x.rs @@ -1459,7 +1459,7 @@ pub fn test_get_blocks_and_microblocks_2_peers_download_multiple_microblock_desc let (_, burn_header_hash, consensus_hash) = peers[1].next_burnchain_block(burn_ops.clone()); - peers[1].process_stacks_epoch(&stacks_block, &consensus_hash, &vec![]); + peers[1].process_stacks_epoch(&stacks_block, &consensus_hash, &[]); TestPeer::set_ops_burn_header_hash(&mut burn_ops, &burn_header_hash); diff --git a/stackslib/src/net/tests/download/nakamoto.rs b/stackslib/src/net/tests/download/nakamoto.rs index a479dad07a..acfebe2bcc 100644 --- a/stackslib/src/net/tests/download/nakamoto.rs +++ b/stackslib/src/net/tests/download/nakamoto.rs @@ -1448,7 +1448,7 @@ fn test_make_tenure_downloaders() { { let sortdb = peer.sortdb(); let wanted_tenures = - NakamotoDownloadStateMachine::load_wanted_tenures_at_tip(None, &tip, sortdb, &vec![]) + NakamotoDownloadStateMachine::load_wanted_tenures_at_tip(None, &tip, sortdb, &[]) .unwrap(); assert_eq!(wanted_tenures.len(), 2); for i in (tip.block_height - 1)..=(tip.block_height) { @@ -1470,7 +1470,7 @@ fn test_make_tenure_downloaders() { None, &tip, sortdb, - &vec![all_wanted_tenures[0].clone()], + &[all_wanted_tenures[0].clone()], ) .unwrap(); assert_eq!(wanted_tenures.len(), 1); diff --git a/stackslib/src/net/tests/httpcore.rs b/stackslib/src/net/tests/httpcore.rs index 4bcf52605c..fed0b7d9af 100644 --- a/stackslib/src/net/tests/httpcore.rs +++ b/stackslib/src/net/tests/httpcore.rs @@ -809,14 +809,14 @@ fn test_http_response_type_codec_err() { ("GET", "/v2/neighbors"), ("GET", "/v2/neighbors"), ]; - let bad_request_payloads = vec![ + let bad_request_payloads = [ "HTTP/1.1 200 OK\r\nServer: stacks/v2.0\r\nX-Request-Id: 123\r\nContent-Type: application/json\r\nContent-length: 2\r\n\r\nab", "HTTP/1.1 200 OK\r\nServer: stacks/v2.0\r\nX-Request-Id: 123\r\nContent-Type: application/json\r\nContent-length: 4\r\n\r\n\"ab\"", "HTTP/1.1 200 OK\r\nServer: stacks/v2.0\r\nX-Request-Id: 123\r\nContent-Type: application/json\r\nContent-length: 1\r\n\r\n{", "HTTP/1.1 200 OK\r\nServer: stacks/v2.0\r\nX-Request-Id: 123\r\nContent-Type: application/json\r\nContent-length: 1\r\n\r\na", "HTTP/1.1 400 Bad Request\r\nServer: stacks/v2.0\r\nX-Request-Id: 123\r\nContent-Type: application/octet-stream\r\nContent-length: 2\r\n\r\n{}", ]; - let expected_bad_request_payload_errors = vec![ + let expected_bad_request_payload_errors = [ "Invalid content-type", "bad length 2 for hex string", "Not enough bytes", diff --git a/stackslib/src/net/tests/inv/epoch2x.rs b/stackslib/src/net/tests/inv/epoch2x.rs index e31b6dc593..91b9c2ed3f 100644 --- a/stackslib/src/net/tests/inv/epoch2x.rs +++ b/stackslib/src/net/tests/inv/epoch2x.rs @@ -34,11 +34,11 @@ use crate::util_lib::test::*; #[test] fn peerblocksinv_has_ith_block() { let peer_inv = PeerBlocksInv::new(vec![0x55, 0x77], vec![0x11, 0x22], vec![0x01], 16, 1, 12345); - let has_blocks = vec![ + let has_blocks = [ true, false, true, false, true, false, true, false, true, true, true, false, true, true, true, false, ]; - let has_microblocks = vec![ + let has_microblocks = [ true, false, false, false, true, false, false, false, false, true, false, false, false, true, false, false, ]; diff --git a/stackslib/src/net/tests/mod.rs b/stackslib/src/net/tests/mod.rs index 53d6ec9fa1..108aecf4f5 100644 --- a/stackslib/src/net/tests/mod.rs +++ b/stackslib/src/net/tests/mod.rs @@ -474,11 +474,11 @@ impl NakamotoBootPlan { // advance to just past pox-4 instantiation let mut blocks_produced = false; while sortition_height <= epoch_25_height { - peer.tenure_with_txs(&vec![], &mut peer_nonce); + peer.tenure_with_txs(&[], &mut peer_nonce); for (other_peer, other_peer_nonce) in other_peers.iter_mut().zip(other_peer_nonces.iter_mut()) { - other_peer.tenure_with_txs(&vec![], other_peer_nonce); + other_peer.tenure_with_txs(&[], other_peer_nonce); } sortition_height = peer.get_burn_block_height(); @@ -490,11 +490,11 @@ impl NakamotoBootPlan { // that if its the first block produced, this will be 0 which will // prevent the lockups from being valid. if !blocks_produced { - peer.tenure_with_txs(&vec![], &mut peer_nonce); + peer.tenure_with_txs(&[], &mut peer_nonce); for (other_peer, other_peer_nonce) in other_peers.iter_mut().zip(other_peer_nonces.iter_mut()) { - other_peer.tenure_with_txs(&vec![], other_peer_nonce); + other_peer.tenure_with_txs(&[], other_peer_nonce); } sortition_height = peer.get_burn_block_height(); @@ -626,7 +626,7 @@ impl NakamotoBootPlan { // advance to the start of epoch 3.0 while sortition_height < epoch_30_height - 1 { let mut old_tip = peer.network.stacks_tip.clone(); - peer.tenure_with_txs(&vec![], &mut peer_nonce); + peer.tenure_with_txs(&[], &mut peer_nonce); let (stacks_tip_ch, stacks_tip_bh) = SortitionDB::get_canonical_stacks_chain_tip_hash(peer.sortdb().conn()).unwrap(); @@ -641,7 +641,7 @@ impl NakamotoBootPlan { other_peers.iter_mut().zip(other_peer_nonces.iter_mut()) { let mut old_tip = peer.network.stacks_tip.clone(); - other_peer.tenure_with_txs(&vec![], other_peer_nonce); + other_peer.tenure_with_txs(&[], other_peer_nonce); let (stacks_tip_ch, stacks_tip_bh) = SortitionDB::get_canonical_stacks_chain_tip_hash(other_peer.sortdb().conn()) diff --git a/stackslib/src/net/tests/relay/epoch2x.rs b/stackslib/src/net/tests/relay/epoch2x.rs index f4fc8d9eb8..ea36d361f9 100644 --- a/stackslib/src/net/tests/relay/epoch2x.rs +++ b/stackslib/src/net/tests/relay/epoch2x.rs @@ -370,7 +370,7 @@ fn test_relay_inbound_peer_rankings() { // total dups == 7 let dist = relay_stats.get_inbound_relay_rankings( - &vec![nk_1.clone(), nk_2.clone(), nk_3.clone()], + &[nk_1.clone(), nk_2.clone(), nk_3.clone()], &all_transactions[0], 0, ); @@ -380,7 +380,7 @@ fn test_relay_inbound_peer_rankings() { // high warmup period let dist = relay_stats.get_inbound_relay_rankings( - &vec![nk_1.clone(), nk_2.clone(), nk_3.clone()], + &[nk_1.clone(), nk_2.clone(), nk_3.clone()], &all_transactions[0], 100, ); @@ -487,23 +487,21 @@ fn test_relay_outbound_peer_rankings() { 0, 4032, UrlString::try_from("http://foo.com").unwrap(), - &vec![asn1, asn2], - &vec![n1.clone(), n2.clone(), n3.clone()], + &[asn1, asn2], + &[n1.clone(), n2.clone(), n3.clone()], ) .unwrap(); - let asn_count = RelayerStats::count_ASNs( - peerdb.conn(), - &vec![nk_1.clone(), nk_2.clone(), nk_3.clone()], - ) - .unwrap(); + let asn_count = + RelayerStats::count_ASNs(peerdb.conn(), &[nk_1.clone(), nk_2.clone(), nk_3.clone()]) + .unwrap(); assert_eq!(asn_count.len(), 3); assert_eq!(*asn_count.get(&nk_1).unwrap(), 1); assert_eq!(*asn_count.get(&nk_2).unwrap(), 2); assert_eq!(*asn_count.get(&nk_3).unwrap(), 2); let ranking = relay_stats - .get_outbound_relay_rankings(&peerdb, &vec![nk_1.clone(), nk_2.clone(), nk_3.clone()]) + .get_outbound_relay_rankings(&peerdb, &[nk_1.clone(), nk_2.clone(), nk_3.clone()]) .unwrap(); assert_eq!(ranking.len(), 3); assert_eq!(*ranking.get(&nk_1).unwrap(), 5 - 1 + 1); @@ -511,7 +509,7 @@ fn test_relay_outbound_peer_rankings() { assert_eq!(*ranking.get(&nk_3).unwrap(), 5 - 2 + 1); let ranking = relay_stats - .get_outbound_relay_rankings(&peerdb, &vec![nk_2.clone(), nk_3.clone()]) + .get_outbound_relay_rankings(&peerdb, &[nk_2.clone(), nk_3.clone()]) .unwrap(); assert_eq!(ranking.len(), 2); assert_eq!(*ranking.get(&nk_2).unwrap(), 4 - 2 + 1); @@ -1675,7 +1673,7 @@ fn test_get_blocks_and_microblocks_2_peers_push_transactions() { peers[i].next_burnchain_block_raw(burn_ops.clone()); if b == 0 { // prime with first block - peers[i].process_stacks_epoch_at_tip(&stacks_block, &vec![]); + peers[i].process_stacks_epoch_at_tip(&stacks_block, &[]); } } @@ -2882,7 +2880,7 @@ fn process_new_blocks_rejects_problematic_asts() { ); let (_, _, consensus_hash) = peer.next_burnchain_block(burn_ops.clone()); - peer.process_stacks_epoch(&block, &consensus_hash, &vec![]); + peer.process_stacks_epoch(&block, &consensus_hash, &[]); let tip = SortitionDB::get_canonical_burn_chain_tip(&peer.sortdb.as_ref().unwrap().conn()).unwrap(); @@ -3040,7 +3038,7 @@ fn process_new_blocks_rejects_problematic_asts() { let bad_mblock = microblocks.pop().unwrap(); let (_, _, new_consensus_hash) = peer.next_burnchain_block(burn_ops.clone()); - peer.process_stacks_epoch(&bad_block, &new_consensus_hash, &vec![]); + peer.process_stacks_epoch(&bad_block, &new_consensus_hash, &[]); // stuff them all into each possible field of NetworkResult // p2p messages diff --git a/stackslib/src/util_lib/bloom.rs b/stackslib/src/util_lib/bloom.rs index d1632f0b14..0bf1a1c3d5 100644 --- a/stackslib/src/util_lib/bloom.rs +++ b/stackslib/src/util_lib/bloom.rs @@ -76,7 +76,7 @@ enum BitFieldEncoding { } /// Encode the inner count array, using a sparse representation if it would save space -fn encode_bitfield(fd: &mut W, bytes: &Vec) -> Result<(), codec_error> { +fn encode_bitfield(fd: &mut W, bytes: &[u8]) -> Result<(), codec_error> { let mut num_filled = 0; for bits in bytes.iter() { if *bits > 0 { @@ -99,7 +99,7 @@ fn encode_bitfield(fd: &mut W, bytes: &Vec) -> Result<(), codec_er // more efficient to encode as-is // (note that the array has a 4-byte length prefix) write_next(fd, &(BitFieldEncoding::Full as u8))?; - write_next(fd, bytes)?; + write_next(fd, &bytes.to_vec())?; } Ok(()) } diff --git a/stackslib/src/util_lib/db.rs b/stackslib/src/util_lib/db.rs index 53f597daa2..7efb023a01 100644 --- a/stackslib/src/util_lib/db.rs +++ b/stackslib/src/util_lib/db.rs @@ -902,8 +902,8 @@ impl<'a, C: Clone, T: MarfTrieId> IndexDBTx<'a, C, T> { &mut self, parent_header_hash: &T, header_hash: &T, - keys: &Vec, - values: &Vec, + keys: &[String], + values: &[String], ) -> Result { assert_eq!(keys.len(), values.len()); match self.block_linkage { diff --git a/stackslib/src/util_lib/strings.rs b/stackslib/src/util_lib/strings.rs index 0486e6bf81..431ace890f 100644 --- a/stackslib/src/util_lib/strings.rs +++ b/stackslib/src/util_lib/strings.rs @@ -367,10 +367,10 @@ mod test { #[test] fn test_contract_name_invalid() { - let s = vec![0u8]; + let s = [0u8]; assert!(ContractName::consensus_deserialize(&mut &s[..]).is_err()); - let s = vec![5u8, 0x66, 0x6f, 0x6f, 0x6f, 0x6f]; // "foooo" + let s = [5u8, 0x66, 0x6f, 0x6f, 0x6f, 0x6f]; // "foooo" assert!(ContractName::consensus_deserialize(&mut &s[..]).is_ok()); let s_body = [0x6fu8; CONTRACT_MAX_NAME_LENGTH + 1]; From 14a3dab030d7c8f6e2b4c1ecba13586a7b166592 Mon Sep 17 00:00:00 2001 From: Jacinta Ferrant Date: Thu, 2 Jan 2025 18:13:15 -0500 Subject: [PATCH 2/3] CRC: reduce needless vector creation Signed-off-by: Jacinta Ferrant --- stackslib/src/burnchains/tests/mod.rs | 6 +++--- stackslib/src/chainstate/stacks/tests/mod.rs | 6 +++--- stackslib/src/net/mod.rs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/stackslib/src/burnchains/tests/mod.rs b/stackslib/src/burnchains/tests/mod.rs index b1688d7b13..af33fe5cdd 100644 --- a/stackslib/src/burnchains/tests/mod.rs +++ b/stackslib/src/burnchains/tests/mod.rs @@ -135,14 +135,14 @@ pub struct TestMinerFactory { impl TestMiner { pub fn new( burnchain: &Burnchain, - privks: &[StacksPrivateKey], + privks: Vec, num_sigs: u16, hash_mode: &AddressHashMode, chain_id: u32, ) -> TestMiner { TestMiner { burnchain: burnchain.clone(), - privks: privks.to_vec(), + privks, num_sigs, hash_mode: hash_mode.clone(), microblock_privks: vec![], @@ -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 diff --git a/stackslib/src/chainstate/stacks/tests/mod.rs b/stackslib/src/chainstate/stacks/tests/mod.rs index 82d587954d..170fec1896 100644 --- a/stackslib/src/chainstate/stacks/tests/mod.rs +++ b/stackslib/src/chainstate/stacks/tests/mod.rs @@ -555,13 +555,13 @@ impl TestStacksNode { burn_block: &mut TestBurnchainBlock, miner: &mut TestMiner, stacks_block: &StacksBlock, - microblocks: &[StacksMicroblock], + microblocks: Vec, burn_amount: u64, miner_key: &LeaderKeyRegisterOp, parent_block_snapshot_opt: Option<&BlockSnapshot>, ) -> LeaderBlockCommitOp { self.anchored_blocks.push(stacks_block.clone()); - self.microblocks.push(microblocks.to_vec()); + self.microblocks.push(microblocks); test_debug!( "Miner {}: Commit to stacks block {} (work {},{})", @@ -704,7 +704,7 @@ impl TestStacksNode { burn_block, miner, &stacks_block, - µblocks, + microblocks.clone(), burn_amount, miner_key, parent_block_snapshot_opt.as_ref(), diff --git a/stackslib/src/net/mod.rs b/stackslib/src/net/mod.rs index 9f5a20d483..15a614bb9a 100644 --- a/stackslib/src/net/mod.rs +++ b/stackslib/src/net/mod.rs @@ -4323,7 +4323,7 @@ pub mod test { &mut burn_block, &mut self.miner, &stacks_block, - µblocks, + microblocks.clone(), 1000, &last_key, parent_sortition_opt.as_ref(), From a3feee79ef784228dcb8d9c20146f56aa3b8b1c4 Mon Sep 17 00:00:00 2001 From: Jacinta Ferrant Date: Fri, 3 Jan 2025 12:20:21 -0500 Subject: [PATCH 3/3] Remove useless vec from MessageSignature::from_raw Signed-off-by: Jacinta Ferrant --- stackslib/src/burnchains/tests/mod.rs | 5 +- stackslib/src/chainstate/stacks/auth.rs | 84 +++++++++---------- .../src/chainstate/stacks/index/test/mod.rs | 6 +- stackslib/src/chainstate/stacks/mod.rs | 30 +++---- stackslib/src/clarity_vm/clarity.rs | 2 +- stackslib/src/core/tests/mod.rs | 2 +- stackslib/src/net/codec.rs | 12 +-- 7 files changed, 67 insertions(+), 74 deletions(-) diff --git a/stackslib/src/burnchains/tests/mod.rs b/stackslib/src/burnchains/tests/mod.rs index 3d88763e2c..24fa52e4ff 100644 --- a/stackslib/src/burnchains/tests/mod.rs +++ b/stackslib/src/burnchains/tests/mod.rs @@ -910,10 +910,7 @@ fn verify_keys_accepted(node: &mut TestBurnchainNode, prev_keys: &[LeaderKeyRegi } } -fn verify_commits_accepted( - node: &TestBurnchainNode, - next_block_commits: &[LeaderBlockCommitOp], -) { +fn verify_commits_accepted(node: &TestBurnchainNode, next_block_commits: &[LeaderBlockCommitOp]) { // all commits accepted for commit in next_block_commits.iter() { let tx_opt = diff --git a/stackslib/src/chainstate/stacks/auth.rs b/stackslib/src/chainstate/stacks/auth.rs index 6d3d1f1241..5a060280f2 100644 --- a/stackslib/src/chainstate/stacks/auth.rs +++ b/stackslib/src/chainstate/stacks/auth.rs @@ -1436,7 +1436,7 @@ mod test { key_encoding: TransactionPublicKeyEncoding::Uncompressed, nonce: 123, tx_fee: 456, - signature: MessageSignature::from_raw(&vec![0xff; 65]), + signature: MessageSignature::from_raw(&[0xff; 65]), }; let spending_condition_p2pkh_uncompressed_bytes = vec![ @@ -1460,7 +1460,7 @@ mod test { key_encoding: TransactionPublicKeyEncoding::Compressed, nonce: 345, tx_fee: 456, - signature: MessageSignature::from_raw(&vec![0xfe; 65]), + signature: MessageSignature::from_raw(&[0xfe; 65]), }; let spending_condition_p2pkh_compressed_bytes = vec![ @@ -1504,8 +1504,8 @@ mod test { nonce: 123, tx_fee: 456, fields: vec![ - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&vec![0xff; 65])), - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&vec![0xfe; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&[0xff; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&[0xfe; 65])), TransactionAuthField::PublicKey(PubKey::from_hex("04ef2340518b5867b23598a9cf74611f8b98064f7d55cdb8c107c67b5efcbc5c771f112f919b00a6c6c5f51f7c63e1762fe9fac9b66ec75a053db7f51f4a52712b").unwrap()), ], signatures_required: 2 @@ -1546,11 +1546,11 @@ mod test { fields: vec![ TransactionAuthField::Signature( TransactionPublicKeyEncoding::Compressed, - MessageSignature::from_raw(&vec![0xff; 65]), + MessageSignature::from_raw(&[0xff; 65]), ), TransactionAuthField::Signature( TransactionPublicKeyEncoding::Compressed, - MessageSignature::from_raw(&vec![0xfe; 65]), + MessageSignature::from_raw(&[0xfe; 65]), ), TransactionAuthField::PublicKey( PubKey::from_hex( @@ -1615,8 +1615,8 @@ mod test { nonce: 123, tx_fee: 456, fields: vec![ - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&vec![0xff; 65])), - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&vec![0xfe; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&[0xff; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&[0xfe; 65])), TransactionAuthField::PublicKey(PubKey::from_hex("04ef2340518b5867b23598a9cf74611f8b98064f7d55cdb8c107c67b5efcbc5c771f112f919b00a6c6c5f51f7c63e1762fe9fac9b66ec75a053db7f51f4a52712b").unwrap()), ], signatures_required: 2 @@ -1657,11 +1657,11 @@ mod test { fields: vec![ TransactionAuthField::Signature( TransactionPublicKeyEncoding::Compressed, - MessageSignature::from_raw(&vec![0xff; 65]), + MessageSignature::from_raw(&[0xff; 65]), ), TransactionAuthField::Signature( TransactionPublicKeyEncoding::Compressed, - MessageSignature::from_raw(&vec![0xfe; 65]), + MessageSignature::from_raw(&[0xfe; 65]), ), TransactionAuthField::PublicKey( PubKey::from_hex( @@ -1725,7 +1725,7 @@ mod test { key_encoding: TransactionPublicKeyEncoding::Compressed, nonce: 345, tx_fee: 567, - signature: MessageSignature::from_raw(&vec![0xfe; 65]), + signature: MessageSignature::from_raw(&[0xfe; 65]), }; let spending_condition_p2wpkh_compressed_bytes = vec![ @@ -1759,11 +1759,11 @@ mod test { fields: vec![ TransactionAuthField::Signature( TransactionPublicKeyEncoding::Compressed, - MessageSignature::from_raw(&vec![0xff; 65]), + MessageSignature::from_raw(&[0xff; 65]), ), TransactionAuthField::Signature( TransactionPublicKeyEncoding::Compressed, - MessageSignature::from_raw(&vec![0xfe; 65]), + MessageSignature::from_raw(&[0xfe; 65]), ), TransactionAuthField::PublicKey( PubKey::from_hex( @@ -1818,7 +1818,7 @@ mod test { key_encoding: TransactionPublicKeyEncoding::Uncompressed, nonce: 123, tx_fee: 567, - signature: MessageSignature::from_raw(&vec![0xff; 65]) + signature: MessageSignature::from_raw(&[0xff; 65]) }), TransactionSpendingCondition::Singlesig(SinglesigSpendingCondition { signer: Hash160([0x11; 20]), @@ -1826,7 +1826,7 @@ mod test { key_encoding: TransactionPublicKeyEncoding::Compressed, nonce: 345, tx_fee: 567, - signature: MessageSignature::from_raw(&vec![0xff; 65]) + signature: MessageSignature::from_raw(&[0xff; 65]) }), TransactionSpendingCondition::Multisig(MultisigSpendingCondition { signer: Hash160([0x11; 20]), @@ -1834,8 +1834,8 @@ mod test { nonce: 123, tx_fee: 567, fields: vec![ - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&vec![0xff; 65])), - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&vec![0xfe; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&[0xff; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&[0xfe; 65])), TransactionAuthField::PublicKey(PubKey::from_hex("04ef2340518b5867b23598a9cf74611f8b98064f7d55cdb8c107c67b5efcbc5c771f112f919b00a6c6c5f51f7c63e1762fe9fac9b66ec75a053db7f51f4a52712b").unwrap()), ], signatures_required: 2 @@ -1846,8 +1846,8 @@ mod test { nonce: 456, tx_fee: 567, fields: vec![ - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&vec![0xff; 65])), - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&vec![0xfe; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&[0xff; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&[0xfe; 65])), TransactionAuthField::PublicKey(PubKey::from_hex("03ef2340518b5867b23598a9cf74611f8b98064f7d55cdb8c107c67b5efcbc5c77").unwrap()) ], signatures_required: 2 @@ -1858,8 +1858,8 @@ mod test { nonce: 123, tx_fee: 567, fields: vec![ - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&vec![0xff; 65])), - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&vec![0xfe; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&[0xff; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&[0xfe; 65])), TransactionAuthField::PublicKey(PubKey::from_hex("04ef2340518b5867b23598a9cf74611f8b98064f7d55cdb8c107c67b5efcbc5c771f112f919b00a6c6c5f51f7c63e1762fe9fac9b66ec75a053db7f51f4a52712b").unwrap()), ], signatures_required: 2 @@ -1870,8 +1870,8 @@ mod test { nonce: 456, tx_fee: 567, fields: vec![ - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&vec![0xff; 65])), - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&vec![0xfe; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&[0xff; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&[0xfe; 65])), TransactionAuthField::PublicKey(PubKey::from_hex("03ef2340518b5867b23598a9cf74611f8b98064f7d55cdb8c107c67b5efcbc5c77").unwrap()) ], signatures_required: 2 @@ -1882,9 +1882,9 @@ mod test { nonce: 123, tx_fee: 567, fields: vec![ - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&vec![0xff; 65])), - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&vec![0xfe; 65])), - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&vec![0xfd; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&[0xff; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&[0xfe; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&[0xfd; 65])), ], signatures_required: 1 }), @@ -1894,9 +1894,9 @@ mod test { nonce: 456, tx_fee: 567, fields: vec![ - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&vec![0xff; 65])), - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&vec![0xfe; 65])), - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&vec![0xfd; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&[0xff; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&[0xfe; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&[0xfd; 65])), ], signatures_required: 1 }), @@ -1906,7 +1906,7 @@ mod test { key_encoding: TransactionPublicKeyEncoding::Compressed, nonce: 345, tx_fee: 567, - signature: MessageSignature::from_raw(&vec![0xfe; 65]), + signature: MessageSignature::from_raw(&[0xfe; 65]), }), TransactionSpendingCondition::Multisig(MultisigSpendingCondition { signer: Hash160([0x11; 20]), @@ -1914,8 +1914,8 @@ mod test { nonce: 456, tx_fee: 567, fields: vec![ - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&vec![0xff; 65])), - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&vec![0xfe; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&[0xff; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&[0xfe; 65])), TransactionAuthField::PublicKey(PubKey::from_hex("03ef2340518b5867b23598a9cf74611f8b98064f7d55cdb8c107c67b5efcbc5c77").unwrap()) ], signatures_required: 2 @@ -1926,8 +1926,8 @@ mod test { nonce: 456, tx_fee: 567, fields: vec![ - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&vec![0xff; 65])), - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&vec![0xfe; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&[0xff; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&[0xfe; 65])), TransactionAuthField::PublicKey(PubKey::from_hex("03ef2340518b5867b23598a9cf74611f8b98064f7d55cdb8c107c67b5efcbc5c77").unwrap()) ], signatures_required: 2 @@ -1938,9 +1938,9 @@ mod test { nonce: 456, tx_fee: 567, fields: vec![ - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&vec![0xff; 65])), - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&vec![0xfe; 65])), - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&vec![0xfd; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&[0xff; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&[0xfe; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&[0xfd; 65])), ], signatures_required: 1 }) @@ -2136,7 +2136,7 @@ mod test { nonce: 123, tx_fee: 567, key_encoding: TransactionPublicKeyEncoding::Uncompressed, - signature: MessageSignature::from_raw(&vec![0xff; 65]), + signature: MessageSignature::from_raw(&[0xff; 65]), }); let bad_p2wpkh_uncompressed_bytes = vec![ @@ -2161,8 +2161,8 @@ mod test { nonce: 456, tx_fee: 567, fields: vec![ - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&vec![0xff; 65])), - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&vec![0xfe; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&[0xff; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&[0xfe; 65])), TransactionAuthField::PublicKey(PubKey::from_hex("04b7e10dd2c02dec648880ea346ece86a7820c4fa5114fb500b2645f6c972092dbe2334a653db0ab8d8ccffa6c35d3919e4cf8da3aeedafc7b9eb8235d0f2e7fdc").unwrap()), ], signatures_required: 2 @@ -2199,8 +2199,8 @@ mod test { nonce: 456, tx_fee: 567, fields: vec![ - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&vec![0xff; 65])), - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&vec![0xfe; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&[0xff; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&[0xfe; 65])), TransactionAuthField::PublicKey(PubKey::from_hex("04b7e10dd2c02dec648880ea346ece86a7820c4fa5114fb500b2645f6c972092dbe2334a653db0ab8d8ccffa6c35d3919e4cf8da3aeedafc7b9eb8235d0f2e7fdc").unwrap()), ], signatures_required: 2 diff --git a/stackslib/src/chainstate/stacks/index/test/mod.rs b/stackslib/src/chainstate/stacks/index/test/mod.rs index a4335d8fff..369be2722e 100644 --- a/stackslib/src/chainstate/stacks/index/test/mod.rs +++ b/stackslib/src/chainstate/stacks/index/test/mod.rs @@ -100,11 +100,7 @@ where test_debug!("----- END TRIE ------\n"); } -pub fn merkle_test( - s: &mut TrieStorageConnection, - path: &[u8], - value: &[u8], -) { +pub fn merkle_test(s: &mut TrieStorageConnection, path: &[u8], value: &[u8]) { let (_, root_hash) = Trie::read_root(s).unwrap(); let triepath = TrieHash::from_bytes(&path[..]).unwrap(); diff --git a/stackslib/src/chainstate/stacks/mod.rs b/stackslib/src/chainstate/stacks/mod.rs index dcb9348a21..23990fe199 100644 --- a/stackslib/src/chainstate/stacks/mod.rs +++ b/stackslib/src/chainstate/stacks/mod.rs @@ -1165,7 +1165,7 @@ pub mod test { key_encoding: TransactionPublicKeyEncoding::Uncompressed, nonce: 123, tx_fee: 456, - signature: MessageSignature::from_raw(&vec![0xff; 65]) + signature: MessageSignature::from_raw(&[0xff; 65]) }), TransactionSpendingCondition::Singlesig(SinglesigSpendingCondition { signer: Hash160([0x11; 20]), @@ -1173,7 +1173,7 @@ pub mod test { key_encoding: TransactionPublicKeyEncoding::Compressed, nonce: 234, tx_fee: 567, - signature: MessageSignature::from_raw(&vec![0xff; 65]) + signature: MessageSignature::from_raw(&[0xff; 65]) }), TransactionSpendingCondition::Multisig(MultisigSpendingCondition { signer: Hash160([0x11; 20]), @@ -1181,8 +1181,8 @@ pub mod test { nonce: 345, tx_fee: 678, fields: vec![ - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&vec![0xff; 65])), - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&vec![0xfe; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&[0xff; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&[0xfe; 65])), TransactionAuthField::PublicKey(PubKey::from_hex("04ef2340518b5867b23598a9cf74611f8b98064f7d55cdb8c107c67b5efcbc5c771f112f919b00a6c6c5f51f7c63e1762fe9fac9b66ec75a053db7f51f4a52712b").unwrap()), ], signatures_required: 2 @@ -1193,8 +1193,8 @@ pub mod test { nonce: 456, tx_fee: 789, fields: vec![ - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&vec![0xff; 65])), - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&vec![0xfe; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&[0xff; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&[0xfe; 65])), TransactionAuthField::PublicKey(PubKey::from_hex("03ef2340518b5867b23598a9cf74611f8b98064f7d55cdb8c107c67b5efcbc5c77").unwrap()) ], signatures_required: 2 @@ -1205,7 +1205,7 @@ pub mod test { key_encoding: TransactionPublicKeyEncoding::Compressed, nonce: 567, tx_fee: 890, - signature: MessageSignature::from_raw(&vec![0xfe; 65]), + signature: MessageSignature::from_raw(&[0xfe; 65]), }), TransactionSpendingCondition::Multisig(MultisigSpendingCondition { signer: Hash160([0x11; 20]), @@ -1213,8 +1213,8 @@ pub mod test { nonce: 678, tx_fee: 901, fields: vec![ - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&vec![0xff; 65])), - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&vec![0xfe; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&[0xff; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&[0xfe; 65])), TransactionAuthField::PublicKey(PubKey::from_hex("03ef2340518b5867b23598a9cf74611f8b98064f7d55cdb8c107c67b5efcbc5c77").unwrap()) ], signatures_required: 2 @@ -1229,8 +1229,8 @@ pub mod test { nonce: 678, tx_fee: 901, fields: vec![ - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&vec![0xff; 65])), - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&vec![0xfe; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&[0xff; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&[0xfe; 65])), TransactionAuthField::PublicKey(PubKey::from_hex("03ef2340518b5867b23598a9cf74611f8b98064f7d55cdb8c107c67b5efcbc5c77").unwrap()) ], signatures_required: 2 @@ -1241,8 +1241,8 @@ pub mod test { nonce: 345, tx_fee: 678, fields: vec![ - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&vec![0xff; 65])), - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&vec![0xfe; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&[0xff; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Uncompressed, MessageSignature::from_raw(&[0xfe; 65])), TransactionAuthField::PublicKey(PubKey::from_hex("04ef2340518b5867b23598a9cf74611f8b98064f7d55cdb8c107c67b5efcbc5c771f112f919b00a6c6c5f51f7c63e1762fe9fac9b66ec75a053db7f51f4a52712b").unwrap()), ], signatures_required: 2 @@ -1253,8 +1253,8 @@ pub mod test { nonce: 456, tx_fee: 789, fields: vec![ - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&vec![0xff; 65])), - TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&vec![0xfe; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&[0xff; 65])), + TransactionAuthField::Signature(TransactionPublicKeyEncoding::Compressed, MessageSignature::from_raw(&[0xfe; 65])), TransactionAuthField::PublicKey(PubKey::from_hex("03ef2340518b5867b23598a9cf74611f8b98064f7d55cdb8c107c67b5efcbc5c77").unwrap()) ], signatures_required: 2 diff --git a/stackslib/src/clarity_vm/clarity.rs b/stackslib/src/clarity_vm/clarity.rs index 739f85d3e8..9db8cc8596 100644 --- a/stackslib/src/clarity_vm/clarity.rs +++ b/stackslib/src/clarity_vm/clarity.rs @@ -2568,7 +2568,7 @@ mod tests { key_encoding: TransactionPublicKeyEncoding::Compressed, nonce: 0, tx_fee: 1, - signature: MessageSignature::from_raw(&vec![0xfe; 65]), + signature: MessageSignature::from_raw(&[0xfe; 65]), }); let contract = "(define-public (foo) (ok 1))"; diff --git a/stackslib/src/core/tests/mod.rs b/stackslib/src/core/tests/mod.rs index 672413b1bb..55cf8ae884 100644 --- a/stackslib/src/core/tests/mod.rs +++ b/stackslib/src/core/tests/mod.rs @@ -1666,7 +1666,7 @@ fn mempool_db_test_rbf() { key_encoding: TransactionPublicKeyEncoding::Uncompressed, nonce: 123, tx_fee: 456, - signature: MessageSignature::from_raw(&vec![0xff; 65]), + signature: MessageSignature::from_raw(&[0xff; 65]), }); let stx_address = StacksAddress { version: 1, diff --git a/stackslib/src/net/codec.rs b/stackslib/src/net/codec.rs index ff37ceaf65..4639c774da 100644 --- a/stackslib/src/net/codec.rs +++ b/stackslib/src/net/codec.rs @@ -1792,7 +1792,7 @@ pub mod test { burn_stable_block_height: 0x00001111, burn_stable_block_hash: BurnchainHeaderHash([0x22; 32]), additional_data: 0x33333333, - signature: MessageSignature::from_raw(&vec![0x44; 65]), + signature: MessageSignature::from_raw(&[0x44; 65]), payload_len: 0x000007ff, }; let preamble_bytes: Vec = vec![ @@ -2344,7 +2344,7 @@ pub mod test { let data = StackerDBChunkData { slot_id: 2, slot_version: 3, - sig: MessageSignature::from_raw(&vec![0x44; 65]), + sig: MessageSignature::from_raw(&[0x44; 65]), data: vec![ 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, ], @@ -2371,7 +2371,7 @@ pub mod test { let data = StackerDBChunkData { slot_id: 2, slot_version: 3, - sig: MessageSignature::from_raw(&vec![0x44; 65]), + sig: MessageSignature::from_raw(&[0x44; 65]), data: vec![ 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, ], @@ -2636,7 +2636,7 @@ pub mod test { StacksMessageType::StackerDBChunk(StackerDBChunkData { slot_id: 2, slot_version: 3, - sig: MessageSignature::from_raw(&vec![0x44; 65]), + sig: MessageSignature::from_raw(&[0x44; 65]), data: vec![0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff] }), StacksMessageType::StackerDBPushChunk(StackerDBPushChunkData { @@ -2645,7 +2645,7 @@ pub mod test { chunk_data: StackerDBChunkData { slot_id: 2, slot_version: 3, - sig: MessageSignature::from_raw(&vec![0x44; 65]), + sig: MessageSignature::from_raw(&[0x44; 65]), data: vec![0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff] } }), @@ -2734,7 +2734,7 @@ pub mod test { burn_stable_block_height: 0x00001111, burn_stable_block_hash: BurnchainHeaderHash([0x22; 32]), additional_data: 0x33333333, - signature: MessageSignature::from_raw(&vec![0x44; 65]), + signature: MessageSignature::from_raw(&[0x44; 65]), payload_len: (relayers_bytes.len() + payload_bytes.len()) as u32, };