Skip to content

Commit

Permalink
pinned sync
Browse files Browse the repository at this point in the history
  • Loading branch information
tbenr committed Feb 25, 2025
1 parent 1c8ea27 commit 6c34ebd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class MultipeerCommonAncestorFinder {
private final EventThread eventThread;
private final Spec spec;

private static Optional<UInt64> PINNED_HOLESKY_SYNC_SLOT = Optional.of(UInt64.valueOf(3712224));

@VisibleForTesting
MultipeerCommonAncestorFinder(
final RecentChainData recentChainData,
Expand All @@ -48,7 +50,10 @@ public class MultipeerCommonAncestorFinder {
public static MultipeerCommonAncestorFinder create(
final RecentChainData recentChainData, final EventThread eventThread, final Spec spec) {
return new MultipeerCommonAncestorFinder(
recentChainData, new CommonAncestor(recentChainData), eventThread, spec);
recentChainData,
new CommonAncestor(recentChainData, PINNED_HOLESKY_SYNC_SLOT),
eventThread,
spec);
}

public SafeFuture<UInt64> findCommonAncestor(final TargetChain targetChain) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,28 @@ public class CommonAncestor {
private final RecentChainData recentChainData;
private final int maxAttempts;

public CommonAncestor(final RecentChainData recentChainData) {
this(recentChainData, DEFAULT_MAX_ATTEMPTS);
private final Optional<UInt64> pinnedCommonAncestorSlot;

public CommonAncestor(final RecentChainData recentChainData, final Optional<UInt64> pinnedSlot) {
this(recentChainData, DEFAULT_MAX_ATTEMPTS, pinnedSlot);
}

@VisibleForTesting
CommonAncestor(final RecentChainData recentChainData, final int maxAttempts) {
CommonAncestor(
final RecentChainData recentChainData,
final int maxAttempts,
final Optional<UInt64> pinnedSlot) {
this.recentChainData = recentChainData;
this.maxAttempts = maxAttempts;
this.pinnedCommonAncestorSlot = pinnedSlot;
}

public SafeFuture<UInt64> getCommonAncestor(
final SyncSource peer, final UInt64 firstNonFinalSlot, final UInt64 peerHeadSlot) {
if (pinnedCommonAncestorSlot.isPresent()) {
return getCommonAncestorFromPinned(peer);
}

final UInt64 ourHeadSlot = recentChainData.getHeadSlot();
final UInt64 lowestHeadSlot = ourHeadSlot.min(peerHeadSlot);

Expand Down Expand Up @@ -106,6 +116,25 @@ private SafeFuture<UInt64> getCommonAncestor(
attempt + 1)));
}

private SafeFuture<UInt64> getCommonAncestorFromPinned(final SyncSource peer) {
if (pinnedCommonAncestorSlot.isEmpty()) {
return SafeFuture.failedFuture(new IllegalStateException("No pinned common ancestor"));
}
final UInt64 pinnedSlot = pinnedCommonAncestorSlot.get();
final UInt64 ourHeadSlot = recentChainData.getHeadSlot();
final UInt64 lowestHeadSlot = ourHeadSlot.min(pinnedSlot);

final UInt64 localNonFinalisedSlotCount = lowestHeadSlot.minusMinZero(pinnedSlot);

LOG.debug(
"Local head slot {}. Have {} non finalized slots, pinned slot is {}",
ourHeadSlot,
localNonFinalisedSlotCount,
pinnedSlot);

return getCommonAncestor(peer, pinnedSlot, pinnedSlot, maxAttempts - 1);
}

private static class BestBlockListener implements RpcResponseListener<SignedBeaconBlock> {
private final RecentChainData recentChainData;
private Optional<UInt64> bestSlot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private SafeFuture<PeerSyncResult> executeSync(
if (!findCommonAncestor) {
return SafeFuture.completedFuture(startSlot);
}
CommonAncestor ancestor = new CommonAncestor(recentChainData);
CommonAncestor ancestor = new CommonAncestor(recentChainData, Optional.empty());
return ancestor.getCommonAncestor(peer, startSlot, status.getHeadSlot());
})
.thenCompose(
Expand Down

0 comments on commit 6c34ebd

Please sign in to comment.