private void verifyChainHeadIs(final Block forkBlock2) { assertThat(blockchain.getChainHeadHash()).isEqualTo(forkBlock2.getHash()); }
private BlockHeader getHeaderForCurrentChainHead() { return blockchain.getBlockHeader(blockchain.getChainHeadHash()).get(); }
@Test public void locallyGeneratedBlockInvalidatesMiningEvenIfInTurn() { // Note also - validators is an hard-ordered LIST, thus in-turn will follow said list - block_1 // should be created by Proposer, and thus will be in-turn. final CliqueMiningCoordinator coordinator = new CliqueMiningCoordinator(blockChain, minerExecutor, syncState, miningTracker); coordinator.enable(); verify(minerExecutor, times(1)).startAsyncMining(any(), any()); reset(minerExecutor); when(minerExecutor.startAsyncMining(any(), any())).thenReturn(blockMiner); final Block importedBlock = createEmptyBlock(1, blockChain.getChainHeadHash(), proposerKeys); blockChain.appendBlock(importedBlock, Lists.emptyList()); // The minerExecutor should not be invoked as the mining operation was conducted by an in-turn // validator, and the created block came from an out-turn validator. ArgumentCaptor<BlockHeader> varArgs = ArgumentCaptor.forClass(BlockHeader.class); verify(minerExecutor, times(1)).startAsyncMining(any(), varArgs.capture()); assertThat(varArgs.getValue()).isEqualTo(blockChain.getChainHeadHeader()); }
@Test public void outOfTurnBlockImportedAtHigherLevelInterruptsMiningOperation() { // As the head of the blockChain is 1 (which effectively doesn't have a signer, all validators // are able to propose. when(blockMiner.getParentHeader()).thenReturn(blockChain.getChainHeadHeader()); // Note also - validators is an hard-ordered LIST, thus in-turn will follow said list - block_1 // should be created by proposer. final CliqueMiningCoordinator coordinator = new CliqueMiningCoordinator(blockChain, minerExecutor, syncState, miningTracker); coordinator.enable(); verify(minerExecutor, times(1)).startAsyncMining(any(), any()); reset(minerExecutor); when(minerExecutor.startAsyncMining(any(), any())).thenReturn(blockMiner); final Block importedBlock = createEmptyBlock(2, blockChain.getChainHeadHash(), validatorKeys); blockChain.appendBlock(importedBlock, Lists.emptyList()); // The minerExecutor should not be invoked as the mining operation was conducted by an in-turn // validator, and the created block came from an out-turn validator. ArgumentCaptor<BlockHeader> varArgs = ArgumentCaptor.forClass(BlockHeader.class); verify(minerExecutor, times(1)).startAsyncMining(any(), varArgs.capture()); assertThat(varArgs.getValue()).isEqualTo(blockChain.getChainHeadHeader()); }
@Test public void outOfTurnBlockImportedDoesNotInterruptInTurnMiningOperation() { // As the head of the blockChain is 0 (which effectively doesn't have a signer, all validators // are able to propose. when(blockMiner.getParentHeader()).thenReturn(blockChain.getChainHeadHeader()); // Note also - validators is an hard-ordered LIST, thus in-turn will follow said list - block_1 // should be created by proposer. final CliqueMiningCoordinator coordinator = new CliqueMiningCoordinator(blockChain, minerExecutor, syncState, miningTracker); coordinator.enable(); verify(minerExecutor, times(1)).startAsyncMining(any(), any()); reset(minerExecutor); final Block importedBlock = createEmptyBlock(1, blockChain.getChainHeadHash(), validatorKeys); blockChain.appendBlock(importedBlock, Lists.emptyList()); // The minerExecutor should not be invoked as the mining operation was conducted by an in-turn // validator, and the created block came from an out-turn validator. verify(minerExecutor, never()).startAsyncMining(any(), any()); }
@Test public void outOfTurnBlockImportedInterruptsOutOfTurnMiningOperation() { blockChain.appendBlock( createEmptyBlock(1, blockChain.getChainHeadHash(), validatorKeys), Lists.emptyList()); when(blockMiner.getParentHeader()).thenReturn(blockChain.getChainHeadHeader()); // Note also - validators is an hard-ordered LIST, thus in-turn will follow said list - block_2 // should be created by 'validator', thus Proposer is out-of-turn. final CliqueMiningCoordinator coordinator = new CliqueMiningCoordinator(blockChain, minerExecutor, syncState, miningTracker); coordinator.enable(); verify(minerExecutor, times(1)).startAsyncMining(any(), any()); reset(minerExecutor); when(minerExecutor.startAsyncMining(any(), any())).thenReturn(blockMiner); final Block importedBlock = createEmptyBlock(2, blockChain.getChainHeadHash(), validatorKeys); blockChain.appendBlock(importedBlock, Lists.emptyList()); // The minerExecutor should not be invoked as the mining operation was conducted by an in-turn // validator, and the created block came from an out-turn validator. ArgumentCaptor<BlockHeader> varArgs = ArgumentCaptor.forClass(BlockHeader.class); verify(minerExecutor, times(1)).startAsyncMining(any(), varArgs.capture()); assertThat(varArgs.getValue()).isEqualTo(blockChain.getChainHeadHeader()); }
@Test public void outOfTurnBlockImportedInterruptsNonRunningMiner() { blockChain.appendBlock( createEmptyBlock(1, blockChain.getChainHeadHash(), proposerKeys), Lists.emptyList()); when(blockMiner.getParentHeader()).thenReturn(blockChain.getChainHeadHeader()); // Note also - validators is an hard-ordered LIST, thus in-turn will follow said list - block_2 // should be created by 'validator', thus Proposer is out-of-turn. final CliqueMiningCoordinator coordinator = new CliqueMiningCoordinator(blockChain, minerExecutor, syncState, miningTracker); coordinator.enable(); verify(minerExecutor, times(1)).startAsyncMining(any(), any()); reset(minerExecutor); when(minerExecutor.startAsyncMining(any(), any())).thenReturn(blockMiner); final Block importedBlock = createEmptyBlock(2, blockChain.getChainHeadHash(), validatorKeys); blockChain.appendBlock(importedBlock, Lists.emptyList()); // The minerExecutor should not be invoked as the mining operation was conducted by an in-turn // validator, and the created block came from an out-turn validator. ArgumentCaptor<BlockHeader> varArgs = ArgumentCaptor.forClass(BlockHeader.class); verify(minerExecutor, times(1)).startAsyncMining(any(), varArgs.capture()); assertThat(varArgs.getValue()).isEqualTo(blockChain.getChainHeadHeader()); }
1, blockchain.getChainHead().getTotalDifficulty(), blockchain.getChainHeadHash(), blockchain.getBlockHeader(BlockHeader.GENESIS_BLOCK_NUMBER).get().getHash());
when(blockchain.getChainHeadHash()).thenReturn(parentHeader.getHash()); when(blockchain.getBlockHeader(any())).thenReturn(optionalHeader);
when(blockchain.getChainHeadHash()).thenReturn(parentHeader.getHash()); when(blockchain.getBlockHeader(any())).thenReturn(optionalHeader);
assertThat(blockchain.getChainHeadHash()).isEqualTo(spec.getLastBlockHash());