forked from hyperledger/besu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bonsai code storage by hash (hyperledger#6505)
Add a storage mode for Bonsai that can store the code by hash instead of account hash Signed-off-by: Jason Frame <jason.frame@consensys.net>
- Loading branch information
Showing
21 changed files
with
596 additions
and
68 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
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
54 changes: 54 additions & 0 deletions
54
...rg/hyperledger/besu/ethereum/trie/bonsai/storage/flat/AccountHashCodeStorageStrategy.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,54 @@ | ||
/* | ||
* 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.trie.bonsai.storage.flat; | ||
|
||
import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.CODE_STORAGE; | ||
|
||
import org.hyperledger.besu.datatypes.Hash; | ||
import org.hyperledger.besu.plugin.services.storage.SegmentedKeyValueStorage; | ||
import org.hyperledger.besu.plugin.services.storage.SegmentedKeyValueStorageTransaction; | ||
|
||
import java.util.Optional; | ||
|
||
import org.apache.tuweni.bytes.Bytes; | ||
|
||
public class AccountHashCodeStorageStrategy implements CodeStorageStrategy { | ||
@Override | ||
public Optional<Bytes> getFlatCode( | ||
final Hash codeHash, final Hash accountHash, final SegmentedKeyValueStorage storage) { | ||
return storage | ||
.get(CODE_STORAGE, accountHash.toArrayUnsafe()) | ||
.map(Bytes::wrap) | ||
.filter(b -> Hash.hash(b).equals(codeHash)); | ||
} | ||
|
||
@Override | ||
public void putFlatCode( | ||
final SegmentedKeyValueStorageTransaction transaction, | ||
final Hash accountHash, | ||
final Hash codeHash, | ||
final Bytes code) { | ||
transaction.put(CODE_STORAGE, accountHash.toArrayUnsafe(), code.toArrayUnsafe()); | ||
} | ||
|
||
@Override | ||
public void removeFlatCode( | ||
final SegmentedKeyValueStorageTransaction transaction, | ||
final Hash accountHash, | ||
final Hash codeHash) { | ||
transaction.remove(CODE_STORAGE, accountHash.toArrayUnsafe()); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...a/org/hyperledger/besu/ethereum/trie/bonsai/storage/flat/CodeHashCodeStorageStrategy.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,55 @@ | ||
/* | ||
* 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.trie.bonsai.storage.flat; | ||
|
||
import static org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier.CODE_STORAGE; | ||
|
||
import org.hyperledger.besu.datatypes.Hash; | ||
import org.hyperledger.besu.plugin.services.storage.SegmentedKeyValueStorage; | ||
import org.hyperledger.besu.plugin.services.storage.SegmentedKeyValueStorageTransaction; | ||
|
||
import java.util.Optional; | ||
|
||
import org.apache.tuweni.bytes.Bytes; | ||
|
||
public class CodeHashCodeStorageStrategy implements CodeStorageStrategy { | ||
|
||
@Override | ||
public Optional<Bytes> getFlatCode( | ||
final Hash codeHash, final Hash accountHash, final SegmentedKeyValueStorage storage) { | ||
return storage.get(CODE_STORAGE, codeHash.toArrayUnsafe()).map(Bytes::wrap); | ||
} | ||
|
||
@Override | ||
public void putFlatCode( | ||
final SegmentedKeyValueStorageTransaction transaction, | ||
final Hash accountHash, | ||
final Hash codeHash, | ||
final Bytes code) { | ||
transaction.put(CODE_STORAGE, codeHash.toArrayUnsafe(), code.toArrayUnsafe()); | ||
} | ||
|
||
@Override | ||
public void removeFlatCode( | ||
final SegmentedKeyValueStorageTransaction transaction, | ||
final Hash accountHash, | ||
final Hash codeHash) {} | ||
|
||
public static boolean isCodeHashValue(final byte[] key, final byte[] value) { | ||
final Hash valueHash = Hash.hash(Bytes.wrap(value)); | ||
return Bytes.wrap(key).equals(valueHash); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...main/java/org/hyperledger/besu/ethereum/trie/bonsai/storage/flat/CodeStorageStrategy.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,41 @@ | ||
/* | ||
* 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.trie.bonsai.storage.flat; | ||
|
||
import org.hyperledger.besu.datatypes.Hash; | ||
import org.hyperledger.besu.plugin.services.storage.SegmentedKeyValueStorage; | ||
import org.hyperledger.besu.plugin.services.storage.SegmentedKeyValueStorageTransaction; | ||
|
||
import java.util.Optional; | ||
|
||
import org.apache.tuweni.bytes.Bytes; | ||
|
||
public interface CodeStorageStrategy { | ||
|
||
Optional<Bytes> getFlatCode( | ||
final Hash codeHash, final Hash accountHash, final SegmentedKeyValueStorage storage); | ||
|
||
void putFlatCode( | ||
final SegmentedKeyValueStorageTransaction transaction, | ||
final Hash accountHash, | ||
final Hash codeHash, | ||
final Bytes code); | ||
|
||
void removeFlatCode( | ||
final SegmentedKeyValueStorageTransaction transaction, | ||
final Hash accountHash, | ||
final Hash codeHash); | ||
} |
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.