From 4f9d620e80f638862ed21ad22b4948acea99bf97 Mon Sep 17 00:00:00 2001 From: Jacinta Ferrant Date: Tue, 31 Dec 2024 13:06:17 -0500 Subject: [PATCH 1/2] Remove unnecessary casts throughout stackslib Signed-off-by: Jacinta Ferrant --- stackslib/src/burnchains/bitcoin/blocks.rs | 30 +++---- stackslib/src/burnchains/tests/affirmation.rs | 11 +-- stackslib/src/burnchains/tests/burnchain.rs | 14 +--- stackslib/src/burnchains/tests/db.rs | 26 +++--- stackslib/src/chainstate/burn/db/sortdb.rs | 22 ++--- stackslib/src/chainstate/burn/mod.rs | 20 ++--- .../burn/operations/delegate_stx.rs | 10 +-- .../burn/operations/leader_block_commit.rs | 4 +- .../chainstate/burn/operations/stack_stx.rs | 2 +- .../burn/operations/vote_for_aggregate_key.rs | 2 +- stackslib/src/chainstate/burn/sortition.rs | 16 ++-- stackslib/src/chainstate/coordinator/tests.rs | 2 +- .../chainstate/nakamoto/coordinator/tests.rs | 22 ++--- .../chainstate/stacks/boot/contract_tests.rs | 22 ++--- .../src/chainstate/stacks/boot/pox_2_tests.rs | 22 +++-- .../src/chainstate/stacks/boot/pox_3_tests.rs | 8 +- .../src/chainstate/stacks/boot/pox_4_tests.rs | 2 +- .../src/chainstate/stacks/db/accounts.rs | 4 +- stackslib/src/chainstate/stacks/db/blocks.rs | 5 +- .../src/chainstate/stacks/index/test/marf.rs | 80 +++++++++---------- .../src/chainstate/stacks/index/test/mod.rs | 48 +++++------ .../src/chainstate/stacks/index/test/node.rs | 2 +- .../src/chainstate/stacks/index/test/trie.rs | 36 ++++----- stackslib/src/chainstate/stacks/index/trie.rs | 11 +-- .../stacks/tests/block_construction.rs | 12 +-- .../src/chainstate/stacks/transaction.rs | 6 +- stackslib/src/clarity_cli.rs | 4 +- stackslib/src/clarity_vm/clarity.rs | 64 +++++++-------- .../src/clarity_vm/tests/analysis_costs.rs | 16 ++-- stackslib/src/clarity_vm/tests/ast.rs | 6 +- stackslib/src/clarity_vm/tests/costs.rs | 28 +++---- stackslib/src/clarity_vm/tests/events.rs | 2 +- stackslib/src/clarity_vm/tests/forking.rs | 12 +-- .../src/clarity_vm/tests/large_contract.rs | 38 ++++----- .../src/clarity_vm/tests/simple_tests.rs | 4 +- stackslib/src/core/tests/mod.rs | 9 +-- stackslib/src/cost_estimates/fee_medians.rs | 2 +- stackslib/src/monitoring/mod.rs | 2 +- stackslib/src/net/api/getheaders.rs | 6 +- .../src/net/api/tests/postmempoolquery.rs | 2 +- stackslib/src/net/atlas/download.rs | 7 +- stackslib/src/net/chat.rs | 6 +- stackslib/src/net/connection.rs | 6 +- stackslib/src/net/db.rs | 16 ++-- stackslib/src/net/inv/epoch2x.rs | 4 +- stackslib/src/net/p2p.rs | 6 +- stackslib/src/net/relay.rs | 2 +- stackslib/src/net/stackerdb/sync.rs | 2 +- stackslib/src/net/stackerdb/tests/sync.rs | 6 +- stackslib/src/net/tests/inv/epoch2x.rs | 12 +-- stackslib/src/net/tests/inv/nakamoto.rs | 2 +- stackslib/src/net/tests/relay/epoch2x.rs | 4 +- .../src/util_lib/signed_structured_data.rs | 2 +- stackslib/src/util_lib/strings.rs | 2 +- 54 files changed, 337 insertions(+), 374 deletions(-) diff --git a/stackslib/src/burnchains/bitcoin/blocks.rs b/stackslib/src/burnchains/bitcoin/blocks.rs index 0cee9e60e6..6bd4b6bd02 100644 --- a/stackslib/src/burnchains/bitcoin/blocks.rs +++ b/stackslib/src/burnchains/bitcoin/blocks.rs @@ -656,7 +656,7 @@ mod tests { data_amt: 0, txid: to_txid(&hex_bytes("185c112401590b11acdfea6bb26d2a8e37cb31f24a0c89dbb8cc14b3d6271fb1").unwrap()), vtxindex: vtxindex, - opcode: '+' as u8, + opcode: b'+', data: hex_bytes("fae543ff5672fb607fe15e16b1c3ef38737c631c7c5d911c6617993c21fba731363f1cfe").unwrap(), inputs: vec![ BitcoinTxInputStructured { @@ -703,7 +703,7 @@ mod tests { data_amt: 0, txid: to_txid(&hex_bytes("eb2e84a45cf411e528185a98cd5fb45ed349843a83d39fd4dff2de47adad8c8f").unwrap()), vtxindex: vtxindex, - opcode: '~' as u8, + opcode: b'~', data: hex_bytes("7061747269636b7374616e6c6579322e6964").unwrap(), inputs: vec![ BitcoinTxInputStructured { @@ -746,7 +746,7 @@ mod tests { data_amt: 0, txid: to_txid(&hex_bytes("b908952b30ccfdfa59985dc1ffdd2a22ef054d20fa253510d2af7797dddee459").unwrap()), vtxindex: vtxindex, - opcode: ':' as u8, + opcode: b':', data: hex_bytes("666f6f2e74657374").unwrap(), inputs: vec![ BitcoinTxInputStructured { @@ -777,7 +777,7 @@ mod tests { data_amt: 0, txid: to_txid(&hex_bytes("16751ca54407b922e3072830cf4be58c5562a6dc350f6703192b673c4cc86182").unwrap()), vtxindex: vtxindex, - opcode: '?' as u8, + opcode: b'?', data: hex_bytes("9fab7f294936ddb6524a48feff691ecbd0ca9e8f107d845c417a5438d1cb441e827c5126").unwrap(), inputs: vec![ BitcoinTxInputStructured { @@ -827,7 +827,7 @@ mod tests { data_amt: 0, txid: to_txid(&hex_bytes("185c112401590b11acdfea6bb26d2a8e37cb31f24a0c89dbb8cc14b3d6271fb1").unwrap()), vtxindex: vtxindex, - opcode: '+' as u8, + opcode: b'+', data: hex_bytes("fae543ff5672fb607fe15e16b1c3ef38737c631c7c5d911c6617993c21fba731363f1cfe").unwrap(), inputs: vec![ BitcoinTxInputRaw { @@ -865,7 +865,7 @@ mod tests { data_amt: 0, txid: to_txid(&hex_bytes("eb2e84a45cf411e528185a98cd5fb45ed349843a83d39fd4dff2de47adad8c8f").unwrap()), vtxindex: vtxindex, - opcode: '~' as u8, + opcode: b'~', data: hex_bytes("7061747269636b7374616e6c6579322e6964").unwrap(), inputs: vec![ BitcoinTxInputRaw { @@ -898,7 +898,7 @@ mod tests { data_amt: 0, txid: to_txid(&hex_bytes("b908952b30ccfdfa59985dc1ffdd2a22ef054d20fa253510d2af7797dddee459").unwrap()), vtxindex: vtxindex, - opcode: ':' as u8, + opcode: b':', data: hex_bytes("666f6f2e74657374").unwrap(), inputs: vec![ BitcoinTxInputRaw { @@ -929,7 +929,7 @@ mod tests { data_amt: 0, txid: to_txid(&hex_bytes("16751ca54407b922e3072830cf4be58c5562a6dc350f6703192b673c4cc86182").unwrap()), vtxindex: vtxindex, - opcode: '?' as u8, + opcode: b'?', data: hex_bytes("9fab7f294936ddb6524a48feff691ecbd0ca9e8f107d845c417a5438d1cb441e827c5126").unwrap(), inputs: vec![ BitcoinTxInputRaw { @@ -962,7 +962,7 @@ mod tests { data_amt: 0, txid: to_txid(&hex_bytes("8b8a12909d48fd86c06e92270133d320498fb36caa0fdcb3292a8bba99669ebd").unwrap()), vtxindex: vtxindex, - opcode: '&' as u8, + opcode: b'&', data: hex_bytes("0000cd73fa046543210000000000aa000174657374").unwrap(), inputs: vec![ BitcoinTxInputRaw { @@ -1039,7 +1039,7 @@ mod tests { // NAME_REGISTRATION with segwit p2wpkh-p2sh input txid: to_txid(&hex_bytes("b908952b30ccfdfa59985dc1ffdd2a22ef054d20fa253510d2af7797dddee459").unwrap()), vtxindex: 1, - opcode: ':' as u8, + opcode: b':', data: hex_bytes("666f6f2e74657374").unwrap(), inputs: vec![ BitcoinTxInputStructured { @@ -1082,7 +1082,7 @@ mod tests { // TOKEN_TRANSFER txid: to_txid(&hex_bytes("13f2c54dbbe3d4d6ed6c9fd1a68fe3c4238ec5de50316d102a106553b57b8728").unwrap()), vtxindex: 2, - opcode: '$' as u8, + opcode: b'$', data: hex_bytes("7c503a2e30a905cb515cfbc291766dfa00000000000000000000000000535441434b530000000000000064").unwrap(), inputs: vec![ BitcoinTxInputStructured { @@ -1110,7 +1110,7 @@ mod tests { // TOKEN_TRANSFER txid: to_txid(&hex_bytes("7c7c60ae8617daeb351da01d0f683633e6778eb39b69e6e652b24ca0ce230291").unwrap()), vtxindex: 4, - opcode: '$' as u8, + opcode: b'$', data: hex_bytes("7c503a2e30a905cb515cfbc291766dfa00000000000000000000000000535441434b530000000000000064").unwrap(), inputs: vec![ BitcoinTxInputStructured { @@ -1138,7 +1138,7 @@ mod tests { // TOKEN_TRANSFER txid: to_txid(&hex_bytes("ae1cf8b812cf28ea96c7343dc7ee9ff2d8dfb2f441ab11c886dfcd56a0a1a2b4").unwrap()), vtxindex: 7, - opcode: '$' as u8, + opcode: b'$', data: hex_bytes("7c503a2e30a905cb515cfbc291766dfa00000000000000000000000000535441434b530000000000000064").unwrap(), inputs: vec![ BitcoinTxInputStructured { @@ -1166,7 +1166,7 @@ mod tests { // TOKEN_TRANSFER txid: to_txid(&hex_bytes("12fed1db482a35dba87535a13089692cea35a71bfb159b21d0a04be41219b2bd").unwrap()), vtxindex: 10, - opcode: '$' as u8, + opcode: b'$', data: hex_bytes("7c503a2e30a905cb515cfbc291766dfa00000000000000000000000000535441434b530000000000000064").unwrap(), inputs: vec![ BitcoinTxInputStructured { @@ -1194,7 +1194,7 @@ mod tests { // TOKEN_TRANSFER txid: to_txid(&hex_bytes("78035609a8733f214555cfec29e3eee1d24014863dc9f9d98092f6fbc5df63e8").unwrap()), vtxindex: 13, - opcode: '$' as u8, + opcode: b'$', data: hex_bytes("7c503a2e30a905cb515cfbc291766dfa00000000000000000000000000535441434b530000000000000064").unwrap(), inputs: vec![ BitcoinTxInputStructured { diff --git a/stackslib/src/burnchains/tests/affirmation.rs b/stackslib/src/burnchains/tests/affirmation.rs index 8876f3d1aa..ad1b8ed21c 100644 --- a/stackslib/src/burnchains/tests/affirmation.rs +++ b/stackslib/src/burnchains/tests/affirmation.rs @@ -389,16 +389,11 @@ pub fn make_reward_cycle_with_vote( ); if let Some(ref parent_commit) = parent_commits[i].as_ref() { + assert!(parent_commit.block_height != block_commit.block_height); assert!( - parent_commit.block_height as u64 != block_commit.block_height as u64 - ); - assert!( - parent_commit.block_height as u64 - == block_commit.parent_block_ptr as u64 - ); - assert!( - parent_commit.vtxindex as u64 == block_commit.parent_vtxindex as u64 + parent_commit.block_height == u64::from(block_commit.parent_block_ptr) ); + assert!(parent_commit.vtxindex == u32::from(block_commit.parent_vtxindex)); } parent_commits[i] = Some(block_commit.clone()); diff --git a/stackslib/src/burnchains/tests/burnchain.rs b/stackslib/src/burnchains/tests/burnchain.rs index 8d72d4efa9..f390dd0c30 100644 --- a/stackslib/src/burnchains/tests/burnchain.rs +++ b/stackslib/src/burnchains/tests/burnchain.rs @@ -464,11 +464,8 @@ fn test_process_block_ops() { 123, )); - let initial_snapshot = BlockSnapshot::initial( - first_block_height, - &first_burn_hash, - first_block_height as u64, - ); + let initial_snapshot = + BlockSnapshot::initial(first_block_height, &first_burn_hash, first_block_height); // process up to 124 { @@ -733,11 +730,8 @@ fn test_burn_snapshot_sequence() { // insert all operations let mut db = SortitionDB::connect_test(first_block_height, &first_burn_hash).unwrap(); - let mut prev_snapshot = BlockSnapshot::initial( - first_block_height, - &first_burn_hash, - first_block_height as u64, - ); + let mut prev_snapshot = + BlockSnapshot::initial(first_block_height, &first_burn_hash, first_block_height); let mut all_stacks_block_hashes = vec![]; for i in 0..32 { diff --git a/stackslib/src/burnchains/tests/db.rs b/stackslib/src/burnchains/tests/db.rs index f14243d049..2d506238b0 100644 --- a/stackslib/src/burnchains/tests/db.rs +++ b/stackslib/src/burnchains/tests/db.rs @@ -602,14 +602,14 @@ fn test_get_commit_at() { for i in 0..5 { let hdr = BurnchainHeaderHash([(i + 1) as u8; 32]); let block_header = BurnchainBlockHeader { - block_height: (first_height + i) as u64, + block_height: first_height + i, block_hash: hdr, parent_block_hash: parent_block_header .as_ref() .map(|blk| blk.block_hash.clone()) .unwrap_or(first_block_header.block_hash.clone()), num_txs: 1, - timestamp: i as u64, + timestamp: i, }; headers.push(block_header.clone()); @@ -656,13 +656,13 @@ fn test_get_commit_at() { assert_eq!(cmt, cmts[4]); // fork off the last stored commit block - let fork_hdr = BurnchainHeaderHash([90 as u8; 32]); + let fork_hdr = BurnchainHeaderHash([90; 32]); let fork_block_header = BurnchainBlockHeader { block_height: 5, block_hash: fork_hdr, - parent_block_hash: BurnchainHeaderHash([4 as u8; 32]), + parent_block_hash: BurnchainHeaderHash([4; 32]), num_txs: 1, - timestamp: 4 as u64, + timestamp: 4, }; let mut fork_cmt = cmts[4].clone(); @@ -716,14 +716,14 @@ fn test_get_set_check_anchor_block() { for i in 0..5 { let hdr = BurnchainHeaderHash([(i + 1) as u8; 32]); let block_header = BurnchainBlockHeader { - block_height: (first_height + i) as u64, + block_height: first_height + i, block_hash: hdr, parent_block_hash: parent_block_header .as_ref() .map(|blk| blk.block_hash.clone()) .unwrap_or(first_block_header.block_hash.clone()), num_txs: 1, - timestamp: i as u64, + timestamp: i, }; headers.push(block_header.clone()); @@ -802,14 +802,14 @@ fn test_update_block_descendancy() { for i in 0..5 { let hdr = BurnchainHeaderHash([(i + 1) as u8; 32]); let block_header = BurnchainBlockHeader { - block_height: (first_height + i) as u64, + block_height: first_height + i, block_hash: hdr, parent_block_hash: parent_block_header .as_ref() .map(|blk| blk.block_hash.clone()) .unwrap_or(first_block_header.block_hash.clone()), num_txs: 3, - timestamp: i as u64, + timestamp: i, }; headers.push(block_header.clone()); @@ -926,14 +926,14 @@ fn test_update_block_descendancy_with_fork() { for i in 0..5 { let hdr = BurnchainHeaderHash([(i + 1) as u8; 32]); let block_header = BurnchainBlockHeader { - block_height: (first_height + i) as u64, + block_height: first_height + i, block_hash: hdr, parent_block_hash: parent_block_header .as_ref() .map(|blk| blk.block_hash.clone()) .unwrap_or(first_block_header.block_hash.clone()), num_txs: 3, - timestamp: i as u64, + timestamp: i, }; headers.push(block_header.clone()); @@ -943,14 +943,14 @@ fn test_update_block_descendancy_with_fork() { for i in 0..5 { let hdr = BurnchainHeaderHash([(i + 128 + 1) as u8; 32]); let block_header = BurnchainBlockHeader { - block_height: (first_height + i) as u64, + block_height: first_height + i, block_hash: hdr, parent_block_hash: parent_block_header .as_ref() .map(|blk| blk.block_hash.clone()) .unwrap_or(first_block_header.block_hash.clone()), num_txs: 3, - timestamp: i as u64, + timestamp: i, }; fork_headers.push(block_header.clone()); diff --git a/stackslib/src/chainstate/burn/db/sortdb.rs b/stackslib/src/chainstate/burn/db/sortdb.rs index e399121e07..16487106c7 100644 --- a/stackslib/src/chainstate/burn/db/sortdb.rs +++ b/stackslib/src/chainstate/burn/db/sortdb.rs @@ -88,7 +88,7 @@ use crate::util_lib::db::{ u64_to_sql, DBConn, DBTx, Error as db_error, FromColumn, FromRow, IndexDBConn, IndexDBTx, }; -const BLOCK_HEIGHT_MAX: u64 = ((1 as u64) << 63) - 1; +const BLOCK_HEIGHT_MAX: u64 = (1 << 63) - 1; pub const REWARD_WINDOW_START: u64 = 144 * 15; pub const REWARD_WINDOW_END: u64 = 144 * 90 + REWARD_WINDOW_START; @@ -7422,7 +7422,7 @@ pub mod tests { for i in 0..255 { let sortition_id = SortitionId([ 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, i as u8, + 0, 0, 0, 0, 0, i, ]); let parent_sortition_id = if i == 0 { last_snapshot.sortition_id.clone() @@ -7459,7 +7459,7 @@ pub mod tests { 0, 0, 0, - i - 1 as u8, + i - 1, ]) }; @@ -7471,7 +7471,7 @@ pub mod tests { burn_header_timestamp: get_epoch_time_secs(), burn_header_hash: BurnchainHeaderHash::from_bytes(&[ 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, i as u8, + 0, 0, 0, 0, 0, 0, i, ]) .unwrap(), sortition_id, @@ -7508,7 +7508,7 @@ pub mod tests { 0, 0, 0, - (if i == 0 { 0xff } else { i - 1 }) as u8, + (if i == 0 { 0xff } else { i - 1 }), ]) .unwrap(), consensus_hash: ConsensusHash::from_bytes(&[ @@ -7531,12 +7531,12 @@ pub mod tests { 0, 0, 0, - (i + 1) as u8, + i + 1, ]) .unwrap(), ops_hash: OpsHash::from_bytes(&[ 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, i as u8, + 0, 0, 0, 0, 0, 0, i, ]) .unwrap(), total_burn: i as u64, @@ -7717,7 +7717,7 @@ pub mod tests { let snapshot_row = BlockSnapshot { accumulated_coinbase_ustx: 0, pox_valid: true, - block_height: i as u64 + 1, + block_height: i + 1, burn_header_timestamp: get_epoch_time_secs(), burn_header_hash: BurnchainHeaderHash::from_bytes(&[ 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, @@ -7789,7 +7789,7 @@ pub mod tests { 0, 0, 0, 0, 0, 0, i as u8, ]) .unwrap(), - total_burn: i as u64, + total_burn: i, sortition: true, sortition_hash: SortitionHash::initial(), winning_block_txid: Txid::from_hex( @@ -7801,7 +7801,7 @@ pub mod tests { ) .unwrap(), index_root: TrieHash::from_empty_data(), - num_sortitions: i as u64 + 1, + num_sortitions: i + 1, stacks_block_accepted: false, stacks_block_height: 0, arrival_index: 0, @@ -7824,7 +7824,7 @@ pub mod tests { last_snapshot = snapshot_row; last_snapshot.index_root = index_root; // should succeed within the tx - let ch = tx.get_consensus_at(i as u64 + 1).unwrap().unwrap(); + let ch = tx.get_consensus_at(i + 1).unwrap().unwrap(); assert_eq!(ch, last_snapshot.consensus_hash); tx.commit().unwrap(); diff --git a/stackslib/src/chainstate/burn/mod.rs b/stackslib/src/chainstate/burn/mod.rs index 4552210f44..5f8a803496 100644 --- a/stackslib/src/chainstate/burn/mod.rs +++ b/stackslib/src/chainstate/burn/mod.rs @@ -62,13 +62,13 @@ impl_byte_array_newtype!(SortitionHash, u8, 32); #[derive(Debug, Clone, PartialEq)] #[repr(u8)] pub enum Opcodes { - LeaderBlockCommit = '[' as u8, - LeaderKeyRegister = '^' as u8, - StackStx = 'x' as u8, - PreStx = 'p' as u8, - TransferStx = '$' as u8, - DelegateStx = '#' as u8, - VoteForAggregateKey = 'v' as u8, + LeaderBlockCommit = b'[', + LeaderKeyRegister = b'^', + StackStx = b'x', + PreStx = b'p', + TransferStx = b'$', + DelegateStx = b'#', + VoteForAggregateKey = b'v', } // a burnchain block snapshot @@ -350,8 +350,8 @@ impl ConsensusHashExtensions for ConsensusHash { ) -> Result, db_error> { let mut i = 0; let mut prev_chs = vec![]; - while i < 64 && block_height - (((1 as u64) << i) - 1) >= first_block_height { - let prev_block: u64 = block_height - (((1 as u64) << i) - 1); + while i < 64 && block_height - ((1 << i) - 1) >= first_block_height { + let prev_block: u64 = block_height - ((1 << i) - 1); let prev_ch = sort_tx .get_consensus_at(prev_block) .unwrap_or_else(|_| { @@ -366,7 +366,7 @@ impl ConsensusHashExtensions for ConsensusHash { prev_chs.push(prev_ch.clone()); i += 1; - if block_height < (((1 as u64) << i) - 1) { + if block_height < ((1 << i) - 1) { break; } } diff --git a/stackslib/src/chainstate/burn/operations/delegate_stx.rs b/stackslib/src/chainstate/burn/operations/delegate_stx.rs index 130a42784b..c4729d1d9b 100644 --- a/stackslib/src/chainstate/burn/operations/delegate_stx.rs +++ b/stackslib/src/chainstate/burn/operations/delegate_stx.rs @@ -230,24 +230,24 @@ impl StacksMessageCodec for DelegateStxOp { .map_err(|e| codec_error::WriteError(e))?; if let Some((index, _)) = self.reward_addr { - fd.write_all(&(1 as u8).to_be_bytes()) + fd.write_all(&1_u8.to_be_bytes()) .map_err(|e| codec_error::WriteError(e))?; fd.write_all(&index.to_be_bytes()) .map_err(|e| codec_error::WriteError(e))?; } else { - fd.write_all(&(0 as u8).to_be_bytes()) + fd.write_all(&0_u8.to_be_bytes()) .map_err(|e| codec_error::WriteError(e))?; - fd.write_all(&(0 as u32).to_be_bytes()) + fd.write_all(&0_u8.to_be_bytes()) .map_err(|e| codec_error::WriteError(e))?; } if let Some(height) = self.until_burn_height { - fd.write_all(&(1 as u8).to_be_bytes()) + fd.write_all(&1_u8.to_be_bytes()) .map_err(|e| codec_error::WriteError(e))?; fd.write_all(&height.to_be_bytes()) .map_err(|e| codec_error::WriteError(e))?; } else { - fd.write_all(&(0 as u8).to_be_bytes()) + fd.write_all(&0_u8.to_be_bytes()) .map_err(|e| codec_error::WriteError(e))?; } Ok(()) diff --git a/stackslib/src/chainstate/burn/operations/leader_block_commit.rs b/stackslib/src/chainstate/burn/operations/leader_block_commit.rs index a752131668..3b24b3b098 100644 --- a/stackslib/src/chainstate/burn/operations/leader_block_commit.rs +++ b/stackslib/src/chainstate/burn/operations/leader_block_commit.rs @@ -2070,7 +2070,7 @@ mod tests { block_height: (i + 1 + first_block_height as usize) as u64, burn_header_timestamp: get_epoch_time_secs(), burn_header_hash: block_header_hashes[i].clone(), - sortition_id: SortitionId(block_header_hashes[i as usize].0.clone()), + sortition_id: SortitionId(block_header_hashes[i].0.clone()), parent_sortition_id: prev_snapshot.sortition_id.clone(), parent_burn_header_hash: prev_snapshot.burn_header_hash.clone(), consensus_hash: ConsensusHash::from_bytes(&[ @@ -2605,7 +2605,7 @@ mod tests { block_height: (i + 1 + first_block_height as usize) as u64, burn_header_timestamp: get_epoch_time_secs(), burn_header_hash: block_header_hashes[i].clone(), - sortition_id: SortitionId(block_header_hashes[i as usize].0.clone()), + sortition_id: SortitionId(block_header_hashes[i].0.clone()), parent_sortition_id: prev_snapshot.sortition_id.clone(), parent_burn_header_hash: prev_snapshot.burn_header_hash.clone(), consensus_hash: ConsensusHash::from_bytes(&[ diff --git a/stackslib/src/chainstate/burn/operations/stack_stx.rs b/stackslib/src/chainstate/burn/operations/stack_stx.rs index c4c54b9737..a1039eb5fb 100644 --- a/stackslib/src/chainstate/burn/operations/stack_stx.rs +++ b/stackslib/src/chainstate/burn/operations/stack_stx.rs @@ -869,7 +869,7 @@ mod tests { auth_id: Some(0u32), }; let op_bytes = { - let mut bytes = ['T' as u8, '3' as u8].to_vec(); + let mut bytes = [b'T', b'3'].to_vec(); op.consensus_serialize(&mut bytes) .expect("Expected to be able to serialize op into bytes"); bytes 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..3e547366cf 100644 --- a/stackslib/src/chainstate/burn/operations/vote_for_aggregate_key.rs +++ b/stackslib/src/chainstate/burn/operations/vote_for_aggregate_key.rs @@ -340,7 +340,7 @@ mod tests { assert_eq!(vote_op.signer_index, signer_index); assert_eq!(&vote_op.aggregate_key, &aggregate_key); - assert_eq!(vote_op.round, round as u32); + assert_eq!(vote_op.round, round); assert_eq!(vote_op.reward_cycle, reward_cycle); } diff --git a/stackslib/src/chainstate/burn/sortition.rs b/stackslib/src/chainstate/burn/sortition.rs index ff71b0cf10..c2391c6f84 100644 --- a/stackslib/src/chainstate/burn/sortition.rs +++ b/stackslib/src/chainstate/burn/sortition.rs @@ -1099,18 +1099,18 @@ mod test { for i in 0..100 { let header = BurnchainBlockHeader { block_height: prev_block_header.block_height + 1, - block_hash: BurnchainHeaderHash([i as u8; 32]), + block_hash: BurnchainHeaderHash([i; 32]), parent_block_hash: prev_block_header.block_hash.clone(), num_txs: 0, - timestamp: prev_block_header.timestamp + (i as u64) + 1, + timestamp: prev_block_header.timestamp + u64::from(i) + 1, }; - let sortition_hash = SortitionHash([i as u8; 32]); + let sortition_hash = SortitionHash([i; 32]); let commit_winner = LeaderBlockCommitOp { sunset_burn: 0, - block_header_hash: BlockHeaderHash([i as u8; 32]), - new_seed: VRFSeed([i as u8; 32]), + block_header_hash: BlockHeaderHash([i; 32]), + new_seed: VRFSeed([i; 32]), parent_block_ptr: 0, parent_vtxindex: 0, key_block_ptr: 0, @@ -1120,11 +1120,11 @@ mod test { burn_fee: 100, input: (Txid([0; 32]), 0), - apparent_sender: BurnchainSigner(format!("signer {}", i)), - txid: Txid([i as u8; 32]), + apparent_sender: BurnchainSigner(format!("signer {i}")), + txid: Txid([i; 32]), vtxindex: 0, block_height: header.block_height, - burn_parent_modulus: (i % BURN_BLOCK_MINED_AT_MODULUS) as u8, + burn_parent_modulus: i % BURN_BLOCK_MINED_AT_MODULUS as u8, burn_header_hash: header.block_hash.clone(), treatment: vec![], }; diff --git a/stackslib/src/chainstate/coordinator/tests.rs b/stackslib/src/chainstate/coordinator/tests.rs index f203ea5e28..0863708122 100644 --- a/stackslib/src/chainstate/coordinator/tests.rs +++ b/stackslib/src/chainstate/coordinator/tests.rs @@ -991,7 +991,7 @@ fn make_stacks_block_with_input( parent_vtxindex, txid: next_txid(), - vtxindex: (1 + key_index) as u32, + vtxindex: 1 + key_index, block_height: 0, burn_parent_modulus: (BURN_BLOCK_MINED_AT_MODULUS - 1) as u8, burn_header_hash: BurnchainHeaderHash([0; 32]), diff --git a/stackslib/src/chainstate/nakamoto/coordinator/tests.rs b/stackslib/src/chainstate/nakamoto/coordinator/tests.rs index 0525717981..d3abee3e36 100644 --- a/stackslib/src/chainstate/nakamoto/coordinator/tests.rs +++ b/stackslib/src/chainstate/nakamoto/coordinator/tests.rs @@ -3243,7 +3243,7 @@ fn test_stacks_on_burnchain_ops() { until_burn_height: None, // mocked - txid: Txid([i as u8; 32]), + txid: Txid([i; 32]), vtxindex: 11, block_height: block_height + 1, burn_header_hash: BurnchainHeaderHash([0x00; 32]), @@ -3263,7 +3263,7 @@ fn test_stacks_on_burnchain_ops() { auth_id: Some(i as u32), // mocked - txid: Txid([(i as u8) | 0x80; 32]), + txid: Txid([i | 0x80; 32]), vtxindex: 12, block_height: block_height + 1, burn_header_hash: BurnchainHeaderHash([0x00; 32]), @@ -3275,7 +3275,7 @@ fn test_stacks_on_burnchain_ops() { memo: vec![0x2], // mocked - txid: Txid([(i as u8) | 0x40; 32]), + txid: Txid([i | 0x40; 32]), vtxindex: 13, block_height: block_height + 1, burn_header_hash: BurnchainHeaderHash([0x00; 32]), @@ -3294,7 +3294,7 @@ fn test_stacks_on_burnchain_ops() { )), // mocked - txid: Txid([(i as u8) | 0xc0; 32]), + txid: Txid([i | 0xc0; 32]), vtxindex: 14, block_height: block_height + 1, burn_header_hash: BurnchainHeaderHash([0x00; 32]), @@ -3307,7 +3307,7 @@ fn test_stacks_on_burnchain_ops() { let (_, _, consensus_hash) = peer.next_burnchain_block(burn_ops.clone()); let vrf_proof = peer.make_nakamoto_vrf_proof(miner_key); - bitpatterns.insert(consensus_hash.clone(), i as u8); + bitpatterns.insert(consensus_hash.clone(), i); tenure_change.tenure_consensus_hash = consensus_hash.clone(); tenure_change.burn_view_consensus_hash = consensus_hash.clone(); @@ -3337,11 +3337,11 @@ fn test_stacks_on_burnchain_ops() { .unwrap(); let mut expected_burnchain_txids = HashSet::new(); - for j in (i as u64).saturating_sub(6)..i { - expected_burnchain_txids.insert(Txid([j as u8; 32])); - expected_burnchain_txids.insert(Txid([(j as u8) | 0x80; 32])); - expected_burnchain_txids.insert(Txid([(j as u8) | 0x40; 32])); - expected_burnchain_txids.insert(Txid([(j as u8) | 0xc0; 32])); + for j in i.saturating_sub(6)..i { + expected_burnchain_txids.insert(Txid([j; 32])); + expected_burnchain_txids.insert(Txid([j | 0x80; 32])); + expected_burnchain_txids.insert(Txid([j | 0x40; 32])); + expected_burnchain_txids.insert(Txid([j | 0xc0; 32])); } assert_eq!(processed_burnchain_txids, expected_burnchain_txids); @@ -3441,7 +3441,7 @@ fn test_stacks_on_burnchain_ops() { sort_tip.consensus_hash ); assert!(last_block.header.consensus_hash == sort_tip.consensus_hash); - assert_eq!(highest_tenure.coinbase_height, 12 + i); + assert_eq!(highest_tenure.coinbase_height, 12 + u64::from(i)); assert_eq!(highest_tenure.cause, TenureChangeCause::Extended); assert_eq!( highest_tenure.num_blocks_confirmed, diff --git a/stackslib/src/chainstate/stacks/boot/contract_tests.rs b/stackslib/src/chainstate/stacks/boot/contract_tests.rs index 4d4e875ba3..58701a2861 100644 --- a/stackslib/src/chainstate/stacks/boot/contract_tests.rs +++ b/stackslib/src/chainstate/stacks/boot/contract_tests.rs @@ -354,7 +354,7 @@ fn cost_2_contract_is_arithmetic_only() { impl BurnStateDB for TestSimBurnStateDB { fn get_tip_burn_block_height(&self) -> Option { - Some(self.height as u32) + Some(self.height) } fn get_tip_sortition_id(&self) -> Option { @@ -587,7 +587,7 @@ impl HeadersDB for TestSimHeadersDB { let burn_block_height = self.get_burn_block_height_for_block(id_bhh)? as u64; Some( BITCOIN_REGTEST_FIRST_BLOCK_TIMESTAMP as u64 + burn_block_height - - BITCOIN_REGTEST_FIRST_BLOCK_HEIGHT as u64, + - BITCOIN_REGTEST_FIRST_BLOCK_HEIGHT, ) } } @@ -607,7 +607,7 @@ impl HeadersDB for TestSimHeadersDB { None } else { Some( - (BITCOIN_REGTEST_FIRST_BLOCK_HEIGHT as u32 + input_height as u32) + (BITCOIN_REGTEST_FIRST_BLOCK_HEIGHT + input_height) .try_into() .unwrap(), ) @@ -3047,7 +3047,7 @@ fn test_vote_too_many_confirms() { .0, Value::Response(ResponseData { committed: true, - data: Value::UInt(i as u128).into() + data: Value::UInt(i).into() }) ); } @@ -3061,10 +3061,7 @@ fn test_vote_too_many_confirms() { None, COST_VOTING_CONTRACT_TESTNET.clone(), "vote-proposal", - &symbols_from_values(vec![ - Value::UInt(i as u128), - Value::UInt(USTX_PER_HOLDER) - ]), + &symbols_from_values(vec![Value::UInt(i), Value::UInt(USTX_PER_HOLDER)]), ) .unwrap() .0, @@ -3079,7 +3076,7 @@ fn test_vote_too_many_confirms() { None, COST_VOTING_CONTRACT_TESTNET.clone(), "confirm-votes", - &symbols_from_values(vec![Value::UInt(i as u128)]) + &symbols_from_values(vec![Value::UInt(i)]) ) .unwrap() .0, @@ -3093,10 +3090,7 @@ fn test_vote_too_many_confirms() { None, COST_VOTING_CONTRACT_TESTNET.clone(), "withdraw-votes", - &symbols_from_values(vec![ - Value::UInt(i as u128), - Value::UInt(USTX_PER_HOLDER), - ]), + &symbols_from_values(vec![Value::UInt(i), Value::UInt(USTX_PER_HOLDER)]), ) .unwrap() .0; @@ -3122,7 +3116,7 @@ fn test_vote_too_many_confirms() { None, COST_VOTING_CONTRACT_TESTNET.clone(), "confirm-miners", - &symbols_from_values(vec![Value::UInt(i as u128)]) + &symbols_from_values(vec![Value::UInt(i)]) ) .unwrap() .0, diff --git a/stackslib/src/chainstate/stacks/boot/pox_2_tests.rs b/stackslib/src/chainstate/stacks/boot/pox_2_tests.rs index 64782c67d6..ee9ec4e919 100644 --- a/stackslib/src/chainstate/stacks/boot/pox_2_tests.rs +++ b/stackslib/src/chainstate/stacks/boot/pox_2_tests.rs @@ -3631,7 +3631,7 @@ fn test_pox_2_getters() { .expect_optional() .unwrap(); assert_eq!(bob_delegation_addr, charlie_address.to_account_principal()); - assert_eq!(bob_delegation_amt, LOCKUP_AMT as u128); + assert_eq!(bob_delegation_amt, LOCKUP_AMT); assert!(bob_pox_addr_opt.is_none()); let allowance = data @@ -3679,7 +3679,7 @@ fn test_pox_2_getters() { .unwrap() .expect_u128() .unwrap(); - assert_eq!(partial_stacked, LOCKUP_AMT as u128); + assert_eq!(partial_stacked, LOCKUP_AMT); let rejected = data .get("get-total-pox-rejection-now") @@ -3695,7 +3695,7 @@ fn test_pox_2_getters() { .unwrap() .expect_u128() .unwrap(); - assert_eq!(rejected, LOCKUP_AMT as u128); + assert_eq!(rejected, LOCKUP_AMT); let rejected = data .get("get-total-pox-rejection-future") @@ -3848,10 +3848,9 @@ fn test_get_pox_addrs() { if tenure_id <= 1 { // record the first reward cycle when tokens get stacked - lockup_reward_cycle = 1 - + (burnchain - .block_height_to_reward_cycle(tip_burn_block_height) - .unwrap()) as u64; + lockup_reward_cycle = 1 + burnchain + .block_height_to_reward_cycle(tip_burn_block_height) + .unwrap(); eprintln!( "\nlockup reward cycle: {}\ncur reward cycle: {}\n", lockup_reward_cycle, cur_reward_cycle @@ -4145,10 +4144,9 @@ fn test_stack_with_segwit() { if tenure_id <= 1 { // record the first reward cycle when tokens get stacked - lockup_reward_cycle = 1 - + (burnchain - .block_height_to_reward_cycle(tip_burn_block_height) - .unwrap()) as u64; + lockup_reward_cycle = 1 + burnchain + .block_height_to_reward_cycle(tip_burn_block_height) + .unwrap(); eprintln!( "\nlockup reward cycle: {}\ncur reward cycle: {}\n", lockup_reward_cycle, cur_reward_cycle @@ -4460,7 +4458,7 @@ fn test_pox_2_delegate_stx_addr_validation() { alice_delegation_addr, charlie_address.to_account_principal() ); - assert_eq!(alice_delegation_amt, LOCKUP_AMT as u128); + assert_eq!(alice_delegation_amt, LOCKUP_AMT); assert!(alice_pox_addr_opt.is_some()); let alice_pox_addr = alice_pox_addr_opt.unwrap(); diff --git a/stackslib/src/chainstate/stacks/boot/pox_3_tests.rs b/stackslib/src/chainstate/stacks/boot/pox_3_tests.rs index 8a173c6adc..5c52297969 100644 --- a/stackslib/src/chainstate/stacks/boot/pox_3_tests.rs +++ b/stackslib/src/chainstate/stacks/boot/pox_3_tests.rs @@ -3278,7 +3278,7 @@ fn pox_3_getters() { .expect_optional() .unwrap(); assert_eq!(bob_delegation_addr, charlie_address.to_account_principal()); - assert_eq!(bob_delegation_amt, LOCKUP_AMT as u128); + assert_eq!(bob_delegation_amt, LOCKUP_AMT); assert!(bob_pox_addr_opt.is_none()); let allowance = data @@ -3326,7 +3326,7 @@ fn pox_3_getters() { .unwrap() .expect_u128() .unwrap(); - assert_eq!(partial_stacked, LOCKUP_AMT as u128); + assert_eq!(partial_stacked, LOCKUP_AMT); let rejected = data .get("get-total-pox-rejection-now") @@ -3334,7 +3334,7 @@ fn pox_3_getters() { .unwrap() .expect_u128() .unwrap(); - assert_eq!(rejected, LOCKUP_AMT as u128); + assert_eq!(rejected, LOCKUP_AMT); let rejected = data .get("get-total-pox-rejection-next") @@ -4430,7 +4430,7 @@ fn pox_3_delegate_stx_addr_validation() { alice_delegation_addr, charlie_address.to_account_principal() ); - assert_eq!(alice_delegation_amt, LOCKUP_AMT as u128); + assert_eq!(alice_delegation_amt, LOCKUP_AMT); assert!(alice_pox_addr_opt.is_some()); let alice_pox_addr = alice_pox_addr_opt.unwrap(); diff --git a/stackslib/src/chainstate/stacks/boot/pox_4_tests.rs b/stackslib/src/chainstate/stacks/boot/pox_4_tests.rs index 14dc9e75ab..481404be23 100644 --- a/stackslib/src/chainstate/stacks/boot/pox_4_tests.rs +++ b/stackslib/src/chainstate/stacks/boot/pox_4_tests.rs @@ -6378,7 +6378,7 @@ fn stack_increase(use_nakamoto: bool) { &pox_addr, lock_period, &signing_pk, - block_height as u64, + block_height, Some(signature), u128::MAX, 1, diff --git a/stackslib/src/chainstate/stacks/db/accounts.rs b/stackslib/src/chainstate/stacks/db/accounts.rs index bf84cc1362..25a10b94f4 100644 --- a/stackslib/src/chainstate/stacks/db/accounts.rs +++ b/stackslib/src/chainstate/stacks/db/accounts.rs @@ -868,9 +868,9 @@ impl StacksChainState { // of all participants' burns. let coinbase_reward = participant .coinbase - .checked_mul(this_burn_total as u128) + .checked_mul(this_burn_total) .expect("FATAL: STX coinbase reward overflow") - / (burn_total as u128); + / burn_total; // process poison -- someone can steal a fraction of the total coinbase if they can present // evidence that the miner forked the microblock stream. The remainder of the coinbase is diff --git a/stackslib/src/chainstate/stacks/db/blocks.rs b/stackslib/src/chainstate/stacks/db/blocks.rs index 233a9d5978..2b1f9e93a5 100644 --- a/stackslib/src/chainstate/stacks/db/blocks.rs +++ b/stackslib/src/chainstate/stacks/db/blocks.rs @@ -10246,10 +10246,7 @@ pub mod test { SortitionDB::get_canonical_burn_chain_tip(&peer.sortdb.as_ref().unwrap().conn()) .unwrap(); - assert_eq!( - tip.block_height, - first_stacks_block_height + (tenure_id as u64) - ); + assert_eq!(tip.block_height, first_stacks_block_height + tenure_id); let (burn_ops, stacks_block, microblocks) = peer.make_tenure( |ref mut miner, diff --git a/stackslib/src/chainstate/stacks/index/test/marf.rs b/stackslib/src/chainstate/stacks/index/test/marf.rs index e7535e9553..ffd7d7a6a4 100644 --- a/stackslib/src/chainstate/stacks/index/test/marf.rs +++ b/stackslib/src/chainstate/stacks/index/test/marf.rs @@ -107,16 +107,16 @@ fn marf_insert_different_leaf_different_path_different_block_100() { for i in 0..100 { debug!("insert {}", i); - let block_header = BlockHeaderHash::from_bytes(&[i + 1 as u8; 32]).unwrap(); + let block_header = BlockHeaderHash::from_bytes(&[i + 1; 32]).unwrap(); let path_bytes = [ 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, i as u8, + 23, 24, 25, 26, 27, 28, 29, 30, i, ]; marf.commit().unwrap(); 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(&vec![], &[i; 40].to_vec()); marf.insert_raw(path, value).unwrap(); } @@ -133,26 +133,26 @@ fn marf_insert_different_leaf_different_path_different_block_100() { debug!("---------"); for i in 0..100 { - let block_header = BlockHeaderHash::from_bytes(&[i + 1 as u8; 32]).unwrap(); + let block_header = BlockHeaderHash::from_bytes(&[i + 1; 32]).unwrap(); let path_bytes = [ 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, i as u8, + 23, 24, 25, 26, 27, 28, 29, 30, i, ]; let path = TrieHash::from_bytes(&path_bytes).unwrap(); - let value = TrieLeaf::new(&vec![], &[i as u8; 40].to_vec()); + let value = TrieLeaf::new(&vec![], &[i; 40].to_vec()); let leaf = MARF::get_path(&mut marf.borrow_storage_backend(), &block_header, &path) .unwrap() .unwrap(); - assert_eq!(leaf.data.to_vec(), [i as u8; 40].to_vec()); + assert_eq!(leaf.data.to_vec(), [i; 40].to_vec()); assert_eq!(marf.borrow_storage_backend().get_cur_block(), block_header); merkle_test_marf( &mut marf.borrow_storage_backend(), &block_header, &path_bytes.to_vec(), - &[i as u8; 40].to_vec(), + &[i; 40].to_vec(), None, ); } @@ -190,13 +190,13 @@ fn marf_insert_same_leaf_different_block_100() { let path = TrieHash::from_bytes(&path_bytes).unwrap(); 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 next_block_header = BlockHeaderHash::from_bytes(&[i + 1; 32]).unwrap(); + let value = TrieLeaf::new(&vec![], &[i; 40].to_vec()); 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(&vec![], &[i; 40].to_vec()); marf.insert_raw(path, value).unwrap(); } @@ -213,8 +213,8 @@ fn marf_insert_same_leaf_different_block_100() { debug!("---------"); 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 next_block_header = BlockHeaderHash::from_bytes(&[i + 1; 32]).unwrap(); + let value = TrieLeaf::new(&vec![], &[i; 40].to_vec()); let leaf = MARF::get_path( &mut marf.borrow_storage_backend(), &next_block_header, @@ -223,7 +223,7 @@ fn marf_insert_same_leaf_different_block_100() { .unwrap() .unwrap(); - assert_eq!(leaf.data.to_vec(), [i as u8; 40].to_vec()); + assert_eq!(leaf.data.to_vec(), [i; 40].to_vec()); assert_eq!( marf.borrow_storage_backend().get_cur_block(), next_block_header @@ -233,7 +233,7 @@ fn marf_insert_same_leaf_different_block_100() { &mut marf.borrow_storage_backend(), &next_block_header, &path_bytes.to_vec(), - &[i as u8; 40].to_vec(), + &[i; 40].to_vec(), None, ); } @@ -266,16 +266,16 @@ fn marf_insert_leaf_sequence_2() { for i in 0..2 { let path_bytes = [ - i as u8, 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, + i, 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 path = TrieHash::from_bytes(&path_bytes).unwrap(); - let prior_block_header = BlockHeaderHash::from_bytes(&[i as u8; 32]).unwrap(); - let next_block_header = BlockHeaderHash::from_bytes(&[i + 1 as u8; 32]).unwrap(); + let prior_block_header = BlockHeaderHash::from_bytes(&[i; 32]).unwrap(); + let next_block_header = BlockHeaderHash::from_bytes(&[i + 1; 32]).unwrap(); 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(&vec![], &[i; 40].to_vec()); marf.insert_raw(path, value).unwrap(); } @@ -287,14 +287,14 @@ fn marf_insert_leaf_sequence_2() { debug!("---------"); for i in 0..2 { - let next_block_header = BlockHeaderHash::from_bytes(&[i + 1 as u8; 32]).unwrap(); + let next_block_header = BlockHeaderHash::from_bytes(&[i + 1; 32]).unwrap(); let path_bytes = [ - i as u8, 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, + i, 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 path = TrieHash::from_bytes(&path_bytes).unwrap(); - let value = TrieLeaf::new(&vec![], &[i as u8; 40].to_vec()); + let value = TrieLeaf::new(&vec![], &[i; 40].to_vec()); let leaf = MARF::get_path( &mut marf.borrow_storage_backend(), &last_block_header, @@ -303,7 +303,7 @@ fn marf_insert_leaf_sequence_2() { .unwrap() .unwrap(); - assert_eq!(leaf.data.to_vec(), [i as u8; 40].to_vec()); + assert_eq!(leaf.data.to_vec(), [i; 40].to_vec()); assert_eq!( marf.borrow_storage_backend().get_cur_block(), next_block_header @@ -313,7 +313,7 @@ fn marf_insert_leaf_sequence_2() { &mut marf.borrow_storage_backend(), &last_block_header, &path_bytes.to_vec(), - &[i as u8; 40].to_vec(), + &[i; 40].to_vec(), None, ); } @@ -343,17 +343,17 @@ fn marf_insert_leaf_sequence_100() { for i in 1..101 { let path_bytes = [ - i as u8, 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, + i, 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 path = TrieHash::from_bytes(&path_bytes).unwrap(); marf.commit().unwrap(); - let next_block_header = BlockHeaderHash::from_bytes(&[i as u8; 32]).unwrap(); + let next_block_header = BlockHeaderHash::from_bytes(&[i; 32]).unwrap(); 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(&vec![], &[i; 40].to_vec()); marf.insert_raw(path, value).unwrap(); } marf.commit().unwrap(); @@ -365,26 +365,26 @@ fn marf_insert_leaf_sequence_100() { let mut f = marf.borrow_storage_backend(); for i in 1..101 { - let next_block_header = BlockHeaderHash::from_bytes(&[i as u8; 32]).unwrap(); + let next_block_header = BlockHeaderHash::from_bytes(&[i; 32]).unwrap(); let path_bytes = [ - i as u8, 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, + i, 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 path = TrieHash::from_bytes(&path_bytes).unwrap(); - let value = TrieLeaf::new(&vec![], &[i as u8; 40].to_vec()); + let value = TrieLeaf::new(&vec![], &[i; 40].to_vec()); eprintln!("Finding value inserted at {}", &next_block_header); let leaf = MARF::get_path(&mut f, &last_block_header, &path) .unwrap() .unwrap(); - assert_eq!(leaf.data.to_vec(), [i as u8; 40].to_vec()); + assert_eq!(leaf.data.to_vec(), [i; 40].to_vec()); merkle_test_marf( &mut f, &last_block_header, &path_bytes.to_vec(), - &[i as u8; 40].to_vec(), + &[i; 40].to_vec(), None, ); } @@ -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(&vec![], &[20; 40].to_vec()), ) .unwrap(); @@ -864,14 +864,14 @@ 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(&vec![], &[21; 40].to_vec()), ) .unwrap(); debug!("----------------"); debug!( "Merkle verify {:?} from {:?}", - &to_hex(&[21 as u8; 40]), + &to_hex(&[21; 40]), block_header_3 ); debug!("----------------"); @@ -882,7 +882,7 @@ fn marf_merkle_verify_backptrs() { &mut marf.borrow_storage_backend(), &block_header_3, &path_3, - &[21 as u8; 40].to_vec(), + &[21; 40].to_vec(), None, ); if let Some(root_hashes) = last_root_hashes.take() { diff --git a/stackslib/src/chainstate/stacks/index/test/mod.rs b/stackslib/src/chainstate/stacks/index/test/mod.rs index 0ccdffa78b..4e6589341b 100644 --- a/stackslib/src/chainstate/stacks/index/test/mod.rs +++ b/stackslib/src/chainstate/stacks/index/test/mod.rs @@ -248,16 +248,16 @@ pub fn make_node_path( // update parent match parent { TrieNodeType::Node256(ref mut data) => { - assert!(data.insert(&TriePtr::new(node_id, chr, node_ptr as u32))) + assert!(data.insert(&TriePtr::new(node_id, chr, node_ptr))) } TrieNodeType::Node48(ref mut data) => { - assert!(data.insert(&TriePtr::new(node_id, chr, node_ptr as u32))) + assert!(data.insert(&TriePtr::new(node_id, chr, node_ptr))) } TrieNodeType::Node16(ref mut data) => { - assert!(data.insert(&TriePtr::new(node_id, chr, node_ptr as u32))) + assert!(data.insert(&TriePtr::new(node_id, chr, node_ptr))) } TrieNodeType::Node4(ref mut data) => { - assert!(data.insert(&TriePtr::new(node_id, chr, node_ptr as u32))) + assert!(data.insert(&TriePtr::new(node_id, chr, node_ptr))) } TrieNodeType::Leaf(_) => panic!("can't insert into leaf"), }; @@ -270,7 +270,7 @@ pub fn make_node_path( .unwrap(); nodes.push(parent.clone()); - node_ptrs.push(TriePtr::new(node_id, chr, node_ptr as u32)); + node_ptrs.push(TriePtr::new(node_id, chr, node_ptr)); hashes.push(TrieHash::from_data(&[(seg_id + 1) as u8; 32])); parent = node; @@ -292,26 +292,18 @@ pub fn make_node_path( // update parent match parent { - TrieNodeType::Node256(ref mut data) => assert!(data.insert(&TriePtr::new( - TrieNodeID::Leaf as u8, - child_chr, - child_ptr as u32 - ))), - TrieNodeType::Node48(ref mut data) => assert!(data.insert(&TriePtr::new( - TrieNodeID::Leaf as u8, - child_chr, - child_ptr as u32 - ))), - TrieNodeType::Node16(ref mut data) => assert!(data.insert(&TriePtr::new( - TrieNodeID::Leaf as u8, - child_chr, - child_ptr as u32 - ))), - TrieNodeType::Node4(ref mut data) => assert!(data.insert(&TriePtr::new( - TrieNodeID::Leaf as u8, - child_chr, - child_ptr as u32 - ))), + TrieNodeType::Node256(ref mut data) => { + assert!(data.insert(&TriePtr::new(TrieNodeID::Leaf as u8, child_chr, child_ptr))) + } + TrieNodeType::Node48(ref mut data) => { + assert!(data.insert(&TriePtr::new(TrieNodeID::Leaf as u8, child_chr, child_ptr))) + } + TrieNodeType::Node16(ref mut data) => { + assert!(data.insert(&TriePtr::new(TrieNodeID::Leaf as u8, child_chr, child_ptr))) + } + TrieNodeType::Node4(ref mut data) => { + assert!(data.insert(&TriePtr::new(TrieNodeID::Leaf as u8, child_chr, child_ptr))) + } TrieNodeType::Leaf(_) => panic!("can't insert into leaf"), }; @@ -323,11 +315,7 @@ pub fn make_node_path( .unwrap(); nodes.push(parent.clone()); - node_ptrs.push(TriePtr::new( - TrieNodeID::Leaf as u8, - child_chr, - child_ptr as u32, - )); + node_ptrs.push(TriePtr::new(TrieNodeID::Leaf as u8, child_chr, child_ptr)); hashes.push(TrieHash::from_data(&[(seg_id + 1) as u8; 32])); (nodes, node_ptrs, hashes) diff --git a/stackslib/src/chainstate/stacks/index/test/node.rs b/stackslib/src/chainstate/stacks/index/test/node.rs index 227adda439..45e07014a3 100644 --- a/stackslib/src/chainstate/stacks/index/test/node.rs +++ b/stackslib/src/chainstate/stacks/index/test/node.rs @@ -3938,7 +3938,7 @@ fn read_write_node256() { assert!(wres.is_ok()); let root_ptr = trie_io.root_ptr(); - let rres = trie_io.read_nodetype(&TriePtr::new(TrieNodeID::Node256 as u8, 0, root_ptr as u32)); + let rres = trie_io.read_nodetype(&TriePtr::new(TrieNodeID::Node256 as u8, 0, root_ptr)); assert!(rres.is_ok()); assert_eq!(rres.unwrap(), (node256.as_trie_node_type(), hash)); diff --git a/stackslib/src/chainstate/stacks/index/test/trie.rs b/stackslib/src/chainstate/stacks/index/test/trie.rs index 9bac45508c..8625527a16 100644 --- a/stackslib/src/chainstate/stacks/index/test/trie.rs +++ b/stackslib/src/chainstate/stacks/index/test/trie.rs @@ -474,7 +474,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(&vec![], &[128 + j; 40].to_vec()), &mut node, ) .unwrap() @@ -490,12 +490,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..].to_vec(), &[128 + j; 40].to_vec()) ); // 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.to_vec(), &[j + 128; 40].to_vec()); } } } @@ -635,7 +635,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(&vec![], &[128 + j; 40].to_vec()), &mut node, ) .unwrap() @@ -652,12 +652,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..].to_vec(), &[128 + j; 40].to_vec()) ); // 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.to_vec(), &[j + 128; 40].to_vec()); } } } @@ -742,7 +742,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(&vec![], &[128 + j; 40].to_vec()), &mut node, ) .unwrap() @@ -759,12 +759,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..].to_vec(), &[128 + j; 40].to_vec()) ); // 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.to_vec(), &[j + 128; 40].to_vec()); } } } @@ -905,7 +905,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(&vec![], &[128 + j; 40].to_vec()), &mut node, ) .unwrap() @@ -922,12 +922,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..].to_vec(), &[128 + j; 40].to_vec()) ); // 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.to_vec(), &[j + 128; 40].to_vec()); } } } @@ -1012,7 +1012,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(&vec![], &[128 + j; 40].to_vec()), &mut node, ) .unwrap() @@ -1028,12 +1028,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..].to_vec(), &[128 + j; 40].to_vec()) ); // 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.to_vec(), &[j + 128; 40].to_vec()); } } } @@ -1118,7 +1118,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(&vec![], &[128 + j; 40].to_vec()), &mut node, ) .unwrap() @@ -1135,12 +1135,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..].to_vec(), &[128 + j; 40].to_vec()) ); // 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.to_vec(), &[j + 128; 40].to_vec()); } } } diff --git a/stackslib/src/chainstate/stacks/index/trie.rs b/stackslib/src/chainstate/stacks/index/trie.rs index 65e41cf3ed..0a890b8e24 100644 --- a/stackslib/src/chainstate/stacks/index/trie.rs +++ b/stackslib/src/chainstate/stacks/index/trie.rs @@ -361,11 +361,8 @@ impl Trie { // update current leaf (path changed) and save it let cur_leaf_disk_ptr = cur_leaf_ptr.ptr(); - let cur_leaf_new_ptr = TriePtr::new( - TrieNodeID::Leaf as u8, - cur_leaf_chr, - cur_leaf_disk_ptr as u32, - ); + let cur_leaf_new_ptr = + TriePtr::new(TrieNodeID::Leaf as u8, cur_leaf_chr, cur_leaf_disk_ptr); assert!(cur_leaf_path.len() <= cur_leaf_data.path.len()); let _sav_cur_leaf_data = cur_leaf_data.clone(); @@ -563,7 +560,7 @@ impl Trie { // append this leaf to the Trie let new_node_disk_ptr = storage.last_ptr()?; - let ret = TriePtr::new(new_node.id(), node_ptr.chr(), new_node_disk_ptr as u32); + let ret = TriePtr::new(new_node.id(), node_ptr.chr(), new_node_disk_ptr); storage.write_nodetype(new_node_disk_ptr, &new_node, new_node_hash)?; // update the cursor so its path of nodes and ptrs accurately reflects that we would have @@ -639,7 +636,7 @@ impl Trie { let new_cur_node_ptr = TriePtr::new( cur_node_cur_ptr.id(), new_cur_node_chr, - new_cur_node_disk_ptr as u32, + new_cur_node_disk_ptr, ); node.set_path(new_cur_node_path); diff --git a/stackslib/src/chainstate/stacks/tests/block_construction.rs b/stackslib/src/chainstate/stacks/tests/block_construction.rs index 90fc7f1705..eba22846ca 100644 --- a/stackslib/src/chainstate/stacks/tests/block_construction.rs +++ b/stackslib/src/chainstate/stacks/tests/block_construction.rs @@ -1256,7 +1256,7 @@ fn test_build_anchored_blocks_incrementing_nonces() { &parent_tip, tip.total_burn, vrf_proof, - Hash160([0 as u8; 20]), + Hash160([0; 20]), &coinbase_tx, BlockBuilderSettings::limited(), None, @@ -1637,7 +1637,7 @@ fn test_build_anchored_blocks_mempool_fee_transaction_too_low() { &parent_tip, tip.total_burn, vrf_proof, - Hash160([0 as u8; 20]), + Hash160([0; 20]), &coinbase_tx, BlockBuilderSettings::max_value(), None, @@ -1728,7 +1728,7 @@ fn test_build_anchored_blocks_zero_fee_transaction() { &parent_tip, vrf_proof, tip.total_burn, - Hash160([0 as u8; 20]), + Hash160([0; 20]), ) .unwrap(); @@ -3355,10 +3355,10 @@ fn test_build_microblock_stream_forks_with_descendants() { for burn_op in burn_ops.iter_mut() { if let BlockstackOperationType::LeaderBlockCommit(ref mut op) = burn_op { // patch it up - op.parent_block_ptr = (*parent_block_ptrs + op.parent_block_ptr = *parent_block_ptrs .borrow() .get(&stacks_block.header.parent_block) - .unwrap()) as u32; + .unwrap(); } } @@ -4841,7 +4841,7 @@ fn test_fee_order_mismatch_nonce_order() { &parent_tip, tip.total_burn, vrf_proof, - Hash160([0 as u8; 20]), + Hash160([0; 20]), &coinbase_tx, BlockBuilderSettings::max_value(), None, diff --git a/stackslib/src/chainstate/stacks/transaction.rs b/stackslib/src/chainstate/stacks/transaction.rs index c45b212b68..16baf9cbf4 100644 --- a/stackslib/src/chainstate/stacks/transaction.rs +++ b/stackslib/src/chainstate/stacks/transaction.rs @@ -3384,7 +3384,7 @@ mod test { .consensus_serialize(&mut contract_call_bytes) .unwrap(); - let mut transaction_contract_call = vec![0xff as u8]; + let mut transaction_contract_call = vec![0xff]; transaction_contract_call.append(&mut contract_call_bytes.clone()); assert!( @@ -3489,14 +3489,14 @@ mod test { let asset_name = ClarityName::try_from("hello-asset").unwrap(); let mut asset_name_bytes = vec![ // length - asset_name.len() as u8, + asset_name.len(), ]; asset_name_bytes.extend_from_slice(&asset_name.to_string().as_str().as_bytes()); let contract_name = ContractName::try_from("hello-world").unwrap(); let mut contract_name_bytes = vec![ // length - contract_name.len() as u8, + contract_name.len(), ]; contract_name_bytes.extend_from_slice(&contract_name.to_string().as_str().as_bytes()); diff --git a/stackslib/src/clarity_cli.rs b/stackslib/src/clarity_cli.rs index f23be191ff..f3a5ee3bfd 100644 --- a/stackslib/src/clarity_cli.rs +++ b/stackslib/src/clarity_cli.rs @@ -708,7 +708,7 @@ impl HeadersDB for CLIHeadersDB { ) -> Option { let conn = self.conn(); if let Some(height) = get_cli_block_height(&conn, id_bhh) { - Some((height * 600 + 1231006505) as u64) + Some(height * 600 + 1231006505) } else { None } @@ -717,7 +717,7 @@ impl HeadersDB for CLIHeadersDB { fn get_stacks_block_time_for_block(&self, id_bhh: &StacksBlockId) -> Option { let conn = self.conn(); if let Some(height) = get_cli_block_height(&conn, id_bhh) { - Some((height * 10 + 1713799973) as u64) + Some(height * 10 + 1713799973) } else { None } diff --git a/stackslib/src/clarity_vm/clarity.rs b/stackslib/src/clarity_vm/clarity.rs index a5497cea24..11c8c1233f 100644 --- a/stackslib/src/clarity_vm/clarity.rs +++ b/stackslib/src/clarity_vm/clarity.rs @@ -1906,7 +1906,7 @@ mod tests { clarity_instance .begin_test_genesis_block( &StacksBlockId::sentinel(), - &StacksBlockId([0 as u8; 32]), + &StacksBlockId([0; 32]), &TEST_HEADER_DB, &TEST_BURN_STATE_DB, ) @@ -1914,8 +1914,8 @@ mod tests { { let mut conn = clarity_instance.begin_block( - &StacksBlockId([0 as u8; 32]), - &StacksBlockId([1 as u8; 32]), + &StacksBlockId([0; 32]), + &StacksBlockId([1; 32]), &TEST_HEADER_DB, &TEST_BURN_STATE_DB, ); @@ -1959,7 +1959,7 @@ mod tests { clarity_instance .begin_test_genesis_block( &StacksBlockId::sentinel(), - &StacksBlockId([0 as u8; 32]), + &StacksBlockId([0; 32]), &TEST_HEADER_DB, &TEST_BURN_STATE_DB, ) @@ -1967,8 +1967,8 @@ mod tests { { let mut conn = clarity_instance.begin_block( - &StacksBlockId([0 as u8; 32]), - &StacksBlockId([1 as u8; 32]), + &StacksBlockId([0; 32]), + &StacksBlockId([1; 32]), &TEST_HEADER_DB, &TEST_BURN_STATE_DB, ); @@ -2020,7 +2020,7 @@ mod tests { clarity_instance .begin_test_genesis_block( &StacksBlockId::sentinel(), - &StacksBlockId([0 as u8; 32]), + &StacksBlockId([0; 32]), &TEST_HEADER_DB, &TEST_BURN_STATE_DB, ) @@ -2028,8 +2028,8 @@ mod tests { { let mut conn = clarity_instance.begin_block( - &StacksBlockId([0 as u8; 32]), - &StacksBlockId([1 as u8; 32]), + &StacksBlockId([0; 32]), + &StacksBlockId([1; 32]), &TEST_HEADER_DB, &TEST_BURN_STATE_DB, ); @@ -2132,7 +2132,7 @@ mod tests { clarity_instance .begin_test_genesis_block( &StacksBlockId::sentinel(), - &StacksBlockId([0 as u8; 32]), + &StacksBlockId([0; 32]), &TEST_HEADER_DB, &TEST_BURN_STATE_DB, ) @@ -2140,8 +2140,8 @@ mod tests { { let mut conn = clarity_instance.begin_block( - &StacksBlockId([0 as u8; 32]), - &StacksBlockId([1 as u8; 32]), + &StacksBlockId([0; 32]), + &StacksBlockId([1; 32]), &TEST_HEADER_DB, &TEST_BURN_STATE_DB, ); @@ -2188,7 +2188,7 @@ mod tests { } let mut marf = clarity_instance.destroy(); - let mut conn = marf.begin_read_only(Some(&StacksBlockId([1 as u8; 32]))); + let mut conn = marf.begin_read_only(Some(&StacksBlockId([1; 32]))); assert!(conn.get_contract_hash(&contract_identifier).is_ok()); } @@ -2201,7 +2201,7 @@ mod tests { { let mut conn = clarity_instance.begin_test_genesis_block( &StacksBlockId::sentinel(), - &StacksBlockId([0 as u8; 32]), + &StacksBlockId([0; 32]), &TEST_HEADER_DB, &TEST_BURN_STATE_DB, ); @@ -2235,7 +2235,7 @@ mod tests { let mut marf = clarity_instance.destroy(); - let mut conn = marf.begin(&StacksBlockId::sentinel(), &StacksBlockId([0 as u8; 32])); + let mut conn = marf.begin(&StacksBlockId::sentinel(), &StacksBlockId([0; 32])); // should not be in the marf. assert_eq!( conn.get_contract_hash(&contract_identifier).unwrap_err(), @@ -2273,7 +2273,7 @@ mod tests { confirmed_clarity_instance .begin_test_genesis_block( &StacksBlockId::sentinel(), - &StacksBlockId([0 as u8; 32]), + &StacksBlockId([0; 32]), &TEST_HEADER_DB, &TEST_BURN_STATE_DB, ) @@ -2295,7 +2295,7 @@ mod tests { // make an unconfirmed block off of the confirmed block { let mut conn = clarity_instance.begin_unconfirmed( - &StacksBlockId([0 as u8; 32]), + &StacksBlockId([0; 32]), &TEST_HEADER_DB, &TEST_BURN_STATE_DB, ); @@ -2328,7 +2328,7 @@ mod tests { // contract is still there, in unconfirmed status { let mut conn = clarity_instance.begin_unconfirmed( - &StacksBlockId([0 as u8; 32]), + &StacksBlockId([0; 32]), &TEST_HEADER_DB, &TEST_BURN_STATE_DB, ); @@ -2347,7 +2347,7 @@ mod tests { // rolled back (but that should only drop the current TrieRAM) { let mut conn = clarity_instance.begin_unconfirmed( - &StacksBlockId([0 as u8; 32]), + &StacksBlockId([0; 32]), &TEST_HEADER_DB, &TEST_BURN_STATE_DB, ); @@ -2365,7 +2365,7 @@ mod tests { // contract is now absent, now that we did a rollback of unconfirmed state { let mut conn = clarity_instance.begin_unconfirmed( - &StacksBlockId([0 as u8; 32]), + &StacksBlockId([0; 32]), &TEST_HEADER_DB, &TEST_BURN_STATE_DB, ); @@ -2380,7 +2380,7 @@ mod tests { } let mut marf = clarity_instance.destroy(); - let mut conn = marf.begin_unconfirmed(&StacksBlockId([0 as u8; 32])); + let mut conn = marf.begin_unconfirmed(&StacksBlockId([0; 32])); // should not be in the marf. assert_eq!( @@ -2411,7 +2411,7 @@ mod tests { clarity_instance .begin_test_genesis_block( &StacksBlockId::sentinel(), - &StacksBlockId([0 as u8; 32]), + &StacksBlockId([0; 32]), &TEST_HEADER_DB, &TEST_BURN_STATE_DB, ) @@ -2419,8 +2419,8 @@ mod tests { { let mut conn = clarity_instance.begin_block( - &StacksBlockId([0 as u8; 32]), - &StacksBlockId([1 as u8; 32]), + &StacksBlockId([0; 32]), + &StacksBlockId([1; 32]), &TEST_HEADER_DB, &TEST_BURN_STATE_DB, ); @@ -2631,7 +2631,7 @@ mod tests { clarity_instance .begin_test_genesis_block( &StacksBlockId::sentinel(), - &StacksBlockId([0 as u8; 32]), + &StacksBlockId([0; 32]), &TEST_HEADER_DB, &TEST_BURN_STATE_DB, ) @@ -2639,8 +2639,8 @@ mod tests { { let mut conn = clarity_instance.begin_block( - &StacksBlockId([0 as u8; 32]), - &StacksBlockId([1 as u8; 32]), + &StacksBlockId([0; 32]), + &StacksBlockId([1; 32]), &TEST_HEADER_DB, &TEST_BURN_STATE_DB, ); @@ -2792,7 +2792,7 @@ mod tests { clarity_instance .begin_test_genesis_block( &StacksBlockId::sentinel(), - &StacksBlockId([0 as u8; 32]), + &StacksBlockId([0; 32]), &TEST_HEADER_DB, &TEST_BURN_STATE_DB, ) @@ -2800,8 +2800,8 @@ mod tests { { let mut conn = clarity_instance.begin_block( - &StacksBlockId([0 as u8; 32]), - &StacksBlockId([1 as u8; 32]), + &StacksBlockId([0; 32]), + &StacksBlockId([1; 32]), &TEST_HEADER_DB, &TEST_BURN_STATE_DB, ); @@ -2842,8 +2842,8 @@ mod tests { { let mut conn = clarity_instance.begin_block( - &StacksBlockId([1 as u8; 32]), - &StacksBlockId([2 as u8; 32]), + &StacksBlockId([1; 32]), + &StacksBlockId([2; 32]), &TEST_HEADER_DB, &burn_state_db, ); diff --git a/stackslib/src/clarity_vm/tests/analysis_costs.rs b/stackslib/src/clarity_vm/tests/analysis_costs.rs index 4fe887f2c3..dc5b33fd31 100644 --- a/stackslib/src/clarity_vm/tests/analysis_costs.rs +++ b/stackslib/src/clarity_vm/tests/analysis_costs.rs @@ -81,7 +81,7 @@ fn setup_tracked_cost_test( clarity_instance .begin_test_genesis_block( &StacksBlockId::sentinel(), - &StacksBlockId([0 as u8; 32]), + &StacksBlockId([0; 32]), &TEST_HEADER_DB, &burn_state_db, ) @@ -89,8 +89,8 @@ fn setup_tracked_cost_test( { let mut conn = clarity_instance.begin_block( - &StacksBlockId([0 as u8; 32]), - &StacksBlockId([1 as u8; 32]), + &StacksBlockId([0; 32]), + &StacksBlockId([1; 32]), &TEST_HEADER_DB, &burn_state_db, ); @@ -107,8 +107,8 @@ fn setup_tracked_cost_test( { let mut conn = clarity_instance.begin_block( - &StacksBlockId([1 as u8; 32]), - &StacksBlockId([2 as u8; 32]), + &StacksBlockId([1; 32]), + &StacksBlockId([2; 32]), &TEST_HEADER_DB, &burn_state_db, ); @@ -145,8 +145,8 @@ fn setup_tracked_cost_test( { let mut conn = clarity_instance.begin_block( - &StacksBlockId([2 as u8; 32]), - &StacksBlockId([3 as u8; 32]), + &StacksBlockId([2; 32]), + &StacksBlockId([3; 32]), &TEST_HEADER_DB, &burn_state_db, ); @@ -221,7 +221,7 @@ fn test_tracked_costs( { let mut conn = clarity_instance.begin_block( - &StacksBlockId([3 as u8; 32]), + &StacksBlockId([3; 32]), &StacksBlockId([4 + prog_id as u8; 32]), &TEST_HEADER_DB, &burn_state_db, diff --git a/stackslib/src/clarity_vm/tests/ast.rs b/stackslib/src/clarity_vm/tests/ast.rs index 2074fa7636..edeaf9d553 100644 --- a/stackslib/src/clarity_vm/tests/ast.rs +++ b/stackslib/src/clarity_vm/tests/ast.rs @@ -35,7 +35,7 @@ fn dependency_edge_counting_runtime( clarity_instance .begin_test_genesis_block( &StacksBlockId::sentinel(), - &StacksBlockId([0 as u8; 32]), + &StacksBlockId([0; 32]), &TEST_HEADER_DB, &TEST_BURN_STATE_DB, ) @@ -43,8 +43,8 @@ fn dependency_edge_counting_runtime( let mut cost_track = clarity_instance .begin_block( - &StacksBlockId([0 as u8; 32]), - &StacksBlockId([1 as u8; 32]), + &StacksBlockId([0; 32]), + &StacksBlockId([1; 32]), &TEST_HEADER_DB, &TEST_BURN_STATE_DB, ) diff --git a/stackslib/src/clarity_vm/tests/costs.rs b/stackslib/src/clarity_vm/tests/costs.rs index 29c57b2e92..030b62af93 100644 --- a/stackslib/src/clarity_vm/tests/costs.rs +++ b/stackslib/src/clarity_vm/tests/costs.rs @@ -204,7 +204,7 @@ where let mut tip = first_block.clone(); if epoch >= StacksEpochId::Epoch2_05 { - let next_block = StacksBlockId([1 as u8; 32]); + let next_block = StacksBlockId([1; 32]); let mut clarity_conn = clarity_instance.begin_block(&tip, &next_block, &TEST_HEADER_DB, &TEST_BURN_STATE_DB); clarity_conn.initialize_epoch_2_05().unwrap(); @@ -213,7 +213,7 @@ where } if epoch >= StacksEpochId::Epoch21 { - let next_block = StacksBlockId([2 as u8; 32]); + let next_block = StacksBlockId([2; 32]); let mut clarity_conn = clarity_instance.begin_block(&tip, &next_block, &TEST_HEADER_DB, &TEST_BURN_STATE_DB); clarity_conn.initialize_epoch_2_1().unwrap(); @@ -223,7 +223,7 @@ where let mut marf_kv = clarity_instance.destroy(); - let mut store = marf_kv.begin(&tip, &StacksBlockId([3 as u8; 32])); + let mut store = marf_kv.begin(&tip, &StacksBlockId([3; 32])); to_do(OwnedEnvironment::new_max_limit( store.as_clarity_db(&TEST_HEADER_DB, &TEST_BURN_STATE_DB), @@ -1052,7 +1052,7 @@ fn test_cost_contract_short_circuits(use_mainnet: bool, clarity_version: Clarity let mut clarity_inst = ClarityInstance::new(use_mainnet, chain_id, marf_kv); let mut block_conn = clarity_inst.begin_block( &StacksBlockId::new(&FIRST_BURNCHAIN_CONSENSUS_HASH, &FIRST_STACKS_BLOCK_HASH), - &StacksBlockId([1 as u8; 32]), + &StacksBlockId([1; 32]), &TEST_HEADER_DB, burn_db, ); @@ -1111,7 +1111,7 @@ fn test_cost_contract_short_circuits(use_mainnet: bool, clarity_version: Clarity }; let without_interposing_5 = { - let mut store = marf_kv.begin(&StacksBlockId([1 as u8; 32]), &StacksBlockId([2 as u8; 32])); + let mut store = marf_kv.begin(&StacksBlockId([1; 32]), &StacksBlockId([2; 32])); let mut owned_env = OwnedEnvironment::new_max_limit( store.as_clarity_db(&TEST_HEADER_DB, burn_db), StacksEpochId::Epoch20, @@ -1134,7 +1134,7 @@ fn test_cost_contract_short_circuits(use_mainnet: bool, clarity_version: Clarity }; let without_interposing_10 = { - let mut store = marf_kv.begin(&StacksBlockId([2 as u8; 32]), &StacksBlockId([3 as u8; 32])); + let mut store = marf_kv.begin(&StacksBlockId([2; 32]), &StacksBlockId([3; 32])); let mut owned_env = OwnedEnvironment::new_max_limit( store.as_clarity_db(&TEST_HEADER_DB, burn_db), StacksEpochId::Epoch20, @@ -1163,7 +1163,7 @@ fn test_cost_contract_short_circuits(use_mainnet: bool, clarity_version: Clarity }; { - let mut store = marf_kv.begin(&StacksBlockId([3 as u8; 32]), &StacksBlockId([4 as u8; 32])); + let mut store = marf_kv.begin(&StacksBlockId([3; 32]), &StacksBlockId([4; 32])); let mut db = store.as_clarity_db(&TEST_HEADER_DB, burn_db); db.begin(); db.set_variable_unknown_descriptor( @@ -1194,7 +1194,7 @@ fn test_cost_contract_short_circuits(use_mainnet: bool, clarity_version: Clarity } let with_interposing_5 = { - let mut store = marf_kv.begin(&StacksBlockId([4 as u8; 32]), &StacksBlockId([5 as u8; 32])); + let mut store = marf_kv.begin(&StacksBlockId([4; 32]), &StacksBlockId([5; 32])); let mut owned_env = OwnedEnvironment::new_max_limit( store.as_clarity_db(&TEST_HEADER_DB, burn_db), @@ -1218,7 +1218,7 @@ fn test_cost_contract_short_circuits(use_mainnet: bool, clarity_version: Clarity }; let with_interposing_10 = { - let mut store = marf_kv.begin(&StacksBlockId([5 as u8; 32]), &StacksBlockId([6 as u8; 32])); + let mut store = marf_kv.begin(&StacksBlockId([5; 32]), &StacksBlockId([6; 32])); let mut owned_env = OwnedEnvironment::new_max_limit( store.as_clarity_db(&TEST_HEADER_DB, burn_db), StacksEpochId::Epoch20, @@ -1304,7 +1304,7 @@ fn test_cost_voting_integration(use_mainnet: bool, clarity_version: ClarityVersi let mut clarity_inst = ClarityInstance::new(use_mainnet, chain_id, marf_kv); let mut block_conn = clarity_inst.begin_block( &StacksBlockId::new(&FIRST_BURNCHAIN_CONSENSUS_HASH, &FIRST_STACKS_BLOCK_HASH), - &StacksBlockId([1 as u8; 32]), + &StacksBlockId([1; 32]), &TEST_HEADER_DB, burn_db, ); @@ -1479,7 +1479,7 @@ fn test_cost_voting_integration(use_mainnet: bool, clarity_version: ClarityVersi }; { - let mut store = marf_kv.begin(&StacksBlockId([1 as u8; 32]), &StacksBlockId([2 as u8; 32])); + let mut store = marf_kv.begin(&StacksBlockId([1; 32]), &StacksBlockId([2; 32])); let mut db = store.as_clarity_db(&TEST_HEADER_DB, burn_db); db.begin(); @@ -1517,7 +1517,7 @@ fn test_cost_voting_integration(use_mainnet: bool, clarity_version: ClarityVersi } let le_cost_without_interception = { - let mut store = marf_kv.begin(&StacksBlockId([2 as u8; 32]), &StacksBlockId([3 as u8; 32])); + let mut store = marf_kv.begin(&StacksBlockId([2; 32]), &StacksBlockId([3; 32])); let mut owned_env = OwnedEnvironment::new_max_limit( store.as_clarity_db(&TEST_HEADER_DB, burn_db), StacksEpochId::Epoch20, @@ -1578,7 +1578,7 @@ fn test_cost_voting_integration(use_mainnet: bool, clarity_version: ClarityVersi ]; { - let mut store = marf_kv.begin(&StacksBlockId([3 as u8; 32]), &StacksBlockId([4 as u8; 32])); + let mut store = marf_kv.begin(&StacksBlockId([3; 32]), &StacksBlockId([4; 32])); let mut db = store.as_clarity_db(&TEST_HEADER_DB, burn_db); db.begin(); @@ -1618,7 +1618,7 @@ fn test_cost_voting_integration(use_mainnet: bool, clarity_version: ClarityVersi } { - let mut store = marf_kv.begin(&StacksBlockId([4 as u8; 32]), &StacksBlockId([5 as u8; 32])); + let mut store = marf_kv.begin(&StacksBlockId([4; 32]), &StacksBlockId([5; 32])); let mut owned_env = OwnedEnvironment::new_max_limit( store.as_clarity_db(&TEST_HEADER_DB, burn_db), StacksEpochId::Epoch20, diff --git a/stackslib/src/clarity_vm/tests/events.rs b/stackslib/src/clarity_vm/tests/events.rs index 7037e8dcf3..3e09b6b924 100644 --- a/stackslib/src/clarity_vm/tests/events.rs +++ b/stackslib/src/clarity_vm/tests/events.rs @@ -88,7 +88,7 @@ fn helper_execute_epoch( &FIRST_BURNCHAIN_CONSENSUS_HASH, &FIRST_STACKS_BLOCK_HASH, ), - &StacksBlockId([1 as u8; 32]), + &StacksBlockId([1; 32]), ); let mut owned_env = OwnedEnvironment::new_max_limit( diff --git a/stackslib/src/clarity_vm/tests/forking.rs b/stackslib/src/clarity_vm/tests/forking.rs index c74cb0c8b0..22a3f07321 100644 --- a/stackslib/src/clarity_vm/tests/forking.rs +++ b/stackslib/src/clarity_vm/tests/forking.rs @@ -195,7 +195,7 @@ fn test_at_block_good(#[case] version: ClarityVersion, #[case] epoch: StacksEpoc Error::Runtime(x, _) => assert_eq!( x, RuntimeErrorType::UnknownBlockHeaderHash(BlockHeaderHash::from( - vec![2 as u8; 32].as_slice() + vec![2; 32].as_slice() )) ), _ => panic!("Unexpected error"), @@ -287,7 +287,7 @@ fn with_separate_forks_environment( let mut marf_kv = MarfedKV::temporary(); { - let mut store = marf_kv.begin(&StacksBlockId::sentinel(), &StacksBlockId([0 as u8; 32])); + let mut store = marf_kv.begin(&StacksBlockId::sentinel(), &StacksBlockId([0; 32])); store .as_clarity_db(&TEST_HEADER_DB, &TEST_BURN_STATE_DB) .initialize(); @@ -295,7 +295,7 @@ fn with_separate_forks_environment( } { - let mut store = marf_kv.begin(&StacksBlockId([0 as u8; 32]), &StacksBlockId([1 as u8; 32])); + let mut store = marf_kv.begin(&StacksBlockId([0; 32]), &StacksBlockId([1; 32])); let mut owned_env = OwnedEnvironment::new( store.as_clarity_db(&TEST_HEADER_DB, &TEST_BURN_STATE_DB), epoch, @@ -307,7 +307,7 @@ fn with_separate_forks_environment( // Now, we can do our forking. { - let mut store = marf_kv.begin(&StacksBlockId([1 as u8; 32]), &StacksBlockId([2 as u8; 32])); + let mut store = marf_kv.begin(&StacksBlockId([1; 32]), &StacksBlockId([2; 32])); let mut owned_env = OwnedEnvironment::new( store.as_clarity_db(&TEST_HEADER_DB, &TEST_BURN_STATE_DB), epoch, @@ -317,7 +317,7 @@ fn with_separate_forks_environment( } { - let mut store = marf_kv.begin(&StacksBlockId([1 as u8; 32]), &StacksBlockId([3 as u8; 32])); + let mut store = marf_kv.begin(&StacksBlockId([1; 32]), &StacksBlockId([3; 32])); let mut owned_env = OwnedEnvironment::new( store.as_clarity_db(&TEST_HEADER_DB, &TEST_BURN_STATE_DB), epoch, @@ -327,7 +327,7 @@ fn with_separate_forks_environment( } { - let mut store = marf_kv.begin(&StacksBlockId([2 as u8; 32]), &StacksBlockId([4 as u8; 32])); + let mut store = marf_kv.begin(&StacksBlockId([2; 32]), &StacksBlockId([4; 32])); let mut owned_env = OwnedEnvironment::new( store.as_clarity_db(&TEST_HEADER_DB, &TEST_BURN_STATE_DB), epoch, diff --git a/stackslib/src/clarity_vm/tests/large_contract.rs b/stackslib/src/clarity_vm/tests/large_contract.rs index e7d8faff0c..2cfc0b2d01 100644 --- a/stackslib/src/clarity_vm/tests/large_contract.rs +++ b/stackslib/src/clarity_vm/tests/large_contract.rs @@ -48,7 +48,7 @@ use crate::clarity_vm::database::MemoryBackingStore; use crate::util_lib::boot::boot_code_id; fn test_block_headers(n: u8) -> StacksBlockId { - StacksBlockId([n as u8; 32]) + StacksBlockId([n; 32]) } pub const TEST_BURN_STATE_DB_AST_PRECHECK: UnitTestBurnStateDB = UnitTestBurnStateDB { @@ -131,7 +131,7 @@ fn test_simple_token_system(#[case] version: ClarityVersion, #[case] epoch: Stac let mut gb = clarity.begin_test_genesis_block( &StacksBlockId::sentinel(), - &StacksBlockId([0xfe as u8; 32]), + &StacksBlockId([0xfe; 32]), &TEST_HEADER_DB, burn_db, ); @@ -197,8 +197,8 @@ fn test_simple_token_system(#[case] version: ClarityVersion, #[case] epoch: Stac { let mut block = new_block( &mut clarity, - &StacksBlockId([0xfe as u8; 32]), - &StacksBlockId([0 as u8; 32]), + &StacksBlockId([0xfe; 32]), + &StacksBlockId([0; 32]), &TEST_HEADER_DB, burn_db, ); @@ -697,7 +697,7 @@ pub fn rollback_log_memory_test( clarity_instance .begin_test_genesis_block( &StacksBlockId::sentinel(), - &StacksBlockId([0 as u8; 32]), + &StacksBlockId([0; 32]), &TEST_HEADER_DB, burn_db, ) @@ -706,8 +706,8 @@ pub fn rollback_log_memory_test( { let mut conn = new_block( &mut clarity_instance, - &StacksBlockId([0 as u8; 32]), - &StacksBlockId([1 as u8; 32]), + &StacksBlockId([0; 32]), + &StacksBlockId([1; 32]), &TEST_HEADER_DB, burn_db, ); @@ -768,7 +768,7 @@ pub fn let_memory_test(#[case] clarity_version: ClarityVersion, #[case] epoch_id clarity_instance .begin_test_genesis_block( &StacksBlockId::sentinel(), - &StacksBlockId([0 as u8; 32]), + &StacksBlockId([0; 32]), &TEST_HEADER_DB, burn_db, ) @@ -777,8 +777,8 @@ pub fn let_memory_test(#[case] clarity_version: ClarityVersion, #[case] epoch_id { let mut conn = new_block( &mut clarity_instance, - &StacksBlockId([0 as u8; 32]), - &StacksBlockId([1 as u8; 32]), + &StacksBlockId([0; 32]), + &StacksBlockId([1; 32]), &TEST_HEADER_DB, burn_db, ); @@ -847,7 +847,7 @@ pub fn argument_memory_test( clarity_instance .begin_test_genesis_block( &StacksBlockId::sentinel(), - &StacksBlockId([0 as u8; 32]), + &StacksBlockId([0; 32]), &TEST_HEADER_DB, burn_db, ) @@ -856,8 +856,8 @@ pub fn argument_memory_test( { let mut conn = new_block( &mut clarity_instance, - &StacksBlockId([0 as u8; 32]), - &StacksBlockId([1 as u8; 32]), + &StacksBlockId([0; 32]), + &StacksBlockId([1; 32]), &TEST_HEADER_DB, burn_db, ); @@ -924,7 +924,7 @@ pub fn fcall_memory_test(#[case] clarity_version: ClarityVersion, #[case] epoch_ clarity_instance .begin_test_genesis_block( &StacksBlockId::sentinel(), - &StacksBlockId([0 as u8; 32]), + &StacksBlockId([0; 32]), &TEST_HEADER_DB, burn_db, ) @@ -933,8 +933,8 @@ pub fn fcall_memory_test(#[case] clarity_version: ClarityVersion, #[case] epoch_ { let mut conn = new_block( &mut clarity_instance, - &StacksBlockId([0 as u8; 32]), - &StacksBlockId([1 as u8; 32]), + &StacksBlockId([0; 32]), + &StacksBlockId([1; 32]), &TEST_HEADER_DB, burn_db, ); @@ -1043,7 +1043,7 @@ pub fn ccall_memory_test(#[case] clarity_version: ClarityVersion, #[case] epoch_ clarity_instance .begin_test_genesis_block( &StacksBlockId::sentinel(), - &StacksBlockId([0 as u8; 32]), + &StacksBlockId([0; 32]), &TEST_HEADER_DB, burn_db, ) @@ -1052,8 +1052,8 @@ pub fn ccall_memory_test(#[case] clarity_version: ClarityVersion, #[case] epoch_ { let mut conn = new_block( &mut clarity_instance, - &StacksBlockId([0 as u8; 32]), - &StacksBlockId([1 as u8; 32]), + &StacksBlockId([0; 32]), + &StacksBlockId([1; 32]), &TEST_HEADER_DB, burn_db, ); diff --git a/stackslib/src/clarity_vm/tests/simple_tests.rs b/stackslib/src/clarity_vm/tests/simple_tests.rs index 0367bd8448..3a98d26c1a 100644 --- a/stackslib/src/clarity_vm/tests/simple_tests.rs +++ b/stackslib/src/clarity_vm/tests/simple_tests.rs @@ -30,7 +30,7 @@ where { let mut store = marf_kv.begin( &StacksBlockId::new(&FIRST_BURNCHAIN_CONSENSUS_HASH, &FIRST_STACKS_BLOCK_HASH), - &StacksBlockId([1 as u8; 32]), + &StacksBlockId([1; 32]), ); let mut owned_env = OwnedEnvironment::new( @@ -65,7 +65,7 @@ fn test_at_unknown_block() { Error::Runtime(x, _) => assert_eq!( x, RuntimeErrorType::UnknownBlockHeaderHash(BlockHeaderHash::from( - vec![2 as u8; 32].as_slice() + vec![2; 32].as_slice() )) ), _ => panic!("Unexpected error"), diff --git a/stackslib/src/core/tests/mod.rs b/stackslib/src/core/tests/mod.rs index a209ef0677..5dea6e9a18 100644 --- a/stackslib/src/core/tests/mod.rs +++ b/stackslib/src/core/tests/mod.rs @@ -1992,8 +1992,7 @@ fn test_txtags() { let txtags = mempool.get_txtags(&seed).unwrap(); let len_txtags = all_txtags.len(); - let last_txtags = - &all_txtags[len_txtags.saturating_sub(BLOOM_COUNTER_DEPTH as usize)..len_txtags]; + let last_txtags = &all_txtags[len_txtags.saturating_sub(BLOOM_COUNTER_DEPTH)..len_txtags]; let mut expected_txtag_set = HashSet::new(); for txtags in last_txtags.iter() { @@ -2240,7 +2239,7 @@ fn test_find_next_missing_transactions() { txid.clone(), tx_bytes, tx_fee, - block_height as u64, + block_height, &origin_addr, origin_nonce, &sponsor_addr, @@ -2375,7 +2374,7 @@ fn test_find_next_missing_transactions() { ) .unwrap(); assert!(txs.len() <= page_size as usize); - assert!(num_visited <= page_size as u64); + assert!(num_visited <= page_size); if txs.len() == 0 { assert!(next_page_opt.is_none()); @@ -2414,7 +2413,7 @@ fn test_find_next_missing_transactions() { eprintln!("find_next_missing_transactions with empty bloom filter took {} ms to serve {} transactions", ts_after.saturating_sub(ts_before), page_size); assert!(txs.len() <= page_size as usize); - assert!(num_visited <= page_size as u64); + assert!(num_visited <= page_size); if txs.len() == 0 { assert!(next_page_opt.is_none()); diff --git a/stackslib/src/cost_estimates/fee_medians.rs b/stackslib/src/cost_estimates/fee_medians.rs index 12bd2fb9b8..8ebff133e1 100644 --- a/stackslib/src/cost_estimates/fee_medians.rs +++ b/stackslib/src/cost_estimates/fee_medians.rs @@ -244,7 +244,7 @@ pub fn fee_rate_estimate_from_sorted_weighted_fees( for rate_and_weight in sorted_fee_rates { cumulative_weight += rate_and_weight.weight as f64; let percentile_n: f64 = - (cumulative_weight as f64 - rate_and_weight.weight as f64 / 2f64) / total_weight as f64; + (cumulative_weight - rate_and_weight.weight as f64 / 2f64) / total_weight; percentiles.push(percentile_n); } assert_eq!(percentiles.len(), sorted_fee_rates.len()); diff --git a/stackslib/src/monitoring/mod.rs b/stackslib/src/monitoring/mod.rs index 7f1aa9db26..6db895249c 100644 --- a/stackslib/src/monitoring/mod.rs +++ b/stackslib/src/monitoring/mod.rs @@ -388,7 +388,7 @@ pub fn test_convert_uint256_to_f64() { let original = ((Uint512::from_uint256(&Uint256::max()) * Uint512::from_u64(10)) / Uint512::from_u64(100)) .to_uint256(); - assert_approx_eq!(convert_uint256_to_f64_percentage(original, 7), 10 as f64); + assert_approx_eq!(convert_uint256_to_f64_percentage(original, 7), 10_f64); let original = ((Uint512::from_uint256(&Uint256::max()) * Uint512::from_u64(122)) / Uint512::from_u64(1000)) diff --git a/stackslib/src/net/api/getheaders.rs b/stackslib/src/net/api/getheaders.rs index fc585fd2e9..3bf7707c6d 100644 --- a/stackslib/src/net/api/getheaders.rs +++ b/stackslib/src/net/api/getheaders.rs @@ -242,7 +242,7 @@ impl HttpChunkGenerator for StacksHeaderStream { // then write ']' test_debug!("Opening header stream"); self.total_bytes += 1; - return Ok(vec!['[' as u8]); + return Ok(vec![b'[']); } if self.num_headers == 0 { test_debug!("End of header stream"); @@ -270,7 +270,7 @@ impl HttpChunkGenerator for StacksHeaderStream { self.num_headers -= 1; if self.num_headers > 0 { - header_bytes.push(',' as u8); + header_bytes.push(b','); } else { self.end_of_stream = true; } @@ -298,7 +298,7 @@ impl HttpChunkGenerator for StacksHeaderStream { test_debug!("Corking header stream"); self.corked = true; self.total_bytes += 1; - return Ok(vec![']' as u8]); + return Ok(vec![b']']); } test_debug!("Header stream terminated"); diff --git a/stackslib/src/net/api/tests/postmempoolquery.rs b/stackslib/src/net/api/tests/postmempoolquery.rs index 6954024844..8f921525a3 100644 --- a/stackslib/src/net/api/tests/postmempoolquery.rs +++ b/stackslib/src/net/api/tests/postmempoolquery.rs @@ -178,7 +178,7 @@ fn test_stream_mempool_txs() { txid.clone(), tx_bytes, tx_fee, - block_height as u64, + block_height, &origin_addr, origin_nonce, &sponsor_addr, diff --git a/stackslib/src/net/atlas/download.rs b/stackslib/src/net/atlas/download.rs index a9dad242a5..c396a94470 100644 --- a/stackslib/src/net/atlas/download.rs +++ b/stackslib/src/net/atlas/download.rs @@ -1314,10 +1314,11 @@ impl ReliabilityReport { } pub fn score(&self) -> u32 { - match self.total_requests_sent { - 0 => 0 as u32, - n => self.total_requests_success * 1000 / (n * 1000) + n, + if self.total_requests_sent == 0 { + return 0; } + self.total_requests_success * 1000 / (self.total_requests_sent * 1000) + + self.total_requests_sent } } diff --git a/stackslib/src/net/chat.rs b/stackslib/src/net/chat.rs index 1d8e5d10d2..7dd5372a9c 100644 --- a/stackslib/src/net/chat.rs +++ b/stackslib/src/net/chat.rs @@ -1442,7 +1442,7 @@ impl ConversationP2P { peer_dbconn, self.network_id, epoch.network_epoch, - (get_epoch_time_secs() as u64).saturating_sub(self.connection.options.max_neighbor_age), + get_epoch_time_secs().saturating_sub(self.connection.options.max_neighbor_age), MAX_NEIGHBORS_DATA_LEN, chain_view.burn_block_height, false, @@ -3252,7 +3252,7 @@ mod test { for i in prev_snapshot.block_height..chain_view.burn_block_height + 1 { let mut next_snapshot = prev_snapshot.clone(); - let big_i = Uint256::from_u64(i as u64); + let big_i = Uint256::from_u64(i); let mut big_i_bytes_32 = [0u8; 32]; let mut big_i_bytes_20 = [0u8; 20]; big_i_bytes_32.copy_from_slice(&big_i.to_u8_slice()); @@ -5575,7 +5575,7 @@ mod test { let getblocksdata_1 = GetBlocksInv { consensus_hash: convo_1_ancestor.consensus_hash, - num_blocks: 10 as u16, + num_blocks: 10, }; let getblocksdata_1_msg = convo_1 .sign_message( diff --git a/stackslib/src/net/connection.rs b/stackslib/src/net/connection.rs index 0e58adb36e..590184288d 100644 --- a/stackslib/src/net/connection.rs +++ b/stackslib/src/net/connection.rs @@ -1989,12 +1989,12 @@ mod test { let mut serialized_ping = vec![]; ping.consensus_serialize(&mut serialized_ping).unwrap(); assert_eq!( - conn.outbox.socket_out_buf[0..(conn.outbox.socket_out_ptr as usize)], - serialized_ping[0..(conn.outbox.socket_out_ptr as usize)] + conn.outbox.socket_out_buf[0..conn.outbox.socket_out_ptr], + serialized_ping[0..conn.outbox.socket_out_ptr] ); let mut half_ping = - conn.outbox.socket_out_buf.clone()[0..(conn.outbox.socket_out_ptr as usize)].to_vec(); + conn.outbox.socket_out_buf.clone()[0..conn.outbox.socket_out_ptr].to_vec(); let mut ping_buf_05 = vec![0; 2 * ping_size - (ping_size + ping_size / 2)]; // flush the remaining half-ping diff --git a/stackslib/src/net/db.rs b/stackslib/src/net/db.rs index ff6b5a9a05..4fd84b3f0d 100644 --- a/stackslib/src/net/db.rs +++ b/stackslib/src/net/db.rs @@ -157,7 +157,7 @@ impl LocalPeer { info!( "Will be authenticating p2p messages with the following"; "public key" => &Secp256k1PublicKey::from_private(&pkey).to_hex(), - "services" => &to_hex(&(services as u16).to_be_bytes()), + "services" => &to_hex(&services.to_be_bytes()), "Stacker DBs" => stacker_dbs.iter().map(|cid| format!("{}", &cid)).collect::>().join(",") ); @@ -169,7 +169,7 @@ impl LocalPeer { private_key_expire: key_expire, addrbytes: addr, port: port, - services: services as u16, + services, data_url: data_url, public_ip_address: None, stacker_dbs, @@ -885,7 +885,7 @@ impl PeerDB { /// Re-key and return the new local peer pub fn rekey(&mut self, new_expire_block: u64) -> Result { - if new_expire_block > ((1 as u64) << 63) - 1 { + if new_expire_block > (1 << 63) - 1 { return Err(db_error::Overflow); } @@ -1253,7 +1253,7 @@ impl PeerDB { let empty_key = StacksPublicKey::from_private(&StacksPrivateKey::new()); let mut empty_neighbor = Neighbor::empty(&nk, &empty_key, 0); - empty_neighbor.allowed = allow_deadline as i64; + empty_neighbor.allowed = allow_deadline; debug!("Preemptively allow peer {:?}", &nk); if !PeerDB::try_insert_peer(tx, &empty_neighbor, &[])? { @@ -2830,7 +2830,7 @@ mod test { }, public_key: Secp256k1PublicKey::from_private(&Secp256k1PrivateKey::new()), expire_block: (i + 23456) as u64, - last_contact_time: (1552509642 + (i as u64)) as u64, + last_contact_time: (1552509642 + (i as u64)), allowed: (now_secs + 600) as i64, denied: -1, asn: (34567 + i) as u32, @@ -2850,7 +2850,7 @@ mod test { }, public_key: Secp256k1PublicKey::from_private(&Secp256k1PrivateKey::new()), expire_block: (i + 23456) as u64, - last_contact_time: (1552509642 + (i as u64)) as u64, + last_contact_time: (1552509642 + (i as u64)), allowed: 0, denied: -1, asn: (34567 + i) as u32, @@ -2934,7 +2934,7 @@ mod test { }, public_key: Secp256k1PublicKey::from_private(&Secp256k1PrivateKey::new()), expire_block: (i + 23456) as u64, - last_contact_time: (1552509642 + (i as u64)) as u64, + last_contact_time: (1552509642 + (i as u64)), allowed: -1, denied: -1, asn: (34567 + i) as u32, @@ -2955,7 +2955,7 @@ mod test { }, public_key: Secp256k1PublicKey::from_private(&Secp256k1PrivateKey::new()), expire_block: (i + 23456) as u64, - last_contact_time: (1552509642 + (i as u64)) as u64, + last_contact_time: (1552509642 + (i as u64)), allowed: -1, denied: -1, asn: (34567 + i) as u32, diff --git a/stackslib/src/net/inv/epoch2x.rs b/stackslib/src/net/inv/epoch2x.rs index bbdd8f68ae..7625aa0776 100644 --- a/stackslib/src/net/inv/epoch2x.rs +++ b/stackslib/src/net/inv/epoch2x.rs @@ -175,8 +175,8 @@ impl PeerBlocksInv { assert!(block_height >= self.first_block_height); let sortition_height = block_height - self.first_block_height; - self.num_sortitions = if self.num_sortitions < sortition_height + (bitlen as u64) { - sortition_height + (bitlen as u64) + self.num_sortitions = if self.num_sortitions < sortition_height + bitlen { + sortition_height + bitlen } else { self.num_sortitions }; diff --git a/stackslib/src/net/p2p.rs b/stackslib/src/net/p2p.rs index 13f7ad7fac..b9f27174db 100644 --- a/stackslib/src/net/p2p.rs +++ b/stackslib/src/net/p2p.rs @@ -3269,9 +3269,9 @@ impl PeerNetwork { } let reward_cycle_start = self.antientropy_start_reward_cycle; - let reward_cycle_finish = - self.antientropy_start_reward_cycle - .saturating_sub(self.connection_opts.inv_reward_cycles) as u64; + let reward_cycle_finish = self + .antientropy_start_reward_cycle + .saturating_sub(self.connection_opts.inv_reward_cycles); self.antientropy_start_reward_cycle = reward_cycle_finish; diff --git a/stackslib/src/net/relay.rs b/stackslib/src/net/relay.rs index b93171916c..04d35624f1 100644 --- a/stackslib/src/net/relay.rs +++ b/stackslib/src/net/relay.rs @@ -342,7 +342,7 @@ impl RelayerStats { let mut to_remove = vec![]; for (ts, old_nk) in self.recent_updates.iter() { self.recent_messages.remove(old_nk); - if self.recent_messages.len() <= (MAX_RELAYER_STATS as usize) - 1 { + if self.recent_messages.len() <= MAX_RELAYER_STATS - 1 { break; } to_remove.push(*ts); diff --git a/stackslib/src/net/stackerdb/sync.rs b/stackslib/src/net/stackerdb/sync.rs index 237f582d26..025509d40c 100644 --- a/stackslib/src/net/stackerdb/sync.rs +++ b/stackslib/src/net/stackerdb/sync.rs @@ -1334,7 +1334,7 @@ impl StackerDBSync { network: &PeerNetwork, ) -> Result<(), net_error> { // figure out the new expected versions - let mut expected_versions = vec![0u32; self.num_slots as usize]; + let mut expected_versions = vec![0u32; self.num_slots]; for (_, chunk_inv) in self.chunk_invs.iter() { for (slot_id, slot_version) in chunk_inv.slot_versions.iter().enumerate() { expected_versions[slot_id] = (*slot_version).max(expected_versions[slot_id]); diff --git a/stackslib/src/net/stackerdb/tests/sync.rs b/stackslib/src/net/stackerdb/tests/sync.rs index 5f6e8a7bed..19926420fc 100644 --- a/stackslib/src/net/stackerdb/tests/sync.rs +++ b/stackslib/src/net/stackerdb/tests/sync.rs @@ -135,7 +135,7 @@ fn setup_stackerdb(peer: &mut TestPeer, idx: usize, fill: bool, num_slots: usize thread_rng().fill(&mut inner_data[..]); let mut chunk_data = StackerDBChunkData::new(i as u32, 1, inner_data); - chunk_data.sign(&pks[i as usize]).unwrap(); + chunk_data.sign(&pks[i]).unwrap(); let chunk_md = chunk_data.get_slot_metadata(); tx.try_replace_chunk(contract_id, &chunk_md, &chunk_data.data) @@ -167,13 +167,13 @@ fn load_stackerdb(peer: &TestPeer, idx: usize) -> Vec<(SlotMetadata, Vec)> { let chunk_metadata = peer .network .stackerdbs - .get_slot_metadata(&peer.config.stacker_dbs[idx], i as u32) + .get_slot_metadata(&peer.config.stacker_dbs[idx], i) .unwrap() .unwrap(); let chunk = peer .network .stackerdbs - .get_latest_chunk(&peer.config.stacker_dbs[idx], i as u32) + .get_latest_chunk(&peer.config.stacker_dbs[idx], i) .unwrap() .unwrap_or(vec![]); ret.push((chunk_metadata, chunk)); diff --git a/stackslib/src/net/tests/inv/epoch2x.rs b/stackslib/src/net/tests/inv/epoch2x.rs index e31b6dc593..aed43bdcba 100644 --- a/stackslib/src/net/tests/inv/epoch2x.rs +++ b/stackslib/src/net/tests/inv/epoch2x.rs @@ -1248,7 +1248,7 @@ fn test_inv_sync_start_reward_cycle() { let mut peer_1 = TestPeer::new(peer_1_config); - let num_blocks = (GETPOXINV_MAX_BITLEN * 2) as u64; + let num_blocks = GETPOXINV_MAX_BITLEN * 2; for i in 0..num_blocks { let (burn_ops, stacks_block, microblocks) = peer_1.make_default_tenure(); peer_1.next_burnchain_block(burn_ops.clone()); @@ -1298,7 +1298,7 @@ fn test_inv_sync_check_peer_epoch2x_synced() { let mut peer_1 = TestPeer::new(peer_1_config); - let num_blocks = (GETPOXINV_MAX_BITLEN * 2) as u64; + let num_blocks = GETPOXINV_MAX_BITLEN * 2; for i in 0..num_blocks { let (burn_ops, stacks_block, microblocks) = peer_1.make_default_tenure(); peer_1.next_burnchain_block(burn_ops.clone()); @@ -1340,7 +1340,7 @@ fn test_sync_inv_2_peers_plain() { peer_1.add_neighbor(&mut peer_2.to_neighbor(), None, true); peer_2.add_neighbor(&mut peer_1.to_neighbor(), None, true); - let num_blocks = (GETPOXINV_MAX_BITLEN * 2) as u64; + let num_blocks = GETPOXINV_MAX_BITLEN * 2; let first_stacks_block_height = { let sn = SortitionDB::get_canonical_burn_chain_tip(&peer_1.sortdb.as_ref().unwrap().conn()) @@ -1517,7 +1517,7 @@ fn test_sync_inv_2_peers_stale() { peer_1.add_neighbor(&mut peer_2.to_neighbor(), None, true); peer_2.add_neighbor(&mut peer_1.to_neighbor(), None, true); - let num_blocks = (GETPOXINV_MAX_BITLEN * 2) as u64; + let num_blocks = GETPOXINV_MAX_BITLEN * 2; let first_stacks_block_height = { let sn = SortitionDB::get_canonical_burn_chain_tip(&peer_1.sortdb.as_ref().unwrap().conn()) @@ -1625,7 +1625,7 @@ fn test_sync_inv_2_peers_unstable() { peer_1.add_neighbor(&mut peer_2.to_neighbor(), None, true); peer_2.add_neighbor(&mut peer_1.to_neighbor(), None, true); - let num_blocks = (GETPOXINV_MAX_BITLEN * 2) as u64; + let num_blocks = GETPOXINV_MAX_BITLEN * 2; let first_stacks_block_height = { let sn = @@ -1838,7 +1838,7 @@ fn test_sync_inv_2_peers_different_pox_vectors() { peer_1.add_neighbor(&mut peer_2.to_neighbor(), None, true); peer_2.add_neighbor(&mut peer_1.to_neighbor(), None, true); - let num_blocks = (GETPOXINV_MAX_BITLEN * 3) as u64; + let num_blocks = GETPOXINV_MAX_BITLEN * 3; let first_stacks_block_height = { let sn = diff --git a/stackslib/src/net/tests/inv/nakamoto.rs b/stackslib/src/net/tests/inv/nakamoto.rs index 5f889cde3e..26d618961c 100644 --- a/stackslib/src/net/tests/inv/nakamoto.rs +++ b/stackslib/src/net/tests/inv/nakamoto.rs @@ -596,7 +596,7 @@ fn check_inv_state( tenure_inv.get(bit.try_into().unwrap()).unwrap_or(false) }; - let burn_block_height = (*tenure_rc as u64) * u64::from(rc_len) + (bit as u64); + let burn_block_height = *tenure_rc * u64::from(rc_len) + (bit as u64); if burn_block_height < nakamoto_start_burn_height { // inv doesn't cover epoch 2 assert!( diff --git a/stackslib/src/net/tests/relay/epoch2x.rs b/stackslib/src/net/tests/relay/epoch2x.rs index f4fc8d9eb8..629fde709d 100644 --- a/stackslib/src/net/tests/relay/epoch2x.rs +++ b/stackslib/src/net/tests/relay/epoch2x.rs @@ -2123,8 +2123,8 @@ fn test_get_blocks_and_microblocks_peers_broadcast() { let ((tip_consensus_hash, tip_block, _), idx) = { let block_data = blocks_and_microblocks.borrow(); - let idx = blocks_idx.borrow(); - (block_data[(*idx as usize).saturating_sub(1)].clone(), *idx) + let idx: usize = *blocks_idx.borrow(); + (block_data[idx.saturating_sub(1)].clone(), idx) }; if idx > 0 { diff --git a/stackslib/src/util_lib/signed_structured_data.rs b/stackslib/src/util_lib/signed_structured_data.rs index ac5c0224d8..14882c2fb9 100644 --- a/stackslib/src/util_lib/signed_structured_data.rs +++ b/stackslib/src/util_lib/signed_structured_data.rs @@ -216,7 +216,7 @@ pub mod pox4 { ); result .expect("FATAL: failed to execute contract call") - .expect_buff(32 as usize) + .expect_buff(32) .expect("FATAL: expected buff result") }) } diff --git a/stackslib/src/util_lib/strings.rs b/stackslib/src/util_lib/strings.rs index 0486e6bf81..eb1a637ff5 100644 --- a/stackslib/src/util_lib/strings.rs +++ b/stackslib/src/util_lib/strings.rs @@ -207,7 +207,7 @@ impl StacksString { // This is 0x20 through 0x7e, inclusive, as well as '\t' and '\n' // TODO: DRY up with vm::representations for c in s.as_bytes().iter() { - if (*c < 0x20 && *c != ('\t' as u8) && *c != ('\n' as u8)) || (*c > 0x7e) { + if (*c < 0x20 && *c != (b'\t') && *c != (b'\n')) || (*c > 0x7e) { return false; } } From 9615a715013acbfe1f703ffa99286e79e36fc0a0 Mon Sep 17 00:00:00 2001 From: Jacinta Ferrant Date: Thu, 2 Jan 2025 17:55:58 -0500 Subject: [PATCH 2/2] CRC: remove unnecessary brackets and store total_requests_sent as a local var Signed-off-by: Jacinta Ferrant --- stackslib/src/net/atlas/download.rs | 8 ++++---- stackslib/src/util_lib/strings.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/stackslib/src/net/atlas/download.rs b/stackslib/src/net/atlas/download.rs index c396a94470..bcc58add47 100644 --- a/stackslib/src/net/atlas/download.rs +++ b/stackslib/src/net/atlas/download.rs @@ -1314,11 +1314,11 @@ impl ReliabilityReport { } pub fn score(&self) -> u32 { - if self.total_requests_sent == 0 { - return 0; + let n = self.total_requests_sent; + if n == 0 { + return n; } - self.total_requests_success * 1000 / (self.total_requests_sent * 1000) - + self.total_requests_sent + self.total_requests_success * 1000 / (n * 1000) + n } } diff --git a/stackslib/src/util_lib/strings.rs b/stackslib/src/util_lib/strings.rs index eb1a637ff5..f9757e4cff 100644 --- a/stackslib/src/util_lib/strings.rs +++ b/stackslib/src/util_lib/strings.rs @@ -207,7 +207,7 @@ impl StacksString { // This is 0x20 through 0x7e, inclusive, as well as '\t' and '\n' // TODO: DRY up with vm::representations for c in s.as_bytes().iter() { - if (*c < 0x20 && *c != (b'\t') && *c != (b'\n')) || (*c > 0x7e) { + if (*c < 0x20 && *c != b'\t' && *c != b'\n') || *c > 0x7e { return false; } }