{"record":{"id":"76a3a51cf6d09039","repo":"hyperledger/fabric","slug":"nil-ledger-instance","errorCode":null,"errorMessage":"nil ledger instance","messagePattern":"nil ledger instance","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/committer/txvalidator/v14/vscc_validator.go","lineNumber":291,"sourceCode":"\nfunc (v *VsccValidatorImpl) VSCCValidateTxForCC(ctx *Context) error {\n\tlogger.Debug(\"Validating\", ctx, \"with plugin\")\n\terr := v.pluginValidator.ValidateWithPlugin(ctx)\n\tif err == nil {\n\t\treturn nil\n\t}\n\t// If the error is a pluggable validation execution error, cast it to the common errors ExecutionFailureError.\n\tif e, isExecutionError := err.(*validation.ExecutionFailureError); isExecutionError {\n\t\treturn &commonerrors.VSCCExecutionFailureError{Err: e}\n\t}\n\t// Else, treat it as an endorsement error.\n\treturn &commonerrors.VSCCEndorsementPolicyError{Err: err}\n}\n\nfunc (v *VsccValidatorImpl) getCDataForCC(chid, ccid string) (*ccprovider.ChaincodeData, error) {\n\tl := v.cr.Ledger()\n\tif l == nil {\n\t\treturn nil, errors.New(\"nil ledger instance\")\n\t}\n\n\tqe, err := l.NewQueryExecutor()\n\tif err != nil {\n\t\treturn nil, errors.WithMessage(err, \"could not retrieve QueryExecutor\")\n\t}\n\tdefer qe.Done()\n\n\tbytes, err := qe.GetState(\"lscc\", ccid)\n\tif err != nil {\n\t\treturn nil, &commonerrors.VSCCInfoLookupFailureError{\n\t\t\tReason: fmt.Sprintf(\"Could not retrieve state for chaincode %s, error %s\", ccid, err),\n\t\t}\n\t}\n\n\tif bytes == nil {\n\t\treturn nil, errors.Errorf(\"lscc's state for [%s] not found.\", ccid)\n\t}","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/committer/txvalidator/v14/vscc_validator.go#L273-L309","documentation":"getCDataForCC returns this error when the ledger retrieved from the validator's LedgerGetter (v.cr.Ledger()) is nil, meaning the peer has no ledger available for the channel at validation time. Without a ledger, lscc state cannot be queried, so chaincode data (version, vscc, policy) cannot be obtained. It is wrapped in VSCCEndorsementPolicyError via the caller.","triggerScenarios":"GetInfoForValidate -> getCDataForCC called while v.cr.Ledger() returns nil — e.g. during peer startup before the ledger is initialized, or a channel whose ledger has not been opened yet.","commonSituations":"Peer bootstrapping/race during early block validation; ledger provider misconfiguration; channel ledger not yet created when validation is invoked.","solutions":["Restart the peer and confirm the ledger initializes correctly before blocks are validated","Check peer logs for earlier ledger initialization errors (e.g. CouchDB/LevelDB connection failures)","Verify ledger configuration in core.yaml (ledger.section state database settings) is correct","Ensure the channel's genesis/ledger exists on disk for the peer"],"exampleFix":"// before: peer started with broken state DB config causing nil ledger\ndatabaseType: sqlcipher\n// after\ncouchDBAddress: couchdb:5984\nstateDatabase: CouchDB\n","handlingStrategy":"retry","validationCode":"// operator pre-check: ensure ledger is healthy before validating/committing\npeer node status && test -d /var/hyperledger/production/ledgersData","typeGuard":null,"tryCatchPattern":"try { await validateTx(tx); } catch (e) {\n  if (String(e).includes('nil ledger instance')) { /* wait and retry; check peer startup logs */ }\n}","preventionTips":["Verify state DB config and connectivity before starting block ingestion","Monitor peer startup for ledger init errors","Restart peer if ledger provider is misconfigured"],"tags":["hyperledger-fabric","ledger","nil-pointer","tx-validation"],"backgroundTag":"nil-ledger","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"}