latent review feedback from pr 4531 (#4589)

Signed-off-by: garyschulte <garyschulte@gmail.com>
pull/4595/head
garyschulte 2 years ago committed by GitHub
parent 76d6429cc0
commit 341799bf46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLDataFetchers.java
  2. 4
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/BlockAdapterBase.java
  3. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/LogAdapter.java
  4. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/PendingStateAdapter.java
  5. 6
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/TransactionAdapter.java
  6. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugAccountRange.java
  7. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugStorageRangeAt.java
  8. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProof.java
  9. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java
  10. 14
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueries.java
  11. 4
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetProofTest.java
  12. 4
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/AbstractTrieLogManager.java
  13. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/LayeredTrieLogManager.java
  14. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/SnapshotTrieLogManager.java
  15. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/TrieLogManager.java
  16. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/GoQuorumKeyValueStorageProvider.java
  17. 5
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/KeyValueStorageProvider.java
  18. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java
  19. 4
      ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/InMemoryKeyValueStorageProvider.java
  20. 2
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/BonsaiSnapshotWorldStateArchiveTest.java

@ -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

Loading…
Cancel
Save