Fix nil metrics panic in VSCC SQL state DB writes#17
Open
krishnanmano wants to merge 1 commit into
Open
Conversation
- pass metricsProvider (not nil) to statesqldb.NewVersionedDBProvider in VSCC server init so registerMetricsOnce.Do actually runs - guard every db.metrics dereference in statesqldb.go with a nil check so ApplyUpdates/GetLatestSavePoint no longer panic when a db handle was built with a nil metrics provider (e.g. snapshot import path) Fixes npci#7
krishnanmano
marked this pull request as ready for review
July 2, 2026 15:27
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.
TL;DR
VSCC initializes its SQL state DB provider with a
nilmetrics provider (statesqldb.NewVersionedDBProvider(..., nil, nil)), soregisterMetricsOnce.Donever runs anddb.metricsstaysnil.ApplyUpdates/GetLatestSavePointthen dereference it unconditionally, panicking on the first block commit on any channel using the standalone VSCC service. Passes the realmetricsProviderthrough at the call site and guards everydb.metricsdereference so a nil provider (e.g. the snapshot-import path, which intentionally passesnil) degrades gracefully instead of crashing.Files to review (2, +25 / -13):
core/vscc/validate.go(start here)NewVersionedDBProviderwas called withnilinstead ofmetricsProvider.core/ledger/kvledger/txmgmt/statedb/statesqldb/statesqldb.godb.metrics.*call inApplyUpdatesandGetLatestSavePointwith a nil check.Reviewer notes
ImportFromSnapshotcallsprovider.newVersionedDB(dbName, nil, nil)on purpose, sodb.metricscan legitimately beniloutside VSCC too — the nil guards keep that path safe even though the VSCC call site is now correct.db.metricsisnil.Links
db.metricspanic on first SQL write via VSCC #7