From 0fb5f2e5059722f799ff3d30641c90508eadc89d Mon Sep 17 00:00:00 2001 From: Meredith Baxter Date: Tue, 13 Aug 2019 13:03:29 -0400 Subject: [PATCH 1/3] Create distinction between mutable / immutable blockchain instances --- .../pantheon/ethereum/ProtocolContext.java | 4 +- ...Blockchain.java => DefaultBlockchain.java} | 47 ++++++- .../core/ExecutionContextTestFixture.java | 4 +- .../core/InMemoryStorageProvider.java | 4 +- ...inTest.java => DefaultBlockchainTest.java} | 122 ++++++++++++++---- .../chain/GenesisBlockMismatchTest.java | 108 ---------------- .../ethereum/worldstate/PrunerTest.java | 21 ++- .../ethereum/retesteth/RetestethContext.java | 12 +- .../retesteth/methods/TestMineBlocks.java | 4 +- 9 files changed, 160 insertions(+), 166 deletions(-) rename ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/{DefaultMutableBlockchain.java => DefaultBlockchain.java} (92%) rename ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/chain/{DefaultMutableBlockchainTest.java => DefaultBlockchainTest.java} (87%) delete mode 100644 ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/chain/GenesisBlockMismatchTest.java diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/ProtocolContext.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/ProtocolContext.java index beaaf95bc3..be71d5a327 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/ProtocolContext.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/ProtocolContext.java @@ -14,7 +14,7 @@ import tech.pegasys.pantheon.ethereum.chain.Blockchain; import tech.pegasys.pantheon.ethereum.chain.BlockchainStorage; -import tech.pegasys.pantheon.ethereum.chain.DefaultMutableBlockchain; +import tech.pegasys.pantheon.ethereum.chain.DefaultBlockchain; import tech.pegasys.pantheon.ethereum.chain.GenesisState; import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; @@ -60,7 +60,7 @@ public static ProtocolContext init( storageProvider.createWorldStatePreimageStorage(); final MutableBlockchain blockchain = - new DefaultMutableBlockchain(genesisState.getBlock(), blockchainStorage, metricsSystem); + DefaultBlockchain.createMutable(genesisState.getBlock(), blockchainStorage, metricsSystem); final WorldStateArchive worldStateArchive = new WorldStateArchive(worldStateStorage, preimageStorage); diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/DefaultMutableBlockchain.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/DefaultBlockchain.java similarity index 92% rename from ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/DefaultMutableBlockchain.java rename to ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/DefaultBlockchain.java index a215c6a358..2b273d9cde 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/DefaultMutableBlockchain.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/DefaultBlockchain.java @@ -42,7 +42,7 @@ import com.google.common.annotations.VisibleForTesting; -public class DefaultMutableBlockchain implements MutableBlockchain { +public class DefaultBlockchain implements MutableBlockchain { protected final BlockchainStorage blockchainStorage; @@ -53,13 +53,16 @@ public class DefaultMutableBlockchain implements MutableBlockchain { private volatile int chainHeadTransactionCount; private volatile int chainHeadOmmerCount; - public DefaultMutableBlockchain( - final Block genesisBlock, + private DefaultBlockchain( + final Optional genesisBlock, final BlockchainStorage blockchainStorage, final MetricsSystem metricsSystem) { checkNotNull(genesisBlock); + checkNotNull(blockchainStorage); + checkNotNull(metricsSystem); + this.blockchainStorage = blockchainStorage; - this.setGenesis(genesisBlock); + genesisBlock.ifPresent(this::setGenesis); final Hash chainHead = blockchainStorage.getChainHead().get(); chainHeader = blockchainStorage.getBlockHeader(chainHead).get(); @@ -112,6 +115,40 @@ public DefaultMutableBlockchain( () -> chainHeadOmmerCount); } + public static DefaultBlockchain createMutable( + final Block genesisBlock, + final BlockchainStorage blockchainStorage, + final MetricsSystem metricsSystem) { + checkNotNull(genesisBlock); + return new DefaultBlockchain(Optional.of(genesisBlock), blockchainStorage, metricsSystem); + } + + public static Blockchain create( + final BlockchainStorage blockchainStorage, final MetricsSystem metricsSystem) { + checkArgument( + validateStorageNonEmpty(blockchainStorage), "Cannot create Blockchain from empty storage"); + return new DefaultBlockchain(Optional.empty(), blockchainStorage, metricsSystem); + } + + private static boolean validateStorageNonEmpty(final BlockchainStorage blockchainStorage) { + // Run a few basic checks to make sure data looks available and consistent + final Optional maybeHead = blockchainStorage.getChainHead(); + if (maybeHead.isEmpty()) { + return false; + } + final Optional genesisHash = + blockchainStorage.getBlockHash(BlockHeader.GENESIS_BLOCK_NUMBER); + if (genesisHash.isEmpty()) { + return false; + } + final Optional td = blockchainStorage.getTotalDifficulty(maybeHead.get()); + if (td.isEmpty()) { + return false; + } + + return true; + } + @Override public ChainHead getChainHead() { return new ChainHead(chainHeader.getHash(), totalDifficulty, chainHeader.getNumber()); @@ -413,7 +450,7 @@ Set getForks() { return new HashSet<>(blockchainStorage.getForkHeads()); } - protected void setGenesis(final Block genesisBlock) { + private void setGenesis(final Block genesisBlock) { checkArgument( genesisBlock.getHeader().getNumber() == BlockHeader.GENESIS_BLOCK_NUMBER, "Invalid genesis block."); diff --git a/ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/ExecutionContextTestFixture.java b/ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/ExecutionContextTestFixture.java index 6b7805880f..d4ce8a7456 100644 --- a/ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/ExecutionContextTestFixture.java +++ b/ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/ExecutionContextTestFixture.java @@ -17,7 +17,7 @@ import tech.pegasys.pantheon.config.GenesisConfigFile; import tech.pegasys.pantheon.config.StubGenesisConfigOptions; import tech.pegasys.pantheon.ethereum.ProtocolContext; -import tech.pegasys.pantheon.ethereum.chain.DefaultMutableBlockchain; +import tech.pegasys.pantheon.ethereum.chain.DefaultBlockchain; import tech.pegasys.pantheon.ethereum.chain.GenesisState; import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHeaderFunctions; @@ -49,7 +49,7 @@ private ExecutionContextTestFixture( this.genesis = genesisState.getBlock(); this.keyValueStorage = keyValueStorage; this.blockchain = - new DefaultMutableBlockchain( + DefaultBlockchain.createMutable( genesis, new KeyValueStoragePrefixedKeyBlockchainStorage( keyValueStorage, new MainnetBlockHeaderFunctions()), diff --git a/ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/InMemoryStorageProvider.java b/ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/InMemoryStorageProvider.java index 5f6b763b1f..09f2b82264 100644 --- a/ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/InMemoryStorageProvider.java +++ b/ethereum/core/src/test-support/java/tech/pegasys/pantheon/ethereum/core/InMemoryStorageProvider.java @@ -13,7 +13,7 @@ package tech.pegasys.pantheon.ethereum.core; import tech.pegasys.pantheon.ethereum.chain.BlockchainStorage; -import tech.pegasys.pantheon.ethereum.chain.DefaultMutableBlockchain; +import tech.pegasys.pantheon.ethereum.chain.DefaultBlockchain; import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHeaderFunctions; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; @@ -43,7 +43,7 @@ public static MutableBlockchain createInMemoryBlockchain(final Block genesisBloc public static MutableBlockchain createInMemoryBlockchain( final Block genesisBlock, final BlockHeaderFunctions blockHeaderFunctions) { final InMemoryKeyValueStorage keyValueStorage = new InMemoryKeyValueStorage(); - return new DefaultMutableBlockchain( + return DefaultBlockchain.createMutable( genesisBlock, new KeyValueStoragePrefixedKeyBlockchainStorage(keyValueStorage, blockHeaderFunctions), new NoOpMetricsSystem()); diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/chain/DefaultMutableBlockchainTest.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/chain/DefaultBlockchainTest.java similarity index 87% rename from ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/chain/DefaultMutableBlockchainTest.java rename to ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/chain/DefaultBlockchainTest.java index 08fd254449..825713152f 100644 --- a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/chain/DefaultMutableBlockchainTest.java +++ b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/chain/DefaultBlockchainTest.java @@ -13,6 +13,7 @@ package tech.pegasys.pantheon.ethereum.chain; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import tech.pegasys.pantheon.ethereum.core.Block; @@ -39,7 +40,7 @@ import org.junit.Test; -public class DefaultMutableBlockchainTest { +public class DefaultBlockchainTest { @Test public void initializeNew() { @@ -47,7 +48,7 @@ public void initializeNew() { final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); final Block genesisBlock = gen.genesisBlock(); - final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); + final DefaultBlockchain blockchain = createMutableBlockchain(kvStore, genesisBlock); assertBlockDataIsStored(blockchain, genesisBlock, Collections.emptyList()); assertBlockIsHead(blockchain, genesisBlock); @@ -62,10 +63,10 @@ public void initializeExisting() { // Write to kv store final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); final Block genesisBlock = gen.genesisBlock(); - createBlockchain(kvStore, genesisBlock); + createMutableBlockchain(kvStore, genesisBlock); // Initialize a new blockchain store with kvStore that already contains data - final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); + final DefaultBlockchain blockchain = createMutableBlockchain(kvStore, genesisBlock); assertBlockDataIsStored(blockchain, genesisBlock, Collections.emptyList()); assertBlockIsHead(blockchain, genesisBlock); @@ -73,17 +74,75 @@ public void initializeExisting() { assertThat(blockchain.getForks()).isEmpty(); } - @Test(expected = IllegalArgumentException.class) + @Test public void initializeExistingWithWrongGenesisBlock() { final BlockDataGenerator gen = new BlockDataGenerator(); // Write to kv store final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); final Block genesisBlock = gen.genesisBlock(); - createBlockchain(kvStore, genesisBlock); + createMutableBlockchain(kvStore, genesisBlock); // Initialize a new blockchain store with same kvStore, but different genesis block - createBlockchain(kvStore, gen.genesisBlock()); + assertThatThrownBy(() -> createMutableBlockchain(kvStore, gen.genesisBlock())) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining( + "Supplied genesis block does not match stored chain data.\n" + + "Please specify a different data directory with --data-path or specify the original genesis file with --genesis-file."); + } + + @Test + public void initializeReadOnly_withGenesisBlock() { + final BlockDataGenerator gen = new BlockDataGenerator(); + final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); + final Block genesisBlock = gen.genesisBlock(); + + // Write genesis block to storage + createMutableBlockchain(kvStore, genesisBlock); + + // Create read only chain + final Blockchain blockchain = createBlockchain(kvStore); + + assertBlockDataIsStored(blockchain, genesisBlock, Collections.emptyList()); + assertBlockIsHead(blockchain, genesisBlock); + assertTotalDifficultiesAreConsistent(blockchain, genesisBlock); + } + + @Test + public void initializeReadOnly_withSmallChain() { + final BlockDataGenerator gen = new BlockDataGenerator(); + final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); + final List blocks = gen.blockSequence(10); + final List> blockReceipts = new ArrayList<>(blocks.size()); + blockReceipts.add(Collections.emptyList()); + + // Write small chain to storage + final MutableBlockchain mutableBlockchain = createMutableBlockchain(kvStore, blocks.get(0)); + for (int i = 1; i < blocks.size(); i++) { + final Block block = blocks.get(i); + final List receipts = gen.receipts(block); + blockReceipts.add(receipts); + mutableBlockchain.appendBlock(block, receipts); + } + + // Create read only chain + final Blockchain blockchain = createBlockchain(kvStore); + + for (int i = 0; i < blocks.size(); i++) { + assertBlockDataIsStored(blockchain, blocks.get(i), blockReceipts.get(i)); + } + final Block lastBlock = blocks.get(blocks.size() - 1); + assertBlockIsHead(blockchain, lastBlock); + assertTotalDifficultiesAreConsistent(blockchain, lastBlock); + } + + @Test + public void initializeReadOnly_emptyStorage() { + final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); + + assertThatThrownBy(() -> createBlockchain(kvStore)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("Cannot create Blockchain from empty BlockchainStorage"); } @Test @@ -92,7 +151,7 @@ public void appendBlock() { final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); final Block genesisBlock = gen.genesisBlock(); - final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); + final DefaultBlockchain blockchain = createMutableBlockchain(kvStore, genesisBlock); final BlockOptions options = new BlockOptions().setBlockNumber(1L).setParentHash(genesisBlock.getHash()); @@ -111,7 +170,7 @@ public void appendUnconnectedBlock() { final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); final Block genesisBlock = gen.genesisBlock(); - final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); + final DefaultBlockchain blockchain = createMutableBlockchain(kvStore, genesisBlock); final BlockOptions options = new BlockOptions().setBlockNumber(1L).setParentHash(Hash.ZERO); final Block newBlock = gen.block(options); @@ -125,7 +184,7 @@ public void appendBlockWithMismatchedReceipts() { final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); final Block genesisBlock = gen.genesisBlock(); - final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); + final DefaultBlockchain blockchain = createMutableBlockchain(kvStore, genesisBlock); final BlockOptions options = new BlockOptions().setBlockNumber(1L).setParentHash(genesisBlock.getHash()); @@ -143,7 +202,7 @@ public void createSmallChain() { chain.stream().map(gen::receipts).collect(Collectors.toList()); final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); - final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, chain.get(0)); + final DefaultBlockchain blockchain = createMutableBlockchain(kvStore, chain.get(0)); for (int i = 1; i < chain.size(); i++) { blockchain.appendBlock(chain.get(i), blockReceipts.get(i)); } @@ -168,7 +227,7 @@ public void appendBlockWithReorgToChainAtEqualHeight() { final List> blockReceipts = chain.stream().map(gen::receipts).collect(Collectors.toList()); final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); - final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, chain.get(0)); + final DefaultBlockchain blockchain = createMutableBlockchain(kvStore, chain.get(0)); for (int i = 1; i < chain.size(); i++) { blockchain.appendBlock(chain.get(i), blockReceipts.get(i)); } @@ -225,7 +284,7 @@ public void appendBlockWithReorgToShorterChain() { final List> blockReceipts = chain.stream().map(gen::receipts).collect(Collectors.toList()); final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); - final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, chain.get(0)); + final DefaultBlockchain blockchain = createMutableBlockchain(kvStore, chain.get(0)); for (int i = 1; i < chain.size(); i++) { blockchain.appendBlock(chain.get(i), blockReceipts.get(i)); } @@ -323,7 +382,7 @@ public void appendBlockWithReorgToLongerChain() { final List> blockReceipts = chain.stream().map(gen::receipts).collect(Collectors.toList()); final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); - final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, chain.get(0)); + final DefaultBlockchain blockchain = createMutableBlockchain(kvStore, chain.get(0)); for (int i = 1; i < chain.size(); i++) { blockchain.appendBlock(chain.get(i), blockReceipts.get(i)); } @@ -412,7 +471,7 @@ public void reorgWithOverlappingTransactions() { final List> blockReceipts = chain.stream().map(gen::receipts).collect(Collectors.toList()); final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); - final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, chain.get(0)); + final DefaultBlockchain blockchain = createMutableBlockchain(kvStore, chain.get(0)); for (int i = 1; i < chain.size(); i++) { blockchain.appendBlock(chain.get(i), blockReceipts.get(i)); } @@ -465,7 +524,7 @@ public void rewindChain() { final List> blockReceipts = chain.stream().map(gen::receipts).collect(Collectors.toList()); final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); - final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, chain.get(0)); + final DefaultBlockchain blockchain = createMutableBlockchain(kvStore, chain.get(0)); for (int i = 1; i < chain.size(); i++) { blockchain.appendBlock(chain.get(i), blockReceipts.get(i)); } @@ -503,7 +562,7 @@ public void appendBlockForFork() { final List> blockReceipts = chain.stream().map(gen::receipts).collect(Collectors.toList()); final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); - final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, chain.get(0)); + final DefaultBlockchain blockchain = createMutableBlockchain(kvStore, chain.get(0)); for (int i = 1; i < chain.size(); i++) { blockchain.appendBlock(chain.get(i), blockReceipts.get(i)); } @@ -580,7 +639,7 @@ public void blockAddedObserver_removeNonexistentObserver() { final BlockDataGenerator gen = new BlockDataGenerator(); final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); final Block genesisBlock = gen.genesisBlock(); - final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); + final DefaultBlockchain blockchain = createMutableBlockchain(kvStore, genesisBlock); assertThat(blockchain.removeObserver(7)).isFalse(); } @@ -591,7 +650,7 @@ public void blockAddedObserver_addRemoveSingle() { final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); final Block genesisBlock = gen.genesisBlock(); - final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); + final DefaultBlockchain blockchain = createMutableBlockchain(kvStore, genesisBlock); final long observerId = blockchain.observeBlockAdded((block, chain) -> {}); assertThat(blockchain.observerCount()).isEqualTo(1); @@ -606,7 +665,7 @@ public void blockAddedObserver_nullObserver() { final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); final Block genesisBlock = gen.genesisBlock(); - final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); + final DefaultBlockchain blockchain = createMutableBlockchain(kvStore, genesisBlock); blockchain.observeBlockAdded(null); } @@ -617,7 +676,7 @@ public void blockAddedObserver_addRemoveMultiple() { final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); final Block genesisBlock = gen.genesisBlock(); - final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); + final DefaultBlockchain blockchain = createMutableBlockchain(kvStore, genesisBlock); final long observerId1 = blockchain.observeBlockAdded((block, chain) -> {}); assertThat(blockchain.observerCount()).isEqualTo(1); @@ -644,7 +703,7 @@ public void blockAddedObserver_invokedSingle() { final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); final Block genesisBlock = gen.genesisBlock(); - final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); + final DefaultBlockchain blockchain = createMutableBlockchain(kvStore, genesisBlock); final BlockOptions options = new BlockOptions().setBlockNumber(1L).setParentHash(genesisBlock.getHash()); @@ -665,7 +724,7 @@ public void blockAddedObserver_invokedMultiple() { final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); final Block genesisBlock = gen.genesisBlock(); - final DefaultMutableBlockchain blockchain = createBlockchain(kvStore, genesisBlock); + final DefaultBlockchain blockchain = createMutableBlockchain(kvStore, genesisBlock); final BlockOptions options = new BlockOptions().setBlockNumber(1L).setParentHash(genesisBlock.getHash()); @@ -734,11 +793,18 @@ private void assertTotalDifficultiesAreConsistent(final Blockchain blockchain, f assertEquals(td, blockchain.getChainHead().getTotalDifficulty()); } - private DefaultMutableBlockchain createBlockchain( + private BlockchainStorage createStorage(final KeyValueStorage kvStore) { + return new KeyValueStoragePrefixedKeyBlockchainStorage( + kvStore, new MainnetBlockHeaderFunctions()); + } + + private DefaultBlockchain createMutableBlockchain( final KeyValueStorage kvStore, final Block genesisBlock) { - return new DefaultMutableBlockchain( - genesisBlock, - new KeyValueStoragePrefixedKeyBlockchainStorage(kvStore, new MainnetBlockHeaderFunctions()), - new NoOpMetricsSystem()); + return DefaultBlockchain.createMutable( + genesisBlock, createStorage(kvStore), new NoOpMetricsSystem()); + } + + private Blockchain createBlockchain(final KeyValueStorage kvStore) { + return DefaultBlockchain.create(createStorage(kvStore), new NoOpMetricsSystem()); } } diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/chain/GenesisBlockMismatchTest.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/chain/GenesisBlockMismatchTest.java deleted file mode 100644 index dec49ea10e..0000000000 --- a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/chain/GenesisBlockMismatchTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2018 ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package tech.pegasys.pantheon.ethereum.chain; - -import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType; - -import tech.pegasys.pantheon.crypto.SecureRandomProvider; -import tech.pegasys.pantheon.ethereum.core.Address; -import tech.pegasys.pantheon.ethereum.core.Block; -import tech.pegasys.pantheon.ethereum.core.BlockBody; -import tech.pegasys.pantheon.ethereum.core.BlockHeader; -import tech.pegasys.pantheon.ethereum.core.BlockHeaderBuilder; -import tech.pegasys.pantheon.ethereum.core.Hash; -import tech.pegasys.pantheon.ethereum.core.LogsBloomFilter; -import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockHeaderFunctions; -import tech.pegasys.pantheon.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage; -import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; -import tech.pegasys.pantheon.services.kvstore.InMemoryKeyValueStorage; -import tech.pegasys.pantheon.services.kvstore.KeyValueStorage; -import tech.pegasys.pantheon.util.InvalidConfigurationException; -import tech.pegasys.pantheon.util.bytes.Bytes32; -import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.uint.UInt256; - -import java.security.SecureRandom; -import java.util.Collections; - -import org.junit.Test; - -public class GenesisBlockMismatchTest { - private static final SecureRandom srand = SecureRandomProvider.publicSecureRandom(); - - private static byte[] bytes(final int len) { - final byte[] bytes = new byte[len]; - srand.nextBytes(bytes); - return bytes; - } - - @Test - public void suppliedGenesisBlockMismatchStoredChainDataException() { - final KeyValueStorage kvStore = new InMemoryKeyValueStorage(); - final BlockHeader genesisHeader00 = - BlockHeaderBuilder.create() - .parentHash(Hash.ZERO) - .ommersHash(Hash.ZERO) - .coinbase(Address.fromHexString("0x0000000000000000000000000000000000000000")) - .stateRoot(Hash.ZERO) - .transactionsRoot(Hash.ZERO) - .receiptsRoot(Hash.ZERO) - .logsBloom(new LogsBloomFilter(BytesValue.of(bytes(LogsBloomFilter.BYTE_SIZE)))) - .difficulty(UInt256.ZERO) - .number(0L) - .gasLimit(1L) - .gasUsed(1L) - .timestamp(0L) - .extraData(Bytes32.wrap(bytes(Bytes32.SIZE))) - .mixHash(Hash.ZERO) - .nonce(0L) - .blockHeaderFunctions(new MainnetBlockHeaderFunctions()) - .buildBlockHeader(); - final BlockBody genesisBody00 = new BlockBody(Collections.emptyList(), Collections.emptyList()); - final Block genesisBlock00 = new Block(genesisHeader00, genesisBody00); - final DefaultMutableBlockchain blockchain00 = - new DefaultMutableBlockchain( - genesisBlock00, - new KeyValueStoragePrefixedKeyBlockchainStorage( - kvStore, new MainnetBlockHeaderFunctions()), - new NoOpMetricsSystem()); - - final BlockHeader genesisHeader01 = - BlockHeaderBuilder.create() - .parentHash(Hash.ZERO) - .ommersHash(Hash.ZERO) - .coinbase(Address.fromHexString("0x0000000000000000000000000000000000000000")) - .stateRoot(Hash.ZERO) - .transactionsRoot(Hash.ZERO) - .receiptsRoot(Hash.ZERO) - .logsBloom(new LogsBloomFilter(BytesValue.of(bytes(LogsBloomFilter.BYTE_SIZE)))) - .difficulty(UInt256.ZERO) - .number(0L) - .gasLimit(1L) - .gasUsed(1L) - .timestamp(0L) - .extraData(Bytes32.wrap(bytes(Bytes32.SIZE))) - .mixHash(Hash.ZERO) - .nonce(0L) - .blockHeaderFunctions(new MainnetBlockHeaderFunctions()) - .buildBlockHeader(); - final BlockBody genesisBody01 = new BlockBody(Collections.emptyList(), Collections.emptyList()); - final Block genesisBlock01 = new Block(genesisHeader01, genesisBody01); - - assertThatExceptionOfType(InvalidConfigurationException.class) - .isThrownBy(() -> blockchain00.setGenesis(genesisBlock01)) - .withMessageContaining( - "Supplied genesis block does not match stored chain data.\n" - + "Please specify a different data directory with --data-path or specify the original genesis file with --genesis-file."); - } -} diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/worldstate/PrunerTest.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/worldstate/PrunerTest.java index bdd9d87dc6..1b8e73f8f2 100644 --- a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/worldstate/PrunerTest.java +++ b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/worldstate/PrunerTest.java @@ -19,7 +19,7 @@ import tech.pegasys.pantheon.ethereum.chain.Blockchain; import tech.pegasys.pantheon.ethereum.chain.BlockchainStorage; -import tech.pegasys.pantheon.ethereum.chain.DefaultMutableBlockchain; +import tech.pegasys.pantheon.ethereum.chain.DefaultBlockchain; import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.BlockDataGenerator; import tech.pegasys.pantheon.ethereum.core.BlockDataGenerator.BlockOptions; @@ -56,8 +56,8 @@ public void shouldMarkCorrectBlockAndSweep() throws InterruptedException { final BlockchainStorage blockchainStorage = new KeyValueStoragePrefixedKeyBlockchainStorage( new InMemoryKeyValueStorage(), new MainnetBlockHeaderFunctions()); - final DefaultMutableBlockchain blockchain = - new DefaultMutableBlockchain(genesisBlock, blockchainStorage, metricsSystem); + final DefaultBlockchain blockchain = + DefaultBlockchain.createMutable(genesisBlock, blockchainStorage, metricsSystem); final Pruner pruner = new Pruner(markSweepPruner, blockchain, mockExecutorService, 0, 0); pruner.start(); @@ -77,8 +77,8 @@ public void shouldOnlySweepAfterTransientForkPeriodAndRetentionPeriodEnds() final BlockchainStorage blockchainStorage = new KeyValueStoragePrefixedKeyBlockchainStorage( new InMemoryKeyValueStorage(), new MainnetBlockHeaderFunctions()); - final DefaultMutableBlockchain blockchain = - new DefaultMutableBlockchain(genesisBlock, blockchainStorage, metricsSystem); + final DefaultBlockchain blockchain = + DefaultBlockchain.createMutable(genesisBlock, blockchainStorage, metricsSystem); final Pruner pruner = new Pruner(markSweepPruner, blockchain, mockExecutorService, 1, 2); pruner.start(); @@ -103,8 +103,8 @@ public void abortsPruningWhenFullyMarkedBlockNoLongerOnCanonicalChain() final BlockchainStorage blockchainStorage = new KeyValueStoragePrefixedKeyBlockchainStorage( new InMemoryKeyValueStorage(), new MainnetBlockHeaderFunctions()); - final DefaultMutableBlockchain blockchain = - new DefaultMutableBlockchain(genesisBlock, blockchainStorage, metricsSystem); + final DefaultBlockchain blockchain = + DefaultBlockchain.createMutable(genesisBlock, blockchainStorage, metricsSystem); // start pruner so it can start handling block added events final Pruner pruner = new Pruner(markSweepPruner, blockchain, mockExecutorService, 0, 1); @@ -150,8 +150,8 @@ public void shouldCleanUpPruningStrategyOnShutdown() throws InterruptedException final BlockchainStorage blockchainStorage = new KeyValueStoragePrefixedKeyBlockchainStorage( new InMemoryKeyValueStorage(), new MainnetBlockHeaderFunctions()); - final DefaultMutableBlockchain blockchain = - new DefaultMutableBlockchain(genesisBlock, blockchainStorage, metricsSystem); + final DefaultBlockchain blockchain = + DefaultBlockchain.createMutable(genesisBlock, blockchainStorage, metricsSystem); final Pruner pruner = new Pruner(markSweepPruner, blockchain, mockExecutorService, 0, 0); pruner.start(); @@ -159,8 +159,7 @@ public void shouldCleanUpPruningStrategyOnShutdown() throws InterruptedException verify(markSweepPruner).cleanup(); } - private Block appendBlockWithParent( - final DefaultMutableBlockchain blockchain, final Block parent) { + private Block appendBlockWithParent(final DefaultBlockchain blockchain, final Block parent) { BlockOptions options = new BlockOptions() .setBlockNumber(parent.getHeader().getNumber() + 1) diff --git a/ethereum/retesteth/src/main/java/tech/pegasys/pantheon/ethereum/retesteth/RetestethContext.java b/ethereum/retesteth/src/main/java/tech/pegasys/pantheon/ethereum/retesteth/RetestethContext.java index 7a7bd916bf..56488e628c 100644 --- a/ethereum/retesteth/src/main/java/tech/pegasys/pantheon/ethereum/retesteth/RetestethContext.java +++ b/ethereum/retesteth/src/main/java/tech/pegasys/pantheon/ethereum/retesteth/RetestethContext.java @@ -18,7 +18,7 @@ import tech.pegasys.pantheon.config.JsonUtil; import tech.pegasys.pantheon.ethereum.ProtocolContext; import tech.pegasys.pantheon.ethereum.blockcreation.IncrementingNonceGenerator; -import tech.pegasys.pantheon.ethereum.chain.DefaultMutableBlockchain; +import tech.pegasys.pantheon.ethereum.chain.DefaultBlockchain; import tech.pegasys.pantheon.ethereum.chain.GenesisState; import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.Block; @@ -67,7 +67,7 @@ public class RetestethContext { private final ReentrantLock contextLock = new ReentrantLock(); private Address coinbase; - private DefaultMutableBlockchain blockchain; + private DefaultBlockchain blockchain; private ProtocolContext protocolContext; private BlockchainQueries blockchainQueries; private ProtocolSchedule protocolSchedule; @@ -181,14 +181,14 @@ private boolean buildContext( return true; } - private static DefaultMutableBlockchain createInMemoryBlockchain(final Block genesisBlock) { + private static DefaultBlockchain createInMemoryBlockchain(final Block genesisBlock) { return createInMemoryBlockchain(genesisBlock, new MainnetBlockHeaderFunctions()); } - private static DefaultMutableBlockchain createInMemoryBlockchain( + private static DefaultBlockchain createInMemoryBlockchain( final Block genesisBlock, final BlockHeaderFunctions blockHeaderFunctions) { final InMemoryKeyValueStorage keyValueStorage = new InMemoryKeyValueStorage(); - return new DefaultMutableBlockchain( + return DefaultBlockchain.createMutable( genesisBlock, new KeyValueStoragePrefixedKeyBlockchainStorage(keyValueStorage, blockHeaderFunctions), new NoOpMetricsSystem()); @@ -238,7 +238,7 @@ public Address getCoinbase() { return coinbase; } - public DefaultMutableBlockchain getBlockchain() { + public DefaultBlockchain getBlockchain() { return blockchain; } diff --git a/ethereum/retesteth/src/main/java/tech/pegasys/pantheon/ethereum/retesteth/methods/TestMineBlocks.java b/ethereum/retesteth/src/main/java/tech/pegasys/pantheon/ethereum/retesteth/methods/TestMineBlocks.java index 162e27a71b..09d4015374 100644 --- a/ethereum/retesteth/src/main/java/tech/pegasys/pantheon/ethereum/retesteth/methods/TestMineBlocks.java +++ b/ethereum/retesteth/src/main/java/tech/pegasys/pantheon/ethereum/retesteth/methods/TestMineBlocks.java @@ -14,7 +14,7 @@ import tech.pegasys.pantheon.ethereum.ProtocolContext; import tech.pegasys.pantheon.ethereum.blockcreation.EthHashBlockCreator; -import tech.pegasys.pantheon.ethereum.chain.DefaultMutableBlockchain; +import tech.pegasys.pantheon.ethereum.chain.DefaultBlockchain; import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.BlockImporter; import tech.pegasys.pantheon.ethereum.core.Wei; @@ -61,7 +61,7 @@ private boolean mineNewBlock() { final RetestethClock retesethClock = context.getRetestethClock(); final ProtocolSchedule protocolSchedule = context.getProtocolSchedule(); final ProtocolContext protocolContext = context.getProtocolContext(); - final DefaultMutableBlockchain blockchain = context.getBlockchain(); + final DefaultBlockchain blockchain = context.getBlockchain(); final HeaderValidationMode headerValidationMode = context.getHeaderValidationMode(); final EthHashBlockCreator blockCreator = new EthHashBlockCreator( From 9a6c0d2ef5a707d1ca673b8724d9367224481cf7 Mon Sep 17 00:00:00 2001 From: Meredith Baxter Date: Tue, 13 Aug 2019 13:14:13 -0400 Subject: [PATCH 2/3] Use interfaces rather than concrete class for variable declarations --- .../pantheon/ethereum/chain/DefaultBlockchain.java | 3 ++- .../pantheon/ethereum/chain/MutableBlockchain.java | 9 +++++++++ .../ethereum/chain/DefaultBlockchainTest.java | 5 +++-- .../pantheon/ethereum/worldstate/PrunerTest.java | 11 ++++++----- .../pantheon/ethereum/retesteth/RetestethContext.java | 9 +++++---- .../ethereum/retesteth/methods/TestMineBlocks.java | 4 ++-- 6 files changed, 27 insertions(+), 14 deletions(-) diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/DefaultBlockchain.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/DefaultBlockchain.java index 2b273d9cde..6c2ce8f6ee 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/DefaultBlockchain.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/DefaultBlockchain.java @@ -115,7 +115,7 @@ private DefaultBlockchain( () -> chainHeadOmmerCount); } - public static DefaultBlockchain createMutable( + public static MutableBlockchain createMutable( final Block genesisBlock, final BlockchainStorage blockchainStorage, final MetricsSystem metricsSystem) { @@ -396,6 +396,7 @@ private BlockAddedEvent handleChainReorg( removedTransactions); } + @Override public boolean rewindToBlock(final long blockNumber) { final Optional blockHash = blockchainStorage.getBlockHash(blockNumber); if (blockHash.isEmpty()) { diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/MutableBlockchain.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/MutableBlockchain.java index 67fe79672e..d3986fa38c 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/MutableBlockchain.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/chain/MutableBlockchain.java @@ -30,4 +30,13 @@ public interface MutableBlockchain extends Blockchain { * @param receipts The list of receipts associated with this block's transactions. */ void appendBlock(Block block, List receipts); + + /** + * Rolls back the canonical chainhead to the specified block number. + * + * @param blockNumber The block number to roll back to. + * @return {@code true} on success, {@code false} if the canonical chain height is less than + * {@code blockNumber} + */ + boolean rewindToBlock(final long blockNumber); } diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/chain/DefaultBlockchainTest.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/chain/DefaultBlockchainTest.java index 825713152f..40b1782769 100644 --- a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/chain/DefaultBlockchainTest.java +++ b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/chain/DefaultBlockchainTest.java @@ -800,8 +800,9 @@ private BlockchainStorage createStorage(final KeyValueStorage kvStore) { private DefaultBlockchain createMutableBlockchain( final KeyValueStorage kvStore, final Block genesisBlock) { - return DefaultBlockchain.createMutable( - genesisBlock, createStorage(kvStore), new NoOpMetricsSystem()); + return (DefaultBlockchain) + DefaultBlockchain.createMutable( + genesisBlock, createStorage(kvStore), new NoOpMetricsSystem()); } private Blockchain createBlockchain(final KeyValueStorage kvStore) { diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/worldstate/PrunerTest.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/worldstate/PrunerTest.java index 1b8e73f8f2..44936d79ec 100644 --- a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/worldstate/PrunerTest.java +++ b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/worldstate/PrunerTest.java @@ -20,6 +20,7 @@ import tech.pegasys.pantheon.ethereum.chain.Blockchain; import tech.pegasys.pantheon.ethereum.chain.BlockchainStorage; import tech.pegasys.pantheon.ethereum.chain.DefaultBlockchain; +import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.BlockDataGenerator; import tech.pegasys.pantheon.ethereum.core.BlockDataGenerator.BlockOptions; @@ -56,7 +57,7 @@ public void shouldMarkCorrectBlockAndSweep() throws InterruptedException { final BlockchainStorage blockchainStorage = new KeyValueStoragePrefixedKeyBlockchainStorage( new InMemoryKeyValueStorage(), new MainnetBlockHeaderFunctions()); - final DefaultBlockchain blockchain = + final MutableBlockchain blockchain = DefaultBlockchain.createMutable(genesisBlock, blockchainStorage, metricsSystem); final Pruner pruner = new Pruner(markSweepPruner, blockchain, mockExecutorService, 0, 0); @@ -77,7 +78,7 @@ public void shouldOnlySweepAfterTransientForkPeriodAndRetentionPeriodEnds() final BlockchainStorage blockchainStorage = new KeyValueStoragePrefixedKeyBlockchainStorage( new InMemoryKeyValueStorage(), new MainnetBlockHeaderFunctions()); - final DefaultBlockchain blockchain = + final MutableBlockchain blockchain = DefaultBlockchain.createMutable(genesisBlock, blockchainStorage, metricsSystem); final Pruner pruner = new Pruner(markSweepPruner, blockchain, mockExecutorService, 1, 2); @@ -103,7 +104,7 @@ public void abortsPruningWhenFullyMarkedBlockNoLongerOnCanonicalChain() final BlockchainStorage blockchainStorage = new KeyValueStoragePrefixedKeyBlockchainStorage( new InMemoryKeyValueStorage(), new MainnetBlockHeaderFunctions()); - final DefaultBlockchain blockchain = + final MutableBlockchain blockchain = DefaultBlockchain.createMutable(genesisBlock, blockchainStorage, metricsSystem); // start pruner so it can start handling block added events @@ -150,7 +151,7 @@ public void shouldCleanUpPruningStrategyOnShutdown() throws InterruptedException final BlockchainStorage blockchainStorage = new KeyValueStoragePrefixedKeyBlockchainStorage( new InMemoryKeyValueStorage(), new MainnetBlockHeaderFunctions()); - final DefaultBlockchain blockchain = + final MutableBlockchain blockchain = DefaultBlockchain.createMutable(genesisBlock, blockchainStorage, metricsSystem); final Pruner pruner = new Pruner(markSweepPruner, blockchain, mockExecutorService, 0, 0); @@ -159,7 +160,7 @@ public void shouldCleanUpPruningStrategyOnShutdown() throws InterruptedException verify(markSweepPruner).cleanup(); } - private Block appendBlockWithParent(final DefaultBlockchain blockchain, final Block parent) { + private Block appendBlockWithParent(final MutableBlockchain blockchain, final Block parent) { BlockOptions options = new BlockOptions() .setBlockNumber(parent.getHeader().getNumber() + 1) diff --git a/ethereum/retesteth/src/main/java/tech/pegasys/pantheon/ethereum/retesteth/RetestethContext.java b/ethereum/retesteth/src/main/java/tech/pegasys/pantheon/ethereum/retesteth/RetestethContext.java index 56488e628c..fbd4ce6e82 100644 --- a/ethereum/retesteth/src/main/java/tech/pegasys/pantheon/ethereum/retesteth/RetestethContext.java +++ b/ethereum/retesteth/src/main/java/tech/pegasys/pantheon/ethereum/retesteth/RetestethContext.java @@ -20,6 +20,7 @@ import tech.pegasys.pantheon.ethereum.blockcreation.IncrementingNonceGenerator; import tech.pegasys.pantheon.ethereum.chain.DefaultBlockchain; import tech.pegasys.pantheon.ethereum.chain.GenesisState; +import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.BlockHeader; @@ -67,7 +68,7 @@ public class RetestethContext { private final ReentrantLock contextLock = new ReentrantLock(); private Address coinbase; - private DefaultBlockchain blockchain; + private MutableBlockchain blockchain; private ProtocolContext protocolContext; private BlockchainQueries blockchainQueries; private ProtocolSchedule protocolSchedule; @@ -181,11 +182,11 @@ private boolean buildContext( return true; } - private static DefaultBlockchain createInMemoryBlockchain(final Block genesisBlock) { + private static MutableBlockchain createInMemoryBlockchain(final Block genesisBlock) { return createInMemoryBlockchain(genesisBlock, new MainnetBlockHeaderFunctions()); } - private static DefaultBlockchain createInMemoryBlockchain( + private static MutableBlockchain createInMemoryBlockchain( final Block genesisBlock, final BlockHeaderFunctions blockHeaderFunctions) { final InMemoryKeyValueStorage keyValueStorage = new InMemoryKeyValueStorage(); return DefaultBlockchain.createMutable( @@ -238,7 +239,7 @@ public Address getCoinbase() { return coinbase; } - public DefaultBlockchain getBlockchain() { + public MutableBlockchain getBlockchain() { return blockchain; } diff --git a/ethereum/retesteth/src/main/java/tech/pegasys/pantheon/ethereum/retesteth/methods/TestMineBlocks.java b/ethereum/retesteth/src/main/java/tech/pegasys/pantheon/ethereum/retesteth/methods/TestMineBlocks.java index 09d4015374..502f070b03 100644 --- a/ethereum/retesteth/src/main/java/tech/pegasys/pantheon/ethereum/retesteth/methods/TestMineBlocks.java +++ b/ethereum/retesteth/src/main/java/tech/pegasys/pantheon/ethereum/retesteth/methods/TestMineBlocks.java @@ -14,7 +14,7 @@ import tech.pegasys.pantheon.ethereum.ProtocolContext; import tech.pegasys.pantheon.ethereum.blockcreation.EthHashBlockCreator; -import tech.pegasys.pantheon.ethereum.chain.DefaultBlockchain; +import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.BlockImporter; import tech.pegasys.pantheon.ethereum.core.Wei; @@ -61,7 +61,7 @@ private boolean mineNewBlock() { final RetestethClock retesethClock = context.getRetestethClock(); final ProtocolSchedule protocolSchedule = context.getProtocolSchedule(); final ProtocolContext protocolContext = context.getProtocolContext(); - final DefaultBlockchain blockchain = context.getBlockchain(); + final MutableBlockchain blockchain = context.getBlockchain(); final HeaderValidationMode headerValidationMode = context.getHeaderValidationMode(); final EthHashBlockCreator blockCreator = new EthHashBlockCreator( From 12234bb9ae640e845fb997f9d64a55004c5e9f3c Mon Sep 17 00:00:00 2001 From: Meredith Baxter Date: Tue, 13 Aug 2019 13:47:12 -0400 Subject: [PATCH 3/3] Fix error message --- .../pegasys/pantheon/ethereum/chain/DefaultBlockchainTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/chain/DefaultBlockchainTest.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/chain/DefaultBlockchainTest.java index 40b1782769..854547a841 100644 --- a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/chain/DefaultBlockchainTest.java +++ b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/chain/DefaultBlockchainTest.java @@ -142,7 +142,7 @@ public void initializeReadOnly_emptyStorage() { assertThatThrownBy(() -> createBlockchain(kvStore)) .isInstanceOf(IllegalArgumentException.class) - .hasMessageContaining("Cannot create Blockchain from empty BlockchainStorage"); + .hasMessageContaining("Cannot create Blockchain from empty storage"); } @Test