Skip to content

Commit

Permalink
WIP: no idea what I am doing
Browse files Browse the repository at this point in the history
Signed-off-by: Jacinta Ferrant <jacinta@trustmachines.co>
  • Loading branch information
jferrant committed Jun 4, 2024
1 parent 447a690 commit a39318d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 21 deletions.
5 changes: 4 additions & 1 deletion testnet/stacks-node/src/nakamoto_node/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ pub enum MinerDirective {
burnchain_tip: BlockSnapshot,
},
/// The miner should try to continue their tenure if they are the active miner
ContinueTenure { new_burn_view: ConsensusHash },
ContinueTenure {
parent_tenure_start: StacksBlockId,
new_burn_view: ConsensusHash,
},
/// The miner did not win sortition
StopTenure,
}
Expand Down
33 changes: 20 additions & 13 deletions testnet/stacks-node/src/nakamoto_node/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ impl RelayerThread {
}
} else {
MinerDirective::ContinueTenure {
parent_tenure_start: committed_index_hash,
new_burn_view: consensus_hash,
}
}
Expand Down Expand Up @@ -650,7 +651,11 @@ impl RelayerThread {
Ok(())
}

fn continue_tenure(&mut self, new_burn_view: ConsensusHash) -> Result<(), NakamotoNodeError> {
fn continue_tenure(
&mut self,
parent_tenure_start: StacksBlockId,
new_burn_view: ConsensusHash,
) -> Result<(), NakamotoNodeError> {
if let Err(e) = self.stop_tenure() {
error!("Relayer: Failed to stop tenure: {:?}", e);
return Ok(());
Expand All @@ -672,10 +677,11 @@ impl RelayerThread {
"block_snapshot_winning_block_txid" => %block_snapshot.winning_block_txid
);
return Ok(());
} else {
debug!("Relayer: the miner won the last sortition. Continuing tenure.");
};

match self.start_new_tenure(
block_snapshot.get_canonical_stacks_block_id(),
parent_tenure_start,
block_snapshot,
MinerReason::Extended {
burn_view_consensus_hash: new_burn_view,
Expand Down Expand Up @@ -717,17 +723,18 @@ impl RelayerThread {
error!("Relayer: Failed to start new tenure: {:?}", e);
}
},
MinerDirective::ContinueTenure { new_burn_view } => {
match self.continue_tenure(new_burn_view) {
Ok(()) => {
debug!("Relayer: successfully handled continue tenure.");
}
Err(e) => {
error!("Relayer: Failed to continue tenure: {:?}", e);
return false;
}
MinerDirective::ContinueTenure {
new_burn_view,
parent_tenure_start,
} => match self.continue_tenure(parent_tenure_start, new_burn_view) {
Ok(()) => {
debug!("Relayer: successfully handled continue tenure.");
}
}
Err(e) => {
error!("Relayer: Failed to continue tenure: {:?}", e);
return false;
}
},
MinerDirective::StopTenure => match self.stop_tenure() {
Ok(()) => {
debug!("Relayer: successfully stopped tenure.");
Expand Down
22 changes: 15 additions & 7 deletions testnet/stacks-node/src/tests/nakamoto_integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4095,17 +4095,25 @@ fn continue_tenure_extend() {
&signers,
);

debug!("Unpausing commit op");
TEST_SKIP_COMMIT_OP.lock().unwrap().replace(false);

debug!("MINIGNT HE TENURES");
debug!("MINING THE NEXT TENURES");
// Mine 15 more regular nakamoto tenures
for _i in 0..15 {
next_block_and_mine_commit(
&mut btc_regtest_controller,
60,
&coord_channel,
&commits_submitted,
)
let commits_before = commits_submitted.load(Ordering::SeqCst);
let blocks_processed_before = coord_channel
.lock()
.expect("Mutex poisoned")
.get_stacks_blocks_processed();
next_block_and(&mut btc_regtest_controller, 60, || {
let commits_count = commits_submitted.load(Ordering::SeqCst);
let blocks_processed = coord_channel
.lock()
.expect("Mutex poisoned")
.get_stacks_blocks_processed();
Ok(commits_count > commits_before && blocks_processed > blocks_processed_before)
})
.unwrap();

signer_vote_if_needed(
Expand Down

0 comments on commit a39318d

Please sign in to comment.