mirror of
https://github.com/vacp2p/linea-besu.git
synced 2026-01-09 15:37:54 -05:00
latent review feedback from pr 4531 (#4589)
Signed-off-by: garyschulte <garyschulte@gmail.com>
This commit is contained in:
@@ -219,7 +219,7 @@ public class GraphQLDataFetchers {
|
||||
final Long bn = dataFetchingEnvironment.getArgument("blockNumber");
|
||||
if (bn != null) {
|
||||
return blockchainQuery
|
||||
.mapWorldState(
|
||||
.getAndMapWorldState(
|
||||
bn,
|
||||
ws -> {
|
||||
final Account account = ws.get(addr);
|
||||
@@ -241,7 +241,7 @@ public class GraphQLDataFetchers {
|
||||
} else {
|
||||
// return account on latest block
|
||||
final long latestBn = blockchainQuery.latestBlock().get().getHeader().getNumber();
|
||||
return blockchainQuery.mapWorldState(
|
||||
return blockchainQuery.getAndMapWorldState(
|
||||
latestBn,
|
||||
ws -> {
|
||||
final Account account = ws.get(addr);
|
||||
|
||||
@@ -96,7 +96,7 @@ public class BlockAdapterBase extends AdapterBase {
|
||||
}
|
||||
|
||||
return query
|
||||
.mapWorldState(blockNumber, ws -> ws.get(header.getCoinbase()))
|
||||
.getAndMapWorldState(blockNumber, ws -> ws.get(header.getCoinbase()))
|
||||
.map(account -> (AdapterBase) new AccountAdapter(account))
|
||||
.or(() -> Optional.of(new EmptyAccountAdapter(header.getCoinbase())));
|
||||
}
|
||||
@@ -146,7 +146,7 @@ public class BlockAdapterBase extends AdapterBase {
|
||||
|
||||
final BlockchainQueries query = getBlockchainQueries(environment);
|
||||
final long bn = header.getNumber();
|
||||
return query.mapWorldState(
|
||||
return query.getAndMapWorldState(
|
||||
bn,
|
||||
ws -> {
|
||||
final Address address = environment.getArgument("address");
|
||||
|
||||
@@ -63,7 +63,7 @@ public class LogAdapter extends AdapterBase {
|
||||
blockNumber = bn;
|
||||
}
|
||||
|
||||
return query.mapWorldState(
|
||||
return query.getAndMapWorldState(
|
||||
blockNumber, ws -> new AccountAdapter(ws.get(logWithMetadata.getLogger())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class PendingStateAdapter extends AdapterBase {
|
||||
final Long blockNumber = dataFetchingEnvironment.getArgument("blockNumber");
|
||||
final long latestBlockNumber = blockchainQuery.latestBlock().get().getHeader().getNumber();
|
||||
return blockchainQuery
|
||||
.mapWorldState(latestBlockNumber, ws -> ws.get(addr))
|
||||
.getAndMapWorldState(latestBlockNumber, ws -> ws.get(addr))
|
||||
.map(AccountAdapter::new);
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ public class TransactionAdapter extends AdapterBase {
|
||||
if (blockNumber == null) {
|
||||
blockNumber = transactionWithMetadata.getBlockNumber().orElseGet(query::headBlockNumber);
|
||||
}
|
||||
return query.mapWorldState(
|
||||
return query.getAndMapWorldState(
|
||||
blockNumber,
|
||||
mutableWorldState ->
|
||||
new AccountAdapter(
|
||||
@@ -96,7 +96,7 @@ public class TransactionAdapter extends AdapterBase {
|
||||
blockNumber = transactionWithMetadata.getBlockNumber().orElseGet(query::headBlockNumber);
|
||||
}
|
||||
|
||||
return query.mapWorldState(
|
||||
return query.getAndMapWorldState(
|
||||
blockNumber,
|
||||
ws ->
|
||||
transactionWithMetadata
|
||||
@@ -174,7 +174,7 @@ public class TransactionAdapter extends AdapterBase {
|
||||
return Optional.empty();
|
||||
}
|
||||
final long blockNumber = bn.orElseGet(txBlockNumber::get);
|
||||
return query.mapWorldState(blockNumber, ws -> new AccountAdapter(ws.get(addr.get())));
|
||||
return query.getAndMapWorldState(blockNumber, ws -> new AccountAdapter(ws.get(addr.get())));
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
|
||||
@@ -75,7 +75,7 @@ public class DebugAccountRange implements JsonRpcMethod {
|
||||
// TODO deal with mid-block locations
|
||||
return blockchainQueries
|
||||
.get()
|
||||
.mapWorldState(
|
||||
.getAndMapWorldState(
|
||||
blockHeaderOptional.get().getNumber(),
|
||||
state -> {
|
||||
final List<StreamableAccount> accounts =
|
||||
|
||||
@@ -104,7 +104,7 @@ public class DebugStorageRangeAt implements JsonRpcMethod {
|
||||
() ->
|
||||
blockchainQueries
|
||||
.get()
|
||||
.mapWorldState(
|
||||
.getAndMapWorldState(
|
||||
blockHeaderOptional.get().getNumber(),
|
||||
worldState ->
|
||||
extractStorageAt(
|
||||
|
||||
@@ -58,7 +58,7 @@ public class EthGetProof extends AbstractBlockParameterOrBlockHashMethod {
|
||||
final List<UInt256> storageKeys = getStorageKeys(requestContext);
|
||||
|
||||
return getBlockchainQueries()
|
||||
.mapWorldState(
|
||||
.getAndMapWorldState(
|
||||
blockHash,
|
||||
worldState -> {
|
||||
Optional<WorldStateProof> proofOptional =
|
||||
|
||||
@@ -111,7 +111,7 @@ public class TraceCallMany extends TraceCall implements JsonRpcMethod {
|
||||
final List<JsonNode> traceCallResults = new ArrayList<>();
|
||||
|
||||
return getBlockchainQueries()
|
||||
.mapWorldState(
|
||||
.getAndMapWorldState(
|
||||
blockHeader.getBlockHash(),
|
||||
ws -> {
|
||||
final WorldUpdater updater =
|
||||
|
||||
@@ -294,7 +294,7 @@ public class BlockchainQueries {
|
||||
* @return The number of transactions sent from the given address.
|
||||
*/
|
||||
public long getTransactionCount(final Address address, final Hash blockHash) {
|
||||
return mapWorldState(blockHash, worldState -> worldState.get(address))
|
||||
return getAndMapWorldState(blockHash, worldState -> worldState.get(address))
|
||||
.map(Account::getNonce)
|
||||
.orElse(0L);
|
||||
}
|
||||
@@ -834,14 +834,16 @@ public class BlockchainQueries {
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps an operation on MutableWorldState with try-with-resources the corresponding block hash
|
||||
* Wraps an operation on MutableWorldState with try-with-resources the corresponding block hash.
|
||||
* This method provides access to the worldstate via a mapper function in order to ensure all of
|
||||
* the uses of the MutableWorldState are subsequently closed, via the try-with-resources block.
|
||||
*
|
||||
* @param <U> return type of the operation on the MutableWorldState
|
||||
* @param blockHash the block hash
|
||||
* @param mapper Function which performs an operation on a MutableWorldState
|
||||
* @return the world state at the block number
|
||||
*/
|
||||
public <U> Optional<U> mapWorldState(
|
||||
public <U> Optional<U> getAndMapWorldState(
|
||||
final Hash blockHash, final Function<MutableWorldState, ? extends U> mapper) {
|
||||
return blockchain
|
||||
.getBlockHeader(blockHash)
|
||||
@@ -869,11 +871,11 @@ public class BlockchainQueries {
|
||||
* @param mapper Function which performs an operation on a MutableWorldState returning type U
|
||||
* @return the world state at the block number
|
||||
*/
|
||||
public <U> Optional<U> mapWorldState(
|
||||
public <U> Optional<U> getAndMapWorldState(
|
||||
final long blockNumber, final Function<MutableWorldState, ? extends U> mapper) {
|
||||
final Hash blockHash =
|
||||
getBlockHeaderByNumber(blockNumber).map(BlockHeader::getHash).orElse(Hash.EMPTY);
|
||||
return mapWorldState(blockHash, mapper);
|
||||
return getAndMapWorldState(blockHash, mapper);
|
||||
}
|
||||
|
||||
public Optional<Long> gasPrice() {
|
||||
@@ -938,7 +940,7 @@ public class BlockchainQueries {
|
||||
final Hash blockHash,
|
||||
final Function<Account, T> getter,
|
||||
final T noAccountValue) {
|
||||
return mapWorldState(
|
||||
return getAndMapWorldState(
|
||||
blockHash,
|
||||
worldState ->
|
||||
Optional.ofNullable(worldState.get(address)).map(getter).orElse(noAccountValue));
|
||||
|
||||
@@ -142,7 +142,7 @@ class EthGetProofTest {
|
||||
void errorWhenWorldStateUnavailable() {
|
||||
|
||||
when(blockchainQueries.headBlockNumber()).thenReturn(14L);
|
||||
when(blockchainQueries.mapWorldState(any(), any())).thenReturn(Optional.empty());
|
||||
when(blockchainQueries.getAndMapWorldState(any(), any())).thenReturn(Optional.empty());
|
||||
|
||||
final JsonRpcErrorResponse expectedResponse =
|
||||
new JsonRpcErrorResponse(null, JsonRpcError.WORLD_STATE_UNAVAILABLE);
|
||||
@@ -231,7 +231,7 @@ class EthGetProofTest {
|
||||
.<Function<MutableWorldState, ? extends JsonRpcResponse>>getArgument(1)
|
||||
.apply(mutableWorldState)))
|
||||
.when(blockchainQueries)
|
||||
.mapWorldState(any(), any());
|
||||
.getAndMapWorldState(any(), any());
|
||||
|
||||
return GetProofResult.buildGetProofResult(address, worldStateProof);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.hyperledger.besu.ethereum.bonsai;
|
||||
import static org.hyperledger.besu.util.Slf4jLambdaHelper.debugLambda;
|
||||
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.ethereum.bonsai.TrieLogManager.CachedLayer;
|
||||
import org.hyperledger.besu.ethereum.bonsai.TrieLogManager.CachedWorldState;
|
||||
import org.hyperledger.besu.ethereum.chain.Blockchain;
|
||||
import org.hyperledger.besu.ethereum.core.BlockHeader;
|
||||
import org.hyperledger.besu.ethereum.core.MutableWorldState;
|
||||
@@ -32,7 +32,7 @@ import org.apache.tuweni.bytes.Bytes32;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public abstract class AbstractTrieLogManager<T extends CachedLayer> implements TrieLogManager {
|
||||
public abstract class AbstractTrieLogManager<T extends CachedWorldState> implements TrieLogManager {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AbstractTrieLogManager.class);
|
||||
public static final long RETAINED_LAYERS = 512; // at least 256 + typical rollbacks
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ public class LayeredTrieLogManager
|
||||
});
|
||||
}
|
||||
|
||||
public static class LayeredWorldStateCache implements CachedLayer {
|
||||
public static class LayeredWorldStateCache implements CachedWorldState {
|
||||
|
||||
final BonsaiLayeredWorldState layeredWorldState;
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ public class SnapshotTrieLogManager
|
||||
// no-op. Snapshots are independent and do not need to update 'next' worldstates
|
||||
}
|
||||
|
||||
public static class CachedSnapshotWorldState implements CachedLayer {
|
||||
public static class CachedSnapshotWorldState implements CachedWorldState {
|
||||
|
||||
final BonsaiSnapshotWorldState snapshot;
|
||||
final TrieLogLayer trieLog;
|
||||
|
||||
@@ -43,7 +43,7 @@ public interface TrieLogManager {
|
||||
|
||||
Optional<TrieLogLayer> getTrieLogLayer(final Hash blockHash);
|
||||
|
||||
interface CachedLayer {
|
||||
interface CachedWorldState {
|
||||
long getHeight();
|
||||
|
||||
TrieLogLayer getTrieLog();
|
||||
|
||||
@@ -41,7 +41,7 @@ public class GoQuorumKeyValueStorageProvider extends KeyValueStorageProvider {
|
||||
worldStatePreimageStorage,
|
||||
privateWorldStatePreimageStorage,
|
||||
segmentIsolationSupported,
|
||||
false);
|
||||
SNAPSHOT_ISOLATION_UNSUPPORTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -35,6 +35,9 @@ import java.util.function.Function;
|
||||
|
||||
public class KeyValueStorageProvider implements StorageProvider {
|
||||
|
||||
public static final boolean SEGMENT_ISOLATION_SUPPORTED = true;
|
||||
public static final boolean SNAPSHOT_ISOLATION_UNSUPPORTED = false;
|
||||
|
||||
protected final Function<SegmentIdentifier, KeyValueStorage> storageCreator;
|
||||
private final KeyValueStorage worldStatePreimageStorage;
|
||||
private final KeyValueStorage privateWorldStatePreimageStorage;
|
||||
@@ -50,7 +53,7 @@ public class KeyValueStorageProvider implements StorageProvider {
|
||||
this.worldStatePreimageStorage = worldStatePreimageStorage;
|
||||
this.privateWorldStatePreimageStorage = null;
|
||||
this.isWorldStateIterable = segmentIsolationSupported;
|
||||
this.isWorldStateSnappable = false;
|
||||
this.isWorldStateSnappable = SNAPSHOT_ISOLATION_UNSUPPORTED;
|
||||
}
|
||||
|
||||
public KeyValueStorageProvider(
|
||||
|
||||
@@ -168,7 +168,7 @@ public class TransactionSimulator {
|
||||
.orElseThrow(
|
||||
() ->
|
||||
new IllegalArgumentException(
|
||||
"Public world state not available for block " + header.getNumber()));
|
||||
"Public world state not available for block " + header.toLogString()));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
||||
@@ -38,8 +38,8 @@ public class InMemoryKeyValueStorageProvider extends KeyValueStorageProvider {
|
||||
segmentIdentifier -> new InMemoryKeyValueStorage(),
|
||||
new InMemoryKeyValueStorage(),
|
||||
new InMemoryKeyValueStorage(),
|
||||
true,
|
||||
false);
|
||||
SEGMENT_ISOLATION_SUPPORTED,
|
||||
SNAPSHOT_ISOLATION_UNSUPPORTED);
|
||||
}
|
||||
|
||||
public static MutableBlockchain createInMemoryBlockchain(final Block genesisBlock) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright ConsenSys AG.
|
||||
* 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
|
||||
|
||||
Reference in New Issue
Block a user