Skip to content

Commit 0c86012

Browse files
committed
Merge branch 'develop' into feat/block_rejections_heuristic
2 parents f66c894 + d2ed454 commit 0c86012

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+680
-1053
lines changed

stackslib/src/burnchains/bitcoin/indexer.rs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -265,40 +265,31 @@ impl BitcoinIndexer {
265265
Ok(s) => {
266266
// Disable Nagle algorithm
267267
s.set_nodelay(true).map_err(|_e| {
268-
test_debug!("Failed to set TCP_NODELAY: {:?}", &_e);
268+
test_debug!("Failed to set TCP_NODELAY: {_e:?}");
269269
btc_error::ConnectionError
270270
})?;
271271

272272
// set timeout
273273
s.set_read_timeout(Some(Duration::from_secs(self.runtime.timeout)))
274274
.map_err(|_e| {
275-
test_debug!("Failed to set TCP read timeout: {:?}", &_e);
275+
test_debug!("Failed to set TCP read timeout: {_e:?}");
276276
btc_error::ConnectionError
277277
})?;
278278

279279
s.set_write_timeout(Some(Duration::from_secs(self.runtime.timeout)))
280280
.map_err(|_e| {
281-
test_debug!("Failed to set TCP write timeout: {:?}", &_e);
281+
test_debug!("Failed to set TCP write timeout: {_e:?}");
282282
btc_error::ConnectionError
283283
})?;
284284

285-
match self.runtime.sock.take() {
286-
Some(s) => {
287-
let _ = s.shutdown(Shutdown::Both);
288-
}
289-
None => {}
285+
if let Some(s_old) = self.runtime.sock.replace(s) {
286+
let _ = s_old.shutdown(Shutdown::Both);
290287
}
291-
292-
self.runtime.sock = Some(s);
293288
Ok(())
294289
}
295290
Err(_e) => {
296-
let s = self.runtime.sock.take();
297-
match s {
298-
Some(s) => {
299-
let _ = s.shutdown(Shutdown::Both);
300-
}
301-
None => {}
291+
if let Some(s) = self.runtime.sock.take() {
292+
let _ = s.shutdown(Shutdown::Both);
302293
}
303294
Err(btc_error::ConnectionError)
304295
}
@@ -926,11 +917,8 @@ impl BitcoinIndexer {
926917

927918
impl Drop for BitcoinIndexer {
928919
fn drop(&mut self) {
929-
match self.runtime.sock {
930-
Some(ref mut s) => {
931-
let _ = s.shutdown(Shutdown::Both);
932-
}
933-
None => {}
920+
if let Some(ref mut s) = self.runtime.sock {
921+
let _ = s.shutdown(Shutdown::Both);
934922
}
935923
}
936924
}

stackslib/src/burnchains/db.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,9 +1193,10 @@ impl BurnchainDB {
11931193
let ops: Vec<BlockstackOperationType> =
11941194
query_rows(&self.conn, qry, args).expect("FATAL: burnchain DB query error");
11951195
for op in ops {
1196-
if let Some(_) = indexer
1196+
if indexer
11971197
.find_burnchain_header_height(&op.burn_header_hash())
11981198
.expect("FATAL: burnchain DB query error")
1199+
.is_some()
11991200
{
12001201
// this is the op on the canonical fork
12011202
return Some(op);

stackslib/src/burnchains/tests/mod.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -577,13 +577,10 @@ impl TestBurnchainBlock {
577577
pub fn patch_from_chain_tip(&mut self, parent_snapshot: &BlockSnapshot) {
578578
assert_eq!(parent_snapshot.block_height + 1, self.block_height);
579579

580-
for i in 0..self.txs.len() {
581-
match self.txs[i] {
582-
BlockstackOperationType::LeaderKeyRegister(ref mut data) => {
583-
assert_eq!(data.block_height, self.block_height);
584-
data.consensus_hash = parent_snapshot.consensus_hash.clone();
585-
}
586-
_ => {}
580+
for tx in self.txs.iter_mut() {
581+
if let BlockstackOperationType::LeaderKeyRegister(ref mut data) = tx {
582+
assert_eq!(data.block_height, self.block_height);
583+
data.consensus_hash = parent_snapshot.consensus_hash.clone();
587584
}
588585
}
589586
}

stackslib/src/chainstate/nakamoto/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2469,7 +2469,7 @@ impl NakamotoChainState {
24692469
) -> Result<bool, ChainstateError> {
24702470
test_debug!("Consider Nakamoto block {}", &block.block_id());
24712471
// do nothing if we already have this block
2472-
if let Some(_) = Self::get_block_header(headers_conn, &block.header.block_id())? {
2472+
if Self::get_block_header(headers_conn, &block.header.block_id())?.is_some() {
24732473
debug!("Already have block {}", &block.header.block_id());
24742474
return Ok(false);
24752475
}

stackslib/src/chainstate/stacks/block.rs

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -353,16 +353,13 @@ impl StacksMessageCodec for StacksBlock {
353353
// must be only one coinbase
354354
let mut coinbase_count = 0;
355355
for tx in txs.iter() {
356-
match tx.payload {
357-
TransactionPayload::Coinbase(..) => {
358-
coinbase_count += 1;
359-
if coinbase_count > 1 {
360-
return Err(codec_error::DeserializeError(
361-
"Invalid block: multiple coinbases found".to_string(),
362-
));
363-
}
356+
if let TransactionPayload::Coinbase(..) = tx.payload {
357+
coinbase_count += 1;
358+
if coinbase_count > 1 {
359+
return Err(codec_error::DeserializeError(
360+
"Invalid block: multiple coinbases found".to_string(),
361+
));
364362
}
365-
_ => {}
366363
}
367364
}
368365

@@ -515,26 +512,23 @@ impl StacksBlock {
515512
let mut found_coinbase = false;
516513
let mut coinbase_index = 0;
517514
for (i, tx) in txs.iter().enumerate() {
518-
match tx.payload {
519-
TransactionPayload::Coinbase(..) => {
520-
if !check_present {
521-
warn!("Found unexpected coinbase tx {}", tx.txid());
522-
return false;
523-
}
524-
525-
if found_coinbase {
526-
warn!("Found duplicate coinbase tx {}", tx.txid());
527-
return false;
528-
}
529-
530-
if tx.anchor_mode != TransactionAnchorMode::OnChainOnly {
531-
warn!("Invalid coinbase tx {}: not on-chain only", tx.txid());
532-
return false;
533-
}
534-
found_coinbase = true;
535-
coinbase_index = i;
515+
if let TransactionPayload::Coinbase(..) = tx.payload {
516+
if !check_present {
517+
warn!("Found unexpected coinbase tx {}", tx.txid());
518+
return false;
519+
}
520+
521+
if found_coinbase {
522+
warn!("Found duplicate coinbase tx {}", tx.txid());
523+
return false;
524+
}
525+
526+
if tx.anchor_mode != TransactionAnchorMode::OnChainOnly {
527+
warn!("Invalid coinbase tx {}: not on-chain only", tx.txid());
528+
return false;
536529
}
537-
_ => {}
530+
found_coinbase = true;
531+
coinbase_index = i;
538532
}
539533
}
540534

stackslib/src/chainstate/stacks/boot/contract_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ impl BurnStateDB for TestSimBurnStateDB {
486486
height: u32,
487487
sortition_id: &SortitionId,
488488
) -> Option<(Vec<TupleData>, u128)> {
489-
if let Some(_) = self.get_burn_header_hash(height, sortition_id) {
489+
if self.get_burn_header_hash(height, sortition_id).is_some() {
490490
let first_block = self.get_burn_start_height();
491491
let prepare_len = self.get_pox_prepare_length();
492492
let rc_len = self.get_pox_reward_cycle_length();

stackslib/src/chainstate/stacks/boot/pox_2_tests.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,23 +1371,20 @@ fn test_simple_pox_2_auto_unlock(alice_first: bool) {
13711371
coinbase_txs.push(r);
13721372
continue;
13731373
}
1374-
match r.transaction {
1375-
TransactionOrigin::Stacks(ref t) => {
1376-
let addr = t.auth.origin().address_testnet();
1377-
eprintln!("TX addr: {}", addr);
1378-
if addr == alice_address {
1379-
alice_txs.insert(t.auth.get_origin_nonce(), r);
1380-
} else if addr == bob_address {
1381-
bob_txs.insert(t.auth.get_origin_nonce(), r);
1382-
} else if addr == charlie_address {
1383-
assert!(
1384-
r.execution_cost != ExecutionCost::ZERO,
1385-
"Execution cost is not zero!"
1386-
);
1387-
charlie_txs.insert(t.auth.get_origin_nonce(), r);
1388-
}
1374+
if let TransactionOrigin::Stacks(ref t) = r.transaction {
1375+
let addr = t.auth.origin().address_testnet();
1376+
eprintln!("TX addr: {}", addr);
1377+
if addr == alice_address {
1378+
alice_txs.insert(t.auth.get_origin_nonce(), r);
1379+
} else if addr == bob_address {
1380+
bob_txs.insert(t.auth.get_origin_nonce(), r);
1381+
} else if addr == charlie_address {
1382+
assert!(
1383+
r.execution_cost != ExecutionCost::ZERO,
1384+
"Execution cost is not zero!"
1385+
);
1386+
charlie_txs.insert(t.auth.get_origin_nonce(), r);
13891387
}
1390-
_ => {}
13911388
}
13921389
}
13931390
}

stackslib/src/chainstate/stacks/boot/pox_3_tests.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -930,16 +930,13 @@ fn pox_auto_unlock(alice_first: bool) {
930930
coinbase_txs.push(r);
931931
continue;
932932
}
933-
match r.transaction {
934-
TransactionOrigin::Stacks(ref t) => {
935-
let addr = t.auth.origin().address_testnet();
936-
if addr == alice_address {
937-
alice_txs.insert(t.auth.get_origin_nonce(), r);
938-
} else if addr == bob_address {
939-
bob_txs.insert(t.auth.get_origin_nonce(), r);
940-
}
933+
if let TransactionOrigin::Stacks(ref t) = r.transaction {
934+
let addr = t.auth.origin().address_testnet();
935+
if addr == alice_address {
936+
alice_txs.insert(t.auth.get_origin_nonce(), r);
937+
} else if addr == bob_address {
938+
bob_txs.insert(t.auth.get_origin_nonce(), r);
941939
}
942-
_ => {}
943940
}
944941
}
945942
}

stackslib/src/chainstate/stacks/boot/pox_4_tests.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9570,16 +9570,13 @@ fn missed_slots_no_unlock() {
95709570
coinbase_txs.push(r);
95719571
continue;
95729572
}
9573-
match r.transaction {
9574-
TransactionOrigin::Stacks(ref t) => {
9575-
let addr = t.auth.origin().address_testnet();
9576-
if addr == alice_address {
9577-
alice_txs.insert(t.auth.get_origin_nonce(), r);
9578-
} else if addr == bob_address {
9579-
bob_txs.insert(t.auth.get_origin_nonce(), r);
9580-
}
9573+
if let TransactionOrigin::Stacks(ref t) = r.transaction {
9574+
let addr = t.auth.origin().address_testnet();
9575+
if addr == alice_address {
9576+
alice_txs.insert(t.auth.get_origin_nonce(), r);
9577+
} else if addr == bob_address {
9578+
bob_txs.insert(t.auth.get_origin_nonce(), r);
95819579
}
9582-
_ => {}
95839580
}
95849581
}
95859582
}

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

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5137,7 +5137,7 @@ impl StacksChainState {
51375137
) {
51385138
Ok(miner_rewards_opt) => miner_rewards_opt,
51395139
Err(e) => {
5140-
if let Some(_) = miner_id_opt {
5140+
if miner_id_opt.is_some() {
51415141
return Err(e);
51425142
} else {
51435143
let msg = format!("Failed to load miner rewards: {:?}", &e);
@@ -11196,15 +11196,12 @@ pub mod test {
1119611196

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

11199-
match (stacks_block_opt, microblocks_opt) {
11200-
(Some(stacks_block), Some(microblocks)) => {
11201-
peer.process_stacks_epoch_at_tip(&stacks_block, &microblocks);
11202-
last_block_id = StacksBlockHeader::make_index_block_hash(
11203-
&consensus_hash,
11204-
&stacks_block.block_hash(),
11205-
);
11206-
}
11207-
_ => {}
11199+
if let (Some(stacks_block), Some(microblocks)) = (stacks_block_opt, microblocks_opt) {
11200+
peer.process_stacks_epoch_at_tip(&stacks_block, &microblocks);
11201+
last_block_id = StacksBlockHeader::make_index_block_hash(
11202+
&consensus_hash,
11203+
&stacks_block.block_hash(),
11204+
);
1120811205
}
1120911206

1121011207
let tip =
@@ -11879,15 +11876,12 @@ pub mod test {
1187911876

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

11882-
match (stacks_block_opt, microblocks_opt) {
11883-
(Some(stacks_block), Some(microblocks)) => {
11884-
peer.process_stacks_epoch_at_tip(&stacks_block, &microblocks);
11885-
last_block_id = StacksBlockHeader::make_index_block_hash(
11886-
&consensus_hash,
11887-
&stacks_block.block_hash(),
11888-
);
11889-
}
11890-
_ => {}
11879+
if let (Some(stacks_block), Some(microblocks)) = (stacks_block_opt, microblocks_opt) {
11880+
peer.process_stacks_epoch_at_tip(&stacks_block, &microblocks);
11881+
last_block_id = StacksBlockHeader::make_index_block_hash(
11882+
&consensus_hash,
11883+
&stacks_block.block_hash(),
11884+
);
1189111885
}
1189211886

1189311887
let tip =

0 commit comments

Comments
 (0)