stratum: fix wallet name after selection, do not panic after stop
This commit is contained in:
parent
442fc425f7
commit
fa6301a1db
4 changed files with 34 additions and 40 deletions
|
@ -25,27 +25,17 @@ use crate::gui::views::network::NetworkContent;
|
||||||
use crate::gui::views::network::setup::StratumSetup;
|
use crate::gui::views::network::setup::StratumSetup;
|
||||||
use crate::gui::views::network::types::{NodeTab, NodeTabType};
|
use crate::gui::views::network::types::{NodeTab, NodeTabType};
|
||||||
use crate::node::{Node, NodeConfig};
|
use crate::node::{Node, NodeConfig};
|
||||||
use crate::wallet::WalletConfig;
|
|
||||||
|
|
||||||
/// Mining tab content.
|
/// Mining tab content.
|
||||||
pub struct NetworkMining {
|
pub struct NetworkMining {
|
||||||
/// Stratum server setup content.
|
/// Stratum server setup content.
|
||||||
stratum_server_setup: StratumSetup,
|
stratum_server_setup: StratumSetup,
|
||||||
|
|
||||||
/// Wallet name for rewards.
|
|
||||||
wallet_name: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for NetworkMining {
|
impl Default for NetworkMining {
|
||||||
fn default() -> Self {
|
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 {
|
Self {
|
||||||
stratum_server_setup: StratumSetup::default(),
|
stratum_server_setup: StratumSetup::default(),
|
||||||
wallet_name,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,7 +81,10 @@ impl NodeTab for NetworkMining {
|
||||||
});
|
});
|
||||||
columns[1].vertical_centered(|ui| {
|
columns[1].vertical_centered(|ui| {
|
||||||
View::label_box(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"),
|
t!("network_mining.rewards_wallet"),
|
||||||
[false, true, false, true]);
|
[false, true, false, true]);
|
||||||
});
|
});
|
||||||
|
|
|
@ -44,7 +44,7 @@ pub struct StratumSetup {
|
||||||
is_port_available: bool,
|
is_port_available: bool,
|
||||||
|
|
||||||
/// Wallet name to receive rewards.
|
/// Wallet name to receive rewards.
|
||||||
wallet_name: Option<String>,
|
pub wallet_name: Option<String>,
|
||||||
|
|
||||||
/// Attempt time value in seconds to mine on a particular header.
|
/// Attempt time value in seconds to mine on a particular header.
|
||||||
attempt_time_edit: String,
|
attempt_time_edit: String,
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
//! Build a block to mine: gathers transactions from the pool, assembles
|
//! Build a block to mine: gathers transactions from the pool, assembles
|
||||||
//! them into a block and returns it.
|
//! them into a block and returns it.
|
||||||
|
|
||||||
use std::panic::panic_any;
|
|
||||||
use chrono::prelude::{DateTime, Utc};
|
use chrono::prelude::{DateTime, Utc};
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
|
@ -77,7 +76,7 @@ pub fn get_block(
|
||||||
key_id: Option<Identifier>,
|
key_id: Option<Identifier>,
|
||||||
wallet_listener_url: Option<String>,
|
wallet_listener_url: Option<String>,
|
||||||
stop_state: &Arc<StratumStopState>
|
stop_state: &Arc<StratumStopState>
|
||||||
) -> (core::Block, BlockFees) {
|
) -> Option<(core::Block, BlockFees)> {
|
||||||
let wallet_retry_interval = 5;
|
let wallet_retry_interval = 5;
|
||||||
// get the latest chain state and build a block on top of it
|
// 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());
|
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.
|
// Stop attempts to build a block on stop.
|
||||||
if stop_state.is_stopped() {
|
if stop_state.is_stopped() {
|
||||||
panic_any("Stopped");
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = build_block(chain, tx_pool, new_key_id, wallet_listener_url.clone());
|
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
|
/// Builds a new block with the chain head as previous and eligible
|
||||||
|
|
|
@ -604,14 +604,13 @@ impl Handler {
|
||||||
let clear_blocks = current_hash != latest_hash;
|
let clear_blocks = current_hash != latest_hash;
|
||||||
|
|
||||||
// Build the new block (version)
|
// Build the new block (version)
|
||||||
let (new_block, block_fees) = get_block(
|
if let Some((new_block, block_fees)) = get_block(
|
||||||
&self.chain,
|
&self.chain,
|
||||||
tx_pool,
|
tx_pool,
|
||||||
state.current_key_id.clone(),
|
state.current_key_id.clone(),
|
||||||
wallet_listener_url,
|
wallet_listener_url,
|
||||||
&stop_state
|
&stop_state
|
||||||
);
|
) {
|
||||||
|
|
||||||
// scaled difficulty
|
// scaled difficulty
|
||||||
state.current_difficulty =
|
state.current_difficulty =
|
||||||
(new_block.header.total_difficulty() - head.total_difficulty).to_num();
|
(new_block.header.total_difficulty() - head.total_difficulty).to_num();
|
||||||
|
@ -636,8 +635,12 @@ impl Handler {
|
||||||
self.workers.update_network_difficulty(difficulty.to_num());
|
self.workers.update_network_difficulty(difficulty.to_num());
|
||||||
self.workers.update_network_hashrate();
|
self.workers.update_network_hashrate();
|
||||||
|
|
||||||
// Add this new block candidate onto our list of block versions for this height
|
// Add this new block candidate onto our list of block versions for height
|
||||||
state.current_block_versions.push(new_block);
|
state.current_block_versions.push(new_block);
|
||||||
|
} else {
|
||||||
|
thread::sleep(Duration::from_millis(1500));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Send this job to all connected workers
|
// Send this job to all connected workers
|
||||||
self.broadcast_job();
|
self.broadcast_job();
|
||||||
|
|
Loading…
Reference in a new issue