hyperledger/fabric · error
invalid chaincode event
Error message
invalid chaincode event
What it means
When V1_2Validation capabilities are enabled and the chaincode action includes Events, VSCC unmarshals them as a peer.ChaincodeEvent; the unmarshal failed, so the events bytes are not a valid ChaincodeEvent protobuf. The transaction is invalidated with TxValidationCode_INVALID_OTHER_REASON and the underlying error wrapped in this message.
Source
Thrown at core/committer/txvalidator/v14/vscc_validator.go:124
err = errors.Errorf("inconsistent ccid info (%s/%s)", ccID, respPayload.ChaincodeId.Name)
logger.Errorf("%+v", err)
return peer.TxValidationCode_INVALID_OTHER_REASON, err
}
// sanity check on ccver
if ccVer == "" {
err = errors.New("invalid chaincode version")
logger.Errorf("%+v", err)
return peer.TxValidationCode_INVALID_OTHER_REASON, err
}
var wrNamespace []string
alwaysEnforceOriginalNamespace := v.cr.Capabilities().V1_2Validation()
if alwaysEnforceOriginalNamespace {
wrNamespace = append(wrNamespace, ccID)
if respPayload.Events != nil {
ccEvent := &peer.ChaincodeEvent{}
if err = proto.Unmarshal(respPayload.Events, ccEvent); err != nil {
return peer.TxValidationCode_INVALID_OTHER_REASON, errors.Wrapf(err, "invalid chaincode event")
}
if ccEvent.ChaincodeId != ccID {
return peer.TxValidationCode_INVALID_OTHER_REASON, errors.Errorf("chaincode event chaincode id does not match chaincode action chaincode id")
}
}
}
namespaces := make(map[string]struct{})
for _, ns := range txRWSet.NsRwSets {
// check to make sure there is no duplicate namespace in txRWSet
if _, ok := namespaces[ns.NameSpace]; ok {
return peer.TxValidationCode_ILLEGAL_WRITESET, errors.Errorf("duplicate namespace '%s' in txRWSet", ns.NameSpace)
}
namespaces[ns.NameSpace] = struct{}{}
if !v.txWritesToNamespace(ns) {
continue
}View on GitHub (pinned to 2736b63f8f)
Solutions
- Fix the chaincode to emit events via the shim's SetEvent with a valid ChaincodeEvent-compatible payload (payload bytes may be arbitrary, but the event wrapper must be standard shim-generated protobuf).
- Check the chaincode shim version matches the peer's proto definitions.
- Inspect respPayload.Events bytes with protoc --decode_raw to identify the malformed content.
Example fix
// before: custom serialization inside shim event field
stub.SetEvent("evt", myCustomProtoBytes)
// after: standard shim event; put custom data in the Event.Payload
stub.SetEvent("evt", []byte(`{"k":"v"}`)) Defensive patterns
Strategy: validation
Validate before calling
if len(respPayload.Events) > 0 {
evt := &peer.ChaincodeEvent{}
if err := proto.Unmarshal(respPayload.Events, evt); err != nil {
return fmt.Errorf("events bytes are not a valid ChaincodeEvent: %w", err)
}
} Type guard
func isValidChaincodeEvent(b []byte) bool {
evt := &peer.ChaincodeEvent{}
return len(b) == 0 || proto.Unmarshal(b, evt) == nil
} Try / catch
if err := proto.Unmarshal(respPayload.Events, ccEvent); err != nil {
return peer.TxValidationCode_INVALID_OTHER_REASON, errors.Wrapf(err, "invalid chaincode event")
} Prevention
- Emit events only through stub.SetEvent; never serialize custom message formats into the event field.
- Keep chaincode shim and peer proto versions aligned.
- Decode respPayload.Events with protoc --decode_raw when debugging event format issues.
When it happens
Trigger: respPayload.Events contains bytes that do not decode as ChaincodeEvent — e.g. a chaincode emits events serialized with a custom format (JSON, plain string) instead of protobuf, or corrupts the field.
Common situations: Chaincode developers using SetEvent with non-protobuf expectations or custom binary payloads inside event bytes; chaincodes ported from other frameworks; shim/proto version mismatches.
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
- chaincode event chaincode id does not match chaincode action
- error unmarshalling ChaincodeHeaderExtension
- nil ChaincodeId in header extension
- nil ChaincodeId in ChaincodeAction
- invalid chaincode ID
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/bdd23addd60ba81f.
Report an issue: GitHub.