diff --git a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java index 3c9fecde267..5d876b6ae32 100644 --- a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java +++ b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java @@ -248,119 +248,6 @@ public void updateForkChoiceShouldPersistLastFinalizedBlockHash() { verify(mergeContext).setSafeBlock(lastFinalizedHeader); } - @Test - public void updateForkChoiceShouldFailIfLastFinalizedNotDescendantOfPreviousFinalized() { - BlockHeader terminalHeader = terminalPowBlock(); - coordinator.executeBlock(new Block(terminalHeader, BlockBody.empty())); - - BlockHeader prevFinalizedHeader = nextBlockHeader(terminalHeader); - Block prevFinalizedBlock = new Block(prevFinalizedHeader, BlockBody.empty()); - coordinator.executeBlock(prevFinalizedBlock); - - when(mergeContext.getFinalized()).thenReturn(Optional.of(prevFinalizedHeader)); - - // not descendant of previous finalized block - BlockHeader lastFinalizedHeader = disjointBlockHeader(prevFinalizedHeader); - Block lastFinalizedBlock = new Block(lastFinalizedHeader, BlockBody.empty()); - coordinator.executeBlock(lastFinalizedBlock); - - BlockHeader headBlockHeader = nextBlockHeader(lastFinalizedHeader); - Block headBlock = new Block(headBlockHeader, BlockBody.empty()); - coordinator.executeBlock(headBlock); - when(blockchain.getBlockHeader(lastFinalizedBlock.getHash())) - .thenReturn(Optional.of(lastFinalizedHeader)); - when(blockchain.getBlockHeader(headBlockHeader.getHash())) - .thenReturn(Optional.of(headBlockHeader)); - var res = - coordinator.updateForkChoice( - headBlockHeader, - lastFinalizedBlock.getHash(), - lastFinalizedBlock.getHash(), - Optional.empty()); - assertThat(res.isValid()).isFalse(); - assertThat(res.getStatus()).isEqualTo(ForkchoiceResult.Status.INVALID); - - verify(blockchain, never()).setFinalized(lastFinalizedBlock.getHash()); - verify(mergeContext, never()).setFinalized(lastFinalizedHeader); - verify(blockchain, never()).setSafeBlock(lastFinalizedBlock.getHash()); - verify(mergeContext, never()).setSafeBlock(lastFinalizedHeader); - } - - @Test - public void updateForkChoiceShouldFailIfHeadNotDescendantOfLastFinalized() { - BlockHeader terminalHeader = terminalPowBlock(); - coordinator.executeBlock(new Block(terminalHeader, BlockBody.empty())); - - BlockHeader prevFinalizedHeader = nextBlockHeader(terminalHeader); - Block prevFinalizedBlock = new Block(prevFinalizedHeader, BlockBody.empty()); - coordinator.executeBlock(prevFinalizedBlock); - - when(mergeContext.getFinalized()).thenReturn(Optional.of(prevFinalizedHeader)); - - BlockHeader lastFinalizedHeader = nextBlockHeader(prevFinalizedHeader); - Block lastFinalizedBlock = new Block(lastFinalizedHeader, BlockBody.empty()); - coordinator.executeBlock(lastFinalizedBlock); - - // not descendant of last finalized block - BlockHeader headBlockHeader = disjointBlockHeader(lastFinalizedHeader); - Block headBlock = new Block(headBlockHeader, BlockBody.empty()); - coordinator.executeBlock(headBlock); - when(blockchain.getBlockHeader(lastFinalizedBlock.getHash())) - .thenReturn(Optional.of(lastFinalizedHeader)); - when(blockchain.getBlockHeader(headBlockHeader.getHash())) - .thenReturn(Optional.of(headBlockHeader)); - var res = - coordinator.updateForkChoice( - headBlockHeader, - lastFinalizedBlock.getHash(), - lastFinalizedBlock.getHash(), - Optional.empty()); - assertThat(res.isValid()).isFalse(); - assertThat(res.getStatus()).isEqualTo(ForkchoiceResult.Status.INVALID); - - verify(blockchain, never()).setFinalized(lastFinalizedBlock.getHash()); - verify(mergeContext, never()).setFinalized(lastFinalizedHeader); - verify(blockchain, never()).setSafeBlock(lastFinalizedBlock.getHash()); - verify(mergeContext, never()).setSafeBlock(lastFinalizedHeader); - } - - @Test - public void updateForkChoiceShouldFailIfFinalizedBlockNotFound() { - BlockHeader terminalHeader = terminalPowBlock(); - coordinator.executeBlock(new Block(terminalHeader, BlockBody.empty())); - - BlockHeader prevFinalizedHeader = nextBlockHeader(terminalHeader); - Block prevFinalizedBlock = new Block(prevFinalizedHeader, BlockBody.empty()); - coordinator.executeBlock(prevFinalizedBlock); - - when(mergeContext.getFinalized()).thenReturn(Optional.of(prevFinalizedHeader)); - - BlockHeader lastFinalizedHeader = nextBlockHeader(prevFinalizedHeader); - Block lastFinalizedBlock = new Block(lastFinalizedHeader, BlockBody.empty()); - // note this block is not executed, so not known by us - - BlockHeader headBlockHeader = nextBlockHeader(lastFinalizedHeader); - Block headBlock = new Block(headBlockHeader, BlockBody.empty()); - coordinator.executeBlock(headBlock); - when(blockchain.getBlockHeader(lastFinalizedBlock.getHash())).thenReturn(Optional.empty()); - when(blockchain.getBlockHeader(headBlockHeader.getHash())) - .thenReturn(Optional.of(headBlockHeader)) - .thenReturn(Optional.of(headBlockHeader)); - var res = - coordinator.updateForkChoice( - headBlockHeader, - lastFinalizedBlock.getHash(), - lastFinalizedBlock.getHash(), - Optional.empty()); - assertThat(res.isValid()).isFalse(); - assertThat(res.getStatus()).isEqualTo(ForkchoiceResult.Status.INVALID); - - verify(blockchain, never()).setFinalized(lastFinalizedBlock.getHash()); - verify(mergeContext, never()).setFinalized(lastFinalizedHeader); - verify(blockchain, never()).setSafeBlock(lastFinalizedBlock.getHash()); - verify(mergeContext, never()).setSafeBlock(lastFinalizedHeader); - } - @Test public void assertGetOrSyncForBlockAlreadyPresent() { BlockHeader mockHeader = @@ -615,24 +502,6 @@ private BlockHeader nextBlockHeader( .buildHeader(); } - private BlockHeader disjointBlockHeader(final BlockHeader disjointFromHeader) { - Hash disjointParentHash = Hash.wrap(disjointFromHeader.getParentHash().shiftRight(1)); - - return headerGenerator - .difficulty(Difficulty.ZERO) - .parentHash(disjointParentHash) - .gasLimit(genesisState.getBlock().getHeader().getGasLimit()) - .number(disjointFromHeader.getNumber() + 1) - .stateRoot(genesisState.getBlock().getHeader().getStateRoot()) - .baseFeePerGas( - feeMarket.computeBaseFee( - genesisState.getBlock().getHeader().getNumber() + 1, - disjointFromHeader.getBaseFee().orElse(Wei.of(0x3b9aca00)), - 0, - 15000000l)) - .buildHeader(); - } - MergeCoordinator terminalAncestorMock(final long chainDepth, final boolean hasTerminalPoW) { final Difficulty mockTTD = Difficulty.of(1000); BlockHeaderTestFixture builder = new BlockHeaderTestFixture().baseFeePerGas(Wei.ONE); diff --git a/gradle.properties b/gradle.properties index 49708e60e7a..6d8557c519f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=22.4.3 +version=22.4.4-SNAPSHOT # Workaround for Java 16 and spotless bug 834 https://github.com/diffplug/spotless/issues/834 org.gradle.jvmargs=--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \