{"record":{"id":"c037e2ff7f6e3e86","repo":"hyperledger/fabric","slug":"error-decoding-the-block-number","errorCode":null,"errorMessage":"error decoding the block number","messagePattern":"error decoding the block number","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/ledger/blkstorage/block_serialization.go","lineNumber":119,"sourceCode":"\tnumItems := uint64(0)\n\tif blockMetadata != nil {\n\t\tnumItems = uint64(len(blockMetadata.Metadata))\n\t}\n\tbuf = protowire.AppendVarint(buf, numItems)\n\tif blockMetadata == nil {\n\t\treturn buf\n\t}\n\tfor _, b := range blockMetadata.Metadata {\n\t\tbuf = protowire.AppendBytes(buf, b)\n\t}\n\treturn buf\n}\n\nfunc extractHeader(buf *buffer) (*common.BlockHeader, error) {\n\theader := &common.BlockHeader{}\n\tvar err error\n\tif header.Number, err = buf.DecodeVarint(); err != nil {\n\t\treturn nil, errors.Wrap(err, \"error decoding the block number\")\n\t}\n\tif header.DataHash, err = buf.DecodeRawBytes(false); err != nil {\n\t\treturn nil, errors.Wrap(err, \"error decoding the data hash\")\n\t}\n\tif header.PreviousHash, err = buf.DecodeRawBytes(false); err != nil {\n\t\treturn nil, errors.Wrap(err, \"error decoding the previous hash\")\n\t}\n\tif len(header.PreviousHash) == 0 {\n\t\theader.PreviousHash = nil\n\t}\n\treturn header, nil\n}\n\nfunc extractData(buf *buffer) (*common.BlockData, []*txindexInfo, error) {\n\tdata := &common.BlockData{}\n\tvar txOffsets []*txindexInfo\n\tvar numItems uint64\n\tvar err error","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/common/ledger/blkstorage/block_serialization.go#L101-L137","documentation":"deserializeBlock/extractSerializedBlockInfo decode Fabric's flat serialized block format via a buffer. extractHeader first decodes the block number as a varint; if the buffer is exhausted or corrupted at that point, this wrapped error is returned. It indicates the serialized bytes are not a valid Fabric block.","triggerScenarios":"Calling blkstorage deserialization (deserializeBlock, extractSerializedBlockInfo, e.g. via GetBlockByHash/GetBlockByNumber internals) on bytes that are empty, truncated, or not produced by serializeBlock.","commonSituations":"Corrupted ledger files on disk (disk full at write time, crash during commit); copying/moving ledger files between nodes without stopping; restoring block files from a partial backup; pointing blkstorage at a directory containing foreign data.","solutions":["Verify the block file integrity; restore the ledger block files from a known-good backup or re-fetch blocks from another peer/orderer.","Stop the node, remove the corrupted channel's ledger data, and re-join the channel to rebuild the ledger from genesis.","Check disk health and free space on the peer's ledger volume.","Confirm the code path passes serialized block bytes, not raw protobuf Block bytes, into the deserializer."],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":"if len(serializedBlockBytes) == 0 {\n    return errors.New(\"refusing to deserialize empty block bytes\")\n}","typeGuard":"func looksLikeSerializedBlock(b []byte) bool {\n    return len(b) > 4 // varint number + hashes + framing must be present\n}","tryCatchPattern":"block, err := deserializeBlock(buf)\nif err != nil && strings.Contains(err.Error(), \"error decoding the block number\") {\n    logger.Errorf(\"corrupt block at head of store: %v\", err)\n    // quarantine the file and resync from peers\n}","preventionTips":["Back up ledger directories only while the peer is stopped.","Monitor ledger volume disk space and I/O errors.","Never hand-edit or truncate block files.","After host crashes, verify block file integrity before restarting the peer."],"tags":["hyperledger-fabric","ledger","serialization","corruption"],"backgroundTag":"ledger-block-corruption","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"}