Error on PoW Skipping for JSON Block Import (#1815)

The JSON block format doesn't include a nonce so we can't skip PoW.

Signed-off-by: Ratan Rai Sur <ratan.r.sur@gmail.com>
pull/1816/head
Ratan (Rai) Sur 4 years ago committed by GitHub
parent 2d83e13bb8
commit 92064a1f87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      CHANGELOG.md
  2. 4
      besu/src/main/java/org/hyperledger/besu/cli/subcommands/blocks/BlocksSubCommand.java
  3. 14
      besu/src/test/java/org/hyperledger/besu/cli/subcommands/blocks/BlocksSubCommandTest.java

@ -3,10 +3,11 @@
## 21.2.0-RC1
### 21.2 Breaking Changes
There are currently no breaking changes in 21.2
* `--skip-pow-validation-enabled` is now an error with `block import --format JSON`. This is because the JSON format doesn't include the nonce so the proof of work must be calculated.
### Additions and Improvements
* Removed unused flags in default genesis configs [\#1812](https://github.com/hyperledger/besu/pull/1812)
* `--skip-pow-validation-enabled` is now an error with `block import --format JSON`. This is because the JSON format doesn't include the nonce so the proof of work must be calculated. [\#1815](https://github.com/hyperledger/besu/pull/1815)
### Bug Fixes

@ -188,6 +188,10 @@ public class BlocksSubCommand implements Runnable {
if (blockImportFiles.isEmpty()) {
throw new ParameterException(spec.commandLine(), "No files specified to import.");
}
if (skipPow && format.equals(BlockImportFormat.JSON)) {
throw new ParameterException(
spec.commandLine(), "Can't skip proof of work validation for JSON blocks");
}
LOG.info("Import {} block data from {} files", format, blockImportFiles.size());
final Optional<MetricsService> metricsService = initMetrics(parentCommand);

@ -145,6 +145,20 @@ public class BlocksSubCommandTest extends CommandTestAbstract {
assertThat(commandErrorOutput.toString()).startsWith(expectedErrorOutputStart);
}
@Test
public void callingBlockImportSubCommandWithJSONAndSkipPOWFails() {
parseCommand(
BLOCK_SUBCOMMAND_NAME,
BLOCK_IMPORT_SUBCOMMAND_NAME,
"--format",
"JSON",
"--skip-pow-validation-enabled",
"blocks.file");
final String expectedErrorOutputStart = "Can't skip";
assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).startsWith(expectedErrorOutputStart);
}
@Test
public void callingBlockImportSubCommandHelpMustDisplayUsage() {
parseCommand(BLOCK_SUBCOMMAND_NAME, BLOCK_IMPORT_SUBCOMMAND_NAME, "--help");

Loading…
Cancel
Save