@lodestar/builder 1.48.0-dev.30d2b0bf52 → 1.48.0-dev.386c085495

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 CHANGED
@@ -6,12 +6,14 @@ import { Logger } from "@lodestar/utils";
6
6
  import { Metrics } from "./metrics.js";
7
7
  import { BuilderSigner, Keypair } from "./services/builderSigner.js";
8
8
  import { BuilderStatusTracker } from "./services/builderStatusTracker.js";
9
+ import { PayloadStore } from "./services/payloadStore.js";
9
10
  export type BuilderModules = {
10
11
  opts: BuilderOptions;
11
12
  builderSigner: BuilderSigner;
12
13
  builderStatusTracker: BuilderStatusTracker;
13
14
  clock: IClock;
14
15
  index: BuilderIndex;
16
+ store: PayloadStore;
15
17
  };
16
18
  export type BuilderOptions = {
17
19
  logger: Logger;
@@ -34,8 +36,10 @@ export declare class Builder {
34
36
  private readonly index;
35
37
  private readonly logger;
36
38
  private readonly executionFeeRecipient;
37
- constructor({ opts, builderSigner, builderStatusTracker, clock, index }: BuilderModules);
39
+ private readonly store;
40
+ constructor({ opts, builderSigner, builderStatusTracker, clock, index, store }: BuilderModules);
38
41
  static init(opts: BuilderOptions): Promise<Builder>;
42
+ private onSlot;
39
43
  close(): Promise<void>;
40
44
  }
41
45
  //# sourceMappingURL=builder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,eAAe,CAAC;AACxC,OAAO,EAAC,eAAe,EAAwC,MAAM,kBAAkB,CAAC;AACxF,OAAO,EAAQ,YAAY,EAAE,MAAM,EAAC,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAC,YAAY,EAAE,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAC,MAAM,EAAmB,MAAM,iBAAiB,CAAC;AAGzD,OAAO,EAAC,OAAO,EAAC,MAA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,CAAC,UAAU,CAAkB;IAC7C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;IACrC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAmB;IACzD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;IAErC,YAAY,EAAC,IAAI,EAAE,aAAa,EAAE,oBAAoB,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAC,EAAE,cAAc,EAmB3F;IAED,OAAa,IAAI,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAiCxD;YAEa,MAAM;IAId,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAE3B;CACF"}
package/lib/builder.js CHANGED
@@ -6,6 +6,7 @@ import { resolveBuilderIdentity } from "./identity.js";
6
6
  import { logNodeVersion, waitForNodeReady } from "./readiness.js";
7
7
  import { BuilderSigner } from "./services/builderSigner.js";
8
8
  import { BuilderStatusTracker } from "./services/builderStatusTracker.js";
9
+ import { PayloadStore } from "./services/payloadStore.js";
9
10
  /**
10
11
  * Main class for the Builder client.
11
12
  */
@@ -17,14 +18,17 @@ export class Builder {
17
18
  index;
18
19
  logger;
19
20
  executionFeeRecipient;
20
- constructor({ opts, builderSigner, builderStatusTracker, clock, index }) {
21
+ store;
22
+ constructor({ opts, builderSigner, builderStatusTracker, clock, index, store }) {
21
23
  this.builderSigner = builderSigner;
22
24
  this.builderStatusTracker = builderStatusTracker;
23
25
  this.clock = clock;
24
26
  this.controller = opts.abortController;
25
27
  this.logger = opts.logger;
26
28
  this.index = index;
29
+ this.store = store;
27
30
  this.executionFeeRecipient = opts.executionFeeRecipient;
31
+ this.clock.runEverySlot(async (slot) => this.onSlot(slot));
28
32
  this.clock.runEveryEpoch((epoch) => this.builderStatusTracker.poll(epoch));
29
33
  this.clock.start(this.controller.signal);
30
34
  this.logger.info("Builder client initialized", {
@@ -48,7 +52,11 @@ export class Builder {
48
52
  const clock = new Clock(config, logger, { genesisTime: Number(genesis.genesisTime), ...opts.clock });
49
53
  const index = await resolveBuilderIdentity(api, logger, builderSigner.getPubkeyHex(), opts.abortController.signal, clock, config);
50
54
  const builderStatusTracker = new BuilderStatusTracker(api, logger, index, opts.metrics);
51
- return new Builder({ opts, builderSigner, builderStatusTracker, clock, index });
55
+ const store = new PayloadStore();
56
+ return new Builder({ opts, builderSigner, builderStatusTracker, clock, index, store });
57
+ }
58
+ async onSlot(slot) {
59
+ this.store.prune(slot);
52
60
  }
53
61
  async close() {
54
62
  this.controller.abort();
@@ -1 +1 @@
1
- {"version":3,"file":"builder.js","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,iBAAiB,EAAE,kBAAkB,EAAC,MAAM,kBAAkB,CAAC;AACxF,OAAO,EAAC,KAAK,EAAuB,MAAM,4BAA4B,CAAC;AAEvE,OAAO,EAAS,KAAK,EAAE,SAAS,EAAC,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAC,cAAc,EAAC,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAC,sBAAsB,EAAC,MAAM,eAAe,CAAC;AAErD,OAAO,EAAC,cAAc,EAAE,gBAAgB,EAAC,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAC,aAAa,EAAU,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAC,oBAAoB,EAAC,MAAM,oCAAoC,CAAC;AAqBxE;;GAEG;AACH,MAAM,OAAO,OAAO;IACT,aAAa,CAAgB;IACrB,oBAAoB,CAAuB;IAC3C,UAAU,CAAkB;IAC5B,KAAK,CAAS;IACd,KAAK,CAAe;IACpB,MAAM,CAAS;IACf,qBAAqB,CAAmB;IAEzD,YAAY,EAAC,IAAI,EAAE,aAAa,EAAE,oBAAoB,EAAE,KAAK,EAAE,KAAK,EAAiB;QACnF,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,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AAM,EAAE,EAAC,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,GAAG,IAAI,CAAC,KAAK,EAAC,CAAC,CAAC;QAEnG,MAAM,KAAK,GAAG,MAAM,sBAAsB,CACxC,GAAG,EACH,MAAM,EACN,aAAa,CAAC,YAAY,EAAE,EAC5B,IAAI,CAAC,eAAe,CAAC,MAAM,EAC3B,KAAK,EACL,MAAM,CACP,CAAC;QAEF,MAAM,oBAAoB,GAAG,IAAI,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAExF,MAAM,KAAK,GAAG,IAAI,YAAY,EAAE,CAAC;QAEjC,OAAO,IAAI,OAAO,CAAC,EAAC,IAAI,EAAE,aAAa,EAAE,oBAAoB,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAC,CAAC,CAAC;IACvF,CAAC;IAEO,KAAK,CAAC,MAAM,CAAC,IAAY;QAC/B,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;CACF"}
package/lib/identity.d.ts CHANGED
@@ -3,7 +3,6 @@ import { ChainForkConfig } from "@lodestar/config";
3
3
  import { IClock } from "@lodestar/state-transition";
4
4
  import { BuilderIndex, BuilderStatus } from "@lodestar/types";
5
5
  import { Logger } from "@lodestar/utils";
6
- export declare const WAITING_FOR_BUILDER_POLL_MS: number;
7
6
  export declare function resolveBuilderIdentity(api: ApiClient, logger: Logger, id: routes.beacon.BuilderId, signal: AbortSignal, clock: IClock, config: ChainForkConfig): Promise<BuilderIndex>;
8
7
  export declare function getBuilderStatus(api: ApiClient, logger: Logger, id: routes.beacon.BuilderId): Promise<{
9
8
  status: BuilderStatus;
@@ -1 +1 @@
1
- {"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src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,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,EAC3B,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,YAAY,CAAC,CAgBvB;AAED,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,SAAS,EACd,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,GAC1B,OAAO,CAAC;IAAC,MAAM,EAAE,aAAa,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAC,GAAG,IAAI,CAAC,CAe1D"}
package/lib/identity.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ApiError, HttpStatusCode } from "@lodestar/api";
2
2
  import { PAYLOAD_BUILDER_VERSION } from "@lodestar/params";
3
+ import { computeStartSlotAtEpoch } from "@lodestar/state-transition";
3
4
  import { ErrorAborted, TimeoutError, isFetchError, sleep, toHex } from "@lodestar/utils";
4
- export const WAITING_FOR_BUILDER_POLL_MS = 10 * 1000;
5
5
  export async function resolveBuilderIdentity(api, logger, id, signal, clock, config) {
6
6
  const builderEntry = await waitForBuilder(api, logger, id, signal, clock, config);
7
7
  if (builderEntry.builder.version !== PAYLOAD_BUILDER_VERSION) {
@@ -44,7 +44,7 @@ async function waitForBuilder(api, logger, id, signal, clock, config) {
44
44
  currentEpoch,
45
45
  slot: clock.getCurrentSlot(),
46
46
  });
47
- await sleep(WAITING_FOR_BUILDER_POLL_MS, signal);
47
+ await sleep(msToNextEpochPoll(clock), signal);
48
48
  continue;
49
49
  }
50
50
  let builder = null;
@@ -60,7 +60,7 @@ async function waitForBuilder(api, logger, id, signal, clock, config) {
60
60
  currentEpoch,
61
61
  slot: clock.getCurrentSlot(),
62
62
  });
63
- await sleep(WAITING_FOR_BUILDER_POLL_MS, signal);
63
+ await sleep(msToNextSlotPoll(clock), signal);
64
64
  continue;
65
65
  }
66
66
  throw e;
@@ -73,11 +73,12 @@ async function waitForBuilder(api, logger, id, signal, clock, config) {
73
73
  }
74
74
  if (builder?.status === "pending") {
75
75
  logger.info("Waiting for builder deposit to be finalized", { id, slot: clock.getCurrentSlot() });
76
+ await sleep(msToNextEpochPoll(clock), signal);
76
77
  }
77
78
  else {
78
79
  logger.info("Waiting for builder to be known to the beacon node", { id, slot: clock.getCurrentSlot() });
80
+ await sleep(msToNextSlotPoll(clock), signal);
79
81
  }
80
- await sleep(WAITING_FOR_BUILDER_POLL_MS, signal);
81
82
  }
82
83
  throw new ErrorAborted("waitForBuilder");
83
84
  }
@@ -110,4 +111,10 @@ async function fetchBuilder(api, logger, id) {
110
111
  throw e;
111
112
  }
112
113
  }
114
+ function msToNextEpochPoll(clock) {
115
+ return clock.msToSlot(computeStartSlotAtEpoch(clock.getCurrentEpoch() + 1));
116
+ }
117
+ function msToNextSlotPoll(clock) {
118
+ return clock.msToSlot(clock.getCurrentSlot() + 1);
119
+ }
113
120
  //# sourceMappingURL=identity.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"identity.js","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,QAAQ,EAAE,cAAc,EAAS,MAAM,eAAe,CAAC;AAE1E,OAAO,EAAC,uBAAuB,EAAC,MAAM,kBAAkB,CAAC;AAGzD,OAAO,EAAC,YAAY,EAAU,YAAY,EAAE,YAAY,EAAE,KAAK,EAAE,KAAK,EAAC,MAAM,iBAAiB,CAAC;AAE/F,MAAM,CAAC,MAAM,2BAA2B,GAAG,EAAE,GAAG,IAAI,CAAC;AAErD,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,GAAc,EACd,MAAc,EACd,EAA2B,EAC3B,MAAmB,EACnB,KAAa,EACb,MAAuB;IAEvB,MAAM,YAAY,GAAG,MAAM,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IAElF,IAAI,YAAY,CAAC,OAAO,CAAC,OAAO,KAAK,uB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OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,CAAC,CAAC;IACV,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAa;IACtC,OAAO,KAAK,CAAC,QAAQ,CAAC,uBAAuB,CAAC,KAAK,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAa;IACrC,OAAO,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC,CAAC;AACpD,CAAC"}
@@ -0,0 +1,61 @@
1
+ import type { Epoch, RootHex, Slot } from "@lodestar/types";
2
+ import { LodestarError } from "@lodestar/utils";
3
+ export type SubmittedBid = {
4
+ slot: Slot;
5
+ parentBlockHash: RootHex;
6
+ parentBlockRoot: RootHex;
7
+ blockHash: RootHex;
8
+ valueGwei: number;
9
+ signedBidRoot: RootHex;
10
+ };
11
+ export type BidIdentity = Pick<SubmittedBid, "slot" | "parentBlockHash" | "parentBlockRoot" | "blockHash">;
12
+ export type BidLedgerRecord = SubmittedBid & {
13
+ wonBlockRoots: RootHex[];
14
+ };
15
+ export declare enum BidLedgerErrorCode {
16
+ INVALID_BID_VALUE = "BID_LEDGER_ERROR_INVALID_BID_VALUE",
17
+ DUPLICATE_BID = "BID_LEDGER_ERROR_DUPLICATE_BID",
18
+ REVEAL_CONFLICT = "BID_LEDGER_ERROR_REVEAL_CONFLICT",
19
+ UNSETTLED_VALUE_OVERFLOW = "BID_LEDGER_ERROR_UNSETTLED_VALUE_OVERFLOW"
20
+ }
21
+ export type BidLedgerErrorType = {
22
+ code: BidLedgerErrorCode.INVALID_BID_VALUE;
23
+ valueGwei: number;
24
+ } | {
25
+ code: BidLedgerErrorCode.DUPLICATE_BID;
26
+ slot: Slot;
27
+ parentBlockHash: RootHex;
28
+ parentBlockRoot: RootHex;
29
+ } | {
30
+ code: BidLedgerErrorCode.REVEAL_CONFLICT;
31
+ blockRoot: RootHex;
32
+ blockHash: RootHex;
33
+ revealedBlockHash: RootHex;
34
+ envelopeRoot: RootHex;
35
+ revealedEnvelopeRoot: RootHex;
36
+ } | {
37
+ code: BidLedgerErrorCode.UNSETTLED_VALUE_OVERFLOW;
38
+ currentEpoch: Epoch;
39
+ };
40
+ export declare class BidLedgerError extends LodestarError<BidLedgerErrorType> {
41
+ }
42
+ /** Tracks at most one bid per (slot, parentBlockHash, parentBlockRoot) and its reveal obligations. */
43
+ export declare class BidLedger {
44
+ private readonly bidsBySlot;
45
+ private readonly revealedPayloadByBlockRoot;
46
+ hasSubmitted(slot: Slot, parentBlockHash: RootHex, parentBlockRoot: RootHex): boolean;
47
+ recordBid(bid: SubmittedBid): BidLedgerRecord;
48
+ recordWin(identity: BidIdentity & Pick<SubmittedBid, "signedBidRoot">, blockRoot: RootHex): BidLedgerRecord | null;
49
+ /** Release a winning bid liability only after its payment is known to be reflected in Builder balance. */
50
+ recordPaymentSettled(identity: BidIdentity): BidLedgerRecord | null;
51
+ canReveal(blockRoot: RootHex, blockHash: RootHex, envelopeRoot: RootHex): boolean;
52
+ hasRevealed(blockRoot: RootHex): boolean;
53
+ hasPublishedReveal(blockRoot: RootHex): boolean;
54
+ recordReveal(slot: Slot, blockRoot: RootHex, blockHash: RootHex, envelopeRoot: RootHex): void;
55
+ recordRevealPublished(slot: Slot, blockRoot: RootHex, blockHash: RootHex, envelopeRoot: RootHex): void;
56
+ getUnsettledValueGwei(currentEpoch: Epoch): number;
57
+ getBidsForSlot(slot: Slot): BidLedgerRecord[];
58
+ prune(currentSlot: Slot): number;
59
+ private getBid;
60
+ }
61
+ //# sourceMappingURL=bidLedger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bidLedger.d.ts","sourceRoot":"","sources":["../../src/services/bidLedger.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAC,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAC,aAAa,E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var BidLedgerErrorCode;
4
+ (function (BidLedgerErrorCode) {
5
+ BidLedgerErrorCode["INVALID_BID_VALUE"] = "BID_LEDGER_ERROR_INVALID_BID_VALUE";
6
+ BidLedgerErrorCode["DUPLICATE_BID"] = "BID_LEDGER_ERROR_DUPLICATE_BID";
7
+ BidLedgerErrorCode["REVEAL_CONFLICT"] = "BID_LEDGER_ERROR_REVEAL_CONFLICT";
8
+ BidLedgerErrorCode["UNSETTLED_VALUE_OVERFLOW"] = "BID_LEDGER_ERROR_UNSETTLED_VALUE_OVERFLOW";
9
+ })(BidLedgerErrorCode || (BidLedgerErrorCode = {}));
10
+ export class BidLedgerError extends LodestarError {
11
+ }
12
+ const RECORD_RETENTION_EPOCHS = 3;
13
+ const KEEP_SLOTS = RECORD_RETENTION_EPOCHS * SLOTS_PER_EPOCH;
14
+ /** Tracks at most one bid per (slot, parentBlockHash, parentBlockRoot) and its reveal obligations. */
15
+ export class BidLedger {
16
+ bidsBySlot = new Map();
17
+ revealedPayloadByBlockRoot = new Map();
18
+ hasSubmitted(slot, parentBlockHash, parentBlockRoot) {
19
+ return this.bidsBySlot.get(slot)?.has(tupleKey(parentBlockHash, parentBlockRoot)) ?? false;
20
+ }
21
+ recordBid(bid) {
22
+ if (!Number.isSafeInteger(bid.valueGwei) || bid.valueGwei < 0) {
23
+ throw new BidLedgerError({ code: BidLedgerErrorCode.INVALID_BID_VALUE, valueGwei: bid.valueGwei }, `Invalid bid value valueGwei=${bid.valueGwei}`);
24
+ }
25
+ let bidsForSlot = this.bidsBySlot.get(bid.slot);
26
+ if (bidsForSlot === undefined) {
27
+ bidsForSlot = new Map();
28
+ this.bidsBySlot.set(bid.slot, bidsForSlot);
29
+ }
30
+ const key = tupleKey(bid.parentBlockHash, bid.parentBlockRoot);
31
+ if (bidsForSlot.has(key)) {
32
+ throw new BidLedgerError({
33
+ code: BidLedgerErrorCode.DUPLICATE_BID,
34
+ slot: bid.slot,
35
+ parentBlockHash: bid.parentBlockHash,
36
+ parentBlockRoot: bid.parentBlockRoot,
37
+ }, `Bid already recorded slot=${bid.slot} parentBlockHash=${bid.parentBlockHash} parentBlockRoot=${bid.parentBlockRoot}`);
38
+ }
39
+ const record = { ...bid, wonBlockRoots: new Set(), paymentSettled: false };
40
+ bidsForSlot.set(key, record);
41
+ return toRecord(record);
42
+ }
43
+ recordWin(identity, blockRoot) {
44
+ const record = this.getBid(identity.slot, identity.parentBlockHash, identity.parentBlockRoot);
45
+ if (record === null || record.blockHash !== identity.blockHash || record.signedBidRoot !== identity.signedBidRoot) {
46
+ return null;
47
+ }
48
+ record.wonBlockRoots.add(blockRoot);
49
+ return toRecord(record);
50
+ }
51
+ /** Release a winning bid liability only after its payment is known to be reflected in Builder balance. */
52
+ recordPaymentSettled(identity) {
53
+ const record = this.getBid(identity.slot, identity.parentBlockHash, identity.parentBlockRoot);
54
+ if (record === null || record.blockHash !== identity.blockHash || record.wonBlockRoots.size === 0) {
55
+ return null;
56
+ }
57
+ record.paymentSettled = true;
58
+ return toRecord(record);
59
+ }
60
+ canReveal(blockRoot, blockHash, envelopeRoot) {
61
+ const revealedPayload = this.revealedPayloadByBlockRoot.get(blockRoot);
62
+ return (revealedPayload === undefined ||
63
+ (revealedPayload.blockHash === blockHash && revealedPayload.envelopeRoot === envelopeRoot));
64
+ }
65
+ hasRevealed(blockRoot) {
66
+ return this.revealedPayloadByBlockRoot.has(blockRoot);
67
+ }
68
+ hasPublishedReveal(blockRoot) {
69
+ return this.revealedPayloadByBlockRoot.get(blockRoot)?.published ?? false;
70
+ }
71
+ recordReveal(slot, blockRoot, blockHash, envelopeRoot) {
72
+ const revealedPayload = this.revealedPayloadByBlockRoot.get(blockRoot);
73
+ if (revealedPayload !== undefined) {
74
+ if (revealedPayload.blockHash !== blockHash || revealedPayload.envelopeRoot !== envelopeRoot) {
75
+ throw new BidLedgerError({
76
+ code: BidLedgerErrorCode.REVEAL_CONFLICT,
77
+ blockRoot,
78
+ blockHash,
79
+ revealedBlockHash: revealedPayload.blockHash,
80
+ envelopeRoot,
81
+ revealedEnvelopeRoot: revealedPayload.envelopeRoot,
82
+ }, `Different envelope already recorded blockRoot=${blockRoot} envelopeRoot=${revealedPayload.envelopeRoot}`);
83
+ }
84
+ return;
85
+ }
86
+ this.revealedPayloadByBlockRoot.set(blockRoot, { slot, blockHash, envelopeRoot, published: false });
87
+ }
88
+ recordRevealPublished(slot, blockRoot, blockHash, envelopeRoot) {
89
+ this.recordReveal(slot, blockRoot, blockHash, envelopeRoot);
90
+ const revealedPayload = this.revealedPayloadByBlockRoot.get(blockRoot);
91
+ if (revealedPayload !== undefined) {
92
+ revealedPayload.published = true;
93
+ }
94
+ }
95
+ getUnsettledValueGwei(currentEpoch) {
96
+ let total = 0;
97
+ for (const bidsForSlot of this.bidsBySlot.values()) {
98
+ for (const record of bidsForSlot.values()) {
99
+ if (record.wonBlockRoots.size === 0 || record.paymentSettled) {
100
+ continue;
101
+ }
102
+ total += record.valueGwei;
103
+ if (!Number.isSafeInteger(total)) {
104
+ throw new BidLedgerError({ code: BidLedgerErrorCode.UNSETTLED_VALUE_OVERFLOW, currentEpoch }, `Unsettled bid value exceeds the safe integer range currentEpoch=${currentEpoch}`);
105
+ }
106
+ }
107
+ }
108
+ return total;
109
+ }
110
+ getBidsForSlot(slot) {
111
+ return Array.from(this.bidsBySlot.get(slot)?.values() ?? [], toRecord);
112
+ }
113
+ prune(currentSlot) {
114
+ let removed = 0;
115
+ for (const [slot, bidsForSlot] of this.bidsBySlot) {
116
+ if (slot >= currentSlot - KEEP_SLOTS) {
117
+ continue;
118
+ }
119
+ for (const [key, record] of bidsForSlot) {
120
+ if (record.wonBlockRoots.size === 0 || record.paymentSettled) {
121
+ bidsForSlot.delete(key);
122
+ removed++;
123
+ }
124
+ }
125
+ if (bidsForSlot.size === 0) {
126
+ this.bidsBySlot.delete(slot);
127
+ }
128
+ }
129
+ for (const [blockRoot, revealedPayload] of this.revealedPayloadByBlockRoot) {
130
+ if (revealedPayload.slot < currentSlot - KEEP_SLOTS) {
131
+ this.revealedPayloadByBlockRoot.delete(blockRoot);
132
+ }
133
+ }
134
+ return removed;
135
+ }
136
+ getBid(slot, parentBlockHash, parentBlockRoot) {
137
+ return this.bidsBySlot.get(slot)?.get(tupleKey(parentBlockHash, parentBlockRoot)) ?? null;
138
+ }
139
+ }
140
+ function tupleKey(parentBlockHash, parentBlockRoot) {
141
+ return `${parentBlockHash}:${parentBlockRoot}`;
142
+ }
143
+ function toRecord(record) {
144
+ return {
145
+ slot: record.slot,
146
+ parentBlockHash: record.parentBlockHash,
147
+ parentBlockRoot: record.parentBlockRoot,
148
+ blockHash: record.blockHash,
149
+ valueGwei: record.valueGwei,
150
+ signedBidRoot: record.signedBidRoot,
151
+ wonBlockRoots: Array.from(record.wonBlockRoots),
152
+ };
153
+ }
154
+ //# sourceMappingURL=bidLedger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bidLedger.js","sourceRoot":"","sources":["../../src/services/bidLedger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AA6B9C,MAAM,CAAN,IAAY,kBAKX;AALD,WAAY,kBAAkB;IAC5B,8EAAwD,CAAA;IACxD,sEAAgD,CAAA;IAChD,0EAAoD,CAAA;IACpD,4FAAsE,CAAA;AACxE,CAAC,EALW,kBAAkB,KAAlB,kBAAkB,QAK7B;AA0BD,MAAM,OAAO,cAAe,SAAQ,aAAiC;CAAG;AAExE,MAAM,uBAAuB,GAAG,CAAC,CAAC;AAClC,MAAM,UAAU,GAAG,uBAAuB,GAAG,eAAe,CAAC;AAE7D,sGAAsG;AACtG,MAAM,OAAO,SAAS;IACH,UAAU,GAAG,IAAI,GAAG,EAA6C,CAAC;IAClE,0BAA0B,GAAG,IAAI,GAAG,EAA4B,CAAC;IAElF,YAAY,CAAC,IAAU,EAAE,eAAwB,EAAE,eAAwB;QACzE,OAAO,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AC,aAAa;QACnC,aAAa,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC;KAChD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,30 @@
1
+ export type BidContext = {
2
+ /** Value of the payload to the builder's fee recipient, as reported by the execution client */
3
+ payloadValueGwei: number;
4
+ /** Builder balance that can back a bid, excess over the minimum and unsettled payments */
5
+ coverableGwei: number;
6
+ };
7
+ /** Decides how much to pay the proposer for a payload, null means do not bid */
8
+ export interface BidPolicy {
9
+ computeValue(ctx: BidContext): number | null;
10
+ }
11
+ export type ProportionalBidPolicyOpts = {
12
+ /** Share of the payload value offered to the proposer, in basis points */
13
+ shareBps: number;
14
+ /** Fixed amount deducted from the share, e.g. to cover operating cost */
15
+ fixedCostGwei: number;
16
+ /** Never bid below this value */
17
+ minValueGwei: number;
18
+ /** Never bid above this value */
19
+ maxValueGwei?: number;
20
+ };
21
+ /**
22
+ * Offers a fixed share of the payload value, bounded by the configured limits and the
23
+ * builder's coverable balance. Independent of competing bids.
24
+ */
25
+ export declare class ProportionalBidPolicy implements BidPolicy {
26
+ private readonly opts;
27
+ constructor(opts: ProportionalBidPolicyOpts);
28
+ computeValue({ payloadValueGwei, coverableGwei }: BidContext): number | null;
29
+ }
30
+ //# sourceMappingURL=bidPolicy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bidPolicy.d.ts","sourceRoot":"","sources":["../../src/services/bidPolicy.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG;IACvB,+FAA+F;IAC/F,gBAAgB,EAAE,MAAM,CAAC;IACzB,0FAA0F;IAC1F,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,gFAAgF;AAChF,MAAM,WAAW,SAAS;IACxB,YAAY,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CAAC;CAC9C;AAED,MAAM,MAAM,yBAAyB,GAAG;IACtC,0EAA0E;IAC1E,QAAQ,EAAE,MAAM,CAAC;IACjB,yEAAyE;IACzE,aAAa,EAAE,MAAM,CAAC;IACtB,iCAAiC;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,iCAAiC;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;;GAGG;AACH,qBAAa,qBAAsB,YAAW,SAAS;IACzC,OAAO,CAAC,QAAQ,CAAC,IAAI;IAAjC,YAA6B,IAAI,EAAE,yBAAyB,EAqB3D;IAED,YAAY,CAAC,EAAC,gBAAgB,EAAE,aAAa,EAAC,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CAYzE;CACF"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Offers a fixed share of the payload value, bounded by the configured limits and the
3
+ * builder's coverable balance. Independent of competing bids.
4
+ */
5
+ export class ProportionalBidPolicy {
6
+ opts;
7
+ constructor(opts) {
8
+ this.opts = opts;
9
+ if (!Number.isSafeInteger(opts.shareBps) || opts.shareBps < 0 || opts.shareBps > 10_000) {
10
+ throw Error(`Invalid shareBps=${opts.shareBps}, must be an integer within [0, 10000]`);
11
+ }
12
+ if (!Number.isSafeInteger(opts.fixedCostGwei) || opts.fixedCostGwei < 0) {
13
+ throw Error(`Invalid fixedCostGwei=${opts.fixedCostGwei}, must be a non-negative safe integer`);
14
+ }
15
+ if (!Number.isSafeInteger(opts.minValueGwei) || opts.minValueGwei < 0) {
16
+ throw Error(`Invalid minValueGwei=${opts.minValueGwei}, must be a non-negative safe integer`);
17
+ }
18
+ if (opts.maxValueGwei !== undefined &&
19
+ (!Number.isSafeInteger(opts.maxValueGwei) || opts.maxValueGwei < opts.minValueGwei)) {
20
+ throw Error(`Invalid maxValueGwei=${opts.maxValueGwei}, must be a safe integer greater than or equal to minValueGwei=${opts.minValueGwei}`);
21
+ }
22
+ }
23
+ computeValue({ payloadValueGwei, coverableGwei }) {
24
+ const proportionalValue = Number((BigInt(payloadValueGwei) * BigInt(this.opts.shareBps)) / 10000n);
25
+ const share = proportionalValue - this.opts.fixedCostGwei;
26
+ // This will override `fixedCostGwei` for the sake of fulfilling `minValueGwei`
27
+ let value = Math.max(this.opts.minValueGwei, share);
28
+ if (this.opts.maxValueGwei !== undefined) {
29
+ value = Math.min(value, this.opts.maxValueGwei);
30
+ }
31
+ if (value > coverableGwei) {
32
+ return null;
33
+ }
34
+ return value;
35
+ }
36
+ }
37
+ //# sourceMappingURL=bidPolicy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bidPolicy.js","sourceRoot":"","sources":["../../src/services/bidPolicy.ts"],"names":[],"mappings":"AAuBA;;;GAGG;AACH,MAAM,OAAO,qBAAqB;IACH,IAAI;IAAjC,YAA6B,IAA+B;oBAA/B,IAAI;QAC/B,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,GAAG,MAAM,EAAE,CAAC;YACxF,MAAM,KAAK,CAAC,oBAAoB,IAAI,CAAC,QAAQ,wCAAwC,CAAC,CAAC;QACzF,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,IAAI,CAAC,aAAa,GAAG,CAAC,EAAE,CAAC;YACxE,MAAM,KAAK,CAAC,yBAAyB,IAAI,CAAC,aAAa,uCAAuC,CAAC,CAAC;QAClG,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,IAAI,CAAC,YAAY,GAAG,CAAC,EAAE,CAAC;YACtE,MAAM,KAAK,CAAC,wBAAwB,IAAI,CAAC,YAAY,uCAAuC,CAAC,CAAC;QAChG,CAAC;QAED,IACE,IAAI,CAAC,YAAY,KAAK,SAAS;YAC/B,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,EACnF,CAAC;YACD,MAAM,KAAK,CACT,wBAAwB,IAAI,CAAC,YAAY,kEAAkE,IAAI,CAAC,YAAY,EAAE,CAC/H,CAAC;QACJ,CAAC;IACH,CAAC;IAED,YAAY,CAAC,EAAC,gBAAgB,EAAE,aAAa,EAAa;QACxD,MAAM,iBAAiB,GAAG,MAAM,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,MAAO,CAAC,CAAC;QACpG,MAAM,KAAK,GAAG,iBAAiB,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC;QAC1D,+EAA+E;QAC/E,IAAI,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;QACpD,IAAI,IAAI,CAAC,IAAI,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;YACzC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAClD,CAAC;QACD,IAAI,KAAK,GAAG,aAAa,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
@@ -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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lodestar/builder",
3
- "version": "1.48.0-dev.30d2b0bf52",
3
+ "version": "1.48.0-dev.386c085495",
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.6.3",
51
- "@lodestar/api": "^1.48.0-dev.30d2b0bf52",
52
- "@lodestar/config": "^1.48.0-dev.30d2b0bf52",
53
- "@lodestar/params": "^1.48.0-dev.30d2b0bf52",
54
- "@lodestar/state-transition": "^1.48.0-dev.30d2b0bf52",
55
- "@lodestar/types": "^1.48.0-dev.30d2b0bf52",
56
- "@lodestar/utils": "^1.48.0-dev.30d2b0bf52"
50
+ "@chainsafe/ssz": "^1.7.0",
51
+ "@lodestar/api": "^1.48.0-dev.386c085495",
52
+ "@lodestar/config": "^1.48.0-dev.386c085495",
53
+ "@lodestar/params": "^1.48.0-dev.386c085495",
54
+ "@lodestar/state-transition": "^1.48.0-dev.386c085495",
55
+ "@lodestar/types": "^1.48.0-dev.386c085495",
56
+ "@lodestar/utils": "^1.48.0-dev.386c085495"
57
57
  },
58
58
  "devDependencies": {
59
- "@lodestar/logger": "^1.48.0-dev.30d2b0bf52",
60
- "@lodestar/test-utils": "^1.48.0-dev.30d2b0bf52"
59
+ "@lodestar/logger": "^1.48.0-dev.386c085495",
60
+ "@lodestar/test-utils": "^1.48.0-dev.386c085495"
61
61
  },
62
- "gitHead": "2b4a3b5c9ce68458e813b026e474355dfcdc0f4e"
62
+ "gitHead": "7778353c18cfefef76dca31047cfce740994f0e9"
63
63
  }
