Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Remove unnecessary casts throughout stackslib #5624

Merged
merged 3 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions stackslib/src/burnchains/bitcoin/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 3 additions & 8 deletions stackslib/src/burnchains/tests/affirmation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
14 changes: 4 additions & 10 deletions stackslib/src/burnchains/tests/burnchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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 {
Expand Down
26 changes: 13 additions & 13 deletions stackslib/src/burnchains/tests/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down
22 changes: 11 additions & 11 deletions stackslib/src/chainstate/burn/db/sortdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -7459,7 +7459,7 @@ pub mod tests {
0,
0,
0,
i - 1 as u8,
i - 1,
])
};

Expand All @@ -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,
Expand Down Expand Up @@ -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(&[
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand All @@ -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();
Expand Down
Loading