@lodestar/builder 1.50.0-dev.6fb6c0bad4 → 1.50.0-dev.814fe8c461
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 +2 -0
- package/lib/builder.d.ts.map +1 -1
- package/lib/builder.js +56 -4
- package/lib/builder.js.map +1 -1
- package/lib/services/bidLedger.d.ts +7 -0
- package/lib/services/bidLedger.d.ts.map +1 -1
- package/lib/services/bidLedger.js +15 -10
- package/lib/services/bidLedger.js.map +1 -1
- package/lib/services/bidPublisher.d.ts +43 -0
- package/lib/services/bidPublisher.d.ts.map +1 -0
- package/lib/services/bidPublisher.js +50 -0
- package/lib/services/bidPublisher.js.map +1 -0
- package/lib/services/blockObserver.d.ts +1 -2
- package/lib/services/blockObserver.d.ts.map +1 -1
- package/lib/services/blockObserver.js +3 -35
- package/lib/services/blockObserver.js.map +1 -1
- package/lib/services/builderSigner.d.ts +2 -1
- package/lib/services/builderSigner.d.ts.map +1 -1
- package/lib/services/builderSigner.js.map +1 -1
- package/lib/services/executionPayloadBid.d.ts +57 -0
- package/lib/services/executionPayloadBid.d.ts.map +1 -0
- package/lib/services/executionPayloadBid.js +69 -0
- package/lib/services/executionPayloadBid.js.map +1 -0
- package/lib/services/proposerPreferencesTracker.d.ts +0 -6
- package/lib/services/proposerPreferencesTracker.d.ts.map +1 -1
- package/lib/services/proposerPreferencesTracker.js +0 -38
- package/lib/services/proposerPreferencesTracker.js.map +1 -1
- package/package.json +10 -10
- package/src/builder.ts +63 -5
- package/src/services/bidLedger.ts +28 -14
- package/src/services/bidPublisher.ts +95 -0
- package/src/services/blockObserver.ts +3 -41
- package/src/services/builderSigner.ts +3 -1
- package/src/services/executionPayloadBid.ts +125 -0
- package/src/services/proposerPreferencesTracker.ts +1 -36
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { INCLUSION_LIST_COMMITTEE_SIZE, isForkPostHeze } from "@lodestar/params";
|
|
2
|
+
import { sszTypesFor } from "@lodestar/types";
|
|
3
|
+
import { LodestarError, byteArrayEquals, toRootHex } from "@lodestar/utils";
|
|
4
|
+
export var ExecutionPayloadBidErrorCode;
|
|
5
|
+
(function (ExecutionPayloadBidErrorCode) {
|
|
6
|
+
ExecutionPayloadBidErrorCode["INVALID_VALUE"] = "EXECUTION_PAYLOAD_BID_ERROR_INVALID_VALUE";
|
|
7
|
+
ExecutionPayloadBidErrorCode["INVALID_GAS_LIMIT"] = "EXECUTION_PAYLOAD_BID_ERROR_INVALID_GAS_LIMIT";
|
|
8
|
+
ExecutionPayloadBidErrorCode["SLOT_MISMATCH"] = "EXECUTION_PAYLOAD_BID_ERROR_SLOT_MISMATCH";
|
|
9
|
+
ExecutionPayloadBidErrorCode["BLOCK_HASH_EQUALS_PARENT"] = "EXECUTION_PAYLOAD_BID_ERROR_BLOCK_HASH_EQUALS_PARENT";
|
|
10
|
+
ExecutionPayloadBidErrorCode["INVALID_INCLUSION_LIST_BITS"] = "EXECUTION_PAYLOAD_BID_ERROR_INVALID_INCLUSION_LIST_BITS";
|
|
11
|
+
ExecutionPayloadBidErrorCode["PREV_RANDAO_MISMATCH"] = "EXECUTION_PAYLOAD_BID_ERROR_PREV_RANDAO_MISMATCH";
|
|
12
|
+
})(ExecutionPayloadBidErrorCode || (ExecutionPayloadBidErrorCode = {}));
|
|
13
|
+
export class ExecutionPayloadBidError extends LodestarError {
|
|
14
|
+
}
|
|
15
|
+
export function createExecutionPayloadBid(input) {
|
|
16
|
+
if (!Number.isSafeInteger(input.value) || input.value < 0) {
|
|
17
|
+
throw new ExecutionPayloadBidError({ code: ExecutionPayloadBidErrorCode.INVALID_VALUE, value: input.value }, `Invalid bid value value=${input.value}`);
|
|
18
|
+
}
|
|
19
|
+
const { fork, executionPayload, executionRequests, blobsBundle } = input.payload;
|
|
20
|
+
if (executionPayload.gasLimit > Number.MAX_SAFE_INTEGER) {
|
|
21
|
+
throw new ExecutionPayloadBidError({
|
|
22
|
+
code: ExecutionPayloadBidErrorCode.INVALID_GAS_LIMIT,
|
|
23
|
+
gasLimit: executionPayload.gasLimit,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if (executionPayload.slotNumber !== input.slot) {
|
|
27
|
+
throw new ExecutionPayloadBidError({
|
|
28
|
+
code: ExecutionPayloadBidErrorCode.SLOT_MISMATCH,
|
|
29
|
+
slot: input.slot,
|
|
30
|
+
payloadSlot: executionPayload.slotNumber,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
if (byteArrayEquals(executionPayload.blockHash, executionPayload.parentHash)) {
|
|
34
|
+
throw new ExecutionPayloadBidError({ code: ExecutionPayloadBidErrorCode.BLOCK_HASH_EQUALS_PARENT });
|
|
35
|
+
}
|
|
36
|
+
if (!byteArrayEquals(executionPayload.prevRandao, input.prevRandao)) {
|
|
37
|
+
throw new ExecutionPayloadBidError({
|
|
38
|
+
code: ExecutionPayloadBidErrorCode.PREV_RANDAO_MISMATCH,
|
|
39
|
+
expectedPrevRandao: toRootHex(input.prevRandao),
|
|
40
|
+
payloadPrevRandao: toRootHex(executionPayload.prevRandao),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const bid = {
|
|
44
|
+
parentBlockHash: executionPayload.parentHash,
|
|
45
|
+
parentBlockRoot: input.parentBlockRoot,
|
|
46
|
+
blockHash: executionPayload.blockHash,
|
|
47
|
+
prevRandao: input.prevRandao,
|
|
48
|
+
feeRecipient: input.feeRecipient,
|
|
49
|
+
gasLimit: BigInt(executionPayload.gasLimit),
|
|
50
|
+
builderIndex: input.builderIndex,
|
|
51
|
+
slot: input.slot,
|
|
52
|
+
value: input.value,
|
|
53
|
+
executionPayment: 0n,
|
|
54
|
+
blobKzgCommitments: blobsBundle.commitments,
|
|
55
|
+
executionRequestsRoot: sszTypesFor(fork).ExecutionRequests.hashTreeRoot(executionRequests),
|
|
56
|
+
};
|
|
57
|
+
if (isForkPostHeze(fork)) {
|
|
58
|
+
const inclusionListBits = "inclusionListBits" in input ? input.inclusionListBits : undefined;
|
|
59
|
+
if (inclusionListBits?.bitLen !== INCLUSION_LIST_COMMITTEE_SIZE) {
|
|
60
|
+
throw new ExecutionPayloadBidError({
|
|
61
|
+
code: ExecutionPayloadBidErrorCode.INVALID_INCLUSION_LIST_BITS,
|
|
62
|
+
bitLen: inclusionListBits?.bitLen,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return { ...bid, inclusionListBits };
|
|
66
|
+
}
|
|
67
|
+
return bid;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=executionPayloadBid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executionPayloadBid.js","sourceRoot":"","sources":["../../src/services/executionPayloadBid.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,6BAA6B,EAAE,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAY7G,OAAO,EAAC,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAC,aAAa,EAAE,eAAe,EAAE,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAuB1E,MAAM,CAAN,IAAY,4BAOX;AAPD,WAAY,4BAA4B;IACtC,2FAA2D,CAAA;IAC3D,mGAAmE,CAAA;IACnE,2FAA2D,CAAA;IAC3D,iHAAiF,CAAA;IACjF,uHAAuF,CAAA;IACvF,yGAAyE,CAAA;AAC3E,CAAC,EAPW,4BAA4B,KAA5B,4BAA4B,QAOvC;AAiBD,MAAM,OAAO,wBAAyB,SAAQ,aAA2C;CAAG;AAK5F,MAAM,UAAU,yBAAyB,CAAC,KAA+B;IACvE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC;QAC1D,MAAM,IAAI,wBAAwB,CAChC,EAAC,IAAI,EAAE,4BAA4B,CAAC,aAAa,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAC,EACtE,2BAA2B,KAAK,CAAC,KAAK,EAAE,CACzC,CAAC;IACJ,CAAC;IAED,MAAM,EAAC,IAAI,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,WAAW,EAAC,GAAG,KAAK,CAAC,OAAO,CAAC;IAC/E,IAAI,gBAAgB,CAAC,QAAQ,GAAG,MAAM,CAAC,gBAAgB,EAAE,CAAC;QACxD,MAAM,IAAI,wBAAwB,CAAC;YACjC,IAAI,EAAE,4BAA4B,CAAC,iBAAiB;YACpD,QAAQ,EAAE,gBAAgB,CAAC,QAAQ;SACpC,CAAC,CAAC;IACL,CAAC;IACD,IAAI,gBAAgB,CAAC,UAAU,KAAK,KAAK,CAAC,IAAI,EAAE,CAAC;QAC/C,MAAM,IAAI,wBAAwB,CAAC;YACjC,IAAI,EAAE,4BAA4B,CAAC,aAAa;YAChD,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,WAAW,EAAE,gBAAgB,CAAC,UAAU;SACzC,CAAC,CAAC;IACL,CAAC;IACD,IAAI,eAAe,CAAC,gBAAgB,CAAC,SAAS,EAAE,gBAAgB,CAAC,UAAU,CAAC,EAAE,CAAC;QAC7E,MAAM,IAAI,wBAAwB,CAAC,EAAC,IAAI,EAAE,4BAA4B,CAAC,wBAAwB,EAAC,CAAC,CAAC;IACpG,CAAC;IACD,IAAI,CAAC,eAAe,CAAC,gBAAgB,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC;QACpE,MAAM,IAAI,wBAAwB,CAAC;YACjC,IAAI,EAAE,4BAA4B,CAAC,oBAAoB;YACvD,kBAAkB,EAAE,SAAS,CAAC,KAAK,CAAC,UAAU,CAAC;YAC/C,iBAAiB,EAAE,SAAS,CAAC,gBAAgB,CAAC,UAAU,CAAC;SAC1D,CAAC,CAAC;IACL,CAAC;IACD,MAAM,GAAG,GAA8B;QACrC,eAAe,EAAE,gBAAgB,CAAC,UAAU;QAC5C,eAAe,EAAE,KAAK,CAAC,eAAe;QACtC,SAAS,EAAE,gBAAgB,CAAC,SAAS;QACrC,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,QAAQ,EAAE,MAAM,CAAC,gBAAgB,CAAC,QAAQ,CAAC;QAC3C,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,gBAAgB,EAAE,EAAE;QACpB,kBAAkB,EAAE,WAAW,CAAC,WAAW;QAC3C,qBAAqB,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC,iBAAiB,CAAC,YAAY,CAAC,iBAAiB,CAAC;KAC3F,CAAC;IAEF,IAAI,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,MAAM,iBAAiB,GAAG,mBAAmB,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,SAAS,CAAC;QAC7F,IAAI,iBAAiB,EAAE,MAAM,KAAK,6BAA6B,EAAE,CAAC;YAChE,MAAM,IAAI,wBAAwB,CAAC;gBACjC,IAAI,EAAE,4BAA4B,CAAC,2BAA2B;gBAC9D,MAAM,EAAE,iBAAiB,EAAE,MAAM;aAClC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,EAAC,GAAG,GAAG,EAAE,iBAAiB,EAAC,CAAC;IACrC,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import { ApiClient } from "@lodestar/api";
|
|
2
1
|
import type { RootHex, Slot, gloas } from "@lodestar/types";
|
|
3
|
-
import { Logger } from "@lodestar/utils";
|
|
4
2
|
/** Retains validated proposer preferences by the branch-specific identity used for bid validation. */
|
|
5
3
|
export declare class ProposerPreferencesTracker {
|
|
6
|
-
private readonly api;
|
|
7
|
-
private readonly logger;
|
|
8
4
|
private readonly byDependentRootBySlot;
|
|
9
|
-
constructor(api: ApiClient, logger: Logger);
|
|
10
|
-
start(signal: AbortSignal): void;
|
|
11
5
|
onProposerPreferences(signedProposerPreferences: gloas.SignedProposerPreferences): boolean;
|
|
12
6
|
get(slot: Slot, dependentRoot: RootHex): gloas.SignedProposerPreferences | null;
|
|
13
7
|
prune(currentSlot: Slot): number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proposerPreferencesTracker.d.ts","sourceRoot":"","sources":["../../src/services/proposerPreferencesTracker.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"proposerPreferencesTracker.d.ts","sourceRoot":"","sources":["../../src/services/proposerPreferencesTracker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAC,MAAM,iBAAiB,CAAC;AAG1D,sGAAsG;AACtG,qBAAa,0BAA0B;IACrC,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAEpC;IAEF,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"}
|
|
@@ -1,45 +1,7 @@
|
|
|
1
|
-
import { routes } from "@lodestar/api";
|
|
2
1
|
import { MapDef, toRootHex } from "@lodestar/utils";
|
|
3
2
|
/** Retains validated proposer preferences by the branch-specific identity used for bid validation. */
|
|
4
3
|
export class ProposerPreferencesTracker {
|
|
5
|
-
api;
|
|
6
|
-
logger;
|
|
7
4
|
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
5
|
onProposerPreferences(signedProposerPreferences) {
|
|
44
6
|
const { proposalSlot, dependentRoot } = signedProposerPreferences.message;
|
|
45
7
|
const dependentRootHex = toRootHex(dependentRoot);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proposerPreferencesTracker.js","sourceRoot":"","sources":["../../src/services/proposerPreferencesTracker.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"proposerPreferencesTracker.js","sourceRoot":"","sources":["../../src/services/proposerPreferencesTracker.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAE,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAElD,sGAAsG;AACtG,MAAM,OAAO,0BAA0B;IACpB,qBAAqB,GAAG,IAAI,MAAM,CACjD,GAAG,EAAE,CAAC,IAAI,GAAG,EAAE,CAChB,CAAC;IAEF,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.50.0-dev.
|
|
3
|
+
"version": "1.50.0-dev.814fe8c461",
|
|
4
4
|
"description": "A Typescript implementation of the builder client",
|
|
5
5
|
"author": "ChainSafe Systems",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -48,16 +48,16 @@
|
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@chainsafe/lodestar-z": "catalog:",
|
|
50
50
|
"@chainsafe/ssz": "^1.8.0",
|
|
51
|
-
"@lodestar/api": "^1.50.0-dev.
|
|
52
|
-
"@lodestar/config": "^1.50.0-dev.
|
|
53
|
-
"@lodestar/params": "^1.50.0-dev.
|
|
54
|
-
"@lodestar/state-transition": "^1.50.0-dev.
|
|
55
|
-
"@lodestar/types": "^1.50.0-dev.
|
|
56
|
-
"@lodestar/utils": "^1.50.0-dev.
|
|
51
|
+
"@lodestar/api": "^1.50.0-dev.814fe8c461",
|
|
52
|
+
"@lodestar/config": "^1.50.0-dev.814fe8c461",
|
|
53
|
+
"@lodestar/params": "^1.50.0-dev.814fe8c461",
|
|
54
|
+
"@lodestar/state-transition": "^1.50.0-dev.814fe8c461",
|
|
55
|
+
"@lodestar/types": "^1.50.0-dev.814fe8c461",
|
|
56
|
+
"@lodestar/utils": "^1.50.0-dev.814fe8c461"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@lodestar/logger": "^1.50.0-dev.
|
|
60
|
-
"@lodestar/test-utils": "^1.50.0-dev.
|
|
59
|
+
"@lodestar/logger": "^1.50.0-dev.814fe8c461",
|
|
60
|
+
"@lodestar/test-utils": "^1.50.0-dev.814fe8c461"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "f8cfef9ffe414aba7e36b26e5fcfdf7c1135e7e8"
|
|
63
63
|
}
|
package/src/builder.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {ApiClient} from "@lodestar/api";
|
|
1
|
+
import {ApiClient, routes} from "@lodestar/api";
|
|
2
2
|
import {ChainForkConfig, assertEqualParams, createBeaconConfig} from "@lodestar/config";
|
|
3
3
|
import {Clock, ClockOptions, IClock} from "@lodestar/state-transition";
|
|
4
4
|
import {BuilderIndex, ExecutionAddress} from "@lodestar/types";
|
|
5
|
-
import {Logger, toHex, toRootHex} from "@lodestar/utils";
|
|
5
|
+
import {Logger, isErrorAborted, toHex, toRootHex} from "@lodestar/utils";
|
|
6
6
|
import {waitForGenesis} from "./genesis.js";
|
|
7
7
|
import {resolveBuilderIdentity} from "./identity.js";
|
|
8
8
|
import {Metrics} from "./metrics.js";
|
|
@@ -75,8 +75,7 @@ export class Builder {
|
|
|
75
75
|
this.clock.runEverySlot(async (slot) => this.onSlot(slot));
|
|
76
76
|
this.clock.runEveryEpoch((epoch) => this.builderStatusTracker.poll(epoch));
|
|
77
77
|
this.clock.start(this.controller.signal);
|
|
78
|
-
this.
|
|
79
|
-
this.proposerPreferencesTracker.start(this.controller.signal);
|
|
78
|
+
this.subscribeToEvents(opts.api);
|
|
80
79
|
|
|
81
80
|
this.logger.info("Builder client initialized", {
|
|
82
81
|
index: this.index,
|
|
@@ -114,7 +113,7 @@ export class Builder {
|
|
|
114
113
|
|
|
115
114
|
const builderStatusTracker = new BuilderStatusTracker(api, logger, index, opts.metrics);
|
|
116
115
|
const blockObserver = new BlockObserver(config, logger, api);
|
|
117
|
-
const proposerPreferencesTracker = new ProposerPreferencesTracker(
|
|
116
|
+
const proposerPreferencesTracker = new ProposerPreferencesTracker();
|
|
118
117
|
|
|
119
118
|
const payloadStore = new PayloadStore();
|
|
120
119
|
|
|
@@ -135,6 +134,65 @@ export class Builder {
|
|
|
135
134
|
this.proposerPreferencesTracker.prune(slot);
|
|
136
135
|
}
|
|
137
136
|
|
|
137
|
+
private subscribeToEvents(api: ApiClient): void {
|
|
138
|
+
const signal = this.controller.signal;
|
|
139
|
+
if (signal.aborted) return;
|
|
140
|
+
|
|
141
|
+
const topics = [routes.events.EventType.block, routes.events.EventType.proposerPreferences];
|
|
142
|
+
this.logger.verbose("Subscribing to builder events", {topics: topics.join(",")});
|
|
143
|
+
api.events
|
|
144
|
+
.eventstream({
|
|
145
|
+
topics,
|
|
146
|
+
signal,
|
|
147
|
+
onEvent: (event) => {
|
|
148
|
+
void this.onEvent(event);
|
|
149
|
+
},
|
|
150
|
+
onError: (error) => {
|
|
151
|
+
if (!signal.aborted) this.logger.error("Failed to receive builder event", {topics: topics.join(",")}, error);
|
|
152
|
+
},
|
|
153
|
+
onClose: () => {
|
|
154
|
+
if (signal.aborted) {
|
|
155
|
+
this.logger.verbose("Closed builder event stream", {topics: topics.join(",")});
|
|
156
|
+
} else {
|
|
157
|
+
this.logger.error("Builder event stream closed unexpectedly", {topics: topics.join(",")});
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
})
|
|
161
|
+
.catch((error: unknown) => {
|
|
162
|
+
if (!signal.aborted && !isErrorAborted(error)) {
|
|
163
|
+
this.logger.error(
|
|
164
|
+
"Failed to subscribe to builder events",
|
|
165
|
+
{topics: topics.join(",")},
|
|
166
|
+
error instanceof Error ? error : Error(String(error))
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
private async onEvent(event: routes.events.BeaconEvent): Promise<void> {
|
|
173
|
+
const signal = this.controller.signal;
|
|
174
|
+
if (signal.aborted) return;
|
|
175
|
+
|
|
176
|
+
try {
|
|
177
|
+
switch (event.type) {
|
|
178
|
+
case routes.events.EventType.block:
|
|
179
|
+
await this.blockObserver.processBlockEvent(event.message, signal);
|
|
180
|
+
break;
|
|
181
|
+
case routes.events.EventType.proposerPreferences:
|
|
182
|
+
this.proposerPreferencesTracker.onProposerPreferences(event.message.data);
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
} catch (error) {
|
|
186
|
+
if (!signal.aborted && !isErrorAborted(error)) {
|
|
187
|
+
this.logger.warn(
|
|
188
|
+
"Failed to process builder event",
|
|
189
|
+
{eventType: event.type},
|
|
190
|
+
error instanceof Error ? error : Error(String(error))
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
138
196
|
async close(): Promise<void> {
|
|
139
197
|
this.controller.abort();
|
|
140
198
|
}
|
|
@@ -32,6 +32,7 @@ type MutableBidLedgerRecord = SubmittedBid & {
|
|
|
32
32
|
export enum BidLedgerErrorCode {
|
|
33
33
|
INVALID_BID_VALUE = "BID_LEDGER_ERROR_INVALID_BID_VALUE",
|
|
34
34
|
DUPLICATE_BID = "BID_LEDGER_ERROR_DUPLICATE_BID",
|
|
35
|
+
BID_TOO_OLD = "BID_LEDGER_ERROR_BID_TOO_OLD",
|
|
35
36
|
REVEAL_CONFLICT = "BID_LEDGER_ERROR_REVEAL_CONFLICT",
|
|
36
37
|
UNSETTLED_VALUE_OVERFLOW = "BID_LEDGER_ERROR_UNSETTLED_VALUE_OVERFLOW",
|
|
37
38
|
}
|
|
@@ -47,6 +48,11 @@ export type BidLedgerErrorType =
|
|
|
47
48
|
parentBlockHash: RootHex;
|
|
48
49
|
parentBlockRoot: RootHex;
|
|
49
50
|
}
|
|
51
|
+
| {
|
|
52
|
+
code: BidLedgerErrorCode.BID_TOO_OLD;
|
|
53
|
+
slot: Slot;
|
|
54
|
+
pruneCutoffSlot: Slot;
|
|
55
|
+
}
|
|
50
56
|
| {
|
|
51
57
|
code: BidLedgerErrorCode.REVEAL_CONFLICT;
|
|
52
58
|
blockRoot: RootHex;
|
|
@@ -69,11 +75,28 @@ const KEEP_SLOTS = RECORD_RETENTION_EPOCHS * SLOTS_PER_EPOCH;
|
|
|
69
75
|
export class BidLedger {
|
|
70
76
|
private readonly bidsBySlot = new Map<Slot, Map<string, MutableBidLedgerRecord>>();
|
|
71
77
|
private readonly revealedPayloadByBlockRoot = new Map<RootHex, RevealedPayload>();
|
|
78
|
+
private pruneCutoffSlot = 0;
|
|
72
79
|
|
|
73
80
|
hasSubmitted(slot: Slot, parentBlockHash: RootHex, parentBlockRoot: RootHex): boolean {
|
|
74
81
|
return this.bidsBySlot.get(slot)?.has(tupleKey(parentBlockHash, parentBlockRoot)) ?? false;
|
|
75
82
|
}
|
|
76
83
|
|
|
84
|
+
assertCanRecordBid({
|
|
85
|
+
slot,
|
|
86
|
+
parentBlockHash,
|
|
87
|
+
parentBlockRoot,
|
|
88
|
+
}: Pick<SubmittedBid, "slot" | "parentBlockHash" | "parentBlockRoot">): void {
|
|
89
|
+
if (slot < this.pruneCutoffSlot) {
|
|
90
|
+
throw new BidLedgerError({code: BidLedgerErrorCode.BID_TOO_OLD, slot, pruneCutoffSlot: this.pruneCutoffSlot});
|
|
91
|
+
}
|
|
92
|
+
if (this.hasSubmitted(slot, parentBlockHash, parentBlockRoot)) {
|
|
93
|
+
throw new BidLedgerError(
|
|
94
|
+
{code: BidLedgerErrorCode.DUPLICATE_BID, slot, parentBlockHash, parentBlockRoot},
|
|
95
|
+
`Bid already recorded slot=${slot} parentBlockHash=${parentBlockHash} parentBlockRoot=${parentBlockRoot}`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
77
100
|
recordBid(bid: SubmittedBid): BidLedgerRecord {
|
|
78
101
|
if (!Number.isSafeInteger(bid.valueGwei) || bid.valueGwei < 0) {
|
|
79
102
|
throw new BidLedgerError(
|
|
@@ -82,6 +105,7 @@ export class BidLedger {
|
|
|
82
105
|
);
|
|
83
106
|
}
|
|
84
107
|
|
|
108
|
+
this.assertCanRecordBid(bid);
|
|
85
109
|
let bidsForSlot = this.bidsBySlot.get(bid.slot);
|
|
86
110
|
if (bidsForSlot === undefined) {
|
|
87
111
|
bidsForSlot = new Map();
|
|
@@ -89,18 +113,6 @@ export class BidLedger {
|
|
|
89
113
|
}
|
|
90
114
|
|
|
91
115
|
const key = tupleKey(bid.parentBlockHash, bid.parentBlockRoot);
|
|
92
|
-
if (bidsForSlot.has(key)) {
|
|
93
|
-
throw new BidLedgerError(
|
|
94
|
-
{
|
|
95
|
-
code: BidLedgerErrorCode.DUPLICATE_BID,
|
|
96
|
-
slot: bid.slot,
|
|
97
|
-
parentBlockHash: bid.parentBlockHash,
|
|
98
|
-
parentBlockRoot: bid.parentBlockRoot,
|
|
99
|
-
},
|
|
100
|
-
`Bid already recorded slot=${bid.slot} parentBlockHash=${bid.parentBlockHash} parentBlockRoot=${bid.parentBlockRoot}`
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
116
|
const record = {...bid, wonBlockRoots: new Set<RootHex>(), paymentSettled: false};
|
|
105
117
|
bidsForSlot.set(key, record);
|
|
106
118
|
return toRecord(record);
|
|
@@ -198,9 +210,11 @@ export class BidLedger {
|
|
|
198
210
|
}
|
|
199
211
|
|
|
200
212
|
prune(currentSlot: Slot): number {
|
|
213
|
+
// Pruning must not make an expired slot eligible for another submission.
|
|
214
|
+
this.pruneCutoffSlot = Math.max(this.pruneCutoffSlot, currentSlot - KEEP_SLOTS);
|
|
201
215
|
let removed = 0;
|
|
202
216
|
for (const [slot, bidsForSlot] of this.bidsBySlot) {
|
|
203
|
-
if (slot >=
|
|
217
|
+
if (slot >= this.pruneCutoffSlot) {
|
|
204
218
|
continue;
|
|
205
219
|
}
|
|
206
220
|
|
|
@@ -216,7 +230,7 @@ export class BidLedger {
|
|
|
216
230
|
}
|
|
217
231
|
|
|
218
232
|
for (const [blockRoot, revealedPayload] of this.revealedPayloadByBlockRoot) {
|
|
219
|
-
if (revealedPayload.slot <
|
|
233
|
+
if (revealedPayload.slot < this.pruneCutoffSlot) {
|
|
220
234
|
this.revealedPayloadByBlockRoot.delete(blockRoot);
|
|
221
235
|
}
|
|
222
236
|
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type {ApiClient} from "@lodestar/api";
|
|
2
|
+
import type {ChainForkConfig} from "@lodestar/config";
|
|
3
|
+
import {isForkPostGloas} from "@lodestar/params";
|
|
4
|
+
import type {BuilderIndex, RootHex, Slot, gloas, heze} from "@lodestar/types";
|
|
5
|
+
import {sszTypesFor} from "@lodestar/types";
|
|
6
|
+
import {LodestarError, toRootHex} from "@lodestar/utils";
|
|
7
|
+
import type {BidIdentity, BidLedger} from "./bidLedger.js";
|
|
8
|
+
import type {BuilderSigner} from "./builderSigner.js";
|
|
9
|
+
|
|
10
|
+
export type BidPublisherModules = {
|
|
11
|
+
api: ApiClient;
|
|
12
|
+
config: ChainForkConfig;
|
|
13
|
+
signer: BuilderSigner;
|
|
14
|
+
ledger: BidLedger;
|
|
15
|
+
builderIndex: BuilderIndex;
|
|
16
|
+
hasPayload: (identity: BidIdentity) => boolean;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export enum BidPublisherErrorCode {
|
|
20
|
+
BUILDER_INDEX_MISMATCH = "BID_PUBLISHER_ERROR_BUILDER_INDEX_MISMATCH",
|
|
21
|
+
PAYLOAD_NOT_RETAINED = "BID_PUBLISHER_ERROR_PAYLOAD_NOT_RETAINED",
|
|
22
|
+
PRE_GLOAS_BID = "BID_PUBLISHER_ERROR_PRE_GLOAS_BID",
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type BidPublisherErrorType =
|
|
26
|
+
| {
|
|
27
|
+
code: BidPublisherErrorCode.PRE_GLOAS_BID;
|
|
28
|
+
slot: Slot;
|
|
29
|
+
}
|
|
30
|
+
| {
|
|
31
|
+
code: BidPublisherErrorCode.BUILDER_INDEX_MISMATCH;
|
|
32
|
+
builderIndex: BuilderIndex;
|
|
33
|
+
bidBuilderIndex: BuilderIndex;
|
|
34
|
+
}
|
|
35
|
+
| {
|
|
36
|
+
code: BidPublisherErrorCode.PAYLOAD_NOT_RETAINED;
|
|
37
|
+
slot: Slot;
|
|
38
|
+
parentBlockHash: RootHex;
|
|
39
|
+
parentBlockRoot: RootHex;
|
|
40
|
+
blockHash: RootHex;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export class BidPublisherError extends LodestarError<BidPublisherErrorType> {}
|
|
44
|
+
|
|
45
|
+
/** Signs and submits a bid only if its payload is retained locally. */
|
|
46
|
+
export class BidPublisher {
|
|
47
|
+
constructor(private readonly modules: BidPublisherModules) {}
|
|
48
|
+
|
|
49
|
+
publish(bid: heze.ExecutionPayloadBid, signal: AbortSignal): Promise<heze.SignedExecutionPayloadBid>;
|
|
50
|
+
publish(bid: gloas.ExecutionPayloadBid, signal: AbortSignal): Promise<gloas.SignedExecutionPayloadBid>;
|
|
51
|
+
async publish(bid: gloas.ExecutionPayloadBid, signal: AbortSignal): Promise<gloas.SignedExecutionPayloadBid> {
|
|
52
|
+
signal.throwIfAborted();
|
|
53
|
+
|
|
54
|
+
const {api, config, builderIndex, hasPayload, ledger, signer} = this.modules;
|
|
55
|
+
const fork = config.getForkName(bid.slot);
|
|
56
|
+
if (!isForkPostGloas(fork)) {
|
|
57
|
+
throw new BidPublisherError({code: BidPublisherErrorCode.PRE_GLOAS_BID, slot: bid.slot});
|
|
58
|
+
}
|
|
59
|
+
if (bid.builderIndex !== builderIndex) {
|
|
60
|
+
throw new BidPublisherError(
|
|
61
|
+
{
|
|
62
|
+
code: BidPublisherErrorCode.BUILDER_INDEX_MISMATCH,
|
|
63
|
+
builderIndex,
|
|
64
|
+
bidBuilderIndex: bid.builderIndex,
|
|
65
|
+
},
|
|
66
|
+
`Bid builder index does not match local builder index builderIndex=${builderIndex} bidBuilderIndex=${bid.builderIndex}`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const identity: BidIdentity = {
|
|
71
|
+
slot: bid.slot,
|
|
72
|
+
parentBlockHash: toRootHex(bid.parentBlockHash),
|
|
73
|
+
parentBlockRoot: toRootHex(bid.parentBlockRoot),
|
|
74
|
+
blockHash: toRootHex(bid.blockHash),
|
|
75
|
+
};
|
|
76
|
+
if (!hasPayload(identity)) {
|
|
77
|
+
throw new BidPublisherError(
|
|
78
|
+
{code: BidPublisherErrorCode.PAYLOAD_NOT_RETAINED, ...identity},
|
|
79
|
+
`Bid payload is not retained slot=${identity.slot} parentBlockHash=${identity.parentBlockHash} parentBlockRoot=${identity.parentBlockRoot} blockHash=${identity.blockHash}`
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
ledger.assertCanRecordBid(identity);
|
|
84
|
+
|
|
85
|
+
const signedExecutionPayloadBid = signer.signExecutionPayloadBid(bid);
|
|
86
|
+
const signedBidRoot = toRootHex(
|
|
87
|
+
sszTypesFor(fork, "SignedExecutionPayloadBid").hashTreeRoot(signedExecutionPayloadBid)
|
|
88
|
+
);
|
|
89
|
+
ledger.recordBid({...identity, valueGwei: bid.value, signedBidRoot});
|
|
90
|
+
|
|
91
|
+
const response = await api.beacon.publishExecutionPayloadBid({signedExecutionPayloadBid}, {signal});
|
|
92
|
+
response.assertOk();
|
|
93
|
+
return signedExecutionPayloadBid;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -47,55 +47,17 @@ export class BlockObserver {
|
|
|
47
47
|
this.retries = retries;
|
|
48
48
|
this.retryDelay = retryDelay;
|
|
49
49
|
this.maxSeenBlockRoots = maxSeenBlockRoots;
|
|
50
|
+
this.logger.info("Block observer initialized", {retries, retryDelay, maxSeenBlockRoots});
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
/**
|
|
53
|
-
* Register a block consumer. Consumers that require complete observation must register before
|
|
54
|
+
* Register a block consumer. Consumers that require complete observation must register before event delivery, because
|
|
54
55
|
* roots observed before registration remain consumed until normal FIFO eviction.
|
|
55
56
|
*/
|
|
56
57
|
runOnBlock(fn: RunOnBlockFn): void {
|
|
57
58
|
this.fns.push(fn);
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
start(signal: AbortSignal): void {
|
|
61
|
-
this.logger.info("Subscribing to block events", {
|
|
62
|
-
retries: this.retries,
|
|
63
|
-
retryDelay: this.retryDelay,
|
|
64
|
-
maxSeenBlockRoots: this.maxSeenBlockRoots,
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
this.api.events
|
|
68
|
-
.eventstream({
|
|
69
|
-
topics: [EventType.block],
|
|
70
|
-
signal,
|
|
71
|
-
onEvent: (event) => {
|
|
72
|
-
if (event.type !== EventType.block) {
|
|
73
|
-
this.logger.debug("Ignoring unexpected beacon event", {eventType: event.type});
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
void this.processBlockEvent(event.message, signal);
|
|
78
|
-
},
|
|
79
|
-
onError: (error) => {
|
|
80
|
-
this.logger.error("Failed to receive block event", {}, error);
|
|
81
|
-
},
|
|
82
|
-
onClose: () => {
|
|
83
|
-
if (signal.aborted) {
|
|
84
|
-
this.logger.debug("Closed stream for block events");
|
|
85
|
-
} else {
|
|
86
|
-
this.logger.error("Block event stream closed unexpectedly", {});
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
})
|
|
90
|
-
.catch((error: unknown) => {
|
|
91
|
-
this.logger.error(
|
|
92
|
-
"Failed to subscribe to block events",
|
|
93
|
-
{},
|
|
94
|
-
error instanceof Error ? error : Error(String(error))
|
|
95
|
-
);
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
61
|
async processBlockEvent(event: BlockEvent, signal: AbortSignal): Promise<void> {
|
|
100
62
|
try {
|
|
101
63
|
const {slot, block: blockRoot, executionOptimistic} = event;
|
|
@@ -145,7 +107,7 @@ export class BlockObserver {
|
|
|
145
107
|
return null;
|
|
146
108
|
});
|
|
147
109
|
|
|
148
|
-
if (response === null) {
|
|
110
|
+
if (response === null || signal.aborted) {
|
|
149
111
|
return;
|
|
150
112
|
}
|
|
151
113
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {PublicKey, SecretKey} from "@chainsafe/lodestar-z/blst";
|
|
2
2
|
import {BeaconConfig} from "@lodestar/config";
|
|
3
3
|
import {getExecutionPayloadBidSigningRoot, getExecutionPayloadEnvelopeSigningRoot} from "@lodestar/state-transition";
|
|
4
|
-
import {gloas} from "@lodestar/types";
|
|
4
|
+
import {gloas, heze} from "@lodestar/types";
|
|
5
5
|
|
|
6
6
|
export type Keypair = {publicKey: PublicKey; secretKey: SecretKey};
|
|
7
7
|
|
|
@@ -23,6 +23,8 @@ export class BuilderSigner {
|
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
signExecutionPayloadBid(bid: heze.ExecutionPayloadBid): heze.SignedExecutionPayloadBid;
|
|
27
|
+
signExecutionPayloadBid(bid: gloas.ExecutionPayloadBid): gloas.SignedExecutionPayloadBid;
|
|
26
28
|
signExecutionPayloadBid(bid: gloas.ExecutionPayloadBid): gloas.SignedExecutionPayloadBid {
|
|
27
29
|
const signingRoot = getExecutionPayloadBidSigningRoot(this.config, bid);
|
|
28
30
|
|