package/src/builder.ts CHANGED
@@ -9,6 +9,7 @@ import {Metrics} from "./metrics.js";
9
9
  import {logNodeVersion, waitForNodeReady} from "./readiness.js";
10
10
  import {BuilderSigner, Keypair} from "./services/builderSigner.js";
11
11
  import {BuilderStatusTracker} from "./services/builderStatusTracker.js";
12
+ import {PayloadStore} from "./services/payloadStore.js";
12
13
 
13
14
  export type BuilderModules = {
14
15
  opts: BuilderOptions;
@@ -16,6 +17,7 @@ export type BuilderModules = {
16
17
  builderStatusTracker: BuilderStatusTracker;
17
18
  clock: IClock;
18
19
  index: BuilderIndex;
20
+ store: PayloadStore;
19
21
  };
20
22
 
21
23
  export type BuilderOptions = {
@@ -40,17 +42,20 @@ export class Builder {
40
42
  private readonly index: BuilderIndex;
41
43
  private readonly logger: Logger;
42
44
  private readonly executionFeeRecipient: ExecutionAddress;
45
+ private readonly store: PayloadStore;
43
46
 
44
- constructor({opts, builderSigner, builderStatusTracker, clock, index}: BuilderModules) {
47
+ constructor({opts, builderSigner, builderStatusTracker, clock, index, store}: BuilderModules) {
45
48
  this.builderSigner = builderSigner;
46
49
  this.builderStatusTracker = builderStatusTracker;
47
50
  this.clock = clock;
48
51
  this.controller = opts.abortController;
49
52
  this.logger = opts.logger;
50
53
  this.index = index;
54
+ this.store = store;
51
55
 
52
56
  this.executionFeeRecipient = opts.executionFeeRecipient;
53
57
 
58
+ this.clock.runEverySlot(async (slot) => this.onSlot(slot));
54
59
  this.clock.runEveryEpoch((epoch) => this.builderStatusTracker.poll(epoch));
55
60
  this.clock.start(this.controller.signal);
56
61
 
@@ -90,7 +95,13 @@ export class Builder {
90
95
 
91
96
  const builderStatusTracker = new BuilderStatusTracker(api, logger, index, opts.metrics);
92
97
 
93
- return new Builder({opts, builderSigner, builderStatusTracker, clock, index});
98
+ const store = new PayloadStore();
99
+
100
+ return new Builder({opts, builderSigner, builderStatusTracker, clock, index, store});
101
+ }
102
+
103
+ private async onSlot(slot: number): Promise<void> {
104
+ this.store.prune(slot);
94
105
  }
95
106
 
96
107
  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(WAITING_FOR_BUILDER_POLL_MS, signal);
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(WAITING_FOR_BUILDER_POLL_MS, signal);
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
+ }
@@ -0,0 +1,245 @@
1
+ import {SLOTS_PER_EPOCH} from "@lodestar/params";
2
+ import type {Epoch, RootHex, Slot} from "@lodestar/types";
3
+ import {LodestarError} from "@lodestar/utils";
4
+
5
+ export type SubmittedBid = {
6
+ slot: Slot;
7
+ parentBlockHash: RootHex;
8
+ parentBlockRoot: RootHex;
9
+ blockHash: RootHex;
10
+ valueGwei: number;
11
+ signedBidRoot: RootHex;
12
+ };
13
+
14
+ export type BidIdentity = Pick<SubmittedBid, "slot" | "parentBlockHash" | "parentBlockRoot" | "blockHash">;
15
+
16
+ export type BidLedgerRecord = SubmittedBid & {
17
+ wonBlockRoots: RootHex[];
18
+ };
19
+
20
+ type RevealedPayload = {
21
+ slot: Slot;
22
+ blockHash: RootHex;
23
+ envelopeRoot: RootHex;
24
+ published: boolean;
25
+ };
26
+
27
+ type MutableBidLedgerRecord = SubmittedBid & {
28
+ wonBlockRoots: Set<RootHex>;
29
+ paymentSettled: boolean;
30
+ };
31
+
32
+ export enum BidLedgerErrorCode {
33
+ INVALID_BID_VALUE = "BID_LEDGER_ERROR_INVALID_BID_VALUE",
34
+ DUPLICATE_BID = "BID_LEDGER_ERROR_DUPLICATE_BID",
35
+ REVEAL_CONFLICT = "BID_LEDGER_ERROR_REVEAL_CONFLICT",
36
+ UNSETTLED_VALUE_OVERFLOW = "BID_LEDGER_ERROR_UNSETTLED_VALUE_OVERFLOW",
37
+ }
38
+
39
+ export type BidLedgerErrorType =
40
+ | {
41
+ code: BidLedgerErrorCode.INVALID_BID_VALUE;
42
+ valueGwei: number;
43
+ }
44
+ | {
45
+ code: BidLedgerErrorCode.DUPLICATE_BID;
46
+ slot: Slot;
47
+ parentBlockHash: RootHex;
48
+ parentBlockRoot: RootHex;
49
+ }
50
+ | {
51
+ code: BidLedgerErrorCode.REVEAL_CONFLICT;
52
+ blockRoot: RootHex;
53
+ blockHash: RootHex;
54
+ revealedBlockHash: RootHex;
55
+ envelopeRoot: RootHex;
56
+ revealedEnvelopeRoot: RootHex;
57
+ }
58
+ | {
59
+ code: BidLedgerErrorCode.UNSETTLED_VALUE_OVERFLOW;
60
+ currentEpoch: Epoch;
61
+ };
62
+
63
+ export class BidLedgerError extends LodestarError<BidLedgerErrorType> {}
64
+
65
+ const RECORD_RETENTION_EPOCHS = 3;
66
+ const KEEP_SLOTS = RECORD_RETENTION_EPOCHS * SLOTS_PER_EPOCH;
67
+
68
+ /** Tracks at most one bid per (slot, parentBlockHash, parentBlockRoot) and its reveal obligations. */
69
+ export class BidLedger {
70
+ private readonly bidsBySlot = new Map<Slot, Map<string, MutableBidLedgerRecord>>();
71
+ private readonly revealedPayloadByBlockRoot = new Map<RootHex, RevealedPayload>();
72
+
73
+ hasSubmitted(slot: Slot, parentBlockHash: RootHex, parentBlockRoot: RootHex): boolean {
74
+ return this.bidsBySlot.get(slot)?.has(tupleKey(parentBlockHash, parentBlockRoot)) ?? false;
75
+ }
76
+
77
+ recordBid(bid: SubmittedBid): BidLedgerRecord {
78
+ if (!Number.isSafeInteger(bid.valueGwei) || bid.valueGwei < 0) {
79
+ throw new BidLedgerError(
80
+ {code: BidLedgerErrorCode.INVALID_BID_VALUE, valueGwei: bid.valueGwei},
81
+ `Invalid bid value valueGwei=${bid.valueGwei}`
82
+ );
83
+ }
84
+
85
+ let bidsForSlot = this.bidsBySlot.get(bid.slot);
86
+ if (bidsForSlot === undefined) {
87
+ bidsForSlot = new Map();
88
+ this.bidsBySlot.set(bid.slot, bidsForSlot);
89
+ }
90
+
91
+ 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
+ const record = {...bid, wonBlockRoots: new Set<RootHex>(), paymentSettled: false};
105
+ bidsForSlot.set(key, record);
106
+ return toRecord(record);
107
+ }
108
+
109
+ recordWin(identity: BidIdentity & Pick<SubmittedBid, "signedBidRoot">, blockRoot: RootHex): BidLedgerRecord | null {
110
+ const record = this.getBid(identity.slot, identity.parentBlockHash, identity.parentBlockRoot);
111
+ if (record === null || record.blockHash !== identity.blockHash || record.signedBidRoot !== identity.signedBidRoot) {
112
+ return null;
113
+ }
114
+
115
+ record.wonBlockRoots.add(blockRoot);
116
+ return toRecord(record);
117
+ }
118
+
119
+ /** Release a winning bid liability only after its payment is known to be reflected in Builder balance. */
120
+ recordPaymentSettled(identity: BidIdentity): BidLedgerRecord | null {
121
+ const record = this.getBid(identity.slot, identity.parentBlockHash, identity.parentBlockRoot);
122
+ if (record === null || record.blockHash !== identity.blockHash || record.wonBlockRoots.size === 0) {
123
+ return null;
124
+ }
125
+
126
+ record.paymentSettled = true;
127
+ return toRecord(record);
128
+ }
129
+
130
+ canReveal(blockRoot: RootHex, blockHash: RootHex, envelopeRoot: RootHex): boolean {
131
+ const revealedPayload = this.revealedPayloadByBlockRoot.get(blockRoot);
132
+ return (
133
+ revealedPayload === undefined ||
134
+ (revealedPayload.blockHash === blockHash && revealedPayload.envelopeRoot === envelopeRoot)
135
+ );
136
+ }
137
+
138
+ hasRevealed(blockRoot: RootHex): boolean {
139
+ return this.revealedPayloadByBlockRoot.has(blockRoot);
140
+ }
141
+
142
+ hasPublishedReveal(blockRoot: RootHex): boolean {
143
+ return this.revealedPayloadByBlockRoot.get(blockRoot)?.published ?? false;
144
+ }
145
+
146
+ recordReveal(slot: Slot, blockRoot: RootHex, blockHash: RootHex, envelopeRoot: RootHex): void {
147
+ const revealedPayload = this.revealedPayloadByBlockRoot.get(blockRoot);
148
+ if (revealedPayload !== undefined) {
149
+ if (revealedPayload.blockHash !== blockHash || revealedPayload.envelopeRoot !== envelopeRoot) {
150
+ throw new BidLedgerError(
151
+ {
152
+ code: BidLedgerErrorCode.REVEAL_CONFLICT,
153
+ blockRoot,
154
+ blockHash,
155
+ revealedBlockHash: revealedPayload.blockHash,
156
+ envelopeRoot,
157
+ revealedEnvelopeRoot: revealedPayload.envelopeRoot,
158
+ },
159
+ `Different envelope already recorded blockRoot=${blockRoot} envelopeRoot=${revealedPayload.envelopeRoot}`
160
+ );
161
+ }
162
+ return;
163
+ }
164
+
165
+ this.revealedPayloadByBlockRoot.set(blockRoot, {slot, blockHash, envelopeRoot, published: false});
166
+ }
167
+
168
+ recordRevealPublished(slot: Slot, blockRoot: RootHex, blockHash: RootHex, envelopeRoot: RootHex): void {
169
+ this.recordReveal(slot, blockRoot, blockHash, envelopeRoot);
170
+ const revealedPayload = this.revealedPayloadByBlockRoot.get(blockRoot);
171
+ if (revealedPayload !== undefined) {
172
+ revealedPayload.published = true;
173
+ }
174
+ }
175
+
176
+ getUnsettledValueGwei(currentEpoch: Epoch): number {
177
+ let total = 0;
178
+ for (const bidsForSlot of this.bidsBySlot.values()) {
179
+ for (const record of bidsForSlot.values()) {
180
+ if (record.wonBlockRoots.size === 0 || record.paymentSettled) {
181
+ continue;
182
+ }
183
+
184
+ total += record.valueGwei;
185
+ if (!Number.isSafeInteger(total)) {
186
+ throw new BidLedgerError(
187
+ {code: BidLedgerErrorCode.UNSETTLED_VALUE_OVERFLOW, currentEpoch},
188
+ `Unsettled bid value exceeds the safe integer range currentEpoch=${currentEpoch}`
189
+ );
190
+ }
191
+ }
192
+ }
193
+ return total;
194
+ }
195
+
196
+ getBidsForSlot(slot: Slot): BidLedgerRecord[] {
197
+ return Array.from(this.bidsBySlot.get(slot)?.values() ?? [], toRecord);
198
+ }
199
+
200
+ prune(currentSlot: Slot): number {
201
+ let removed = 0;
202
+ for (const [slot, bidsForSlot] of this.bidsBySlot) {
203
+ if (slot >= currentSlot - KEEP_SLOTS) {
204
+ continue;
205
+ }
206
+
207
+ for (const [key, record] of bidsForSlot) {
208
+ if (record.wonBlockRoots.size === 0 || record.paymentSettled) {
209
+ bidsForSlot.delete(key);
210
+ removed++;
211
+ }
212
+ }
213
+ if (bidsForSlot.size === 0) {
214
+ this.bidsBySlot.delete(slot);
215
+ }
216
+ }
217
+
218
+ for (const [blockRoot, revealedPayload] of this.revealedPayloadByBlockRoot) {
219
+ if (revealedPayload.slot < currentSlot - KEEP_SLOTS) {
220
+ this.revealedPayloadByBlockRoot.delete(blockRoot);
221
+ }
222
+ }
223
+ return removed;
224
+ }
225
+
226
+ private getBid(slot: Slot, parentBlockHash: RootHex, parentBlockRoot: RootHex): MutableBidLedgerRecord | null {
227
+ return this.bidsBySlot.get(slot)?.get(tupleKey(parentBlockHash, parentBlockRoot)) ?? null;
228
+ }
229
+ }
230
+
231
+ function tupleKey(parentBlockHash: RootHex, parentBlockRoot: RootHex): string {
232
+ return `${parentBlockHash}:${parentBlockRoot}`;
233
+ }
234
+
235
+ function toRecord(record: MutableBidLedgerRecord): BidLedgerRecord {
236
+ return {
237
+ slot: record.slot,
238
+ parentBlockHash: record.parentBlockHash,
239
+ parentBlockRoot: record.parentBlockRoot,
240
+ blockHash: record.blockHash,
241
+ valueGwei: record.valueGwei,
242
+ signedBidRoot: record.signedBidRoot,
243
+ wonBlockRoots: Array.from(record.wonBlockRoots),
244
+ };
245
+ }
@@ -0,0 +1,65 @@
1
+ export type BidContext = {
2
+ /** Value of the payload to the builder's fee recipient, as reported by the execution client */
3
+ payloadValueGwei: number;
4
+ /** Builder balance that can back a bid, excess over the minimum and unsettled payments */
5
+ coverableGwei: number;
6
+ };
7
+
8
+ /** Decides how much to pay the proposer for a payload, null means do not bid */
9
+ export interface BidPolicy {
10
+ computeValue(ctx: BidContext): number | null;
11
+ }
12
+
13
+ export type ProportionalBidPolicyOpts = {
14
+ /** Share of the payload value offered to the proposer, in basis points */
15
+ shareBps: number;
16
+ /** Fixed amount deducted from the share, e.g. to cover operating cost */
17
+ fixedCostGwei: number;
18
+ /** Never bid below this value */
19
+ minValueGwei: number;
20
+ /** Never bid above this value */
21
+ maxValueGwei?: number;
22
+ };
23
+
24
+ /**
25
+ * Offers a fixed share of the payload value, bounded by the configured limits and the
26
+ * builder's coverable balance. Independent of competing bids.
27
+ */
28
+ export class ProportionalBidPolicy implements BidPolicy {
29
+ constructor(private readonly opts: ProportionalBidPolicyOpts) {
30
+ if (!Number.isSafeInteger(opts.shareBps) || opts.shareBps < 0 || opts.shareBps > 10_000) {
31
+ throw Error(`Invalid shareBps=${opts.shareBps}, must be an integer within [0, 10000]`);
32
+ }
33
+
34
+ if (!Number.isSafeInteger(opts.fixedCostGwei) || opts.fixedCostGwei < 0) {
35
+ throw Error(`Invalid fixedCostGwei=${opts.fixedCostGwei}, must be a non-negative safe integer`);
36
+ }
37
+
38
+ if (!Number.isSafeInteger(opts.minValueGwei) || opts.minValueGwei < 0) {
39
+ throw Error(`Invalid minValueGwei=${opts.minValueGwei}, must be a non-negative safe integer`);
40
+ }
41
+
42
+ if (
43
+ opts.maxValueGwei !== undefined &&
44
+ (!Number.isSafeInteger(opts.maxValueGwei) || opts.maxValueGwei < opts.minValueGwei)
45
+ ) {
46
+ throw Error(
47
+ `Invalid maxValueGwei=${opts.maxValueGwei}, must be a safe integer greater than or equal to minValueGwei=${opts.minValueGwei}`
48
+ );
49
+ }
50
+ }
51
+
52
+ computeValue({payloadValueGwei, coverableGwei}: BidContext): number | null {
53
+ const proportionalValue = Number((BigInt(payloadValueGwei) * BigInt(this.opts.shareBps)) / 10_000n);
54
+ const share = proportionalValue - this.opts.fixedCostGwei;
55
+ // This will override `fixedCostGwei` for the sake of fulfilling `minValueGwei`
56
+ let value = Math.max(this.opts.minValueGwei, share);
57
+ if (this.opts.maxValueGwei !== undefined) {
58
+ value = Math.min(value, this.opts.maxValueGwei);
59
+ }
60
+ if (value > coverableGwei) {
61
+ return null;
62
+ }
63
+ return value;
64
+ }
65
+ }
@@ -0,0 +1,51 @@
1
+ import {ForkPostGloas} from "@lodestar/params";
2
+ import {BlobsBundle, ExecutionPayload, Root, RootHex, Slot, gloas} from "@lodestar/types";
3
+
4
+ // NOTE: BuiltPayload will migrate to payloadSource.ts when the payload source lands; the store
5
+ // holds it here for now.
6
+ export type BuiltPayload = {
7
+ sourceId: string;
8
+ executionPayload: ExecutionPayload<ForkPostGloas>;
9
+ executionRequests: gloas.ExecutionRequests;
10
+ blobsBundle: BlobsBundle<ForkPostGloas>;
11
+ /** Value of the payload to the fee recipient in wei, as reported by the execution client */
12
+ executionPayloadValue: bigint;
13
+ };
14
+
15
+ export type StoredPayload = {
16
+ slot: Slot;
17
+ parentBlockRoot: Root;
18
+ blockHash: RootHex;
19
+ payload: BuiltPayload;
20
+ };
21
+
22
+ /** Keep payloads for this many slots after their target slot, late blocks may still commit to them */
23
+ const KEEP_SLOTS = 2;
24
+
25
+ export class PayloadStore {
26
+ private readonly byBlockHash = new Map<RootHex, StoredPayload>();
27
+
28
+ add(payload: StoredPayload): void {
29
+ this.byBlockHash.set(payload.blockHash, payload);
30
+ }
31
+
32
+ get(blockHash: RootHex): StoredPayload | null {
33
+ return this.byBlockHash.get(blockHash) ?? null;
34
+ }
35
+
36
+ has(blockHash: RootHex): boolean {
37
+ return this.byBlockHash.has(blockHash);
38
+ }
39
+
40
+ prune(currentSlot: Slot): void {
41
+ for (const [blockHash, {slot}] of this.byBlockHash) {
42
+ if (slot + KEEP_SLOTS < currentSlot) {
43
+ this.byBlockHash.delete(blockHash);
44
+ }
45
+ }
46
+ }
47
+
48
+ get size(): number {
49
+ return this.byBlockHash.size;
50
+ }
51
+ }