feat(core,cmd,eth,docs): handle chain config mismatch by cli flag#2443
feat(core,cmd,eth,docs): handle chain config mismatch by cli flag#2443gzliudan wants to merge 1 commit into
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR introduces an explicit chain config mismatch startup policy to replace the previous implicit behavior that would unconditionally rewind and persist updated ChainConfig when incompatibilities are detected. The policy is operator-controlled via --chain-config-mismatch-policy and a ChainConfigMismatchPolicy TOML setting, and is threaded through core blockchain open paths, CLI/config resolution, tests, and upgrade documentation.
Changes:
- Add
core.ChainConfigMismatchPolicy(with parsing/validation) and thread it through resolved blockchain constructors andnewBlockChainmismatch handling. - Expose the policy through CLI flag + TOML config plumbing, and ensure CLI vs config precedence is deterministic.
- Update operator docs and adjust/extend tests to cover parsing, policy resolution, and new error surfaces/messages.
Reviewed changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| eth/ethconfig/gen_config.go | Adds TOML marshal/unmarshal support for ChainConfigMismatchPolicy in eth config codec. |
| eth/ethconfig/config.go | Introduces ChainConfigMismatchPolicy in ethconfig.Config and sets a default from core. |
| eth/backend.go | Passes configured mismatch policy into resolved blockchain open path. |
| docs/upgrade.md | Documents the new policy options, defaults, and operational guidance. |
| core/chain_config_mismatch_policy.go | New core policy type + normalize/parse/validate helpers. |
| core/chain_config_mismatch_policy_test.go | Unit tests for policy normalization/parsing behavior. |
| core/blockchain.go | Threads policy through open config, adds readonly update error, and applies policy-specific mismatch behavior. |
| core/blockchain_test.go | Updates constructor call sites and adds coverage for invalid policy rejection. |
| cmd/XDC/main.go | Wires the new CLI flag into the main command flag set. |
| cmd/XDC/genesis_startup_test.go | Updates startup/export tests for new default behavior and adds args plumbing for console startup. |
| cmd/XDC/chaincmd.go | Ensures chain subcommands pass the configured policy into utils.MakeChain. |
| cmd/utils/flags.go | Defines the new flag, resolves CLI-vs-config precedence, formats new operator-facing errors, and passes policy into blockchain open. |
| cmd/utils/flags_test.go | Updates tests for new messages and adds tests for policy resolution precedence and invalid values. |
Files not reviewed (1)
- eth/ethconfig/gen_config.go: Generated file
3a2de87 to
630e754
Compare
f69fe8e to
362aa4c
Compare
dd75dc6 to
dbb0a1d
Compare
54c3d0a to
80e3f92
Compare
f6194a8 to
dd87482
Compare
Replace unconditional rewind-on-mismatch with an explicit chain-config mismatch policy exposed via --chain-config-mismatch-policy and ethconfig.Config.ChainConfigMismatchPolicy. Supported policies: - exit (default): fail fast without mutating the database. - rewind-and-update: rewind to compatErr.RewindTo and persist the resolved config. - update-config-only: persist the resolved config without rewinding. - ignore-mismatch: keep the in-memory config and skip database writes. Writable opens preserve the selected recovery mode, while readonly opens reject policies that would require rewinds or writes. The CLI resolves the policy from config or flag, threads it through MakeChain, and documents the new operator-facing startup behavior.
dd87482 to
23eb167
Compare
Proposed changes
Replace unconditional rewind-on-mismatch startup behavior with an explicit chain config mismatch policy exposed through
--chain-config-mismatch-policyandethconfig.Config.ChainConfigMismatchPolicy.Behavior
Supported policies:
exit(default): fail fast without mutating the database.rewind-and-update: rewind tocompatErr.RewindToand persist the resolved config.update-config-only: persist the resolved config without rewinding.ignore-mismatch: keep the in-memory config and skip database writes.Writable opens preserve the selected recovery mode. Readonly opens reject policies that would require rewinds or writes.
Changes
Types of changes
What types of changes does your code introduce to XDC network?
Put an
✅in the boxes that applyImpacted Components
Which parts of the codebase does this PR touch?
Put an
✅in the boxes that applyChecklist
Put an
✅in the boxes once you have confirmed below actions (or provide reasons on not doing so) that