Skip to content

Fix nil metrics panic in VSCC SQL state DB writes#17

Open
krishnanmano wants to merge 1 commit into
npci:mainfrom
krishnanmano:fix/vscc-nil-metrics-panic
Open

Fix nil metrics panic in VSCC SQL state DB writes#17
krishnanmano wants to merge 1 commit into
npci:mainfrom
krishnanmano:fix/vscc-nil-metrics-panic

Conversation

@krishnanmano

Copy link
Copy Markdown

TL;DR

VSCC initializes its SQL state DB provider with a nil metrics provider (statesqldb.NewVersionedDBProvider(..., nil, nil)), so registerMetricsOnce.Do never runs and db.metrics stays nil. ApplyUpdates/GetLatestSavePoint then dereference it unconditionally, panicking on the first block commit on any channel using the standalone VSCC service. Passes the real metricsProvider through at the call site and guards every db.metrics dereference so a nil provider (e.g. the snapshot-import path, which intentionally passes nil) degrades gracefully instead of crashing.

Files to review (2, +25 / -13):

File Why
core/vscc/validate.go (start here) Root cause: NewVersionedDBProvider was called with nil instead of metricsProvider.
core/ledger/kvledger/txmgmt/statedb/statesqldb/statesqldb.go Wraps every db.metrics.* call in ApplyUpdates and GetLatestSavePoint with a nil check.

Reviewer notes

  • Both the root cause and the guard are fixed. ImportFromSnapshot calls provider.newVersionedDB(dbName, nil, nil) on purpose, so db.metrics can legitimately be nil outside VSCC too — the nil guards keep that path safe even though the VSCC call site is now correct.
  • No behavior change on the happy path. When a metrics provider is present, metrics are recorded exactly as before; the guard only skips recording when db.metrics is nil.

Links

- 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
krishnanmano marked this pull request as ready for review July 2, 2026 15:27
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.

Nil db.metrics panic on first SQL write via VSCC

1 participant