hyperledger / hyperledger/fabric-x-common

[blkstorage] Extract only the header when only the header is read

Open Beginner friendly
#183 0 comments 0 reactions 0 assignees View on GitHub
enhancement performance
Dominant language
Go
Stars
21
Forks
15
Avg merge
2d 19h
Merged PRs (30d)
20

Description

Part of the umbrella #167.

Two paths want nothing but a block header, and both parse the entire serialized block to get it.
`extractSerializedBlockInfo` (`common/ledger/blkstorage/block_serialization.go:56`) decodes every
envelope, computes a transaction ID per envelope, and decodes all metadata entries:

- `blockfileMgr.retrieveBlockHeaderByNumber` (`blockfile_mgr.go:604`) reads `info.blockHeader` and
drops the rest. It runs at every store open, on the last persisted block, to build the initial
`BlockchainInfo` (`blockfile_mgr.go:159`).
- `retrieveFirstBlockNumFromFile` (`blockfile_helper.go:127`) reads `blockInfo.blockHeader.Number`
and drops the rest. `binarySearchFileNumForBlock` calls it once per probe, so a rollback pays it
O(log n) times over the block files.

Neither is on a steady-state hot path, so this is smaller than #165 and #182.
It is worth doing anyway because the fix is a few lines and the current cost is unbounded in block
size: opening a store that last wrote a 10,000-transaction block unmarshals 10,000 envelopes to read
three header fields.

Proposal: add a header-only extractor that stops after `extractHeader`, and use it in both places.
The Fabric-X Orderer's fork of this package already carries exactly this as
`extractSerializedBlockHeader`, used in the same two call sites.

Note that #182 also touches `extractSerializedBlockInfo`; if that lands
first this becomes smaller still, but the two are independent — a header-only path skips the
metadata decode and the envelope decode as well, not just the transaction IDs.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in common/ledger/blkstorage/block_serialization.go at extractSerializedBlockInfo and extractHeader, then compare the existing extractSerializedBlockHeader implementation in the Fabric-X Orderer fork. Trace blockfileMgr.go:604 and blockfile_helper.go:127, where only the header is needed. Done means both call sites use the header-only path without decoding the rest of the serialized block.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.