mirror of https://github.com/hyperledger/besu
TrieLogFactory plugin support (#5440)
* TrieLogs in plugin data * adds dagger-wired plugincontext and TrieLogService * add getTrieLogByRange, TrieLogRangeTuple composition --------- Signed-off-by: garyschulte <garyschulte@gmail.com>pull/5465/head
parent
3b4f5e13d6
commit
c85841d308
@ -0,0 +1,55 @@ |
|||||||
|
/* |
||||||
|
* Copyright contributors to Hyperledger Besu |
||||||
|
* |
||||||
|
* 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.datatypes; |
||||||
|
|
||||||
|
import org.hyperledger.besu.ethereum.rlp.RLPOutput; |
||||||
|
|
||||||
|
/** The values of an account in the world state trie. */ |
||||||
|
public interface AccountValue { |
||||||
|
/** |
||||||
|
* The nonce of the account. |
||||||
|
* |
||||||
|
* @return the nonce of the account. |
||||||
|
*/ |
||||||
|
long getNonce(); |
||||||
|
|
||||||
|
/** |
||||||
|
* The available balance of that account. |
||||||
|
* |
||||||
|
* @return the balance, in Wei, of the account. |
||||||
|
*/ |
||||||
|
Wei getBalance(); |
||||||
|
|
||||||
|
/** |
||||||
|
* The hash of the root of the storage trie associated with this account. |
||||||
|
* |
||||||
|
* @return the hash of the root node of the storage trie. |
||||||
|
*/ |
||||||
|
Hash getStorageRoot(); |
||||||
|
|
||||||
|
/** |
||||||
|
* The hash of the EVM bytecode associated with this account. |
||||||
|
* |
||||||
|
* @return the hash of the account code (which may be {@link Hash#EMPTY}). |
||||||
|
*/ |
||||||
|
Hash getCodeHash(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Writes the account value to the provided {@link RLPOutput}. |
||||||
|
* |
||||||
|
* @param out the {@link RLPOutput} to write to. |
||||||
|
*/ |
||||||
|
void writeTo(final RLPOutput out); |
||||||
|
} |
@ -0,0 +1,111 @@ |
|||||||
|
/* |
||||||
|
* Copyright contributors to Hyperledger Besu |
||||||
|
* |
||||||
|
* 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.datatypes; |
||||||
|
|
||||||
|
import java.util.Objects; |
||||||
|
import java.util.Optional; |
||||||
|
|
||||||
|
import org.apache.tuweni.units.bigints.UInt256; |
||||||
|
import org.jetbrains.annotations.NotNull; |
||||||
|
|
||||||
|
/** |
||||||
|
* StorageSlotKey represents a key used for storage slots in Ethereum. It contains the hash of the |
||||||
|
* slot key and an optional representation of the key itself. |
||||||
|
* |
||||||
|
* <p>The class provides methods for accessing the hash and key, as well as methods for equality, |
||||||
|
* hashcode, and comparison. |
||||||
|
* |
||||||
|
* <p>StorageSlotKey is used to uniquely identify storage slots within the Ethereum state. |
||||||
|
*/ |
||||||
|
public class StorageSlotKey implements Comparable<StorageSlotKey> { |
||||||
|
|
||||||
|
private final Hash slotHash; |
||||||
|
private final Optional<UInt256> slotKey; |
||||||
|
|
||||||
|
/** |
||||||
|
* Creates a StorageSlotKey. |
||||||
|
* |
||||||
|
* @param slotHash Hashed storage slot key. |
||||||
|
* @param slotKey Optional UInt256 storage slot key. |
||||||
|
*/ |
||||||
|
public StorageSlotKey(final Hash slotHash, final Optional<UInt256> slotKey) { |
||||||
|
this.slotHash = slotHash; |
||||||
|
this.slotKey = slotKey; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Creates a StorageSlotKey, hashing the slotKey. |
||||||
|
* |
||||||
|
* @param slotKey the UInt256 storage slot key. |
||||||
|
*/ |
||||||
|
public StorageSlotKey(final UInt256 slotKey) { |
||||||
|
this(Hash.hash(slotKey), Optional.of(slotKey)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Gets the hash representation of the storage slot key. |
||||||
|
* |
||||||
|
* @return the hash of the storage slot key. |
||||||
|
*/ |
||||||
|
public Hash getSlotHash() { |
||||||
|
return slotHash; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Gets the optional UInt256 representation of the storage slot key. |
||||||
|
* |
||||||
|
* @return an Optional containing the UInt256 storage slot key if present, otherwise an empty |
||||||
|
* Optional. |
||||||
|
*/ |
||||||
|
public Optional<UInt256> getSlotKey() { |
||||||
|
return slotKey; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Indicates whether some other object is "equal to" this one. Two StorageSlotKey objects are |
||||||
|
* considered equal if their slot hash values are equal. |
||||||
|
* |
||||||
|
* @param o the reference object with which to compare. |
||||||
|
* @return true if this object is the same as the obj argument; false otherwise. |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public boolean equals(final Object o) { |
||||||
|
if (this == o) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
if (o == null || getClass() != o.getClass()) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
StorageSlotKey that = (StorageSlotKey) o; |
||||||
|
return Objects.equals(slotHash, that.slotHash); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int hashCode() { |
||||||
|
return Objects.hash(slotHash.hashCode()); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String toString() { |
||||||
|
return String.format( |
||||||
|
"StorageSlotKey{slotHash=%s, slotKey=%s}", |
||||||
|
slotHash, slotKey.map(UInt256::toString).orElse("null")); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int compareTo(@NotNull final StorageSlotKey other) { |
||||||
|
return this.slotHash.compareTo(other.slotHash); |
||||||
|
} |
||||||
|
} |
@ -1,62 +0,0 @@ |
|||||||
/* |
|
||||||
* 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.worldview; |
|
||||||
|
|
||||||
import org.hyperledger.besu.datatypes.Hash; |
|
||||||
|
|
||||||
import java.util.Objects; |
|
||||||
import java.util.Optional; |
|
||||||
|
|
||||||
import org.apache.tuweni.units.bigints.UInt256; |
|
||||||
import org.jetbrains.annotations.NotNull; |
|
||||||
|
|
||||||
public record StorageSlotKey(Hash slotHash, Optional<UInt256> slotKey) |
|
||||||
implements Comparable<org.hyperledger.besu.ethereum.bonsai.worldview.StorageSlotKey> { |
|
||||||
|
|
||||||
public StorageSlotKey(final UInt256 slotKey) { |
|
||||||
this(Hash.hash(slotKey), Optional.of(slotKey)); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public boolean equals(final Object o) { |
|
||||||
if (this == o) { |
|
||||||
return true; |
|
||||||
} |
|
||||||
if (o == null || getClass() != o.getClass()) { |
|
||||||
return false; |
|
||||||
} |
|
||||||
StorageSlotKey that = (StorageSlotKey) o; |
|
||||||
return Objects.equals(slotHash, that.slotHash); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public int hashCode() { |
|
||||||
return Objects.hash(slotHash.hashCode()); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public String toString() { |
|
||||||
return String.format( |
|
||||||
"StorageSlotKey{slotHash=%s, slotKey=%s}", |
|
||||||
slotHash, slotKey.map(UInt256::toString).orElse("null")); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public int compareTo( |
|
||||||
@NotNull final org.hyperledger.besu.ethereum.bonsai.worldview.StorageSlotKey other) { |
|
||||||
return this.slotHash.compareTo(other.slotHash); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,58 @@ |
|||||||
|
/* |
||||||
|
* 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.plugin.services; |
||||||
|
|
||||||
|
import org.hyperledger.besu.plugin.services.trielogs.TrieLogEvent; |
||||||
|
import org.hyperledger.besu.plugin.services.trielogs.TrieLogFactory; |
||||||
|
import org.hyperledger.besu.plugin.services.trielogs.TrieLogProvider; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* A service interface for registering observers for trie log events. |
||||||
|
* |
||||||
|
* <p>Implementations must be thread-safe. |
||||||
|
*/ |
||||||
|
public interface TrieLogService extends BesuService { |
||||||
|
|
||||||
|
/** |
||||||
|
* Provides list of observers to configure for trie log events. |
||||||
|
* |
||||||
|
* @return the list of observers to configure |
||||||
|
*/ |
||||||
|
List<TrieLogEvent.TrieLogObserver> getObservers(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Provide a TrieLogFactory implementation to use for serializing and deserializing TrieLogs. |
||||||
|
* |
||||||
|
* @return the TrieLogFactory implementation |
||||||
|
*/ |
||||||
|
TrieLogFactory getTrieLogFactory(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Configure a TrieLogProvider implementation to use for retrieving stored TrieLogs. |
||||||
|
* |
||||||
|
* @param provider the TrieLogProvider implementation |
||||||
|
*/ |
||||||
|
void configureTrieLogProvider(TrieLogProvider provider); |
||||||
|
|
||||||
|
/** |
||||||
|
* Retrieve the configured TrieLogProvider implementation. |
||||||
|
* |
||||||
|
* @return the TrieLogProvider implementation |
||||||
|
*/ |
||||||
|
TrieLogProvider getTrieLogProvider(); |
||||||
|
} |
@ -0,0 +1,176 @@ |
|||||||
|
/* |
||||||
|
* Copyright contributors to Hyperledger Besu |
||||||
|
* |
||||||
|
* 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.plugin.services.trielogs; |
||||||
|
|
||||||
|
import org.hyperledger.besu.datatypes.AccountValue; |
||||||
|
import org.hyperledger.besu.datatypes.Address; |
||||||
|
import org.hyperledger.besu.datatypes.Hash; |
||||||
|
import org.hyperledger.besu.datatypes.StorageSlotKey; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
import java.util.Objects; |
||||||
|
import java.util.Optional; |
||||||
|
|
||||||
|
import org.apache.tuweni.bytes.Bytes; |
||||||
|
import org.apache.tuweni.units.bigints.UInt256; |
||||||
|
|
||||||
|
/** |
||||||
|
* An interface for interacting with TrieLog objects, which represent changes to accounts, code, and |
||||||
|
* storage in a blockchain state trie. |
||||||
|
*/ |
||||||
|
public interface TrieLog { |
||||||
|
|
||||||
|
/** |
||||||
|
* Gets the block hash associated with this TrieLog. |
||||||
|
* |
||||||
|
* @return the block hash |
||||||
|
*/ |
||||||
|
Hash getBlockHash(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Gets the block number associated with this TrieLog, if available. |
||||||
|
* |
||||||
|
* @return an Optional containing the block number if available, otherwise an empty Optional |
||||||
|
*/ |
||||||
|
Optional<Long> getBlockNumber(); |
||||||
|
|
||||||
|
/** Freezes the TrieLog to prevent further modifications. */ |
||||||
|
void freeze(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Gets a map of addresses to their account value changes. |
||||||
|
* |
||||||
|
* @param <U> the type of LogTuple representing the account value changes |
||||||
|
* @return a map of addresses to their account value changes |
||||||
|
*/ |
||||||
|
<U extends LogTuple<AccountValue>> Map<Address, U> getAccountChanges(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Gets a map of addresses to their code changes. |
||||||
|
* |
||||||
|
* @param <U> the type of LogTuple representing the code changes |
||||||
|
* @return a map of addresses to their code changes |
||||||
|
*/ |
||||||
|
<U extends LogTuple<Bytes>> Map<Address, U> getCodeChanges(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Gets a map of addresses to their storage changes. |
||||||
|
* |
||||||
|
* @param <U> the type of LogTuple representing the storage changes |
||||||
|
* @return a map of addresses to their storage changes |
||||||
|
*/ |
||||||
|
<U extends LogTuple<UInt256>> Map<Address, Map<StorageSlotKey, U>> getStorageChanges(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Gets the storage changes for a specific address. |
||||||
|
* |
||||||
|
* @param address the address to get the storage changes for |
||||||
|
* @param <U> the type of LogTuple representing the storage changes |
||||||
|
* @return a map of storage slot keys to their changes |
||||||
|
*/ |
||||||
|
<U extends LogTuple<UInt256>> Map<StorageSlotKey, U> getStorageChanges(final Address address); |
||||||
|
|
||||||
|
/** |
||||||
|
* Gets the prior code for a specific address, if available. |
||||||
|
* |
||||||
|
* @param address the address to get the prior code for |
||||||
|
* @return an Optional containing the prior code if available, otherwise an empty Optional |
||||||
|
*/ |
||||||
|
Optional<Bytes> getPriorCode(final Address address); |
||||||
|
|
||||||
|
/** |
||||||
|
* Gets the code for a specific address, if available. |
||||||
|
* |
||||||
|
* @param address the address to get the code for |
||||||
|
* @return an Optional containing the code if available, otherwise an empty Optional |
||||||
|
*/ |
||||||
|
Optional<Bytes> getCode(final Address address); |
||||||
|
|
||||||
|
/** |
||||||
|
* Gets the prior storage value for a specific address and storage slot key, if available. |
||||||
|
* |
||||||
|
* @param address the address to get the prior storage value for |
||||||
|
* @param storageSlotKey the storage slot key to get the prior storage value for |
||||||
|
* @return an Optional containing the prior storage value if available, otherwise an empty |
||||||
|
* Optional |
||||||
|
*/ |
||||||
|
Optional<UInt256> getPriorStorageByStorageSlotKey( |
||||||
|
final Address address, final StorageSlotKey storageSlotKey); |
||||||
|
|
||||||
|
/** |
||||||
|
* Gets the storage value for a specific address and storage slot key, if available. |
||||||
|
* |
||||||
|
* @param address the address to get the storage value for |
||||||
|
* @param storageSlotKey the storage slot key to get the storage value for |
||||||
|
* @return an Optional containing the storage value if available, otherwise an empty Optional |
||||||
|
*/ |
||||||
|
Optional<UInt256> getStorageByStorageSlotKey( |
||||||
|
final Address address, final StorageSlotKey storageSlotKey); |
||||||
|
|
||||||
|
/** |
||||||
|
* Gets the prior account value for a specific address, if available. |
||||||
|
* |
||||||
|
* @param address the address to get the prior account value for |
||||||
|
* @return an Optional containing the prior account value if available, otherwise an empty |
||||||
|
* Optional |
||||||
|
*/ |
||||||
|
Optional<? extends AccountValue> getPriorAccount(final Address address); |
||||||
|
/** |
||||||
|
* Gets the account value for a specific address, if available. |
||||||
|
* |
||||||
|
* @param address the address to get the account value for |
||||||
|
* @return an Optional containing the account value if available, otherwise an empty Optional |
||||||
|
*/ |
||||||
|
Optional<? extends AccountValue> getAccount(final Address address); |
||||||
|
|
||||||
|
/** |
||||||
|
* An interface representing a tuple of prior and updated values for a specific type T in a log. |
||||||
|
* The interface also provides methods to check if the values are unchanged or cleared. |
||||||
|
* |
||||||
|
* @param <T> the type of values stored in the log tuple |
||||||
|
*/ |
||||||
|
public interface LogTuple<T> { |
||||||
|
|
||||||
|
/** |
||||||
|
* Gets the prior value of the tuple. |
||||||
|
* |
||||||
|
* @return the prior value of type T |
||||||
|
*/ |
||||||
|
T getPrior(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Gets the updated value of the tuple. |
||||||
|
* |
||||||
|
* @return the updated value of type T |
||||||
|
*/ |
||||||
|
T getUpdated(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Checks if the prior and updated values are equal. |
||||||
|
* |
||||||
|
* @return true if the prior and updated values are equal, false otherwise |
||||||
|
*/ |
||||||
|
default boolean isUnchanged() { |
||||||
|
return Objects.equals(getUpdated(), getPrior()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Checks if the updated value represents a cleared state. |
||||||
|
* |
||||||
|
* @return true if the updated value is cleared, false otherwise |
||||||
|
*/ |
||||||
|
boolean isCleared(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,50 @@ |
|||||||
|
/* |
||||||
|
* Copyright contributors to Hyperledger Besu |
||||||
|
* |
||||||
|
* 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.plugin.services.trielogs; |
||||||
|
|
||||||
|
import org.hyperledger.besu.datatypes.AccountValue; |
||||||
|
import org.hyperledger.besu.datatypes.Address; |
||||||
|
import org.hyperledger.besu.datatypes.StorageSlotKey; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
import org.apache.tuweni.bytes.Bytes; |
||||||
|
import org.apache.tuweni.units.bigints.UInt256; |
||||||
|
|
||||||
|
/** Accumulator interface tor provding trie updates for creating TrieLogs. */ |
||||||
|
public interface TrieLogAccumulator { |
||||||
|
|
||||||
|
/** |
||||||
|
* Returns the state trie accounts which have been updated. |
||||||
|
* |
||||||
|
* @return the accounts to update |
||||||
|
*/ |
||||||
|
Map<Address, ? extends TrieLog.LogTuple<? extends AccountValue>> getAccountsToUpdate(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Returns code which has been updated. |
||||||
|
* |
||||||
|
* @return the code to update |
||||||
|
*/ |
||||||
|
Map<Address, ? extends TrieLog.LogTuple<Bytes>> getCodeToUpdate(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Returns storage which has been updated. |
||||||
|
* |
||||||
|
* @return the storage to update |
||||||
|
*/ |
||||||
|
Map<Address, ? extends Map<StorageSlotKey, ? extends TrieLog.LogTuple<UInt256>>> |
||||||
|
getStorageToUpdate(); |
||||||
|
} |
@ -0,0 +1,49 @@ |
|||||||
|
/* |
||||||
|
* Copyright contributors to Hyperledger Besu |
||||||
|
* |
||||||
|
* 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.plugin.services.trielogs; |
||||||
|
|
||||||
|
/** A TrieLog event. */ |
||||||
|
public interface TrieLogEvent { |
||||||
|
/** The type of the event. */ |
||||||
|
enum Type { |
||||||
|
/** TrieLog added event type */ |
||||||
|
ADDED |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* The type of the event. |
||||||
|
* |
||||||
|
* @return the type of the event |
||||||
|
*/ |
||||||
|
TrieLogEvent.Type getType(); |
||||||
|
|
||||||
|
/** |
||||||
|
* The TrieLog layer. |
||||||
|
* |
||||||
|
* @return the TrieLog layer |
||||||
|
*/ |
||||||
|
TrieLog layer(); |
||||||
|
|
||||||
|
/** Observer interface for TrieLog events. */ |
||||||
|
interface TrieLogObserver { |
||||||
|
|
||||||
|
/** |
||||||
|
* Called when a TrieLog is added. |
||||||
|
* |
||||||
|
* @param event the TrieLog event |
||||||
|
*/ |
||||||
|
void onTrieLogAdded(TrieLogEvent event); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,46 @@ |
|||||||
|
/* |
||||||
|
* Copyright contributors to Hyperledger Besu |
||||||
|
* |
||||||
|
* 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.plugin.services.trielogs; |
||||||
|
|
||||||
|
import org.hyperledger.besu.plugin.data.BlockHeader; |
||||||
|
|
||||||
|
/** Interface for serializing and deserializing {@link TrieLog} objects. */ |
||||||
|
public interface TrieLogFactory { |
||||||
|
|
||||||
|
/** |
||||||
|
* Creates a new TrieLog object. |
||||||
|
* |
||||||
|
* @param accumulator the accumulator |
||||||
|
* @param blockHeader the block header |
||||||
|
* @return a new TrieLog object |
||||||
|
*/ |
||||||
|
TrieLog create(TrieLogAccumulator accumulator, BlockHeader blockHeader); |
||||||
|
|
||||||
|
/** |
||||||
|
* Deserializes a TrieLog object. |
||||||
|
* |
||||||
|
* @param bytes the serialized TrieLog |
||||||
|
* @return the deserialized TrieLog |
||||||
|
*/ |
||||||
|
TrieLog deserialize(final byte[] bytes); |
||||||
|
|
||||||
|
/** |
||||||
|
* Serializes a TrieLog object. |
||||||
|
* |
||||||
|
* @param layer the TrieLog |
||||||
|
* @return the serialized TrieLog |
||||||
|
*/ |
||||||
|
byte[] serialize(final TrieLog layer); |
||||||
|
} |
@ -0,0 +1,61 @@ |
|||||||
|
/* |
||||||
|
* Copyright contributors to Hyperledger Besu |
||||||
|
* |
||||||
|
* 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.plugin.services.trielogs; |
||||||
|
|
||||||
|
import org.hyperledger.besu.datatypes.Hash; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.Optional; |
||||||
|
|
||||||
|
/** Trielog provider interface for a given block hash. */ |
||||||
|
public interface TrieLogProvider { |
||||||
|
/** |
||||||
|
* Returns the TrieLog layer for the given block hash. |
||||||
|
* |
||||||
|
* @param blockHash the block hash |
||||||
|
* @return the TrieLog layer for the given block hash |
||||||
|
* @param <T> the type of the TrieLog |
||||||
|
*/ |
||||||
|
<T extends TrieLog.LogTuple<?>> Optional<TrieLog> getTrieLogLayer(final Hash blockHash); |
||||||
|
|
||||||
|
/** |
||||||
|
* Returns the TrieLog layer for the given block number. |
||||||
|
* |
||||||
|
* @param blockNumber the block hash |
||||||
|
* @return the TrieLog layer for the given block hash |
||||||
|
* @param <T> the type of the TrieLog |
||||||
|
*/ |
||||||
|
<T extends TrieLog.LogTuple<?>> Optional<TrieLog> getTrieLogLayer(final long blockNumber); |
||||||
|
|
||||||
|
/** |
||||||
|
* Returns the TrieLog layers for the given block number range. |
||||||
|
* |
||||||
|
* @param fromBlockNumber the from block number |
||||||
|
* @param toBlockNumber the to block number |
||||||
|
* @return the TrieLog layers for the given block number range |
||||||
|
* @param <T> the type of the TrieLog |
||||||
|
*/ |
||||||
|
<T extends TrieLog.LogTuple<?>> List<TrieLogRangeTuple> getTrieLogsByRange( |
||||||
|
long fromBlockNumber, long toBlockNumber); |
||||||
|
|
||||||
|
/** |
||||||
|
* Block and TrieLog layer composition, used for returning a range of TrieLog layers. |
||||||
|
* |
||||||
|
* @param blockHash the block hash |
||||||
|
* @param blockNumber the block number |
||||||
|
* @param trieLog the associated TrieLog layer |
||||||
|
*/ |
||||||
|
record TrieLogRangeTuple(Hash blockHash, long blockNumber, TrieLog trieLog) {} |
||||||
|
} |
Loading…
Reference in new issue