Skip to content

Commit

Permalink
remove TTD depth limit for ancestorIsValidTerminalProofOfWork (#3728)
Browse files Browse the repository at this point in the history
Signed-off-by: garyschulte <garyschulte@gmail.com>
  • Loading branch information
garyschulte authored Apr 13, 2022
1 parent ae6c368 commit 6c8602d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,11 @@ public boolean latestValidAncestorDescendsFromTerminal(final BlockHeader blockHe
}
}

// 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
Expand All @@ -382,16 +380,12 @@ boolean ancestorIsValidTerminalProofOfWork(final BlockHeader blockheader) {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,16 +405,6 @@ public void assertCachedUnfinalizedAncestorDescendsFromTTD() {
.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;
Expand Down

0 comments on commit 6c8602d

Please sign in to comment.