Skip to content

Commit

Permalink
feat: fix startup bugs
Browse files Browse the repository at this point in the history
1. Wallet

There are 2 extra settings in the wallet config. clear_peer_db, clears
the peer database when configuring the wallet.
This should be true for at least the first run or until
tari-project/tari#5998 is fixed.

`interacive` must be false for the first run, and can be set to true
after that.
Adds a quick fix for the wallet for the non-interactive and peer DB
We only display the instructions for attaching to the docker wallet
instance if interactive is true, and the wallet is active.

bugs.

You can control whether the wallet is non-interactive (default. will run
on first startup), and whether the peer DB is deleted (true. shold let
2. Base node

Similarly to the wallet, there's an `interactive` setting for the base
node now that must be false on the first run.

A future PR should make these editable in the UI.
  • Loading branch information
CjS77 committed Dec 4, 2023
1 parent 5e75297 commit f3b6a1e
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 18 deletions.
21 changes: 15 additions & 6 deletions cli/src/component/normal/wallet/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,22 @@ impl<B: Backend> Component<B> for BalanceWidget {
let table = Table::new(rows)
.widths(&[Constraint::Percentage(40), Constraint::Percentage(60)])
.column_spacing(2);

let help = Paragraph::new(Text::from(
"\
let interactive = state
.state
.config
.settings
.as_ref()
.and_then(|lps| lps.saved_settings.wallet.as_ref())
.map(|w| w.interactive)
.unwrap_or_default();
if interactive && state.state.config.session.is_wallet_active() {
let help = Paragraph::new(Text::from(
"\
To access the full-featured console\nwallet, open a new terminal and run\n\ndocker attach \
stagenet_minotari_console_wallet\n\n",
));
f.render_widget(help, h_chunks[1]);
stagenet_minotari_console_wallet\n\n",
));
f.render_widget(help, h_chunks[1]);
}
f.render_widget(table, v_chunks[0]);
}
}
Expand Down
21 changes: 19 additions & 2 deletions libs/protocol/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,29 @@ http://xmr-lux.boldsuck.org:38081,\
http://singapore.node.xmr.pm:38081";

#[derive(Default, Debug, Serialize, Deserialize, Clone)]
pub struct BaseNodeConfig {}
pub struct BaseNodeConfig {
/// Should node be started in interactive mode.
pub interactive: bool,
}

#[derive(Default, Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct WalletConfig {
/// The password to de/en-crypt the wallet database
pub password: String,
/// Should the peer DB be deleted before starting up. Issue: https://github.com/tari-project/tari/issues/5998
pub clear_peer_db: bool,
/// Should wallet be started in interactive mode.
pub interactive: bool,
}

impl Default for WalletConfig {
fn default() -> Self {
WalletConfig {
password: String::new(),
clear_peer_db: true,
interactive: false,
}
}
}

#[derive(Default, Debug, Serialize, Deserialize, Clone)]
Expand Down
5 changes: 5 additions & 0 deletions libs/sdm-assets/assets/settings.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Local settings for launchpad
tari_network = "Stagenet"

[base_node]
interactive = false

[sha3_miner]
num_mining_threads = 1

Expand All @@ -17,3 +20,5 @@ monero_mining_address = "5AJ8FwQge4UjT9Gbj4zn7yYcnpVQzzkqr636pKto59jQcu85CFsuYVe

