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

Now able to inject static nodes by explicitly specifying
a static nodes JSON file (.json) on the command line

Co-authored-by: Ratan (Rai) Sur <ratan.r.sur@gmail.com>
Signed-off-by: Terrence Cooke <terrence.s.cooke@gmail.com>
pull/1745/head
terrencecooke 4 years ago committed by GitHub
parent cd66968b6d
commit 9d22d03703
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      CHANGELOG.md
  2. 22
      besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
  3. 39
      besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java
  4. 1
      besu/src/test/resources/everything_config.toml

@ -6,6 +6,7 @@
* Implemented [EIP-778](https://eips.ethereum.org/EIPS/eip-778): Ethereum Node Records (ENR) [\#1680](https://github.com/hyperledger/besu/pull/1680)
* Implemented [EIP-868](https://eips.ethereum.org/EIPS/eip-868): Simple Subroutines for the EVM [\#1721](https://github.com/hyperledger/besu/pull/1721)
* Added revert reason to eth_estimateGas RPC call. [\#1730](https://github.com/hyperledger/besu/pull/1730)
* Added command line option --static-nodes-file. [#1644](https://github.com/hyperledger/besu/pull/1644)
### Bug Fixes
@ -17,6 +18,7 @@
### Download link
TBA
## 20.10.3
### Additions and Improvements

@ -1055,6 +1055,13 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
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;
@ -2398,9 +2405,18 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
}
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();
if (!staticNodesPath.toFile().exists()) {
throw new ParameterException(
commandLine, String.format("Static nodes file %s does not exist", staticNodesPath));
}
} else {
final String staticNodesFilename = "static-nodes.json";
staticNodesPath = dataDir().resolve(staticNodesFilename);
}
logger.info("Static Nodes file = {}", staticNodesPath);
return StaticNodesParser.fromPath(staticNodesPath, getEnodeDnsConfiguration());
}

@ -4074,4 +4074,43 @@ public class BesuCommandTest extends CommandTestAbstract {
.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()).contains("Static nodes file", "does not exist");
}
@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();
}
}

@ -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"

Loading…
Cancel
Save