Skip to content

Commit 978fddc

Browse files
committed
fix: ensure miner continues mining off its own block
Without this change, when mining a fork (caused by unfortunate timing), the miner will never build off of its tenure change block. This change resolves this issue.
1 parent 1607145 commit 978fddc

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

testnet/stacks-node/src/nakamoto_node/miner.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,9 +845,8 @@ impl BlockMinerThread {
845845
})?;
846846

847847
let stacks_tip_block_id = StacksBlockId::new(&stacks_tip_ch, &stacks_tip_bh);
848-
let tenure_tip_opt = NakamotoChainState::get_highest_block_header_in_tenure(
848+
let tenure_tip_opt = NakamotoChainState::get_highest_known_block_header_in_tenure(
849849
&mut chain_state.index_conn(),
850-
&stacks_tip_block_id,
851850
&self.burn_election_block.consensus_hash,
852851
)
853852
.map_err(|e| {

testnet/stacks-node/src/tests/signer/v0.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11009,7 +11009,7 @@ fn allow_reorg_within_first_proposal_burn_block_timing_secs() {
1100911009
.nakamoto_test_skip_commit_op
1101011010
.set(true);
1101111011

11012-
info!("------------------------- Miner 1 Mines a Nakamoto Block N (Globally Accepted) -------------------------");
11012+
info!("------------------------- Miner 1 Mines a Nakamoto Block N -------------------------");
1101311013
let blocks_processed_before_1 = blocks_mined1.load(Ordering::SeqCst);
1101411014
let stacks_height_before = signer_test
1101511015
.stacks_client
@@ -11039,6 +11039,8 @@ fn allow_reorg_within_first_proposal_burn_block_timing_secs() {
1103911039

1104011040
let blocks = test_observer::get_mined_nakamoto_blocks();
1104111041
let block_n = blocks.last().unwrap().clone();
11042+
let block_n_height = block_n.stacks_height;
11043+
info!("Block N: {block_n_height}");
1104211044
let block_n_signature_hash = block_n.signer_signature_hash;
1104311045

1104411046
let info_after = get_chain_info(&conf);
@@ -11128,6 +11130,8 @@ fn allow_reorg_within_first_proposal_burn_block_timing_secs() {
1112811130
assert!(tip.sortition);
1112911131
assert_eq!(tip.miner_pk_hash.unwrap(), mining_pkh_2);
1113011132

11133+
assert_eq!(get_chain_info(&conf).stacks_tip_height, block_n_height + 1);
11134+
1113111135
info!("------------------------- Miner 2 Mines N+2 and N+3 -------------------------");
1113211136
let blocks_processed_before_2 = blocks_mined2.load(Ordering::SeqCst);
1113311137
let stacks_height_before = signer_test
@@ -11195,6 +11199,8 @@ fn allow_reorg_within_first_proposal_burn_block_timing_secs() {
1119511199
})
1119611200
.expect("Timed out waiting for Miner 2 to Mine Block N+3");
1119711201

11202+
assert_eq!(get_chain_info(&conf).stacks_tip_height, block_n_height + 3);
11203+
1119811204
info!("------------------------- Miner 1 Wins the Next Tenure -------------------------");
1119911205

1120011206
let blocks_processed_before_1 = blocks_mined1.load(Ordering::SeqCst);
@@ -11212,6 +11218,10 @@ fn allow_reorg_within_first_proposal_burn_block_timing_secs() {
1121211218
)
1121311219
.expect("Timed out waiting for Miner 1 to Mine Block N+1'");
1121411220

11221+
let blocks = test_observer::get_mined_nakamoto_blocks();
11222+
let last_block = blocks.last().expect("No blocks mined");
11223+
assert_eq!(last_block.stacks_height, block_n_height + 1);
11224+
1121511225
info!("------------------------- Miner 1 Mines N+2 -------------------------");
1121611226

1121711227
let blocks_processed_before_1 = blocks_mined1.load(Ordering::SeqCst);
@@ -11237,6 +11247,10 @@ fn allow_reorg_within_first_proposal_burn_block_timing_secs() {
1123711247
})
1123811248
.expect("Timed out waiting for Miner 1 to Mine Block N+2");
1123911249

11250+
let blocks = test_observer::get_mined_nakamoto_blocks();
11251+
let last_block = blocks.last().expect("No blocks mined");
11252+
assert_eq!(last_block.stacks_height, block_n_height + 2);
11253+
1124011254
info!("------------------------- Shutdown -------------------------");
1124111255
rl2_coord_channels
1124211256
.lock()

0 commit comments

Comments
 (0)