prevent Besu starting in GoQuorum mode on Mainnet (#1647)

* prevent startup on mainnet if GoQuorum mode enabled

Signed-off-by: Sally MacFarlane <sally.macfarlane@consensys.net>
pull/1654/head
Sally MacFarlane 4 years ago committed by GitHub
parent 67efaa9145
commit 809b801add
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      CHANGELOG.md
  2. 65
      besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
  3. 46
      besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java

@ -4,8 +4,8 @@
### Additions and Improvements
* Added support for batched requests in WebSockets. [#1583](https://github.com/hyperledger/besu/pull/1583)
* Added a protocols section to `admin_peers` to provide info about peer health. [\#1582](https://github.com/hyperledger/besu/pull/1582)
* Added CLI option `--goquorum-compatibility-enabled` to enable GoQuorum compatibility mode. [#1598](https://github.com/hyperledger/besu/pull/1598)
* Added protocols section to `admin_peers` to provide info about peer health. [\#1582](https://github.com/hyperledger/besu/pull/1582)
* Added CLI option `--goquorum-compatibility-enabled` to enable GoQuorum compatibility mode. [#1598](https://github.com/hyperledger/besu/pull/1598). Note that this mode is incompatible with Mainnet.
### Bug Fixes

@ -1327,7 +1327,6 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
validateNatParams();
validateNetStatsParams();
validateDnsOptionsParams();
validateGoQuorumCompatibilityModeParam();
return this;
}
@ -1397,19 +1396,6 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
}
}
private void validateGoQuorumCompatibilityModeParam() {
if (isGoQuorumCompatibilityMode) {
final GenesisConfigOptions genesisConfigOptions = readGenesisConfigOptions();
// this static flag is read by the RLP decoder
GoQuorumOptions.goquorumCompatibilityMode = true;
if (!genesisConfigOptions.isQuorum()) {
throw new IllegalStateException(
"GoQuorum compatibility mode (enabled) can only be used if genesis file has 'isQuorum' flag set to true.");
}
}
}
private GenesisConfigOptions readGenesisConfigOptions() {
final GenesisConfigOptions genesisConfigOptions;
try {
@ -1471,10 +1457,6 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
private BesuCommand configure() throws Exception {
checkPortClash();
if (isGoQuorumCompatibilityMode) {
checkGoQuorumCompatibilityConfig();
}
syncMode =
Optional.ofNullable(syncMode)
.orElse(
@ -1483,6 +1465,9 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
: SyncMode.FULL);
ethNetworkConfig = updateNetworkConfig(getNetwork());
if (isGoQuorumCompatibilityMode) {
checkGoQuorumCompatibilityConfig(ethNetworkConfig);
}
jsonRpcConfiguration = jsonRpcConfiguration();
graphQLConfiguration = graphQLConfiguration();
webSocketConfiguration = webSocketConfiguration();
@ -2281,7 +2266,6 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
throw new ParameterException(commandLine, e.getMessage());
}
}
return builder.build();
}
@ -2400,13 +2384,42 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
});
}
private void checkGoQuorumCompatibilityConfig() {
if (genesisFile != null
&& getGenesisConfigFile().getConfigOptions().isQuorum()
&& !minTransactionGasPrice.isZero()) {
throw new ParameterException(
this.commandLine,
"--min-gas-price must be set to zero if GoQuorum compatibility is enabled in the genesis config.");
private void checkGoQuorumCompatibilityConfig(final EthNetworkConfig ethNetworkConfig) {
if (isGoQuorumCompatibilityMode) {
final GenesisConfigOptions genesisConfigOptions = readGenesisConfigOptions();
// this static flag is read by the RLP decoder
GoQuorumOptions.goquorumCompatibilityMode = true;
if (!genesisConfigOptions.isQuorum()) {
throw new IllegalStateException(
"GoQuorum compatibility mode (enabled) can only be used if genesis file has 'isQuorum' flag set to true.");
}
genesisConfigOptions
.getChainId()
.ifPresent(
chainId ->
ensureGoQuorumCompatibilityModeNotUsedOnMainnet(
chainId, isGoQuorumCompatibilityMode));
if (genesisFile != null
&& getGenesisConfigFile().getConfigOptions().isQuorum()
&& !minTransactionGasPrice.isZero()) {
throw new ParameterException(
this.commandLine,
"--min-gas-price must be set to zero if GoQuorum compatibility is enabled in the genesis config.");
}
if (ethNetworkConfig.getNetworkId().equals(EthNetworkConfig.MAINNET_NETWORK_ID)) {
throw new ParameterException(
this.commandLine, "GoQuorum compatibility mode (enabled) cannot be used on Mainnet.");
}
}
}
private void ensureGoQuorumCompatibilityModeNotUsedOnMainnet(
final BigInteger chainId, final boolean isGoQuorumCompatibilityMode) {
if (isGoQuorumCompatibilityMode && chainId.equals(EthNetworkConfig.MAINNET_NETWORK_ID)) {
throw new IllegalStateException(
"GoQuorum compatibility mode (enabled) cannot be used on Mainnet.");
}
}

@ -125,7 +125,12 @@ public class BesuCommandTest extends CommandTestAbstract {
.put("config", (new JsonObject()).put("chainId", GENESIS_CONFIG_TEST_CHAINID));
private static final JsonObject GENESIS_INVALID_DATA =
(new JsonObject()).put("config", new JsonObject());
private static final JsonObject GENESIS_QUORUM_INTEROP_ENABLED =
private static final JsonObject VALID_GENESIS_QUORUM_INTEROP_ENABLED_WITH_CHAINID =
(new JsonObject())
.put(
"config",
new JsonObject().put("isquorum", true).put("chainId", GENESIS_CONFIG_TEST_CHAINID));
private static final JsonObject INVALID_GENESIS_QUORUM_INTEROP_ENABLED_MAINNET =
(new JsonObject()).put("config", new JsonObject().put("isquorum", true));
private static final String ENCLAVE_PUBLIC_KEY_PATH =
BesuCommand.class.getResource("/orion_publickey.pub").getPath();
@ -3923,7 +3928,8 @@ public class BesuCommandTest extends CommandTestAbstract {
@Test
public void quorumInteropDisabledDoesNotEnforceZeroGasPrice() throws IOException {
final Path genesisFile = createFakeGenesisFile(GENESIS_QUORUM_INTEROP_ENABLED);
final Path genesisFile =
createFakeGenesisFile(VALID_GENESIS_QUORUM_INTEROP_ENABLED_WITH_CHAINID);
parseCommand(
"--goquorum-compatibility-enabled=false", "--genesis-file", genesisFile.toString());
assertThat(commandErrorOutput.toString()).isEmpty();
@ -3931,7 +3937,8 @@ public class BesuCommandTest extends CommandTestAbstract {
@Test
public void quorumInteropEnabledFailsWithoutGasPriceSet() throws IOException {
final Path genesisFile = createFakeGenesisFile(GENESIS_QUORUM_INTEROP_ENABLED);
final Path genesisFile =
createFakeGenesisFile(VALID_GENESIS_QUORUM_INTEROP_ENABLED_WITH_CHAINID);
parseCommand("--goquorum-compatibility-enabled", "--genesis-file", genesisFile.toString());
assertThat(commandErrorOutput.toString())
.contains(
@ -3940,7 +3947,8 @@ public class BesuCommandTest extends CommandTestAbstract {
@Test
public void quorumInteropEnabledFailsWithoutGasPriceSetToZero() throws IOException {
final Path genesisFile = createFakeGenesisFile(GENESIS_QUORUM_INTEROP_ENABLED);
final Path genesisFile =
createFakeGenesisFile(VALID_GENESIS_QUORUM_INTEROP_ENABLED_WITH_CHAINID);
parseCommand(
"--goquorum-compatibility-enabled",
"--genesis-file",
@ -3954,7 +3962,8 @@ public class BesuCommandTest extends CommandTestAbstract {
@Test
public void quorumInteropEnabledSucceedsWithGasPriceSetToZero() throws IOException {
final Path genesisFile = createFakeGenesisFile(GENESIS_QUORUM_INTEROP_ENABLED);
final Path genesisFile =
createFakeGenesisFile(VALID_GENESIS_QUORUM_INTEROP_ENABLED_WITH_CHAINID);
parseCommand(
"--goquorum-compatibility-enabled",
"--genesis-file",
@ -3963,4 +3972,31 @@ public class BesuCommandTest extends CommandTestAbstract {
"0");
assertThat(commandErrorOutput.toString()).isEmpty();
}
@Test
public void quorumInteropEnabledFailsWithMainnetDefaultNetwork() throws IOException {
final Path genesisFile = createFakeGenesisFile(INVALID_GENESIS_QUORUM_INTEROP_ENABLED_MAINNET);
parseCommand(
"--goquorum-compatibility-enabled",
"--genesis-file",
genesisFile.toString(),
"--min-gas-price",
"0");
assertThat(commandErrorOutput.toString())
.contains("GoQuorum compatibility mode (enabled) cannot be used on Mainnet");
}
@Test
public void quorumInteropEnabledFailsWithMainnetChainId() throws IOException {
final Path genesisFile =
createFakeGenesisFile(INVALID_GENESIS_QUORUM_INTEROP_ENABLED_MAINNET.put("chainId", "1"));
parseCommand(
"--goquorum-compatibility-enabled",
"--genesis-file",
genesisFile.toString(),
"--min-gas-price",
"0");
assertThat(commandErrorOutput.toString())
.contains("GoQuorum compatibility mode (enabled) cannot be used on Mainnet");
}
}

Loading…
Cancel
Save