Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added command line option --static-nodes-file (#1414) #1644

Merged
merged 8 commits into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Additions and Improvements
* Added `memory` as an option to `--key-value-storage`. This ephemeral storage is intended for sync testing and debugging. [\#1617](https://github.com/hyperledger/besu/pull/1617)
* Fixed gasPrice parameter not always respected when passed to `eth_estimateGas` endpoint [#1636](https://github.com/hyperledger/besu/pull/1636)
* Added command line option --static-nodes-file. [#1644](https://github.com/hyperledger/besu/pull/1644)

### Bug Fixes

Expand Down
18 changes: 15 additions & 3 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,13 @@ void setBannedNodeIds(final List<String> values) {
description = "Start Besu in GoQuorum compatibility mode (default: ${DEFAULT-VALUE})")
private final Boolean isGoQuorumCompatibilityMode = false;

@CommandLine.Option(
names = {"--static-nodes-file"},
paramLabel = MANDATORY_FILE_FORMAT_HELP,
description =
"Specifies the static node file containing the static nodes for this node to connect to")
private final Path staticNodesFile = null;

private EthNetworkConfig ethNetworkConfig;
private JsonRpcConfiguration jsonRpcConfiguration;
private GraphQLConfiguration graphQLConfiguration;
Expand Down Expand Up @@ -2348,9 +2355,14 @@ public MetricsSystem getMetricsSystem() {
}

private Set<EnodeURL> loadStaticNodes() throws IOException {
final String staticNodesFilename = "static-nodes.json";
final Path staticNodesPath = dataDir().resolve(staticNodesFilename);

final Path staticNodesPath;
if (staticNodesFile != null) {
staticNodesPath = staticNodesFile.toAbsolutePath();
} else {
final String staticNodesFilename = "static-nodes.json";
staticNodesPath = dataDir().resolve(staticNodesFilename);
}
logger.info("Static Nodes file = {}", staticNodesPath);
return StaticNodesParser.fromPath(staticNodesPath, getEnodeDnsConfiguration());
}

Expand Down
39 changes: 39 additions & 0 deletions besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4027,4 +4027,43 @@ public void assertThatCheckPortClashRejectsAsExpected() throws Exception {
.contains(
"Port number '8546' has been specified multiple times. Please review the supplied configuration.");
}

@Test
public void staticNodesFileOptionValueAbsentMessage() {
parseCommand("--static-nodes-file");
assertThat(commandErrorOutput.toString()).startsWith("Missing required parameter for option");
}

@Test
public void staticNodesFilesOptionInvalidJSONFormatError() throws IOException {
final Path tempfile =
createTempFile(
"static-nodes-badformat.json",
"\"enode://c0b0e1151971f8a22dc2493c622317c8706c731f6fcf46d93104ef"
+ "3a08f21f7750b5d5e17f311091f732c9f917b02e1ae6d39f076903779fd1e7"
+ "e7e6cd2fcef6@192.168.1.25:30303\"\n]");
parseCommand("--static-nodes-file", tempfile.toString());
assertThat(commandErrorOutput.toString())
.startsWith("Failed to decode:Cannot deserialize instance of");
}

@Test
public void staticNodesFileOptionFileDoesNotExistMessage() {
parseCommand("--static-nodes-file", "this-file-does-not-exist-at-all.json");
assertThat(commandErrorOutput.toString()).isEmpty();
}

@Test
public void staticNodesFileOptionValidParamenter() throws IOException {
final Path staticNodeTempFile =
createTempFile(
"static-nodes-goodformat.json",
"[\n"
+ "\"enode://c0b0e1151971f8a22dc2493c622317c8706c731f6fcf46d93104ef"
+ "3a08f21f7750b5d5e17f311091f732c9f917b02e1ae6d39f076903779fd1e7"
+ "e7e6cd2fcef6@192.168.1.25:30303\"\n]");
parseCommand("--static-nodes-file", staticNodeTempFile.toString());
assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).isEmpty();
}
}
1 change: 1 addition & 0 deletions besu/src/test/resources/everything_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ color-enabled=false
node-private-key-file="./path/to/privateKey"
pid-path="~/.pid"
reorg-logging-threshold=0
static-nodes-file="~/besudata/static-nodes.json"

# Security Module plugin to use
security-module="localfile"
Expand Down