@@ -30,24 +30,28 @@ impl PoolSv2 {
30
30
let ( s_message_recv_signal, r_message_recv_signal) = bounded ( 10 ) ;
31
31
let coinbase_output_result = get_coinbase_output ( & config) ?;
32
32
let coinbase_output_len = coinbase_output_result. len ( ) as u32 ;
33
- let tp_authority_public_key = config. tp_authority_public_key ( ) ;
33
+ let tp_authority_public_key = config. tp_authority_public_key ( ) . cloned ( ) ;
34
34
let coinbase_output_sigops = coinbase_output_result
35
35
. iter ( )
36
36
. map ( |output| output. script_pubkey . count_sigops ( ) as u16 )
37
37
. sum :: < u16 > ( ) ;
38
38
39
- TemplateRx :: connect (
40
- config. tp_address ( ) . parse ( ) . unwrap ( ) ,
41
- s_new_t,
42
- s_prev_hash,
43
- r_solution,
44
- r_message_recv_signal,
45
- status:: Sender :: Upstream ( status_tx. clone ( ) ) ,
46
- coinbase_output_len,
47
- coinbase_output_sigops,
48
- tp_authority_public_key. cloned ( ) ,
49
- )
50
- . await ?;
39
+ let tp_address = config. tp_address ( ) . clone ( ) ;
40
+ let cloned_status_tx = status_tx. clone ( ) ;
41
+ tokio:: spawn ( async move {
42
+ let _ = TemplateRx :: connect (
43
+ tp_address. parse ( ) . unwrap ( ) ,
44
+ s_new_t,
45
+ s_prev_hash,
46
+ r_solution,
47
+ r_message_recv_signal,
48
+ status:: Sender :: Upstream ( cloned_status_tx) ,
49
+ coinbase_output_len,
50
+ coinbase_output_sigops,
51
+ tp_authority_public_key,
52
+ )
53
+ . await ;
54
+ } ) ;
51
55
let pool = Pool :: start (
52
56
config. clone ( ) ,
53
57
r_new_t,
@@ -60,51 +64,54 @@ impl PoolSv2 {
60
64
61
65
// Start the error handling loop
62
66
// See `./status.rs` and `utils/error_handling` for information on how this operates
63
- loop {
64
- let task_status = select ! {
65
- task_status = status_rx. recv( ) => task_status,
66
- interrupt_signal = tokio:: signal:: ctrl_c( ) => {
67
- match interrupt_signal {
68
- Ok ( ( ) ) => {
69
- info!( "Interrupt received" ) ;
70
- } ,
71
- Err ( err) => {
72
- error!( "Unable to listen for interrupt signal: {}" , err) ;
73
- // we also shut down in case of error
74
- } ,
67
+ tokio:: spawn ( async move {
68
+ loop {
69
+ let task_status = select ! {
70
+ task_status = status_rx. recv( ) => task_status,
71
+ interrupt_signal = tokio:: signal:: ctrl_c( ) => {
72
+ match interrupt_signal {
73
+ Ok ( ( ) ) => {
74
+ info!( "Interrupt received" ) ;
75
+ } ,
76
+ Err ( err) => {
77
+ error!( "Unable to listen for interrupt signal: {}" , err) ;
78
+ // we also shut down in case of error
79
+ } ,
80
+ }
81
+ break ;
75
82
}
76
- break Ok ( ( ) ) ;
77
- }
78
- } ;
79
- let task_status: status:: Status = task_status. unwrap ( ) ;
83
+ } ;
84
+ let task_status: status:: Status = task_status. unwrap ( ) ;
80
85
81
- match task_status. state {
82
- // Should only be sent by the downstream listener
83
- status:: State :: DownstreamShutdown ( err) => {
84
- error ! (
85
- "SHUTDOWN from Downstream: {}\n Try to restart the downstream listener" ,
86
- err
87
- ) ;
88
- break Ok ( ( ) ) ;
89
- }
90
- status:: State :: TemplateProviderShutdown ( err) => {
91
- error ! ( "SHUTDOWN from Upstream: {}\n Try to reconnecting or connecting to a new upstream" , err) ;
92
- break Ok ( ( ) ) ;
93
- }
94
- status:: State :: Healthy ( msg) => {
95
- info ! ( "HEALTHY message: {}" , msg) ;
96
- }
97
- status:: State :: DownstreamInstanceDropped ( downstream_id) => {
98
- warn ! ( "Dropping downstream instance {} from pool" , downstream_id) ;
99
- if pool
100
- . safe_lock ( |p| p. remove_downstream ( downstream_id) )
101
- . is_err ( )
102
- {
103
- break Ok ( ( ) ) ;
86
+ match task_status. state {
87
+ // Should only be sent by the downstream listener
88
+ status:: State :: DownstreamShutdown ( err) => {
89
+ error ! (
90
+ "SHUTDOWN from Downstream: {}\n Try to restart the downstream listener" ,
91
+ err
92
+ ) ;
93
+ break ;
94
+ }
95
+ status:: State :: TemplateProviderShutdown ( err) => {
96
+ error ! ( "SHUTDOWN from Upstream: {}\n Try to reconnecting or connecting to a new upstream" , err) ;
97
+ break ;
98
+ }
99
+ status:: State :: Healthy ( msg) => {
100
+ info ! ( "HEALTHY message: {}" , msg) ;
101
+ }
102
+ status:: State :: DownstreamInstanceDropped ( downstream_id) => {
103
+ warn ! ( "Dropping downstream instance {} from pool" , downstream_id) ;
104
+ if pool
105
+ . safe_lock ( |p| p. remove_downstream ( downstream_id) )
106
+ . is_err ( )
107
+ {
108
+ break ;
109
+ }
104
110
}
105
111
}
106
112
}
107
- }
113
+ } ) ;
114
+ Ok ( ( ) )
108
115
}
109
116
}
110
117
0 commit comments