[wallet]
password = "tari"
interactive = false
clear_peer_db = true
18 changes: 12 additions & 6 deletions libs/sdm-launchpad/src/resources/images/l2_base_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use anyhow::Error;
use async_trait::async_trait;
use log::debug;
use tari_base_node_grpc_client::{grpc, BaseNodeGrpcClient};
use tari_launchpad_protocol::container::TaskProgress;
use tari_launchpad_protocol::{container::TaskProgress, settings::BaseNodeConfig};
use tari_sdm::{
ids::{ManagedTask, TaskId},
image::{
Expand Down Expand Up @@ -58,6 +58,7 @@ use crate::resources::{
#[derive(Debug, Default)]
pub struct TariBaseNode {
settings: Option<ConnectionSettings>,
config: BaseNodeConfig,
}

impl ManagedTask for TariBaseNode {
Expand Down Expand Up @@ -87,7 +88,13 @@ impl ManagedContainer for TariBaseNode {

fn reconfigure(&mut self, config: Option<&LaunchpadConfig>) -> Option<bool> {
debug!("Reconfiguring base node");
self.settings = ConnectionSettings::try_extract(config?);
let config = config?;
self.config = config
.settings
.as_ref()
.and_then(|s| s.saved_settings.base_node.clone())
.unwrap_or_default();
self.settings = ConnectionSettings::try_extract(config);
let session = &self.settings.as_ref()?.session;
Some(session.is_base_node_active())
}
Expand All @@ -98,11 +105,10 @@ impl ManagedContainer for TariBaseNode {

fn args(&self, args: &mut Args) {
args.set("--log-config", "/var/tari/config/log4rs.yml");
// An id file is only generated if `--init` or `-n` is specified. But the node exits immediately if `--init` is
// specified. So for now, we must run in non-interactive mode to have launchpad work.
// args.flag("--init");
args.flag("-n");
args.set("--watch", "status");
if !self.config.interactive {
args.flag("-n");
}
}

fn envs(&self, envs: &mut Envs) {
Expand Down
41 changes: 37 additions & 4 deletions libs/sdm-launchpad/src/resources/images/l2_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::ops::Deref;

use anyhow::Error;
use async_trait::async_trait;
use log::{debug, error};
use log::*;
use tari_app_grpc::tari_rpc::{ConnectivityStatus, Empty};
use tari_launchpad_protocol::container::TaskProgress;
use tari_sdm::{
Expand Down Expand Up @@ -67,6 +67,27 @@ pub struct TariWallet {
identity: Option<WalletIdentity>,
}

impl TariWallet {
fn delete_peer_db(&self) {
// Only called when settings is Some(.)
let settings = self
.settings
.as_ref()
.expect("`delete_peer_db` must only be called if `self.settings.is_some()`");
let peer_db_path = settings
.data_directory
.join("wallet")
.join(settings.tari_network.lower_case())
.join("peer_db");
if peer_db_path.exists() {
match std::fs::remove_dir_all(peer_db_path) {
Ok(_) => info!("Deleted peer_db"),
Err(e) => error!("Failed to delete peer_db: {e}"),
}
}
}
}

impl ManagedTask for TariWallet {
fn id() -> TaskId {
"Wallet".into()
Expand Down Expand Up @@ -98,8 +119,13 @@ impl ManagedContainer for TariWallet {
self.settings = ConnectionSettings::try_extract(config);
self.wallet = config.settings.as_ref().and_then(|s| s.saved_settings.wallet.clone());
let session = &self.settings.as_ref()?.session;
self.wallet.as_ref()?;
Some(session.is_wallet_active())
self.wallet.as_ref().map(|wallet| {
// Addressing Issue https://github.com/tari-project/tari/issues/5998. Can be removed once fixed.
if wallet.clear_peer_db {
self.delete_peer_db();
}
session.is_wallet_active()
})
}

fn on_event(&mut self, event: LaunchpadInnerEvent) {
Expand Down Expand Up @@ -127,7 +153,14 @@ impl ManagedContainer for TariWallet {
args.set("--log-config", "/var/tari/config/log4rs.yml");
args.set("--seed-words-file", "/var/tari/config/seed_words.txt");
args.flag("--enable-grpc");
// args.flag("-n");
let non_interactive = if let Some(WalletConfig { interactive, .. }) = self.wallet.as_ref() {
!interactive
} else {
true
};
if non_interactive {
args.flag("-n");
}
}

fn envs(&self, envs: &mut Envs) {
Expand Down

0 comments on commit f3b6a1e

Please sign in to comment.