[NC-1812] Fix blockchainImport error (#178)

mbaxter 6 years ago committed by GitHub
parent 13ae9f5701
commit 5fa4ed6fb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      pantheon/src/main/java/tech/pegasys/pantheon/util/BlockchainImporter.java
  2. 19
      pantheon/src/test/java/tech/pegasys/pantheon/util/BlockchainImporterTest.java
  3. 0
      pantheon/src/test/resources/tech/pegasys/pantheon/util/blockchain-import-genesis-file.json
  4. 0
      pantheon/src/test/resources/tech/pegasys/pantheon/util/blockchain-import.bin

@ -174,6 +174,7 @@ public class BlockchainImporter extends BlockImporter {
final ProtocolContext<C> context = pantheonController.getProtocolContext(); final ProtocolContext<C> context = pantheonController.getProtocolContext();
final GenesisConfig<C> genesis = pantheonController.getGenesisConfig(); final GenesisConfig<C> genesis = pantheonController.getGenesisConfig();
checkNotNull(isSkipBlocks); checkNotNull(isSkipBlocks);
final BlockHeader genesisHeader = genesis.getBlock().getHeader();
final long startTime = System.currentTimeMillis(); final long startTime = System.currentTimeMillis();
long lapStartTime = startTime; long lapStartTime = startTime;
@ -227,6 +228,11 @@ public class BlockchainImporter extends BlockImporter {
body = new BlockBody(rlp.readList(Transaction::readFrom), rlp.readList(headerReader)); body = new BlockBody(rlp.readList(Transaction::readFrom), rlp.readList(headerReader));
rlp.leaveList(); rlp.leaveList();
receipts = rlp.readList(TransactionReceipt::readFrom); receipts = rlp.readList(TransactionReceipt::readFrom);
if (header.getNumber() == genesisHeader.getNumber()) {
// Don't import genesis block
previousHeader = header;
continue;
}
final ProtocolSpec<C> protocolSpec = final ProtocolSpec<C> protocolSpec =
protocolSchedule.getByBlockNumber(header.getNumber()); protocolSchedule.getByBlockNumber(header.getNumber());

@ -44,11 +44,18 @@ public final class BlockchainImporterTest {
BlockchainImporter blockImporter = new BlockchainImporter(); BlockchainImporter blockImporter = new BlockchainImporter();
@Test @Test
public void blockImport() throws Exception { public void importBlocksWithoutValidation() throws Exception {
blockImportTest(true);
}
@Test
public void importBlocksWithValidation() throws Exception {
blockImportTest(false);
}
private void blockImportTest(final boolean skipValidation) throws Exception {
final URL importFileURL = final URL importFileURL =
getClass() getClass().getClassLoader().getResource("tech/pegasys/pantheon/util/blockchain-import.bin");
.getClassLoader()
.getResource("tech/pegasys/pantheon/ethereum/jsonrpc/json-rpc-test.bin");
assertThat(importFileURL).isNotNull(); assertThat(importFileURL).isNotNull();
final Path source = new File(importFileURL.toURI()).toPath(); final Path source = new File(importFileURL.toURI()).toPath();
@ -57,7 +64,7 @@ public final class BlockchainImporterTest {
final URL genesisJsonUrl = final URL genesisJsonUrl =
getClass() getClass()
.getClassLoader() .getClassLoader()
.getResource("tech/pegasys/pantheon/ethereum/jsonrpc/jsonRpcTestGenesis.json"); .getResource("tech/pegasys/pantheon/util/blockchain-import-genesis-file.json");
assertThat(genesisJsonUrl).isNotNull(); assertThat(genesisJsonUrl).isNotNull();
final String genesisJson = Resources.toString(genesisJsonUrl, Charsets.UTF_8); final String genesisJson = Resources.toString(genesisJsonUrl, Charsets.UTF_8);
final KeyPair keyPair = loadKeyPair(target); final KeyPair keyPair = loadKeyPair(target);
@ -73,7 +80,7 @@ public final class BlockchainImporterTest {
miningParams, miningParams,
keyPair); keyPair);
final BlockchainImporter.ImportResult result = final BlockchainImporter.ImportResult result =
blockImporter.importBlockchain(source, ctrl, true, 1, 1, false, false, null); blockImporter.importBlockchain(source, ctrl, skipValidation, 1, 1, false, false, null);
System.out.println(source); System.out.println(source);
System.out.println(target); System.out.println(target);

Loading…
Cancel
Save