storingBytes() {
- return create(bytes -> bytes);
- }
-
- /**
- * Create a trie with value of type {@link String}.
- *
- * Strings are stored in UTF-8 encoding.
- *
- * @return A new merkle trie.
- */
- static MerklePatriciaTrie storingStrings() {
- return create(s -> Bytes.wrap(s.getBytes(UTF_8)));
- }
-}
diff --git a/merkle-trie/src/main/java/net/consensys/cava/trie/StoredMerklePatriciaTrie.java b/merkle-trie/src/main/java/net/consensys/cava/trie/StoredMerklePatriciaTrie.java
deleted file mode 100644
index 0b31da0a..00000000
--- a/merkle-trie/src/main/java/net/consensys/cava/trie/StoredMerklePatriciaTrie.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright 2018 ConsenSys AG.
- *
- * 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.
- */
-package net.consensys.cava.trie;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-
-import net.consensys.cava.bytes.Bytes;
-import net.consensys.cava.bytes.Bytes32;
-
-import java.util.function.Function;
-
-public interface StoredMerklePatriciaTrie extends MerkleTrie {
-
- /**
- * Create a trie.
- *
- * @param storage The storage to use for persistence.
- * @param valueSerializer A function for serializing values to bytes.
- * @param valueDeserializer A function for deserializing values from bytes.
- * @param The serialized type.
- * @return A new merkle trie.
- */
- static StoredMerklePatriciaTrie create(
- MerkleStorage storage,
- Function valueSerializer,
- Function valueDeserializer) {
- return new net.consensys.cava.trie.experimental.StoredMerklePatriciaTrie<>(
- new CoroutineMerkleStorageAdapter(storage),
- valueSerializer,
- valueDeserializer);
- }
-
- /**
- * Create a trie.
- *
- * @param storage The storage to use for persistence.
- * @param rootHash The initial root has for the trie, which should be already present in {@code storage}.
- * @param valueSerializer A function for serializing values to bytes.
- * @param valueDeserializer A function for deserializing values from bytes.
- * @param The serialized type.
- * @return A new merkle trie.
- */
- static StoredMerklePatriciaTrie create(
- MerkleStorage storage,
- Bytes32 rootHash,
- Function valueSerializer,
- Function valueDeserializer) {
- return new net.consensys.cava.trie.experimental.StoredMerklePatriciaTrie<>(
- new CoroutineMerkleStorageAdapter(storage),
- rootHash,
- valueSerializer,
- valueDeserializer);
- }
-
- /**
- * Create a trie with value of type {@link Bytes}.
- *
- * @param storage The storage to use for persistence.
- * @return A new merkle trie.
- */
- static StoredMerklePatriciaTrie storingBytes(MerkleStorage storage) {
- return create(storage, bytes -> bytes, bytes -> bytes);
- }
-
- /**
- * Create a trie with value of type {@link Bytes}.
- *
- * @param storage The storage to use for persistence.
- * @param rootHash The initial root has for the trie, which should be already present in `storage`.
- * @return A new merkle trie.
- */
- static StoredMerklePatriciaTrie storingBytes(MerkleStorage storage, Bytes32 rootHash) {
- return create(storage, rootHash, bytes -> bytes, bytes -> bytes);
- }
-
- /**
- * Create a trie with value of type {@link String}.
- *
- * Strings are stored in UTF-8 encoding.
- *
- * @param storage The storage to use for persistence.
- * @return A new merkle trie.
- */
- static StoredMerklePatriciaTrie storingStrings(MerkleStorage storage) {
- return create(storage, s -> Bytes.wrap(s.getBytes(UTF_8)), bytes -> new String(bytes.toArrayUnsafe(), UTF_8));
- }
-
- /**
- * Create a trie with value of type {@link String}.
- *
- * Strings are stored in UTF-8 encoding.
- *
- * @param storage The storage to use for persistence.
- * @param rootHash The initial root has for the trie, which should be already present in `storage`.
- * @return A new merkle trie.
- */
- static StoredMerklePatriciaTrie storingStrings(MerkleStorage storage, Bytes32 rootHash) {
- return create(
- storage,
- rootHash,
- s -> Bytes.wrap(s.getBytes(UTF_8)),
- bytes -> new String(bytes.toArrayUnsafe(), UTF_8));
- }
-
- /**
- * Forces any cached trie nodes to be released, so they can be garbage collected.
- *
- * Note: nodes are already stored using {@link java.lang.ref.SoftReference}'s, so they will be released automatically
- * based on memory demands.
- */
- void clearCache();
-}
diff --git a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/BranchNode.kt b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/BranchNode.kt
similarity index 97%
rename from merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/BranchNode.kt
rename to merkle-trie/src/main/kotlin/net/consensys/cava/trie/BranchNode.kt
index 9a0551e2..75493adc 100644
--- a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/BranchNode.kt
+++ b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/BranchNode.kt
@@ -10,14 +10,13 @@
* 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.
*/
-package net.consensys.cava.trie.experimental
+package net.consensys.cava.trie
import net.consensys.cava.bytes.Bytes
import net.consensys.cava.bytes.Bytes32
import net.consensys.cava.bytes.MutableBytes
import net.consensys.cava.crypto.Hash.keccak256
import net.consensys.cava.rlp.RLP
-import net.consensys.cava.trie.CompactEncoding
import java.lang.ref.WeakReference
private val NULL_NODE: NullNode<*> = NullNode.instance()
diff --git a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/DefaultNodeFactory.kt b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/DefaultNodeFactory.kt
similarity index 93%
rename from merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/DefaultNodeFactory.kt
rename to merkle-trie/src/main/kotlin/net/consensys/cava/trie/DefaultNodeFactory.kt
index 70f89a14..b0917313 100644
--- a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/DefaultNodeFactory.kt
+++ b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/DefaultNodeFactory.kt
@@ -10,16 +10,18 @@
* 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.
*/
-package net.consensys.cava.trie.experimental
+package net.consensys.cava.trie
import net.consensys.cava.bytes.Bytes
import java.util.Collections
-internal class DefaultNodeFactory(private val valueSerializer: (V) -> Bytes) : NodeFactory {
+internal class DefaultNodeFactory(private val valueSerializer: (V) -> Bytes) :
+ NodeFactory {
private val nullNode: NullNode = NullNode.instance()
- override suspend fun createExtension(path: Bytes, child: Node): Node = ExtensionNode(path, child, this)
+ override suspend fun createExtension(path: Bytes, child: Node): Node =
+ ExtensionNode(path, child, this)
override suspend fun createBranch(leftIndex: Byte, left: Node, rightIndex: Byte, right: Node): Node {
assert(leftIndex <= BranchNode.RADIX)
diff --git a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/ExtensionNode.kt b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/ExtensionNode.kt
similarity index 96%
rename from merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/ExtensionNode.kt
rename to merkle-trie/src/main/kotlin/net/consensys/cava/trie/ExtensionNode.kt
index 4ce37e6b..773ef4e1 100644
--- a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/ExtensionNode.kt
+++ b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/ExtensionNode.kt
@@ -10,13 +10,12 @@
* 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.
*/
-package net.consensys.cava.trie.experimental
+package net.consensys.cava.trie
import net.consensys.cava.bytes.Bytes
import net.consensys.cava.bytes.Bytes32
import net.consensys.cava.crypto.Hash.keccak256
import net.consensys.cava.rlp.RLP
-import net.consensys.cava.trie.CompactEncoding
import java.lang.ref.WeakReference
internal class ExtensionNode(
diff --git a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/GetVisitor.kt b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/GetVisitor.kt
similarity index 93%
rename from merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/GetVisitor.kt
rename to merkle-trie/src/main/kotlin/net/consensys/cava/trie/GetVisitor.kt
index 116890b9..95d5887d 100644
--- a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/GetVisitor.kt
+++ b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/GetVisitor.kt
@@ -10,10 +10,9 @@
* 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.
*/
-package net.consensys.cava.trie.experimental
+package net.consensys.cava.trie
import net.consensys.cava.bytes.Bytes
-import net.consensys.cava.trie.CompactEncoding
internal class GetVisitor : NodeVisitor {
@@ -51,5 +50,6 @@ internal class GetVisitor : NodeVisitor {
return leafNode
}
- override suspend fun visit(nullNode: NullNode, path: Bytes): Node = NullNode.instance()
+ override suspend fun visit(nullNode: NullNode, path: Bytes): Node =
+ NullNode.instance()
}
diff --git a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/LeafNode.kt b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/LeafNode.kt
similarity index 95%
rename from merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/LeafNode.kt
rename to merkle-trie/src/main/kotlin/net/consensys/cava/trie/LeafNode.kt
index 437dd837..1b653fa8 100644
--- a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/LeafNode.kt
+++ b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/LeafNode.kt
@@ -10,13 +10,12 @@
* 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.
*/
-package net.consensys.cava.trie.experimental
+package net.consensys.cava.trie
import net.consensys.cava.bytes.Bytes
import net.consensys.cava.bytes.Bytes32
import net.consensys.cava.crypto.Hash.keccak256
import net.consensys.cava.rlp.RLP
-import net.consensys.cava.trie.CompactEncoding
import java.lang.ref.WeakReference
internal class LeafNode(
diff --git a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/MerklePatriciaTrie.kt b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/MerklePatriciaTrie.kt
similarity index 71%
rename from merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/MerklePatriciaTrie.kt
rename to merkle-trie/src/main/kotlin/net/consensys/cava/trie/MerklePatriciaTrie.kt
index 14643083..ed2d2a66 100644
--- a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/MerklePatriciaTrie.kt
+++ b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/MerklePatriciaTrie.kt
@@ -10,10 +10,11 @@
* 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.
*/
-package net.consensys.cava.trie.experimental
+package net.consensys.cava.trie
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.runBlocking
import net.consensys.cava.bytes.Bytes
import net.consensys.cava.bytes.Bytes32
import net.consensys.cava.concurrent.AsyncCompletion
@@ -33,16 +34,15 @@ internal fun stringDeserializer(b: Bytes): String = String(b.toArrayUnsafe(), UT
* @param valueSerializer A function for serializing values to bytes.
* @constructor Creates an empty trie.
*/
-class MerklePatriciaTrie(
- valueSerializer: (V) -> Bytes
-) : MerkleTrie, net.consensys.cava.trie.MerklePatriciaTrie {
+class MerklePatriciaTrie(valueSerializer: (V) -> Bytes) : MerkleTrie {
companion object {
/**
* Create a trie with keys and values of type [Bytes].
*/
@JvmStatic
- fun storingBytes(): MerklePatriciaTrie = MerklePatriciaTrie(::bytesIdentity)
+ fun storingBytes(): MerklePatriciaTrie =
+ MerklePatriciaTrie(::bytesIdentity)
/**
* Create a trie with value of type [String].
@@ -50,7 +50,19 @@ class MerklePatriciaTrie(
* Strings are stored in UTF-8 encoding.
*/
@JvmStatic
- fun storingStrings(): MerklePatriciaTrie = MerklePatriciaTrie(::stringSerializer)
+ fun storingStrings(): MerklePatriciaTrie =
+ MerklePatriciaTrie(::stringSerializer)
+
+ /**
+ * Create a trie.
+ *
+ * @param valueSerializer A function for serializing values to bytes.
+ * @param The serialized type.
+ * @return A new merkle trie.
+ */
+ @JvmStatic
+ fun create(valueSerializer: Function): MerklePatriciaTrie =
+ MerklePatriciaTrie(valueSerializer::apply)
}
private val getVisitor = GetVisitor()
@@ -58,18 +70,13 @@ class MerklePatriciaTrie(
private val nodeFactory: DefaultNodeFactory = DefaultNodeFactory(valueSerializer)
private var root: Node = NullNode.instance()
- /**
- * Creates an empty trie.
- *
- * @param valueSerializer A function for serializing values to bytes.
- */
- constructor(valueSerializer: Function) : this(valueSerializer::apply)
-
override suspend fun get(key: Bytes): V? = root.accept(getVisitor, bytesToPath(key)).value()
// This implementation does not suspend, so we can use the unconfined context
@UseExperimental(ExperimentalCoroutinesApi::class)
- override fun getAsync(key: Bytes): AsyncResult = getAsync(Dispatchers.Unconfined, key)
+ override fun getAsync(key: Bytes): AsyncResult = runBlocking(Dispatchers.Unconfined) {
+ AsyncResult.completed(get(key))
+ }
override suspend fun put(key: Bytes, value: V?) {
if (value == null) {
@@ -80,7 +87,10 @@ class MerklePatriciaTrie(
// This implementation does not suspend, so we can use the unconfined context
@UseExperimental(ExperimentalCoroutinesApi::class)
- override fun putAsync(key: Bytes, value: V?): AsyncCompletion = putAsync(Dispatchers.Unconfined, key, value)
+ override fun putAsync(key: Bytes, value: V?): AsyncCompletion = runBlocking(Dispatchers.Unconfined) {
+ put(key, value)
+ AsyncCompletion.completed()
+ }
override suspend fun remove(key: Bytes) {
this.root = root.accept(removeVisitor, bytesToPath(key))
@@ -88,14 +98,15 @@ class MerklePatriciaTrie(
// This implementation does not suspend, so we can use the unconfined context
@UseExperimental(ExperimentalCoroutinesApi::class)
- override fun removeAsync(key: Bytes): AsyncCompletion = removeAsync(Dispatchers.Unconfined, key)
+ override fun removeAsync(key: Bytes): AsyncCompletion = runBlocking(Dispatchers.Unconfined) {
+ remove(key)
+ AsyncCompletion.completed()
+ }
override fun rootHash(): Bytes32 = root.hash()
/**
* @return A string representation of the object.
*/
- override fun toString(): String {
- return javaClass.simpleName + "[" + rootHash() + "]"
- }
+ override fun toString(): String = javaClass.simpleName + "[" + rootHash() + "]"
}
diff --git a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/MerkleStorage.kt b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/MerkleStorage.kt
index 3155a9ab..bcea6941 100644
--- a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/MerkleStorage.kt
+++ b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/MerkleStorage.kt
@@ -27,9 +27,9 @@ interface MerkleStorage {
* Get the stored content under the given hash.
*
* @param hash The hash for the content.
- * @return An [AsyncResult] that will complete with the stored content or {@code null} if not found.
+ * @return The stored content, or {@code null} if not found.
*/
- fun getAsync(hash: Bytes32): AsyncResult
+ suspend fun get(hash: Bytes32): Bytes?
/**
* Store content with a given hash.
@@ -39,16 +39,35 @@ interface MerkleStorage {
*
* @param hash The hash for the content.
* @param content The content to store.
- * @return An [AsyncCompletion] that will complete when the content is stored.
*/
- fun putAsync(hash: Bytes32, content: Bytes): AsyncCompletion
+ suspend fun put(hash: Bytes32, content: Bytes)
}
-internal class CoroutineMerkleStorageAdapter(
- private val storage: MerkleStorage
-) : net.consensys.cava.trie.experimental.MerkleStorage {
+/**
+ * A [MerkleStorage] implementation using [AsyncResult]'s.
+ */
+abstract class AsyncMerkleStorage : MerkleStorage {
+ override suspend fun get(hash: Bytes32): Bytes? = getAsync(hash).await()
+
+ /**
+ * Get the stored content under the given hash.
+ *
+ * @param hash The hash for the content.
+ * @return An [AsyncResult] that will complete with the stored content or {@code null} if not found.
+ */
+ abstract fun getAsync(hash: Bytes32): AsyncResult
- override suspend fun get(hash: Bytes32): Bytes? = storage.getAsync(hash).await()
+ override suspend fun put(hash: Bytes32, content: Bytes) = putAsync(hash, content).await()
- override suspend fun put(hash: Bytes32, content: Bytes) = storage.putAsync(hash, content).await()
+ /**
+ * Store content with a given hash.
+ *
+ * Note: if the storage implementation already contains content for the given hash, it does not need to replace the
+ * existing content.
+ *
+ * @param hash The hash for the content.
+ * @param content The content to store.
+ * @return An [AsyncCompletion] that will complete when the content is stored.
+ */
+ abstract fun putAsync(hash: Bytes32, content: Bytes): AsyncCompletion
}
diff --git a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/MerkleStorageException.kt b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/MerkleStorageException.kt
similarity index 96%
rename from merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/MerkleStorageException.kt
rename to merkle-trie/src/main/kotlin/net/consensys/cava/trie/MerkleStorageException.kt
index fd8183cd..97bf1506 100644
--- a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/MerkleStorageException.kt
+++ b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/MerkleStorageException.kt
@@ -10,7 +10,7 @@
* 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.
*/
-package net.consensys.cava.trie.experimental
+package net.consensys.cava.trie
/**
* This exception is thrown when there is an issue retrieving or decoding values from [MerkleStorage].
diff --git a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/MerkleTrie.kt b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/MerkleTrie.kt
index 49b15c0e..4ffaabfc 100644
--- a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/MerkleTrie.kt
+++ b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/MerkleTrie.kt
@@ -12,10 +12,15 @@
*/
package net.consensys.cava.trie
+import kotlinx.coroutines.CoroutineDispatcher
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.GlobalScope
import net.consensys.cava.bytes.Bytes
import net.consensys.cava.bytes.Bytes32
import net.consensys.cava.concurrent.AsyncCompletion
import net.consensys.cava.concurrent.AsyncResult
+import net.consensys.cava.concurrent.coroutines.asyncCompletion
+import net.consensys.cava.concurrent.coroutines.asyncResult
import net.consensys.cava.crypto.Hash
import net.consensys.cava.rlp.RLP
@@ -34,10 +39,50 @@ interface MerkleTrie {
* Returns the value that corresponds to the specified key, or an empty byte array if no such value exists.
*
* @param key The key of the value to be returned.
- * @return An Optional containing the value that corresponds to the specified key, or an empty Optional if no such
- * value exists.
+ * @return The value that corresponds to the specified key, or {@code null} if no such value exists.
+ * @throws MerkleStorageException If there is an error while accessing or decoding data from storage.
*/
- fun getAsync(key: K): AsyncResult
+ suspend fun get(key: K): V?
+
+ /**
+ * Returns the value that corresponds to the specified key, or an empty byte array if no such value exists.
+ *
+ * @param key The key of the value to be returned.
+ * @return A value that corresponds to the specified key, or {@code null} if no such value exists.
+ */
+ fun getAsync(key: K): AsyncResult = getAsync(Dispatchers.Default, key)
+
+ /**
+ * Returns the value that corresponds to the specified key, or an empty byte array if no such value exists.
+ *
+ * @param key The key of the value to be returned.
+ * @param dispatcher The co-routine dispatcher for asynchronous tasks.
+ * @return A value that corresponds to the specified key, or {@code null} if no such value exists.
+ */
+ fun getAsync(dispatcher: CoroutineDispatcher, key: K): AsyncResult =
+ GlobalScope.asyncResult(dispatcher) { get(key) }
+
+ /**
+ * Updates the value that corresponds to the specified key, creating the value if one does not already exist.
+ *
+ * If the value is null, deletes the value that corresponds to the specified key, if such a value exists.
+ *
+ * @param key The key that corresponds to the value to be updated.
+ * @param value The value to associate the key with.
+ * @throws MerkleStorageException If there is an error while writing to storage.
+ */
+ suspend fun put(key: K, value: V?)
+
+ /**
+ * Updates the value that corresponds to the specified key, creating the value if one does not already exist.
+ *
+ * If the value is null, deletes the value that corresponds to the specified key, if such a value exists.
+ *
+ * @param key The key that corresponds to the value to be updated.
+ * @param value The value to associate the key with.
+ * @return A completion that will complete when the value has been put into the trie.
+ */
+ fun putAsync(key: K, value: V?): AsyncCompletion = putAsync(Dispatchers.Default, key, value)
/**
* Updates the value that corresponds to the specified key, creating the value if one does not already exist.
@@ -46,17 +91,37 @@ interface MerkleTrie {
*
* @param key The key that corresponds to the value to be updated.
* @param value The value to associate the key with.
+ * @param dispatcher The co-routine dispatcher for asynchronous tasks.
* @return A completion that will complete when the value has been put into the trie.
*/
- fun putAsync(key: K, value: V?): AsyncCompletion
+ fun putAsync(dispatcher: CoroutineDispatcher, key: K, value: V?): AsyncCompletion =
+ GlobalScope.asyncCompletion(dispatcher) { put(key, value) }
+
+ /**
+ * Deletes the value that corresponds to the specified key, if such a value exists.
+ *
+ * @param key The key of the value to be deleted.
+ * @throws MerkleStorageException If there is an error while writing to storage.
+ */
+ suspend fun remove(key: K)
+
+ /**
+ * Deletes the value that corresponds to the specified key, if such a value exists.
+ *
+ * @param key The key of the value to be deleted.
+ * @return A completion that will complete when the value has been removed.
+ */
+ fun removeAsync(key: K): AsyncCompletion = removeAsync(Dispatchers.Default, key)
/**
* Deletes the value that corresponds to the specified key, if such a value exists.
*
* @param key The key of the value to be deleted.
+ * @param dispatcher The co-routine dispatcher for asynchronous tasks.
* @return A completion that will complete when the value has been removed.
*/
- fun removeAsync(key: K): AsyncCompletion
+ fun removeAsync(dispatcher: CoroutineDispatcher, key: K): AsyncCompletion =
+ GlobalScope.asyncCompletion(dispatcher) { remove(key) }
/**
* Returns the KECCAK256 hash of the root node of the trie.
diff --git a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/Node.kt b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/Node.kt
similarity index 95%
rename from merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/Node.kt
rename to merkle-trie/src/main/kotlin/net/consensys/cava/trie/Node.kt
index f97cddfe..d3e18cea 100644
--- a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/Node.kt
+++ b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/Node.kt
@@ -10,7 +10,7 @@
* 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.
*/
-package net.consensys.cava.trie.experimental
+package net.consensys.cava.trie
import net.consensys.cava.bytes.Bytes
import net.consensys.cava.bytes.Bytes32
diff --git a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/NodeFactory.kt b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/NodeFactory.kt
similarity index 95%
rename from merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/NodeFactory.kt
rename to merkle-trie/src/main/kotlin/net/consensys/cava/trie/NodeFactory.kt
index 2384c355..24100912 100644
--- a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/NodeFactory.kt
+++ b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/NodeFactory.kt
@@ -10,7 +10,7 @@
* 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.
*/
-package net.consensys.cava.trie.experimental
+package net.consensys.cava.trie
import net.consensys.cava.bytes.Bytes
diff --git a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/NodeVisitor.kt b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/NodeVisitor.kt
similarity index 95%
rename from merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/NodeVisitor.kt
rename to merkle-trie/src/main/kotlin/net/consensys/cava/trie/NodeVisitor.kt
index 186f30e4..3f627aba 100644
--- a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/NodeVisitor.kt
+++ b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/NodeVisitor.kt
@@ -10,7 +10,7 @@
* 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.
*/
-package net.consensys.cava.trie.experimental
+package net.consensys.cava.trie
import net.consensys.cava.bytes.Bytes
diff --git a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/NullNode.kt b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/NullNode.kt
similarity index 97%
rename from merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/NullNode.kt
rename to merkle-trie/src/main/kotlin/net/consensys/cava/trie/NullNode.kt
index 6bccc94f..ddf0467e 100644
--- a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/NullNode.kt
+++ b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/NullNode.kt
@@ -10,7 +10,7 @@
* 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.
*/
-package net.consensys.cava.trie.experimental
+package net.consensys.cava.trie
import net.consensys.cava.bytes.Bytes
import net.consensys.cava.bytes.Bytes32
diff --git a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/PutVisitor.kt b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/PutVisitor.kt
similarity index 97%
rename from merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/PutVisitor.kt
rename to merkle-trie/src/main/kotlin/net/consensys/cava/trie/PutVisitor.kt
index d48627bb..9bdb650a 100644
--- a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/PutVisitor.kt
+++ b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/PutVisitor.kt
@@ -10,10 +10,9 @@
* 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.
*/
-package net.consensys.cava.trie.experimental
+package net.consensys.cava.trie
import net.consensys.cava.bytes.Bytes
-import net.consensys.cava.trie.CompactEncoding
internal class PutVisitor(
private val nodeFactory: NodeFactory,
diff --git a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/RemoveVisitor.kt b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/RemoveVisitor.kt
similarity index 94%
rename from merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/RemoveVisitor.kt
rename to merkle-trie/src/main/kotlin/net/consensys/cava/trie/RemoveVisitor.kt
index f4af4929..205ffec5 100644
--- a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/RemoveVisitor.kt
+++ b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/RemoveVisitor.kt
@@ -10,10 +10,9 @@
* 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.
*/
-package net.consensys.cava.trie.experimental
+package net.consensys.cava.trie
import net.consensys.cava.bytes.Bytes
-import net.consensys.cava.trie.CompactEncoding
internal class RemoveVisitor : NodeVisitor {
@@ -54,5 +53,6 @@ internal class RemoveVisitor : NodeVisitor {
return leafNode
}
- override suspend fun visit(nullNode: NullNode, path: Bytes): Node = NullNode.instance()
+ override suspend fun visit(nullNode: NullNode, path: Bytes): Node =
+ NullNode.instance()
}
diff --git a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/StoredMerklePatriciaTrie.kt b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/StoredMerklePatriciaTrie.kt
similarity index 77%
rename from merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/StoredMerklePatriciaTrie.kt
rename to merkle-trie/src/main/kotlin/net/consensys/cava/trie/StoredMerklePatriciaTrie.kt
index 97a2b49f..7eb92091 100644
--- a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/StoredMerklePatriciaTrie.kt
+++ b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/StoredMerklePatriciaTrie.kt
@@ -10,7 +10,7 @@
* 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.
*/
-package net.consensys.cava.trie.experimental
+package net.consensys.cava.trie
import net.consensys.cava.bytes.Bytes
import net.consensys.cava.bytes.Bytes32
@@ -23,7 +23,7 @@ import java.util.function.Function
*
* @param The type of values stored by this trie.
*/
-class StoredMerklePatriciaTrie : MerkleTrie, net.consensys.cava.trie.StoredMerklePatriciaTrie {
+class StoredMerklePatriciaTrie : MerkleTrie {
companion object {
/**
@@ -67,6 +67,44 @@ class StoredMerklePatriciaTrie : MerkleTrie, net.consensys.cava.tri
@JvmStatic
fun storingStrings(storage: MerkleStorage, rootHash: Bytes32): StoredMerklePatriciaTrie =
StoredMerklePatriciaTrie(storage, rootHash, ::stringSerializer, ::stringDeserializer)
+
+ /**
+ * Create a trie.
+ *
+ * @param storage The storage to use for persistence.
+ * @param valueSerializer A function for serializing values to bytes.
+ * @param valueDeserializer A function for deserializing values from bytes.
+ * @param The serialized type.
+ * @return A new merkle trie.
+ */
+ @JvmStatic
+ fun create(
+ storage: MerkleStorage,
+ valueSerializer: Function,
+ valueDeserializer: Function
+ ): StoredMerklePatriciaTrie {
+ return StoredMerklePatriciaTrie(storage, valueSerializer::apply, valueDeserializer::apply)
+ }
+
+ /**
+ * Create a trie.
+ *
+ * @param storage The storage to use for persistence.
+ * @param rootHash The initial root has for the trie, which should be already present in `storage`.
+ * @param valueSerializer A function for serializing values to bytes.
+ * @param valueDeserializer A function for deserializing values from bytes.
+ * @param The serialized type.
+ * @return A new merkle trie.
+ */
+ @JvmStatic
+ fun create(
+ storage: MerkleStorage,
+ rootHash: Bytes32,
+ valueSerializer: Function,
+ valueDeserializer: Function
+ ): StoredMerklePatriciaTrie {
+ return StoredMerklePatriciaTrie(storage, rootHash, valueSerializer::apply, valueDeserializer::apply)
+ }
}
private val getVisitor = GetVisitor()
@@ -75,19 +113,6 @@ class StoredMerklePatriciaTrie : MerkleTrie, net.consensys.cava.tri
private val nodeFactory: StoredNodeFactory
private var root: Node
- /**
- * Create a trie.
- *
- * @param storage The storage to use for persistence.
- * @param valueSerializer A function for serializing values to bytes.
- * @param valueDeserializer A function for deserializing values from bytes.
- */
- constructor(
- storage: MerkleStorage,
- valueSerializer: Function,
- valueDeserializer: Function
- ) : this(storage, EMPTY_TRIE_ROOT_HASH, valueSerializer::apply, valueDeserializer::apply)
-
/**
* Create a trie.
*
@@ -101,21 +126,6 @@ class StoredMerklePatriciaTrie : MerkleTrie, net.consensys.cava.tri
valueDeserializer: (Bytes) -> V
) : this(storage, EMPTY_TRIE_ROOT_HASH, valueSerializer, valueDeserializer)
- /**
- * Create a trie.
- *
- * @param storage The storage to use for persistence.
- * @param rootHash The initial root has for the trie, which should be already present in `storage`.
- * @param valueSerializer A function for serializing values to bytes.
- * @param valueDeserializer A function for deserializing values from bytes.
- */
- constructor(
- storage: MerkleStorage,
- rootHash: Bytes32,
- valueSerializer: Function,
- valueDeserializer: Function
- ) : this(storage, rootHash, valueSerializer::apply, valueDeserializer::apply)
-
/**
* Create a trie.
*
@@ -159,7 +169,7 @@ class StoredMerklePatriciaTrie : MerkleTrie, net.consensys.cava.tri
* Note: nodes are already stored using [java.lang.ref.SoftReference]'s, so they will be released automatically
* based on memory demands.
*/
- override fun clearCache() {
+ fun clearCache() {
val currentRoot = root
if (currentRoot is StoredNode<*>) {
currentRoot.unload()
diff --git a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/StoredNode.kt b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/StoredNode.kt
similarity index 98%
rename from merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/StoredNode.kt
rename to merkle-trie/src/main/kotlin/net/consensys/cava/trie/StoredNode.kt
index 0388d761..a07b87e6 100644
--- a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/StoredNode.kt
+++ b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/StoredNode.kt
@@ -10,7 +10,7 @@
* 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.
*/
-package net.consensys.cava.trie.experimental
+package net.consensys.cava.trie
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.Deferred
diff --git a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/StoredNodeFactory.kt b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/StoredNodeFactory.kt
similarity index 98%
rename from merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/StoredNodeFactory.kt
rename to merkle-trie/src/main/kotlin/net/consensys/cava/trie/StoredNodeFactory.kt
index 93e32a64..3a268a2f 100644
--- a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/StoredNodeFactory.kt
+++ b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/StoredNodeFactory.kt
@@ -10,14 +10,13 @@
* 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.
*/
-package net.consensys.cava.trie.experimental
+package net.consensys.cava.trie
import net.consensys.cava.bytes.Bytes
import net.consensys.cava.bytes.Bytes32
import net.consensys.cava.rlp.RLP
import net.consensys.cava.rlp.RLPException
import net.consensys.cava.rlp.RLPReader
-import net.consensys.cava.trie.CompactEncoding
import java.util.Collections
internal class StoredNodeFactory(
diff --git a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/MerkleStorage.kt b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/MerkleStorage.kt
deleted file mode 100644
index fba94778..00000000
--- a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/MerkleStorage.kt
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2018 ConsenSys AG.
- *
- * 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.
- */
-package net.consensys.cava.trie.experimental
-
-import net.consensys.cava.bytes.Bytes
-import net.consensys.cava.bytes.Bytes32
-
-/**
- * Storage for use in a [StoredMerklePatriciaTrie].
- */
-interface MerkleStorage {
-
- /**
- * Get the stored content under the given hash.
- *
- * @param hash The hash for the content.
- * @return The stored content, or {@code null} if not found.
- */
- suspend fun get(hash: Bytes32): Bytes?
-
- /**
- * Store content with a given hash.
- *
- * Note: if the storage implementation already contains content for the given hash, it does not need to replace the
- * existing content.
- *
- * @param hash The hash for the content.
- * @param content The content to store.
- */
- suspend fun put(hash: Bytes32, content: Bytes)
-}
diff --git a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/MerkleTrie.kt b/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/MerkleTrie.kt
deleted file mode 100644
index a6db7b15..00000000
--- a/merkle-trie/src/main/kotlin/net/consensys/cava/trie/experimental/MerkleTrie.kt
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright 2018 ConsenSys AG.
- *
- * 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.
- */
-package net.consensys.cava.trie.experimental
-
-import kotlinx.coroutines.CoroutineDispatcher
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.GlobalScope
-import net.consensys.cava.concurrent.AsyncCompletion
-import net.consensys.cava.concurrent.AsyncResult
-import net.consensys.cava.concurrent.coroutines.asyncCompletion
-import net.consensys.cava.concurrent.coroutines.asyncResult
-
-/**
- * A Merkle Trie.
- */
-interface MerkleTrie : net.consensys.cava.trie.MerkleTrie {
-
- /**
- * Returns the value that corresponds to the specified key, or an empty byte array if no such value exists.
- *
- * @param key The key of the value to be returned.
- * @return The value that corresponds to the specified key, or null if no such value exists.
- * @throws MerkleStorageException If there is an error while accessing or decoding data from storage.
- */
- suspend fun get(key: K): V?
-
- /**
- * Returns the value that corresponds to the specified key, or an empty byte array if no such value exists.
- *
- * @param key The key of the value to be returned.
- * @return An Optional containing the value that corresponds to the specified key, or an empty Optional if no such
- * value exists.
- */
- override fun getAsync(key: K): AsyncResult = getAsync(Dispatchers.Default, key)
-
- /**
- * Returns the value that corresponds to the specified key, or an empty byte array if no such value exists.
- *
- * @param key The key of the value to be returned.
- * @param dispatcher The co-routine dispatcher for asynchronous tasks.
- * @return An Optional containing the value that corresponds to the specified key, or an empty Optional if no such
- * value exists.
- */
- fun getAsync(dispatcher: CoroutineDispatcher, key: K): AsyncResult =
- GlobalScope.asyncResult(dispatcher) { get(key) }
-
- /**
- * Updates the value that corresponds to the specified key, creating the value if one does not already exist.
- *
- * If the value is null, deletes the value that corresponds to the specified key, if such a value exists.
- *
- * @param key The key that corresponds to the value to be updated.
- * @param value The value to associate the key with.
- * @throws MerkleStorageException If there is an error while writing to storage.
- */
- suspend fun put(key: K, value: V?)
-
- /**
- * Updates the value that corresponds to the specified key, creating the value if one does not already exist.
- *
- * If the value is null, deletes the value that corresponds to the specified key, if such a value exists.
- *
- * @param key The key that corresponds to the value to be updated.
- * @param value The value to associate the key with.
- * @return A completion that will complete when the value has been put into the trie.
- */
- override fun putAsync(key: K, value: V?): AsyncCompletion = putAsync(Dispatchers.Default, key, value)
-
- /**
- * Updates the value that corresponds to the specified key, creating the value if one does not already exist.
- *
- * If the value is null, deletes the value that corresponds to the specified key, if such a value exists.
- *
- * @param key The key that corresponds to the value to be updated.
- * @param value The value to associate the key with.
- * @param dispatcher The co-routine dispatcher for asynchronous tasks.
- * @return A completion that will complete when the value has been put into the trie.
- */
- fun putAsync(dispatcher: CoroutineDispatcher, key: K, value: V?): AsyncCompletion =
- GlobalScope.asyncCompletion(dispatcher) { put(key, value) }
-
- /**
- * Deletes the value that corresponds to the specified key, if such a value exists.
- *
- * @param key The key of the value to be deleted.
- * @throws MerkleStorageException If there is an error while writing to storage.
- */
- suspend fun remove(key: K)
-
- /**
- * Deletes the value that corresponds to the specified key, if such a value exists.
- *
- * @param key The key of the value to be deleted.
- * @return A completion that will complete when the value has been removed.
- */
- override fun removeAsync(key: K): AsyncCompletion = removeAsync(Dispatchers.Default, key)
-
- /**
- * Deletes the value that corresponds to the specified key, if such a value exists.
- *
- * @param key The key of the value to be deleted.
- * @param dispatcher The co-routine dispatcher for asynchronous tasks.
- * @return A completion that will complete when the value has been removed.
- */
- fun removeAsync(dispatcher: CoroutineDispatcher, key: K): AsyncCompletion =
- GlobalScope.asyncCompletion(dispatcher) { remove(key) }
-}
diff --git a/merkle-trie/src/test/java/net/consensys/cava/trie/StoredMerklePatriciaTrieJavaTest.java b/merkle-trie/src/test/java/net/consensys/cava/trie/StoredMerklePatriciaTrieJavaTest.java
index fffb2b60..dcdc1af8 100644
--- a/merkle-trie/src/test/java/net/consensys/cava/trie/StoredMerklePatriciaTrieJavaTest.java
+++ b/merkle-trie/src/test/java/net/consensys/cava/trie/StoredMerklePatriciaTrieJavaTest.java
@@ -37,7 +37,7 @@ class StoredMerklePatriciaTrieJavaTest {
@BeforeEach
void setup() {
Map storage = new HashMap<>();
- merkleStorage = new MerkleStorage() {
+ merkleStorage = new AsyncMerkleStorage() {
@Override
public @NotNull AsyncResult getAsync(@NotNull Bytes32 hash) {
return AsyncResult.completed(storage.get(hash));
diff --git a/merkle-trie/src/test/kotlin/net/consensys/cava/trie/experimental/MerklePatriciaTrieKotlinTest.kt b/merkle-trie/src/test/kotlin/net/consensys/cava/trie/MerklePatriciaTrieKotlinTest.kt
similarity index 99%
rename from merkle-trie/src/test/kotlin/net/consensys/cava/trie/experimental/MerklePatriciaTrieKotlinTest.kt
rename to merkle-trie/src/test/kotlin/net/consensys/cava/trie/MerklePatriciaTrieKotlinTest.kt
index dfed1d37..95263e3c 100644
--- a/merkle-trie/src/test/kotlin/net/consensys/cava/trie/experimental/MerklePatriciaTrieKotlinTest.kt
+++ b/merkle-trie/src/test/kotlin/net/consensys/cava/trie/MerklePatriciaTrieKotlinTest.kt
@@ -10,7 +10,7 @@
* 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.
*/
-package net.consensys.cava.trie.experimental
+package net.consensys.cava.trie
import kotlinx.coroutines.runBlocking
import net.consensys.cava.bytes.Bytes
diff --git a/merkle-trie/src/test/kotlin/net/consensys/cava/trie/experimental/StoredMerklePatriciaTrieKotlinTest.kt b/merkle-trie/src/test/kotlin/net/consensys/cava/trie/StoredMerklePatriciaTrieKotlinTest.kt
similarity index 99%
rename from merkle-trie/src/test/kotlin/net/consensys/cava/trie/experimental/StoredMerklePatriciaTrieKotlinTest.kt
rename to merkle-trie/src/test/kotlin/net/consensys/cava/trie/StoredMerklePatriciaTrieKotlinTest.kt
index 4bb4affc..ee080441 100644
--- a/merkle-trie/src/test/kotlin/net/consensys/cava/trie/experimental/StoredMerklePatriciaTrieKotlinTest.kt
+++ b/merkle-trie/src/test/kotlin/net/consensys/cava/trie/StoredMerklePatriciaTrieKotlinTest.kt
@@ -10,7 +10,7 @@
* 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.
*/
-package net.consensys.cava.trie.experimental
+package net.consensys.cava.trie
import kotlinx.coroutines.runBlocking
import net.consensys.cava.bytes.Bytes
@@ -29,6 +29,7 @@ internal class StoredMerklePatriciaTrieKotlinTest {
private lateinit var storage: MutableMap
private val merkleStorage = object : MerkleStorage {
override suspend fun get(hash: Bytes32): Bytes? = storage[hash]
+
override suspend fun put(hash: Bytes32, content: Bytes) {
storage[hash] = content
}
diff --git a/net-coroutines/src/test/java/net/consensys/cava/net/coroutines/experimental/SelectorTest.java b/net-coroutines/src/test/java/net/consensys/cava/net/coroutines/SelectorTest.java
similarity index 98%
rename from net-coroutines/src/test/java/net/consensys/cava/net/coroutines/experimental/SelectorTest.java
rename to net-coroutines/src/test/java/net/consensys/cava/net/coroutines/SelectorTest.java
index 2d23cf47..6e5e30f2 100644
--- a/net-coroutines/src/test/java/net/consensys/cava/net/coroutines/experimental/SelectorTest.java
+++ b/net-coroutines/src/test/java/net/consensys/cava/net/coroutines/SelectorTest.java
@@ -10,7 +10,7 @@
* 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.
*/
-package net.consensys.cava.net.coroutines.experimental;
+package net.consensys.cava.net.coroutines;
import static java.nio.channels.SelectionKey.OP_READ;
import static org.junit.jupiter.api.Assertions.assertFalse;
diff --git a/units/src/test/java/net/consensys/cava/units/bigints/test/BaseUInt256ValueTest.java b/units/src/test/java/net/consensys/cava/units/bigints/BaseUInt256ValueTest.java
similarity index 99%
rename from units/src/test/java/net/consensys/cava/units/bigints/test/BaseUInt256ValueTest.java
rename to units/src/test/java/net/consensys/cava/units/bigints/BaseUInt256ValueTest.java
index 394a20b1..7b545039 100644
--- a/units/src/test/java/net/consensys/cava/units/bigints/test/BaseUInt256ValueTest.java
+++ b/units/src/test/java/net/consensys/cava/units/bigints/BaseUInt256ValueTest.java
@@ -10,14 +10,12 @@
* 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.
*/
-package net.consensys.cava.units.bigints.test;
+package net.consensys.cava.units.bigints;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import net.consensys.cava.bytes.Bytes;
-import net.consensys.cava.units.bigints.BaseUInt256Value;
-import net.consensys.cava.units.bigints.UInt256;
import java.math.BigInteger;
import java.util.stream.Stream;
diff --git a/units/src/test/java/net/consensys/cava/units/bigints/Uint256Test.java b/units/src/test/java/net/consensys/cava/units/bigints/UInt256Test.java
similarity index 100%
rename from units/src/test/java/net/consensys/cava/units/bigints/Uint256Test.java
rename to units/src/test/java/net/consensys/cava/units/bigints/UInt256Test.java
diff --git a/units/src/test/java/net/consensys/cava/units/bigints/test/GasTest.java b/units/src/test/java/net/consensys/cava/units/ethereum/GasTest.java
similarity index 94%
rename from units/src/test/java/net/consensys/cava/units/bigints/test/GasTest.java
rename to units/src/test/java/net/consensys/cava/units/ethereum/GasTest.java
index 6aee8545..efd39c42 100644
--- a/units/src/test/java/net/consensys/cava/units/bigints/test/GasTest.java
+++ b/units/src/test/java/net/consensys/cava/units/ethereum/GasTest.java
@@ -10,16 +10,13 @@
* 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.
*/
-package net.consensys.cava.units.bigints.test;
+package net.consensys.cava.units.ethereum;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import net.consensys.cava.units.ethereum.Gas;
-import net.consensys.cava.units.ethereum.Wei;
-
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
diff --git a/units/src/test/java/net/consensys/cava/units/bigints/test/WeiTest.java b/units/src/test/java/net/consensys/cava/units/ethereum/WeiTest.java
similarity index 95%
rename from units/src/test/java/net/consensys/cava/units/bigints/test/WeiTest.java
rename to units/src/test/java/net/consensys/cava/units/ethereum/WeiTest.java
index aacb8464..65250d24 100644
--- a/units/src/test/java/net/consensys/cava/units/bigints/test/WeiTest.java
+++ b/units/src/test/java/net/consensys/cava/units/ethereum/WeiTest.java
@@ -10,15 +10,13 @@
* 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.
*/
-package net.consensys.cava.units.bigints.test;
+package net.consensys.cava.units.ethereum;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import net.consensys.cava.units.ethereum.Wei;
-
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;