Skip to content

Commit 2261a86

Browse files
authored
Merge branch 'develop' into fix/clippy-ci-needless-borrowed-ref
2 parents e0d2a6b + a4566b8 commit 2261a86

File tree

36 files changed

+1194
-951
lines changed

36 files changed

+1194
-951
lines changed

.github/workflows/bitcoin-tests.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ jobs:
5454
# - tests::neon_integrations::size_overflow_unconfirmed_microblocks_integration_test
5555
# - tests::neon_integrations::size_overflow_unconfirmed_stream_microblocks_integration_test
5656
# - tests::neon_integrations::runtime_overflow_unconfirmed_microblocks_integration_test
57+
# - tests::epoch_25::microblocks_disabled
5758
# Disable this flaky test. Microblocks are no longer supported anyways.
5859
# - tests::neon_integrations::microblock_large_tx_integration_test_FLAKY
5960
- tests::neon_integrations::miner_submit_twice
@@ -80,7 +81,6 @@ jobs:
8081
- tests::neon_integrations::bitcoin_reorg_flap
8182
- tests::neon_integrations::bitcoin_reorg_flap_with_follower
8283
- tests::neon_integrations::start_stop_bitcoind
83-
- tests::epoch_25::microblocks_disabled
8484
- tests::should_succeed_handling_malformed_and_valid_txs
8585
- tests::nakamoto_integrations::simple_neon_integration
8686
- tests::nakamoto_integrations::flash_blocks_on_epoch_3
@@ -141,6 +141,8 @@ jobs:
141141
- tests::signer::v0::incoming_signers_ignore_block_proposals
142142
- tests::signer::v0::outgoing_signers_ignore_block_proposals
143143
- tests::signer::v0::injected_signatures_are_ignored_across_boundaries
144+
- tests::signer::v0::block_proposal_timeout
145+
- tests::signer::v0::rejected_blocks_count_towards_miner_validity
144146
- tests::nakamoto_integrations::burn_ops_integration_test
145147
- tests::nakamoto_integrations::check_block_heights
146148
- tests::nakamoto_integrations::clarity_burn_state

stacks-signer/src/chainstate.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,8 @@ impl SortitionState {
8989
if self.miner_status != SortitionMinerStatus::Valid {
9090
return Ok(false);
9191
}
92-
// if we've already signed a block in this tenure, the miner can't have timed out.
93-
let has_blocks = signer_db
94-
.get_last_signed_block_in_tenure(&self.consensus_hash)?
95-
.is_some();
92+
// if we've already seen a proposed block from this miner. It cannot have timed out.
93+
let has_blocks = signer_db.has_proposed_block_in_tenure(&self.consensus_hash)?;
9694
if has_blocks {
9795
return Ok(false);
9896
}

stacks-signer/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const BLOCK_PROPOSAL_TIMEOUT_MS: u64 = 600_000;
3939
const BLOCK_PROPOSAL_VALIDATION_TIMEOUT_MS: u64 = 120_000;
4040
const DEFAULT_FIRST_PROPOSAL_BURN_BLOCK_TIMING_SECS: u64 = 60;
4141
const DEFAULT_TENURE_LAST_BLOCK_PROPOSAL_TIMEOUT_SECS: u64 = 30;
42-
const TENURE_IDLE_TIMEOUT_SECS: u64 = 300;
42+
const TENURE_IDLE_TIMEOUT_SECS: u64 = 120;
4343

4444
#[derive(thiserror::Error, Debug)]
4545
/// An error occurred parsing the provided configuration

stacks-signer/src/signerdb.rs

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -746,15 +746,13 @@ impl SignerDb {
746746
try_deserialize(result)
747747
}
748748

749-
/// Return the last signed block in a tenure (identified by its consensus hash)
750-
pub fn get_last_signed_block_in_tenure(
751-
&self,
752-
tenure: &ConsensusHash,
753-
) -> Result<Option<BlockInfo>, DBError> {
754-
let query = "SELECT block_info FROM blocks WHERE consensus_hash = ? AND signed_over = 1 ORDER BY stacks_height DESC LIMIT 1";
749+
/// Return whether a block proposal has been stored for a tenure (identified by its consensus hash)
750+
/// Does not consider the block's state.
751+
pub fn has_proposed_block_in_tenure(&self, tenure: &ConsensusHash) -> Result<bool, DBError> {
752+
let query = "SELECT block_info FROM blocks WHERE consensus_hash = ? LIMIT 1";
755753
let result: Option<String> = query_row(&self.db, query, [tenure])?;
756754

757-
try_deserialize(result)
755+
Ok(result.is_some())
758756
}
759757

760758
/// Return the first signed block in a tenure (identified by its consensus hash)
@@ -1904,4 +1902,28 @@ mod tests {
19041902
let pendings = db.get_all_pending_block_validations().unwrap();
19051903
assert_eq!(pendings.len(), 0);
19061904
}
1905+
1906+
#[test]
1907+
fn has_proposed_block() {
1908+
let db_path = tmp_db_path();
1909+
let consensus_hash_1 = ConsensusHash([0x01; 20]);
1910+
let consensus_hash_2 = ConsensusHash([0x02; 20]);
1911+
let mut db = SignerDb::new(db_path).expect("Failed to create signer db");
1912+
let (mut block_info, _) = create_block_override(|b| {
1913+
b.block.header.consensus_hash = consensus_hash_1;
1914+
b.block.header.chain_length = 1;
1915+
});
1916+
1917+
assert!(!db.has_proposed_block_in_tenure(&consensus_hash_1).unwrap());
1918+
assert!(!db.has_proposed_block_in_tenure(&consensus_hash_2).unwrap());
1919+
1920+
db.insert_block(&block_info).unwrap();
1921+
1922+
block_info.block.header.chain_length = 2;
1923+
1924+
db.insert_block(&block_info).unwrap();
1925+
1926+
assert!(db.has_proposed_block_in_tenure(&consensus_hash_1).unwrap());
1927+
assert!(!db.has_proposed_block_in_tenure(&consensus_hash_2).unwrap());
1928+
}
19071929
}

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/burnchains/bitcoin/spv.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,11 @@ impl SpvClient {
328328
} else {
329329
return Err(btc_error::DBError(db_error::NoDBError));
330330
}
331-
} else {
331+
} else if readwrite {
332332
// can just open
333-
if readwrite {
334-
OpenFlags::SQLITE_OPEN_READ_WRITE
335-
} else {
336-
OpenFlags::SQLITE_OPEN_READ_ONLY
337-
}
333+
OpenFlags::SQLITE_OPEN_READ_WRITE
334+
} else {
335+
OpenFlags::SQLITE_OPEN_READ_ONLY
338336
};
339337

