Skip to content

Commit d892a89

Browse files
committed
chore: improved loops
1 parent d96fa87 commit d892a89

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

stackslib/src/chainstate/stacks/db/blocks.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9440,50 +9440,49 @@ pub mod test {
94409440
assert_block_stored_not_staging(&mut chainstate, &consensus_hashes[0], blocks[0]);
94419441

94429442
// process and store blocks 1 and N, as well as microblocks in-between
9443-
let len = blocks.len();
9444-
for i in 1..len {
9443+
for (i, block) in blocks.iter().enumerate().skip(1) {
94459444
// this is what happens at the end of append_block()
94469445
// store block to staging and process it
94479446
assert!(StacksChainState::load_staging_block_data(
94489447
chainstate.db(),
94499448
&chainstate.blocks_path,
94509449
&consensus_hashes[i],
9451-
&blocks[i].block_hash()
9450+
&block.block_hash()
94529451
)
94539452
.unwrap()
94549453
.is_none());
94559454
store_staging_block(
94569455
&mut chainstate,
94579456
&consensus_hashes[i],
9458-
blocks[i],
9457+
block,
94599458
&consensus_hashes[0],
94609459
1,
94619460
2,
94629461
);
9463-
assert_block_staging_not_processed(&mut chainstate, &consensus_hashes[i], blocks[i]);
9462+
assert_block_staging_not_processed(&mut chainstate, &consensus_hashes[i], block);
94649463

94659464
set_block_processed(
94669465
&mut chainstate,
94679466
&consensus_hashes[i],
9468-
&blocks[i].block_hash(),
9467+
&block.block_hash(),
94699468
true,
94709469
);
94719470

94729471
// set different parts of this stream as confirmed
94739472
set_microblocks_processed(
94749473
&mut chainstate,
94759474
&consensus_hashes[i],
9476-
&blocks[i].block_hash(),
9477-
&blocks[i].header.parent_microblock,
9475+
&block.block_hash(),
9476+
&block.header.parent_microblock,
94789477
);
94799478

9480-
assert_block_stored_not_staging(&mut chainstate, &consensus_hashes[i], blocks[i]);
9479+
assert_block_stored_not_staging(&mut chainstate, &consensus_hashes[i], block);
94819480

94829481
let mblocks_confirmed = StacksChainState::load_processed_microblock_stream_fork(
94839482
chainstate.db(),
94849483
&consensus_hashes[0],
94859484
&blocks[0].block_hash(),
9486-
&blocks[i].header.parent_microblock,
9485+
&block.header.parent_microblock,
94879486
)
94889487
.unwrap()
94899488
.unwrap();
@@ -9559,24 +9558,24 @@ pub mod test {
95599558
}
95609559

95619560
// store blocks to staging
9562-
for i in 0..blocks.len() {
9561+
for (i, block) in blocks.iter().enumerate() {
95639562
assert!(StacksChainState::load_staging_block_data(
95649563
chainstate.db(),
95659564
&chainstate.blocks_path,
95669565
&consensus_hashes[i],
9567-
&blocks[i].block_hash()
9566+
&block.block_hash()
95689567
)
95699568
.unwrap()
95709569
.is_none());
95719570
store_staging_block(
95729571
&mut chainstate,
95739572
&consensus_hashes[i],
9574-
&blocks[i],
9573+
&block,
95759574
&parent_consensus_hashes[i],
95769575
1,
95779576
2,
95789577
);
9579-
assert_block_staging_not_processed(&mut chainstate, &consensus_hashes[i], &blocks[i]);
9578+
assert_block_staging_not_processed(&mut chainstate, &consensus_hashes[i], &block);
95809579
}
95819580

95829581
// reject block 1
@@ -9588,16 +9587,16 @@ pub mod test {
95889587
);
95899588

95909589
// destroy all descendants
9591-
for i in 0..blocks.len() {
9590+
for (i, block) in blocks.iter().enumerate() {
95929591
// confirm that block i is deleted, as are its microblocks
9593-
assert_block_stored_rejected(&mut chainstate, &consensus_hashes[i], &blocks[i]);
9592+
assert_block_stored_rejected(&mut chainstate, &consensus_hashes[i], block);
95949593

95959594
// block i's microblocks should all be marked as processed, orphaned, and deleted
9596-
for mblock in microblocks[i].iter() {
9595+
for mblock in &microblocks[i] {
95979596
assert!(StacksChainState::load_staging_microblock(
95989597
chainstate.db(),
95999598
&consensus_hashes[i],
9600-
&blocks[i].block_hash(),
9599+
&block.block_hash(),
96019600
&mblock.block_hash()
96029601
)
96039602
.unwrap()
@@ -9611,30 +9610,31 @@ pub mod test {
96119610
.is_none());
96129611
}
96139612

9614-
if i + 1 < blocks.len() {
9613+
// Check block i+1 if it exists
9614+
if let Some(next_block) = blocks.get(i + 1) {
96159615
// block i+1 should be marked as an orphan, but its data should still be there
96169616
assert!(StacksChainState::load_staging_block(
96179617
chainstate.db(),
96189618
&chainstate.blocks_path,
96199619
&consensus_hashes[i + 1],
9620-
&blocks[i + 1].block_hash()
9620+
&next_block.block_hash()
96219621
)
96229622
.unwrap()
96239623
.is_none());
96249624
assert!(!StacksChainState::load_block_bytes(
96259625
&chainstate.blocks_path,
96269626
&consensus_hashes[i + 1],
9627-
&blocks[i + 1].block_hash()
9627+
&next_block.block_hash()
96289628
)
96299629
.unwrap()
96309630
.unwrap()
96319631
.is_empty());
96329632

9633-
for mblock in microblocks[i + 1].iter() {
9633+
for mblock in &microblocks[i + 1] {
96349634
let staging_mblock = StacksChainState::load_staging_microblock(
96359635
chainstate.db(),
96369636
&consensus_hashes[i + 1],
9637-
&blocks[i + 1].block_hash(),
9637+
&next_block.block_hash(),
96389638
&mblock.block_hash(),
96399639
)
96409640
.unwrap()

0 commit comments

Comments
 (0)