hyperledger/fabric · error
nil ledger instance
Error message
nil ledger instance
What it means
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.
Source
Thrown at core/committer/txvalidator/v14/vscc_validator.go:291
func (v *VsccValidatorImpl) VSCCValidateTxForCC(ctx *Context) error {
logger.Debug("Validating", ctx, "with plugin")
err := v.pluginValidator.ValidateWithPlugin(ctx)
if err == nil {
return nil
}
// If the error is a pluggable validation execution error, cast it to the common errors ExecutionFailureError.
if e, isExecutionError := err.(*validation.ExecutionFailureError); isExecutionError {
return &commonerrors.VSCCExecutionFailureError{Err: e}
}
// Else, treat it as an endorsement error.
return &commonerrors.VSCCEndorsementPolicyError{Err: err}
}
func (v *VsccValidatorImpl) getCDataForCC(chid, ccid string) (*ccprovider.ChaincodeData, error) {
l := v.cr.Ledger()
if l == nil {
return nil, errors.New("nil ledger instance")
}
qe, err := l.NewQueryExecutor()
if err != nil {
return nil, errors.WithMessage(err, "could not retrieve QueryExecutor")
}
defer qe.Done()
bytes, err := qe.GetState("lscc", ccid)
if err != nil {
return nil, &commonerrors.VSCCInfoLookupFailureError{
Reason: fmt.Sprintf("Could not retrieve state for chaincode %s, error %s", ccid, err),
}
}
if bytes == nil {
return nil, errors.Errorf("lscc's state for [%s] not found.", ccid)
}View on GitHub (pinned to 2736b63f8f)
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
Example fix
// before: peer started with broken state DB config causing nil ledger databaseType: sqlcipher // after couchDBAddress: couchdb:5984 stateDatabase: CouchDB
Defensive patterns
Strategy: retry
Validate before calling
// operator pre-check: ensure ledger is healthy before validating/committing peer node status && test -d /var/hyperledger/production/ledgersData
Try / catch
try { await validateTx(tx); } catch (e) {
if (String(e).includes('nil ledger instance')) { /* wait and retry; check peer startup logs */ }
} Prevention
- Verify state DB config and connectivity before starting block ingestion
- Monitor peer startup for ledger init errors
- Restart peer if ledger provider is misconfigured
When it happens
Trigger: 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.
Common situations: Peer bootstrapping/race during early block validation; ledger provider misconfiguration; channel ledger not yet created when validation is invoked.
Related errors
- config envelope is nil
- error decoding the block number
- error decoding the data hash
- error decoding the previous hash
- error decoding the length of block data
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/76a3a51cf6d09039.
Report an issue: GitHub.