Skip to content

Commit

Permalink
[NC-1812] Fix blockchainImport error (hyperledger#178)
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
  • Loading branch information
mbaxter authored Oct 26, 2018
1 parent 4c57a91 commit dc2fc72
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ private <C> BlockImporter.ImportResult importBlockchain(
final ProtocolContext<C> context = pantheonController.getProtocolContext();
final GenesisConfig<C> genesis = pantheonController.getGenesisConfig();
checkNotNull(isSkipBlocks);
final BlockHeader genesisHeader = genesis.getBlock().getHeader();

final long startTime = System.currentTimeMillis();
long lapStartTime = startTime;
Expand Down Expand Up @@ -227,6 +228,11 @@ private <C> BlockImporter.ImportResult importBlockchain(
body = new BlockBody(rlp.readList(Transaction::readFrom), rlp.readList(headerReader));
rlp.leaveList();
receipts = rlp.readList(TransactionReceipt::readFrom);
if (header.getNumber() == genesisHeader.getNumber()) {
// Don't import genesis block
previousHeader = header;
continue;
}
final ProtocolSpec<C> protocolSpec =
protocolSchedule.getByBlockNumber(header.getNumber());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,18 @@ public final class BlockchainImporterTest {
BlockchainImporter blockImporter = new BlockchainImporter();

@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 =
getClass()
.getClassLoader()
.getResource("tech/pegasys/pantheon/ethereum/jsonrpc/json-rpc-test.bin");
getClass().getClassLoader().getResource("tech/pegasys/pantheon/util/blockchain-import.bin");
assertThat(importFileURL).isNotNull();

final Path source = new File(importFileURL.toURI()).toPath();
Expand All @@ -57,7 +64,7 @@ public void blockImport() throws Exception {
final URL genesisJsonUrl =
getClass()
.getClassLoader()
.getResource("tech/pegasys/pantheon/ethereum/jsonrpc/jsonRpcTestGenesis.json");
.getResource("tech/pegasys/pantheon/util/blockchain-import-genesis-file.json");
assertThat(genesisJsonUrl).isNotNull();
final String genesisJson = Resources.toString(genesisJsonUrl, Charsets.UTF_8);
final KeyPair keyPair = loadKeyPair(target);
Expand All @@ -73,7 +80,7 @@ public void blockImport() throws Exception {
miningParams,
keyPair);
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(target);

Expand Down

0 comments on commit dc2fc72

Please sign in to comment.