-
Notifications
You must be signed in to change notification settings - Fork 879
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
Feature/multi version flat db #5865
Closed
garyschulte
wants to merge
1
commit into
hyperledger:main
from
garyschulte:feature/multi-version-flat-db
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/BonsaiContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright Hyperledger Besu Contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
package org.hyperledger.besu.ethereum.bonsai; | ||
|
||
import org.hyperledger.besu.plugin.data.BlockHeader; | ||
|
||
import java.util.Optional; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
/** Context which holds information relevant to a bonsai archive storage query. */ | ||
public class BonsaiContext { | ||
|
||
private final AtomicReference<BlockHeader> blockHeader; | ||
|
||
public BonsaiContext() { | ||
blockHeader = new AtomicReference<>(); | ||
} | ||
|
||
public BonsaiContext copy() { | ||
var newCtx = new BonsaiContext(); | ||
Optional.ofNullable(blockHeader.get()).ifPresent(newCtx::setBlockHeader); | ||
return newCtx; | ||
} | ||
|
||
public BonsaiContext setBlockHeader(final BlockHeader blockHeader) { | ||
this.blockHeader.set(blockHeader); | ||
return this; | ||
} | ||
|
||
public Optional<BlockHeader> getBlockHeader() { | ||
return Optional.ofNullable(blockHeader.get()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure why we are doing that . seems not clear to clone only the flatdb . It seems to be better to follow the logic of bonsai to clone all the storage if we need a clone and pass this clone to BonsaiWorldstate . like that no need to have a specific clone for flat db .
just passing a clone of the storage to the worldstate and the internal flat db will check directly the snapshot automatically
I'm also not fan to clone everytime. we had problem before because of that . I think we can use the same code as before . using the clone in the cache and if not present create a new one (without rollback)
When we will have the checkpointed trie we will have to add again the rollback. maybe an optional rolling depending if we need the state or not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just saw that the current implemention is a hack for testing 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There isn't really any cloning exactly, contextSafeClone exists only to directly reuse the flatdb storage, but with a different bonsai context for a different block number. For example we don't want RPC queries to modify the bonsai context, because that will mess up the block suffixing when we persist.
We need to guard the bonsai context for the primary worldstate, but otherwise as long as we are not persisting, there is no need to snapshot or clone the database itself.
So clone is probably not the best name for this, better naming suggestions welcome :). My thinking here is that as long as this is a 'non-persisting' mutable worldstate, we can just hand out the primary worldstate storage with whatever bonsai context the caller is requesting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we should have a different BonsaiWorldState subclass that better reflects that it is non-persisting and limited to flatdb only for reads. Right now we use non-persisting worldstates to propose blocks, so we might need some other "marker" to indicate we can hand out a worldstate that is both non-persisting and non-mutable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Layered storage is already doing this. It is not a clone and prevents modification. I would like to limit the number of classes to keep the same logic as much as possible. We also have the notion of Frozen BonsaiWorldState . The idea imo is to have a single worldstate and give a storage to this one. And at the storage level it will be different . Maybe I'm wrong but I think we have to think about this because we did the refactoring to reduce the number of worldstate class etc and I think that we must avoid redoing what we removed
So I would say that we should have just a Layered Storage that wraps it and give it to the worldstate. And we freeze the worldstate as we are doing with bonsai before rpc call. Then find out if we should have a special worldstate for flat DB. I think we have to wait to see the implementation of the checkpointed trie. We could access in one worldstate to the flat db directly and the checkpointed trie in lazy mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Freeze's call is already wrapping the storage with layered storage https://github.com/hyperledger/besu/blob/main/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/worldview/BonsaiWorldState.java#L592
Here
https://github.com/hyperledger/besu/blob/main/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/BonsaiWorldStateProvider.java#L177
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally, I think that it is in the creation of the worldstate storage that we will give the context of the block number.
BonsaiWorldstate doesn't need to know this.