Skip to content

Commit d239b7b

Browse files
committed
implement solo mining mode for the handle_new_template
1 parent b6b533c commit d239b7b

4 files changed

Lines changed: 17 additions & 3 deletions

File tree

pool-apps/pool/src/lib/channel_manager/mining_message_handler.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ impl HandleMiningMessagesFromClientAsync for ChannelManager {
163163
);
164164

165165
downstream.downstream_data.super_safe_lock(|downstream_data| {
166+
downstream_data.payout_mode = Some(payout_mode);
167+
166168
let nominal_hash_rate = msg.nominal_hash_rate;
167169
let requested_max_target = Target::from_le_bytes(msg.max_target.inner_as_ref().try_into().unwrap());
168170
let extranonce_prefix = channel_manager_data.extranonce_prefix_factory_standard.next_prefix_standard().map_err(PoolError::shutdown)?;
@@ -342,6 +344,8 @@ impl HandleMiningMessagesFromClientAsync for ChannelManager {
342344
}
343345
};
344346

347+
downstream_data.payout_mode = Some(payout_mode.clone());
348+
345349
let channel_id = downstream_data
346350
.channel_id_factory
347351
.fetch_add(1, Ordering::SeqCst);

pool-apps/pool/src/lib/channel_manager/template_distribution_message_handler.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ impl HandleTemplateDistributionMessagesFromServerAsync for ChannelManager {
5151
}
5252

5353
let messages_: Vec<RouteMessageTo<'_>> = downstream.downstream_data.super_safe_lock(|data| {
54-
data.group_channel.on_new_template(msg.clone().into_static(), coinbase_output.clone()).map_err(|e| {
54+
let downstream_coinbase_outputs = if let Some(ref payout_mode) = data.payout_mode {
55+
payout_mode.coinbase_outputs(msg.coinbase_tx_value_remaining, &self.coinbase_reward_script)
56+
} else {
57+
coinbase_output.clone()
58+
};
59+
60+
data.group_channel.on_new_template(msg.clone().into_static(), downstream_coinbase_outputs.clone()).map_err(|e| {
5561
tracing::error!("Error while adding template to group channel");
5662
PoolError::shutdown(e)
5763
})?;
@@ -92,7 +98,7 @@ impl HandleTemplateDistributionMessagesFromServerAsync for ChannelManager {
9298
PoolError::shutdown(e)
9399
})?;
94100
} else {
95-
standard_channel.on_new_template(msg.clone().into_static(), coinbase_output.clone()).map_err(|e| {
101+
standard_channel.on_new_template(msg.clone().into_static(), downstream_coinbase_outputs.clone()).map_err(|e| {
96102
tracing::error!("Error while adding template to standard channel");
97103
PoolError::shutdown(e)
98104
})?;

pool-apps/pool/src/lib/downstream/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use crate::{
3636
error::{self, PoolError, PoolErrorKind, PoolResult},
3737
io_task::spawn_io_tasks,
3838
status::{handle_error, Status, StatusSender},
39+
utils::PayoutMode,
3940
};
4041

4142
mod common_message_handler;
@@ -58,6 +59,8 @@ pub struct DownstreamData {
5859
pub channel_id_factory: AtomicU32,
5960
/// Extensions that have been successfully negotiated with this client
6061
pub negotiated_extensions: Vec<u16>,
62+
/// Payout mode derived from user_identity (None until channel is opened)
63+
pub payout_mode: Option<PayoutMode>,
6164
}
6265

6366
/// Communication layer for a downstream connection.
@@ -144,6 +147,7 @@ impl Downstream {
144147
group_channel,
145148
channel_id_factory,
146149
negotiated_extensions: vec![],
150+
payout_mode: None,
147151
}));
148152

149153
Downstream {

pool-apps/pool/src/lib/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub(crate) fn create_close_channel_msg(channel_id: ChannelId, msg: &str) -> Clos
8484
/// `sri/donate/<percentage>/<payout_address>/<worker_name>` (percentage is 0-100, representing
8585
/// pool's portion)
8686
/// - `FullDonation`: Full reward goes to the pool.
87-
#[derive(Debug)]
87+
#[derive(Debug, Clone)]
8888
pub enum PayoutMode {
8989
/// Solo mode: miner receives full block reward.
9090
Solo { script: CoinbaseRewardScript },

0 commit comments

Comments
 (0)