-
Notifications
You must be signed in to change notification settings - Fork 677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nakamoto Miner[3.0] - Miners should handle tenure extend transactions #4709
Comments
Adding a bit more context here: The nakamoto miner implementation currently works with essentially a two thread process. The relayer thread (implemented in Some relevant code pointers: In relayer.rs: ...
if sn.sortition {
if won_sortition {
MinerDirective::BeginTenure {
parent_tenure_start: committed_index_hash,
burnchain_tip: sn,
}
} else {
MinerDirective::StopTenure
}
} else {
MinerDirective::ContinueTenure {
new_burn_view: consensus_hash,
}
} and ...
match miner_instruction {
MinerDirective::BeginTenure {
parent_tenure_start,
burnchain_tip,
} => match self.start_new_tenure(parent_tenure_start, burnchain_tip) {
Ok(()) => {
debug!("Relayer: successfully started new tenure.");
}
Err(e) => {
error!("Relayer: Failed to start new tenure: {:?}", e);
}
},
MinerDirective::ContinueTenure { new_burn_view: _ } => {
// TODO: in this case, we eventually want to undergo a tenure
// change to switch to the new burn view, but right now, we will
// simply end our current tenure if it exists
match self.stop_tenure() {
Ok(()) => {
debug!("Relayer: successfully stopped tenure.");
}
Err(e) => {
error!("Relayer: Failed to stop tenure: {:?}", e);
}
}
}
MinerDirective::StopTenure => match self.stop_tenure() {
Ok(()) => {
debug!("Relayer: successfully stopped tenure.");
}
Err(e) => {
error!("Relayer: Failed to stop tenure: {:?}", e);
}
},
}
... I think the most straight-forward way to implement this is to add a field to the You can check if the current miner is the last winning miner with something like: self.sortdb.index_handle_at_tip().get_last_snapshot_with_sortition_at_tip()?.winning_block_txid == self.current_mining_commit_tx
diff --git a/stackslib/src/chainstate/burn/db/sortdb.rs b/stackslib/src/chainstate/burn/db/sortdb.rs
index e3802d6ec..1d515f2ef 100644
--- a/stackslib/src/chainstate/burn/db/sortdb.rs
+++ b/stackslib/src/chainstate/burn/db/sortdb.rs
@@ -2226,6 +2226,29 @@ impl<'a> SortitionHandleConn<'a> {
})
}
+ /// Get the latest block snapshot on this fork where a sortition occured.
+ pub fn get_last_snapshot_with_sortition_from_tip(
+ &self,
+ ) -> Result<BlockSnapshot, db_error> {
+ let ancestor_hash = match self.get_indexed(&self.context.chain_tip, &db_keys::last_sortition())? {
+ Some(hex_str) => BurnchainHeaderHash::from_hex(&hex_str).unwrap_or_else(|_| {
+ panic!(
+ "FATAL: corrupt database: failed to parse {} into a hex string",
+ &hex_str
+ )
+ }),
+ None => {
+ // no prior sortitions, so get the first
+ return self.get_first_block_snapshot();
+ }
+ };
+
+ self.get_block_snapshot(&ancestor_hash).map(|snapshot_opt| {
+ snapshot_opt
+ .unwrap_or_else(|| panic!("FATAL: corrupt index: no snapshot {}", ancestor_hash))
+ })
+ }
+
pub fn get_leader_key_at(
&self,
key_block_height: u64, |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
The text was updated successfully, but these errors were encountered: