docs: Add clear clarification around previousBlockHash source in RecordFileItem pseudocode#24508
Conversation
|
✨ Submitted to Merge by @jsync-swirlds. It will be added to the merge queue once all branch protection rules pass and there are no merge conflicts with the target branch. See more details here. |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
previousBlockHash source in RecordFileItem pseudocode
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #24508 +/- ##
============================================
+ Coverage 78.21% 78.22% +0.01%
+ Complexity 11679 11676 -3
============================================
Files 2486 2486
Lines 94619 94619
Branches 10211 10210 -1
============================================
+ Hits 74004 74015 +11
+ Misses 16871 16862 -9
+ Partials 3744 3742 -2 see 13 files with indirect coverage changes 🚀 New features to boost your workflow:
|
ff5bc8a to
8e8e01f
Compare
The reconstructRecordFile pseudocode referenced a previousBlockHash parameter without documenting where it comes from. This was confusing because it could be mistaken for BlockFooter.previous_block_root_hash, which is a completely different value (the block stream merkle tree root hash of the previous block). The fix: - Renamed the parameter to previousRecordFileHash for clarity - Added explicit variable bindings showing all parameters come from record_file_contents and BlockProof.SignedRecordFileProof - Added a NOTE explaining that start_object_running_hash has different semantics per version: for v2 it holds the previous record file hash, while for v5/v6 it holds the actual running hash of RecordStreamItems Signed-off-by: Rocky Thind <harpender.t@swirldslabs.com>
8e8e01f to
3d45dad
Compare
|
/trunk merge |
|
An error occurred while submitting your PR to the queue: |
|
/trunk merge |
| * recordStreamFile): | ||
| * WRITE version number (4 bytes, int) | ||
| * IF version == 2: | ||
| * WRITE HAPI major version (4 bytes int) |
There was a problem hiding this comment.
When creating WRB, do we read the HAPI version number from V2 file and write it into record_file_contents.hapi_proto_version.major?
If so and before it's too late, we should instead write it to record_file_contents.hapi_proto_version.minor and update the pseudo code.
There was a problem hiding this comment.
Good catch — you're right that the single int in V2 files (value 3) semantically represents HAPI version 0.3.0, not 3.0.0. We do currently read it and store it in hapi_proto_version.major.
However, after looking into it, I don't think we should change it:
-
The round-trip is lossless — we read the int into
major, and the pseudocode reconstructs V2 by writinghapi_proto_version.majorback as the single int. The original V2 binary is reproduced byte-for-byte, and signature verification works correctly. -
Changing it would break existing wrapped blocks — storing
3inminorinstead ofmajorchanges the protobuf serialization ofSemanticVersion(field 1 vs field 2), which changes theRecordStreamFilebytes, which changes the block hash for every V2-era wrapped block (~blocks 0 to ~1.8M). All existing hash registries, Merkle trees, and jumpstart files would be invalidated and everything would need to be re-wrapped and re-validated. -
No practical impact — V2 blocks are from 2019 (the start of mainnet). No downstream consumer is making decisions based on
hapi_proto_versionfrom these blocks.
So the cost of fixing (re-wrapping millions of blocks, invalidating all state files) outweighs the cosmetic benefit. The pseudocode and code are internally consistent as-is.
There was a problem hiding this comment.
@xin-hedera do you agree we shouldn't change this?
Summary
previousBlockHashtopreviousRecordFileHashin thereconstructRecordFilepseudocode to avoid confusion withBlockFooter.previous_block_root_hash(which is the block stream merkle tree root hash — a completely different value)record_file_contents,BlockProof.SignedRecordFileProof)start_object_running_hashhas different semantics per version:RecordStreamItemsbefore this fileContext
The pseudocode referenced a
previousBlockHashparameter without documenting its source. This was misleading because it could be mistaken forBlockFooter.previous_block_root_hash. In reality, the value comes fromrecord_file_contents.start_object_running_hash.hash, which for v2 files holds the previous record file's content hash — a semantic overload of a field that means something different for v5/v6.This is a documentation-only change — no proto fields or message definitions are modified.