-
Notifications
You must be signed in to change notification settings - Fork 357
Don't subscribe in AttestationTopicSubscriber if subscription is outdated #8837
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| import it.unimi.dsi.fastutil.ints.IntSet; | ||
| import java.util.Iterator; | ||
| import java.util.Set; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import tech.pegasys.teku.ethereum.events.SlotEventsChannel; | ||
|
|
@@ -39,6 +40,7 @@ public class AttestationTopicSubscriber implements SlotEventsChannel { | |
| private final Eth2P2PNetwork eth2P2PNetwork; | ||
| private final Spec spec; | ||
| private final SettableLabelledGauge subnetSubscriptionsGauge; | ||
| private final AtomicReference<UInt64> lastSlot = new AtomicReference<>(null); | ||
|
|
||
| public AttestationTopicSubscriber( | ||
| final Spec spec, | ||
|
|
@@ -56,6 +58,14 @@ public synchronized void subscribeToCommitteeForAggregation( | |
| aggregationSlot, UInt64.valueOf(committeeIndex), committeesAtSlot); | ||
| final UInt64 currentUnsubscriptionSlot = subnetIdToUnsubscribeSlot.getOrDefault(subnetId, ZERO); | ||
| final UInt64 unsubscribeSlot = currentUnsubscriptionSlot.max(aggregationSlot); | ||
| if (lastSlot.get() != null && unsubscribeSlot.isLessThan(lastSlot.get())) { | ||
|
||
| LOG.trace( | ||
| "Skipping outdated aggregation subnet {} with unsubscribe due at slot {}", | ||
| subnetId, | ||
| unsubscribeSlot); | ||
| return; | ||
| } | ||
|
|
||
| if (currentUnsubscriptionSlot.equals(ZERO)) { | ||
| eth2P2PNetwork.subscribeToAttestationSubnetId(subnetId); | ||
| toggleAggregateSubscriptionMetric(subnetId, false); | ||
|
|
@@ -97,6 +107,15 @@ public synchronized void subscribeToPersistentSubnets( | |
|
|
||
| for (SubnetSubscription subnetSubscription : newSubscriptions) { | ||
| int subnetId = subnetSubscription.subnetId(); | ||
|
||
| if (lastSlot.get() != null | ||
| && subnetSubscription.unsubscriptionSlot().isLessThan(lastSlot.get())) { | ||
|
||
| LOG.trace( | ||
| "Skipping outdated persistent subnet {} with unsubscribe due at slot {}", | ||
| subnetId, | ||
| subnetSubscription.unsubscriptionSlot()); | ||
| continue; | ||
| } | ||
|
|
||
| shouldUpdateENR = persistentSubnetIdSet.add(subnetId) || shouldUpdateENR; | ||
| LOG.trace( | ||
| "Subscribing to persistent subnet {} with unsubscribe due at slot {}", | ||
|
|
@@ -127,6 +146,7 @@ public synchronized void subscribeToPersistentSubnets( | |
|
|
||
| @Override | ||
| public synchronized void onSlot(final UInt64 slot) { | ||
| lastSlot.set(slot); | ||
| boolean shouldUpdateENR = false; | ||
|
|
||
| final Iterator<Int2ObjectMap.Entry<UInt64>> iterator = | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is probably better called
currentSlot?