@lodestar/validator 1.50.0-dev.db953a4f93 → 1.50.0-dev.dff4197219
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.
- package/lib/services/block.d.ts.map +1 -1
- package/lib/services/block.js +14 -3
- package/lib/services/block.js.map +1 -1
- package/lib/services/{proposerPreferences.d.ts → proposalPreferences.d.ts} +16 -7
- package/lib/services/proposalPreferences.d.ts.map +1 -0
- package/lib/services/proposalPreferences.js +205 -0
- package/lib/services/proposalPreferences.js.map +1 -0
- package/lib/services/ptc.d.ts.map +1 -1
- package/lib/services/ptc.js +11 -2
- package/lib/services/ptc.js.map +1 -1
- package/lib/services/ptcDuties.js +2 -2
- package/lib/services/ptcDuties.js.map +1 -1
- package/lib/services/validatorStore.d.ts.map +1 -1
- package/lib/services/validatorStore.js +4 -9
- package/lib/services/validatorStore.js.map +1 -1
- package/lib/validator.d.ts.map +1 -1
- package/lib/validator.js +2 -4
- package/lib/validator.js.map +1 -1
- package/package.json +13 -13
- package/src/services/block.ts +18 -4
- package/src/services/proposalPreferences.ts +247 -0
- package/src/services/ptc.ts +12 -3
- package/src/services/ptcDuties.ts +2 -2
- package/src/services/validatorStore.ts +4 -8
- package/src/validator.ts +2 -4
- package/lib/services/builderPreferences.d.ts +0 -27
- package/lib/services/builderPreferences.d.ts.map +0 -1
- package/lib/services/builderPreferences.js +0 -127
- package/lib/services/builderPreferences.js.map +0 -1
- package/lib/services/proposerPreferences.d.ts.map +0 -1
- package/lib/services/proposerPreferences.js +0 -130
- package/lib/services/proposerPreferences.js.map +0 -1
- package/src/services/builderPreferences.ts +0 -142
- package/src/services/proposerPreferences.ts +0 -154
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import {ApiClient} 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 {ValidatorStore} from "./validatorStore.js";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Submit a proposer's `SignedProposerPreferences` this many slots before the proposal slot.
|
|
14
|
-
*
|
|
15
|
-
* Earlier submission means more reorg-triggered resubmits (and gossip flood); later
|
|
16
|
-
* submission risks missing the bid-auction window for this proposal slot. The bid for
|
|
17
|
-
* slot S typically arrives at slot S-1, so we want preferences propagated to the network
|
|
18
|
-
* and consumed by builders before then. SLOTS_PER_EPOCH / 4 (8 slots @ 32 SPE, ~96s @ 12s
|
|
19
|
-
* slots) gives ample margin while bounding redundant resubmits.
|
|
20
|
-
*/
|
|
21
|
-
const SUBMIT_BEFORE_PROPOSAL_SLOTS = Math.floor(SLOTS_PER_EPOCH / 4);
|
|
22
|
-
|
|
23
|
-
/** Per-epoch tracking of preferences already submitted under the current dependent_root. */
|
|
24
|
-
type SubmittedAtEpoch = {dependentRoot: RootHex; slots: Set<Slot>};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Signs and submits `SignedProposerPreferences` for any local validator that will propose
|
|
28
|
-
* within the next `SUBMIT_BEFORE_PROPOSAL_SLOTS`. Re-submits automatically when the proposer
|
|
29
|
-
* dependent root for an epoch shifts (e.g. after a reorg) — detected by comparing the cached
|
|
30
|
-
* `dependentRoot` reported by `BlockDutiesService` against the one we last submitted under.
|
|
31
|
-
*
|
|
32
|
-
* Proposers should broadcast their preferences before the fork so the proposer preference caches
|
|
33
|
-
* of beacon nodes and builders are warm for the first Gloas slots. We start submitting
|
|
34
|
-
* as soon as a duty's proposal slot is in Gloas, which is up to `SUBMIT_BEFORE_PROPOSAL_SLOTS`
|
|
35
|
-
* before the fork, so only the first few Gloas slots are affected by this pre-fork submission.
|
|
36
|
-
*/
|
|
37
|
-
export class ProposerPreferencesService {
|
|
38
|
-
private readonly submitted = new Map<Epoch, SubmittedAtEpoch>();
|
|
39
|
-
private activeScheduledGasLimit: number | undefined;
|
|
40
|
-
|
|
41
|
-
constructor(
|
|
42
|
-
private readonly config: ChainForkConfig,
|
|
43
|
-
private readonly logger: LoggerVc,
|
|
44
|
-
private readonly api: ApiClient,
|
|
45
|
-
clock: IClock,
|
|
46
|
-
private readonly validatorStore: ValidatorStore,
|
|
47
|
-
private readonly blockDutiesService: BlockDutiesService,
|
|
48
|
-
_metrics: Metrics | null
|
|
49
|
-
) {
|
|
50
|
-
clock.runEverySlot(this.runProposerPreferencesTask);
|
|
51
|
-
clock.runEveryEpoch(this.runEveryEpochTask);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
private runProposerPreferencesTask = async (slot: Slot): Promise<void> => {
|
|
55
|
-
// Start running once the submission window (`slot + SUBMIT_BEFORE_PROPOSAL_SLOTS`) reaches
|
|
56
|
-
// Gloas, i.e. already in the epoch before the fork. This allows builders to prepare and
|
|
57
|
-
// submit bids for the first Gloas slots.
|
|
58
|
-
if (!isForkPostGloas(this.config.getForkName(slot + SUBMIT_BEFORE_PROPOSAL_SLOTS))) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const currentEpoch = computeEpochAtSlot(slot);
|
|
63
|
-
const batch: gloas.SignedProposerPreferences[] = [];
|
|
64
|
-
// Track which `(submission, slot)` pairs are pending an API submission so we can mark
|
|
65
|
-
// them only after the network call succeeds. Marking before would silently drop a
|
|
66
|
-
// preference on transient API failure (no retry until dependent_root shifts).
|
|
67
|
-
const pending: {submission: SubmittedAtEpoch; slot: Slot}[] = [];
|
|
68
|
-
|
|
69
|
-
for (const epoch of [currentEpoch, currentEpoch + 1]) {
|
|
70
|
-
const dutiesAtEpoch = this.blockDutiesService.getProposersAtEpoch(epoch);
|
|
71
|
-
if (!dutiesAtEpoch) continue;
|
|
72
|
-
|
|
73
|
-
// Reset submission tracking if the dependent root for this epoch has shifted
|
|
74
|
-
// (e.g. due to a reorg). Any previously-submitted preferences are now stale.
|
|
75
|
-
let submission = this.submitted.get(epoch);
|
|
76
|
-
if (submission === undefined || submission.dependentRoot !== dutiesAtEpoch.dependentRoot) {
|
|
77
|
-
if (submission !== undefined) {
|
|
78
|
-
this.logger.info("Proposer-shuffling dependent root shifted; resubmitting preferences", {
|
|
79
|
-
epoch,
|
|
80
|
-
priorDependentRoot: submission.dependentRoot,
|
|
81
|
-
dependentRoot: dutiesAtEpoch.dependentRoot,
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
submission = {dependentRoot: dutiesAtEpoch.dependentRoot, slots: new Set()};
|
|
85
|
-
this.submitted.set(epoch, submission);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const dependentRootBytes = fromHex(dutiesAtEpoch.dependentRoot);
|
|
89
|
-
|
|
90
|
-
for (const duty of dutiesAtEpoch.data) {
|
|
91
|
-
if (duty.slot <= slot) continue;
|
|
92
|
-
if (duty.slot > slot + SUBMIT_BEFORE_PROPOSAL_SLOTS) continue;
|
|
93
|
-
if (!isForkPostGloas(this.config.getForkName(duty.slot))) continue;
|
|
94
|
-
if (submission.slots.has(duty.slot)) continue;
|
|
95
|
-
|
|
96
|
-
try {
|
|
97
|
-
const pubkeyHex = toPubkeyHex(duty.pubkey);
|
|
98
|
-
const signed = await this.validatorStore.signProposerPreferences(
|
|
99
|
-
duty,
|
|
100
|
-
dependentRootBytes,
|
|
101
|
-
this.validatorStore.getFeeRecipient(pubkeyHex),
|
|
102
|
-
this.validatorStore.getGasLimit(pubkeyHex, duty.slot, this.logger),
|
|
103
|
-
slot
|
|
104
|
-
);
|
|
105
|
-
batch.push(signed);
|
|
106
|
-
pending.push({submission, slot: duty.slot});
|
|
107
|
-
} catch (e) {
|
|
108
|
-
this.logger.error(
|
|
109
|
-
"Error signing proposer preferences",
|
|
110
|
-
{slot: duty.slot, validatorIndex: duty.validatorIndex},
|
|
111
|
-
e as Error
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (batch.length === 0) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
try {
|
|
122
|
-
await this.api.validator.submitProposerPreferences({signedProposerPreferences: batch});
|
|
123
|
-
// Only mark as submitted after the API call succeeds; a thrown error leaves the
|
|
124
|
-
// slot eligible for retry on the next tick.
|
|
125
|
-
for (const {submission, slot: submittedSlot} of pending) {
|
|
126
|
-
submission.slots.add(submittedSlot);
|
|
127
|
-
}
|
|
128
|
-
this.logger.debug("Submitted signed proposer preferences", {count: batch.length});
|
|
129
|
-
} catch (e) {
|
|
130
|
-
this.logger.error("Error submitting signed proposer preferences", {count: batch.length}, e as Error);
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
private runEveryEpochTask = async (epoch: Epoch): Promise<void> => {
|
|
135
|
-
const scheduledGasLimit = this.config.getScheduledGasLimit(epoch);
|
|
136
|
-
if (scheduledGasLimit !== undefined && scheduledGasLimit !== this.activeScheduledGasLimit) {
|
|
137
|
-
const configuredDefaultGasLimit = this.validatorStore.getConfiguredDefaultGasLimit();
|
|
138
|
-
this.logger.info("Gas limit schedule active", {
|
|
139
|
-
epoch,
|
|
140
|
-
recommendedGasLimit: scheduledGasLimit,
|
|
141
|
-
effectiveDefaultGasLimit: configuredDefaultGasLimit ?? scheduledGasLimit,
|
|
142
|
-
defaultGasLimitSource: configuredDefaultGasLimit === undefined ? "schedule" : "operator",
|
|
143
|
-
});
|
|
144
|
-
this.activeScheduledGasLimit = scheduledGasLimit;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// Drop tracking for past epochs; only currentEpoch and currentEpoch + 1 are ever processed.
|
|
148
|
-
for (const trackedEpoch of this.submitted.keys()) {
|
|
149
|
-
if (trackedEpoch < epoch) {
|
|
150
|
-
this.submitted.delete(trackedEpoch);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
}
|