{"record":{"id":"a5f86f9e798e2bf9","repo":"hyperledger/fabric","slug":"invalid-chaincode-event-a5f86f","errorCode":null,"errorMessage":"invalid chaincode event","messagePattern":"invalid chaincode event","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/committer/txvalidator/v20/plugindispatcher/dispatcher.go","lineNumber":164,"sourceCode":"\t}\n\tif ccID != respPayload.ChaincodeId.Name {\n\t\terr = errors.Errorf(\"inconsistent ccid info (%s/%s)\", ccID, respPayload.ChaincodeId.Name)\n\t\tlogger.Errorf(\"%+v\", err)\n\t\treturn peer.TxValidationCode_INVALID_CHAINCODE, err\n\t}\n\t// sanity check on ccver\n\tif ccVer == \"\" {\n\t\terr = errors.New(\"invalid chaincode version\")\n\t\tlogger.Errorf(\"%+v\", err)\n\t\treturn peer.TxValidationCode_INVALID_CHAINCODE, err\n\t}\n\n\twrNamespace := map[string]bool{}\n\twrNamespace[ccID] = true\n\tif respPayload.Events != nil {\n\t\tccEvent := &peer.ChaincodeEvent{}\n\t\tif err = proto.Unmarshal(respPayload.Events, ccEvent); err != nil {\n\t\t\treturn peer.TxValidationCode_INVALID_OTHER_REASON, errors.Wrapf(err, \"invalid chaincode event\")\n\t\t}\n\t\tif ccEvent.ChaincodeId != ccID {\n\t\t\treturn peer.TxValidationCode_INVALID_OTHER_REASON, errors.Errorf(\"chaincode event chaincode id does not match chaincode action chaincode id\")\n\t\t}\n\t}\n\n\tnamespaces := make(map[string]struct{})\n\tfor _, ns := range txRWSet.NsRwSets {\n\t\t// check to make sure there is no duplicate namespace in txRWSet\n\t\tif _, ok := namespaces[ns.NameSpace]; ok {\n\t\t\tlogger.Errorf(\"duplicate namespace '%s' in txRWSet\", ns.NameSpace)\n\t\t\treturn peer.TxValidationCode_ILLEGAL_WRITESET,\n\t\t\t\terrors.Errorf(\"duplicate namespace '%s' in txRWSet\", ns.NameSpace)\n\t\t}\n\t\tnamespaces[ns.NameSpace] = struct{}{}\n\n\t\tif v.txWritesToNamespace(ns) {\n\t\t\twrNamespace[ns.NameSpace] = true","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/committer/txvalidator/v20/plugindispatcher/dispatcher.go#L146-L182","documentation":"Dispatch failed to protobuf-unmarshal respPayload.Events into a peer.ChaincodeEvent. The Events field of the chaincode action must be a serialized ChaincodeEvent message; Fabric wraps the unmarshal failure with 'invalid chaincode event' and marks the tx INVALID_OTHER_REASON.","triggerScenarios":"During validation, respPayload.Events is non-nil but its bytes are not a valid serialized ChaincodeEvent — produced by a chaincode emitting raw/arbitrary bytes via SetEvent, corrupted payloads, or non-standard serializers.","commonSituations":"Chaincode that sets an event with manually marshaled or non-ChaincodeEvent bytes; corrupted response payloads after serialization bugs; custom shims writing events in a different format.","solutions":["In chaincode, only pass event payloads via shim.SetEvent(name, payload); do not pre-wrap or manually marshal into ChaincodeEvent.","Verify the chaincode shim version matches the peer (event wire format is proto-defined).","Locate the offending chaincode from the failing tx and fix/redeploy it; re-submit the transaction.","If custom serialization was applied to respPayload.Events upstream, remove it."],"exampleFix":"// before\nstub.SetEvent(\"myevent\", protoMarshal(&peer.ChaincodeEvent{...}))\n// after\nstub.SetEvent(\"myevent\", []byte(`{\"k\":\"v\"}`)) // shim handles serialization","handlingStrategy":"validation","validationCode":"// chaincode side, before SetEvent: ensure payload is plain bytes, not a pre-marshaled ChaincodeEvent\nif (typeof eventPayload !== 'string' && !(eventPayload instanceof Uint8Array)) { throw new Error('event payload must be raw bytes'); }","typeGuard":null,"tryCatchPattern":"try { validate(tx); } catch (err) { if (/invalid chaincode event/.test(err.message)) { /* fix emitting chaincode, redeploy, resubmit */ } else { throw err; } }","preventionTips":["Only pass raw payload bytes to shim.SetEvent.","Never pre-wrap payloads in ChaincodeEvent messages.","Keep chaincode shim version aligned with peer.","Test event emission in dev network before production."],"tags":["hyperledger-fabric","validation","chaincode-events","protobuf"],"backgroundTag":"invalid-chaincode-event","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"}