XDC subnet snapshot manager#10380
Conversation
…ter and update SnapshotManager and SubnetSnapshotManager accordingly. Add unit tests for SubnetSnapshotManager to validate snapshot retrieval and storage behavior.
…r improved readability.
There was a problem hiding this comment.
Pull request overview
This PR introduces a refactoring to support subnet-specific snapshot management alongside the existing main chain snapshot management. It extracts common snapshot manager functionality into a generic base class and creates specialized implementations for main chain and subnet operations.
Changes:
- Refactored
SnapshotManagerto inherit from a new genericBaseSnapshotManager<TSnapshot>base class, extracting common snapshot storage, retrieval, and caching logic - Added
SubnetSnapshotManagerwhich stores penalties in snapshots (calculated at snapshot creation time) rather than computing them dynamically - Introduced
SubnetEpochSwitchManagerwith an overridden penalty resolution method that retrieves penalties fromSubnetSnapshotinstances - Modified
EpochSwitchManagerto add a virtualResolvePenaltiesmethod, enabling subnet-specific penalty handling while maintaining backward compatibility
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| BaseSnapshotManager.cs | New generic base class containing common snapshot management logic including caching, database operations, and the NewHeadBlock event handler |
| SubnetSnapshotManager.cs | Subnet-specific snapshot manager that stores penalties in snapshots at creation time |
| SnapshotManager.cs | Refactored to inherit from BaseSnapshotManager, preserving existing functionality for main chain |
| SubnetEpochSwitchManager.cs | Subnet-specific epoch switch manager that retrieves penalties from SubnetSnapshot |
| EpochSwitchManager.cs | Added virtual ResolvePenalties method to support different penalty resolution strategies |
| SubnetSnapshotManagerTests.cs | Test suite for SubnetSnapshotManager covering basic snapshot operations |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…SnapshotManager to accept penalty handler
…r order and improve test setup
|
@claude review |
|
Claude finished @batrr's task in 3m 10s —— View job Code Review: XDC Subnet Snapshot Manager
OverviewThe PR cleanly extracts common snapshot logic into Issues1. Event handler subscription leak —
|
…s on genesis blocks
Changes
Relevant links
https://github.com/XinFinOrg/XDC-Subnet/blob/master/consensus/XDPoS/engines/engine_v2/snapshot.go#L14-L23
https://github.com/XinFinOrg/XDC-Subnet/blob/master/consensus/XDPoS/engines/engine_v2/engine.go#L1044
https://github.com/XinFinOrg/XDC-Subnet/blob/master/consensus/XDPoS/engines/engine_v2/engine.go#L520-L529
Types of changes
What types of changes does your code introduce?
Testing
Requires testing
If yes, did you write tests?