340338
let mut conn = sqlite_open(headers_path, open_flags, false)

stackslib/src/burnchains/tests/affirmation.rs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -351,29 +351,27 @@ pub fn make_reward_cycle_with_vote(
351351
let append = if !burnchain.is_in_prepare_phase(block_commit.block_height) {
352352
// non-prepare-phase commits always confirm their parent
353353
true
354+
} else if confirm_anchor_block {
355+
// all block-commits confirm anchor block
356+
true
354357
} else {
355-
if confirm_anchor_block {
356-
// all block-commits confirm anchor block
358+
// fewer than anchor_threshold commits confirm anchor block
359+
let next_rc_start = burnchain.reward_cycle_to_block_height(
360+
burnchain
361+
.block_height_to_reward_cycle(block_commit.block_height)
362+
.unwrap()
363+
+ 1,
364+
);
365+
if block_commit.block_height
366+
+ (burnchain.pox_constants.anchor_threshold as u64)
367+
+ 1
368+
< next_rc_start
369+
{
370+
// in first half of prepare phase, so confirm
357371
true
358372
} else {
359-
// fewer than anchor_threshold commits confirm anchor block
360-
let next_rc_start = burnchain.reward_cycle_to_block_height(
361-
burnchain
362-
.block_height_to_reward_cycle(block_commit.block_height)
363-
.unwrap()
364-
+ 1,
365-
);
366-
if block_commit.block_height
367-
+ (burnchain.pox_constants.anchor_threshold as u64)
368-
+ 1
369-
< next_rc_start
370-
{
371-
// in first half of prepare phase, so confirm
372-
true
373-
} else {
374-
// in second half of prepare phase, so don't confirm
375-
false
376-
}
373+
// in second half of prepare phase, so don't confirm
374+
false
377375
}
378376
};
379377

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

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,21 +1849,19 @@ impl SortitionHandleTx<'_> {
18491849
true
18501850
} else if cur_height > stacks_block_height {
18511851
false
1852+
} else if &cur_ch == consensus_hash {
1853+
// same sortition (i.e. nakamoto block)
1854+
// no replacement
1855+
false
18521856
} else {
1853-
if &cur_ch == consensus_hash {
1854-
// same sortition (i.e. nakamoto block)
1855-
// no replacement
1856-
false
1857-
} else {
1858-
// tips come from different sortitions
1859-
// break ties by going with the latter-signed block
1860-
let sn_current = SortitionDB::get_block_snapshot_consensus(self, &cur_ch)?
1857+
// tips come from different sortitions
1858+
// break ties by going with the latter-signed block
1859+
let sn_current = SortitionDB::get_block_snapshot_consensus(self, &cur_ch)?
1860+
.ok_or(db_error::NotFoundError)?;
1861+
let sn_accepted =
1862+
SortitionDB::get_block_snapshot_consensus(self, &consensus_hash)?
18611863
.ok_or(db_error::NotFoundError)?;
1862-
let sn_accepted =
1863-
SortitionDB::get_block_snapshot_consensus(self, &consensus_hash)?
1864-
.ok_or(db_error::NotFoundError)?;
1865-
sn_current.block_height < sn_accepted.block_height
1866-
}
1864+
sn_current.block_height < sn_accepted.block_height
18671865
};
18681866

18691867
debug!("Setting Stacks tip as accepted";
@@ -5774,10 +5772,9 @@ impl SortitionHandleTx<'_> {
57745772
.map(|parent_commit_sn| parent_commit_sn.sortition_id)
57755773
.unwrap_or(SortitionId([0x00; 32]));
57765774

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-
}
5775+
if !cfg!(test) && (block_commit.parent_block_ptr != 0 || block_commit.parent_vtxindex != 0)
5776+
{
5777+
assert!(parent_sortition_id != SortitionId([0x00; 32]));
57815778
}
57825779

57835780
let args = params![

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,11 @@ 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-
}
321-
// if parent block ptr and parent vtxindex are both 0, then this block's parent is
322-
// the genesis block.
316+
// if parent block ptr and parent vtxindex are both 0, then this block's parent is
317+
// the genesis block.
318+
if data.parent_block_ptr == 0 && data.parent_vtxindex != 0 {
319+
warn!("Invalid tx: parent block back-pointer must be positive");
320+
return Err(op_error::ParseError);
323321
}
324322

325323
if u64::from(data.parent_block_ptr) >= block_height {

0 commit comments

Comments
 (0)