Dynamic Node Configuration
Modify node configuration files on-the-fly during testnet generation.
Dynamic Node Configuration is a feature of the marood testnet command that allows developers to override default settings in the config.toml file for each generated node. By passing a comma-separated list of key-value pairs, you can customize parameters like consensus timeouts, logging levels, or P2P settings without manually editing files after creation.
Usage
The feature is accessed via the
Syntax:
--config-changes flag when running marood testnet. The value is a string containing one or more overrides. Multiple overrides are separated by commas.Syntax:
"path.to.key=value,another.key=value"- Nested Keys: Use dot notation for nested fields (e.g.,
consensus.timeout_commit=1s). - Top-Level Keys: Use the key directly for top-level fields (e.g.,
log_level="debug"). - String Slices: For fields that accept a list of strings, provide a comma-separated list within the value (e.g.,
p2p.persistent_peers="id1@host1:port1,id2@host2:port2").
Example
To create a testnet where the commit timeout is reduced to 1 second and the log level is set to debug, you would use the following flag:
This will apply these changes to the
marood testnet -v 2 --config-changes "consensus.timeout_commit=1s,log_level=debug"This will apply these changes to the
config.toml file of every node generated by the command.Implementation Details
The
testnet_utils.go file contains the logic for this feature. It parses the string provided to the flag, splitting it by commas into individual overrides. For each override, it splits the key and value at the = sign. It then uses reflection to traverse the CometBFT Config struct, locate the target field based on its mapstructure tag or name, and set its value. The utility supports various data types, including strings, booleans, integers, and time.Duration, automatically parsing the value string into the correct type.Use Cases
This feature is particularly useful for:
- Stress Testing: Drastically reducing block times (
consensus.timeout_commit) to test network performance under high load. - Debugging: Increasing log verbosity (
log_level) to get more detailed output when troubleshooting issues. - Simulating Network Conditions: Customizing P2P settings like
max_num_inbound_peersorsend_rateto simulate different network topologies or constraints.