Skip to content

Commit

Permalink
chore: Apply Clippy lint single_match
Browse files Browse the repository at this point in the history
  • Loading branch information
jbencin committed Jan 23, 2025
1 parent 2f2cb53 commit da64cec
Show file tree
Hide file tree
Showing 41 changed files with 663 additions and 1,033 deletions.
21 changes: 6 additions & 15 deletions stackslib/src/burnchains/bitcoin/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,23 +282,17 @@ impl BitcoinIndexer {
btc_error::ConnectionError
})?;

match self.runtime.sock.take() {
Some(s) => {
let _ = s.shutdown(Shutdown::Both);
}
None => {}
if let Some(s) = self.runtime.sock.take() {
let _ = s.shutdown(Shutdown::Both);
}

self.runtime.sock = Some(s);
Ok(())
}
Err(_e) => {
let s = self.runtime.sock.take();
match s {
Some(s) => {
let _ = s.shutdown(Shutdown::Both);
}
None => {}
if let Some(s) = s {
let _ = s.shutdown(Shutdown::Both);
}
Err(btc_error::ConnectionError)
}
Expand Down Expand Up @@ -932,11 +926,8 @@ impl BitcoinIndexer {

impl Drop for BitcoinIndexer {
fn drop(&mut self) {
match self.runtime.sock {
Some(ref mut s) => {
let _ = s.shutdown(Shutdown::Both);
}
None => {}
if let Some(ref mut s) = self.runtime.sock {
let _ = s.shutdown(Shutdown::Both);
}
}
}
Expand Down
9 changes: 3 additions & 6 deletions stackslib/src/burnchains/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,12 +580,9 @@ impl TestBurnchainBlock {
assert_eq!(parent_snapshot.block_height + 1, self.block_height);

for i in 0..self.txs.len() {
match self.txs[i] {
BlockstackOperationType::LeaderKeyRegister(ref mut data) => {
assert_eq!(data.block_height, self.block_height);
data.consensus_hash = parent_snapshot.consensus_hash.clone();
}
_ => {}
if let BlockstackOperationType::LeaderKeyRegister(ref mut data) = self.txs[i] {
assert_eq!(data.block_height, self.block_height);
data.consensus_hash = parent_snapshot.consensus_hash.clone();
}
}
}
Expand Down
57 changes: 24 additions & 33 deletions stackslib/src/chainstate/stacks/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,16 +353,13 @@ impl StacksMessageCodec for StacksBlock {
// must be only one coinbase
let mut coinbase_count = 0;
for tx in txs.iter() {
match tx.payload {
TransactionPayload::Coinbase(..) => {
coinbase_count += 1;
if coinbase_count > 1 {
return Err(codec_error::DeserializeError(
"Invalid block: multiple coinbases found".to_string(),
));
}
if let TransactionPayload::Coinbase(..) = tx.payload {
coinbase_count += 1;
if coinbase_count > 1 {
return Err(codec_error::DeserializeError(
"Invalid block: multiple coinbases found".to_string(),
));
}
_ => {}
}
}

Expand Down Expand Up @@ -518,26 +515,23 @@ impl StacksBlock {
let mut found_coinbase = false;
let mut coinbase_index = 0;
for (i, tx) in txs.iter().enumerate() {
match tx.payload {
TransactionPayload::Coinbase(..) => {
if !check_present {
warn!("Found unexpected coinbase tx {}", tx.txid());
return false;
}

if found_coinbase {
warn!("Found duplicate coinbase tx {}", tx.txid());
return false;
}

if tx.anchor_mode != TransactionAnchorMode::OnChainOnly {
warn!("Invalid coinbase tx {}: not on-chain only", tx.txid());
return false;
}
found_coinbase = true;
coinbase_index = i;
if let TransactionPayload::Coinbase(..) = tx.payload {
if !check_present {
warn!("Found unexpected coinbase tx {}", tx.txid());
return false;
}

if found_coinbase {
warn!("Found duplicate coinbase tx {}", tx.txid());
return false;
}
_ => {}

if tx.anchor_mode != TransactionAnchorMode::OnChainOnly {
warn!("Invalid coinbase tx {}: not on-chain only", tx.txid());
return false;
}
found_coinbase = true;
coinbase_index = i;
}
}

Expand Down Expand Up @@ -1150,11 +1144,8 @@ mod test {
let mut txs_anchored = vec![];

for tx in all_txs.iter() {
match tx.payload {
TransactionPayload::Coinbase(..) => {
continue;
}
_ => {}
if let TransactionPayload::Coinbase(..) = tx.payload {
continue;
}
txs_anchored.push(tx);
}
Expand Down
29 changes: 13 additions & 16 deletions stackslib/src/chainstate/stacks/boot/pox_2_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1371,23 +1371,20 @@ fn test_simple_pox_2_auto_unlock(alice_first: bool) {
coinbase_txs.push(r);
continue;
}
match r.transaction {
TransactionOrigin::Stacks(ref t) => {
let addr = t.auth.origin().address_testnet();
eprintln!("TX addr: {}", addr);
if addr == alice_address {
alice_txs.insert(t.auth.get_origin_nonce(), r);
} else if addr == bob_address {
bob_txs.insert(t.auth.get_origin_nonce(), r);
} else if addr == charlie_address {
assert!(
r.execution_cost != ExecutionCost::ZERO,
"Execution cost is not zero!"
);
charlie_txs.insert(t.auth.get_origin_nonce(), r);
}
if let TransactionOrigin::Stacks(ref t) = r.transaction {
let addr = t.auth.origin().address_testnet();
eprintln!("TX addr: {}", addr);
if addr == alice_address {
alice_txs.insert(t.auth.get_origin_nonce(), r);
} else if addr == bob_address {
bob_txs.insert(t.auth.get_origin_nonce(), r);
} else if addr == charlie_address {
assert!(
r.execution_cost != ExecutionCost::ZERO,
"Execution cost is not zero!"
);
charlie_txs.insert(t.auth.get_origin_nonce(), r);
}
_ => {}
}
}
}
Expand Down
15 changes: 6 additions & 9 deletions stackslib/src/chainstate/stacks/boot/pox_3_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -930,16 +930,13 @@ fn pox_auto_unlock(alice_first: bool) {
coinbase_txs.push(r);
continue;
}
match r.transaction {
TransactionOrigin::Stacks(ref t) => {
let addr = t.auth.origin().address_testnet();
if addr == alice_address {
alice_txs.insert(t.auth.get_origin_nonce(), r);
} else if addr == bob_address {
bob_txs.insert(t.auth.get_origin_nonce(), r);
}
if let TransactionOrigin::Stacks(ref t) = r.transaction {
let addr = t.auth.origin().address_testnet();
if addr == alice_address {
alice_txs.insert(t.auth.get_origin_nonce(), r);
} else if addr == bob_address {
bob_txs.insert(t.auth.get_origin_nonce(), r);
}
_ => {}
}
}
}
Expand Down
15 changes: 6 additions & 9 deletions stackslib/src/chainstate/stacks/boot/pox_4_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9184,16 +9184,13 @@ fn missed_slots_no_unlock() {
coinbase_txs.push(r);
continue;
}
match r.transaction {
TransactionOrigin::Stacks(ref t) => {
let addr = t.auth.origin().address_testnet();
if addr == alice_address {
alice_txs.insert(t.auth.get_origin_nonce(), r);
} else if addr == bob_address {
bob_txs.insert(t.auth.get_origin_nonce(), r);
}
if let TransactionOrigin::Stacks(ref t) = r.transaction {
let addr = t.auth.origin().address_testnet();
if addr == alice_address {
alice_txs.insert(t.auth.get_origin_nonce(), r);
} else if addr == bob_address {
bob_txs.insert(t.auth.get_origin_nonce(), r);
}
_ => {}
}
}
}
Expand Down
30 changes: 12 additions & 18 deletions stackslib/src/chainstate/stacks/db/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11206,15 +11206,12 @@ pub mod test {

let (_, burn_header_hash, consensus_hash) = peer.next_burnchain_block(burn_ops.clone());

match (stacks_block_opt, microblocks_opt) {
(Some(stacks_block), Some(microblocks)) => {
peer.process_stacks_epoch_at_tip(&stacks_block, &microblocks);
last_block_id = StacksBlockHeader::make_index_block_hash(
&consensus_hash,
&stacks_block.block_hash(),
);
}
_ => {}
if let (Some(stacks_block), Some(microblocks)) = (stacks_block_opt, microblocks_opt) {
peer.process_stacks_epoch_at_tip(&stacks_block, &microblocks);
last_block_id = StacksBlockHeader::make_index_block_hash(
&consensus_hash,
&stacks_block.block_hash(),
);
}

let tip =
Expand Down Expand Up @@ -11889,15 +11886,12 @@ pub mod test {

let (_, burn_header_hash, consensus_hash) = peer.next_burnchain_block(burn_ops.clone());

match (stacks_block_opt, microblocks_opt) {
(Some(stacks_block), Some(microblocks)) => {
peer.process_stacks_epoch_at_tip(&stacks_block, &microblocks);
last_block_id = StacksBlockHeader::make_index_block_hash(
&consensus_hash,
&stacks_block.block_hash(),
);
}
_ => {}
if let (Some(stacks_block), Some(microblocks)) = (stacks_block_opt, microblocks_opt) {
peer.process_stacks_epoch_at_tip(&stacks_block, &microblocks);
last_block_id = StacksBlockHeader::make_index_block_hash(
&consensus_hash,
&stacks_block.block_hash(),
);
}

let tip =
Expand Down
21 changes: 6 additions & 15 deletions stackslib/src/chainstate/stacks/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2746,11 +2746,8 @@ pub mod test {
balances: Vec<(StacksAddress, u64)>,
) -> StacksChainState {
let path = chainstate_path(test_name);
match fs::metadata(&path) {
Ok(_) => {
fs::remove_dir_all(&path).unwrap();
}
Err(_) => {}
if let Ok(_) = fs::metadata(&path) {
fs::remove_dir_all(&path).unwrap();
};

let initial_balances = balances
Expand Down Expand Up @@ -2866,11 +2863,8 @@ pub mod test {
};

let path = chainstate_path(function_name!());
match fs::metadata(&path) {
Ok(_) => {
fs::remove_dir_all(&path).unwrap();
}
Err(_) => {}
if let Ok(_) = fs::metadata(&path) {
fs::remove_dir_all(&path).unwrap();
};

let mut chainstate =
Expand Down Expand Up @@ -2956,11 +2950,8 @@ pub mod test {
};

let path = chainstate_path(function_name!());
match fs::metadata(&path) {
Ok(_) => {
fs::remove_dir_all(&path).unwrap();
}
Err(_) => {}
if let Ok(_) = fs::metadata(&path) {
fs::remove_dir_all(&path).unwrap();
};

let mut chainstate =
Expand Down
14 changes: 6 additions & 8 deletions stackslib/src/chainstate/stacks/index/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,11 @@ impl<T: MarfTrieId> TrieCache<T> {
TrieCache::Everything(ref mut state) => {
state.store_node_and_hash(block_id, trieptr, node, hash);
}
TrieCache::Node256(ref mut state) => match node {
TrieNodeType::Node256(data) => {
TrieCache::Node256(ref mut state) => {
if let TrieNodeType::Node256(data) = node {
state.store_node_and_hash(block_id, trieptr, TrieNodeType::Node256(data), hash);
}
_ => {}
},
}
}
}

Expand All @@ -273,12 +272,11 @@ impl<T: MarfTrieId> TrieCache<T> {
match self {
TrieCache::Noop(_) => {}
TrieCache::Everything(ref mut state) => state.store_node(block_id, trieptr, node),
TrieCache::Node256(ref mut state) => match node {
TrieNodeType::Node256(data) => {
TrieCache::Node256(ref mut state) => {
if let TrieNodeType::Node256(data) = node {
state.store_node(block_id, trieptr, TrieNodeType::Node256(data))
}
_ => {}
},
}
}
}

Expand Down
14 changes: 4 additions & 10 deletions stackslib/src/chainstate/stacks/index/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,8 @@ impl TrieFile {
.map(|stat| Some(stat.len()))
.unwrap_or(None);

match (size_before_opt, size_after_opt) {
(Some(sz_before), Some(sz_after)) => {
debug!("Shrank DB from {} to {} bytes", sz_before, sz_after);
}
_ => {}
if let (Some(sz_before), Some(sz_after)) = (size_before_opt, size_after_opt) {
debug!("Shrank DB from {} to {} bytes", sz_before, sz_after);
}

Ok(())
Expand Down Expand Up @@ -461,11 +458,8 @@ impl TrieFile {
self.write_all(buf)?;
self.flush()?;

match self {
TrieFile::Disk(ref mut data) => {
data.fd.sync_data()?;
}
_ => {}
if let TrieFile::Disk(ref mut data) = self {
data.fd.sync_data()?;
}
Ok(offset)
}
Expand Down
5 changes: 2 additions & 3 deletions stackslib/src/chainstate/stacks/index/marf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1291,9 +1291,8 @@ impl<T: MarfTrieId> MARF<T> {
// used in testing in order to short-circuit block-height lookups
// when the trie struct is tested outside of marf.rs usage
if height == 0 {
match storage.test_genesis_block {
Some(ref s) => return Ok(Some(s.clone())),
_ => {}
if let Some(ref s) = storage.test_genesis_block {
return Ok(Some(s.clone()));
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions stackslib/src/chainstate/stacks/index/proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1213,12 +1213,12 @@ impl<T: MarfTrieId> TrieMerkleProof<T> {
};

// next proof item should be part of a segment proof
match proof[i] {
TrieMerkleProofType::Shunt(_) => {
test_debug!("Malformed proof -- exepcted segment proof following first shunt proof head at {}", i);
return false;
}
_ => {}
if let TrieMerkleProofType::Shunt(_) = proof[i] {
test_debug!(
"Malformed proof -- exepcted segment proof following first shunt proof head at {}",
i
);
return false;
}

while i < proof.len() {
Expand Down
Loading

0 comments on commit da64cec

Please sign in to comment.