@lodestar/builder 1.48.0-dev.fd70e5fc15 → 1.48.0-dev.ff9749be2c
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/builder.d.ts +11 -1
- package/lib/builder.d.ts.map +1 -1
- package/lib/builder.js +30 -2
- package/lib/builder.js.map +1 -1
- package/lib/identity.d.ts +0 -1
- package/lib/identity.d.ts.map +1 -1
- package/lib/identity.js +11 -4
- package/lib/identity.js.map +1 -1
- package/lib/services/bidLedger.d.ts +61 -0
- package/lib/services/bidLedger.d.ts.map +1 -0
- package/lib/services/bidLedger.js +154 -0
- package/lib/services/bidLedger.js.map +1 -0
- package/lib/services/bidPolicy.d.ts +30 -0
- package/lib/services/bidPolicy.d.ts.map +1 -0
- package/lib/services/bidPolicy.js +37 -0
- package/lib/services/bidPolicy.js.map +1 -0
- package/lib/services/blockObserver.d.ts +48 -0
- package/lib/services/blockObserver.d.ts.map +1 -0
- package/lib/services/blockObserver.js +172 -0
- package/lib/services/blockObserver.js.map +1 -0
- package/lib/services/payloadStore.d.ts +25 -0
- package/lib/services/payloadStore.d.ts.map +1 -0
- package/lib/services/payloadStore.js +25 -0
- package/lib/services/payloadStore.js.map +1 -0
- package/lib/services/proposerPreferencesTracker.d.ts +15 -0
- package/lib/services/proposerPreferencesTracker.d.ts.map +1 -0
- package/lib/services/proposerPreferencesTracker.js +68 -0
- package/lib/services/proposerPreferencesTracker.js.map +1 -0
- package/package.json +11 -11
- package/src/builder.ts +45 -3
- package/src/identity.ts +13 -6
- package/src/services/bidLedger.ts +245 -0
- package/src/services/bidPolicy.ts +65 -0
- package/src/services/blockObserver.ts +231 -0
- package/src/services/payloadStore.ts +51 -0
- package/src/services/proposerPreferencesTracker.ts +74 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { ApiError, routes } from "@lodestar/api";
|
|
2
|
+
import { isForkPostGloas } from "@lodestar/params";
|
|
3
|
+
import { isGloasBeaconBlock } from "@lodestar/types";
|
|
4
|
+
import { TimeoutError, isErrorAborted, isFetchError, pruneSetToMax, retry, toRootHex } from "@lodestar/utils";
|
|
5
|
+
const { EventType } = routes.events;
|
|
6
|
+
/**
|
|
7
|
+
* Observes imported beacon blocks through the source beacon node API.
|
|
8
|
+
*
|
|
9
|
+
* Each block root is evaluated at most once while retained in the bounded seen set. Terminal failures remain consumed
|
|
10
|
+
* until normal FIFO eviction; reconnect, replay, and recovery policies are handled separately.
|
|
11
|
+
*/
|
|
12
|
+
export class BlockObserver {
|
|
13
|
+
config;
|
|
14
|
+
logger;
|
|
15
|
+
api;
|
|
16
|
+
fns = [];
|
|
17
|
+
seenBlockRoots = new Set();
|
|
18
|
+
retries;
|
|
19
|
+
retryDelay;
|
|
20
|
+
maxSeenBlockRoots;
|
|
21
|
+
constructor(config, logger, api, { retries = 5, retryDelay = 200, maxSeenBlockRoots = 256 } = {}) {
|
|
22
|
+
this.config = config;
|
|
23
|
+
this.logger = logger;
|
|
24
|
+
this.api = api;
|
|
25
|
+
this.retries = retries;
|
|
26
|
+
this.retryDelay = retryDelay;
|
|
27
|
+
this.maxSeenBlockRoots = maxSeenBlockRoots;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Register a block consumer. Consumers that require complete observation must register before {@link start}, because
|
|
31
|
+
* roots observed before registration remain consumed until normal FIFO eviction.
|
|
32
|
+
*/
|
|
33
|
+
runOnBlock(fn) {
|
|
34
|
+
this.fns.push(fn);
|
|
35
|
+
}
|
|
36
|
+
start(signal) {
|
|
37
|
+
this.logger.info("Subscribing to block events", {
|
|
38
|
+
retries: this.retries,
|
|
39
|
+
retryDelay: this.retryDelay,
|
|
40
|
+
maxSeenBlockRoots: this.maxSeenBlockRoots,
|
|
41
|
+
});
|
|
42
|
+
this.api.events
|
|
43
|
+
.eventstream({
|
|
44
|
+
topics: [EventType.block],
|
|
45
|
+
signal,
|
|
46
|
+
onEvent: (event) => {
|
|
47
|
+
if (event.type !== EventType.block) {
|
|
48
|
+
this.logger.debug("Ignoring unexpected beacon event", { eventType: event.type });
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
void this.processBlockEvent(event.message, signal);
|
|
52
|
+
},
|
|
53
|
+
onError: (error) => {
|
|
54
|
+
this.logger.error("Failed to receive block event", {}, error);
|
|
55
|
+
},
|
|
56
|
+
onClose: () => {
|
|
57
|
+
if (signal.aborted) {
|
|
58
|
+
this.logger.debug("Closed stream for block events");
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
this.logger.error("Block event stream closed unexpectedly", {});
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
})
|
|
65
|
+
.catch((error) => {
|
|
66
|
+
this.logger.error("Failed to subscribe to block events", {}, error instanceof Error ? error : Error(String(error)));
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async processBlockEvent(event, signal) {
|
|
70
|
+
try {
|
|
71
|
+
const { slot, block: blockRoot, executionOptimistic } = event;
|
|
72
|
+
if (this.seenBlockRoots.has(blockRoot)) {
|
|
73
|
+
this.logger.debug("Ignoring duplicate block event", { slot, blockRoot });
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
this.seenBlockRoots.add(blockRoot);
|
|
77
|
+
pruneSetToMax(this.seenBlockRoots, this.maxSeenBlockRoots);
|
|
78
|
+
if (!isForkPostGloas(this.config.getForkName(slot))) {
|
|
79
|
+
this.logger.debug("Ignoring pre-Gloas block event", { slot, blockRoot });
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const response = await retry(async () => {
|
|
83
|
+
// TODO GLOAS: Remove this lookup once bid-selection notifications provide the required data.
|
|
84
|
+
const result = await this.api.beacon.getBlockV2({ blockId: blockRoot }, { signal });
|
|
85
|
+
result.assertOk();
|
|
86
|
+
return result;
|
|
87
|
+
}, {
|
|
88
|
+
retries: this.retries,
|
|
89
|
+
retryDelay: this.retryDelay,
|
|
90
|
+
signal,
|
|
91
|
+
shouldRetry: isRetryableBlockRetrievalError,
|
|
92
|
+
onRetry: (error, attempt) => {
|
|
93
|
+
this.logger.debug("Retrying block retrieval", {
|
|
94
|
+
slot,
|
|
95
|
+
blockRoot,
|
|
96
|
+
attempt,
|
|
97
|
+
error: error.message,
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
}).catch((error) => {
|
|
101
|
+
if (!isErrorAborted(error)) {
|
|
102
|
+
this.logger.error("Failed to retrieve block referenced by block event", { slot, blockRoot }, error instanceof Error ? error : Error(String(error)));
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
105
|
+
});
|
|
106
|
+
if (response === null) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const { version } = response.meta();
|
|
110
|
+
if (!isForkPostGloas(version)) {
|
|
111
|
+
this.logger.warn("Ignoring block with unsupported fork version", { slot, blockRoot, fork: version });
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const block = response.value();
|
|
115
|
+
if (!isGloasBeaconBlock(block.message)) {
|
|
116
|
+
this.logger.warn("Block response version and body do not agree", { slot, blockRoot, fork: version });
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (block.message.slot !== slot) {
|
|
120
|
+
this.logger.warn("Block response slot does not match block event", {
|
|
121
|
+
slot,
|
|
122
|
+
blockRoot,
|
|
123
|
+
blockSlot: block.message.slot,
|
|
124
|
+
});
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const postGloasBlock = block;
|
|
128
|
+
const signedBid = postGloasBlock.message.body.signedExecutionPayloadBid;
|
|
129
|
+
const observedBlock = {
|
|
130
|
+
blockRoot,
|
|
131
|
+
slot,
|
|
132
|
+
executionOptimistic,
|
|
133
|
+
version,
|
|
134
|
+
block: postGloasBlock,
|
|
135
|
+
signedBid,
|
|
136
|
+
};
|
|
137
|
+
this.logger.debug("Observed post-Gloas block", {
|
|
138
|
+
slot,
|
|
139
|
+
blockRoot,
|
|
140
|
+
fork: version,
|
|
141
|
+
builderIndex: signedBid.message.builderIndex,
|
|
142
|
+
value: signedBid.message.value,
|
|
143
|
+
blockHash: toRootHex(signedBid.message.blockHash),
|
|
144
|
+
parentBlockHash: toRootHex(signedBid.message.parentBlockHash),
|
|
145
|
+
});
|
|
146
|
+
await Promise.all(this.fns.map(async (fn) => {
|
|
147
|
+
try {
|
|
148
|
+
await fn(observedBlock);
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
if (isErrorAborted(error)) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
this.logger.error("Failed to process observed block", { slot, blockRoot }, error instanceof Error ? error : Error(String(error)));
|
|
155
|
+
}
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
if (isErrorAborted(error)) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
this.logger.error("Failed to process block event", { slot: event.slot, blockRoot: event.block }, error instanceof Error ? error : Error(String(error)));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
export function isRetryableBlockRetrievalError(error) {
|
|
167
|
+
if (error instanceof ApiError) {
|
|
168
|
+
return error.status === 404 || error.status >= 500;
|
|
169
|
+
}
|
|
170
|
+
return error instanceof TimeoutError || (isFetchError(error) && error.type !== "input");
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=blockObserver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blockObserver.js","sourceRoot":"","sources":["../../src/services/blockObserver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,QAAQ,EAAE,MAAM,EAAC,MAAM,eAAe,CAAC;AAE1D,OAAO,EAAgB,eAAe,EAAC,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAmC,kBAAkB,EAAC,MAAM,iBAAiB,CAAC;AACrF,OAAO,EAAS,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,KAAK,EAAE,SAAS,EAAC,MAAM,iBAAiB,CAAC;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BAA8B,CAAC,KAAY;IACzD,IAAI,KAAK,YAAY,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG,CAAC;IACrD,CAAC;IAED,OAAO,KAAK,YAAY,YAAY,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC;AAC1F,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ForkPostGloas } from "@lodestar/params";
|
|
2
|
+
import { BlobsBundle, ExecutionPayload, Root, RootHex, Slot, gloas } from "@lodestar/types";
|
|
3
|
+
export type BuiltPayload = {
|
|
4
|
+
sourceId: string;
|
|
5
|
+
executionPayload: ExecutionPayload<ForkPostGloas>;
|
|
6
|
+
executionRequests: gloas.ExecutionRequests;
|
|
7
|
+
blobsBundle: BlobsBundle<ForkPostGloas>;
|
|
8
|
+
/** Value of the payload to the fee recipient in wei, as reported by the execution client */
|
|
9
|
+
executionPayloadValue: bigint;
|
|
10
|
+
};
|
|
11
|
+
export type StoredPayload = {
|
|
12
|
+
slot: Slot;
|
|
13
|
+
parentBlockRoot: Root;
|
|
14
|
+
blockHash: RootHex;
|
|
15
|
+
payload: BuiltPayload;
|
|
16
|
+
};
|
|
17
|
+
export declare class PayloadStore {
|
|
18
|
+
private readonly byBlockHash;
|
|
19
|
+
add(payload: StoredPayload): void;
|
|
20
|
+
get(blockHash: RootHex): StoredPayload | null;
|
|
21
|
+
has(blockHash: RootHex): boolean;
|
|
22
|
+
prune(currentSlot: Slot): void;
|
|
23
|
+
get size(): number;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=payloadStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payloadStore.d.ts","sourceRoot":"","sources":["../../src/services/payloadStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAC,WAAW,EAAE,gBAAgB,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAC,MAAM,iBAAiB,CAAC;AAI1F,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAC;IAClD,iBAAiB,EAAE,KAAK,CAAC,iBAAiB,CAAC;IAC3C,WAAW,EAAE,WAAW,CAAC,aAAa,CAAC,CAAC;IACxC,4FAA4F;IAC5F,qBAAqB,EAAE,MAAM,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,IAAI,CAAC;IACX,eAAe,EAAE,IAAI,CAAC;IACtB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,YAAY,CAAC;CACvB,CAAC;AAKF,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqC;IAEjE,GAAG,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAEhC;IAED,GAAG,CAAC,SAAS,EAAE,OAAO,GAAG,aAAa,GAAG,IAAI,CAE5C;IAED,GAAG,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAE/B;IAED,KAAK,CAAC,WAAW,EAAE,IAAI,GAAG,IAAI,CAM7B;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Keep payloads for this many slots after their target slot, late blocks may still commit to them */
|
|
2
|
+
const KEEP_SLOTS = 2;
|
|
3
|
+
export class PayloadStore {
|
|
4
|
+
byBlockHash = new Map();
|
|
5
|
+
add(payload) {
|
|
6
|
+
this.byBlockHash.set(payload.blockHash, payload);
|
|
7
|
+
}
|
|
8
|
+
get(blockHash) {
|
|
9
|
+
return this.byBlockHash.get(blockHash) ?? null;
|
|
10
|
+
}
|
|
11
|
+
has(blockHash) {
|
|
12
|
+
return this.byBlockHash.has(blockHash);
|
|
13
|
+
}
|
|
14
|
+
prune(currentSlot) {
|
|
15
|
+
for (const [blockHash, { slot }] of this.byBlockHash) {
|
|
16
|
+
if (slot + KEEP_SLOTS < currentSlot) {
|
|
17
|
+
this.byBlockHash.delete(blockHash);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
get size() {
|
|
22
|
+
return this.byBlockHash.size;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=payloadStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payloadStore.js","sourceRoot":"","sources":["../../src/services/payloadStore.ts"],"names":[],"mappings":"AAqBA,sGAAsG;AACtG,MAAM,UAAU,GAAG,CAAC,CAAC;AAErB,MAAM,OAAO,YAAY;IACN,WAAW,GAAG,IAAI,GAAG,EAA0B,CAAC;IAEjE,GAAG,CAAC,OAAsB;QACxB,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IACnD,CAAC;IAED,GAAG,CAAC,SAAkB;QACpB,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC;IACjD,CAAC;IAED,GAAG,CAAC,SAAkB;QACpB,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,WAAiB;QACrB,KAAK,MAAM,CAAC,SAAS,EAAE,EAAC,IAAI,EAAC,CAAC,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACnD,IAAI,IAAI,GAAG,UAAU,GAAG,WAAW,EAAE,CAAC;gBACpC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YACrC,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IAC/B,CAAC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ApiClient } from "@lodestar/api";
|
|
2
|
+
import type { RootHex, Slot, gloas } from "@lodestar/types";
|
|
3
|
+
import { Logger } from "@lodestar/utils";
|
|
4
|
+
/** Retains validated proposer preferences by the branch-specific identity used for bid validation. */
|
|
5
|
+
export declare class ProposerPreferencesTracker {
|
|
6
|
+
private readonly api;
|
|
7
|
+
private readonly logger;
|
|
8
|
+
private readonly byDependentRootBySlot;
|
|
9
|
+
constructor(api: ApiClient, logger: Logger);
|
|
10
|
+
start(signal: AbortSignal): void;
|
|
11
|
+
onProposerPreferences(signedProposerPreferences: gloas.SignedProposerPreferences): boolean;
|
|
12
|
+
get(slot: Slot, dependentRoot: RootHex): gloas.SignedProposerPreferences | null;
|
|
13
|
+
prune(currentSlot: Slot): number;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=proposerPreferencesTracker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proposerPreferencesTracker.d.ts","sourceRoot":"","sources":["../../src/services/proposerPreferencesTracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAS,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAC,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAC,MAAM,EAAoB,MAAM,iBAAiB,CAAC;AAE1D,sGAAsG;AACtG,qBAAa,0BAA0B;IAMnC,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM;IANzB,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAEpC;IAEF,YACmB,GAAG,EAAE,SAAS,EACd,MAAM,EAAE,MAAM,EAC7B;IAEJ,KAAK,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CA2B/B;IAED,qBAAqB,CAAC,yBAAyB,EAAE,KAAK,CAAC,yBAAyB,GAAG,OAAO,CAWzF;IAED,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,GAAG,KAAK,CAAC,yBAAyB,GAAG,IAAI,CAE9E;IAED,KAAK,CAAC,WAAW,EAAE,IAAI,GAAG,MAAM,CAW/B;CACF"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { routes } from "@lodestar/api";
|
|
2
|
+
import { MapDef, toRootHex } from "@lodestar/utils";
|
|
3
|
+
/** Retains validated proposer preferences by the branch-specific identity used for bid validation. */
|
|
4
|
+
export class ProposerPreferencesTracker {
|
|
5
|
+
api;
|
|
6
|
+
logger;
|
|
7
|
+
byDependentRootBySlot = new MapDef(() => new Map());
|
|
8
|
+
constructor(api, logger) {
|
|
9
|
+
this.api = api;
|
|
10
|
+
this.logger = logger;
|
|
11
|
+
}
|
|
12
|
+
start(signal) {
|
|
13
|
+
if (signal.aborted)
|
|
14
|
+
return;
|
|
15
|
+
this.logger.verbose("Subscribing to proposer preferences");
|
|
16
|
+
this.api.events
|
|
17
|
+
.eventstream({
|
|
18
|
+
topics: [routes.events.EventType.proposerPreferences],
|
|
19
|
+
signal,
|
|
20
|
+
onEvent: (event) => {
|
|
21
|
+
if (!signal.aborted && event.type === routes.events.EventType.proposerPreferences) {
|
|
22
|
+
this.onProposerPreferences(event.message.data);
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
onError: (error) => {
|
|
26
|
+
if (!signal.aborted)
|
|
27
|
+
this.logger.error("Failed to receive proposer preferences", {}, error);
|
|
28
|
+
},
|
|
29
|
+
onClose: () => {
|
|
30
|
+
if (signal.aborted) {
|
|
31
|
+
this.logger.verbose("Closed proposer preferences stream");
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
this.logger.error("Proposer preferences stream closed unexpectedly", {});
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
})
|
|
38
|
+
.catch((error) => {
|
|
39
|
+
if (!signal.aborted)
|
|
40
|
+
this.logger.error("Failed to subscribe to proposer preferences", {}, error);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
onProposerPreferences(signedProposerPreferences) {
|
|
44
|
+
const { proposalSlot, dependentRoot } = signedProposerPreferences.message;
|
|
45
|
+
const dependentRootHex = toRootHex(dependentRoot);
|
|
46
|
+
const byDependentRoot = this.byDependentRootBySlot.getOrDefault(proposalSlot);
|
|
47
|
+
if (byDependentRoot.has(dependentRootHex)) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
byDependentRoot.set(dependentRootHex, signedProposerPreferences);
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
get(slot, dependentRoot) {
|
|
54
|
+
return this.byDependentRootBySlot.get(slot)?.get(dependentRoot) ?? null;
|
|
55
|
+
}
|
|
56
|
+
prune(currentSlot) {
|
|
57
|
+
let removed = 0;
|
|
58
|
+
for (const [slot, byDependentRoot] of this.byDependentRootBySlot) {
|
|
59
|
+
if (slot >= currentSlot) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
removed += byDependentRoot.size;
|
|
63
|
+
this.byDependentRootBySlot.delete(slot);
|
|
64
|
+
}
|
|
65
|
+
return removed;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=proposerPreferencesTracker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proposerPreferencesTracker.js","sourceRoot":"","sources":["../../src/services/proposerPreferencesTracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,MAAM,EAAC,MAAM,eAAe,CAAC;AAEhD,OAAO,EAAS,MAAM,EAAE,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAE1D,sGAAsG;AACtG,MAAM,OAAO,0BAA0B;IAMlB,GAAG;IACH,MAAM;IANR,qBAAqB,GAAG,IAAI,MAAM,CACjD,GAAG,EAAE,CAAC,IAAI,GAAG,EAAE,CAChB,CAAC;IAEF,YACmB,GAAc,EACd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C;IAED,qBAAqB,CAAC,yBAA0D;QAC9E,MAAM,EAAC,YAAY,EAAE,aAAa,EAAC,GAAG,yBAAyB,CAAC,OAAO,CAAC;QACxE,MAAM,gBAAgB,GAAG,SAAS,CAAC,aAAa,CAAC,CAAC;QAClD,MAAM,eAAe,GAAG,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QAE9E,IAAI,eAAe,CAAC,GAAG,CAAC,gBAAgB,CAAC,EAAE,CAAC;YAC1C,OAAO,KAAK,CAAC;QACf,CAAC;QAED,eAAe,CAAC,GAAG,CAAC,gBAAgB,EAAE,yBAAyB,CAAC,CAAC;QACjE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,GAAG,CAAC,IAAU,EAAE,aAAsB;QACpC,OAAO,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,aAAa,CAAC,IAAI,IAAI,CAAC;IAC1E,CAAC;IAED,KAAK,CAAC,WAAiB;QACrB,IAAI,OAAO,GAAG,CAAC,CAAC;QAChB,KAAK,MAAM,CAAC,IAAI,EAAE,eAAe,CAAC,IAAI,IAAI,CAAC,qBAAqB,EAAE,CAAC;YACjE,IAAI,IAAI,IAAI,WAAW,EAAE,CAAC;gBACxB,SAAS;YACX,CAAC;YAED,OAAO,IAAI,eAAe,CAAC,IAAI,CAAC;YAChC,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC1C,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lodestar/builder",
|
|
3
|
-
"version": "1.48.0-dev.
|
|
3
|
+
"version": "1.48.0-dev.ff9749be2c",
|
|
4
4
|
"description": "A Typescript implementation of the builder client",
|
|
5
5
|
"author": "ChainSafe Systems",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -47,17 +47,17 @@
|
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@chainsafe/lodestar-z": "catalog:",
|
|
50
|
-
"@chainsafe/ssz": "^1.
|
|
51
|
-
"@lodestar/api": "^1.48.0-dev.
|
|
52
|
-
"@lodestar/config": "^1.48.0-dev.
|
|
53
|
-
"@lodestar/params": "^1.48.0-dev.
|
|
54
|
-
"@lodestar/state-transition": "^1.48.0-dev.
|
|
55
|
-
"@lodestar/types": "^1.48.0-dev.
|
|
56
|
-
"@lodestar/utils": "^1.48.0-dev.
|
|
50
|
+
"@chainsafe/ssz": "^1.8.0",
|
|
51
|
+
"@lodestar/api": "^1.48.0-dev.ff9749be2c",
|
|
52
|
+
"@lodestar/config": "^1.48.0-dev.ff9749be2c",
|
|
53
|
+
"@lodestar/params": "^1.48.0-dev.ff9749be2c",
|
|
54
|
+
"@lodestar/state-transition": "^1.48.0-dev.ff9749be2c",
|
|
55
|
+
"@lodestar/types": "^1.48.0-dev.ff9749be2c",
|
|
56
|
+
"@lodestar/utils": "^1.48.0-dev.ff9749be2c"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@lodestar/logger": "^1.48.0-dev.
|
|
60
|
-
"@lodestar/test-utils": "^1.48.0-dev.
|
|
59
|
+
"@lodestar/logger": "^1.48.0-dev.ff9749be2c",
|
|
60
|
+
"@lodestar/test-utils": "^1.48.0-dev.ff9749be2c"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "bb8a252f7ae741ea6943becf36aeeea93b08e36d"
|
|
63
63
|
}
|
package/src/builder.ts
CHANGED
|
@@ -7,15 +7,21 @@ import {waitForGenesis} from "./genesis.js";
|
|
|
7
7
|
import {resolveBuilderIdentity} from "./identity.js";
|
|
8
8
|
import {Metrics} from "./metrics.js";
|
|
9
9
|
import {logNodeVersion, waitForNodeReady} from "./readiness.js";
|
|
10
|
+
import {BlockObserver} from "./services/blockObserver.js";
|
|
10
11
|
import {BuilderSigner, Keypair} from "./services/builderSigner.js";
|
|
11
12
|
import {BuilderStatusTracker} from "./services/builderStatusTracker.js";
|
|
13
|
+
import {PayloadStore} from "./services/payloadStore.js";
|
|
14
|
+
import {ProposerPreferencesTracker} from "./services/proposerPreferencesTracker.js";
|
|
12
15
|
|
|
13
16
|
export type BuilderModules = {
|
|
14
17
|
opts: BuilderOptions;
|
|
15
18
|
builderSigner: BuilderSigner;
|
|
19
|
+
blockObserver: BlockObserver;
|
|
16
20
|
builderStatusTracker: BuilderStatusTracker;
|
|
21
|
+
proposerPreferencesTracker: ProposerPreferencesTracker;
|
|
17
22
|
clock: IClock;
|
|
18
23
|
index: BuilderIndex;
|
|
24
|
+
payloadStore: PayloadStore;
|
|
19
25
|
};
|
|
20
26
|
|
|
21
27
|
export type BuilderOptions = {
|
|
@@ -34,25 +40,43 @@ export type BuilderOptions = {
|
|
|
34
40
|
*/
|
|
35
41
|
export class Builder {
|
|
36
42
|
readonly builderSigner: BuilderSigner;
|
|
43
|
+
readonly proposerPreferencesTracker: ProposerPreferencesTracker;
|
|
44
|
+
private readonly blockObserver: BlockObserver;
|
|
37
45
|
private readonly builderStatusTracker: BuilderStatusTracker;
|
|
38
46
|
private readonly controller: AbortController;
|
|
39
47
|
private readonly clock: IClock;
|
|
40
48
|
private readonly index: BuilderIndex;
|
|
41
49
|
private readonly logger: Logger;
|
|
42
50
|
private readonly executionFeeRecipient: ExecutionAddress;
|
|
43
|
-
|
|
44
|
-
|
|
51
|
+
private readonly payloadStore: PayloadStore;
|
|
52
|
+
|
|
53
|
+
constructor({
|
|
54
|
+
opts,
|
|
55
|
+
builderSigner,
|
|
56
|
+
blockObserver,
|
|
57
|
+
builderStatusTracker,
|
|
58
|
+
proposerPreferencesTracker,
|
|
59
|
+
clock,
|
|
60
|
+
index,
|
|
61
|
+
payloadStore,
|
|
62
|
+
}: BuilderModules) {
|
|
45
63
|
this.builderSigner = builderSigner;
|
|
64
|
+
this.blockObserver = blockObserver;
|
|
46
65
|
this.builderStatusTracker = builderStatusTracker;
|
|
66
|
+
this.proposerPreferencesTracker = proposerPreferencesTracker;
|
|
47
67
|
this.clock = clock;
|
|
48
68
|
this.controller = opts.abortController;
|
|
49
69
|
this.logger = opts.logger;
|
|
50
70
|
this.index = index;
|
|
71
|
+
this.payloadStore = payloadStore;
|
|
51
72
|
|
|
52
73
|
this.executionFeeRecipient = opts.executionFeeRecipient;
|
|
53
74
|
|
|
75
|
+
this.clock.runEverySlot(async (slot) => this.onSlot(slot));
|
|
54
76
|
this.clock.runEveryEpoch((epoch) => this.builderStatusTracker.poll(epoch));
|
|
55
77
|
this.clock.start(this.controller.signal);
|
|
78
|
+
this.blockObserver.start(this.controller.signal);
|
|
79
|
+
this.proposerPreferencesTracker.start(this.controller.signal);
|
|
56
80
|
|
|
57
81
|
this.logger.info("Builder client initialized", {
|
|
58
82
|
index: this.index,
|
|
@@ -89,8 +113,26 @@ export class Builder {
|
|
|
89
113
|
);
|
|
90
114
|
|
|
91
115
|
const builderStatusTracker = new BuilderStatusTracker(api, logger, index, opts.metrics);
|
|
116
|
+
const blockObserver = new BlockObserver(config, logger, api);
|
|
117
|
+
const proposerPreferencesTracker = new ProposerPreferencesTracker(api, logger);
|
|
118
|
+
|
|
119
|
+
const payloadStore = new PayloadStore();
|
|
120
|
+
|
|
121
|
+
return new Builder({
|
|
122
|
+
opts,
|
|
123
|
+
builderSigner,
|
|
124
|
+
blockObserver,
|
|
125
|
+
builderStatusTracker,
|
|
126
|
+
proposerPreferencesTracker,
|
|
127
|
+
clock,
|
|
128
|
+
index,
|
|
129
|
+
payloadStore,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
92
132
|
|
|
93
|
-
|
|
133
|
+
private async onSlot(slot: number): Promise<void> {
|
|
134
|
+
this.payloadStore.prune(slot);
|
|
135
|
+
this.proposerPreferencesTracker.prune(slot);
|
|
94
136
|
}
|
|
95
137
|
|
|
96
138
|
async close(): Promise<void> {
|
package/src/identity.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import {ApiClient, ApiError, HttpStatusCode, routes} from "@lodestar/api";
|
|
2
2
|
import {ChainForkConfig} from "@lodestar/config";
|
|
3
3
|
import {PAYLOAD_BUILDER_VERSION} from "@lodestar/params";
|
|
4
|
-
import {IClock} from "@lodestar/state-transition";
|
|
4
|
+
import {IClock, computeStartSlotAtEpoch} from "@lodestar/state-transition";
|
|
5
5
|
import {BuilderIndex, BuilderStatus} from "@lodestar/types";
|
|
6
6
|
import {ErrorAborted, Logger, TimeoutError, isFetchError, sleep, toHex} from "@lodestar/utils";
|
|
7
7
|
|
|
8
|
-
export const WAITING_FOR_BUILDER_POLL_MS = 10 * 1000;
|
|
9
|
-
|
|
10
8
|
export async function resolveBuilderIdentity(
|
|
11
9
|
api: ApiClient,
|
|
12
10
|
logger: Logger,
|
|
@@ -71,7 +69,7 @@ async function waitForBuilder(
|
|
|
71
69
|
currentEpoch,
|
|
72
70
|
slot: clock.getCurrentSlot(),
|
|
73
71
|
});
|
|
74
|
-
await sleep(
|
|
72
|
+
await sleep(msToNextEpochPoll(clock), signal);
|
|
75
73
|
continue;
|
|
76
74
|
}
|
|
77
75
|
|
|
@@ -87,7 +85,7 @@ async function waitForBuilder(
|
|
|
87
85
|
currentEpoch,
|
|
88
86
|
slot: clock.getCurrentSlot(),
|
|
89
87
|
});
|
|
90
|
-
await sleep(
|
|
88
|
+
await sleep(msToNextSlotPoll(clock), signal);
|
|
91
89
|
continue;
|
|
92
90
|
}
|
|
93
91
|
throw e;
|
|
@@ -101,10 +99,11 @@ async function waitForBuilder(
|
|
|
101
99
|
}
|
|
102
100
|
if (builder?.status === "pending") {
|
|
103
101
|
logger.info("Waiting for builder deposit to be finalized", {id, slot: clock.getCurrentSlot()});
|
|
102
|
+
await sleep(msToNextEpochPoll(clock), signal);
|
|
104
103
|
} else {
|
|
105
104
|
logger.info("Waiting for builder to be known to the beacon node", {id, slot: clock.getCurrentSlot()});
|
|
105
|
+
await sleep(msToNextSlotPoll(clock), signal);
|
|
106
106
|
}
|
|
107
|
-
await sleep(WAITING_FOR_BUILDER_POLL_MS, signal);
|
|
108
107
|
}
|
|
109
108
|
throw new ErrorAborted("waitForBuilder");
|
|
110
109
|
}
|
|
@@ -145,3 +144,11 @@ async function fetchBuilder(
|
|
|
145
144
|
throw e;
|
|
146
145
|
}
|
|
147
146
|
}
|
|
147
|
+
|
|
148
|
+
function msToNextEpochPoll(clock: IClock): number {
|
|
149
|
+
return clock.msToSlot(computeStartSlotAtEpoch(clock.getCurrentEpoch() + 1));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function msToNextSlotPoll(clock: IClock): number {
|
|
153
|
+
return clock.msToSlot(clock.getCurrentSlot() + 1);
|
|
154
|
+
}
|