Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
zilm13 committed Aug 17, 2023
1 parent 654de6f commit 1918917
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,16 @@ public synchronized void subscribeToCommitteeForAggregation(
final UInt64 unsubscribeSlot = currentUnsubscriptionSlot.max(aggregationSlot);
if (currentUnsubscriptionSlot.equals(ZERO)) {
eth2P2PNetwork.subscribeToAttestationSubnetId(subnetId);
subnetSubscriptionsGauge.set(1, String.format(GAUGE_AGGREGATION_SUBNETS_LABEL, subnetId));
toggleAggregateSubscriptionMetric(subnetId, false);
LOG.trace(
"Subscribing to aggregation subnet {} with unsubscribe due at slot {}",
subnetId,
unsubscribeSlot);
} else {
if (aggregationSlot.isGreaterThan(currentUnsubscriptionSlot)
&& persistentSubnetIdSet.contains(subnetId)) {
subnetSubscriptionsGauge.set(0, String.format(GAUGE_PERSISTENT_SUBNETS_LABEL, subnetId));
toggleAggregateSubscriptionMetric(subnetId, true);
persistentSubnetIdSet.remove(subnetId);
subnetSubscriptionsGauge.set(1, String.format(GAUGE_AGGREGATION_SUBNETS_LABEL, subnetId));
}
LOG.trace(
"Already subscribed to aggregation subnet {}, updating unsubscription slot to {}",
Expand All @@ -78,6 +77,20 @@ public synchronized void subscribeToCommitteeForAggregation(
subnetIdToUnsubscribeSlot.put(subnetId, unsubscribeSlot);
}

private void togglePersistentSubscriptionMetric(final int subnetId, final boolean reset) {
subnetSubscriptionsGauge.set(1, String.format(GAUGE_PERSISTENT_SUBNETS_LABEL, subnetId));
if (reset) {
subnetSubscriptionsGauge.set(0, String.format(GAUGE_AGGREGATION_SUBNETS_LABEL, subnetId));
}
}

private void toggleAggregateSubscriptionMetric(final int subnetId, final boolean reset) {
subnetSubscriptionsGauge.set(1, String.format(GAUGE_AGGREGATION_SUBNETS_LABEL, subnetId));
if (reset) {
subnetSubscriptionsGauge.set(0, String.format(GAUGE_PERSISTENT_SUBNETS_LABEL, subnetId));
}
}

public synchronized void subscribeToPersistentSubnets(
final Set<SubnetSubscription> newSubscriptions) {
boolean shouldUpdateENR = false;
Expand All @@ -97,12 +110,11 @@ public synchronized void subscribeToPersistentSubnets(
"Already subscribed to subnet {}, updating unsubscription slot to {}",
subnetId,
unsubscriptionSlot);
subnetSubscriptionsGauge.set(0, String.format(GAUGE_AGGREGATION_SUBNETS_LABEL, subnetId));
subnetSubscriptionsGauge.set(1, String.format(GAUGE_PERSISTENT_SUBNETS_LABEL, subnetId));
togglePersistentSubscriptionMetric(subnetId, true);
subnetIdToUnsubscribeSlot.put(subnetId, unsubscriptionSlot);
} else {
eth2P2PNetwork.subscribeToAttestationSubnetId(subnetId);
subnetSubscriptionsGauge.set(1, String.format(GAUGE_PERSISTENT_SUBNETS_LABEL, subnetId));
togglePersistentSubscriptionMetric(subnetId, false);
LOG.trace("Subscribed to new persistent subnet {}", subnetId);
subnetIdToUnsubscribeSlot.put(subnetId, subnetSubscription.getUnsubscriptionSlot());
}
Expand Down

0 comments on commit 1918917

Please sign in to comment.