Skip to content

Commit

Permalink
Use different transaction simulators for different behavior of rpc ga…
Browse files Browse the repository at this point in the history
…s cap

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
  • Loading branch information
fab-10 committed Sep 30, 2024
1 parent 513ce1f commit d00c324
Show file tree
Hide file tree
Showing 14 changed files with 218 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.hyperledger.besu.tests.acceptance.dsl.node;

import static org.hyperledger.besu.controller.BesuController.DATABASE_PATH;
import static org.hyperledger.besu.ethereum.transaction.TransactionSimulator.RpcGasCapMode.BOUNDED;

import org.hyperledger.besu.Runner;
import org.hyperledger.besu.RunnerBuilder;
Expand Down Expand Up @@ -377,8 +378,9 @@ TransactionSimulator provideTransactionSimulator(
final WorldStateArchive worldStateArchive,
final ProtocolSchedule protocolSchedule,
final ApiConfiguration apiConfiguration) {
return new TransactionSimulator(
blockchain, worldStateArchive, protocolSchedule, apiConfiguration.getGasCap());
return new TransactionSimulator.Builder(blockchain, worldStateArchive, protocolSchedule)
.rpcGasCap(apiConfiguration.getGasCap(), BOUNDED)
.build();
}

@Provides
Expand Down
10 changes: 5 additions & 5 deletions besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static java.util.function.Predicate.not;
import static org.hyperledger.besu.controller.BesuController.CACHE_PATH;
import static org.hyperledger.besu.ethereum.core.PrivacyParameters.FLEXIBLE_PRIVACY;
import static org.hyperledger.besu.ethereum.transaction.TransactionSimulator.RpcGasCapMode.BOUNDED;

import org.hyperledger.besu.cli.config.EthNetworkConfig;
import org.hyperledger.besu.cli.config.NetworkName;
Expand Down Expand Up @@ -699,11 +700,10 @@ public Runner build() {
final Synchronizer synchronizer = besuController.getSynchronizer();

final TransactionSimulator transactionSimulator =
new TransactionSimulator(
context.getBlockchain(),
context.getWorldStateArchive(),
protocolSchedule,
apiConfiguration.getGasCap());
new TransactionSimulator.Builder(
context.getBlockchain(), context.getWorldStateArchive(), protocolSchedule)
.rpcGasCap(apiConfiguration.getGasCap(), BOUNDED)
.build();

final Bytes localNodeId = nodeKey.getPublicKey().getEncodedBytes();
final Optional<NodePermissioningController> nodePermissioningController =
Expand Down
12 changes: 7 additions & 5 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.hyperledger.besu.controller.BesuController.DATABASE_PATH;
import static org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration.DEFAULT_ENGINE_JSON_RPC_PORT;
import static org.hyperledger.besu.ethereum.api.jsonrpc.authentication.EngineAuthService.EPHEMERAL_JWT_FILE;
import static org.hyperledger.besu.ethereum.transaction.TransactionSimulator.RpcGasCapMode.BOUNDED;
import static org.hyperledger.besu.nat.kubernetes.KubernetesNatManager.DEFAULT_BESU_SERVICE_NAME_FILTER;

import org.hyperledger.besu.BesuInfo;
Expand Down Expand Up @@ -1434,11 +1435,12 @@ private void startPlugins(final Runner runner) {
besuController.getProtocolContext(), besuController.getProtocolSchedule());
transactionSimulationServiceImpl.init(
besuController.getProtocolContext().getBlockchain(),
new TransactionSimulator(
besuController.getProtocolContext().getBlockchain(),
besuController.getProtocolContext().getWorldStateArchive(),
besuController.getProtocolSchedule(),
apiConfiguration.getGasCap()));
new TransactionSimulator.Builder(
besuController.getProtocolContext().getBlockchain(),
besuController.getProtocolContext().getWorldStateArchive(),
besuController.getProtocolSchedule())
.rpcGasCap(apiConfiguration.getGasCap(), BOUNDED)
.build());
rpcEndpointServiceImpl.init(runner.getInProcessRpcMethods());

