Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix clippy::needless_borrow throughout stackslib #5651

Merged
merged 19 commits into from
Jan 24, 2025
Merged
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
541ec42
Fix clippy::needless_borrow throughout stackslib
jferrant Jan 4, 2025
c3ccfb2
Merge branch 'develop' of https://github.com/stacks-network/stacks-co…
jferrant Jan 9, 2025
e45112a
CRC: cleanup
jferrant Jan 9, 2025
215ed4c
Merge branch 'develop' into fix/clippy-ci-stacks-lib-needless-borrow
jferrant Jan 13, 2025
2d758c6
Merge branch 'develop' of https://github.com/stacks-network/stacks-co…
jferrant Jan 14, 2025
56c69e2
Merge branch 'develop' of https://github.com/stacks-network/stacks-co…
jferrant Jan 17, 2025
45e3409
Merge branch 'develop' into fix/clippy-ci-stacks-lib-needless-borrow
jferrant Jan 18, 2025
9f3033a
Merge branch 'develop' of https://github.com/stacks-network/stacks-co…
jferrant Jan 21, 2025
407d744
Merge branch 'fix/clippy-ci-stacks-lib-needless-borrow' of https://gi…
jferrant Jan 21, 2025
c439560
Merge branch 'develop' into fix/clippy-ci-stacks-lib-needless-borrow
jferrant Jan 21, 2025
489aa27
Merge branch 'develop' of https://github.com/stacks-network/stacks-co…
jferrant Jan 21, 2025
b8a51e3
Fix test
jferrant Jan 22, 2025
6426d8a
Merge branch 'develop' of https://github.com/stacks-network/stacks-co…
jferrant Jan 22, 2025
d96fa87
Merge branch 'develop' into fix/clippy-ci-stacks-lib-needless-borrow
jferrant Jan 22, 2025
d892a89
chore: improved loops
obycode Jan 22, 2025
cd77f5c
Merge branch 'develop' of https://github.com/stacks-network/stacks-co…
jferrant Jan 22, 2025
af9f7ea
Fix last of needless refs in loops
jferrant Jan 22, 2025
7f77a5b
Merge branch 'develop' of https://github.com/stacks-network/stacks-co…
jferrant Jan 23, 2025
399e284
Merge branch 'develop' of https://github.com/stacks-network/stacks-co…
jferrant Jan 23, 2025
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
49 changes: 23 additions & 26 deletions stackslib/src/chainstate/stacks/db/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,8 @@ impl StacksChainState {

/// Get all stacks block headers. Great for testing!
pub fn get_all_staging_block_headers(blocks_conn: &DBConn) -> Result<Vec<StagingBlock>, Error> {
let sql = "SELECT * FROM staging_blocks ORDER BY height".to_string();
query_rows::<StagingBlock, _>(blocks_conn, &sql, NO_PARAMS).map_err(Error::DBError)
let sql = "SELECT * FROM staging_blocks ORDER BY height";
query_rows::<StagingBlock, _>(blocks_conn, sql, NO_PARAMS).map_err(Error::DBError)
}

/// Get a list of all microblocks' hashes, and their anchored blocks' hashes
Expand Down Expand Up @@ -929,7 +929,7 @@ impl StacksChainState {
table: &str,
block_hash: &BlockHeaderHash,
) -> Result<Option<Vec<u8>>, Error> {
let sql = format!("SELECT block_data FROM {} WHERE block_hash = ?1", table);
let sql = format!("SELECT block_data FROM {table} WHERE block_hash = ?1");
let args = [&block_hash];
let mut blobs = StacksChainState::load_block_data_blobs(block_conn, &sql, &args)?;
let len = blobs.len();
Expand Down Expand Up @@ -982,10 +982,10 @@ impl StacksChainState {
consensus_hash: &ConsensusHash,
block_hash: &BlockHeaderHash,
) -> Result<Option<StagingBlock>, Error> {
let sql = "SELECT * FROM staging_blocks WHERE anchored_block_hash = ?1 AND consensus_hash = ?2 AND orphaned = 0 AND processed = 0".to_string();
let sql = "SELECT * FROM staging_blocks WHERE anchored_block_hash = ?1 AND consensus_hash = ?2 AND orphaned = 0 AND processed = 0";
let args = params![block_hash, consensus_hash];
let mut rows =
query_rows::<StagingBlock, _>(block_conn, &sql, args).map_err(Error::DBError)?;
query_rows::<StagingBlock, _>(block_conn, sql, args).map_err(Error::DBError)?;
let len = rows.len();
match len {
0 => Ok(None),
Expand Down Expand Up @@ -1330,22 +1330,18 @@ impl StacksChainState {

let sql = if start_seq == last_seq {
// takes the same arguments as the range case below, but will
"SELECT * FROM staging_microblocks WHERE index_block_hash = ?1 AND sequence == ?2 AND sequence == ?3 AND orphaned = 0 ORDER BY sequence ASC".to_string()
"SELECT * FROM staging_microblocks WHERE index_block_hash = ?1 AND sequence == ?2 AND sequence == ?3 AND orphaned = 0 ORDER BY sequence ASC"
} else {
"SELECT * FROM staging_microblocks WHERE index_block_hash = ?1 AND sequence >= ?2 AND sequence < ?3 AND orphaned = 0 ORDER BY sequence ASC".to_string()
"SELECT * FROM staging_microblocks WHERE index_block_hash = ?1 AND sequence >= ?2 AND sequence < ?3 AND orphaned = 0 ORDER BY sequence ASC"
};

let args = params![parent_index_block_hash, start_seq, last_seq];
let staging_microblocks =
query_rows::<StagingMicroblock, _>(blocks_conn, &sql, args).map_err(Error::DBError)?;
query_rows::<StagingMicroblock, _>(blocks_conn, sql, args).map_err(Error::DBError)?;

if staging_microblocks.is_empty() {
// haven't seen any microblocks that descend from this block yet
test_debug!(
"No microblocks built on {} up to {}",
&parent_index_block_hash,
last_seq
);
test_debug!("No microblocks built on {parent_index_block_hash} up to {last_seq}");
return Ok(None);
}

Expand Down Expand Up @@ -9444,49 +9440,50 @@ pub mod test {
assert_block_stored_not_staging(&mut chainstate, &consensus_hashes[0], blocks[0]);

// process and store blocks 1 and N, as well as microblocks in-between
for (i, block) in blocks.iter().skip(1).enumerate() {
let len = blocks.len();
for i in 1..len {
obycode marked this conversation as resolved.
Show resolved Hide resolved
// this is what happens at the end of append_block()
// store block to staging and process it
assert!(StacksChainState::load_staging_block_data(
chainstate.db(),
&chainstate.blocks_path,
&consensus_hashes[i],
&block.block_hash()
&blocks[i].block_hash()
)
.unwrap()
.is_none());
store_staging_block(
&mut chainstate,
&consensus_hashes[i],
block,
blocks[i],
&consensus_hashes[0],
1,
2,
);
assert_block_staging_not_processed(&mut chainstate, &consensus_hashes[i], block);
assert_block_staging_not_processed(&mut chainstate, &consensus_hashes[i], blocks[i]);

set_block_processed(
&mut chainstate,
&consensus_hashes[i],
&block.block_hash(),
&blocks[i].block_hash(),
true,
);

// set different parts of this stream as confirmed
set_microblocks_processed(
&mut chainstate,
&consensus_hashes[i],
&block.block_hash(),
&block.header.parent_microblock,
&blocks[i].block_hash(),
&blocks[i].header.parent_microblock,
);

assert_block_stored_not_staging(&mut chainstate, &consensus_hashes[i], block);
assert_block_stored_not_staging(&mut chainstate, &consensus_hashes[i], blocks[i]);

let mblocks_confirmed = StacksChainState::load_processed_microblock_stream_fork(
chainstate.db(),
&consensus_hashes[0],
&blocks[0].block_hash(),
&block.header.parent_microblock,
&blocks[i].header.parent_microblock,
)
.unwrap()
.unwrap();
Expand Down Expand Up @@ -9562,24 +9559,24 @@ pub mod test {
}

// store blocks to staging
for (i, block) in blocks.iter().enumerate() {
for i in 0..blocks.len() {
assert!(StacksChainState::load_staging_block_data(
chainstate.db(),
&chainstate.blocks_path,
&consensus_hashes[i],
&block.block_hash()
&blocks[i].block_hash()
)
.unwrap()
.is_none());
store_staging_block(
&mut chainstate,
&consensus_hashes[i],
block,
&blocks[i],
&parent_consensus_hashes[i],
1,
2,
);
assert_block_staging_not_processed(&mut chainstate, &consensus_hashes[i], block);
assert_block_staging_not_processed(&mut chainstate, &consensus_hashes[i], &blocks[i]);
}

// reject block 1
Expand Down
Loading