Skip to content

Fix statedb errors silently swallowed in multi-key queries#5529

Open
Atishyy27 wants to merge 1 commit into
hyperledger:mainfrom
Atishyy27:fix/query-executor-swallowed-statedb-error
Open

Fix statedb errors silently swallowed in multi-key queries#5529
Atishyy27 wants to merge 1 commit into
hyperledger:mainfrom
Atishyy27:fix/query-executor-swallowed-statedb-error

Conversation

@Atishyy27

Copy link
Copy Markdown

What's wrong

GetStateMultipleKeys and GetPrivateDataMultipleKeys in
core/ledger/kvledger/txmgmt/txmgr/query_executor.go both discard the
underlying statedb error and return (nil, nil) instead of propagating it:

versionedValues, err := q.txmgr.db.GetStateMultipleKeys(ns, keys)
if err != nil {
    return nil, nil   // should be: return nil, err
}

The identical pattern appears in GetPrivateDataMultipleKeys a few lines
down. Every other error path in this file correctly does return nil, err
(see GetPrivateDataMetadataByHash right above it, for example) — these two
are the only ones that swallow it.

Why it matters

If the state database fails while resolving a multi-key read (as invoked
from chaincode via these two query executor methods), the ledger currently
reports success with an empty/nil result instead of surfacing the failure.
A caller has no way to distinguish "no data" from "the read actually
failed," which can let a chaincode invocation proceed on the wrong
assumption.

Fix

Propagate the error on both paths, matching every other branch in the file.

Testing

Added a regression test for each function
(TestGetStateMultipleKeysPropagatesDBError,
TestGetPrivateDataMultipleKeysPropagatesDBError) using a minimal
statedb.VersionedDB fake that returns a fixed error, wired through
privacyenabledstate.DB so the real query_executor code path is
exercised end to end (not the underlying leveldb/couchdb implementation).

Verified both tests fail against the pre-fix code (asserting an error is
returned, they got nil instead) and pass after the two-line fix.

go test ./core/ledger/kvledger/txmgmt/txmgr/... -run "TestGetStateMultipleKeysPropagatesDBError|TestGetPrivateDataMultipleKeysPropagatesDBError" -v
--- PASS: TestGetStateMultipleKeysPropagatesDBError (0.00s)
--- PASS: TestGetPrivateDataMultipleKeysPropagatesDBError (0.00s)

go build ./... and gofmt -l both clean on the changed files.

GetStateMultipleKeys and GetPrivateDataMultipleKeys both discarded the
underlying statedb error and returned (nil, nil) instead of propagating
it, on the exact same line pattern in both functions. Every other error
path in this file correctly returns (nil, err).

The practical effect: if the state database fails while resolving a
multi-key read (GetStateMultipleKeys or GetPrivateDataMultipleKeys, as
called from chaincode), the ledger reports success with zero values
instead of surfacing the failure, so a caller cannot tell "no data" from
"the read actually failed."

Added a regression test for each function using a minimal statedb.VersionedDB
fake that returns a fixed error, wired through privacyenabledstate.DB so the
real query_executor code path is exercised end to end.

Signed-off-by: Atishyy27 <142108881+Atishyy27@users.noreply.github.com>
@Atishyy27
Atishyy27 requested a review from a team as a code owner July 22, 2026 11:28
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.

1 participant