-
Notifications
You must be signed in to change notification settings - Fork 839
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bonsai based reference test worldstate (#5686)
* create a bonsai based reference test worldstate -> getOrCreate in BonsaiWorldStateUpdateAccumulator - do not throw if we discover an empty account in a non-null BonsaiValue<Account> -> add curentStateRoot to t8n -> storageEntriesFrom and streamAccounts implemented in BonsaiWorldStateKeyValueStorage -> add endKey version of streamFromKey * bonsai fix for self-destruct and create2 at the same address and same block Signed-off-by: garyschulte <garyschulte@gmail.com> Signed-off-by: Karim TAAM <karim.t2am@gmail.com> Co-authored-by: Karim TAAM <karim.t2am@gmail.com>
- Loading branch information
1 parent
3538561
commit 4b2ef68
Showing
53 changed files
with
746 additions
and
141 deletions.
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
68 changes: 68 additions & 0 deletions
68
.../core/src/main/java/org/hyperledger/besu/ethereum/bonsai/storage/BonsaiPreImageProxy.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,68 @@ | ||
/* | ||
* 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.storage; | ||
|
||
import org.hyperledger.besu.datatypes.Address; | ||
import org.hyperledger.besu.datatypes.Hash; | ||
import org.hyperledger.besu.ethereum.worldstate.WorldStatePreimageStorage; | ||
|
||
import java.util.Optional; | ||
|
||
import com.google.common.collect.BiMap; | ||
import com.google.common.collect.HashBiMap; | ||
import org.apache.tuweni.bytes.Bytes; | ||
import org.apache.tuweni.bytes.Bytes32; | ||
import org.apache.tuweni.units.bigints.UInt256; | ||
|
||
/** Acts as both a Hasher and PreImageStorage for Bonsai storage format. */ | ||
public interface BonsaiPreImageProxy extends WorldStatePreimageStorage { | ||
/** | ||
* If this value is not already present, save in preImage store and return the hash value. | ||
* | ||
* @param value value to hash | ||
* @return Hash of value | ||
*/ | ||
Hash hashAndSavePreImage(Bytes value); | ||
|
||
/** | ||
* A caching PreImageProxy suitable for ReferenceTestWorldState which saves hashes in an unbounded | ||
* BiMap. | ||
*/ | ||
class BonsaiReferenceTestPreImageProxy implements BonsaiPreImageProxy { | ||
BiMap<Hash, Bytes> preImageCache = HashBiMap.create(); | ||
|
||
@Override | ||
public synchronized Hash hashAndSavePreImage(final Bytes value) { | ||
return preImageCache.inverse().computeIfAbsent(value, Hash::hash); | ||
} | ||
|
||
@Override | ||
public Optional<UInt256> getStorageTrieKeyPreimage(final Bytes32 trieKey) { | ||
return Optional.ofNullable(preImageCache.get(trieKey)).map(UInt256::fromBytes); | ||
} | ||
|
||
@Override | ||
public Optional<Address> getAccountTrieKeyPreimage(final Bytes32 trieKey) { | ||
return Optional.ofNullable(preImageCache.get(trieKey)).map(Address::wrap); | ||
} | ||
|
||
@Override | ||
public Updater updater() { | ||
throw new UnsupportedOperationException( | ||
"BonsaiReferenceTestPreImageProxy does not implement an updater"); | ||
} | ||
} | ||
} |
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
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.