Skip to content

Commit 697157f

Browse files
authored
Merge pull request #420 from Shourya742/2026-04-08-fix-jdc-pool-drop-on-no-bitcoin-conn
Make sure JDC and Pool shuts on no bitcoin conn
2 parents 89c23b5 + cfecfd0 commit 697157f

File tree

2 files changed

+8
-27
lines changed

2 files changed

+8
-27
lines changed

miner-apps/jd-client/src/lib/template_receiver/bitcoin_core.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
2-
error::{self, JDCError, JDCErrorKind},
3-
status::{handle_error, State, Status, StatusSender},
2+
error::JDCErrorKind,
3+
status::{State, Status},
44
};
55
use async_channel::{Receiver, Sender};
66
use bitcoin_core_sv2::template_distribution_protocol::{BitcoinCoreSv2TDP, CancellationToken};
@@ -26,7 +26,6 @@ pub async fn connect_to_bitcoin_core(
2626
status_sender: Sender<Status>,
2727
) -> JoinHandle<()> {
2828
let bitcoin_core_sv2_token = bitcoin_core_config.cancellation_token.clone();
29-
let status_sender_clone = status_sender.clone();
3029

3130
// spawn a task to handle shutdown signals and cancellation token activations
3231
task_manager.spawn(async move {
@@ -35,19 +34,11 @@ pub async fn connect_to_bitcoin_core(
3534
bitcoin_core_sv2_token.cancel();
3635
}
3736
_ = bitcoin_core_sv2_token.cancelled() => {
38-
// turn status_sender into a StatusSender::TemplateReceiver
39-
let status_sender = StatusSender::TemplateReceiver(status_sender_clone);
40-
handle_error(
41-
&status_sender,
42-
JDCError::<error::TemplateProvider>::shutdown(JDCErrorKind::BitcoinCoreSv2TDPCancellationTokenActivated),
43-
)
44-
.await;
37+
cancellation_token.cancel();
4538
}
4639
}
4740
});
4841

49-
let status_sender_clone = status_sender.clone();
50-
5142
// spawn a dedicated thread to run the BitcoinCoreSv2TDP instance
5243
// because we're limited to tokio::task::LocalSet due to the use of `capnp` clients on
5344
// `bitcoin-core-sv2`, which are not `Send`
@@ -59,7 +50,7 @@ pub async fn connect_to_bitcoin_core(
5950
tracing::error!("Failed to create Tokio runtime: {:?}", e);
6051

6152
// we can't use handle_error here because we're not in a async context yet
62-
let _ = status_sender_clone.send_blocking(Status {
53+
let _ = status_sender.send_blocking(Status {
6354
state: State::TemplateReceiverShutdown(
6455
JDCErrorKind::FailedToCreateBitcoinCoreTokioRuntime,
6556
),

pool-apps/pool/src/lib/template_receiver/bitcoin_core.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
2-
error::{self, PoolError, PoolErrorKind},
3-
status::{handle_error, State, Status, StatusSender},
2+
error::PoolErrorKind,
3+
status::{State, Status},
44
};
55
use async_channel::{Receiver, Sender};
66
use bitcoin_core_sv2::template_distribution_protocol::{BitcoinCoreSv2TDP, CancellationToken};
@@ -25,7 +25,6 @@ pub async fn connect_to_bitcoin_core(
2525
status_sender: Sender<Status>,
2626
) -> JoinHandle<()> {
2727
let bitcoin_core_canc_token = bitcoin_core_config.cancellation_token.clone();
28-
let status_sender_clone = status_sender.clone();
2928

3029
// spawn a task to handle shutdown signals and cancellation token activations
3130
task_manager.spawn(async move {
@@ -34,20 +33,11 @@ pub async fn connect_to_bitcoin_core(
3433
bitcoin_core_canc_token.cancel();
3534
}
3635
_ = bitcoin_core_canc_token.cancelled() => {
37-
// turn status_sender into a StatusSender::TemplateReceiver
38-
let status_sender = StatusSender::TemplateReceiver(status_sender_clone);
39-
40-
handle_error::<error::TemplateProvider>(
41-
&status_sender,
42-
PoolError::shutdown(PoolErrorKind::BitcoinCoreSv2TDPCancellationTokenActivated),
43-
)
44-
.await;
36+
cancellation_token.cancel();
4537
}
4638
}
4739
});
4840

49-
let status_sender_clone = status_sender.clone();
50-
5141
// spawn a dedicated thread to run the BitcoinCoreSv2TDP instance
5242
// because we're limited to tokio::task::LocalSet due to the use of `capnp` clients on
5343
// `bitcoin-core-sv2`, which are not `Send`
@@ -59,7 +49,7 @@ pub async fn connect_to_bitcoin_core(
5949
tracing::error!("Failed to create Tokio runtime: {:?}", e);
6050

6151
// we can't use handle_error here because we're not in a async context yet
62-
let _ = status_sender_clone.send_blocking(Status {
52+
let _ = status_sender.send_blocking(Status {
6353
state: State::TemplateReceiverShutdown(
6454
PoolErrorKind::FailedToCreateBitcoinCoreTokioRuntime,
6555
),

0 commit comments

Comments
 (0)