Skip to content

Commit

Permalink
Refactor: Move rpcGasCap and rpcMaxLogsRange to apiConfiguration (hyp…
Browse files Browse the repository at this point in the history
…erledger#6195)

Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
  • Loading branch information
Gabriel-Trintinalia authored Nov 22, 2023
1 parent 6dea9a0 commit 31a57e0
Show file tree
Hide file tree
Showing 38 changed files with 139 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.hyperledger.besu.crypto.KeyPair;
import org.hyperledger.besu.crypto.KeyPairUtil;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.ethereum.api.ApiConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.ipc.JsonRpcIpcConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration;
Expand Down Expand Up @@ -107,6 +108,7 @@ public class BesuNode implements NodeConfiguration, RunnableNode, AutoCloseable
private final JsonRpcIpcConfiguration jsonRpcIpcConfiguration;
private final MetricsConfiguration metricsConfiguration;
private Optional<PermissioningConfiguration> permissioningConfiguration;
private final ApiConfiguration apiConfiguration;
private final GenesisConfigurationProvider genesisConfigProvider;
private final boolean devMode;
private final NetworkName network;
Expand Down Expand Up @@ -139,6 +141,7 @@ public BesuNode(
final JsonRpcIpcConfiguration jsonRpcIpcConfiguration,
final MetricsConfiguration metricsConfiguration,
final Optional<PermissioningConfiguration> permissioningConfiguration,
final ApiConfiguration apiConfiguration,
final Optional<String> keyfilePath,
final boolean devMode,
final NetworkName network,
Expand Down Expand Up @@ -187,6 +190,7 @@ public BesuNode(
this.jsonRpcIpcConfiguration = jsonRpcIpcConfiguration;
this.metricsConfiguration = metricsConfiguration;
this.permissioningConfiguration = permissioningConfiguration;
this.apiConfiguration = apiConfiguration;
this.genesisConfigProvider = genesisConfigProvider;
this.devMode = devMode;
this.network = network;
Expand Down Expand Up @@ -806,4 +810,8 @@ public void setExitCode(final int exitValue) {
public Map<String, String> getEnvironment() {
return environment;
}

public ApiConfiguration getApiConfiguration() {
return apiConfiguration;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ public void startNode(final BesuNode node) {

final RunnerBuilder runnerBuilder = new RunnerBuilder();
runnerBuilder.permissioningConfiguration(node.getPermissioningConfiguration());
runnerBuilder.apiConfiguration(node.getApiConfiguration());

runnerBuilder
.vertx(Vertx.vertx())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import org.hyperledger.besu.cli.config.NetworkName;
import org.hyperledger.besu.crypto.KeyPair;
import org.hyperledger.besu.ethereum.api.ApiConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.ipc.JsonRpcIpcConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration;
Expand Down Expand Up @@ -44,6 +45,7 @@ public class BesuNodeConfiguration {
private final JsonRpcIpcConfiguration jsonRpcIpcConfiguration;
private final MetricsConfiguration metricsConfiguration;
private final Optional<PermissioningConfiguration> permissioningConfiguration;
private final ApiConfiguration apiConfiguration;
private final Optional<String> keyFilePath;
private final boolean devMode;
private final GenesisConfigurationProvider genesisConfigProvider;
Expand Down Expand Up @@ -78,6 +80,7 @@ public class BesuNodeConfiguration {
final JsonRpcIpcConfiguration jsonRpcIpcConfiguration,
final MetricsConfiguration metricsConfiguration,
final Optional<PermissioningConfiguration> permissioningConfiguration,
final ApiConfiguration apiConfiguration,
final Optional<String> keyFilePath,
final boolean devMode,
final NetworkName network,
Expand Down Expand Up @@ -109,6 +112,7 @@ public class BesuNodeConfiguration {
this.jsonRpcIpcConfiguration = jsonRpcIpcConfiguration;
this.metricsConfiguration = metricsConfiguration;
this.permissioningConfiguration = permissioningConfiguration;
this.apiConfiguration = apiConfiguration;
this.keyFilePath = keyFilePath;
this.dataPath = dataPath;
this.devMode = devMode;
Expand Down Expand Up @@ -167,6 +171,10 @@ public Optional<PermissioningConfiguration> getPermissioningConfiguration() {
return permissioningConfiguration;
}

public ApiConfiguration getApiConfiguration() {
return apiConfiguration;
}

public Optional<String> getKeyFilePath() {
return keyFilePath;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import org.hyperledger.besu.cli.config.NetworkName;
import org.hyperledger.besu.crypto.KeyPair;
import org.hyperledger.besu.ethereum.api.ApiConfiguration;
import org.hyperledger.besu.ethereum.api.ImmutableApiConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis;
import org.hyperledger.besu.ethereum.api.jsonrpc.authentication.JwtAlgorithm;
Expand Down Expand Up @@ -68,6 +70,7 @@ public class BesuNodeConfigurationBuilder {
private JsonRpcIpcConfiguration jsonRpcIpcConfiguration = new JsonRpcIpcConfiguration();
private MetricsConfiguration metricsConfiguration = MetricsConfiguration.builder().build();
private Optional<PermissioningConfiguration> permissioningConfiguration = Optional.empty();
private ApiConfiguration apiConfiguration = ImmutableApiConfiguration.builder().build();
private String keyFilePath = null;
private boolean devMode = true;
private GenesisConfigurationProvider genesisConfigProvider = ignore -> Optional.empty();
Expand Down Expand Up @@ -490,6 +493,11 @@ public BesuNodeConfigurationBuilder environment(final Map<String, String> enviro
return this;
}

public BesuNodeConfigurationBuilder apiConfiguration(final ApiConfiguration apiConfiguration) {
this.apiConfiguration = apiConfiguration;
return this;
}

public BesuNodeConfiguration build() {
return new BesuNodeConfiguration(
name,
Expand All @@ -501,6 +509,7 @@ public BesuNodeConfiguration build() {
jsonRpcIpcConfiguration,
metricsConfiguration,
permissioningConfiguration,
apiConfiguration,
Optional.ofNullable(keyFilePath),
devMode,
network,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public BesuNode create(final BesuNodeConfiguration config) throws IOException {
config.getJsonRpcIpcConfiguration(),
config.getMetricsConfiguration(),
config.getPermissioningConfiguration(),
config.getApiConfiguration(),
config.getKeyFilePath(),
config.isDevMode(),
config.getNetwork(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public PrivacyNode(
besuConfig.getJsonRpcIpcConfiguration(),
besuConfig.getMetricsConfiguration(),
besuConfig.getPermissioningConfiguration(),
besuConfig.getApiConfiguration(),
besuConfig.getKeyFilePath(),
besuConfig.isDevMode(),
besuConfig.getNetwork(),
Expand Down
35 changes: 7 additions & 28 deletions besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,6 @@ public class RunnerBuilder {
private RpcEndpointServiceImpl rpcEndpointServiceImpl;
private JsonRpcIpcConfiguration jsonRpcIpcConfiguration;
private boolean legacyForkIdEnabled;
private Optional<Long> rpcMaxLogsRange;
private Optional<Long> rpcGasCap;
private Optional<EnodeDnsConfiguration> enodeDnsConfiguration;

/**
Expand Down Expand Up @@ -576,27 +574,6 @@ public RunnerBuilder jsonRpcIpcConfiguration(
return this;
}

/**
* Add Rpc max logs range.
*
* @param rpcMaxLogsRange the rpc max logs range
* @return the runner builder
*/
public RunnerBuilder rpcMaxLogsRange(final Long rpcMaxLogsRange) {
this.rpcMaxLogsRange = rpcMaxLogsRange > 0 ? Optional.of(rpcMaxLogsRange) : Optional.empty();
return this;
}
/**
* Add Rpc gasLimit cap .
*
* @param rpcGasCap the rpc gas limit cap for transaction simulation methods
* @return the runner builder
*/
public RunnerBuilder rpcGasCap(final Long rpcGasCap) {
this.rpcGasCap = rpcGasCap > 0 ? Optional.of(rpcGasCap) : Optional.empty();
return this;
}

/**
* Add enode DNS configuration
*
Expand Down Expand Up @@ -672,7 +649,10 @@ public Runner build() {

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

final Bytes localNodeId = nodeKey.getPublicKey().getEncodedBytes();
final Optional<NodePermissioningController> nodePermissioningController =
Expand Down Expand Up @@ -921,7 +901,7 @@ public Runner build() {
graphQlContextMap.putIfAbsent(GraphQLContextType.SYNCHRONIZER, synchronizer);
graphQlContextMap.putIfAbsent(
GraphQLContextType.CHAIN_ID, protocolSchedule.getChainId().map(UInt256::valueOf));
graphQlContextMap.putIfAbsent(GraphQLContextType.GAS_CAP, rpcGasCap);
graphQlContextMap.putIfAbsent(GraphQLContextType.GAS_CAP, apiConfiguration.getGasCap());
final GraphQL graphQL;
try {
graphQL = GraphQLProvider.buildGraphQL(fetchers);
Expand Down Expand Up @@ -1251,9 +1231,8 @@ private Map<String, JsonRpcMethod> jsonRpcMethods(
dataDir,
besuController.getProtocolManager().ethContext().getEthPeers(),
consensusEngineServer,
rpcMaxLogsRange,
enodeDnsConfiguration,
rpcGasCap);
apiConfiguration,
enodeDnsConfiguration);
methods.putAll(besuController.getAdditionalJsonRpcMethods(jsonRpcApis));

final var pluginMethods =
Expand Down
4 changes: 2 additions & 2 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2491,6 +2491,8 @@ private ApiConfiguration apiConfiguration() {
.gasPriceMinSupplier(
getMiningParameters().getMinTransactionGasPrice().getAsBigInteger()::longValueExact)
.gasPriceMax(apiGasPriceMax)
.maxLogsRange(rpcMaxLogsRange)
.gasCap(rpcGasCap)
.build();
}

Expand Down Expand Up @@ -2953,8 +2955,6 @@ private Runner synchronize(
.ethstatsOptions(ethstatsOptions)
.storageProvider(keyValueStorageProvider(keyValueStorageName))
.rpcEndpointService(rpcEndpointServiceImpl)
.rpcMaxLogsRange(rpcMaxLogsRange)
.rpcGasCap(rpcGasCap)
.enodeDnsConfiguration(getEnodeDnsConfiguration())
.build();

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

final TransactionSimulator transactionSimulator =
new TransactionSimulator(blockchain, worldStateArchive, protocolSchedule, Optional.empty());
new TransactionSimulator(blockchain, worldStateArchive, protocolSchedule, 0L);
transactionValidatorProvider =
new TransactionValidatorProvider(
blockchain, new ValidatorContractController(transactionSimulator), qbftForksSchedule);
Expand Down
13 changes: 7 additions & 6 deletions besu/src/test/java/org/hyperledger/besu/RunnerBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.hyperledger.besu.cryptoservices.NodeKey;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.ImmutableApiConfiguration;
import org.hyperledger.besu.ethereum.api.graphql.GraphQLConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.ipc.JsonRpcIpcConfiguration;
Expand Down Expand Up @@ -167,7 +168,7 @@ public void enodeUrlShouldHaveAdvertisedHostWhenDiscoveryDisabled() {
.dataDir(dataDir.getRoot())
.storageProvider(mock(KeyValueStorageProvider.class, RETURNS_DEEP_STUBS))
.rpcEndpointService(new RpcEndpointServiceImpl())
.rpcGasCap(50_000_000L)
.apiConfiguration(ImmutableApiConfiguration.builder().build())
.build();
runner.startEthereumMainLoop();

Expand Down Expand Up @@ -212,7 +213,7 @@ public void movingAcrossProtocolSpecsUpdatesNodeRecord() {
.dataDir(dataDir.getRoot())
.storageProvider(storageProvider)
.rpcEndpointService(new RpcEndpointServiceImpl())
.rpcGasCap(50_000_000L)
.apiConfiguration(ImmutableApiConfiguration.builder().build())
.build();
runner.startEthereumMainLoop();

Expand Down Expand Up @@ -272,7 +273,7 @@ public void whenEngineApiAddedListensOnDefaultPort() {
.storageProvider(mock(KeyValueStorageProvider.class, RETURNS_DEEP_STUBS))
.rpcEndpointService(new RpcEndpointServiceImpl())
.besuPluginContext(mock(BesuPluginContextImpl.class))
.rpcGasCap(50_000_000L)
.apiConfiguration(ImmutableApiConfiguration.builder().build())
.build();

assertThat(runner.getJsonRpcPort()).isPresent();
Expand Down Expand Up @@ -315,7 +316,7 @@ public void whenEngineApiAddedWebSocketReadyOnSamePort() {
.storageProvider(mock(KeyValueStorageProvider.class, RETURNS_DEEP_STUBS))
.rpcEndpointService(new RpcEndpointServiceImpl())
.besuPluginContext(mock(BesuPluginContextImpl.class))
.rpcGasCap(50_000_000L)
.apiConfiguration(ImmutableApiConfiguration.builder().build())
.build();

assertThat(runner.getEngineJsonRpcPort()).isPresent();
Expand Down Expand Up @@ -357,7 +358,7 @@ public void whenEngineApiAddedEthSubscribeAvailable() {
.storageProvider(mock(KeyValueStorageProvider.class, RETURNS_DEEP_STUBS))
.rpcEndpointService(new RpcEndpointServiceImpl())
.besuPluginContext(mock(BesuPluginContextImpl.class))
.rpcGasCap(50_000_000L)
.apiConfiguration(ImmutableApiConfiguration.builder().build())
.build();

assertThat(runner.getEngineJsonRpcPort()).isPresent();
Expand Down Expand Up @@ -401,7 +402,7 @@ public void noEngineApiNoServiceForMethods() {
.rpcEndpointService(new RpcEndpointServiceImpl())
.besuPluginContext(mock(BesuPluginContextImpl.class))
.networkingConfiguration(NetworkingConfiguration.create())
.rpcGasCap(50_000_000L)
.apiConfiguration(ImmutableApiConfiguration.builder().build())
.build();

assertThat(runner.getJsonRpcPort()).isPresent();
Expand Down
3 changes: 2 additions & 1 deletion besu/src/test/java/org/hyperledger/besu/RunnerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.hyperledger.besu.cryptoservices.NodeKeyUtils;
import org.hyperledger.besu.ethereum.GasLimitCalculator;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.ImmutableApiConfiguration;
import org.hyperledger.besu.ethereum.api.graphql.GraphQLConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.ipc.JsonRpcIpcConfiguration;
Expand Down Expand Up @@ -193,7 +194,7 @@ private void syncFromGenesis(final SyncMode mode, final GenesisConfigFile genesi
.staticNodes(emptySet())
.storageProvider(new InMemoryKeyValueStorageProvider())
.rpcEndpointService(new RpcEndpointServiceImpl())
.rpcGasCap(50_000_000L);
.apiConfiguration(ImmutableApiConfiguration.builder().build());

Runner runnerBehind = null;
final Runner runnerAhead =
Expand Down
18 changes: 13 additions & 5 deletions besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.GasLimitCalculator;
import org.hyperledger.besu.ethereum.api.ApiConfiguration;
import org.hyperledger.besu.ethereum.api.ImmutableApiConfiguration;
import org.hyperledger.besu.ethereum.api.graphql.GraphQLConfiguration;
import org.hyperledger.besu.ethereum.api.handlers.TimeoutOptions;
import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration;
Expand Down Expand Up @@ -149,6 +151,8 @@ public class BesuCommandTest extends CommandTestAbstract {
private static final GraphQLConfiguration DEFAULT_GRAPH_QL_CONFIGURATION;
private static final WebSocketConfiguration DEFAULT_WEB_SOCKET_CONFIGURATION;
private static final MetricsConfiguration DEFAULT_METRICS_CONFIGURATION;
private static final ApiConfiguration DEFAULT_API_CONFIGURATION;

private static final int GENESIS_CONFIG_TEST_CHAINID = 3141592;
private static final JsonObject GENESIS_VALID_JSON =
(new JsonObject())
Expand Down Expand Up @@ -191,6 +195,7 @@ public class BesuCommandTest extends CommandTestAbstract {
DEFAULT_GRAPH_QL_CONFIGURATION = GraphQLConfiguration.createDefault();
DEFAULT_WEB_SOCKET_CONFIGURATION = WebSocketConfiguration.createDefault();
DEFAULT_METRICS_CONFIGURATION = MetricsConfiguration.builder().build();
DEFAULT_API_CONFIGURATION = ImmutableApiConfiguration.builder().build();
}

@Before
Expand Down Expand Up @@ -258,7 +263,7 @@ public void callingBesuCommandWithoutOptionsMustSyncWithDefaultValues() {
verify(mockRunnerBuilder).metricsConfiguration(eq(DEFAULT_METRICS_CONFIGURATION));
verify(mockRunnerBuilder).ethNetworkConfig(ethNetworkArg.capture());
verify(mockRunnerBuilder).autoLogBloomCaching(eq(true));
verify(mockRunnerBuilder).rpcMaxLogsRange(eq(5000L));
verify(mockRunnerBuilder).apiConfiguration(DEFAULT_API_CONFIGURATION);
verify(mockRunnerBuilder).build();

verify(mockControllerBuilderFactory)
Expand Down Expand Up @@ -1575,13 +1580,15 @@ public void maxpeersOptionMustBeUsed() {

@Test
public void rpcMaxLogsRangeOptionMustBeUsed() {

final long rpcMaxLogsRange = 150L;
parseCommand("--rpc-max-logs-range", Long.toString(rpcMaxLogsRange));

verify(mockRunnerBuilder).rpcMaxLogsRange(longArgumentCaptor.capture());
verify(mockRunnerBuilder).apiConfiguration(apiConfigurationCaptor.capture());
verify(mockRunnerBuilder).build();

assertThat(longArgumentCaptor.getValue()).isEqualTo(rpcMaxLogsRange);
assertThat(apiConfigurationCaptor.getValue())
.isEqualTo(ImmutableApiConfiguration.builder().maxLogsRange((rpcMaxLogsRange)).build());

assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
Expand All @@ -1592,10 +1599,11 @@ public void rpcGasCapOptionMustBeUsed() {
final long rpcGasCap = 150L;
parseCommand("--rpc-gas-cap", Long.toString(rpcGasCap));

verify(mockRunnerBuilder).rpcGasCap(longArgumentCaptor.capture());
verify(mockRunnerBuilder).apiConfiguration(apiConfigurationCaptor.capture());
verify(mockRunnerBuilder).build();

assertThat(longArgumentCaptor.getValue()).isEqualTo(rpcGasCap);
assertThat(apiConfigurationCaptor.getValue())
.isEqualTo(ImmutableApiConfiguration.builder().gasCap((rpcGasCap)).build());

assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
Expand Down
Loading

0 comments on commit 31a57e0

Please sign in to comment.