@@ -757,8 +757,8 @@ impl StacksChainState {
757
757
758
758
/// Get all stacks block headers. Great for testing!
759
759
pub fn get_all_staging_block_headers ( blocks_conn : & DBConn ) -> Result < Vec < StagingBlock > , Error > {
760
- let sql = "SELECT * FROM staging_blocks ORDER BY height" . to_string ( ) ;
761
- query_rows :: < StagingBlock , _ > ( blocks_conn, & sql, NO_PARAMS ) . map_err ( Error :: DBError )
760
+ let sql = "SELECT * FROM staging_blocks ORDER BY height" ;
761
+ query_rows :: < StagingBlock , _ > ( blocks_conn, sql, NO_PARAMS ) . map_err ( Error :: DBError )
762
762
}
763
763
764
764
/// Get a list of all microblocks' hashes, and their anchored blocks' hashes
@@ -929,7 +929,7 @@ impl StacksChainState {
929
929
table : & str ,
930
930
block_hash : & BlockHeaderHash ,
931
931
) -> Result < Option < Vec < u8 > > , Error > {
932
- let sql = format ! ( "SELECT block_data FROM {} WHERE block_hash = ?1" , table ) ;
932
+ let sql = format ! ( "SELECT block_data FROM {table } WHERE block_hash = ?1" ) ;
933
933
let args = [ & block_hash] ;
934
934
let mut blobs = StacksChainState :: load_block_data_blobs ( block_conn, & sql, & args) ?;
935
935
let len = blobs. len ( ) ;
@@ -982,10 +982,10 @@ impl StacksChainState {
982
982
consensus_hash : & ConsensusHash ,
983
983
block_hash : & BlockHeaderHash ,
984
984
) -> Result < Option < StagingBlock > , Error > {
985
- let sql = "SELECT * FROM staging_blocks WHERE anchored_block_hash = ?1 AND consensus_hash = ?2 AND orphaned = 0 AND processed = 0" . to_string ( ) ;
985
+ let sql = "SELECT * FROM staging_blocks WHERE anchored_block_hash = ?1 AND consensus_hash = ?2 AND orphaned = 0 AND processed = 0" ;
986
986
let args = params ! [ block_hash, consensus_hash] ;
987
987
let mut rows =
988
- query_rows :: < StagingBlock , _ > ( block_conn, & sql, args) . map_err ( Error :: DBError ) ?;
988
+ query_rows :: < StagingBlock , _ > ( block_conn, sql, args) . map_err ( Error :: DBError ) ?;
989
989
let len = rows. len ( ) ;
990
990
match len {
991
991
0 => Ok ( None ) ,
@@ -1330,22 +1330,18 @@ impl StacksChainState {
1330
1330
1331
1331
let sql = if start_seq == last_seq {
1332
1332
// takes the same arguments as the range case below, but will
1333
- "SELECT * FROM staging_microblocks WHERE index_block_hash = ?1 AND sequence == ?2 AND sequence == ?3 AND orphaned = 0 ORDER BY sequence ASC" . to_string ( )
1333
+ "SELECT * FROM staging_microblocks WHERE index_block_hash = ?1 AND sequence == ?2 AND sequence == ?3 AND orphaned = 0 ORDER BY sequence ASC"
1334
1334
} else {
1335
- "SELECT * FROM staging_microblocks WHERE index_block_hash = ?1 AND sequence >= ?2 AND sequence < ?3 AND orphaned = 0 ORDER BY sequence ASC" . to_string ( )
1335
+ "SELECT * FROM staging_microblocks WHERE index_block_hash = ?1 AND sequence >= ?2 AND sequence < ?3 AND orphaned = 0 ORDER BY sequence ASC"
1336
1336
} ;
1337
1337
1338
1338
let args = params ! [ parent_index_block_hash, start_seq, last_seq] ;
1339
1339
let staging_microblocks =
1340
- query_rows :: < StagingMicroblock , _ > ( blocks_conn, & sql, args) . map_err ( Error :: DBError ) ?;
1340
+ query_rows :: < StagingMicroblock , _ > ( blocks_conn, sql, args) . map_err ( Error :: DBError ) ?;
1341
1341
1342
1342
if staging_microblocks. is_empty ( ) {
1343
1343
// haven't seen any microblocks that descend from this block yet
1344
- test_debug ! (
1345
- "No microblocks built on {} up to {}" ,
1346
- & parent_index_block_hash,
1347
- last_seq
1348
- ) ;
1344
+ test_debug ! ( "No microblocks built on {parent_index_block_hash} up to {last_seq}" ) ;
1349
1345
return Ok ( None ) ;
1350
1346
}
1351
1347
@@ -9444,49 +9440,50 @@ pub mod test {
9444
9440
assert_block_stored_not_staging ( & mut chainstate, & consensus_hashes[ 0 ] , blocks[ 0 ] ) ;
9445
9441
9446
9442
// process and store blocks 1 and N, as well as microblocks in-between
9447
- for ( i, block) in blocks. iter ( ) . skip ( 1 ) . enumerate ( ) {
9443
+ let len = blocks. len ( ) ;
9444
+ for i in 1 ..len {
9448
9445
// this is what happens at the end of append_block()
9449
9446
// store block to staging and process it
9450
9447
assert ! ( StacksChainState :: load_staging_block_data(
9451
9448
chainstate. db( ) ,
9452
9449
& chainstate. blocks_path,
9453
9450
& consensus_hashes[ i] ,
9454
- & block . block_hash( )
9451
+ & blocks [ i ] . block_hash( )
9455
9452
)
9456
9453
. unwrap( )
9457
9454
. is_none( ) ) ;
9458
9455
store_staging_block (
9459
9456
& mut chainstate,
9460
9457
& consensus_hashes[ i] ,
9461
- block ,
9458
+ blocks [ i ] ,
9462
9459
& consensus_hashes[ 0 ] ,
9463
9460
1 ,
9464
9461
2 ,
9465
9462
) ;
9466
- assert_block_staging_not_processed ( & mut chainstate, & consensus_hashes[ i] , block ) ;
9463
+ assert_block_staging_not_processed ( & mut chainstate, & consensus_hashes[ i] , blocks [ i ] ) ;
9467
9464
9468
9465
set_block_processed (
9469
9466
& mut chainstate,
9470
9467
& consensus_hashes[ i] ,
9471
- & block . block_hash ( ) ,
9468
+ & blocks [ i ] . block_hash ( ) ,
9472
9469
true ,
9473
9470
) ;
9474
9471
9475
9472
// set different parts of this stream as confirmed
9476
9473
set_microblocks_processed (
9477
9474
& mut chainstate,
9478
9475
& consensus_hashes[ i] ,
9479
- & block . block_hash ( ) ,
9480
- & block . header . parent_microblock ,
9476
+ & blocks [ i ] . block_hash ( ) ,
9477
+ & blocks [ i ] . header . parent_microblock ,
9481
9478
) ;
9482
9479
9483
- assert_block_stored_not_staging ( & mut chainstate, & consensus_hashes[ i] , block ) ;
9480
+ assert_block_stored_not_staging ( & mut chainstate, & consensus_hashes[ i] , blocks [ i ] ) ;
9484
9481
9485
9482
let mblocks_confirmed = StacksChainState :: load_processed_microblock_stream_fork (
9486
9483
chainstate. db ( ) ,
9487
9484
& consensus_hashes[ 0 ] ,
9488
9485
& blocks[ 0 ] . block_hash ( ) ,
9489
- & block . header . parent_microblock ,
9486
+ & blocks [ i ] . header . parent_microblock ,
9490
9487
)
9491
9488
. unwrap ( )
9492
9489
. unwrap ( ) ;
@@ -9562,24 +9559,24 @@ pub mod test {
9562
9559
}
9563
9560
9564
9561
// store blocks to staging
9565
- for ( i , block ) in blocks . iter ( ) . enumerate ( ) {
9562
+ for i in 0 ..blocks . len ( ) {
9566
9563
assert ! ( StacksChainState :: load_staging_block_data(
9567
9564
chainstate. db( ) ,
9568
9565
& chainstate. blocks_path,
9569
9566
& consensus_hashes[ i] ,
9570
- & block . block_hash( )
9567
+ & blocks [ i ] . block_hash( )
9571
9568
)
9572
9569
. unwrap( )
9573
9570
. is_none( ) ) ;
9574
9571
store_staging_block (
9575
9572
& mut chainstate,
9576
9573
& consensus_hashes[ i] ,
9577
- block ,
9574
+ & blocks [ i ] ,
9578
9575
& parent_consensus_hashes[ i] ,
9579
9576
1 ,
9580
9577
2 ,
9581
9578
) ;
9582
- assert_block_staging_not_processed ( & mut chainstate, & consensus_hashes[ i] , block ) ;
9579
+ assert_block_staging_not_processed ( & mut chainstate, & consensus_hashes[ i] , & blocks [ i ] ) ;
9583
9580
}
9584
9581
9585
9582
// reject block 1
0 commit comments