Skip to content

feat(core,cmd,eth,docs): handle chain config mismatch by cli flag#2443

Open
gzliudan wants to merge 1 commit into
XinFinOrg:dev-upgradefrom
gzliudan:handle-mismatch-chain-config
Open

feat(core,cmd,eth,docs): handle chain config mismatch by cli flag#2443
gzliudan wants to merge 1 commit into
XinFinOrg:dev-upgradefrom
gzliudan:handle-mismatch-chain-config

Conversation

@gzliudan

@gzliudan gzliudan commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Proposed changes

Replace unconditional rewind-on-mismatch startup behavior with an explicit chain config mismatch policy exposed through --chain-config-mismatch-policy and ethconfig.Config.ChainConfigMismatchPolicy.

Behavior

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. Readonly opens reject policies that would require rewinds or writes.

Changes

  • Thread the selected policy through CLI/config resolution and blockchain startup.
  • Add validation and normalization for mismatch policy values.
  • Update operator-facing error messages for readonly startup failures.
  • Document the new startup behavior in the upgrade notes.

Types of changes

What types of changes does your code introduce to XDC network?
Put an in the boxes that apply

  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Changes that don't change source code or tests
  • docs: Documentation only changes
  • feat: A new feature
  • fix: A bug fix
  • perf: A code change that improves performance
  • refactor: A code change that neither fixes a bug nor adds a feature
  • revert: Revert something
  • style: Changes that do not affect the meaning of the code
  • test: Adding missing tests or correcting existing tests

Impacted Components

Which parts of the codebase does this PR touch?
Put an in the boxes that apply

  • Consensus
  • Account
  • Network
  • Geth
  • Smart Contract
  • External components
  • Not sure (Please specify below)

Checklist

Put an in the boxes once you have confirmed below actions (or provide reasons on not doing so) that

  • This PR has sufficient test coverage (unit/integration test) OR I have provided reason in the PR description for not having test coverage
  • Tested on a private network from the genesis block and monitored the chain operating correctly for multiple epochs.
  • Provide an end-to-end test plan in the PR description on how to manually test it on the devnet/testnet.
  • Tested the backwards compatibility.
  • Tested with XDC nodes running this version co-exist with those running the previous version.
  • Relevant documentation has been updated as part of this PR
  • N/A

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5ae5cc0f-ba27-4667-a826-67934fbc22bd

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 and newBlockChain mismatch 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

Comment thread core/blockchain.go Outdated
Comment thread core/blockchain.go Outdated
@gzliudan gzliudan force-pushed the handle-mismatch-chain-config branch 2 times, most recently from 3a2de87 to 630e754 Compare July 8, 2026 08:17
@gzliudan gzliudan requested a review from Copilot July 8, 2026 08:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • eth/ethconfig/gen_config.go: Generated file

Comment thread core/chain_config_mismatch_policy.go Outdated
@gzliudan gzliudan force-pushed the handle-mismatch-chain-config branch 2 times, most recently from f69fe8e to 362aa4c Compare July 8, 2026 09:13
@gzliudan gzliudan changed the title feat(core,cmd,eth,docs): add chain config mismatch policy feat(core,cmd,eth,docs): handle chain config mismatch by cli flag Jul 8, 2026
@gzliudan gzliudan force-pushed the handle-mismatch-chain-config branch 4 times, most recently from dd75dc6 to dbb0a1d Compare July 9, 2026 01:16
@gzliudan gzliudan requested a review from wanwiset25 July 9, 2026 07:21
@gzliudan gzliudan force-pushed the handle-mismatch-chain-config branch 8 times, most recently from 54c3d0a to 80e3f92 Compare July 10, 2026 01:15
@gzliudan gzliudan requested a review from Copilot July 10, 2026 01:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 14 changed files in this pull request and generated 2 comments.

Files not reviewed (1)
  • eth/ethconfig/gen_config.go: Generated file

Comment thread cmd/utils/cmd.go Outdated
Comment thread cmd/utils/flags_test.go
@gzliudan gzliudan force-pushed the handle-mismatch-chain-config branch 7 times, most recently from f6194a8 to dd87482 Compare July 10, 2026 12:12
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.
@gzliudan gzliudan force-pushed the handle-mismatch-chain-config branch from dd87482 to 23eb167 Compare July 11, 2026 08:02
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.

3 participants