@lodestar/validator 1.50.0-dev.fef46df5ba → 1.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/lib/services/block.d.ts.map +1 -1
  2. package/lib/services/block.js +14 -3
  3. package/lib/services/block.js.map +1 -1
  4. package/lib/services/prepareBeaconProposer.d.ts +2 -1
  5. package/lib/services/prepareBeaconProposer.d.ts.map +1 -1
  6. package/lib/services/prepareBeaconProposer.js +5 -1
  7. package/lib/services/prepareBeaconProposer.js.map +1 -1
  8. package/lib/services/proposalPreferences.d.ts +47 -0
  9. package/lib/services/proposalPreferences.d.ts.map +1 -0
  10. package/lib/services/proposalPreferences.js +260 -0
  11. package/lib/services/proposalPreferences.js.map +1 -0
  12. package/lib/services/ptc.d.ts.map +1 -1
  13. package/lib/services/ptc.js +11 -2
  14. package/lib/services/ptc.js.map +1 -1
  15. package/lib/services/ptcDuties.js +2 -2
  16. package/lib/services/ptcDuties.js.map +1 -1
  17. package/lib/services/validatorStore.d.ts.map +1 -1
  18. package/lib/services/validatorStore.js +4 -9
  19. package/lib/services/validatorStore.js.map +1 -1
  20. package/lib/validator.d.ts.map +1 -1
  21. package/lib/validator.js +2 -4
  22. package/lib/validator.js.map +1 -1
  23. package/package.json +13 -13
  24. package/src/services/block.ts +18 -4
  25. package/src/services/prepareBeaconProposer.ts +5 -1
  26. package/src/services/proposalPreferences.ts +308 -0
  27. package/src/services/ptc.ts +12 -3
  28. package/src/services/ptcDuties.ts +2 -2
  29. package/src/services/validatorStore.ts +4 -8
  30. package/src/validator.ts +11 -4
  31. package/lib/services/builderPreferences.d.ts +0 -27
  32. package/lib/services/builderPreferences.d.ts.map +0 -1
  33. package/lib/services/builderPreferences.js +0 -127
  34. package/lib/services/builderPreferences.js.map +0 -1
  35. package/lib/services/proposerPreferences.d.ts +0 -31
  36. package/lib/services/proposerPreferences.d.ts.map +0 -1
  37. package/lib/services/proposerPreferences.js +0 -130
  38. package/lib/services/proposerPreferences.js.map +0 -1
  39. package/src/services/builderPreferences.ts +0 -142
  40. package/src/services/proposerPreferences.ts +0 -154
