Skip to content

Commit 0b5abf5

Browse files
authored
Created validatorTimingChannel entries for sync and contribution messages (#9822)
partially addresses #9761
1 parent 50be3d3 commit 0b5abf5

File tree

14 files changed

+124
-15
lines changed

14 files changed

+124
-15
lines changed

validator/api/src/main/java/tech/pegasys/teku/validator/api/ValidatorTimingChannel.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ void onHeadUpdate(
4141

4242
void onAttestationAggregationDue(UInt64 slot);
4343

44+
void onSyncCommitteeCreationDue(UInt64 slot);
45+
46+
void onContributionCreationDue(UInt64 slot);
47+
4448
void onAttesterSlashing(AttesterSlashing attesterSlashing);
4549

4650
void onProposerSlashing(ProposerSlashing proposerSlashing);

validator/beaconnode/src/main/java/tech/pegasys/teku/validator/beaconnode/TimeBasedEventAdapter.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import tech.pegasys.teku.infrastructure.time.TimeProvider;
2323
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
2424
import tech.pegasys.teku.spec.Spec;
25+
import tech.pegasys.teku.spec.SpecMilestone;
2526
import tech.pegasys.teku.validator.api.ValidatorTimingChannel;
2627

2728
public class TimeBasedEventAdapter implements BeaconChainEventAdapter {
@@ -72,6 +73,16 @@ void start(final UInt64 genesisTime) {
7273
nextSlotStartTimeMillis.plus(spec.getAggregateDueMillis(nextSlot)),
7374
millisPerSlot,
7475
this::onAggregationDue);
76+
if (spec.atSlot(nextSlot).getMilestone().isGreaterThanOrEqualTo(SpecMilestone.ALTAIR)) {
77+
taskScheduler.scheduleRepeatingEventInMillis(
78+
nextSlotStartTimeMillis.plus(spec.getSyncMessageDueMillis(nextSlot)),
79+
millisPerSlot,
80+
this::onSyncCommitteeCreationDue);
81+
taskScheduler.scheduleRepeatingEventInMillis(
82+
nextSlotStartTimeMillis.plus(spec.getContributionDueMillis(nextSlot)),
83+
millisPerSlot,
84+
this::onContributionCreationDue);
85+
}
7586
}
7687

7788
private UInt64 getCurrentSlot() {
@@ -99,6 +110,30 @@ private void onAttestationCreationDue(
99110
validatorTimingChannel.onAttestationCreationDue(slot);
100111
}
101112

113+
private void onSyncCommitteeCreationDue(
114+
final UInt64 scheduledTimeInMillis, final UInt64 actualTimeInMillis) {
115+
final UInt64 slot = spec.getCurrentSlotFromTimeMillis(scheduledTimeInMillis, genesisTimeMillis);
116+
if (isTooLate(scheduledTimeInMillis, actualTimeInMillis)) {
117+
LOG.warn(
118+
"Skipping sync committee message for slot {} due to unexpected delay in slot processing",
119+
slot);
120+
return;
121+
}
122+
validatorTimingChannel.onSyncCommitteeCreationDue(slot);
123+
}
124+
125+
private void onContributionCreationDue(
126+
final UInt64 scheduledTimeInMillis, final UInt64 actualTimeInMillis) {
127+
final UInt64 slot = spec.getCurrentSlotFromTimeMillis(scheduledTimeInMillis, genesisTimeMillis);
128+
if (isTooLate(scheduledTimeInMillis, actualTimeInMillis)) {
129+
LOG.warn(
130+
"Skipping contribution message for slot {} due to unexpected delay in slot processing",
131+
slot);
132+
return;
133+
}
134+
validatorTimingChannel.onContributionCreationDue(slot);
135+
}
136+
102137
private void onAggregationDue(
103138
final UInt64 scheduledTimeInMillis, final UInt64 actualTimeInMillis) {
104139
final UInt64 slot = spec.getCurrentSlotFromTimeMillis(scheduledTimeInMillis, genesisTimeMillis);

validator/client/src/main/java/tech/pegasys/teku/validator/client/AttestationDutyBatchSchedulingStrategy.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ public void onAttestationCreationDue(final UInt64 slot) {}
183183
@Override
184184
public void onAttestationAggregationDue(final UInt64 slot) {}
185185

186+
@Override
187+
public void onSyncCommitteeCreationDue(final UInt64 slot) {}
188+
189+
@Override
190+
public void onContributionCreationDue(final UInt64 slot) {}
191+
186192
@Override
187193
public void onAttesterSlashing(final AttesterSlashing attesterSlashing) {}
188194

validator/client/src/main/java/tech/pegasys/teku/validator/client/AttestationDutyScheduler.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ public void onAttestationCreationDue(final UInt64 slot) {
6868
onProductionDue(slot);
6969
}
7070

71+
@Override
72+
public void onSyncCommitteeCreationDue(final UInt64 slot) {}
73+
74+
@Override
75+
public void onContributionCreationDue(final UInt64 slot) {}
76+
7177
@Override
7278
public void onAttesterSlashing(final AttesterSlashing attesterSlashing) {}
7379

validator/client/src/main/java/tech/pegasys/teku/validator/client/BeaconProposerPreparer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ public void onAttestationCreationDue(final UInt64 slot) {}
9595
@Override
9696
public void onAttestationAggregationDue(final UInt64 slot) {}
9797

98+
@Override
99+
public void onSyncCommitteeCreationDue(final UInt64 slot) {}
100+
101+
@Override
102+
public void onContributionCreationDue(final UInt64 slot) {}
103+
98104
@Override
99105
public void onAttesterSlashing(final AttesterSlashing attesterSlashing) {}
100106

validator/client/src/main/java/tech/pegasys/teku/validator/client/BlockDutyScheduler.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ public void onBlockProductionDue(final UInt64 slot) {
4545
onProductionDue(slot);
4646
}
4747

48+
@Override
49+
public void onSyncCommitteeCreationDue(final UInt64 slot) {}
50+
51+
@Override
52+
public void onContributionCreationDue(final UInt64 slot) {}
53+
4854
@Override
4955
public void onAttesterSlashing(final AttesterSlashing attesterSlashing) {}
5056

validator/client/src/main/java/tech/pegasys/teku/validator/client/OwnedValidatorStatusProvider.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ public void onAttestationCreationDue(final UInt64 slot) {}
133133
@Override
134134
public void onAttestationAggregationDue(final UInt64 slot) {}
135135

136+
@Override
137+
public void onSyncCommitteeCreationDue(final UInt64 slot) {}
138+
139+
@Override
140+
public void onContributionCreationDue(final UInt64 slot) {}
141+
136142
@Override
137143
public void onAttesterSlashing(final AttesterSlashing attesterSlashing) {}
138144

validator/client/src/main/java/tech/pegasys/teku/validator/client/SyncCommitteeScheduler.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private SyncCommitteePeriod createSyncCommitteePeriod(
127127
}
128128

129129
@Override
130-
public void onAttestationCreationDue(final UInt64 slot) {
130+
public void onSyncCommitteeCreationDue(final UInt64 slot) {
131131
// Check slot being null for the edge case of genesis slot (i.e. slot 0)
132132
if (lastProductionSlot != null && slot.compareTo(lastProductionSlot) <= 0) {
133133
LOG.debug(
@@ -142,7 +142,7 @@ public void onAttestationCreationDue(final UInt64 slot) {
142142
}
143143

144144
@Override
145-
public void onAttestationAggregationDue(final UInt64 slot) {
145+
public void onContributionCreationDue(final UInt64 slot) {
146146
getDutiesForSlot(slot).ifPresent(duties -> duties.onAggregationDue(slot));
147147
}
148148

@@ -189,6 +189,12 @@ public void onValidatorsAdded() {
189189
@Override
190190
public void onBlockProductionDue(final UInt64 slot) {}
191191

192+
@Override
193+
public void onAttestationCreationDue(final UInt64 slot) {}
194+
195+
@Override
196+
public void onAttestationAggregationDue(final UInt64 slot) {}
197+
192198
@Override
193199
public void onAttesterSlashing(final AttesterSlashing attesterSlashing) {}
194200

validator/client/src/main/java/tech/pegasys/teku/validator/client/ValidatorRegistrator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ public void onAttestationCreationDue(final UInt64 slot) {}
128128
@Override
129129
public void onAttestationAggregationDue(final UInt64 slot) {}
130130

131+
@Override
132+
public void onSyncCommitteeCreationDue(final UInt64 slot) {}
133+
134+
@Override
135+
public void onContributionCreationDue(final UInt64 slot) {}
136+
131137
@Override
132138
public void onAttesterSlashing(final AttesterSlashing attesterSlashing) {}
133139

validator/client/src/main/java/tech/pegasys/teku/validator/client/ValidatorTimingActions.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ public void onAttestationAggregationDue(final UInt64 slot) {
108108
delegates.forEach(delegates -> delegates.onAttestationAggregationDue(slot));
109109
}
110110

111+
@Override
112+
public void onSyncCommitteeCreationDue(final UInt64 slot) {
113+
delegates.forEach(delegate -> delegate.onSyncCommitteeCreationDue(slot));
114+
}
115+
116+
@Override
117+
public void onContributionCreationDue(final UInt64 slot) {
118+
delegates.forEach(delegate -> delegate.onContributionCreationDue(slot));
119+
}
120+
111121
@Override
112122
public void onAttesterSlashing(final AttesterSlashing attesterSlashing) {
113123
delegates.forEach(delegates -> delegates.onAttesterSlashing(attesterSlashing));

0 commit comments

Comments
 (0)