{"record":{"id":"7baccae51f947b4b","repo":"hyperledger/fabric","slug":"could-not-retrieve-state-for-chaincode-s","errorCode":null,"errorMessage":"could not retrieve state for chaincode %s","messagePattern":"could not retrieve state for chaincode (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/scc/lscc/lscc.go","lineNumber":258,"sourceCode":"\t// peer on the other hand might have created a deploy\n\t// transaction that attempts to bypass the instantiation\n\t// policy. This check is there to ensure that this will not\n\t// happen, i.e. that the peer will refuse to invoke the\n\t// chaincode under these conditions. More info on\n\t// https://jira.hyperledger.org/browse/FAB-3156\n\tif fsData.InstantiationPolicy != nil {\n\t\tif !bytes.Equal(fsData.InstantiationPolicy, cd.InstantiationPolicy) {\n\t\t\treturn fmt.Errorf(\"Instantiation policy mismatch for cc %s\", cd.ChaincodeID())\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (lscc *SCC) ChaincodeEndorsementInfo(channelID, chaincodeName string, qe ledger.SimpleQueryExecutor) (*lifecycle.ChaincodeEndorsementInfo, error) {\n\tchaincodeDataBytes, err := qe.GetState(\"lscc\", chaincodeName)\n\tif err != nil {\n\t\treturn nil, errors.Wrapf(err, \"could not retrieve state for chaincode %s\", chaincodeName)\n\t}\n\n\tif chaincodeDataBytes == nil {\n\t\treturn nil, errors.Errorf(\"chaincode %s not found\", chaincodeName)\n\t}\n\n\tchaincodeData := &ccprovider.ChaincodeData{}\n\terr = proto.Unmarshal(chaincodeDataBytes, chaincodeData)\n\tif err != nil {\n\t\treturn nil, errors.Wrapf(err, \"chaincode %s has bad definition\", chaincodeName)\n\t}\n\n\tls := &LegacySecurity{\n\t\tSupport:      lscc.Support,\n\t\tPackageCache: &lscc.PackageCache,\n\t}\n\n\terr = ls.SecurityCheckLegacyChaincode(chaincodeData)","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/scc/lscc/lscc.go#L240-L276","documentation":"ChaincodeEndorsementInfo wraps ledger errors with this message when qe.GetState(\"lscc\", chaincodeName) itself fails (a state-retrieval error, not a missing key). It distinguishes 'could not read the ledger' from 'chaincode not found' — the wrapped err carries the storage-level cause.","triggerScenarios":"Calling ChaincodeEndorsementInfo when the underlying query executor's GetState returns a non-nil error — e.g. ledger/database I/O failure, iterator problems, or transient state-DB issues while reading the lscc namespace.","commonSituations":"CouchDB/LevelDB connectivity problems; state database corruption; querying during ledger maintenance or while the state DB is being rebuilt.","solutions":["Inspect the wrapped error for the state-DB failure cause","Check the peer logs and state database (LevelDB/CouchDB) health","Retry once the ledger/state DB is healthy — this is typically a transient or environmental failure","If the DB is corrupt, rebuild the state database from the blockchain"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Go: probe state availability first\nif _, err := qe.GetState(\"lscc\", chaincodeName); err != nil {\n    // state DB currently failing; defer the call until healthy\n    return fmt.Errorf(\"lscc state unavailable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"// Go\ninfo, err := lscc.ChaincodeEndorsementInfo(channelID, name, qe)\nif err != nil && strings.Contains(err.Error(), \"could not retrieve state for chaincode\") {\n    // transient ledger failure: back off and retry\n    time.Sleep(retryDelay)\n    info, err = lscc.ChaincodeEndorsementInfo(channelID, name, qe)\n}","preventionTips":["Monitor state DB (LevelDB/CouchDB) health on validating peers","Add bounded retry with backoff for ledger read errors","Keep disk space and DB connections healthy; alert on state-DB errors in peer logs","Distinguish read-failure vs not-found errors when handling ChaincodeEndorsementInfo results"],"tags":["hyperledger-fabric","ledger","state-retrieval","lscc"],"backgroundTag":"ledger-state-read-failed","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}