-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Service's Configuration has optional fields that shouldn't be optional #4776
Comments
I was going to make a new ticket but I think my issue is possible related to this ticket and known. It is currently not possible to disable the substrate/client/service/src/config.rs Lines 75 to 76 in 26e37ff
This appears to be because of: substrate/client/cli/src/lib.rs Lines 637 to 642 in 26e37ff
The Same goes for substrate/client/cli/src/lib.rs Lines 628 to 635 in 26e37ff
|
Is it new? It doesn't look related to my change, the code was there before: substrate/client/cli/src/lib.rs Lines 1072 to 1076 in 1ed1cc5
|
It is not directly related to your latest changes I believe but I thought it might relate to this ticket. If it does not I’ll gladly make a new ticket specifically for the issue that I’m facing.
… Op 30 jan. 2020 om 19:01 heeft Cecile Tonglet ***@***.***> het volgende geschreven:
Is it new? It doesn't look related to my change, the code was there before:
https://github.com/paritytech/substrate/blob/1ed1cc542110aaaee9cf0de87a7c256a1de407c6/client/cli/src/lib.rs#L1072-L1076
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
No no I think you're right, it's definitely related to this ticket. I was just afraid I broke something. The comment really is an indication that it was meant to be an option but clearly it's never None when running a node. |
@TimvanScherpenzeel actually I'm an idiot. The main reason for this refactoring was to allow more flexibility so you can customize at different places how you run the node. So you CAN actually put those values to None if you want. In the most common case, you would use the "run" function to run the node: substrate/bin/node-template/src/command.rs Lines 39 to 46 in 26e37ff
But what this function does is just initializing and running the node: substrate/client/cli/src/lib.rs Lines 245 to 249 in 26e37ff
So what you can do is actually initialized yourself, modify the configuration and then run the node: sc_cli::init(&mut config, spec_factory, &run_cmd.shared_params, version)?;
config.grafana_port = None;
run_cmd.run(config, new_light, new_full, version) |
I got a brilliant idea on how to solve this ticket and the implementation is almost exactly like this crate: https://crates.io/crates/optional_struct but also kinda the opposite:
With this implementation we would have:
|
…t be optional (#4842) Related to #4776 Related to paritytech/polkadot#832 To summarize the changes: 1. I did not manage to validate with types the service's Configuration. But I did reduce the possibility of errors by moving all the "fill" functions to their respective structopts 2. I split params.rs to multiple modules: one module params for just CLI parameters and one module commands for CLI subcommands (and RunCmd). Every command and params are in their own file so things are grouped better together and easier to remove 3. I removed the run and run_subcommand helpers as they are not helping much anymore. Running a command is always a set of 3 commands: 1. init 2. update config 3. run. This still allow the user to change the config before arguments get parsed or right after. 4. I added tests for all subcommands. 5. [deleted] Overall the aim is to improve the situation with the Configuration and the optional parameters, add tests, make the API more consistent and simpler.
@bkchr can you check this private repo here and let me know what you think of it? This is very similar to optional_struct but it does enforce defaults at compile time: Example build output where a default field is missing its default function:
|
…t be optional (paritytech#4842) Related to paritytech#4776 Related to paritytech/polkadot#832 To summarize the changes: 1. I did not manage to validate with types the service's Configuration. But I did reduce the possibility of errors by moving all the "fill" functions to their respective structopts 2. I split params.rs to multiple modules: one module params for just CLI parameters and one module commands for CLI subcommands (and RunCmd). Every command and params are in their own file so things are grouped better together and easier to remove 3. I removed the run and run_subcommand helpers as they are not helping much anymore. Running a command is always a set of 3 commands: 1. init 2. update config 3. run. This still allow the user to change the config before arguments get parsed or right after. 4. I added tests for all subcommands. 5. [deleted] Overall the aim is to improve the situation with the Configuration and the optional parameters, add tests, make the API more consistent and simpler.
Mentioning #5204 which shows that the API is still not good. Note 1: probably enforcing the fields to be required would prevent this situation where database and config_dir are not set. Note 2: optional_struct won't help for this case. |
Following the discussion on: https://github.com/paritytech/substrate/pull/4692/files/bea809d4c14a2ede953227ac885e3b3f9771c548#r372049016
There are 2 conflicting things we would like to have:
The text was updated successfully, but these errors were encountered: