Skip to content

Commit

Permalink
feat: add mining threads user control (#319)
Browse files Browse the repository at this point in the history
* Add mining threads

Completed wiring of mining SHA3 and RandomX mining threads

* merge to main
  • Loading branch information
hansieodendaal committed Feb 19, 2024
1 parent 5800182 commit 7206849
Show file tree
Hide file tree
Showing 24 changed files with 160 additions and 138 deletions.
2 changes: 1 addition & 1 deletion backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tari_launchpad"
version = "1.6.0"
description = "A unified user interface for a Tari node, wallet and miner, with a focus on ease-of-use and UX."
description = "A unified user interface for a Tari node and miner, with a focus on ease-of-use and UX."
authors = ["The Tari Development Community"]
license = "BSD-3-Clause"
repository = "https://github.com/tari-project/tari-launchpad"
Expand Down
34 changes: 0 additions & 34 deletions backend/assets/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,44 +66,10 @@ dns_seeds = ["seeds.stagenet.tari.com"]
# Custom specified peer seed nodes
peer_seeds = []

[wallet]
override_from = "stagenet"
db_file = "wallet/wallet.dat"
grpc_enabled = true
grpc_address = "/ip4/0.0.0.0/tcp/18143"
password = "tari"
use_libtor = false
#gRPC authentication method (default = "none")
#grpc_authentication = { username = "admin", password = "xxxx" }

# A custom base node peer that will be used to obtain metadata from, example
# "0eefb45a4de9484eca74846a4f47d2c8d38e76be1fec63b0112bd00d297c0928::/ip4/13.40.98.39/tcp/18189"
# This is set internally by launchpad when the base node starts
# custom_base_node = "none"

[wallet.p2p]

[wallet.p2p.transport]
type = "tor"

[wallet.p2p.transport.tor]
control_auth = "password=tari"
socks_address_override = "/dns4/tor/tcp/9050"
control_address = "/dns4/tor/tcp/9051"
# When these peer addresses are encountered when dialing another peer, the tor proxy is bypassed and the connection is
# made directly over TCP. /ip4, /ip6, /dns, /dns4 and /dns6 are supported. (e.g. ["/dns4/my-foo-base-node/tcp/9998"])
proxy_bypass_addresses = ["/dns4/wallet/tcp/18188"]
proxy_bypass_for_outbound_tcp = true

[wallet.p2p.transport.tcp]
#listener_address = "/dns4/wallet/tcp/18188"
listener_address = "/dns4/wallet/tcp/18188"

[miner]
base_node_grpc_address = "/dns4/base_node/tcp/18142"
wallet_grpc_address = "/dns4/wallet/tcp/18143"
mine_on_tip_only = true
num_mining_threads = 4

[merge_mining_proxy]
monerod_url = [ # stagenet
Expand Down
5 changes: 0 additions & 5 deletions backend/assets/log4rs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ loggers:
appenders:
- core
additive: false
wallet:
level: info
appenders:
- core
additive: false
tari_miner:
level: debug
appenders:
Expand Down
2 changes: 1 addition & 1 deletion backend/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"tauri": {
"cli": {
"description": "A simple single-click UI to launch a Tari node, wallet and miner",
"description": "A simple single-click UI to launch a Tari node and miner",
"args": [
{
"short": "c",
Expand Down
1 change: 1 addition & 0 deletions cli/src/component/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ mod settings;
mod tabs;
mod termination;
mod widgets;

use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use derive_more::From;
pub use main_view::MainView;
Expand Down
54 changes: 45 additions & 9 deletions cli/src/component/settings/mining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,21 @@ use crate::{
AppState,
},
};
use tari_launchpad_protocol::OptionUsizeWrapper;

pub static MINING_SETTINGS: Focus = focus_id!();
static MONERO_ADDRESS: Focus = focus_id!();
static SHA_THREADS: Focus = focus_id!();
static RANDOM_X_THREADS: Focus = focus_id!();
static MONERO_URL: Focus = focus_id!();
static WALLET_PAYMENT_ADDRESS: Focus = focus_id!();

pub struct MiningSettings {
expert_sep: Separator,
monero_address: LabeledInput,
monero_url: LabeledInput,
sha_threads: LabeledInput<usize>,
random_x_threads: LabeledInput<OptionUsizeWrapper>,
sha3_threads: LabeledInput<usize>,
wallet_payment_address: LabeledInput,
}

Expand All @@ -61,7 +64,8 @@ impl MiningSettings {
expert_sep: Separator::new("Expert", []),
monero_address: LabeledInput::new("Monero mining address", MONERO_ADDRESS),
monero_url: LabeledInput::new("Monero node URL", MONERO_URL),
sha_threads: LabeledInput::new_with_value("SHA3 threads", SHA_THREADS, 2),
random_x_threads: LabeledInput::new("RandomX threads", RANDOM_X_THREADS),
sha3_threads: LabeledInput::new_with_value("SHA3 threads", SHA_THREADS, 8),
wallet_payment_address: LabeledInput::new("Wallet payment address", WALLET_PAYMENT_ADDRESS),
}
}
Expand All @@ -77,8 +81,12 @@ impl MiningSettings {
saved_settings.set_monero_mining_address(addr);
should_write = true;
}
if let Some(v) = self.sha_threads.fetch_new_value() {
saved_settings.set_num_mining_threads(*v);
if let Some(v) = self.random_x_threads.fetch_new_value() {
saved_settings.set_random_x_num_mining_threads(v.clone());
should_write = true;
}
if let Some(v) = self.sha3_threads.fetch_new_value() {
saved_settings.set_sha3_num_mining_threads(*v);
should_write = true;
}
if let Some(v) = self.wallet_payment_address.fetch_new_value() {
Expand All @@ -97,13 +105,19 @@ impl MiningSettings {
impl Input for MiningSettings {
type Output = ();

#[allow(clippy::too_many_lines)]
fn on_event(&mut self, event: ComponentEvent, state: &mut AppState) -> Option<Self::Output> {
if let ComponentEvent::StateChanged = event {
if let Some(settings) = &state.state.config.settings {
if let Some(conf) = &settings.saved_settings.xmrig {
let value = conf.monero_mining_address.clone();
self.monero_address.set(value);
}
if let Some(num) = &settings.saved_settings.xmrig {
if let Some(value) = num.num_mining_threads.clone() {
self.random_x_threads.set(value);
}
}
if let Some(conf) = &settings.saved_settings.mm_proxy {
let value = conf.monerod_url.clone();
self.monero_url.set(value);
Expand All @@ -113,6 +127,10 @@ impl Input for MiningSettings {
self.wallet_payment_address.set(wallet_payment_address.to_string());
}
}
if let Some(num) = &settings.saved_settings.sha3_miner {
let value = num.num_mining_threads;
self.sha3_threads.set(value);
}
}
return None;
}
Expand Down Expand Up @@ -141,19 +159,35 @@ impl Input for MiningSettings {
},
}
} else if state.focus_on == SHA_THREADS {
let released = self.sha_threads.is_released();
let released = self.sha3_threads.is_released();
match event.pass() {
Pass::Leave if released => {
state.focus_on(MINING_SETTINGS);
},
Pass::Up if released => {
state.focus_on(MONERO_ADDRESS);
},
Pass::Down if released => {
state.focus_on(RANDOM_X_THREADS);
},
_ => {
self.sha3_threads.on_event(event, state);
},
}
} else if state.focus_on == RANDOM_X_THREADS {
let released = self.random_x_threads.is_released();
match event.pass() {
Pass::Leave if released => {
state.focus_on(MINING_SETTINGS);
},
Pass::Up if released => {
state.focus_on(SHA_THREADS);
},
Pass::Down if released => {
state.focus_on(MONERO_URL);
},
_ => {
self.sha_threads.on_event(event, state);
self.random_x_threads.on_event(event, state);
},
}
} else if state.focus_on == MONERO_URL {
Expand Down Expand Up @@ -209,6 +243,7 @@ impl<B: Backend> Component<B> for MiningSettings {
Constraint::Length(3),
Constraint::Length(3),
Constraint::Length(3),
Constraint::Length(3),
Constraint::Min(0),
];
let chunks = Layout::default()
Expand All @@ -219,8 +254,9 @@ impl<B: Backend> Component<B> for MiningSettings {
.split(inner_rect);
self.expert_sep.draw(f, chunks[0], state);
self.monero_address.draw(f, chunks[1], state);
self.sha_threads.draw(f, chunks[2], state);
self.monero_url.draw(f, chunks[3], state);
self.wallet_payment_address.draw(f, chunks[4], state);
self.sha3_threads.draw(f, chunks[2], state);
self.random_x_threads.draw(f, chunks[3], state);
self.monero_url.draw(f, chunks[4], state);
self.wallet_payment_address.draw(f, chunks[5], state);
}
}
25 changes: 13 additions & 12 deletions cli/src/component/widgets/labeled_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use crate::{
state::{AppState, Focus},
};

#[derive(Debug)]
pub enum Value<T> {
// No value is set
Empty,
Expand Down Expand Up @@ -103,6 +104,7 @@ pub struct LabeledInput<T: Eq + FromStr = String> {
validator: Box<dyn CharValidator>,
}

// Define a newtype wrapper for Option<usize>
impl<T> LabeledInput<T>
where
T: Eq + FromStr + ToString,
Expand Down Expand Up @@ -140,16 +142,11 @@ where
/// Update the value held in this input field, if the value has changed.
pub fn update_value<E: ToString>(&mut self, value: Result<T, E>) {
match value {
Ok(new_value) => {
let replace = self.value().map(|v| *v != new_value).unwrap_or(true); // covers empty and invalid cases
if replace {
self.value = Value::New { value: new_value };
}
},
Ok(new_value) => self.value = Value::New { value: new_value },
Err(err) => {
self.value = Value::Invalid {
reason: err.to_string(),
};
}
},
}
}
Expand All @@ -165,18 +162,22 @@ where
let old = mem::replace(&mut self.value, Value::Empty);
let value = old.into_inner();
let _unused = mem::replace(&mut self.value, Value::Valid { value });
self.value().ok()
if let Ok(val) = self.value() {
val
} else {
None
}
} else {
None
}
}

pub fn value(&self) -> Result<&T, Error> {
pub fn value(&self) -> Result<Option<&T>, Error> {
match &self.value {
Value::Valid { value } => Ok(value),
Value::New { value } => Ok(value),
Value::Valid { value } => Ok(Some(value)),
Value::New { value } => Ok(Some(value)),
Value::Invalid { reason } => Err(Error::msg(reason.to_owned())),
Value::Empty => Err(Error::msg("Value is empty")),
Value::Empty => Ok(None),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cli/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl AppState {
configured",
)
})?;
let action = Action::Action(LaunchpadAction::SaveSettings(settings));
let action = Action::Action(LaunchpadAction::SaveSettings(Box::new(settings)));
self.bus_tx.send(action)?;
},
}
Expand Down
34 changes: 0 additions & 34 deletions docker_rig/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,44 +66,10 @@ dns_seeds = ["seeds.stagenet.tari.com"]
# Custom specified peer seed nodes
peer_seeds = []

[wallet]
override_from = "stagenet"
db_file = "wallet/wallet.dat"
grpc_enabled = true
grpc_address = "/ip4/0.0.0.0/tcp/18143"
password = "tari"
use_libtor = false
#gRPC authentication method (default = "none")
#grpc_authentication = { username = "admin", password = "xxxx" }

# A custom base node peer that will be used to obtain metadata from, example
# "0eefb45a4de9484eca74846a4f47d2c8d38e76be1fec63b0112bd00d297c0928::/ip4/13.40.98.39/tcp/18189"
# This is set internally by launchpad when the base node starts
# custom_base_node = "none"

[wallet.p2p]

[wallet.p2p.transport]
type = "tor"

[wallet.p2p.transport.tor]
control_auth = "password=tari"
socks_address_override = "/dns4/tor/tcp/9050"
control_address = "/dns4/tor/tcp/9051"
# When these peer addresses are encountered when dialing another peer, the tor proxy is bypassed and the connection is
# made directly over TCP. /ip4, /ip6, /dns, /dns4 and /dns6 are supported. (e.g. ["/dns4/my-foo-base-node/tcp/9998"])
proxy_bypass_addresses = ["/dns4/wallet/tcp/18188"]
proxy_bypass_for_outbound_tcp = true

[wallet.p2p.transport.tcp]
#listener_address = "/dns4/wallet/tcp/18188"
listener_address = "/dns4/wallet/tcp/18188"

[miner]
base_node_grpc_address = "/dns4/base_node/tcp/18142"
wallet_grpc_address = "/dns4/wallet/tcp/18143"
mine_on_tip_only = true
num_mining_threads = 4

[merge_mining_proxy]
monerod_url = [ # stagenet
Expand Down
1 change: 0 additions & 1 deletion docker_rig/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ services:
APP_EXEC: tari_base_node
WAIT_FOR_TOR: ${WAIT_FOR_TOR:-0}
TARI_NETWORK: ${TARI_NETWORK}
TARI_DIBBLER__BASE_NODE__DATA_DIR: "/blockchain/dibbler"
ports:
- 18189:18189
- 18142:18142
Expand Down
12 changes: 0 additions & 12 deletions docker_rig/xmrig.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,4 @@ ENV dockerfile_version=$VERSION
ENV dockerfile_build_arch=$BUILDPLATFORM
ENV xmrig_version=$XMRIG_VERSION

RUN echo -e "\
{\
\"autosave\": true,\
\"cpu\": true,\
\"opencl\": false,\
\"cuda\": false,\
\"pools\": [ \
{ \"coin\": \"monero\", \"url\": \"127.0.0.1:18081\", \"user\": \"44\", \"daemon\": true }\
]\
}\
" > /home/tari/.xmrig.json

ENTRYPOINT [ "/usr/local/bin/xmrig" ]
2 changes: 1 addition & 1 deletion gui-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.1.0",
"private": true,
"license": "BSD-3-Clause",
"description": "A simple single-click UI to launch a Tari node, wallet and miner",
"description": "A simple single-click UI to launch a Tari node and miner",
"dependencies": {
"@headlessui/react": "^1.5.0",
"@nivo/bar": "^0.79.1",
Expand Down
2 changes: 1 addition & 1 deletion libs/protocol/src/launchpad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub enum Action {
pub enum LaunchpadAction {
Connect,
ChangeSession(LaunchpadSession),
SaveSettings(PersistentSettings),
SaveSettings(Box<PersistentSettings>),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down

0 comments on commit 7206849

Please sign in to comment.