Skip to content

Commit c7b84d4

Browse files
authored
Merge branch 'develop' into test/flaky-miner-forking
2 parents 820702c + 0e796a5 commit c7b84d4

Some content is hidden

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

78 files changed

+1462
-1227
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/blockstack_cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ fn main_handler(mut argv: Vec<String>) -> Result<String, CliError> {
864864
if let Some(custom_chain_id) = flag.split('=').nth(1) {
865865
// Attempt to parse the custom chain ID from hex
866866
chain_id = u32::from_str_radix(custom_chain_id.trim_start_matches("0x"), 16)
867-
.map_err(|err| CliError::InvalidChainId(err))?;
867+
.map_err(CliError::InvalidChainId)?;
868868
} else {
869869
// Use the default testnet chain ID
870870
chain_id = CHAIN_ID_TESTNET;

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/bits.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,7 @@ impl BitcoinTxInputStructured {
223223
Instruction::Op(btc_opcodes::OP_CHECKMULTISIG),
224224
) => {
225225
// op1 and op2 must be integers
226-
match (
227-
btc_opcodes::from(*op1).classify(),
228-
btc_opcodes::from(*op2).classify(),
229-
) {
226+
match (op1.classify(), op2.classify()) {
230227
(Class::PushNum(num_sigs), Class::PushNum(num_pubkeys)) => {
231228
// the "#instructions - 3" comes from the OP_m, OP_n, and OP_CHECKMULTISIG
232229
if num_sigs < 1

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/db.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ impl BurnchainDBTransaction<'_> {
393393
let args = params![u64_to_sql(target_reward_cycle)?];
394394
self.sql_tx
395395
.execute(sql, args)
396-
.map_err(|e| DBError::SqliteError(e))?;
396+
.map_err(DBError::SqliteError)?;
397397

398398
let sql = "UPDATE block_commit_metadata SET anchor_block = ?1 WHERE burn_block_hash = ?2 AND txid = ?3";
399399
let args = params![
@@ -424,7 +424,7 @@ impl BurnchainDBTransaction<'_> {
424424
self.sql_tx
425425
.execute(sql, args)
426426
.map(|_| ())
427-
.map_err(|e| DBError::SqliteError(e))
427+
.map_err(DBError::SqliteError)
428428
}
429429

430430
/// Calculate a burnchain block's block-commits' descendancy information.

0 commit comments

Comments
 (0)