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

Snapshot based non-persisting MutableWorldState usage #4531

Conversation

garyschulte
Copy link
Contributor

@garyschulte garyschulte commented Oct 13, 2022

PR description

Adds Bonsai snapshots as an experimental option (--Xbonsai-use-snapshots) into BonsaiWorldStateArchive for arbitrary mutable non-persisting worldstate. Also refactors TrieLogManager into a LayeredTrieLogManager and SnapshotTrieLogManager such that cached worldstates use either layered worldstates or snapshot worldstates.

Since snapshot transactions need to release their snapshot in order to allow their logs to be compacted, this PR refactors direct uses of mutable worldstates to be in try-with-resources blocks (to auto-close snapshots after usage):

  • MainnetTransactionValidator
  • AbstractBlockCreator
  • TransactionSimulator
  • TransactionPool.validateTransaction

Fixed Issue(s)

relates to #4372
relates to #4250
relates to #4199
relates to #4151

Documentation

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

Changelog

@lgtm-com
Copy link

lgtm-com bot commented Oct 13, 2022

This pull request introduces 1 alert when merging dcfcc53 into d73ce21 - view on LGTM.com

new alerts:

  • 1 for Type mismatch on container modification

@garyschulte garyschulte force-pushed the feature/snapshot-based-mergecoordinator branch 6 times, most recently from 64a6d35 to 6377bb0 Compare October 19, 2022 06:58
@garyschulte garyschulte force-pushed the feature/snapshot-based-mergecoordinator branch 3 times, most recently from a9df9b3 to a07d7d2 Compare October 24, 2022 10:00
@garyschulte garyschulte force-pushed the feature/snapshot-based-mergecoordinator branch from 267fd18 to 94a0b25 Compare October 26, 2022 20:29
@garyschulte garyschulte marked this pull request as ready for review October 27, 2022 02:55
@garyschulte garyschulte force-pushed the feature/snapshot-based-mergecoordinator branch 3 times, most recently from bba8cb0 to 93459f4 Compare October 29, 2022 21:32
@garyschulte garyschulte force-pushed the feature/snapshot-based-mergecoordinator branch from 46b8bab to 099a762 Compare October 31, 2022 17:04
} catch (final EmptySimulatorResultException e) {
LOG.error(
"Empty simulator result, call params: {}, blockHeader: {} ",
JsonCallParameterUtil.validateAndGetCallParams(requestContext),

Check notice

Code scanning / CodeQL

Use of default toString()

Default toString(): JsonCallParameter inherits toString() from Object, and so is not suitable for printing.
@garyschulte garyschulte force-pushed the feature/snapshot-based-mergecoordinator branch from 7c074aa to c03c476 Compare November 1, 2022 17:36
Copy link
Contributor

@gezero gezero left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@jflo jflo left a comment

Choose a reason for hiding this comment

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

just a couple of minor optional notes, but this is pretty awesome.

final Optional<Hash> blockHashByNumber = blockchain.getBlockHashByNumber(blockNumber);
if (blockHashByNumber.isPresent()) {
return getMutable(null, blockHashByNumber.get(), isPersistingState);
final Hash rootHash, final Hash blockHash, final boolean shouldPersistState) {
Copy link
Contributor

Choose a reason for hiding this comment

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

rootHash is only needed if shouldPersistState == true, and in that case it is not passed any further along. Could be deleted.

… usages

  includes: try-with-resources and AutoCloseable in order to relase snapshots when we are done with them
  still outstanding:
   .. try-with-resources on transaction simulation stuff
   .. jsonrpc query stuff
   .. figure out what to do with the collection of layered worldstates (keep and base on snapshot?, or just ditch?)

Signed-off-by: garyschulte <garyschulte@gmail.com>
Signed-off-by: garyschulte <garyschulte@gmail.com>
…tateUpdater based snapshot worldstates for performance comparison

Signed-off-by: garyschulte <garyschulte@gmail.com>
Signed-off-by: garyschulte <garyschulte@gmail.com>
 still outstanding:
  - add and implement snapshot-capable subclass of StorageProvider
  - add --Xsnapshot-bonsai CLI flag

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

Signed-off-by: garyschulte <garyschulte@gmail.com>
Signed-off-by: garyschulte <garyschulte@gmail.com>
…adability refactor, rethrow unchecked exception in BlockchainQueries

Signed-off-by: garyschulte <garyschulte@gmail.com>
Signed-off-by: garyschulte <garyschulte@gmail.com>
…ate, not just restart a new transaction from the original snapshot

Signed-off-by: garyschulte <garyschulte@gmail.com>
…apshotPersistedWorldState rather than an explicitly managed flag

Signed-off-by: garyschulte <garyschulte@gmail.com>
Signed-off-by: garyschulte <garyschulte@gmail.com>
Signed-off-by: garyschulte <garyschulte@gmail.com>
…rces autoclosing mutableworldstate

Signed-off-by: garyschulte <garyschulte@gmail.com>
Signed-off-by: garyschulte <garyschulte@gmail.com>
Signed-off-by: garyschulte <garyschulte@gmail.com>
…te in TransactionSimulator

Signed-off-by: garyschulte <garyschulte@gmail.com>
@garyschulte garyschulte force-pushed the feature/snapshot-based-mergecoordinator branch from c03c476 to b5c64ab Compare November 1, 2022 22:32
@garyschulte garyschulte enabled auto-merge (squash) November 1, 2022 22:34
@garyschulte garyschulte merged commit 76d6429 into hyperledger:main Nov 1, 2022
macfarla pushed a commit to macfarla/besu that referenced this pull request Jan 10, 2023
* implementation of Bonsai snapshots based BonsaiWorldStateArchive
  includes: try-with-resources and AutoCloseable WorldState in order to release snapshots when we are done with them

Signed-off-by: garyschulte <garyschulte@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
* implementation of Bonsai snapshots based BonsaiWorldStateArchive 
  includes: try-with-resources and AutoCloseable WorldState in order to release snapshots when we are done with them

Signed-off-by: garyschulte <garyschulte@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants