Skip to content

Commit

Permalink
fix ForkId if there are no Forks and the starting timestamp is not 0 (#…
Browse files Browse the repository at this point in the history
…5819)

Signed-off-by: Stefan <[email protected]>
  • Loading branch information
pinges authored Aug 29, 2023
1 parent ee0fa6b commit c16a327
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class ForkIdManager {

private final Supplier<BlockHeader> chainHeadSupplier;
private final long forkNext;
private final boolean onlyZerosForkBlocks;
private final boolean noForksAvailable;
private final long highestKnownFork;
private Bytes genesisHashCrc;
private final boolean legacyEth64;
Expand Down Expand Up @@ -77,11 +77,11 @@ public ForkIdManager(
final List<Long> allForkNumbers =
Stream.concat(blockNumberForks.stream(), timestampForks.stream())
.collect(Collectors.toList());
this.onlyZerosForkBlocks = allForkNumbers.stream().allMatch(value -> 0L == value);
this.forkNext = createForkIds();
this.allForkIds =
Stream.concat(blockNumbersForkIds.stream(), timestampsForkIds.stream())
.collect(Collectors.toList());
this.noForksAvailable = allForkIds.isEmpty();
this.highestKnownFork =
!allForkNumbers.isEmpty() ? allForkNumbers.get(allForkNumbers.size() - 1) : 0L;
}
Expand Down Expand Up @@ -128,7 +128,7 @@ public static ForkId readFrom(final RLPInput in) {
* @return boolean (peer valid (true) or invalid (false))
*/
public boolean peerCheck(final ForkId forkId) {
if (forkId == null || onlyZerosForkBlocks) {
if (forkId == null || noForksAvailable) {
return true; // Another method must be used to validate (i.e. genesis hash)
}
// Run the fork checksum validation rule set:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,4 +619,18 @@ public void testGenesisTimestampEqualToShanghaiTimestamp() {
assertThat(forkIdManager.getAllForkIds().get(0).getNext()).isEqualTo(2L);
assertThat(forkIdManager.getAllForkIds().get(1).getNext()).isEqualTo(0L);
}

@Test
public void testNoBlockNoForksAndNoTimestampForksGreaterThanGenesisTimestamp() {
final ForkIdManager forkIdManager =
new ForkIdManager(
mockBlockchain(Hash.ZERO.toHexString(), 10L, 1L),
Collections.emptyList(),
List.of(1L),
false);
assertThat(forkIdManager.getAllForkIds().size()).isEqualTo(0);
// There is no ForkId, so peerCheck always has to return true
assertThat(forkIdManager.peerCheck(new ForkId(Bytes.fromHexString("0xdeadbeef"), 100L)))
.isEqualTo(true);
}
}

0 comments on commit c16a327

Please sign in to comment.