Skip to content

Commit

Permalink
In process RPC service (hyperledger#7395)
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Signed-off-by: gconnect <agatevureglory@gmail.com>
  • Loading branch information
fab-10 authored and gconnect committed Aug 26, 2024
1 parent 9e3e258 commit 0a52e35
Show file tree
Hide file tree
Showing 28 changed files with 568 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

### Additions and Improvements
- Expose set finalized/safe block in plugin api BlockchainService. These method can be used by plugins to set finalized/safe block for a PoA network (such as QBFT, IBFT and Clique).[#7382](https://github.com/hyperledger/besu/pull/7382)
- In process RPC service [#7395](https://github.com/hyperledger/besu/pull/7395)

### Bug fixes

Expand Down Expand Up @@ -44,7 +45,7 @@
- Force bonsai-limit-trie-logs-enabled=false when sync-mode=FULL instead of startup error [#7357](https://github.com/hyperledger/besu/pull/7357)
- `--Xbonsai-parallel-tx-processing-enabled` option enables executing transactions in parallel during block processing for Bonsai nodes
- Reduce default trie log pruning window size from 30,000 to 5,000 [#7365](https://github.com/hyperledger/besu/pull/7365)
- Add option `--poa-discovery-retry-bootnodes` for PoA networks to always use bootnodes during peer refresh, not just on first start [#7314](https://github.com/hyperledger/besu/pull/7314)
- Add option `--poa-discovery-retry-bootnodes` for PoA networks to always use bootnodes during peer refresh, not just on first start [#7314](https://github.com/hyperledger/besu/pull/7314)

### Bug fixes
- Fix `eth_call` deserialization to correctly ignore unknown fields in the transaction object. [#7323](https://github.com/hyperledger/besu/pull/7323)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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.InProcessRpcConfiguration;
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 @@ -109,6 +110,7 @@ public class BesuNode implements NodeConfiguration, RunnableNode, AutoCloseable
private final Optional<JsonRpcConfiguration> engineRpcConfiguration;
private final WebSocketConfiguration webSocketConfiguration;
private final JsonRpcIpcConfiguration jsonRpcIpcConfiguration;
private final InProcessRpcConfiguration inProcessRpcConfiguration;
private final MetricsConfiguration metricsConfiguration;
private final DataStorageConfiguration dataStorageConfiguration;
private Optional<PermissioningConfiguration> permissioningConfiguration;
Expand Down Expand Up @@ -143,6 +145,7 @@ public BesuNode(
final Optional<JsonRpcConfiguration> engineRpcConfiguration,
final WebSocketConfiguration webSocketConfiguration,
final JsonRpcIpcConfiguration jsonRpcIpcConfiguration,
final InProcessRpcConfiguration inProcessRpcConfiguration,
final MetricsConfiguration metricsConfiguration,
final Optional<PermissioningConfiguration> permissioningConfiguration,
final ApiConfiguration apiConfiguration,
Expand Down Expand Up @@ -193,6 +196,7 @@ public BesuNode(
this.engineRpcConfiguration = engineRpcConfiguration;
this.webSocketConfiguration = webSocketConfiguration;
this.jsonRpcIpcConfiguration = jsonRpcIpcConfiguration;
this.inProcessRpcConfiguration = inProcessRpcConfiguration;
this.metricsConfiguration = metricsConfiguration;
this.permissioningConfiguration = permissioningConfiguration;
this.apiConfiguration = apiConfiguration;
Expand Down Expand Up @@ -624,6 +628,10 @@ JsonRpcIpcConfiguration jsonRpcIpcConfiguration() {
return jsonRpcIpcConfiguration;
}

InProcessRpcConfiguration inProcessRpcConfiguration() {
return inProcessRpcConfiguration;
}

Optional<String> wsRpcListenHost() {
return Optional.of(webSocketConfiguration().getHost());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.hyperledger.besu.ethereum.GasLimitCalculator;
import org.hyperledger.besu.ethereum.api.ApiConfiguration;
import org.hyperledger.besu.ethereum.api.graphql.GraphQLConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.InProcessRpcConfiguration;
import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters;
import org.hyperledger.besu.ethereum.core.plugins.PluginConfiguration;
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration;
Expand Down Expand Up @@ -236,6 +237,8 @@ public void startNode(final BesuNode node) {
.transactionPoolValidatorService(transactionPoolValidatorServiceImpl)
.build();

final InProcessRpcConfiguration inProcessRpcConfiguration = node.inProcessRpcConfiguration();

final int maxPeers = 25;

builder
Expand Down Expand Up @@ -297,7 +300,8 @@ public void startNode(final BesuNode node) {
.besuPluginContext(besuPluginContext)
.autoLogBloomCaching(false)
.storageProvider(storageProvider)
.rpcEndpointService(rpcEndpointServiceImpl);
.rpcEndpointService(rpcEndpointServiceImpl)
.inProcessRpcConfiguration(inProcessRpcConfiguration);
node.engineRpcConfiguration().ifPresent(runnerBuilder::engineJsonRpcConfiguration);

besuPluginContext.beforeExternalServices();
Expand All @@ -313,6 +317,9 @@ public void startNode(final BesuNode node) {
besuController.getTransactionPool(),
besuController.getSyncState(),
besuController.getProtocolContext().getBadBlockManager()));

rpcEndpointServiceImpl.init(runner.getInProcessRpcMethods());

besuPluginContext.startPlugins();

runner.startEthereumMainLoop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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.InProcessRpcConfiguration;
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 @@ -45,6 +46,7 @@ public class BesuNodeConfiguration {
private final Optional<JsonRpcConfiguration> engineRpcConfiguration;
private final WebSocketConfiguration webSocketConfiguration;
private final JsonRpcIpcConfiguration jsonRpcIpcConfiguration;
private final InProcessRpcConfiguration inProcessRpcConfiguration;
private final MetricsConfiguration metricsConfiguration;
private final Optional<PermissioningConfiguration> permissioningConfiguration;
private final ApiConfiguration apiConfiguration;
Expand Down Expand Up @@ -81,6 +83,7 @@ public class BesuNodeConfiguration {
final Optional<JsonRpcConfiguration> engineRpcConfiguration,
final WebSocketConfiguration webSocketConfiguration,
final JsonRpcIpcConfiguration jsonRpcIpcConfiguration,
final InProcessRpcConfiguration inProcessRpcConfiguration,
final MetricsConfiguration metricsConfiguration,
final Optional<PermissioningConfiguration> permissioningConfiguration,
final ApiConfiguration apiConfiguration,
Expand Down Expand Up @@ -114,6 +117,7 @@ public class BesuNodeConfiguration {
this.engineRpcConfiguration = engineRpcConfiguration;
this.webSocketConfiguration = webSocketConfiguration;
this.jsonRpcIpcConfiguration = jsonRpcIpcConfiguration;
this.inProcessRpcConfiguration = inProcessRpcConfiguration;
this.metricsConfiguration = metricsConfiguration;
this.permissioningConfiguration = permissioningConfiguration;
this.apiConfiguration = apiConfiguration;
Expand Down Expand Up @@ -171,6 +175,10 @@ public JsonRpcIpcConfiguration getJsonRpcIpcConfiguration() {
return jsonRpcIpcConfiguration;
}

public InProcessRpcConfiguration getInProcessRpcConfiguration() {
return inProcessRpcConfiguration;
}

public MetricsConfiguration getMetricsConfiguration() {
return metricsConfiguration;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
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.ImmutableInProcessRpcConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.InProcessRpcConfiguration;
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 @@ -70,6 +72,8 @@ public class BesuNodeConfigurationBuilder {
private JsonRpcConfiguration engineRpcConfiguration = JsonRpcConfiguration.createEngineDefault();
private WebSocketConfiguration webSocketConfiguration = WebSocketConfiguration.createDefault();
private JsonRpcIpcConfiguration jsonRpcIpcConfiguration = new JsonRpcIpcConfiguration();
private InProcessRpcConfiguration inProcessRpcConfiguration =
ImmutableInProcessRpcConfiguration.builder().build();
private MetricsConfiguration metricsConfiguration = MetricsConfiguration.builder().build();
private Optional<PermissioningConfiguration> permissioningConfiguration = Optional.empty();
private ApiConfiguration apiConfiguration = ImmutableApiConfiguration.builder().build();
Expand Down Expand Up @@ -258,6 +262,12 @@ public BesuNodeConfigurationBuilder jsonRpcIpcConfiguration(
return this;
}

public BesuNodeConfigurationBuilder inProcessRpcConfiguration(
final InProcessRpcConfiguration inProcessRpcConfiguration) {
this.inProcessRpcConfiguration = inProcessRpcConfiguration;
return this;
}

public BesuNodeConfigurationBuilder metricsConfiguration(
final MetricsConfiguration metricsConfiguration) {
this.metricsConfiguration = metricsConfiguration;
Expand Down Expand Up @@ -516,6 +526,7 @@ public BesuNodeConfiguration build() {
Optional.of(engineRpcConfiguration),
webSocketConfiguration,
jsonRpcIpcConfiguration,
inProcessRpcConfiguration,
metricsConfiguration,
permissioningConfiguration,
apiConfiguration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import static java.util.Arrays.asList;
import static java.util.stream.Collectors.toList;
import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.ADMIN;
import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.IBFT;

import org.hyperledger.besu.crypto.KeyPair;
import org.hyperledger.besu.datatypes.Wei;
Expand Down Expand Up @@ -43,6 +45,7 @@
import java.net.URISyntaxException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.Set;
Expand All @@ -64,6 +67,7 @@ public BesuNode create(final BesuNodeConfiguration config) throws IOException {
config.getEngineRpcConfiguration(),
config.getWebSocketConfiguration(),
config.getJsonRpcIpcConfiguration(),
config.getInProcessRpcConfiguration(),
config.getMetricsConfiguration(),
config.getPermissioningConfiguration(),
config.getApiConfiguration(),
Expand Down Expand Up @@ -330,12 +334,20 @@ public BesuNode createArchiveNodeWithRpcDisabled(final String name) throws IOExc
}

public BesuNode createPluginsNode(
final String name, final List<String> plugins, final List<String> extraCLIOptions)
final String name,
final List<String> plugins,
final List<String> extraCLIOptions,
final String... extraRpcApis)
throws IOException {

final List<String> enableRpcApis = new ArrayList<>(Arrays.asList(extraRpcApis));
enableRpcApis.addAll(List.of(IBFT.name(), ADMIN.name()));

return create(
new BesuNodeConfigurationBuilder()
.name(name)
.jsonRpcConfiguration(node.createJsonRpcWithIbft2AdminEnabledConfig())
.jsonRpcConfiguration(
node.createJsonRpcWithRpcApiEnabledConfig(enableRpcApis.toArray(String[]::new)))
.webSocketConfiguration(node.createWebSocketEnabledConfig())
.plugins(plugins)
.extraCLIOptions(extraCLIOptions)
Expand Down Expand Up @@ -394,6 +406,7 @@ public BesuNode createCliqueNodeWithExtraCliOptionsAndRpcApis(
.miningEnabled()
.jsonRpcConfiguration(node.createJsonRpcWithCliqueEnabledConfig(extraRpcApis))
.webSocketConfiguration(node.createWebSocketEnabledConfig())
.inProcessRpcConfiguration(node.createInProcessRpcConfiguration(extraRpcApis))
.devMode(false)
.jsonRpcTxPool()
.genesisConfigProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.MINER;
import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis.QBFT;

import org.hyperledger.besu.ethereum.api.jsonrpc.ImmutableInProcessRpcConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.InProcessRpcConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration;
import org.hyperledger.besu.tests.acceptance.dsl.node.RunnableNode;
Expand Down Expand Up @@ -94,4 +96,14 @@ public JsonRpcConfiguration createJsonRpcWithRpcApiEnabledConfig(final String...
jsonRpcConfig.setRpcApis(rpcApis);
return jsonRpcConfig;
}

public InProcessRpcConfiguration createInProcessRpcConfiguration(final Set<String> extraRpcApis) {
final Set<String> rpcApis =
new HashSet<>(ImmutableInProcessRpcConfiguration.DEFAULT_IN_PROCESS_RPC_APIS);
rpcApis.addAll(extraRpcApis);
return ImmutableInProcessRpcConfiguration.builder()
.inProcessRpcApis(rpcApis)
.isEnabled(true)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public PrivacyNode(
besuConfig.getEngineRpcConfiguration(),
besuConfig.getWebSocketConfiguration(),
besuConfig.getJsonRpcIpcConfiguration(),
besuConfig.getInProcessRpcConfiguration(),
besuConfig.getMetricsConfiguration(),
besuConfig.getPermissioningConfiguration(),
besuConfig.getApiConfiguration(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.tests.acceptance.dsl.transaction.miner;

import static org.assertj.core.api.Assertions.assertThat;

import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests;
import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction;

import java.io.IOException;
import java.math.BigInteger;

import org.web3j.protocol.core.methods.response.EthGasPrice;

public class MinerGetMinGasPriceTransaction implements Transaction<BigInteger> {

@Override
public BigInteger execute(final NodeRequests node) {
try {
final EthGasPrice result = node.miner().minerGetMinGasPrice().send();
assertThat(result).isNotNull();
assertThat(result.hasError()).isFalse();

return result.getGasPrice();

} catch (final IOException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import org.web3j.protocol.Web3jService;
import org.web3j.protocol.core.Request;
import org.web3j.protocol.core.methods.response.EthGasPrice;

public class MinerRequestFactory {

Expand All @@ -40,4 +41,8 @@ Request<?, org.web3j.protocol.core.methods.response.VoidResponse> minerStop() {
web3jService,
org.web3j.protocol.core.methods.response.VoidResponse.class);
}

Request<?, EthGasPrice> minerGetMinGasPrice() {
return new Request<>("miner_getMinGasPrice", null, web3jService, EthGasPrice.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ public MinerStartTransaction minerStart() {
public MinerStopTransaction minerStop() {
return new MinerStopTransaction();
}

public MinerGetMinGasPriceTransaction minerGetMinGasPrice() {
return new MinerGetMinGasPriceTransaction();
}
}
Loading

0 comments on commit 0a52e35

Please sign in to comment.