diff --git a/.github/workflows/bitcoin-tests.yml b/.github/workflows/bitcoin-tests.yml index a832bc223..6acedec75 100644 --- a/.github/workflows/bitcoin-tests.yml +++ b/.github/workflows/bitcoin-tests.yml @@ -81,6 +81,7 @@ jobs: - tests::nakamoto_integrations::correct_burn_outs - tests::nakamoto_integrations::vote_for_aggregate_key_burn_op - tests::nakamoto_integrations::follower_bootup + - tests::nakamoto_integrations::forked_tenure_is_ignored - tests::signer::stackerdb_dkg - tests::signer::stackerdb_sign - tests::signer::stackerdb_block_proposal diff --git a/testnet/stacks-node/src/nakamoto_node/miner.rs b/testnet/stacks-node/src/nakamoto_node/miner.rs index e0bf33a31..090122eba 100644 --- a/testnet/stacks-node/src/nakamoto_node/miner.rs +++ b/testnet/stacks-node/src/nakamoto_node/miner.rs @@ -686,50 +686,14 @@ impl BlockMinerThread { // 1. The highest block in the miner's current tenure // 2. The highest block in the current tenure's parent tenure // Where the current tenure's parent tenure is the tenure start block committed to in the current tenure's associated block commit. - // let stacks_block_id = if let Some(block) = self.mined_blocks.last() { - // block.block_id() - // } else { - // self.parent_tenure_id - // }; - // let Some(mut stacks_tip_header) = - // NakamotoChainState::get_block_header(chain_state.db(), &stacks_block_id) - // .expect("FATAL: could not query prior stacks block id") - // else { - // debug!("No Stacks chain tip known, will return a genesis block"); - // let burnchain_params = burnchain_params_from_config(&self.config.burnchain); - - // let chain_tip = ChainTip::genesis( - // &burnchain_params.first_block_hash, - // burnchain_params.first_block_height.into(), - // burnchain_params.first_block_timestamp.into(), - // ); - - // return Ok(ParentStacksBlockInfo { - // parent_tenure: Some(ParentTenureInfo { - // parent_tenure_consensus_hash: chain_tip.metadata.consensus_hash, - // parent_tenure_blocks: 0, - // }), - // stacks_parent_header: chain_tip.metadata, - // coinbase_nonce: 0, - // }); - // }; - - // if self.mined_blocks.is_empty() { - // // We could call this even if self.mined_blocks was not empty, but would return the same value, so save the effort and only do it when necessary. - // // If we are starting a new tenure, then make sure we are building off of the last block of our parent tenure - // if let Some(last_tenure_finish_block_header) = - // NakamotoChainState::get_nakamoto_tenure_finish_block_header( - // chain_state.db(), - // &stacks_tip_header.consensus_hash, - // ) - // .expect("FATAL: could not query parent tenure finish block") - // { - // stacks_tip_header = last_tenure_finish_block_header; - // } - // } - let Some(stacks_tip_header) = - NakamotoChainState::get_canonical_block_header(chain_state.db(), burn_db) - .expect("FATAL: could not query chain tip") + let stacks_block_id = if let Some(block) = self.mined_blocks.last() { + block.block_id() + } else { + self.parent_tenure_id + }; + let Some(mut stacks_tip_header) = + NakamotoChainState::get_block_header(chain_state.db(), &stacks_block_id) + .expect("FATAL: could not query prior stacks block id") else { debug!("No Stacks chain tip known, will return a genesis block"); let burnchain_params = burnchain_params_from_config(&self.config.burnchain); @@ -749,6 +713,20 @@ impl BlockMinerThread { coinbase_nonce: 0, }); }; + + if self.mined_blocks.is_empty() { + // We could call this even if self.mined_blocks was not empty, but would return the same value, so save the effort and only do it when necessary. + // If we are starting a new tenure, then make sure we are building off of the last block of our parent tenure + if let Some(last_tenure_finish_block_header) = + NakamotoChainState::get_nakamoto_tenure_finish_block_header( + chain_state.db(), + &stacks_tip_header.consensus_hash, + ) + .expect("FATAL: could not query parent tenure finish block") + { + stacks_tip_header = last_tenure_finish_block_header; + } + } let miner_address = self .keychain .origin_address(self.config.is_mainnet()) diff --git a/testnet/stacks-node/src/tests/nakamoto_integrations.rs b/testnet/stacks-node/src/tests/nakamoto_integrations.rs index 35766f685..c50097487 100644 --- a/testnet/stacks-node/src/tests/nakamoto_integrations.rs +++ b/testnet/stacks-node/src/tests/nakamoto_integrations.rs @@ -3216,7 +3216,7 @@ fn forked_tenure_is_ignored() { let burnchain = naka_conf.get_burnchain(); let sortdb = burnchain.open_sortition_db(true).unwrap(); - let (mut chainstate, _) = StacksChainState::open( + let (chainstate, _) = StacksChainState::open( naka_conf.is_mainnet(), naka_conf.burnchain.chain_id, &naka_conf.get_chainstate_path_str(), @@ -3253,7 +3253,7 @@ fn forked_tenure_is_ignored() { }) .unwrap(); - let block_tenure_a = NakamotoChainState::get_canonical_block_header(chainstate.db(), &sortdb) + let _block_tenure_a = NakamotoChainState::get_canonical_block_header(chainstate.db(), &sortdb) .unwrap() .unwrap();