besuPluginContext.addService(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ protected BftContext createConsensusContext(
blockchain, epochManager, bftBlockInterface().get(), validatorOverrides);

final TransactionSimulator transactionSimulator =
new TransactionSimulator(blockchain, worldStateArchive, protocolSchedule, 0L);
new TransactionSimulator.Builder(blockchain, worldStateArchive, protocolSchedule).build();
transactionValidatorProvider =
new TransactionValidatorProvider(
blockchain, new ValidatorContractController(transactionSimulator), qbftForksSchedule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ private static ControllerAndState createControllerAndFinalState(

final BftValidatorOverrides validatorOverrides = convertBftForks(qbftForks);
final TransactionSimulator transactionSimulator =
new TransactionSimulator(blockChain, worldStateArchive, protocolSchedule, 0L);
new TransactionSimulator.Builder(blockChain, worldStateArchive, protocolSchedule).build();

final BlockValidatorProvider blockValidatorProvider =
BlockValidatorProvider.forkingValidatorProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
package org.hyperledger.besu.ethereum.api.graphql.internal.pojoadapter;

import static org.hyperledger.besu.ethereum.transaction.TransactionSimulator.RpcGasCapMode.BOUNDED;

import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.BlobGas;
import org.hyperledger.besu.datatypes.Hash;
Expand Down Expand Up @@ -334,8 +336,10 @@ private Optional<CallResult> executeCall(final DataFetchingEnvironment environme
final long bn = header.getNumber();
final long gasCap = environment.getGraphQlContext().get(GraphQLContextType.GAS_CAP);
final TransactionSimulator transactionSimulator =
new TransactionSimulator(
query.getBlockchain(), query.getWorldStateArchive(), protocolSchedule, gasCap);
new TransactionSimulator.Builder(
query.getBlockchain(), query.getWorldStateArchive(), protocolSchedule)
.rpcGasCap(gasCap, BOUNDED)
.build();

long gasParam = -1;
Wei gasPriceParam = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
package org.hyperledger.besu.ethereum.api.graphql.internal.pojoadapter;

import static org.hyperledger.besu.ethereum.transaction.TransactionSimulator.RpcGasCapMode.BOUNDED;

import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.api.graphql.GraphQLContextType;
Expand Down Expand Up @@ -147,9 +149,10 @@ public Optional<CallResult> getCall(final DataFetchingEnvironment environment) {
environment.getGraphQlContext().get(GraphQLContextType.PROTOCOL_SCHEDULE);
final long gasCap = environment.getGraphQlContext().get(GraphQLContextType.GAS_CAP);
final TransactionSimulator transactionSimulator =
new TransactionSimulator(
query.getBlockchain(), query.getWorldStateArchive(), protocolSchedule, gasCap);

new TransactionSimulator.Builder(
query.getBlockchain(), query.getWorldStateArchive(), protocolSchedule)
.rpcGasCap(gasCap, BOUNDED)
.build();
long gasParam = -1;
Wei gasPriceParam = null;
Wei valueParam = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.methods;

import static org.hyperledger.besu.ethereum.transaction.TransactionSimulator.RpcGasCapMode.BOUNDED;

import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.ApiConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis;
Expand Down Expand Up @@ -123,10 +125,11 @@ protected Map<String, JsonRpcMethod> create() {
new DebugTraceCall(
blockchainQueries,
protocolSchedule,
new TransactionSimulator(
blockchainQueries.getBlockchain(),
blockchainQueries.getWorldStateArchive(),
protocolSchedule,
apiConfiguration.getGasCap())));
new TransactionSimulator.Builder(
blockchainQueries.getBlockchain(),
blockchainQueries.getWorldStateArchive(),
protocolSchedule)
.rpcGasCap(apiConfiguration.getGasCap(), BOUNDED)
.build()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.methods;

import static org.hyperledger.besu.ethereum.transaction.TransactionSimulator.RpcGasCapMode.BOUNDED;
import static org.hyperledger.besu.ethereum.transaction.TransactionSimulator.RpcGasCapMode.UNBOUNDED;

import org.hyperledger.besu.ethereum.api.ApiConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager;
Expand Down Expand Up @@ -127,11 +130,12 @@ protected Map<String, JsonRpcMethod> create() {
new EthGetBlockTransactionCountByHash(blockchainQueries),
new EthCall(
blockchainQueries,
new TransactionSimulator(
blockchainQueries.getBlockchain(),
blockchainQueries.getWorldStateArchive(),
protocolSchedule,
apiConfiguration.getGasCap())),
new TransactionSimulator.Builder(
blockchainQueries.getBlockchain(),
blockchainQueries.getWorldStateArchive(),
protocolSchedule)
.rpcGasCap(apiConfiguration.getGasCap(), UNBOUNDED)
.build()),
new EthFeeHistory(
protocolSchedule,
blockchainQueries.getBlockchain(),
Expand Down Expand Up @@ -161,18 +165,20 @@ protected Map<String, JsonRpcMethod> create() {
new EthSendTransaction(),
new EthEstimateGas(
blockchainQueries,
new TransactionSimulator(
blockchainQueries.getBlockchain(),
blockchainQueries.getWorldStateArchive(),
protocolSchedule,
apiConfiguration.getGasCap())),
new TransactionSimulator.Builder(
blockchainQueries.getBlockchain(),
blockchainQueries.getWorldStateArchive(),
protocolSchedule)
.rpcGasCap(apiConfiguration.getGasCap(), BOUNDED)
.build()),
new EthCreateAccessList(
blockchainQueries,
new TransactionSimulator(
blockchainQueries.getBlockchain(),
blockchainQueries.getWorldStateArchive(),
protocolSchedule,
apiConfiguration.getGasCap())),
new TransactionSimulator.Builder(
blockchainQueries.getBlockchain(),
blockchainQueries.getWorldStateArchive(),
protocolSchedule)
.rpcGasCap(apiConfiguration.getGasCap(), BOUNDED)
.build()),
new EthMining(miningCoordinator),
new EthCoinbase(miningCoordinator),
new EthProtocolVersion(supportedCapabilities),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.methods;

import static org.hyperledger.besu.ethereum.transaction.TransactionSimulator.RpcGasCapMode.BOUNDED;

import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.ApiConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis;
Expand Down Expand Up @@ -76,26 +78,29 @@ protected Map<String, JsonRpcMethod> create() {
new TraceCall(
blockchainQueries,
protocolSchedule,
new TransactionSimulator(
blockchainQueries.getBlockchain(),
blockchainQueries.getWorldStateArchive(),
protocolSchedule,
apiConfiguration.getGasCap())),
new TransactionSimulator.Builder(
blockchainQueries.getBlockchain(),
blockchainQueries.getWorldStateArchive(),
protocolSchedule)
.rpcGasCap(apiConfiguration.getGasCap(), BOUNDED)
.build()),
new TraceCallMany(
blockchainQueries,
protocolSchedule,
new TransactionSimulator(
blockchainQueries.getBlockchain(),
blockchainQueries.getWorldStateArchive(),
protocolSchedule,
apiConfiguration.getGasCap())),
new TransactionSimulator.Builder(
blockchainQueries.getBlockchain(),
blockchainQueries.getWorldStateArchive(),
protocolSchedule)
.rpcGasCap(apiConfiguration.getGasCap(), BOUNDED)
.build()),
new TraceRawTransaction(
protocolSchedule,
blockchainQueries,
new TransactionSimulator(
blockchainQueries.getBlockchain(),
blockchainQueries.getWorldStateArchive(),
protocolSchedule,
apiConfiguration.getGasCap())));
new TransactionSimulator.Builder(
blockchainQueries.getBlockchain(),
blockchainQueries.getWorldStateArchive(),
protocolSchedule)
.rpcGasCap(apiConfiguration.getGasCap(), BOUNDED)
.build()));
}
}
Loading

0 comments on commit d00c324

Please sign in to comment.