Fix statedb errors silently swallowed in multi-key queries#5529
Open
Atishyy27 wants to merge 1 commit into
Open
Fix statedb errors silently swallowed in multi-key queries#5529Atishyy27 wants to merge 1 commit into
Atishyy27 wants to merge 1 commit into
Conversation
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>
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.
What's wrong
GetStateMultipleKeysandGetPrivateDataMultipleKeysincore/ledger/kvledger/txmgmt/txmgr/query_executor.goboth discard theunderlying statedb error and return
(nil, nil)instead of propagating it:The identical pattern appears in
GetPrivateDataMultipleKeysa few linesdown. Every other error path in this file correctly does
return nil, err(see
GetPrivateDataMetadataByHashright above it, for example) — these twoare 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 minimalstatedb.VersionedDBfake that returns a fixed error, wired throughprivacyenabledstate.DBso the realquery_executorcode path isexercised 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
nilinstead) and pass after the two-line fix.go build ./...andgofmt -lboth clean on the changed files.