File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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} ;
1213use tokio:: sync:: { broadcast, mpsc} ;
1314use tracing:: { debug, error, info, warn} ;
@@ -51,7 +52,8 @@ pub struct JobDeclaratorClient {
5152impl 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,
Original file line number Diff line number Diff line change 1313#![ allow( clippy:: module_inception) ]
1414use async_channel:: { unbounded, Receiver , Sender } ;
1515use 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+ } ;
1719use tokio:: sync:: { broadcast, mpsc} ;
1820use 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 > ( ) ;
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ use async_channel::unbounded;
55use bitcoin_core_sv2:: CancellationToken ;
66use stratum_apps:: {
77 stratum_core:: bitcoin:: consensus:: Encodable , task_manager:: TaskManager ,
8- tp_type:: TemplateProviderType ,
8+ tp_type:: TemplateProviderType , SHUTDOWN_BROADCAST_CAPACITY ,
99} ;
1010use tokio:: sync:: broadcast;
1111use tracing:: { debug, error, info, warn} ;
@@ -41,7 +41,8 @@ pub struct PoolSv2 {
4141#[ cfg_attr( not( test) , hotpath:: measure_all) ]
4242impl 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,
Original file line number Diff line number Diff line change @@ -75,3 +75,15 @@ pub mod tp_type;
7575
7676/// Creates a CoinbaseOutputConstraints message from a list of coinbase outputs
7777pub 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 ;
You can’t perform that action at this time.
0 commit comments