Skip to content

Commit 48567ed

Browse files
committed
chore: cleanup
1 parent 11001c8 commit 48567ed

File tree

2 files changed

+25
-55
lines changed

2 files changed

+25
-55
lines changed

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

Lines changed: 25 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -191,69 +191,45 @@ impl LastCommit {
191191

192192
pub type MinerThreadJoinHandle = JoinHandle<Result<(), NakamotoNodeError>>;
193193

194-
/// Miner thread join handle.
195-
/// This can be a "bare" miner thread, or a "tenure-stop" miner thread which itself stops a "bare"
196-
/// miner thread.
197-
pub enum MinerStopHandle {
198-
Miner(MinerThreadJoinHandle, Arc<AtomicBool>),
199-
TenureStop(MinerThreadJoinHandle, Arc<AtomicBool>),
194+
/// Miner thread join handle, as well as an "abort" flag to force the miner thread to exit when it
195+
/// is blocked.
196+
pub struct MinerStopHandle {
197+
/// The join handle itself
198+
join_handle: MinerThreadJoinHandle,
199+
/// The relayer-set abort flag
200+
abort_flag: Arc<AtomicBool>,
200201
}
201202

202203
impl MinerStopHandle {
203-
pub fn new_miner(jh: MinerThreadJoinHandle, abort_flag: Arc<AtomicBool>) -> Self {
204-
Self::Miner(jh, abort_flag)
205-
}
206-
207-
pub fn new_tenure_stop(jh: MinerThreadJoinHandle, abort_flag: Arc<AtomicBool>) -> Self {
208-
Self::TenureStop(jh, abort_flag)
204+
pub fn new(join_handle: MinerThreadJoinHandle, abort_flag: Arc<AtomicBool>) -> Self {
205+
Self {
206+
join_handle,
207+
abort_flag,
208+
}
209209
}
210210

211+
/// Get a ref to the inner thread object
211212
pub fn inner_thread(&self) -> &std::thread::Thread {
212-
match self {
213-
Self::Miner(jh, ..) => jh.thread(),
214-
Self::TenureStop(jh, ..) => jh.thread(),
215-
}
213+
self.join_handle.thread()
216214
}
217215

216+
/// Destroy this stop handle to get the thread join handle
218217
pub fn into_inner(self) -> MinerThreadJoinHandle {
219-
match self {
220-
Self::Miner(jh, ..) => jh,
221-
Self::TenureStop(jh, ..) => jh,
222-
}
223-
}
224-
225-
pub fn is_tenure_stop(&self) -> bool {
226-
match self {
227-
Self::TenureStop(..) => true,
228-
_ => false,
229-
}
230-
}
231-
232-
pub fn is_miner(&self) -> bool {
233-
match self {
234-
Self::Miner(..) => true,
235-
_ => false,
236-
}
218+
self.join_handle
237219
}
238220

221+
/// Set the miner-abort flag to true, which causes the miner thread to exit if it is blocked.
239222
pub fn set_abort_flag(&self) {
240-
match self {
241-
Self::Miner(_, abort_flag) => {
242-
(*abort_flag).store(true, Ordering::SeqCst);
243-
}
244-
Self::TenureStop(_, abort_flag) => {
245-
(*abort_flag).store(true, Ordering::SeqCst);
246-
}
247-
}
223+
self.abort_flag.store(true, Ordering::SeqCst);
248224
}
249225

226+
/// Get an Arc to the abort flag, so another thread can set it.
250227
pub fn get_abort_flag(&self) -> Arc<AtomicBool> {
251-
match self {
252-
Self::Miner(_, abort_flag) => abort_flag.clone(),
253-
Self::TenureStop(_, abort_flag) => abort_flag.clone(),
254-
}
228+
self.abort_flag.clone()
255229
}
256230

231+
/// Stop the inner miner thread.
232+
/// Blocks the miner, and sets the abort flag so that a blocked miner will error out.
257233
pub fn stop(self, globals: &Globals) -> Result<(), NakamotoNodeError> {
258234
let my_id = thread::current().id();
259235
let prior_thread_id = self.inner_thread().id();
@@ -1181,10 +1157,8 @@ impl RelayerThread {
11811157
"Relayer: started tenure thread ID {:?}",
11821158
new_miner_handle.thread().id()
11831159
);
1184-
self.miner_thread.replace(MinerStopHandle::new_miner(
1185-
new_miner_handle,
1186-
miner_abort_flag,
1187-
));
1160+
self.miner_thread
1161+
.replace(MinerStopHandle::new(new_miner_handle, miner_abort_flag));
11881162
self.miner_thread_burn_view.replace(burn_tip);
11891163
Ok(())
11901164
}
@@ -1214,7 +1188,7 @@ impl RelayerThread {
12141188
})?;
12151189

12161190
self.miner_thread
1217-
.replace(MinerStopHandle::new_tenure_stop(stop_handle, abort_flag));
1191+
.replace(MinerStopHandle::new(stop_handle, abort_flag));
12181192
debug!("Relayer: stopped tenure thread ID {id:?}");
12191193
Ok(())
12201194
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11385,8 +11385,6 @@ fn multiple_miners_empty_sortition() {
1138511385
})
1138611386
.expect("Timed out waiting for boostrapped node to catch up to the miner");
1138711387

11388-
let pre_nakamoto_peer_1_height = get_chain_info(&conf).stacks_tip_height;
11389-
1139011388
info!("------------------------- Reached Epoch 3.0 -------------------------");
1139111389

1139211390
let burn_height_contract = "
@@ -11411,8 +11409,6 @@ fn multiple_miners_empty_sortition() {
1141111409
let last_sender_nonce = loop {
1141211410
// Mine 1 nakamoto tenures
1141311411
info!("Mining tenure...");
11414-
let rl2_commits_before = rl2_commits.load(Ordering::SeqCst);
11415-
let rl1_commits_before = rl1_commits.load(Ordering::SeqCst);
1141611412

1141711413
signer_test.mine_block_wait_on_processing(
1141811414
&[&rl1_coord_channels, &rl2_coord_channels],

0 commit comments

Comments
 (0)