remove TTD depth limit for ancestorIsValidTerminalProofOfWork (#3728)

Signed-off-by: garyschulte <garyschulte@gmail.com>
pull/3638/head
garyschulte 3 years ago committed by GitHub
parent ae6c368d53
commit 6c8602d435
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java
  2. 10
      consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinatorTest.java

@ -362,13 +362,11 @@ public class MergeCoordinator implements MergeMiningCoordinator {
}
}
// TODO: post-merge cleanup
static final long MAX_TTD_SEARCH_DEPTH = 131072L; // 32 * 4096 epochs
// package visibility for testing
boolean ancestorIsValidTerminalProofOfWork(final BlockHeader blockheader) {
// this should only happen very close to the transition from PoW to PoS, prior to a finalized
// block
// block. For example, after a full sync of an already-merged chain which does not have
// terminal block info in the genesis config.
// check a 'cached' block which was determined to descend from terminal to short circuit
// in the case of a long period of non-finality
@ -382,16 +380,12 @@ public class MergeCoordinator implements MergeMiningCoordinator {
var blockchain = protocolContext.getBlockchain();
Optional<BlockHeader> parent = blockchain.getBlockHeader(blockheader.getParentHash());
do {
LOG.debug(
"checking ancestor {} is valid terminal PoW for {}",
parent.map(BlockHeader::toLogString).orElse("empty"),
blockheader.toLogString());
if (parent.isPresent()) {
if (MAX_TTD_SEARCH_DEPTH < blockheader.getNumber() - parent.get().getNumber()) {
return false;
}
if (!parent.get().getDifficulty().equals(Difficulty.ZERO)) {
break;
}

@ -405,16 +405,6 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
.isTrue();
}
@Test
public void ancestorExceedsDepthValidTerminalProofOfWork() {
final long howDeep = MergeCoordinator.MAX_TTD_SEARCH_DEPTH + 2;
assertThat(
terminalAncestorMock(howDeep, true)
.ancestorIsValidTerminalProofOfWork(
new BlockHeaderTestFixture().number(howDeep).buildHeader()))
.isFalse();
}
@Test
public void ancestorNotFoundValidTerminalProofOfWork() {
final long howDeep = 10L;

Loading…
Cancel
Save