Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ForkId if there are no Forks and the starting timestamp is not 0 #5819

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading