hyperledger/fabric · error
error unmarshalling chaincode state data
Error message
error unmarshalling chaincode state data
What it means
Raised by ChaincodeInfo in lscc's deployed-chaincode info provider when the raw bytes stored under the chaincode name in the lscc namespace cannot be proto-unmarshalled into ccprovider.ChaincodeData. It means the ledger state for that chaincode definition is corrupt, truncated, or was written by an incompatible format. The wrapped underlying error is carried via errors.Wrap.
Source
Thrown at core/scc/lscc/deployedcc_infoprovider.go:78
func (p *DeployedCCInfoProvider) ImplicitCollections(channelName, chaincodeName string, qe ledger.SimpleQueryExecutor) ([]*peer.StaticCollectionConfig, error) {
return nil, nil
}
// GenerateImplicitCollectionForOrg is not implemented for legacy chaincodes
func (p *DeployedCCInfoProvider) GenerateImplicitCollectionForOrg(mspid string) *peer.StaticCollectionConfig {
return nil
}
// ChaincodeInfo implements function in interface ledger.DeployedChaincodeInfoProvider
func (p *DeployedCCInfoProvider) ChaincodeInfo(channelName, chaincodeName string, qe ledger.SimpleQueryExecutor) (*ledger.DeployedChaincodeInfo, error) {
chaincodeDataBytes, err := qe.GetState(lsccNamespace, chaincodeName)
if err != nil || chaincodeDataBytes == nil {
return nil, err
}
chaincodeData := &ccprovider.ChaincodeData{}
if err := proto.Unmarshal(chaincodeDataBytes, chaincodeData); err != nil {
return nil, errors.Wrap(err, "error unmarshalling chaincode state data")
}
collConfigPkg, err := fetchCollConfigPkg(chaincodeName, qe)
if err != nil {
return nil, err
}
return &ledger.DeployedChaincodeInfo{
Name: chaincodeName,
Hash: chaincodeData.Id,
Version: chaincodeData.Version,
ExplicitCollectionConfigPkg: collConfigPkg,
IsLegacy: true,
}, nil
}
// AllChaincodesInfo returns the mapping of chaincode name to DeployedChaincodeInfo for legacy chaincodes
func (p *DeployedCCInfoProvider) AllChaincodesInfo(channelName string, qe ledger.SimpleQueryExecutor) (map[string]*ledger.DeployedChaincodeInfo, error) {
iter, err := qe.GetStateRangeScanIterator(lsccNamespace, "", "")
if err != nil {View on GitHub (pinned to 2736b63f8f)
Solutions
- Inspect the state entry for the chaincode under the lscc namespace and check the wrapped error for the protobuf decode cause
- Re-deploy/redefine the chaincode so a valid ChaincodeData is written
- Restore the peer's state database from a consistent backup
- Check Fabric version compatibility of the ledger data (state written by an incompatible release)
Defensive patterns
Strategy: try-catch
Validate before calling
// Go: verify state bytes decode before relying on ChaincodeInfo
raw, err := qe.GetState("lscc", chaincodeName)
if err != nil { return err }
if raw == nil { return fmt.Errorf("chaincode %s not defined", chaincodeName) }
data := &ccprovider.ChaincodeData{}
if err := proto.Unmarshal(raw, data); err != nil {
return fmt.Errorf("corrupt ChaincodeData for %s: %w", chaincodeName, err)
} Try / catch
// Go
info, err := provider.ChaincodeInfo(channelID, chaincodeName, qe)
if err != nil {
if strings.Contains(err.Error(), "error unmarshalling chaincode state data") {
// corrupt state: alert ops, do not retry blindly
return fmt.Errorf("corrupt chaincode data in ledger for %s: %w", chaincodeName, err)
}
return err
} Prevention
- Never write raw/non-proto bytes into the lscc namespace
- Restore state DBs only from consistent backups of the same Fabric version
- Run peer upgrade procedures so ChaincodeData schema stays compatible
- Monitor ledger integrity and re-deploy chaincodes whose stored data is suspect
When it happens
Trigger: Calling ChaincodeInfo (directly or via AllChaincodesInfo) on a query executor whose GetState(lsccNamespace, chaincodeName) returns bytes that fail proto.Unmarshal into ChaincodeData.
Common situations: Corrupted or hand-edited ledger state; state written by a much older Fabric version with a different ChaincodeData schema; database corruption after an upgrade or restore from inconsistent backup.
Understand the failure class
Background: "cannot parse invalid wire-format data", "cannot unmarshal", "failed unmarshalling": protobuf unmarshal errors explained — this error's family across 10 libraries.
Related errors
- failed to deserialize values
- error converting envelope to config update: %s
- failed to unmarshal response for transaction %s
- unmarshalling ChaincodeQueryResponse failed
- could not unmarshal chaincode package to CDS or SignedCDS
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/c8bb1637a3e1bcc1.
Report an issue: GitHub.