{"record":{"id":"a11ce07c71504048","repo":"hyperledger/fabric","slug":"block-data-size-d-is-different-from-tx-filter-si","errorCode":null,"errorMessage":"block data size(%d) is different from Tx filter size(%d)","messagePattern":"block data size\\((.+?)\\) is different from Tx filter size\\((.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gossip/privdata/coordinator.go","lineNumber":304,"sourceCode":"\t\t\t}\n\t\t}\n\t}\n\n\treturn blockAndPvtData.Block, seqs2Namespaces.asPrivateData(), nil\n}\n\n// getTxPvtdataInfoFromBlock parses the block transactions and returns the list of private data items in the block.\n// Note that this peer's eligibility for the private data is not checked here.\nfunc (c *coordinator) getTxPvtdataInfoFromBlock(block *common.Block) ([]*ledger.TxPvtdataInfo, error) {\n\ttxPvtdataItemsFromBlock := []*ledger.TxPvtdataInfo{}\n\n\tif block.Metadata == nil || len(block.Metadata.Metadata) <= int(common.BlockMetadataIndex_TRANSACTIONS_FILTER) {\n\t\treturn nil, errors.New(\"Block.Metadata is nil or Block.Metadata lacks a Tx filter bitmap\")\n\t}\n\ttxsFilter := txValidationFlags(block.Metadata.Metadata[common.BlockMetadataIndex_TRANSACTIONS_FILTER])\n\tdata := block.Data.Data\n\tif len(txsFilter) != len(block.Data.Data) {\n\t\treturn nil, errors.Errorf(\"block data size(%d) is different from Tx filter size(%d)\", len(block.Data.Data), len(txsFilter))\n\t}\n\n\tfor seqInBlock, txEnvBytes := range data {\n\t\tinvalid := txsFilter[seqInBlock] != uint8(peer.TxValidationCode_VALID)\n\t\ttxInfo, err := getTxInfoFromTransactionBytes(txEnvBytes)\n\t\tif err != nil {\n\t\t\tcontinue\n\t\t}\n\n\t\tcolPvtdataInfo := []*ledger.CollectionPvtdataInfo{}\n\t\tfor _, ns := range txInfo.txRWSet.NsRwSets {\n\t\t\tfor _, hashedCollection := range ns.CollHashedRwSets {\n\t\t\t\t// skip if no writes\n\t\t\t\tif !containsWrites(txInfo.txID, ns.NameSpace, hashedCollection) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tcc := privdata.CollectionCriteria{\n\t\t\t\t\tChannel:    txInfo.channelID,","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/gossip/privdata/coordinator.go#L286-L322","documentation":"getTxPvtdataInfoFromBlock cross-checks the length of the Tx validation filter bitmap against the number of transactions in block.Data.Data. Each tx in the block must have exactly one validation flag byte; a size mismatch means the block is internally inconsistent and cannot be safely processed, so this error is returned.","triggerScenarios":"StoreBlock -> getTxPvtdataInfoFromBlock where len(block.Metadata.Metadata[TRANSACTIONS_FILTER]) != len(block.Data.Data) — e.g. metadata truncated/rebuilt separately from data, or txs added/removed without updating the filter.","commonSituations":"Ledger repair or export/import tools that rewrote block.Data but not the metadata filter; corrupted block from gossip; custom block builders; tests with mismatched fixture data.","solutions":["Re-obtain the intact block from the orderer or another peer","Fix the block repair/conversion tooling to keep the Tx filter in sync with block data length","Rebuild the filter bitmap (one TxValidationCode byte per tx) if you must repair locally","Correct test fixtures so filter length equals len(block.Data.Data)"],"exampleFix":"// before\nfilter := []byte{0x00} // only 1 flag, but 3 txs\n// after\nfilter := bytes.Repeat([]byte{byte(peer.TxValidationCode_VALID)}, len(block.Data.Data))\nblock.Metadata.Metadata[common.BlockMetadataIndex_TRANSACTIONS_FILTER] = filter","handlingStrategy":"validation","validationCode":"filter := block.Metadata.Metadata[common.BlockMetadataIndex_TRANSACTIONS_FILTER]\nif len(filter) != len(block.Data.Data) {\n    return fmt.Errorf(\"filter size %d != tx count %d\", len(filter), len(block.Data.Data))\n}","typeGuard":"func txFilterConsistent(b *common.Block) bool {\n    if b == nil || b.Metadata == nil || b.Data == nil ||\n        len(b.Metadata.Metadata) <= int(common.BlockMetadataIndex_TRANSACTIONS_FILTER) {\n        return false\n    }\n    return len(b.Metadata.Metadata[common.BlockMetadataIndex_TRANSACTIONS_FILTER]) == len(b.Data.Data)\n}","tryCatchPattern":null,"preventionTips":["When repairing blocks, rebuild the Tx filter to match block data length byte-for-byte","Verify block integrity (filter length vs tx count) before committing","Don't modify block.Data.Data in tooling without updating metadata","Use fabric-native APIs for block export/import instead of manual proto edits"],"tags":["gossip","privdata","block-metadata","validation"],"backgroundTag":"block-filter-size-mismatch","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"}