|
1 | 1 | #![allow(special_module_name)]
|
2 |
| -use async_channel::{bounded, unbounded}; |
3 | 2 |
|
4 |
| -use tracing::{error, info, warn}; |
5 | 3 | mod lib;
|
6 |
| -use lib::{ |
7 |
| - mining_pool::{get_coinbase_output, Configuration, Pool}, |
8 |
| - status, |
9 |
| - template_receiver::TemplateRx, |
10 |
| -}; |
11 |
| - |
12 | 4 | use ext_config::{Config, File, FileFormat};
|
13 |
| -use tokio::select; |
| 5 | +pub use lib::{mining_pool::Configuration, status, PoolSv2}; |
| 6 | +use tracing::error; |
14 | 7 |
|
15 | 8 | mod args {
|
16 | 9 | use std::path::PathBuf;
|
@@ -106,93 +99,5 @@ async fn main() {
|
106 | 99 | return;
|
107 | 100 | }
|
108 | 101 | };
|
109 |
| - |
110 |
| - let (status_tx, status_rx) = unbounded(); |
111 |
| - let (s_new_t, r_new_t) = bounded(10); |
112 |
| - let (s_prev_hash, r_prev_hash) = bounded(10); |
113 |
| - let (s_solution, r_solution) = bounded(10); |
114 |
| - let (s_message_recv_signal, r_message_recv_signal) = bounded(10); |
115 |
| - info!("Pool INITIALIZING with config: {:?}", &args.config_path); |
116 |
| - let coinbase_output_result = get_coinbase_output(&config); |
117 |
| - let coinbase_output_len = match coinbase_output_result { |
118 |
| - Ok(coinbase_output) => coinbase_output.len() as u32, |
119 |
| - Err(err) => { |
120 |
| - error!("Failed to get coinbase output: {:?}", err); |
121 |
| - return; |
122 |
| - } |
123 |
| - }; |
124 |
| - let tp_authority_public_key = config.tp_authority_public_key; |
125 |
| - let template_rx_res = TemplateRx::connect( |
126 |
| - config.tp_address.parse().unwrap(), |
127 |
| - s_new_t, |
128 |
| - s_prev_hash, |
129 |
| - r_solution, |
130 |
| - r_message_recv_signal, |
131 |
| - status::Sender::Upstream(status_tx.clone()), |
132 |
| - coinbase_output_len, |
133 |
| - tp_authority_public_key, |
134 |
| - ) |
135 |
| - .await; |
136 |
| - |
137 |
| - if let Err(e) = template_rx_res { |
138 |
| - error!("Could not connect to Template Provider: {}", e); |
139 |
| - return; |
140 |
| - } |
141 |
| - |
142 |
| - let pool = Pool::start( |
143 |
| - config.clone(), |
144 |
| - r_new_t, |
145 |
| - r_prev_hash, |
146 |
| - s_solution, |
147 |
| - s_message_recv_signal, |
148 |
| - status::Sender::DownstreamListener(status_tx), |
149 |
| - ); |
150 |
| - |
151 |
| - // Start the error handling loop |
152 |
| - // See `./status.rs` and `utils/error_handling` for information on how this operates |
153 |
| - loop { |
154 |
| - let task_status = select! { |
155 |
| - task_status = status_rx.recv() => task_status, |
156 |
| - interrupt_signal = tokio::signal::ctrl_c() => { |
157 |
| - match interrupt_signal { |
158 |
| - Ok(()) => { |
159 |
| - info!("Interrupt received"); |
160 |
| - }, |
161 |
| - Err(err) => { |
162 |
| - error!("Unable to listen for interrupt signal: {}", err); |
163 |
| - // we also shut down in case of error |
164 |
| - }, |
165 |
| - } |
166 |
| - break; |
167 |
| - } |
168 |
| - }; |
169 |
| - let task_status: status::Status = task_status.unwrap(); |
170 |
| - |
171 |
| - match task_status.state { |
172 |
| - // Should only be sent by the downstream listener |
173 |
| - status::State::DownstreamShutdown(err) => { |
174 |
| - error!( |
175 |
| - "SHUTDOWN from Downstream: {}\nTry to restart the downstream listener", |
176 |
| - err |
177 |
| - ); |
178 |
| - break; |
179 |
| - } |
180 |
| - status::State::TemplateProviderShutdown(err) => { |
181 |
| - error!("SHUTDOWN from Upstream: {}\nTry to reconnecting or connecting to a new upstream", err); |
182 |
| - break; |
183 |
| - } |
184 |
| - status::State::Healthy(msg) => { |
185 |
| - info!("HEALTHY message: {}", msg); |
186 |
| - } |
187 |
| - status::State::DownstreamInstanceDropped(downstream_id) => { |
188 |
| - warn!("Dropping downstream instance {} from pool", downstream_id); |
189 |
| - if pool |
190 |
| - .safe_lock(|p| p.remove_downstream(downstream_id)) |
191 |
| - .is_err() |
192 |
| - { |
193 |
| - break; |
194 |
| - } |
195 |
| - } |
196 |
| - } |
197 |
| - } |
| 102 | + PoolSv2::new(config).start().await; |
198 | 103 | }
|
0 commit comments