Repository navigation
feat(statesync): implement statesync spec for the new approach - #663
Merged
shotonoff merged 22 commits intoJul 19, 2023
Merged
Conversation
Co-authored-by: lklimek <[email protected]>
Co-authored-by: lklimek <[email protected]>
Co-authored-by: lklimek <[email protected]>
Member
|
Was told this was already reviewed, so I'm accepting it. |
QuantumExplorer
approved these changes
Jul 19, 2023
lklimek
approved these changes
Jul 19, 2023
PastaPastaPasta
added a commit
that referenced
this pull request
Sep 2, 2026
…omics SnapshotChunksTotal was left on the Metricer interface when the snapshot_chunks_total RPC field was removed in #663; nothing consumes it and chunks are discovered incrementally, so it is not a usable progress denominator. Remove it along with the chunkQueue.TotalChunksCount and snapshotPool.Len plumbing that only existed to serve it. Switch the syncer's lock-free counters to atomic.Int64, matching the evidence pool and p2p rate limiter, so the alignment guarantee is structural rather than by comment. Drop the stale snapshots != nil guard in TotalSnapshots, and make tests read the metrics through the accessors instead of raw fields.
lklimek
added a commit
that referenced
this pull request
Sep 11, 2026
…tus (#1426) * fix(statesync): implement missing Metricer methods and keep metrics after sync The state-sync counters surfaced by the /status RPC were never usable: *statesync.Reactor did not implement SnapshotChunksCount()/SnapshotChunksTotal(), so it silently failed to satisfy the Metricer interface, and the remaining getters read through r.syncer, which syncComplete() nils the moment a sync ends - so even a wired-up reactor would report zeros for the rest of the process lifetime. - Implement SnapshotChunksCount()/SnapshotChunksTotal(), sourced from the syncer's chunk queue while a sync is active (chunks are content-addressed and discovered incrementally, so the total is the number of distinct chunks seen so far), and add a compile-time var _ Metricer assertion so the interface can no longer drift. - Snapshot the sync's final values (total snapshots, avg chunk time, snapshot height, chunk counts) into Reactor fields under r.mtx before syncComplete() drops the syncer; getters read the live syncer during a sync and the snapshot afterwards. The syncer likewise records the queue's final chunk counts before dropping it at the end of Sync(). - Fix data races: backfilledBlocks/backfillBlockTotal were written without r.mtx while the Metricer getters read them under RLock; the writes now take the lock. The syncer's avgChunkTime/lastSyncedSnapshotHeight were similarly read across goroutines; they are now accessed atomically, and TotalSnapshots() now uses a locked pool.Len() instead of reading the pool map directly. Persisting the completed-sync record across process restart is deliberately out of scope: it needs a state-store change, which is a design decision left to maintainers. Co-Authored-By: Claude Fable 5 <[email protected]> * fix(node): wire the statesync reactor into the RPC env as StateSyncMetricer The statesync reactor was constructed and dropped straight into node.services with no reference kept, so env.StateSyncMetricer was never assigned anywhere and /status unconditionally skipped the state-sync counters. Keep a reference and expose it on rpcEnv, mirroring how ConsensusReactor and BlockSyncReactor are wired. Co-Authored-By: Claude Fable 5 <[email protected]> * docs(rpc): remove phantom snapshot_chunks_total field from openapi The SyncInfo Go struct has no snapshot_chunks_total field; the openapi schema documented one that /status never returns. Remove it to match the actual response. Co-Authored-By: Claude Fable 5 <[email protected]> * test(statesync): cover the Metricer surface and /status metrics wiring - TestReactorMetricer exercises every Metricer getter across the sync lifecycle: zeros before any sync, live syncer values during a sync (snapshot pool, chunk queue counts), and persistence of the snapshotted values after releaseChunkQueue and syncComplete drop the syncing objects. - TestReactor_Sync now asserts that a completed end-to-end sync leaves the final metrics readable (snapshot height, snapshot/chunk counts, avg chunk time) after the syncer is gone. - TestStatusStateSyncMetrics verifies /status copies the metrics from a wired StateSyncMetricer into sync_info. All run under go test -race. Co-Authored-By: Claude Fable 5 <[email protected]> * docs(statesync): clarify metric accessor invariants from review Note that syncer.snapshots is set once at construction (why TotalSnapshots reads it without s.mtx), and that the test stub's SnapshotChunksTotal only satisfies the interface since SyncInfo has no such field. Co-Authored-By: Claude Fable 5 <[email protected]> * fix(statesync): count discovered snapshots cumulatively for /status TotalSnapshots previously returned the snapshot pool size, which shrinks on rejections and peer disconnects; a peer leaving between the restore and syncComplete (e.g. during backfill) zeroed the metric this PR exists to fix. Back it with an atomic counter incremented when AddSnapshot accepts a new snapshot, and pin in the metrics test that the value survives emptying the pool. Co-Authored-By: Claude Fable 5 <[email protected]> * test(node): assert the statesync reactor is wired as the RPC StateSyncMetricer Removing the rpcEnv.StateSyncMetricer wiring kept every existing test green; TestNodeStartStop now fails if the /status metrics source is unplugged. Co-Authored-By: Claude Fable 5 <[email protected]> * refactor(statesync): drop unused SnapshotChunksTotal and use typed atomics SnapshotChunksTotal was left on the Metricer interface when the snapshot_chunks_total RPC field was removed in #663; nothing consumes it and chunks are discovered incrementally, so it is not a usable progress denominator. Remove it along with the chunkQueue.TotalChunksCount and snapshotPool.Len plumbing that only existed to serve it. Switch the syncer's lock-free counters to atomic.Int64, matching the evidence pool and p2p rate limiter, so the alignment guarantee is structural rather than by comment. Drop the stale snapshots != nil guard in TotalSnapshots, and make tests read the metrics through the accessors instead of raw fields. * docs(rpc): describe the state sync fields in sync_info These fields carry real values now, and chunk_process_avg_time is a nanosecond duration serialized as a string, which is not guessable from the schema. --------- Co-authored-by: Claude Fable 5 <[email protected]> Co-authored-by: lklimek <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue being fixed or feature implemented
To be able to perform state synchronization in Dash Platform, Tenderdash must be compatible with some restriction of GroveDB.
This PR contains the changes of a new approach state synchonization, that is described in specification
What was done?
How Has This Been Tested?
Unit Tests / E2E tests
Breaking Changes
The original way of replicating state synchronization is obsolete and has been replaced by another approach
Checklist:
For repository code-owners and collaborators only