-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MovePoolSv2
lib code out of main.rs
#1097
Merged
plebhash
merged 2 commits into
stratum-mining:main
from
jbesraa:2024-08-13-refactor-poolsv2
Aug 30, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,111 @@ pub mod error; | |
pub mod mining_pool; | ||
pub mod status; | ||
pub mod template_receiver; | ||
|
||
use async_channel::{bounded, unbounded}; | ||
|
||
use mining_pool::{get_coinbase_output, Configuration, Pool}; | ||
use template_receiver::TemplateRx; | ||
use tracing::{error, info, warn}; | ||
|
||
use tokio::select; | ||
|
||
pub struct PoolSv2 { | ||
config: Configuration, | ||
} | ||
|
||
impl PoolSv2 { | ||
pub fn new(config: Configuration) -> PoolSv2 { | ||
PoolSv2 { config } | ||
} | ||
pub async fn start(self) { | ||
let config = self.config.clone(); | ||
let (status_tx, status_rx) = unbounded(); | ||
let (s_new_t, r_new_t) = bounded(10); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: naming conventions for channels should be consistent with the rest of the code base. |
||
let (s_prev_hash, r_prev_hash) = bounded(10); | ||
let (s_solution, r_solution) = bounded(10); | ||
let (s_message_recv_signal, r_message_recv_signal) = bounded(10); | ||
let coinbase_output_result = get_coinbase_output(&config); | ||
let coinbase_output_len = match coinbase_output_result { | ||
Ok(coinbase_output) => coinbase_output.len() as u32, | ||
Err(err) => { | ||
error!("Failed to get Coinbase output: {:?}", err); | ||
return; | ||
} | ||
}; | ||
let tp_authority_public_key = config.tp_authority_public_key; | ||
let template_rx_res = TemplateRx::connect( | ||
config.tp_address.parse().unwrap(), | ||
s_new_t, | ||
s_prev_hash, | ||
r_solution, | ||
r_message_recv_signal, | ||
status::Sender::Upstream(status_tx.clone()), | ||
coinbase_output_len, | ||
tp_authority_public_key, | ||
) | ||
.await; | ||
|
||
if let Err(e) = template_rx_res { | ||
error!("Could not connect to Template Provider: {}", e); | ||
return; | ||
} | ||
|
||
let pool = Pool::start( | ||
config.clone(), | ||
r_new_t, | ||
r_prev_hash, | ||
s_solution, | ||
s_message_recv_signal, | ||
status::Sender::DownstreamListener(status_tx), | ||
); | ||
|
||
// Start the error handling loop | ||
// See `./status.rs` and `utils/error_handling` for information on how this operates | ||
loop { | ||
let task_status = select! { | ||
task_status = status_rx.recv() => task_status, | ||
interrupt_signal = tokio::signal::ctrl_c() => { | ||
match interrupt_signal { | ||
Ok(()) => { | ||
info!("Interrupt received"); | ||
}, | ||
Err(err) => { | ||
error!("Unable to listen for interrupt signal: {}", err); | ||
// we also shut down in case of error | ||
}, | ||
} | ||
break; | ||
} | ||
}; | ||
let task_status: status::Status = task_status.unwrap(); | ||
|
||
match task_status.state { | ||
// Should only be sent by the downstream listener | ||
status::State::DownstreamShutdown(err) => { | ||
error!( | ||
"SHUTDOWN from Downstream: {}\nTry to restart the downstream listener", | ||
err | ||
); | ||
break; | ||
} | ||
status::State::TemplateProviderShutdown(err) => { | ||
error!("SHUTDOWN from Upstream: {}\nTry to reconnecting or connecting to a new upstream", err); | ||
break; | ||
} | ||
status::State::Healthy(msg) => { | ||
info!("HEALTHY message: {}", msg); | ||
} | ||
status::State::DownstreamInstanceDropped(downstream_id) => { | ||
warn!("Dropping downstream instance {} from pool", downstream_id); | ||
if pool | ||
.safe_lock(|p| p.remove_downstream(downstream_id)) | ||
.is_err() | ||
{ | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This struct appears all over. I'll create an issue from this comment to consolidate to a location in the code base that makes sense.
#1066 (comment)
#1066 (comment)
#1066 (comment)