StratisBitcoinFullNode
StratisBitcoinFullNode copied to clipboard
Modular configuration file instead of having hard coded default values around whole solution.
Problem
Right now some of the constants are hard coded and it's impossible to configure them. The other part is configurable and their default values are specified inside the GetOrDefault statement, example:
this.Stake = config.GetOrDefault<bool>("stake", false);
This way it's really hard to keep track of where which default values are defined and it's not obvious which values can be configured and which not.
Suggested solution
Having a json configuration file could solve those problems. Making it partial will allow setting default values inside the projects those values belong to. Also we won't need to create a huge config file in case we're making a light node that don't need config values specified in features that were not included. Using this approach will make it simple and clear where default value is set and what it is.
//File with this class will be stored in the base feature project.
public partial class ModularConfig
{
private ModularConfig()
{
}
// this will allow user to override config values with the command line arguments
// without the need to actually edit the config file.
public static ModularConfig LoadConfig(string path, string[] args)
{
...
}
[JsonProperty(PropertyName = "baseFeatureConfiguration")]
public BaseFeatureConfig BaseFeatureConfig = new BaseFeatureConfig();
}
public class BaseFeatureConfig
{
....
}
//File with this class will be stored in the RPC feature project.
public partial class ModularConfig
{
[JsonProperty(PropertyName = "rpcConfiguration")]
public RPCConfig RPCConfig = new RPCConfig();
}
public class RPCConfig
{
[JsonProperty(PropertyName = "rpcport")]
public int RPCPort = 16888;
...
}
////File with this class will be stored in the Miner feature project.
public partial class ModularConfig
{
[JsonProperty(PropertyName = "minerConfiguration")]
public MinerConfig MinerConfig = new MinerConfig();
}
public class MinerConfig
{
[JsonProperty(PropertyName = "stake")]
public bool Stake = false;
...
}
This way we will keep all the advantages of the old configuration solution but also make it much easier to add new configurable values, trace default settings and will allow to keep all values organized in one place instead of spreading it across the whole codebase.
Thanks @noescape00. I've had this task to do on Trello for a few weeks now but haven't got round to do it yet. I think we decided on another approach, but I'll review your proposal in more depth.
@bokobza ok, didn't know that there was already a task for that. Feel free to close this issue if you consider decided approach better then this one.
@bokobza what's the status of this? Would you mind if I took a look?
what's the status of this?
No one is working on this. Since the issue was created we've moved a bit towards modularity and now for each component we have [ComponentName]Settings file.
Imho this is low priority atm given that we are doing a big refactoring/rewriting on a full node, but it will be nice to have it implemented.