Skip to content

Add setup wizard binary - #92

Merged
rustaceanrob merged 1 commit into
kernel-node:masterfrom
rustaceanrob:wizard
Aug 1, 2026
Merged

Add setup wizard binary#92
rustaceanrob merged 1 commit into
kernel-node:masterfrom
rustaceanrob:wizard

Conversation

@rustaceanrob

Copy link
Copy Markdown
Contributor

Closes #91

Common configuration options can be set via this setup program that prompts the user. This uses the existing libc dependency for raw mode in the terminal.

@rustaceanrob rustaceanrob mentioned this pull request Jul 31, 2026

@pzafonte pzafonte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mostly thew some odd inputs at the prompts.

Otherwise, good to have a wizard guided setup!

Comment thread src/bin/wizard.rs Outdated

println!();
println!("{YELLOW}Run:{RESET}");
println!(" {GREEN}cargo {}{RESET}", args.join(" "));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A datadir with spaces silently runs against a truncated path. Perhaps quote each arg with a single-quote?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing with ~/My Node is creating the 'My Node' folder in my home directory. Maybe this is a Linux/MacOS discrepancy in the PathBuf type?

@pzafonte pzafonte Aug 1, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, cold card related stuff ate my day yesterday so I didn't get to suggesting fixes. Also my comment wasn't clear on this, I meant the printed string, not the args passed to Command. Typed bare, ~/My Node works when the wizard launches the node itself, since Command::args passes it as one argv entry, it's only the printed line that splits when pasted. It's also worth noting that path expansion can also introduce spaces the user never typed.

Here's a suggestion...

Suggested change
println!(" {GREEN}cargo {}{RESET}", args.join(" "));
let printable: Vec<Cow<'_, str>> = args.iter().map(|a| shell_quote(a)).collect();
println!(" {GREEN}cargo {}{RESET}", printable.join(" "));
use std::borrow::Cow;

fn shell_quote(arg: &str) -> Cow<'_, str> {
    let safe = |c: char| c.is_ascii_alphanumeric() || "-_./=:,@+~".contains(c);
    if !arg.is_empty() && arg.chars().all(safe) {
        Cow::Borrowed(arg)
    } else {
        Cow::Owned(format!("'{}'", arg.replace('\'', r"'\''")))
    }
}

Each arg is printed bare if it's made only of characters a shell already treats literally, otherwise I am wrapping them in single quotes:

signet                     -> signet
--daemon=true              -> --daemon=true
~/.kernel-node             -> ~/.kernel-node
/tmp/kn demo               -> '/tmp/kn demo'
/tmp/$HOME/keys.bin        -> '/tmp/$HOME/keys.bin'
/home/me/o'brien/keys.bin  -> '/home/me/o'\''brien/keys.bin'

I put single quotes on something like $HOME so it stays literal instead of expanding. I put ~ in the bare set because quoting it would suppress expansion and make the default datadir look broken, but that's a judgement call on my part, I think it's correct either way. The last one is an awkward case. You can't nest a single quote, so it closes, emits an escaped one, and reopens.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, applied that suggestion in the latest push. Sorry about the coldcard debacle. In fact, I was gonna open and issue to potentially bump our rand and make explicit we are using the SysRng, which internally uses the getrandom syscall on the Linux kernel. This syscall uses entropy generated from different sources like CPU temperature, mouse clicks, etc and is believed to be CSRNG

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, I was gonna open and issue to potentially bump our rand and make explicit we are using the SysRng, which internally uses the getrandom syscall on the Linux kernel. This syscall uses entropy generated from different sources like CPU temperature, mouse clicks, etc and is believed to be CSRNG

Agreed, was thinking about that & related matters as well.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was gonna open and issue to potentially bump our rand and make explicit we are using the SysRng

which crate are you referring to? I noticed the wallet uses rand via secp:
let mut rng = bitcoin::secp256k1::rand::thread_rng();

I don't see rand in the node crate though..

@rustaceanrob rustaceanrob Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, rand is the correct crate, just an older version. thread_rng is considered secure. The propose of the refactor would be to make it abundantly clear to ourselves and others that the source is CSRNG. The current state of the rand book recommends:

let rng = StdRng::try_from_rng(&mut SysRng).unwrap();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I created this PR last year (in october) to bump rand from 0.8 to 0.9 p2pderivatives/rust-bitcoin-coin-selection#234 for the coin-selection crate. Cant remember why, but the PR switches from thread_rng to rng it looks like.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, I think you would want to open an issue on the secp256k1 crate to bump the rand dep there? Although it looks like master is on 0.9.x for rand.

Comment thread src/bin/wizard.rs Outdated
@rustaceanrob
rustaceanrob force-pushed the wizard branch 2 times, most recently from 4ebde34 to 58f25b5 Compare August 1, 2026 08:32
@pzafonte

pzafonte commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

ACK 76a809d

@rustaceanrob
rustaceanrob merged commit 9845eac into kernel-node:master Aug 1, 2026
2 checks passed
@rustaceanrob
rustaceanrob deleted the wizard branch August 1, 2026 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add startup wizard

3 participants