Skip to content

XDC Add sync support for switch boundary#10787

Open
batrr wants to merge 6 commits intomasterfrom
feat/xdc-swtich-sync
Open

XDC Add sync support for switch boundary#10787
batrr wants to merge 6 commits intomasterfrom
feat/xdc-swtich-sync

Conversation

@batrr
Copy link
Contributor

@batrr batrr commented Mar 11, 2026

Changes

  • Add ParseV1Masternodes extension method to XdcExtensions to parse masternodes from V1 headers
  • Add initial V2 snapshot in XdcStateSyncSnapshotManager
  • Add support for the first V2 epoch in XdcRewardCalculator
    Two missing checks for non-zero SwitchBlock: skip SwitchBlock+1 and use v1 masternode parsing if number <= SwitchBlock. With SwitchBlock=0 it worked by accident.

Refer:

Types of changes

What types of changes does your code introduce?

  • Bugfix (a non-breaking change that fixes an issue)
  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a change that causes existing functionality not to work as expected)
  • Optimization
  • Refactoring
  • Documentation update
  • Build-related changes
  • Other: Description

Testing

Requires testing

  • Yes
  • No

If yes, did you write tests?

  • Yes
  • No

@batrr batrr changed the title Add sync support for switch boundary XDC Add sync support for switch boundary Mar 11, 2026
@batrr batrr requested a review from Copilot March 11, 2026 18:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds XDC chain support around the V1→V2 switch boundary so fast-sync snapshot bootstrapping and reward/epoch calculations behave correctly when SwitchBlock != 0.

Changes:

  • Add ParseV1Masternodes to parse masternode addresses from V1-format ExtraData, and reuse it for genesis parsing when SwitchBlock == 0.
  • Bootstrap an initial snapshot when the computed gap lands on the switch boundary.
  • Adjust epoch-switch/reward logic to treat pre-switch blocks as V1 epoch checkpoints and to skip SwitchBlock + 1.

Reviewed changes

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

Show a summary per file
File Description
src/Nethermind/Nethermind.Xdc/XdcStateSyncSnapshotManager.cs Stores an initial snapshot when the gap calculation aligns with SwitchBlock.
src/Nethermind/Nethermind.Xdc/XdcRewardCalculator.cs Skips SwitchBlock+1 and uses V1 masternode parsing for headers <= SwitchBlock.
src/Nethermind/Nethermind.Xdc/XdcExtensions.cs Introduces ParseV1Masternodes helper for V1 ExtraData.
src/Nethermind/Nethermind.Xdc/Spec/XdcChainSpecBasedSpecProvider.cs Uses ParseV1Masternodes to derive genesis masternodes when SwitchBlock == 0.
src/Nethermind/Nethermind.Xdc/EpochSwitchManager.cs Treats pre-switch epoch switches as blockNumber % EpochLength == 0.
src/Nethermind/Nethermind.Xdc.Test/XdcStateSyncSnapshotManagerTests.cs Adds coverage for the “gap lands on switch block” snapshot bootstrapping case.
src/Nethermind/Nethermind.Xdc.Test/ModuleTests/RewardTests.cs Updates reward test setup so block 0 uses V1 ExtraData format when SwitchBlock == 0.
src/Nethermind/Nethermind.Xdc.Test/Helpers/XdcTestHelper.cs Adds helper to build V1-format ExtraData for tests.
src/Nethermind/Nethermind.Xdc.Test/EpochSwitchManagerTests.cs Adds tests for IsEpochSwitchAtBlock behavior pre-switch.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@NethermindEth NethermindEth deleted a comment from Copilot AI Mar 11, 2026
@batrr batrr marked this pull request as ready for review March 12, 2026 06:28
@batrr batrr requested review from Demuirgos, ak88 and cicr99 as code owners March 12, 2026 06:28
return spec;
}

public static Address[] ParseV1Masternodes(this byte[] extraData)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe would be better to make it an extension to BlockHeader? byte[] is a very commonly use object, and this is not really related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants