Implement clear methodology for config validation checking #3370
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR establishes a clear, consistent methodology for where config validation checks should be placed in the Nitro codebase, resolving the confusion between validation logic scattered across config parsing and node creation phases.
Problem
Previously, config validation checks were inconsistently placed across two main areas:
cmd/nitro/nitro.go
during config parsing and CLI initializationarbnode/node.go
during actual node creationThis created confusion about where different types of validation should be placed and could lead to duplicated or inconsistent validation logic.
Solution
Implemented a three-tier validation methodology with clear guidelines:
1. Component-Level Validations
Location: Individual config struct
Validate()
methodsPurpose: Validate single component configuration consistency
Example: Field value ranges, internal component consistency
2. Cross-Component Validations
Location: Top-level config
Validate()
methodsPurpose: Validate configuration consistency across multiple components
Example: Validator + path scheme compatibility, archive mode warnings
3. Runtime/Environmental Validations
Location: Node creation functions (
createNodeImpl()
and helpers)Purpose: Validate configuration against runtime environment and external dependencies
Example: Network connectivity, file system permissions, external service availability
Key Changes
MessagePrunerConfig.Validate()
- Example of component-level validation with proper error handlingNodeConfig.Validate()
- Added cross-component validation for archive mode consistencyVALIDATION_METHODOLOGY.md
anddocs/CONFIG_VALIDATION_GUIDE.md
Benefits
✅ Clarity - Developers know exactly where to place validation logic
✅ Performance - Expensive runtime checks happen only when necessary
✅ Maintainability - Validations are logically grouped and easy to find
✅ Testability - Each validation type can be tested independently
✅ User Experience - Users get validation feedback at the appropriate time
Implementation Status
Analysis shows that most of the codebase already follows this methodology:
BatchPosterConfig.Validate()
,MaintenanceConfig.Validate()
, etc.NodeConfig.Validate()
createNodeImpl()
for connectivity and resource checksThis PR formalizes the approach with clear documentation and examples for future development.
Fixes #503.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.