Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Remove Previous Block Hash from BlockHeader #17862

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

thomas-swirlds-labs
Copy link
Contributor

@thomas-swirlds-labs thomas-swirlds-labs commented Feb 12, 2025

Description:
The previousBlockHash is no longer required in the Block Stream BlockHeader because it causes a timing problem that prevents optimal parallel thread pipelining in the consensus node and we do not want to hold up creating the block header until that hash is ready. It will continue to be available in the Block Proof however.

Related issue(s):

Fixes #17861, hashgraph/hedera-protobufs#468

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

Copy link

codacy-production bot commented Feb 12, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
-0.01% (target: -1.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (a2f4da1) 99435 72515 72.93%
Head commit (d5147cd) 99448 (+13) 72519 (+4) 72.92% (-0.01%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#17862) 0 0 ∅ (not applicable)

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

Copy link

codecov bot commented Feb 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.02%. Comparing base (a2f4da1) to head (d5147cd).
Report is 5 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##               main   #17862   +/-   ##
=========================================
  Coverage     69.01%   69.02%           
- Complexity    23036    23051   +15     
=========================================
  Files          2654     2655    +1     
  Lines         99652    99674   +22     
  Branches      10284    10289    +5     
=========================================
+ Hits          68777    68796   +19     
- Misses        26976    26985    +9     
+ Partials       3899     3893    -6     
Files with missing lines Coverage Δ
...a/node/app/blocks/impl/BlockStreamManagerImpl.java 95.36% <ø> (+1.12%) ⬆️

... and 31 files with indirect coverage changes

Impacted file tree graph

@thomas-swirlds-labs thomas-swirlds-labs marked this pull request as draft February 12, 2025 14:03
Copy link
Contributor

@Neeharika-Sompalli Neeharika-Sompalli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @thomas-swirlds-labs

Signed-off-by: Thomas Moran <[email protected]>
Copy link
Contributor

@jasperpotts jasperpotts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to have the optimization to compute last block hash later

@@ -254,7 +254,6 @@ public void startRound(@NonNull final Round round, @NonNull final State state) {
worker = new BlockStreamManagerTask();
final var header = BlockHeader.newBuilder()
.number(blockNumber)
.previousBlockHash(lastBlockHash)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also be able to change when we compute lastBlockHash. The whole point of this change is so we have more time to compute it as it is not needed till the end of the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, we will do this in a small follow up PR 👍

Signed-off-by: Thomas Moran <[email protected]>
@thomas-swirlds-labs thomas-swirlds-labs marked this pull request as ready for review February 13, 2025 16:28
* </li>
* <li>The block hash SHALL be the SHA-384 hash calculated for the root
* of this merkle tree.</li>
* </ul>
*/
bytes previous_block_root_hash = 2;
Copy link
Contributor

@edward-swirldslabs edward-swirldslabs Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm, in order to check the signature in this BlockProof for Block 4, we have to compute the root hash of the merkle tree for Block 4, merge it with the sibling hashes and validate that the signature matches the result?

  • Where does the previous_block_root_hash fit into this picture?

I think there is a problem in this new formulation. If this is the BlockProof for Block 4, the root hash for Block 3 needs to be part of the merkletree of block 4 and signed. The BlockProof for Block 4 is outside of the merkle tree contributing to the block root hash for block 4. We deleted the previous block root hash from the block header, but did not re-add it anywhere else inside the merkle tree.

We need to add a new BlockItem that is the root hash of the previous block so that it is a formal part of the merkle tree being signed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasperpotts, can you double check my thoughts here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(Services) Remove previous_block_hash from BlockHeader
4 participants