Skip to content

Commit fd09409

Browse files
jflo2fehee
authored andcommitted
Simplifying BesuCommand step 1 (hyperledger#7682)
Simplifying BesuCommand --------- Signed-off-by: Justin Florentine <justin+github@florentine.us>Signed-off-by: Chulhee lee <leefehee@naver.com>
1 parent 7601fd9 commit fd09409

File tree

19 files changed

+501
-269
lines changed

19 files changed

+501
-269
lines changed

acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ProcessBesuNodeRunner.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import static com.google.common.base.Preconditions.checkState;
1818
import static java.nio.charset.StandardCharsets.UTF_8;
1919

20+
import org.hyperledger.besu.cli.options.DataStorageOptions;
2021
import org.hyperledger.besu.cli.options.TransactionPoolOptions;
21-
import org.hyperledger.besu.cli.options.stable.DataStorageOptions;
2222
import org.hyperledger.besu.cli.options.unstable.NetworkingOptions;
2323
import org.hyperledger.besu.ethereum.api.jsonrpc.ipc.JsonRpcIpcConfiguration;
2424
import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration;

besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java

+54-251
Large diffs are not rendered by default.

besu/src/main/java/org/hyperledger/besu/cli/options/stable/DataStorageOptions.java besu/src/main/java/org/hyperledger/besu/cli/options/DataStorageOptions.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
* SPDX-License-Identifier: Apache-2.0
1414
*/
15-
package org.hyperledger.besu.cli.options.stable;
15+
package org.hyperledger.besu.cli.options;
1616

1717
import static org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration.DEFAULT_BONSAI_LIMIT_TRIE_LOGS_ENABLED;
1818
import static org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration.DEFAULT_BONSAI_MAX_LAYERS_TO_LOAD;
@@ -22,7 +22,6 @@
2222
import static org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration.Unstable.DEFAULT_BONSAI_CODE_USING_CODE_HASH_ENABLED;
2323
import static org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration.Unstable.DEFAULT_BONSAI_FULL_FLAT_DB_ENABLED;
2424

25-
import org.hyperledger.besu.cli.options.CLIOptions;
2625
import org.hyperledger.besu.cli.util.CommandLineUtils;
2726
import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration;
2827
import org.hyperledger.besu.ethereum.worldstate.ImmutableDataStorageConfiguration;

besu/src/main/java/org/hyperledger/besu/cli/options/stable/ApiConfigurationOptions.java

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
* Handles configuration options for the API in Besu, including gas price settings, RPC log range,
2929
* and trace filter range.
3030
*/
31+
// TODO: implement CLIOption<ApiConfiguration>
3132
public class ApiConfigurationOptions {
3233
/** Default constructor. */
3334
public ApiConfigurationOptions() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright contributors to Hyperledger Besu.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*
13+
* SPDX-License-Identifier: Apache-2.0
14+
*/
15+
package org.hyperledger.besu.cli.options.stable;
16+
17+
import org.hyperledger.besu.cli.custom.JsonRPCAllowlistHostsProperty;
18+
19+
import java.nio.file.Path;
20+
21+
/**
22+
* Command line options for configuring Engine RPC on the node.
23+
*
24+
* @param overrideEngineRpcEnabled enable the engine api, even in the absence of merge-specific
25+
* configurations.
26+
* @param engineRpcPort Port to provide consensus client APIS on
27+
* @param engineJwtKeyFile Path to file containing shared secret key for JWT signature verification
28+
* @param isEngineAuthDisabled Disable authentication for Engine APIs
29+
* @param engineHostsAllowlist List of hosts to allowlist for Engine APIs
30+
*/
31+
public record EngineRPCConfiguration(
32+
Boolean overrideEngineRpcEnabled,
33+
Integer engineRpcPort,
34+
Path engineJwtKeyFile,
35+
Boolean isEngineAuthDisabled,
36+
JsonRPCAllowlistHostsProperty engineHostsAllowlist) {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright contributors to Hyperledger Besu.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*
13+
* SPDX-License-Identifier: Apache-2.0
14+
*/
15+
package org.hyperledger.besu.cli.options.stable;
16+
17+
import static org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration.DEFAULT_ENGINE_JSON_RPC_PORT;
18+
19+
import org.hyperledger.besu.cli.DefaultCommandValues;
20+
import org.hyperledger.besu.cli.custom.JsonRPCAllowlistHostsProperty;
21+
import org.hyperledger.besu.cli.options.CLIOptions;
22+
import org.hyperledger.besu.cli.util.CommandLineUtils;
23+
24+
import java.nio.file.Path;
25+
import java.util.List;
26+
27+
import picocli.CommandLine;
28+
29+
/** Command line options for configuring Engine RPC on the node. */
30+
public class EngineRPCOptions implements CLIOptions<EngineRPCConfiguration> {
31+
32+
/** Default constructor */
33+
public EngineRPCOptions() {}
34+
35+
@CommandLine.Option(
36+
names = {"--engine-rpc-enabled"},
37+
description = "enable the engine api, even in the absence of merge-specific configurations.")
38+
private final Boolean overrideEngineRpcEnabled = false;
39+
40+
@CommandLine.Option(
41+
names = {"--engine-rpc-port", "--engine-rpc-http-port"},
42+
paramLabel = DefaultCommandValues.MANDATORY_PORT_FORMAT_HELP,
43+
description = "Port to provide consensus client APIS on (default: ${DEFAULT-VALUE})",
44+
arity = "1")
45+
private final Integer engineRpcPort = DEFAULT_ENGINE_JSON_RPC_PORT;
46+
47+
@CommandLine.Option(
48+
names = {"--engine-jwt-secret"},
49+
paramLabel = DefaultCommandValues.MANDATORY_FILE_FORMAT_HELP,
50+
description = "Path to file containing shared secret key for JWT signature verification")
51+
private final Path engineJwtKeyFile = null;
52+
53+
@CommandLine.Option(
54+
names = {"--engine-jwt-disabled"},
55+
description = "Disable authentication for Engine APIs (default: ${DEFAULT-VALUE})")
56+
private final Boolean isEngineAuthDisabled = false;
57+
58+
@CommandLine.Option(
59+
names = {"--engine-host-allowlist"},
60+
paramLabel = "<hostname>[,<hostname>...]... or * or all",
61+
description =
62+
"Comma separated list of hostnames to allow for ENGINE API access (applies to both HTTP and websockets), or * to accept any host (default: ${DEFAULT-VALUE})",
63+
defaultValue = "localhost,127.0.0.1")
64+
private final JsonRPCAllowlistHostsProperty engineHostsAllowlist =
65+
new JsonRPCAllowlistHostsProperty();
66+
67+
@Override
68+
public EngineRPCConfiguration toDomainObject() {
69+
return new EngineRPCConfiguration(
70+
overrideEngineRpcEnabled,
71+
engineRpcPort,
72+
engineJwtKeyFile,
73+
isEngineAuthDisabled,
74+
engineHostsAllowlist);
75+
}
76+
77+
@Override
78+
public List<String> getCLIOptions() {
79+
return CommandLineUtils.getCLIOptions(this, new EngineRPCOptions());
80+
}
81+
}

besu/src/main/java/org/hyperledger/besu/cli/options/stable/GraphQlOptions.java

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import picocli.CommandLine;
3030

3131
/** Handles configuration options for the GraphQL HTTP service in Besu. */
32+
// TODO: implement CLIOptions<GraphQLConfiguration>
3233
public class GraphQlOptions {
3334
@CommandLine.Option(
3435
names = {"--graphql-http-enabled"},

besu/src/main/java/org/hyperledger/besu/cli/options/stable/JsonRpcHttpOptions.java

+24-10
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
* Handles configuration options for the JSON-RPC HTTP service, including validation and creation of
5353
* a JSON-RPC configuration.
5454
*/
55+
// TODO: implement CLIOption<JsonRpcConfiguration>
5556
public class JsonRpcHttpOptions {
5657
@CommandLine.Option(
5758
names = {"--rpc-http-enabled"},
@@ -265,37 +266,50 @@ && rpcHttpAuthenticationCredentialsFile(commandLine) == null
265266
/**
266267
* Creates a JsonRpcConfiguration based on the provided options.
267268
*
268-
* @param hostsAllowlist List of hosts allowed
269-
* @param defaultHostAddress Default host address
270-
* @param timoutSec timeout in seconds
271-
* @return A JsonRpcConfiguration instance
269+
* @return configuration populated from options or defaults
272270
*/
273-
public JsonRpcConfiguration jsonRpcConfiguration(
274-
final List<String> hostsAllowlist, final String defaultHostAddress, final Long timoutSec) {
271+
public JsonRpcConfiguration jsonRpcConfiguration() {
275272

276273
final JsonRpcConfiguration jsonRpcConfiguration = JsonRpcConfiguration.createDefault();
277274
jsonRpcConfiguration.setEnabled(isRpcHttpEnabled);
278-
jsonRpcConfiguration.setHost(
279-
Strings.isNullOrEmpty(rpcHttpHost) ? defaultHostAddress : rpcHttpHost);
280275
jsonRpcConfiguration.setPort(rpcHttpPort);
281276
jsonRpcConfiguration.setMaxActiveConnections(rpcHttpMaxConnections);
282277
jsonRpcConfiguration.setCorsAllowedDomains(rpcHttpCorsAllowedOrigins);
283278
jsonRpcConfiguration.setRpcApis(rpcHttpApis.stream().distinct().collect(Collectors.toList()));
284279
jsonRpcConfiguration.setNoAuthRpcApis(
285280
rpcHttpApiMethodsNoAuth.stream().distinct().collect(Collectors.toList()));
286-
jsonRpcConfiguration.setHostsAllowlist(hostsAllowlist);
287281
jsonRpcConfiguration.setAuthenticationEnabled(isRpcHttpAuthenticationEnabled);
288282
jsonRpcConfiguration.setAuthenticationCredentialsFile(rpcHttpAuthenticationCredentialsFile);
289283
jsonRpcConfiguration.setAuthenticationPublicKeyFile(rpcHttpAuthenticationPublicKeyFile);
290284
jsonRpcConfiguration.setAuthenticationAlgorithm(rpcHttpAuthenticationAlgorithm);
291285
jsonRpcConfiguration.setTlsConfiguration(rpcHttpTlsConfiguration());
292-
jsonRpcConfiguration.setHttpTimeoutSec(timoutSec);
293286
jsonRpcConfiguration.setMaxBatchSize(rpcHttpMaxBatchSize);
294287
jsonRpcConfiguration.setMaxRequestContentLength(rpcHttpMaxRequestContentLength);
295288
jsonRpcConfiguration.setPrettyJsonEnabled(prettyJsonEnabled);
296289
return jsonRpcConfiguration;
297290
}
298291

292+
/**
293+
* Creates a JsonRpcConfiguration based on the provided options.
294+
*
295+
* @param hostsAllowlist List of hosts allowed
296+
* @param defaultHostAddress Default host address
297+
* @param timoutSec timeout in seconds
298+
* @return A JsonRpcConfiguration instance
299+
*/
300+
public JsonRpcConfiguration jsonRpcConfiguration(
301+
final List<String> hostsAllowlist, final String defaultHostAddress, final Long timoutSec) {
302+
303+
final JsonRpcConfiguration jsonRpcConfiguration = this.jsonRpcConfiguration();
304+
305+
jsonRpcConfiguration.setHost(
306+
Strings.isNullOrEmpty(rpcHttpHost) ? defaultHostAddress : rpcHttpHost);
307+
jsonRpcConfiguration.setHostsAllowlist(hostsAllowlist);
308+
;
309+
jsonRpcConfiguration.setHttpTimeoutSec(timoutSec);
310+
return jsonRpcConfiguration;
311+
}
312+
299313
/**
300314
* Checks dependencies between options.
301315
*

besu/src/main/java/org/hyperledger/besu/cli/options/stable/MetricsOptionGroup.java

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import picocli.CommandLine;
3131

3232
/** Command line options for configuring metrics. */
33+
// TODO: implement CLIOption<MetricsConfiguration> and rename to drop the Group
3334
public class MetricsOptionGroup {
3435
@CommandLine.Option(
3536
names = {"--metrics-enabled"},

0 commit comments

Comments
 (0)