Skip to content

Commit 22fffb5

Browse files
authored
Merge pull request stratum-mining#214 from plebhash/2026-01-25-patch-broadcast-shutdown
add `SHUTDOWN_BROADCAST_CAPACITY` constant
2 parents 0230122 + d3427f4 commit 22fffb5

4 files changed

Lines changed: 23 additions & 5 deletions

File tree

miner-apps/jd-client/src/lib/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use stratum_apps::{
88
task_manager::TaskManager,
99
tp_type::TemplateProviderType,
1010
utils::types::Sv2Frame,
11+
SHUTDOWN_BROADCAST_CAPACITY,
1112
};
1213
use tokio::sync::{broadcast, mpsc};
1314
use tracing::{debug, error, info, warn};
@@ -51,7 +52,8 @@ pub struct JobDeclaratorClient {
5152
impl JobDeclaratorClient {
5253
/// Creates a new [`JobDeclaratorClient`] instance.
5354
pub fn new(config: JobDeclaratorClientConfig) -> Self {
54-
let (notify_shutdown, _) = tokio::sync::broadcast::channel::<ShutdownMessage>(100);
55+
let (notify_shutdown, _) =
56+
tokio::sync::broadcast::channel::<ShutdownMessage>(SHUTDOWN_BROADCAST_CAPACITY);
5557
Self {
5658
config,
5759
notify_shutdown,

miner-apps/translator/src/lib/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
#![allow(clippy::module_inception)]
1414
use async_channel::{unbounded, Receiver, Sender};
1515
use std::{net::SocketAddr, sync::Arc, time::Duration};
16-
use stratum_apps::{task_manager::TaskManager, utils::types::Sv2Frame};
16+
use stratum_apps::{
17+
task_manager::TaskManager, utils::types::Sv2Frame, SHUTDOWN_BROADCAST_CAPACITY,
18+
};
1719
use tokio::sync::{broadcast, mpsc};
1820
use tracing::{debug, error, info, warn};
1921

@@ -62,7 +64,8 @@ impl TranslatorSv2 {
6264
pub async fn start(self) {
6365
info!("Starting Translator Proxy...");
6466

65-
let (notify_shutdown, _) = broadcast::channel::<ShutdownMessage>(1);
67+
let (notify_shutdown, _) =
68+
broadcast::channel::<ShutdownMessage>(SHUTDOWN_BROADCAST_CAPACITY);
6669
let (shutdown_complete_tx, mut shutdown_complete_rx) = mpsc::channel::<()>(1);
6770
let task_manager = Arc::new(TaskManager::new());
6871
let (status_sender, status_receiver) = async_channel::unbounded::<Status>();

pool-apps/pool/src/lib/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use async_channel::unbounded;
55
use bitcoin_core_sv2::CancellationToken;
66
use stratum_apps::{
77
stratum_core::bitcoin::consensus::Encodable, task_manager::TaskManager,
8-
tp_type::TemplateProviderType,
8+
tp_type::TemplateProviderType, SHUTDOWN_BROADCAST_CAPACITY,
99
};
1010
use tokio::sync::broadcast;
1111
use tracing::{debug, error, info, warn};
@@ -41,7 +41,8 @@ pub struct PoolSv2 {
4141
#[cfg_attr(not(test), hotpath::measure_all)]
4242
impl PoolSv2 {
4343
pub fn new(config: PoolConfig) -> Self {
44-
let (notify_shutdown, _) = tokio::sync::broadcast::channel::<ShutdownMessage>(100);
44+
let (notify_shutdown, _) =
45+
tokio::sync::broadcast::channel::<ShutdownMessage>(SHUTDOWN_BROADCAST_CAPACITY);
4546
Self {
4647
config,
4748
notify_shutdown,

stratum-apps/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,15 @@ pub mod tp_type;
7575

7676
/// Creates a CoinbaseOutputConstraints message from a list of coinbase outputs
7777
pub mod coinbase_output_constraints;
78+
79+
/// Maximum theoretical TCP client connections
80+
/// (limited by the number of file descriptors a process can have)
81+
const MAX_TCP_CLIENTS: usize = 1_048_576;
82+
83+
/// Safety margin multiplier for shutdown broadcast buffer to handle stacked lags.
84+
const SHUTDOWN_BUFFER_SAFETY_MARGIN: usize = 4;
85+
86+
/// Buffer size for shutdown broadcast channels.
87+
/// Calculated as MAX_TCP_CLIENTS × SHUTDOWN_BUFFER_SAFETY_MARGIN.
88+
/// TODO: migrate away from broadcast channels, see issue https://github.com/stratum-mining/sv2-apps/issues/215
89+
pub const SHUTDOWN_BROADCAST_CAPACITY: usize = MAX_TCP_CLIENTS * SHUTDOWN_BUFFER_SAFETY_MARGIN;

0 commit comments

Comments
 (0)