-
-
Save matkt/3f550cbf962c597db48710d69a31d71e to your computer and use it in GitHub Desktop.
Verkle trie
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
/* | |
* 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.verkle; | |
import org.apache.tuweni.bytes.Bytes; | |
import org.apache.tuweni.bytes.Bytes32; | |
public interface NodeUpdater { | |
//This method is called to ask Besu to save the node in the database (value is the node represented as a list of bytes. | |
//RLP or something else for verkle). | |
void store(Bytes location, Bytes32 hash, Bytes value); | |
} |
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
/* | |
* 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 | |
*/ | |
public interface PathNodeVisitor<V> { | |
//At each step, the Verkle Trie traversal can either descend to a child node or modify the tree to update | |
//its structure based on specific requirements. A visiting step on a stem node may involve descending to visit | |
//another type of node subsequently. | |
Node<V> visit(StemNode<V> stemNode, Bytes path); | |
Node<V> visit(ExtensionNode<V> extensionNode, Bytes path); | |
Node<V> visit(SuffixNode<V> suffixNode, Bytes path); | |
Node<V> visit(LeafNode<V> leafNode, Bytes path); | |
Node<V> visit(NullNode<V> nullNode, Bytes path); | |
} |
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
/* | |
* 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.patricia; | |
import org.hyperledger.besu.ethereum.trie.CompactEncoding; | |
import org.hyperledger.besu.ethereum.trie.Node; | |
import org.hyperledger.besu.ethereum.trie.NodeFactory; | |
import org.hyperledger.besu.ethereum.trie.NullNode; | |
import org.hyperledger.besu.ethereum.trie.verkle.PathNodeVisitor; | |
import org.apache.tuweni.bytes.Bytes; | |
public class PutVisitor<V> implements PathNodeVisitor<V> { | |
private final NodeFactory<V> nodeFactory; | |
private final V value; | |
public PutVisitor(final NodeFactory<V> nodeFactory, final V value) { | |
this.nodeFactory = nodeFactory; | |
this.value = value; | |
} | |
@Override | |
public Node<V> visit(final StemNode<V> stemNode, final Bytes path) { | |
// | |
} | |
@Override | |
public Node<V> visit(final ExtensionNode<V> extensionNode, final Bytes path) { | |
// | |
} | |
@Override | |
public Node<V> visit(final SuffixNode<V> suffixNode, final Bytes path) { | |
// | |
} | |
@Override | |
public Node<V> visit(final LeafNode<V> leafNode, final Bytes path) { | |
// | |
} | |
@Override | |
public Node<V> visit(final NullNode<V> nullNode, final Bytes path) { | |
// | |
} | |
} |
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
/* | |
* 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.verkle; | |
import java.util.Optional; | |
import org.apache.tuweni.bytes.Bytes32; | |
import org.hyperledger.besu.ethereum.trie.PathNodeVisitor; | |
/** Verkle Trie. */ | |
public interface VerkleTrie<K, V> { | |
/** | |
* Returns an {@code Optional} of value mapped to the hash if it exists; otherwise empty. | |
* | |
* @param key The key for the value. | |
* @return an {@code Optional} of value mapped to the hash if it exists; otherwise empty | |
*/ | |
Optional<V> get(K key); | |
/** | |
* Returns an {@code Optional} of value mapped to the hash if it exists; otherwise empty. | |
* | |
* @param key The key for the value. | |
* @param getVisitor custom visitor for the get | |
* @return an {@code Optional} of value mapped to the hash if it exists; otherwise empty | |
*/ | |
Optional<V> get(K key, GetVisitor<V> getVisitor); | |
/** | |
* Updates the value mapped to the specified key, creating the mapping if one does not already | |
* exist. | |
* | |
* @param key The key that corresponds to the value to be updated. | |
* @param value The value to associate the key with. | |
*/ | |
void put(K key, V value); | |
/** | |
* Updates the value mapped to the specified key, creating the mapping if one does not already | |
* exist. | |
* | |
* @param key The key that corresponds to the value to be updated. | |
* @param putVisitor custom visitor for the update | |
*/ | |
void put(K key, PutVisitor<V> putVisitor); | |
/** | |
* Deletes the value mapped to the specified key, if such a value exists (Optional operation). | |
* | |
* @param key The key of the value to be deleted. | |
*/ | |
void remove(K key); | |
/** | |
* Returns the hash of the root node of the trie. | |
* | |
* @return The hash of the root node of the trie. | |
*/ | |
Bytes32 getRootHash(); | |
/** | |
* Commits any pending changes to the underlying storage. | |
* | |
* @param nodeUpdater used to store the node values | |
*/ | |
void commit(NodeUpdater nodeUpdater); | |
/** | |
* Commits any pending changes to the underlying storage. | |
* | |
* @param nodeUpdater used to store the node values | |
* @param commitVisitor custom visitor for the commit | |
*/ | |
void commit(NodeUpdater nodeUpdater, CommitVisitor<V> commitVisitor); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment