Skip to content

Commit 78cadb5

Browse files
committed
Fix collapsible_if and collapsible_match
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent c8e2130 commit 78cadb5

File tree

15 files changed

+590
-652
lines changed

15 files changed

+590
-652
lines changed

stackslib/src/burnchains/bitcoin/address.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,10 +591,10 @@ impl BitcoinAddress {
591591
} else {
592592
BitcoinNetworkType::Testnet
593593
};
594-
if let Some(addr) = BitcoinAddress::from_scriptpubkey(network_id, scriptpubkey) {
595-
if let BitcoinAddress::Segwit(sw) = addr {
596-
return Some(BitcoinAddress::Segwit(sw));
597-
}
594+
if let Some(BitcoinAddress::Segwit(sw)) =
595+
BitcoinAddress::from_scriptpubkey(network_id, scriptpubkey)
596+
{
597+
return Some(BitcoinAddress::Segwit(sw));
598598
}
599599
return None;
600600
}

stackslib/src/burnchains/bitcoin/indexer.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -503,13 +503,11 @@ impl BitcoinIndexer {
503503
start_block: u64,
504504
remove_old: bool,
505505
) -> Result<SpvClient, btc_error> {
506-
if remove_old {
507-
if PathBuf::from(&reorg_headers_path).exists() {
508-
fs::remove_file(&reorg_headers_path).map_err(|e| {
509-
error!("Failed to remove {}", reorg_headers_path);
510-
btc_error::Io(e)
511-
})?;
512-
}
506+
if remove_old && PathBuf::from(&reorg_headers_path).exists() {
507+
fs::remove_file(&reorg_headers_path).map_err(|e| {
508+
error!("Failed to remove {}", reorg_headers_path);
509+
btc_error::Io(e)
510+
})?;
513511
}
514512

515513
// bootstrap reorg client

stackslib/src/chainstate/burn/db/sortdb.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5774,10 +5774,9 @@ impl<'a> SortitionHandleTx<'a> {
57745774
.map(|parent_commit_sn| parent_commit_sn.sortition_id)
57755775
.unwrap_or(SortitionId([0x00; 32]));
57765776

5777-
if !cfg!(test) {
5778-
if block_commit.parent_block_ptr != 0 || block_commit.parent_vtxindex != 0 {
5779-
assert!(parent_sortition_id != SortitionId([0x00; 32]));
5780-
}
5777+
if !cfg!(test) && (block_commit.parent_block_ptr != 0 || block_commit.parent_vtxindex != 0)
5778+
{
5779+
assert!(parent_sortition_id != SortitionId([0x00; 32]));
57815780
}
57825781

57835782
let args = params![

stackslib/src/chainstate/burn/operations/leader_block_commit.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,9 @@ impl LeaderBlockCommitOp {
313313
})?;
314314

315315
// basic sanity checks
316-
if data.parent_block_ptr == 0 {
317-
if data.parent_vtxindex != 0 {
318-
warn!("Invalid tx: parent block back-pointer must be positive");
319-
return Err(op_error::ParseError);
320-
}
316+
if data.parent_block_ptr == 0 && data.parent_vtxindex != 0 {
317+
warn!("Invalid tx: parent block back-pointer must be positive");
318+
return Err(op_error::ParseError);
321319
// if parent block ptr and parent vtxindex are both 0, then this block's parent is
322320
// the genesis block.
323321
}

stackslib/src/chainstate/coordinator/mod.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,11 @@ impl<'a, T: BlockEventDispatcher> RewardSetProvider for OnChainRewardSetProvider
373373
cur_epoch,
374374
)?;
375375

376-
if is_nakamoto_reward_set {
377-
if reward_set.signers.is_none() || reward_set.signers == Some(vec![]) {
378-
error!("FATAL: Signer sets are empty in a reward set that will be used in nakamoto"; "reward_set" => ?reward_set);
379-
return Err(Error::PoXAnchorBlockRequired);
380-
}
376+
if is_nakamoto_reward_set
377+
&& (reward_set.signers.is_none() || reward_set.signers == Some(vec![]))
378+
{
379+
error!("FATAL: Signer sets are empty in a reward set that will be used in nakamoto"; "reward_set" => ?reward_set);
380+
return Err(Error::PoXAnchorBlockRequired);
381381
}
382382

383383
Ok(reward_set)
@@ -1398,21 +1398,20 @@ impl<
13981398
}
13991399
};
14001400

1401-
if sortition_changed_reward_cycle_opt.is_none() {
1402-
if sortition_tip_affirmation_map.len() >= heaviest_am.len()
1403-
&& sortition_tip_affirmation_map.len() <= canonical_affirmation_map.len()
1401+
if sortition_changed_reward_cycle_opt.is_none()
1402+
&& sortition_tip_affirmation_map.len() >= heaviest_am.len()
1403+
&& sortition_tip_affirmation_map.len() <= canonical_affirmation_map.len()
1404+
{
1405+
if let Some(divergence_rc) =
1406+
canonical_affirmation_map.find_divergence(&sortition_tip_affirmation_map)
14041407
{
1405-
if let Some(divergence_rc) =
1406-
canonical_affirmation_map.find_divergence(&sortition_tip_affirmation_map)
1407-
{
1408-
if divergence_rc + 1 >= (heaviest_am.len() as u64) {
1409-
// this can arise if there are unaffirmed PoX anchor blocks that are not
1410-
// reflected in the sortiiton affirmation map
1411-
debug!("Update sortition-changed reward cycle to {} from canonical affirmation map `{}` (sortition AM is `{}`)",
1412-
divergence_rc, &canonical_affirmation_map, &sortition_tip_affirmation_map);
1408+
if divergence_rc + 1 >= (heaviest_am.len() as u64) {
1409+
// this can arise if there are unaffirmed PoX anchor blocks that are not
1410+
// reflected in the sortiiton affirmation map
1411+
debug!("Update sortition-changed reward cycle to {} from canonical affirmation map `{}` (sortition AM is `{}`)",
1412+
divergence_rc, &canonical_affirmation_map, &sortition_tip_affirmation_map);
14131413

1414-
sortition_changed_reward_cycle_opt = Some(divergence_rc);
1415-
}
1414+
sortition_changed_reward_cycle_opt = Some(divergence_rc);
14161415
}
14171416
}
14181417
}

stackslib/src/chainstate/nakamoto/miner.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -572,20 +572,18 @@ impl NakamotoBlockBuilder {
572572
);
573573
let mut remaining_limit = block_limit.clone();
574574
let cost_so_far = tenure_tx.cost_so_far();
575-
if remaining_limit.sub(&cost_so_far).is_ok() {
576-
if remaining_limit.divide(100).is_ok() {
577-
remaining_limit.multiply(percentage.into()).expect(
578-
"BUG: failed to multiply by {percentage} when previously divided by 100",
579-
);
580-
remaining_limit.add(&cost_so_far).expect("BUG: unexpected overflow when adding cost_so_far, which was previously checked");
581-
debug!(
582-
"Setting soft limit for clarity cost to {percentage}% of remaining block limit";
583-
"remaining_limit" => %remaining_limit,
584-
"cost_so_far" => %cost_so_far,
585-
"block_limit" => %block_limit,
586-
);
587-
soft_limit = Some(remaining_limit);
588-
}
575+
if remaining_limit.sub(&cost_so_far).is_ok() && remaining_limit.divide(100).is_ok() {
576+
remaining_limit.multiply(percentage.into()).expect(
577+
"BUG: failed to multiply by {percentage} when previously divided by 100",
578+
);
579+
remaining_limit.add(&cost_so_far).expect("BUG: unexpected overflow when adding cost_so_far, which was previously checked");
580+
debug!(
581+
"Setting soft limit for clarity cost to {percentage}% of remaining block limit";
582+
"remaining_limit" => %remaining_limit,
583+
"cost_so_far" => %cost_so_far,
584+
"block_limit" => %block_limit,
585+
);
586+
soft_limit = Some(remaining_limit);
589587
};
590588
}
591589

stackslib/src/chainstate/nakamoto/mod.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4179,17 +4179,15 @@ impl NakamotoChainState {
41794179
"Bitvec does not match the block commit's PoX handling".into(),
41804180
));
41814181
}
4182-
} else if all_0 {
4183-
if treated_addr.is_reward() {
4184-
warn!(
4185-
"Invalid Nakamoto block: rewarded PoX address when bitvec contained 0s for the address";
4186-
"reward_address" => %treated_addr.deref(),
4187-
"bitvec_values" => ?bitvec_values,
4188-
);
4189-
return Err(ChainstateError::InvalidStacksBlock(
4190-
"Bitvec does not match the block commit's PoX handling".into(),
4191-
));
4192-
}
4182+
} else if all_0 && treated_addr.is_reward() {
4183+
warn!(
4184+
"Invalid Nakamoto block: rewarded PoX address when bitvec contained 0s for the address";
4185+
"reward_address" => %treated_addr.deref(),
4186+
"bitvec_values" => ?bitvec_values,
4187+
);
4188+
return Err(ChainstateError::InvalidStacksBlock(
4189+
"Bitvec does not match the block commit's PoX handling".into(),
4190+
));
41934191
}
41944192
}
41954193

stackslib/src/chainstate/stacks/auth.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,12 +1407,10 @@ impl TransactionAuth {
14071407
};
14081408
origin_supported && sponsor_supported
14091409
}
1410-
TransactionAuth::Standard(ref origin) => match origin {
1411-
TransactionSpendingCondition::OrderIndependentMultisig(..) => {
1412-
epoch_id >= StacksEpochId::Epoch30
1413-
}
1414-
_ => true,
1415-
},
1410+
TransactionAuth::Standard(TransactionSpendingCondition::OrderIndependentMultisig(
1411+
..,
1412+
)) => epoch_id >= StacksEpochId::Epoch30,
1413+
_ => true,
14161414
}
14171415
}
14181416
}

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