@@ -0,0 +1,308 @@
1
+ import {ApiClient, ApiError, routes} from "@lodestar/api";
2
+ import {ChainForkConfig} from "@lodestar/config";
3
+ import {SLOTS_PER_EPOCH, isForkPostGloas} from "@lodestar/params";
4
+ import {IClock, computeEpochAtSlot} from "@lodestar/state-transition";
5
+ import {Epoch, RootHex, Slot, gloas} from "@lodestar/types";
6
+ import {fromHex, toPubkeyHex} from "@lodestar/utils";
7
+ import {Metrics} from "../metrics.js";
8
+ import {LoggerVc} from "../util/index.js";
9
+ import {BlockDutiesService} from "./blockDuties.js";
10
+ import {SyncingStatusTracker} from "./syncingStatusTracker.js";
11
+ import {ValidatorStore} from "./validatorStore.js";
12
+
13
+ /**
14
+ * Submit the preferences of a proposal this many slots before the proposal slot.
15
+ *
16
+ * Earlier submission means more reorg-triggered resubmits (and gossip flood); later
17
+ * submission risks missing the bid-auction window for this proposal slot. The bid for
18
+ * slot S typically arrives at slot S-1, so we want preferences propagated to the network
19
+ * and consumed by builders before then. SLOTS_PER_EPOCH / 4 (8 slots @ 32 SPE, ~96s @ 12s
20
+ * slots) gives ample margin while bounding redundant resubmits.
21
+ */
22
+ const SUBMIT_BEFORE_PROPOSAL_SLOTS = Math.floor(SLOTS_PER_EPOCH / 4);
23
+
24
+ /** Per-epoch tracking of preferences already submitted under the current dependent_root. */
25
+ type SubmittedAtEpoch = {dependentRoot: RootHex; proposerSlots: Set<Slot>; builderSlots: Set<Slot>};
26
+ type PendingSubmission = {submission: SubmittedAtEpoch; slot: Slot};
27
+ /** A local proposal within the submission window along with the tracking of its epoch */
28
+ type UpcomingProposal = {duty: routes.validator.ProposerDuty; submission: SubmittedAtEpoch};
29
+
30
+ /**
31
+ * Signs and submits the preferences of local proposals within the next `SUBMIT_BEFORE_PROPOSAL_SLOTS`:
32
+ * the `SignedProposerPreferences` the beacon node broadcasts on gossip and the builder preferences
33
+ * it forwards to the builders configured for the validator. Signing the builder request auths here
34
+ * also pre-fills the auth cache used at proposal time.
35
+ *
36
+ * Re-submits automatically when the proposer dependent root for an epoch shifts (e.g. after a reorg)
37
+ * since the proposer for a slot may have changed. Detected by comparing the cached `dependentRoot`
38
+ * reported by `BlockDutiesService` against the one we last submitted under.
39
+ *
40
+ * Proposers should broadcast their preferences before the fork so the proposer preference caches
41
+ * of beacon nodes and builders are warm for the first Gloas slots. We start submitting
42
+ * as soon as a duty's proposal slot is in Gloas, which is up to `SUBMIT_BEFORE_PROPOSAL_SLOTS`
43
+ * before the fork, so only the first few Gloas slots are affected by this pre-fork submission.
44
+ */
45
+ export class ProposalPreferencesService {
46
+ private readonly submitted = new Map<Epoch, SubmittedAtEpoch>();
47
+ private activeScheduledGasLimit: number | undefined;
48
+
49
+ constructor(
50
+ private readonly config: ChainForkConfig,
51
+ private readonly logger: LoggerVc,
52
+ private readonly api: ApiClient,
53
+ clock: IClock,
54
+ private readonly validatorStore: ValidatorStore,
55
+ private readonly blockDutiesService: BlockDutiesService,
56
+ syncingStatusTracker: SyncingStatusTracker,
57
+ _metrics: Metrics | null
58
+ ) {
59
+ clock.runEverySlot(this.runPreferencesTask);
60
+ clock.runEveryEpoch(this.runEveryEpochTask);
61
+ syncingStatusTracker.runOnResynced(this.onResynced);
62
+ }
63
+
64
+ /**
65
+ * A beacon node that was unreachable or syncing may have restarted and lost the preferences it
66
+ * accepted, it keeps them in memory only. Submit everything within the window again, the beacon
67
+ * node ignores preferences it still has.
68
+ */
69
+ private onResynced = async (slot: Slot): Promise<void> => {
70
+ if (this.submitted.size === 0) {
71
+ return;
72
+ }
73
+
74
+ this.logger.verbose("Beacon node resynced; resubmitting preferences", {slot});
75
+ this.submitted.clear();
76
+ await this.runPreferencesTask(slot);
77
+ };
78
+
79
+ private runPreferencesTask = async (slot: Slot): Promise<void> => {
80
+ // Start running once the submission window (`slot + SUBMIT_BEFORE_PROPOSAL_SLOTS`) reaches
81
+ // Gloas, i.e. already in the epoch before the fork. This allows builders to prepare and
82
+ // submit bids for the first Gloas slots.
83
+ if (!isForkPostGloas(this.config.getForkName(slot + SUBMIT_BEFORE_PROPOSAL_SLOTS))) {
84
+ return;
85
+ }
86
+
87
+ const proposals = this.getUpcomingProposals(slot);
88
+ if (proposals.length === 0) {
89
+ return;
90
+ }
91
+
92
+ // Signed and submitted independently, a slow signer for one must not delay the other
93
+ await Promise.all([
94
+ this.submitProposerPreferences(proposals, slot),
95
+ this.submitBuilderPreferences(proposals, slot),
96
+ ]);
97
+ };
98
+
99
+ private runEveryEpochTask = async (epoch: Epoch): Promise<void> => {
100
+ const scheduledGasLimit = this.config.getScheduledGasLimit(epoch);
101
+ if (scheduledGasLimit !== undefined && scheduledGasLimit !== this.activeScheduledGasLimit) {
102
+ const configuredDefaultGasLimit = this.validatorStore.getConfiguredDefaultGasLimit();
103
+ this.logger.info("Gas limit schedule active", {
104
+ epoch,
105
+ recommendedGasLimit: scheduledGasLimit,
106
+ effectiveDefaultGasLimit: configuredDefaultGasLimit ?? scheduledGasLimit,
107
+ defaultGasLimitSource: configuredDefaultGasLimit === undefined ? "schedule" : "operator",
108
+ });
109
+ this.activeScheduledGasLimit = scheduledGasLimit;
110
+ }
111
+
112
+ // Drop tracking for past epochs; only currentEpoch and currentEpoch + 1 are ever processed.
113
+ for (const trackedEpoch of this.submitted.keys()) {
114
+ if (trackedEpoch < epoch) {
115
+ this.submitted.delete(trackedEpoch);
116
+ }
117
+ }
118
+ };
119
+
120
+ /** Resets the tracking of `epoch` if the dependent root shifted, previously submitted preferences are stale. */
121
+ private getSubmissionAtEpoch(epoch: Epoch, dependentRoot: RootHex): SubmittedAtEpoch {
122
+ let submission = this.submitted.get(epoch);
123
+ if (submission === undefined || submission.dependentRoot !== dependentRoot) {
124
+ if (submission !== undefined) {
125
+ this.logger.info("Proposer-shuffling dependent root shifted; resubmitting preferences", {
126
+ epoch,
127
+ priorDependentRoot: submission.dependentRoot,
128
+ dependentRoot,
129
+ });
130
+ }
131
+ submission = {dependentRoot, proposerSlots: new Set(), builderSlots: new Set()};
132
+ this.submitted.set(epoch, submission);
133
+ }
134
+ return submission;
135
+ }
136
+
137
+ private getUpcomingProposals(slot: Slot): UpcomingProposal[] {
138
+ const currentEpoch = computeEpochAtSlot(slot);
139
+ const proposals: UpcomingProposal[] = [];
140
+
141
+ for (const epoch of [currentEpoch, currentEpoch + 1]) {
142
+ const dutiesAtEpoch = this.blockDutiesService.getProposersAtEpoch(epoch);
143
+ if (!dutiesAtEpoch) continue;
144
+
145
+ const submission = this.getSubmissionAtEpoch(epoch, dutiesAtEpoch.dependentRoot);
146
+
147
+ for (const duty of dutiesAtEpoch.data) {
148
+ if (duty.slot <= slot) continue;
149
+ if (duty.slot > slot + SUBMIT_BEFORE_PROPOSAL_SLOTS) continue;
150
+ if (!isForkPostGloas(this.config.getForkName(duty.slot))) continue;
151
+
152
+ proposals.push({duty, submission});
153
+ }
154
+ }
155
+
156
+ return proposals;
157
+ }
158
+
159
+ private async submitProposerPreferences(proposals: UpcomingProposal[], slot: Slot): Promise<void> {
160
+ const signedProposerPreferences: gloas.SignedProposerPreferences[] = [];
161
+ // Track which `(submission, slot)` pairs are pending an API submission so we can mark
162
+ // them only after the network call succeeds. Marking before would silently drop a
163
+ // preference on transient API failure (no retry until dependent_root shifts).
164
+ const pending: PendingSubmission[] = [];
165
+
166
+ for (const {duty, submission} of proposals) {
167
+ if (submission.proposerSlots.has(duty.slot)) continue;
168
+
169
+ try {
170
+ const pubkeyHex = toPubkeyHex(duty.pubkey);
171
+ const signed = await this.validatorStore.signProposerPreferences(
172
+ duty,
173
+ fromHex(submission.dependentRoot),
174
+ this.validatorStore.getFeeRecipient(pubkeyHex),
175
+ this.validatorStore.getGasLimit(pubkeyHex, duty.slot, this.logger),
176
+ slot
177
+ );
178
+ signedProposerPreferences.push(signed);
179
+ pending.push({submission, slot: duty.slot});
180
+ } catch (e) {
181
+ this.logger.error(
182
+ "Error signing proposer preferences",
183
+ {slot: duty.slot, validatorIndex: duty.validatorIndex},
184
+ e as Error
185
+ );
186
+ }
187
+ }
188
+
189
+ if (signedProposerPreferences.length === 0) {
190
+ return;
191
+ }
192
+
193
+ try {
194
+ (await this.api.validator.submitProposerPreferences({signedProposerPreferences})).assertOk();
195
+ // Only mark as submitted after the API call succeeds; a thrown error leaves the
196
+ // slot eligible for retry on the next tick.
197
+ for (const {submission, slot: submittedSlot} of pending) {
198
+ submission.proposerSlots.add(submittedSlot);
199
+ }
200
+ this.logger.debug("Submitted signed proposer preferences", {count: signedProposerPreferences.length});
201
+ } catch (e) {
202
+ const failures = e instanceof ApiError ? e.failures : undefined;
203
+ if (failures === undefined) {
204
+ this.logger.error(
205
+ "Error submitting signed proposer preferences",
206
+ {count: signedProposerPreferences.length},
207
+ e as Error
208
+ );
209
+ return;
210
+ }
211
+
212
+ // The beacon node rejected some of the preferences, reported by index into the batch.
213
+ // Mark the accepted ones, the rejected ones are retried on the next tick.
214
+ const failedIndices = new Set(failures.map(({index}) => index));
215
+ pending.forEach(({submission, slot: submittedSlot}, index) => {
216
+ if (!failedIndices.has(index)) {
217
+ submission.proposerSlots.add(submittedSlot);
218
+ }
219
+ });
220
+ for (const {index, message} of failures) {
221
+ this.logger.error("Error submitting signed proposer preferences", {
222
+ slot: pending[index]?.slot,
223
+ validatorIndex: signedProposerPreferences[index]?.message.validatorIndex,
224
+ message,
225
+ });
226
+ }
227
+ }
228
+ }
229
+
230
+ private async submitBuilderPreferences(proposals: UpcomingProposal[], slot: Slot): Promise<void> {
231
+ const builderPreferences: routes.validator.BuilderPreferencesEntry[] = [];
232
+ const pending: PendingSubmission[] = [];
233
+ // Index into `pending` of each entry in `builderPreferences`, a proposal has one entry per builder
234
+ const pendingIndexByEntry: number[] = [];
235
+
236
+ for (const {duty, submission} of proposals) {
237
+ if (submission.builderSlots.has(duty.slot)) continue;
238
+
239
+ const pubkeyHex = toPubkeyHex(duty.pubkey);
240
+ const {selection} = this.validatorStore.getBuilderSelectionParams(pubkeyHex, duty.slot);
241
+ if (selection === routes.validator.BuilderSelection.ExecutionOnly) continue;
242
+
243
+ const builderEntries = this.validatorStore.getResolvedBuilderEntries(pubkeyHex);
244
+ if (builderEntries.length === 0) continue;
245
+
246
+ try {
247
+ // Collect entries per duty and only add them to the batch if signing
248
+ // succeeded for all builders, else the duty is retried on the next tick
249
+ const dutyEntries: routes.validator.BuilderPreferencesEntry[] = [];
250
+ for (const entry of builderEntries) {
251
+ const auth = await this.validatorStore.getBuilderRequestAuth(duty.pubkey, entry.authData, duty.slot, slot);
252
+ dutyEntries.push({
253
+ proposerPubkey: duty.pubkey,
254
+ url: new TextEncoder().encode(entry.url),
255
+ auth,
256
+ maxExecutionPayment: entry.maxExecutionPayment,
257
+ });
258
+ }
259
+ builderPreferences.push(...dutyEntries);
260
+ pendingIndexByEntry.push(...dutyEntries.map(() => pending.length));
261
+ pending.push({submission, slot: duty.slot});
262
+ } catch (e) {
263
+ this.logger.error(
264
+ "Error signing builder preferences",
265
+ {slot: duty.slot, validatorIndex: duty.validatorIndex},
266
+ e as Error
267
+ );
268
+ }
269
+ }
270
+
271
+ if (builderPreferences.length === 0) {
272
+ return;
273
+ }
274
+
275
+ try {
276
+ (await this.api.validator.submitBuilderPreferences({builderPreferences})).assertOk();
277
+ // Only mark as submitted after the API call succeeds; a thrown error, including per-entry
278
+ // failures reported by index, leaves all slots eligible for retry on the next tick.
279
+ // Re-submitting preferences a builder already accepted is harmless.
280
+ for (const {submission, slot: submittedSlot} of pending) {
281
+ submission.builderSlots.add(submittedSlot);
282
+ }
283
+ this.logger.debug("Submitted builder preferences", {count: builderPreferences.length});
284
+ } catch (e) {
285
+ const failures = e instanceof ApiError ? e.failures : undefined;
286
+ if (failures === undefined) {
287
+ this.logger.warn("Error submitting builder preferences", {count: builderPreferences.length}, e as Error);
288
+ return;
289
+ }
290
+
291
+ // Some entries were not accepted by their builder, reported by index into the batch. Mark the
292
+ // proposals whose entries were all accepted, the others are retried with all their builders.
293
+ const failedPendingIndices = new Set(failures.map(({index}) => pendingIndexByEntry[index]));
294
+ pending.forEach(({submission, slot: submittedSlot}, index) => {
295
+ if (!failedPendingIndices.has(index)) {
296
+ submission.builderSlots.add(submittedSlot);
297
+ }
298
+ });
299
+ for (const {index, message} of failures) {
300
+ this.logger.warn("Error submitting builder preferences", {
301
+ slot: pending[pendingIndexByEntry[index]]?.slot,
302
+ builder: builderPreferences[index] ? new TextDecoder().decode(builderPreferences[index].url) : undefined,
303
+ message,
304
+ });
305
+ }
306
+ }
307
+ }
308
+ }
@@ -1,7 +1,7 @@
1
1
  import {ApiClient, routes} from "@lodestar/api";
