Skip to content

Commit 927a099

Browse files
committed
feat: API for choosing which Nakamoto tenure to mine on
1 parent cde0547 commit 927a099

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

stackslib/src/net/mod.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,6 +2275,10 @@ pub mod test {
22752275
>,
22762276
/// list of malleablized blocks produced when mining.
22772277
pub malleablized_blocks: Vec<NakamotoBlock>,
2278+
pub mine_malleablized_blocks: bool,
2279+
/// tenure-start block of tenure to mine on.
2280+
/// gets consumed on the call to begin_nakamoto_tenure
2281+
pub nakamoto_parent_tenure_opt: Option<Vec<NakamotoBlock>>,
22782282
}
22792283

22802284
impl<'a> TestPeer<'a> {
@@ -2689,6 +2693,8 @@ pub mod test {
26892693
coord: coord,
26902694
indexer: Some(indexer),
26912695
malleablized_blocks: vec![],
2696+
mine_malleablized_blocks: true,
2697+
nakamoto_parent_tenure_opt: None,
26922698
}
26932699
}
26942700

@@ -3509,6 +3515,10 @@ pub mod test {
35093515
self.sortdb.as_mut().unwrap()
35103516
}
35113517

3518+
pub fn sortdb_ref(&mut self) -> &SortitionDB {
3519+
self.sortdb.as_ref().unwrap()
3520+
}
3521+
35123522
pub fn with_db_state<F, R>(&mut self, f: F) -> Result<R, net_error>
35133523
where
35143524
F: FnOnce(
@@ -4198,6 +4208,43 @@ pub mod test {
41984208
}
41994209
}
42004210
}
4211+
4212+
/// Set the nakamoto tenure to mine on
4213+
pub fn mine_nakamoto_on(&mut self, parent_tenure: Vec<NakamotoBlock>) {
4214+
self.nakamoto_parent_tenure_opt = Some(parent_tenure);
4215+
}
4216+
4217+
/// Clear the tenure to mine on. This causes the miner to build on the canonical tip
4218+
pub fn mine_nakamoto_on_canonical_tip(&mut self) {
4219+
self.nakamoto_parent_tenure_opt = None;
4220+
}
4221+
4222+
/// Get an account off of a tip
4223+
pub fn get_account(
4224+
&mut self,
4225+
tip: &StacksBlockId,
4226+
account: &PrincipalData,
4227+
) -> StacksAccount {
4228+
let sortdb = self.sortdb.take().expect("FATAL: sortdb not restored");
4229+
let mut node = self
4230+
.stacks_node
4231+
.take()
4232+
.expect("FATAL: chainstate not restored");
4233+
4234+
let acct = node
4235+
.chainstate
4236+
.maybe_read_only_clarity_tx(
4237+
&sortdb.index_handle_at_block(&node.chainstate, tip).unwrap(),
4238+
tip,
4239+
|clarity_tx| StacksChainState::get_account(clarity_tx, account),
4240+
)
4241+
.unwrap()
4242+
.unwrap();
4243+
4244+
self.sortdb = Some(sortdb);
4245+
self.stacks_node = Some(node);
4246+
acct
4247+
}
42014248
}
42024249

42034250
pub fn to_addr(sk: &StacksPrivateKey) -> StacksAddress {

0 commit comments

Comments
 (0)