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

Create a specific calculateRootHash method for BonsaiInMemoryWorldState to improve performance #4568

Merged
merged 12 commits into from
Nov 2, 2022

Conversation

ahamlat
Copy link
Contributor

@ahamlat ahamlat commented Oct 27, 2022

PR description

Create a specific calculateRootHash for BonsaiInMemoryWorldState, avoid committing and rollbacking as it is not necessary. This PR parallelize also the accounts update storage in calculateRootHash method.

The yellow line below is the version with the modifications in this PR, the other node is used as a reference node (a baseline) regarding block size and the number of transactions per block.

image

We have below engine_newPayloadV1 RPC call (Block processing) mean time comparaison between this PR, version 22.7.6 and version 22.7.7

image

We can notice also that calculateRootHash method is consuming less (real) time on CPU because of the parallelization and the fact we removed commit and rollback method.

Before this PR
image

After this PR
image

Fixed Issue(s)

Mitigate #4549

Documentation

  • I thought about documentation and added the doc-change-required label to this PR if
    updates are required.

Changelog

@macfarla
Copy link
Contributor

macfarla commented Nov 2, 2022

These files required manual handling in commit da8904d:
both modified: ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueries.java
both modified: ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreator.java
both modified: ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/BonsaiPersistedWorldState.java
both modified: ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/BonsaiSnapshotWorldState.java
both modified: ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/BonsaiWorldStateArchive.java
both modified: ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/BonsaiWorldStateUpdater.java
both modified: ethereum/core/src/test/java/org/hyperledger/besu/ethereum/MainnetBlockValidatorTest.java
both added: ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/BonsaiSnapshotWorldStateArchiveTest.java
both modified: plugin-api/build.gradle

garyschulte added a commit to garyschulte/besu that referenced this pull request Nov 2, 2022
Signed-off-by: garyschulte <garyschulte@gmail.com>
… method

Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
@garyschulte
Copy link
Contributor

@ahamlat - I took the liberty of rebasing this off of main. the merges of main and rc3 branch were making the commit history too hard to follow.

Signed-off-by: garyschulte <garyschulte@gmail.com>
garyschulte added a commit to garyschulte/besu that referenced this pull request Nov 2, 2022
Signed-off-by: garyschulte <garyschulte@gmail.com>
garyschulte added a commit to garyschulte/besu that referenced this pull request Nov 2, 2022
Signed-off-by: garyschulte <garyschulte@gmail.com>
Copy link
Contributor

@macfarla macfarla left a comment

Choose a reason for hiding this comment

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

LGTM

garyschulte added a commit that referenced this pull request Nov 2, 2022
Signed-off-by: garyschulte <garyschulte@gmail.com>
} finally {
updater.rollback();
final Hash calculatedRootHash = calculateRootHash(localUpdater);
return Hash.wrap(calculatedRootHash);
Copy link
Contributor

Choose a reason for hiding this comment

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

it can be one line

@ahamlat ahamlat merged commit b50f866 into hyperledger:main Nov 2, 2022
fab-10 added a commit to fab-10/besu that referenced this pull request Nov 3, 2022
commit 0d24b22
Author: Fabio Di Fabio <fabio.difabio@consensys.net>
Date:   Wed Nov 2 21:34:35 2022 +0100

    Preparing for next release (hyperledger#4595)

    Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

commit b50f866
Author: ahamlat <ameziane.hamlat@consensys.net>
Date:   Wed Nov 2 18:05:15 2022 +0100

    Create a specific calculateRootHash method for BonsaiInMemoryWorldState to improve performance (hyperledger#4568)

    * Parallelize some steps in BonsaiPersistedWorldState.calculateRootHash  method
    Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

    * Add synchronized on storage flat database remove and update method

    Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

    * Add synchronized on storage flat database remove and update method

    Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

    * Fix this error org.rocksdb.RocksDBException: unknown WriteBatch tag

    Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

    * create a specific calculateRootHash for BonsaiInMemoryWorldState class

    Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

    * create a specific calculateRootHash for BonsaiInMemoryWorldState class

    Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

    * Fix nullPointerException on Collections.synchronizedSet

    Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

    * Use parallelStreams instead of CompletableFuture API

    Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

    * Modify CHANGELOG.md

    Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

    * spotless and synchronizedSet initializaton

    Signed-off-by: garyschulte <garyschulte@gmail.com>

    Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
    Signed-off-by: garyschulte <garyschulte@gmail.com>
    Co-authored-by: garyschulte <garyschulte@gmail.com>
    Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
macfarla added a commit to jflo/besu that referenced this pull request Jan 10, 2023
…te to improve performance (hyperledger#4568)

* Parallelize some steps in BonsaiPersistedWorldState.calculateRootHash  method
Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

* Add synchronized on storage flat database remove and update method

Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

* Add synchronized on storage flat database remove and update method

Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

* Fix this error org.rocksdb.RocksDBException: unknown WriteBatch tag

Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

* create a specific calculateRootHash for BonsaiInMemoryWorldState class

Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

* create a specific calculateRootHash for BonsaiInMemoryWorldState class

Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

* Fix nullPointerException on Collections.synchronizedSet

Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

* Use parallelStreams instead of CompletableFuture API

Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

* Modify CHANGELOG.md

Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

* spotless and synchronizedSet initializaton

Signed-off-by: garyschulte <garyschulte@gmail.com>

Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
Signed-off-by: garyschulte <garyschulte@gmail.com>
Co-authored-by: garyschulte <garyschulte@gmail.com>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
eum602 pushed a commit to lacchain/besu that referenced this pull request Nov 3, 2023
…te to improve performance (hyperledger#4568)

* Parallelize some steps in BonsaiPersistedWorldState.calculateRootHash  method
Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

* Add synchronized on storage flat database remove and update method

Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

* Add synchronized on storage flat database remove and update method

Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

* Fix this error org.rocksdb.RocksDBException: unknown WriteBatch tag

Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

* create a specific calculateRootHash for BonsaiInMemoryWorldState class

Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

* create a specific calculateRootHash for BonsaiInMemoryWorldState class

Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

* Fix nullPointerException on Collections.synchronizedSet

Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

* Use parallelStreams instead of CompletableFuture API

Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

* Modify CHANGELOG.md

Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>

* spotless and synchronizedSet initializaton

Signed-off-by: garyschulte <garyschulte@gmail.com>

Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
Signed-off-by: garyschulte <garyschulte@gmail.com>
Co-authored-by: garyschulte <garyschulte@gmail.com>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
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.

4 participants