Skip to content

Commit

Permalink
Fix missing Gossip subnet subscription on startup (#8730)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nashatyrev authored Oct 16, 2024
1 parent 398be12 commit f5790a5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ private synchronized void stopGossip() {

@Override
public void onSyncStateChanged(final boolean isInSync, final boolean isOptimistic) {
gossipForkManager.onOptimisticHeadChanged(isOptimistic);

if (state.get() != State.RUNNING) {
return;
}
Expand All @@ -176,7 +178,6 @@ public void onSyncStateChanged(final boolean isInSync, final boolean isOptimisti
} else {
stopGossip();
}
gossipForkManager.onOptimisticHeadChanged(isOptimistic);
}

@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class GossipForkManager {
private final IntSet currentSyncCommitteeSubnets = new IntOpenHashSet();

private Optional<UInt64> currentEpoch = Optional.empty();
private boolean isHeadOptimistic;

private GossipForkManager(
final Spec spec,
Expand All @@ -71,6 +72,7 @@ private GossipForkManager(
this.spec = spec;
this.recentChainData = recentChainData;
this.forksByActivationEpoch = forksByActivationEpoch;
this.isHeadOptimistic = recentChainData.isChainHeadOptimistic();
}

public static GossipForkManager.Builder builder() {
Expand Down Expand Up @@ -141,6 +143,7 @@ public synchronized void stopGossip() {
}

public synchronized void onOptimisticHeadChanged(final boolean isHeadOptimistic) {
this.isHeadOptimistic = isHeadOptimistic;
if (isHeadOptimistic) {
activeSubscriptions.forEach(GossipForkSubscriptions::stopGossipForOptimisticSync);
} else {
Expand Down Expand Up @@ -279,7 +282,7 @@ private void startSubscriptions(final GossipForkSubscriptions subscription) {
if (activeSubscriptions.add(subscription)) {
subscription.startGossip(
recentChainData.getGenesisData().orElseThrow().getGenesisValidatorsRoot(),
recentChainData.isChainHeadOptimistic());
isHeadOptimistic);
currentAttestationSubnets.forEach(subscription::subscribeToAttestationSubnetId);
currentSyncCommitteeSubnets.forEach(subscription::subscribeToSyncCommitteeSubnet);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,19 @@ void shouldStartSubscriptionsInOptimisticSyncMode() {
verify(subscriptions).startGossip(GENESIS_VALIDATORS_ROOT, true);
}

@Test
void shouldStartSubscriptionsInNonOptimisticSyncModeWhenSyncStateChangedBeforeStart() {
when(recentChainData.isChainHeadOptimistic()).thenReturn(true);

final GossipForkSubscriptions subscriptions = forkAtEpoch(0);
final GossipForkManager manager = managerForForks(subscriptions);

manager.onOptimisticHeadChanged(false);
manager.configureGossipForEpoch(UInt64.ZERO);

verify(subscriptions).startGossip(GENESIS_VALIDATORS_ROOT, false);
}

private GossipForkSubscriptions forkAtEpoch(final long epoch) {
final GossipForkSubscriptions subscriptions =
mock(GossipForkSubscriptions.class, "subscriptionsForEpoch" + epoch);
Expand Down

0 comments on commit f5790a5

Please sign in to comment.