Lines changed: 57 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -883,12 +883,10 @@ impl StacksChainState {
883883

884884
/// Closure for defaulting to an empty microblock stream if a microblock stream file is not found
885885
fn empty_stream(e: Error) -> Result<Option<Vec<StacksMicroblock>>, Error> {
886-
match e {
887-
Error::DBError(ref dbe) => match dbe {
888-
db_error::NotFoundError => Ok(Some(vec![])),
889-
_ => Err(e),
890-
},
891-
_ => Err(e),
886+
if matches!(e, Error::DBError(db_error::NotFoundError)) {
887+
Ok(Some(vec![]))
888+
} else {
889+
Err(e)
892890
}
893891
}
894892

@@ -1209,17 +1207,17 @@ impl StacksChainState {
12091207
}
12101208
};
12111209

1212-
if processed_only {
1213-
if !StacksChainState::has_processed_microblocks_indexed(
1210+
if processed_only
1211+
&& !StacksChainState::has_processed_microblocks_indexed(
12141212
blocks_conn,
12151213
&StacksBlockHeader::make_index_block_hash(
12161214
parent_consensus_hash,
12171215
&microblock.block_hash(),
12181216
),
1219-
)? {
1220-
debug!("Microblock {} is not processed", &microblock.block_hash());
1221-
return Ok(None);
1222-
}
1217+
)?
1218+
{
1219+
debug!("Microblock {} is not processed", &microblock.block_hash());
1220+
return Ok(None);
12231221
}
12241222

12251223
debug!(
@@ -3287,17 +3285,16 @@ impl StacksChainState {
32873285
blocks_conn,
32883286
&parent_stacks_chain_tip.consensus_hash,
32893287
&parent_stacks_chain_tip.winning_stacks_block_hash,
3290-
)? {
3291-
if block.has_microblock_parent() {
3292-
warn!(
3293-
"Invalid block {}/{}: its parent {}/{} crossed the epoch boundary but this block confirmed its microblocks",
3294-
&consensus_hash,
3295-
&block.block_hash(),
3296-
&parent_stacks_chain_tip.consensus_hash,
3297-
&parent_stacks_chain_tip.winning_stacks_block_hash
3298-
);
3299-
return Ok(None);
3300-
}
3288+
)? && block.has_microblock_parent()
3289+
{
3290+
warn!(
3291+
"Invalid block {}/{}: its parent {}/{} crossed the epoch boundary but this block confirmed its microblocks",
3292+
&consensus_hash,
3293+
&block.block_hash(),
3294+
&parent_stacks_chain_tip.consensus_hash,
3295+
&parent_stacks_chain_tip.winning_stacks_block_hash
3296+
);
3297+
return Ok(None);
33013298
}
33023299

33033300
let sortition_burns = SortitionDB::get_block_burn_amount(db_handle, &burn_chain_tip)
@@ -6095,34 +6092,33 @@ impl StacksChainState {
60956092
SortitionDB::are_microblocks_disabled(sort_tx.tx(), u64::from(burn_header_height))?;
60966093

60976094
// microblocks are not allowed after Epoch 2.5 starts
6098-
if microblocks_disabled_by_epoch_25 {
6099-
if next_staging_block.parent_microblock_seq != 0
6100-
|| next_staging_block.parent_microblock_hash != BlockHeaderHash([0; 32])
6101-
{
6102-
let msg = format!(
6103-
"Invalid stacks block {}/{} ({}). Confirms microblocks after Epoch 2.5 start.",
6095+
if microblocks_disabled_by_epoch_25
6096+
&& (next_staging_block.parent_microblock_seq != 0
6097+
|| next_staging_block.parent_microblock_hash != BlockHeaderHash([0; 32]))
6098+
{
6099+
let msg = format!(
6100+
"Invalid stacks block {}/{} ({}). Confirms microblocks after Epoch 2.5 start.",
6101+
&next_staging_block.consensus_hash,
6102+
&next_staging_block.anchored_block_hash,
6103+
&StacksBlockId::new(
61046104
&next_staging_block.consensus_hash,
6105-
&next_staging_block.anchored_block_hash,
6106-
&StacksBlockId::new(
6107-
&next_staging_block.consensus_hash,
6108-
&next_staging_block.anchored_block_hash
6109-
),
6110-
);
6111-
warn!("{msg}");
6105+
&next_staging_block.anchored_block_hash
6106+
),
6107+
);
6108+
warn!("{msg}");
61126109

6113-
// clear out
6114-
StacksChainState::set_block_processed(
6115-
chainstate_tx.deref_mut(),
6116-
None,
6117-
&blocks_path,
6118-
&next_staging_block.consensus_hash,
6119-
&next_staging_block.anchored_block_hash,
6120-
false,
6121-
)?;
6122-
chainstate_tx.commit().map_err(Error::DBError)?;
6110+
// clear out
6111+
StacksChainState::set_block_processed(
6112+
chainstate_tx.deref_mut(),
6113+
None,
6114+
&blocks_path,
6115+
&next_staging_block.consensus_hash,
6116+
&next_staging_block.anchored_block_hash,
6117+
false,
6118+
)?;
6119+
chainstate_tx.commit().map_err(Error::DBError)?;
61236120

6124-
return Err(Error::InvalidStacksBlock(msg));
6125-
}
6121+
return Err(Error::InvalidStacksBlock(msg));
61266122
}
61276123

61286124
debug!(
@@ -6812,24 +6808,24 @@ impl StacksChainState {
68126808
}
68136809

68146810
// if the payer for the tx is different from owner, check if they can afford fee
6815-
if origin != payer {
6816-
if !payer.stx_balance.can_transfer_at_burn_block(
6811+
if origin != payer
6812+
&& !payer.stx_balance.can_transfer_at_burn_block(
68176813
u128::from(fee),
68186814
block_height,
68196815
v1_unlock_height,
68206816
v2_unlock_height,
68216817
v3_unlock_height,
6822-
)? {
6823-
return Err(MemPoolRejection::NotEnoughFunds(
6824-
u128::from(fee),
6825-
payer.stx_balance.get_available_balance_at_burn_block(
6826-
block_height,
6827-
v1_unlock_height,
6828-
v2_unlock_height,
6829-
v3_unlock_height,
6830-
)?,
6831-
));
6832-
}
6818+
)?
6819+
{
6820+
return Err(MemPoolRejection::NotEnoughFunds(
6821+
u128::from(fee),
6822+
payer.stx_balance.get_available_balance_at_burn_block(
6823+
block_height,
6824+
v1_unlock_height,
6825+
v2_unlock_height,
6826+
v3_unlock_height,
6827+
)?,
6828+
));
68336829
}
68346830
}
68356831
TransactionPayload::ContractCall(TransactionContractCall {

stackslib/src/chainstate/stacks/index/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,7 @@ impl error::Error for Error {
333333
Error::IOError(ref e) => Some(e),
334334
Error::SQLError(ref e) => Some(e),
335335
Error::RestoreMarfBlockError(ref e) => Some(e),
336-
Error::BlockHashMapCorruptionError(ref opt_e) => match opt_e {
337-
Some(ref e) => Some(e),
338-
None => None,
339-
},
336+
Error::BlockHashMapCorruptionError(Some(ref e)) => Some(e),
340337
_ => None,
341338
}
342339
}

0 commit comments

Comments
 (0)