2
2
  import {ChainForkConfig} from "@lodestar/config";
3
3
  import {isForkPostGloas} from "@lodestar/params";
4
- import {IClock} from "@lodestar/state-transition";
4
+ import {IClock, computeStartSlotAtEpoch} from "@lodestar/state-transition";
5
5
  import {Slot, gloas} from "@lodestar/types";
6
6
  import {prettyBytes, sleep, toRootHex} from "@lodestar/utils";
7
7
  import {Metrics} from "../metrics.js";
@@ -54,8 +54,10 @@ export class PtcService {
54
54
  return;
55
55
  }
56
56
 
57
- const duties = this.dutiesService.getDutiesAtSlot(slot);
58
- if (duties.length === 0) {
57
+ let duties = this.dutiesService.getDutiesAtSlot(slot);
58
+ // Duties of the first Gloas epoch can't be polled ahead of the fork, at its first slot they are still being polled
59
+ const isFirstGloasSlot = slot === computeStartSlotAtEpoch(this.config.GLOAS_FORK_EPOCH);
60
+ if (duties.length === 0 && !isFirstGloasSlot) {
59
61
  return;
60
62
  }
61
63
 
@@ -71,6 +73,13 @@ export class PtcService {
71
73
  payloadAvailable.abort();
72
74
  }
73
75
 
76
+ if (isFirstGloasSlot) {
77
+ duties = this.dutiesService.getDutiesAtSlot(slot);
78
+ if (duties.length === 0) {
79
+ return;
80
+ }
81
+ }
82
+
74
83
  this.metrics?.ptcStepCallProducePayloadAttestation.observe(
75
84
  this.clock.secFromSlot(slot) - payloadAttestationDueMs / 1000
76
85
  );
@@ -95,8 +95,8 @@ export class PtcDutiesService {
95
95
  }
96
96
 
97
97
  private runDutiesTasks = async (epoch: Epoch): Promise<void> => {
98
- const nextEpoch = epoch + 1;
99
- if (!isForkPostGloas(this.config.getForkName(nextEpoch * SLOTS_PER_EPOCH))) {
98
+ // PTC duties of the first Gloas epoch only exist after the fork upgrade, they can't be polled one epoch ahead
99
+ if (!isForkPostGloas(this.config.getForkName(epoch * SLOTS_PER_EPOCH))) {
100
100
  return;
101
101
  }
102
102
 
@@ -359,14 +359,10 @@ export class ValidatorStore {
359
359
  }
360
360
 
361
361
  // Post-Gloas block production uses standard builder boost factor. Need to normalize the
362
- // gloas-deprecated "builderonly" and "executiononly" to the gloas fallback "builderalways"
363
- // and "executionalways" equivalent before deriving the boost factor.
364
- if (isPostGloas) {
365
- if (selection === routes.validator.BuilderSelection.BuilderOnly) {
366
- selection = routes.validator.BuilderSelection.BuilderAlways;
367
- } else if (selection === routes.validator.BuilderSelection.ExecutionOnly) {
368
- selection = routes.validator.BuilderSelection.ExecutionAlways;
369
- }
362
+ // gloas-deprecated "builderonly" to the gloas fallback "builderalways" equivalent before
363
+ // deriving the boost factor.
364
+ if (isPostGloas && selection === routes.validator.BuilderSelection.BuilderOnly) {
365
+ selection = routes.validator.BuilderSelection.BuilderAlways;
370
366
  }
371
367
 
372
368
  const boostFactor = getBuilderBoostFactor(
package/src/validator.ts CHANGED
@@ -16,14 +16,13 @@ import {MetaDataRepository} from "./repositories/metaDataRepository.js";
16
16
  import {AttestationService} from "./services/attestation.js";
17
17
  import {BlockProposingService} from "./services/block.js";
18
18
  import {BlockDutiesService} from "./services/blockDuties.js";
19
- import {BuilderPreferencesService} from "./services/builderPreferences.js";
20
19
  import {ChainHeaderTracker} from "./services/chainHeaderTracker.js";
21
20
  import {DoppelgangerService} from "./services/doppelgangerService.js";
22
21
  import {ValidatorEventEmitter} from "./services/emitter.js";
23
22
  import {ExternalSignerOptions, pollExternalSignerPubkeys} from "./services/externalSignerSync.js";
24
23
  import {IndicesService} from "./services/indices.js";
25
24
  import {pollBuilderValidatorRegistration, pollPrepareBeaconProposer} from "./services/prepareBeaconProposer.js";
26
- import {ProposerPreferencesService} from "./services/proposerPreferences.js";
25
+ import {ProposalPreferencesService} from "./services/proposalPreferences.js";
27
26
  import {PtcService} from "./services/ptc.js";
28
27
  import {SyncCommitteeService} from "./services/syncCommittee.js";
29
28
  import {SyncingStatusTracker} from "./services/syncingStatusTracker.js";
@@ -320,8 +319,16 @@ export class Validator {
320
319
  }
321
320
  );
322
321
 
323
- new ProposerPreferencesService(config, loggerVc, api, clock, validatorStore, blockDutiesService, metrics);
324
- new BuilderPreferencesService(config, loggerVc, api, clock, validatorStore, blockDutiesService, metrics);
322
+ new ProposalPreferencesService(
323
+ config,
324
+ loggerVc,
325
+ api,
326
+ clock,
327
+ validatorStore,
328
+ blockDutiesService,
329
+ syncingStatusTracker,
330
+ metrics
331
+ );
325
332
 
326
333
  return new Validator({
327
334
  opts,
@@ -1,27 +0,0 @@
1
- import { ApiClient } from "@lodestar/api";
2
- import { ChainForkConfig } from "@lodestar/config";
3
- import { IClock } from "@lodestar/state-transition";
4
- import { Metrics } from "../metrics.js";
5
- import { LoggerVc } from "../util/index.js";
6
- import { BlockDutiesService } from "./blockDuties.js";
7
- import { ValidatorStore } from "./validatorStore.js";
8
- /**
9
- * Signs and submits builder preferences for any local validator that will propose within the
10
- * next `SUBMIT_BEFORE_PROPOSAL_SLOTS` and has external builders configured. Signing the request
11
- * auths here also pre-fills the auth cache used at proposal time.
12
- *
13
- * The beacon node submits each entry to the builder at the entry's url. Re-submits automatically
14
- * when the proposer dependent root for an epoch shifts (e.g. after a reorg) since the proposer
15
- * for a slot may have changed.
16
- */
17
- export declare class BuilderPreferencesService {
18
- private readonly config;
19
- private readonly logger;
20
- private readonly api;
21
- private readonly validatorStore;
22
- private readonly blockDutiesService;
23
- private readonly submitted;
24
- constructor(config: ChainForkConfig, logger: LoggerVc, api: ApiClient, clock: IClock, validatorStore: ValidatorStore, blockDutiesService: BlockDutiesService, _metrics: Metrics | null);
25
- private runBuilderPreferencesTask;
26
- }
27
- //# sourceMappingURL=builderPreferences.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"builderPreferences.d.ts","sourceRoot":"","sources":["../../src/services/builderPreferences.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAS,MAAM,eAAe,CAAC;AAChD,OAAO,EAAC,eAAe,EAAC,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAC,MAAM,EAAqB,MAAM,4BAA4B,CAAC;AAGtE,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AACtC,OAAO,EAAC,QAAQ,EAAC,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAC,kBAAkB,EAAC,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AAYnD;;;;;;;;GAQG;AACH,qBAAa,yBAAyB;IAIlC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAEpB,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IARrC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAsC;IAEhE,YACmB,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,QAAQ,EAChB,GAAG,EAAE,SAAS,EAC/B,KAAK,EAAE,MAAM,EACI,cAAc,EAAE,cAAc,EAC9B,kBAAkB,EAAE,kBAAkB,EACvD,QAAQ,EAAE,OAAO,GAAG,IAAI,EAGzB;IAED,OAAO,CAAC,yBAAyB,CA+F/B;CACH"}
@@ -1,127 +0,0 @@
1
- import { routes } from "@lodestar/api";
2
- import { SLOTS_PER_EPOCH, isForkPostGloas } from "@lodestar/params";
3
- import { computeEpochAtSlot } from "@lodestar/state-transition";
4
- import { toPubkeyHex } from "@lodestar/utils";
5
- /**
6
- * Submit a proposer's builder preferences this many slots before the proposal slot.
7
- * Same pacing as `ProposerPreferencesService`, builders must have the preferences
8
- * before the bid request arrives at proposal time.
9
- */
10
- const SUBMIT_BEFORE_PROPOSAL_SLOTS = Math.floor(SLOTS_PER_EPOCH / 4);
11
- /**
12
- * Signs and submits builder preferences for any local validator that will propose within the
13
- * next `SUBMIT_BEFORE_PROPOSAL_SLOTS` and has external builders configured. Signing the request
14
- * auths here also pre-fills the auth cache used at proposal time.
15
- *
16
- * The beacon node submits each entry to the builder at the entry's url. Re-submits automatically
17
- * when the proposer dependent root for an epoch shifts (e.g. after a reorg) since the proposer
18
- * for a slot may have changed.
19
- */
20
- export class BuilderPreferencesService {
21
- config;
22
- logger;
23
- api;
24
- validatorStore;
25
- blockDutiesService;
26
- submitted = new Map();
27
- constructor(config, logger, api, clock, validatorStore, blockDutiesService, _metrics) {
28
- this.config = config;
29
- this.logger = logger;
30
- this.api = api;
31
- this.validatorStore = validatorStore;
32
- this.blockDutiesService = blockDutiesService;
33
- clock.runEverySlot(this.runBuilderPreferencesTask);
34
- }
35
- runBuilderPreferencesTask = async (slot) => {
36
- // Start running once the submission window (`slot + SUBMIT_BEFORE_PROPOSAL_SLOTS`) reaches
37
- // Gloas, i.e. already in the epoch before the fork. This allows builders to prepare and
38
- // submit bids for the first Gloas slots.
39
- if (!isForkPostGloas(this.config.getForkName(slot + SUBMIT_BEFORE_PROPOSAL_SLOTS))) {
40
- return;
41
- }
42
- const currentEpoch = computeEpochAtSlot(slot);
43
- const entries = [];
44
- // Track which `(submission, slot)` pairs are pending an API submission so we can mark
45
- // them only after the network call succeeds. Marking before would silently drop a
46
- // preference on transient API failure (no retry until dependent_root shifts).
47
- const pending = [];
48
- for (const epoch of [currentEpoch, currentEpoch + 1]) {
49
- const dutiesAtEpoch = this.blockDutiesService.getProposersAtEpoch(epoch);
50
- if (!dutiesAtEpoch)
51
- continue;
52
- // Reset submission tracking if the dependent root for this epoch has shifted
53
- // (e.g. due to a reorg). The proposer for a slot may have changed.
54
- let submission = this.submitted.get(epoch);
55
- if (submission === undefined || submission.dependentRoot !== dutiesAtEpoch.dependentRoot) {
56
- if (submission !== undefined) {
57
- this.logger.info("Proposer-shuffling dependent root shifted; resubmitting builder preferences", {
58
- epoch,
59
- priorDependentRoot: submission.dependentRoot,
60
- dependentRoot: dutiesAtEpoch.dependentRoot,
61
- });
62
- }
63
- submission = { dependentRoot: dutiesAtEpoch.dependentRoot, slots: new Set() };
64
- this.submitted.set(epoch, submission);
65
- }
66
- for (const duty of dutiesAtEpoch.data) {
67
- if (duty.slot <= slot)
68
- continue;
69
- if (duty.slot > slot + SUBMIT_BEFORE_PROPOSAL_SLOTS)
70
- continue;
71
- if (!isForkPostGloas(this.config.getForkName(duty.slot)))
72
- continue;
73
- if (submission.slots.has(duty.slot))
74
- continue;
75
- const pubkeyHex = toPubkeyHex(duty.pubkey);
76
- const { selection } = this.validatorStore.getBuilderSelectionParams(pubkeyHex, duty.slot);
77
- if (selection === routes.validator.BuilderSelection.ExecutionOnly)
78
- continue;
79
- const builderEntries = this.validatorStore.getResolvedBuilderEntries(pubkeyHex);
80
- if (builderEntries.length === 0)
81
- continue;
82
- try {
83
- // Collect entries per duty and only add them to the batch if signing
84
- // succeeded for all builders, else the duty is retried on the next tick
85
- const dutyEntries = [];
86
- for (const entry of builderEntries) {
87
- const auth = await this.validatorStore.getBuilderRequestAuth(duty.pubkey, entry.authData, duty.slot, slot);
88
- dutyEntries.push({
89
- proposerPubkey: duty.pubkey,
90
- url: new TextEncoder().encode(entry.url),
91
- auth,
92
- maxExecutionPayment: entry.maxExecutionPayment,
93
- });
94
- }
95
- entries.push(...dutyEntries);
96
- pending.push({ submission, slot: duty.slot });
97
- }
98
- catch (e) {
99
- this.logger.error("Error signing builder preferences", { slot: duty.slot, validatorIndex: duty.validatorIndex }, e);
100
- }
101
- }
102
- }
103
- // Prune tracking for past epochs
104
- for (const epoch of this.submitted.keys()) {
105
- if (epoch < currentEpoch) {
106
- this.submitted.delete(epoch);
107
- }
108
- }
109
- if (entries.length === 0) {
110
- return;
111
- }
112
- try {
113
- (await this.api.validator.submitBuilderPreferences({ builderPreferences: entries })).assertOk();
114
- // Only mark as submitted after the API call succeeds; a thrown error, including per-entry
115
- // failures reported by index, leaves all slots eligible for retry on the next tick.
116
- // Re-submitting preferences a builder already accepted is harmless.
117
- for (const { submission, slot: submittedSlot } of pending) {
118
- submission.slots.add(submittedSlot);
119
- }
120
- this.logger.debug("Submitted builder preferences", { count: entries.length });
121
- }
122
- catch (e) {
123
- this.logger.warn("Error submitting builder preferences", { count: entries.length }, e);
124
- }
125
- };
126
- }
127
- //# sourceMappingURL=builderPreferences.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"builderPreferences.js","sourceRoot":"","sources":["../../src/services/builderPreferences.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,MAAM,EAAC,MAAM,eAAe,CAAC;AAEhD,OAAO,EAAC,eAAe,EAAE,eAAe,EAAC,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAS,kBAAkB,EAAC,MAAM,4BAA4B,CAAC;AAEtE,OAAO,EAAC,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAM5C;;;;GAIG;AACH,MAAM,4BAA4B,GAAG,IAAI,CAAC,KAAK,CAAC,eAAe,GAAG,CAAC,CAAC,CAAC;AAKrE;;;;;;;;GAQG;AACH,MAAM,OAAO,yBAAyB;IAIjB,MAAM;IACN,MAAM;IACN,GAAG;IAEH,cAAc;IACd,kBAAkB;IARpB,SAAS,GAAG,IAAI,GAAG,EAA2B,CAAC;IAEhE,YACmB,MAAuB,EACvB,MAAgB,EAChB,GAAc,EAC/B,KAAa,EACI,cAA8B,EAC9B,kBAAsC,EACvD,QAAwB;sBANP,MAAM;sBACN,MAAM;mBACN,GAAG;8BAEH,cAAc;kCACd,kBAAkB;QAGnC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;IAC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C,MAAM,EAAC,CAAC,CAAC;QAC9E,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,sCAAsC,EAAE,EAAC,KAAK,EAAE,OAAO,CAAC,MAAM,EAAC,EAAE,CAAU,CAAC,CAAC;QAChG,CAAC;IACH,CAAC,CAAC;CACH"}
@@ -1,31 +0,0 @@
1
- import { ApiClient } from "@lodestar/api";
2
- import { ChainForkConfig } from "@lodestar/config";
3
- import { IClock } from "@lodestar/state-transition";
4
- import { Metrics } from "../metrics.js";
5
- import { LoggerVc } from "../util/index.js";
6
- import { BlockDutiesService } from "./blockDuties.js";
7
- import { ValidatorStore } from "./validatorStore.js";
8
- /**
9
- * Signs and submits `SignedProposerPreferences` for any local validator that will propose
10
- * within the next `SUBMIT_BEFORE_PROPOSAL_SLOTS`. Re-submits automatically when the proposer
11
- * dependent root for an epoch shifts (e.g. after a reorg) — detected by comparing the cached
12
- * `dependentRoot` reported by `BlockDutiesService` against the one we last submitted under.
13
- *
14
- * Proposers should broadcast their preferences before the fork so the proposer preference caches
15
- * of beacon nodes and builders are warm for the first Gloas slots. We start submitting
16
- * as soon as a duty's proposal slot is in Gloas, which is up to `SUBMIT_BEFORE_PROPOSAL_SLOTS`
17
- * before the fork, so only the first few Gloas slots are affected by this pre-fork submission.
18
- */
19
- export declare class ProposerPreferencesService {
20
- private readonly config;
21
- private readonly logger;
22
- private readonly api;
23
- private readonly validatorStore;
24
- private readonly blockDutiesService;
25
- private readonly submitted;
26
- private activeScheduledGasLimit;
27
- constructor(config: ChainForkConfig, logger: LoggerVc, api: ApiClient, clock: IClock, validatorStore: ValidatorStore, blockDutiesService: BlockDutiesService, _metrics: Metrics | null);
28
- private runProposerPreferencesTask;
29
- private runEveryEpochTask;
30
- }
31
- //# sourceMappingURL=proposerPreferences.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"proposerPreferences.d.ts","sourceRoot":"","sources":["../../src/services/proposerPreferences.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,eAAe,CAAC;AACxC,OAAO,EAAC,eAAe,EAAC,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAC,MAAM,EAAqB,MAAM,4BAA4B,CAAC;AAGtE,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AACtC,OAAO,EAAC,QAAQ,EAAC,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAC,kBAAkB,EAAC,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AAgBnD;;;;;;;;;;GAUG;AACH,qBAAa,0BAA0B;IAKnC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAEpB,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IATrC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAsC;IAChE,OAAO,CAAC,uBAAuB,CAAqB;IAEpD,YACmB,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,QAAQ,EAChB,GAAG,EAAE,SAAS,EAC/B,KAAK,EAAE,MAAM,EACI,cAAc,EAAE,cAAc,EAC9B,kBAAkB,EAAE,kBAAkB,EACvD,QAAQ,EAAE,OAAO,GAAG,IAAI,EAIzB;IAED,OAAO,CAAC,0BAA0B,CA8EhC;IAEF,OAAO,CAAC,iBAAiB,CAmBvB;CACH"}