-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow using a toml config file #429
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution. In addition to the inline comments, please also check out the TODO below.
TODO
- Update the README.md to mention that a config file can now be used, what format it has to be, and show a sample of how to use it.
@@ -176,6 +178,7 @@ pub fn cli() -> Command { | |||
let cmd = Command::new("kaspad") | |||
.about(format!("{} (rusty-kaspa) v{}", env!("CARGO_PKG_DESCRIPTION"), version())) | |||
.version(env!("CARGO_PKG_VERSION")) | |||
.arg(arg!(-C --configfile <CONFIG_FILE> "Path of config file.")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created a config.toml
file and tried these params as they are the ones I would use for testnet-11:
testnet=true
utxoindex=true
disable-upnp=true
perf-metrics=true
unsaferpc=true
appdir = "tn11-test"
netsuffix=11
loglevel="info,kaspad_lib::daemon=trace"
appdir
seems to be set, but the rest aren't getting set properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, now that I've tested it more thoroughly it appears that defaults take precedence if exist and clap's get_one()
always return Some(default)
so unwrap_or()
didn't work like I'd expect.
I made a kinda hacky fix for it, it's possible that a refactor for the Args
struct so that it's auto parsed using clap's Parser
derive macro can be a prettier solution but I didn't want make so many changes.
kaspad/src/args.rs
Outdated
|
||
if let Some(config_file) = m.get_one::<String>("configfile") { | ||
let config_str = fs::read_to_string(config_file)?; | ||
defaults = from_str(&config_str).map_err(|_| clap::Error::new(clap::error::ErrorKind::ValueValidation))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When there's a problem with the config file, the error is only error: invalid value for one of the arguments
. Can this be updated so that the error is more descriptive of which config value needs to be fixed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the parsing of the config is now stricter and provides better errors, like:
error: failed parsing config file, reason: unknown field `blahblah`, expected one of `appdir`, `logdir`, `no-log-files`, `rpclisten`, `rpclisten-borsh`, `rpclisten-json`, `unsafe-rpc`, `wrpc-verbose`, `log-level`, `async-threads`, `connect-peers`, `add-peers`, `listen`, `user-agent-comments`, `utxoindex`, `reset-db`, `outbound-target`, `inbound-limit`, `rpc-max-clients`, `enable-unsynced-mining`, `enable-mainnet-mining`, `testnet`, `testnet-suffix`, `devnet`, `simnet`, `archival`, `sanity`, `yes`, `externalip`, `perf-metrics`, `perf-metrics-interval-sec`, `block-template-cache-lifetime`, `disable-upnp`, `disable-dns-seeding`, `disable-grpc`, `ram-scale`
cd6ad98
to
25abd10
Compare
kaspad/src/args.rs
Outdated
@@ -74,7 +76,7 @@ pub struct Args { | |||
impl Default for Args { | |||
fn default() -> Self { | |||
Self { | |||
appdir: Some("datadir".into()), | |||
appdir: None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this change necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a residual from testing the defaults issue, reverted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing again with this new config file:
testnet=true
utxoindex=true
disable-upnp=true
perf-metrics=true
unsafe-rpc=true
appdir = "../tn11-test"
testnet-suffix=11
log-level="info,kaspad_lib::daemon=trace"
And it's now using all the params.
README.md
Outdated
# or | ||
cargo run --release --bin kaspad -- -C /path/to/configfile.toml | ||
``` | ||
The config file should be a list of \<CLI argument\> = \<value\> seperated by newlines. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments:
"seperated by newlines. for example:" -> "separated by newlines. For example:"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
With the change from kaspanet#429 the defaults are now used whenever no value is passed to cli args. appdir default value used to not matter, but now if it's set it makes the datadir be inside the current directory
With the change from #429 the defaults are now used whenever no value is passed to cli args. appdir default value used to not matter, but now if it's set it makes the datadir be inside the current directory
* allow using a toml config file * linting fix, serde lowercase WrpcNetAddress * Fix handling of defaults, strict deserialize of config file + error message * Update README * Revert debug default, README fixes
With the change from kaspanet#429 the defaults are now used whenever no value is passed to cli args. appdir default value used to not matter, but now if it's set it makes the datadir be inside the current directory
* allow using a toml config file * linting fix, serde lowercase WrpcNetAddress * Fix handling of defaults, strict deserialize of config file + error message * Update README * Revert debug default, README fixes
With the change from kaspanet#429 the defaults are now used whenever no value is passed to cli args. appdir default value used to not matter, but now if it's set it makes the datadir be inside the current directory
* allow using a toml config file * linting fix, serde lowercase WrpcNetAddress * Fix handling of defaults, strict deserialize of config file + error message * Update README * Revert debug default, README fixes
* allow using a toml config file * linting fix, serde lowercase WrpcNetAddress * Fix handling of defaults, strict deserialize of config file + error message * Update README * Revert debug default, README fixes
With the change from kaspanet#429 the defaults are now used whenever no value is passed to cli args. appdir default value used to not matter, but now if it's set it makes the datadir be inside the current directory
resolves #418