-
Notifications
You must be signed in to change notification settings - Fork 24
Enable SOLO mining mode on our Pool #135 #269
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| use std::str::FromStr; | ||
| use std::sync::atomic::Ordering; | ||
|
|
||
| use stratum_apps::stratum_core::{ | ||
| binary_sv2::Str0255, | ||
| bitcoin::{consensus::Decodable, Amount, Target, TxOut}, | ||
| bitcoin::{consensus::Decodable, Address, Amount, Target, TxOut}, | ||
| channels_sv2::{ | ||
| server::{ | ||
| error::{ExtendedChannelError, StandardChannelError}, | ||
|
|
@@ -141,10 +142,23 @@ impl HandleMiningMessagesFromClientAsync for ChannelManager { | |
| return Err(PoolError::disconnect(PoolErrorKind::LastNewPrevhashNotFound, downstream_id)); | ||
| }; | ||
|
|
||
| // Determine the script pubkey for the coinbase output | ||
| // If SOLO mining is enabled, we try to use the address provided by the miner | ||
| let script_pubkey = if self.solo_mining { | ||
| match Address::from_str(&user_identity) { | ||
| Ok(addr) => addr.assume_checked().script_pubkey(), | ||
| Err(_) => { | ||
| error!("SOLO Mining Error: Invalid address '{}' provided by user. Fallback to pool reward address.", user_identity); | ||
| self.coinbase_reward_script.script_pubkey().clone() | ||
| } | ||
| } | ||
| } else { | ||
| self.coinbase_reward_script.script_pubkey().clone() | ||
|
Contributor
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. Wouldn't this just be self for Channel manager? I would think you want per Channel address and not for the broader Pool Channel Manager.
Contributor
Author
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.
You are correct that for Solo Mining we need the per-channel address. That logic is handled in the if block immediately above this. This specific line is inside the else block, which handles Standard Mining. In Standard mode, the coinbase reward must go to the Pool's global wallet (self.coinbase_reward_script) so the pool can collect the funds and distribute shares later. |
||
| }; | ||
|
|
||
| let pool_coinbase_output = TxOut { | ||
| value: Amount::from_sat(last_future_template.coinbase_tx_value_remaining), | ||
| script_pubkey: self.coinbase_reward_script.script_pubkey(), | ||
| script_pubkey, | ||
| }; | ||
|
|
||
| downstream.downstream_data.super_safe_lock(|downstream_data| { | ||
|
|
@@ -435,11 +449,25 @@ impl HandleMiningMessagesFromClientAsync for ChannelManager { | |
| // future extended job | ||
| // and the SetNewPrevHash message | ||
| } else { | ||
| // Determine the script pubkey for the coinbase output | ||
| // If SOLO mining is enabled, we try to use the address provided by the miner | ||
| let script_pubkey = if self.solo_mining { | ||
| match Address::from_str(&user_identity) { | ||
| Ok(addr) => addr.assume_checked().script_pubkey(), | ||
| Err(_) => { | ||
| error!("SOLO Mining Error: Invalid address '{}' provided by user. Fallback to pool reward address.", user_identity); | ||
| self.coinbase_reward_script.script_pubkey().clone() | ||
|
Comment on lines
+458
to
+459
Member
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. Here we should disconnect the the client, instead of doing fallback to pool's address. |
||
| } | ||
| } | ||
| } else { | ||
| self.coinbase_reward_script.script_pubkey().clone() | ||
| }; | ||
|
|
||
| let pool_coinbase_output = TxOut { | ||
| value: Amount::from_sat( | ||
| last_future_template.coinbase_tx_value_remaining, | ||
| ), | ||
| script_pubkey: self.coinbase_reward_script.script_pubkey(), | ||
| script_pubkey, | ||
| }; | ||
|
|
||
| extended_channel.on_new_template( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,12 @@ pub struct PoolConfig { | |
| required_extensions: Vec<u16>, | ||
| #[serde(default)] | ||
| monitoring_address: Option<SocketAddr>, | ||
|
|
||
|
Member
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. Remove this blank line. |
||
| /// Enable SOLO mining mode. | ||
| /// In this mode, the block reward is sent to the address provided by the miner | ||
| /// in the 'user_identity' field. | ||
| #[serde(default)] | ||
| solo_mining: bool, | ||
| } | ||
|
|
||
| impl PoolConfig { | ||
|
|
@@ -75,6 +81,7 @@ impl PoolConfig { | |
| supported_extensions, | ||
| required_extensions, | ||
| monitoring_address: None, | ||
| solo_mining: false, | ||
|
Member
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. Why did you set this to false here? |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -165,6 +172,11 @@ impl PoolConfig { | |
| pub fn monitoring_address(&self) -> Option<SocketAddr> { | ||
| self.monitoring_address | ||
| } | ||
|
|
||
| /// Returns true if SOLO mining mode is enabled. | ||
| pub fn solo_mining(&self) -> bool { | ||
| self.solo_mining | ||
| } | ||
| } | ||
|
|
||
| /// Pool's authority public and secret keys. | ||
|
|
||
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.
Here we should disconnect the the client, instead of doing fallback to pool's address.