{"record":{"id":"d399223be5969a6e","repo":"hyperledger/fabric","slug":"wrong-chain-type","errorCode":null,"errorMessage":"wrong chain type","messagePattern":"wrong chain type","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/peer/deliverevents.go","lineNumber":182,"sourceCode":"\t\tType: &peer.DeliverResponse_BlockAndPrivateData{BlockAndPrivateData: blockAndPvtData},\n\t}\n\treturn bprs.Send(response)\n}\n\nfunc (bprs *blockAndPrivateDataResponseSender) DataType() string {\n\treturn \"block_and_pvtdata\"\n}\n\n// getPrivateData returns private data for the block\nfunc (bprs *blockAndPrivateDataResponseSender) getPrivateData(\n\tblock *common.Block,\n\tchain deliver.Chain,\n\tchannelID string,\n\tsignedData *protoutil.SignedData,\n) (map[uint64]*rwset.TxPvtReadWriteSet, error) {\n\tchannel, ok := chain.(Chain)\n\tif !ok {\n\t\treturn nil, errors.New(\"wrong chain type\")\n\t}\n\n\tpvtData, err := channel.Ledger().GetPvtDataByNum(block.Header.Number, nil)\n\tif err != nil {\n\t\tlogger.Errorf(\"Error getting private data by block number %d on channel %s\", block.Header.Number, channelID)\n\t\treturn nil, errors.Wrapf(err, \"error getting private data by block number %d\", block.Header.Number)\n\t}\n\n\tseqs2Namespaces := aggregatedCollections(make(map[seqAndDataModel]map[string][]*rwset.CollectionPvtReadWriteSet))\n\n\tconfigHistoryRetriever, err := channel.Ledger().GetConfigHistoryRetriever()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tidentityDeserializer, err := bprs.IdentityDeserializerManager.Deserializer(channelID)\n\tif err != nil {\n\t\treturn nil, err","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/peer/deliverevents.go#L164-L200","documentation":"getPrivateData receives the deliver chain as a generic deliver.Chain interface and immediately asserts it to the local Chain type to access Ledger(). If the injected chain is not this concrete type (a different deliver.Chain implementation), the assertion fails and this error is returned.","triggerScenarios":"Calling SendBlockResponse (which calls getPrivateData) with a chain value that implements deliver.Chain but not the package-local Chain interface — typically only in tests or when a custom/foreign chain implementation is registered.","commonSituations":"Unit tests passing mock deliver.Chain implementations that lack the local Chain methods; registering a custom deliver support handler; refactoring that changed the Chain interface without updating all implementations.","solutions":["Ensure the chain registered with the deliver handler is the package-local Chain (has Ledger() etc.).","Update mocks in tests to implement the full local Chain interface.","Use embedding (mock embeds the real Chain or implements all methods) so the type assertion succeeds."],"exampleFix":"// before\ntype fakeChain struct{} // only deliver.Chain methods\nhandler.getPrivateData(block, fakeChain{}, \"mychannel\", sd)\n// after\ntype fakeChain struct {\n  *peer.Chain // embed to satisfy local Chain interface\n}\nhandler.getPrivateData(block, fakeChain{}, \"mychannel\", sd)","handlingStrategy":"type-guard","validationCode":"if _, ok := chain.(Chain); !ok {\n  return errors.New(\"chain must implement the local Chain interface\")\n}","typeGuard":"func asLocalChain(c deliver.Chain) (Chain, bool) {\n  ch, ok := c.(Chain)\n  return ch, ok\n}","tryCatchPattern":"pvt, err := getPrivateData(block, chain, chID, sd)\nif err != nil && err.Error() == \"wrong chain type\" {\n  return fmt.Errorf(\"deliver chain is not the local Chain implementation: %w\", err)\n}","preventionTips":["Embed the full local Chain interface in test mocks","Add var _ Chain = (*mockChain)(nil) compile checks","Keep the Chain interface small so mocks stay in sync"],"tags":["deliver","type-assertion","private-data","hyperledger-fabric"],"backgroundTag":"type-assertion-failed","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"}