diff --git a/src/gui/views/network/mining.rs b/src/gui/views/network/mining.rs index df42ed6..1de1823 100644 --- a/src/gui/views/network/mining.rs +++ b/src/gui/views/network/mining.rs @@ -25,27 +25,17 @@ use crate::gui::views::network::NetworkContent; use crate::gui::views::network::setup::StratumSetup; use crate::gui::views::network::types::{NodeTab, NodeTabType}; use crate::node::{Node, NodeConfig}; -use crate::wallet::WalletConfig; /// Mining tab content. pub struct NetworkMining { /// Stratum server setup content. stratum_server_setup: StratumSetup, - - /// Wallet name for rewards. - wallet_name: String, } impl Default for NetworkMining { fn default() -> Self { - let wallet_name = if let Some(id) = NodeConfig::get_stratum_wallet_id() { - WalletConfig::name_by_id(id).unwrap_or("-".to_string()) - } else { - "-".to_string() - }; Self { stratum_server_setup: StratumSetup::default(), - wallet_name, } } } @@ -91,7 +81,10 @@ impl NodeTab for NetworkMining { }); columns[1].vertical_centered(|ui| { View::label_box(ui, - self.wallet_name.clone(), + self.stratum_server_setup + .wallet_name + .clone() + .unwrap_or("-".to_string()), t!("network_mining.rewards_wallet"), [false, true, false, true]); }); diff --git a/src/gui/views/network/setup/stratum.rs b/src/gui/views/network/setup/stratum.rs index 2c955b9..a681e56 100644 --- a/src/gui/views/network/setup/stratum.rs +++ b/src/gui/views/network/setup/stratum.rs @@ -44,7 +44,7 @@ pub struct StratumSetup { is_port_available: bool, /// Wallet name to receive rewards. - wallet_name: Option, + pub wallet_name: Option, /// Attempt time value in seconds to mine on a particular header. attempt_time_edit: String, diff --git a/src/node/mine_block.rs b/src/node/mine_block.rs index d5594ca..f7c46a4 100644 --- a/src/node/mine_block.rs +++ b/src/node/mine_block.rs @@ -15,7 +15,6 @@ //! Build a block to mine: gathers transactions from the pool, assembles //! them into a block and returns it. -use std::panic::panic_any; use chrono::prelude::{DateTime, Utc}; use rand::{thread_rng, Rng}; use serde_json::{json, Value}; @@ -77,7 +76,7 @@ pub fn get_block( key_id: Option, wallet_listener_url: Option, stop_state: &Arc -) -> (core::Block, BlockFees) { +) -> Option<(core::Block, BlockFees)> { let wallet_retry_interval = 5; // get the latest chain state and build a block on top of it let mut result = build_block(chain, tx_pool, key_id.clone(), wallet_listener_url.clone()); @@ -116,12 +115,11 @@ pub fn get_block( // Stop attempts to build a block on stop. if stop_state.is_stopped() { - panic_any("Stopped"); + return None; } - result = build_block(chain, tx_pool, new_key_id, wallet_listener_url.clone()); } - return result.unwrap(); + Some(result.unwrap()) } /// Builds a new block with the chain head as previous and eligible diff --git a/src/node/stratum.rs b/src/node/stratum.rs index 4207a74..dcbff4e 100644 --- a/src/node/stratum.rs +++ b/src/node/stratum.rs @@ -604,40 +604,43 @@ impl Handler { let clear_blocks = current_hash != latest_hash; // Build the new block (version) - let (new_block, block_fees) = get_block( + if let Some((new_block, block_fees)) = get_block( &self.chain, tx_pool, state.current_key_id.clone(), wallet_listener_url, &stop_state - ); + ) { + // scaled difficulty + state.current_difficulty = + (new_block.header.total_difficulty() - head.total_difficulty).to_num(); - // scaled difficulty - state.current_difficulty = - (new_block.header.total_difficulty() - head.total_difficulty).to_num(); + state.current_key_id = block_fees.key_id(); - state.current_key_id = block_fees.key_id(); + current_hash = latest_hash; + // set the minimum acceptable share unscaled difficulty for this block + state.minimum_share_difficulty = config.minimum_share_difficulty; - current_hash = latest_hash; - // set the minimum acceptable share unscaled difficulty for this block - state.minimum_share_difficulty = config.minimum_share_difficulty; + // set a new deadline for rebuilding with fresh transactions + deadline = Utc::now().timestamp() + config.attempt_time_per_block as i64; - // set a new deadline for rebuilding with fresh transactions - deadline = Utc::now().timestamp() + config.attempt_time_per_block as i64; + // If this is a new block we will clear the current_block version history + if clear_blocks { + state.current_block_versions.clear(); + } - // If this is a new block we will clear the current_block version history - if clear_blocks { - state.current_block_versions.clear(); + // Update the mining stats + self.workers.update_block_height(new_block.header.height); + let difficulty = new_block.header.total_difficulty() - head.total_difficulty; + self.workers.update_network_difficulty(difficulty.to_num()); + self.workers.update_network_hashrate(); + + // Add this new block candidate onto our list of block versions for height + state.current_block_versions.push(new_block); + } else { + thread::sleep(Duration::from_millis(1500)); + break; } - - // Update the mining stats - self.workers.update_block_height(new_block.header.height); - let difficulty = new_block.header.total_difficulty() - head.total_difficulty; - self.workers.update_network_difficulty(difficulty.to_num()); - self.workers.update_network_hashrate(); - - // Add this new block candidate onto our list of block versions for this height - state.current_block_versions.push(new_block); } // Send this job to all connected workers self.broadcast_job();