Skip to content

fix: fall back to defaults for missing config keys#3893

Open
iho wants to merge 1 commit into
mimblewimble:stagingfrom
iho:fix/config-serde-defaults
Open

fix: fall back to defaults for missing config keys#3893
iho wants to merge 1 commit into
mimblewimble:stagingfrom
iho:fix/config-serde-defaults

Conversation

@iho

@iho iho commented Jul 9, 2026

Copy link
Copy Markdown

Summary

Fixes #3002.

Operators who trim grin-server.toml to only non-default keys hit parse failures for missing fields such as log_to_file, even though the code has sensible defaults.

Change

  • LoggingConfig: #[serde(default)] + field defaults matching Default (so omitting log_to_filetrue, etc.)
  • ConfigMembers: optional logging / config_file_version with serde default
  • ServerConfig / StratumServerConfig: missing keys use the same values as Default

Minimal configs can now omit keys safely; present keys still override.

Test plan

  • cargo test -p grin_config -- --test-threads=1 (9 passed), including:
    • test_logging_config_missing_keys_use_defaults
    • test_logging_section_optional
    • test_stratum_partial_config_defaults

Allow omitting non-required keys such as log_to_file without parse
failure. LoggingConfig, ServerConfig, StratumServerConfig, and
ConfigMembers now use serde defaults aligned with Default impls.

Addresses mimblewimble#3002.
@wiesche89
wiesche89 self-requested a review July 11, 2026 13:06
Comment thread config/src/types.rs
pub server: ServerConfig,
/// Logging config
/// Logging config (optional section; missing keys use LoggingConfig defaults)
#[serde(default)]

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 missing logging section now becomes None, but node startup still calls .logging.clone().unwrap(). The minimal config therefore parses and then panics. Should this default to Some(LoggingConfig::default()) instead?

///
/// Missing optional keys fall back to [`Default`] (see #3002).
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(default)]

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.

These are always the mainnet defaults. A trimmed testnet or usernet config therefore misses the network-specific API, P2P, and stratum values from GlobalConfig::for_chain(). Could we apply defaults for the selected chain instead?

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.

With these defaults, a misspelled key can be silently ignored and replaced by its default, which is risky for settings such as archive_mode. Could we reject or at least report unknown fields?

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.

2 participants