@lodestar/builder 1.48.0-dev.04d463c59a → 1.48.0-dev.262a9c1d16
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/README.md +1 -1
- package/lib/builder.d.ts +5 -1
- package/lib/builder.d.ts.map +1 -1
- package/lib/builder.js +10 -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/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/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/package.json +11 -11
- package/src/builder.ts +13 -2
- package/src/identity.ts +13 -6
- package/src/services/bidPolicy.ts +65 -0
- package/src/services/payloadStore.ts +51 -0
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Lodestar Builder
|
|
2
2
|
|
|
3
3
|
[](https://discord.gg/aMxzVcr)
|
|
4
|
-
[](https://github.com/ethereum/consensus-specs/releases/tag/v1.7.0-beta.0)
|
|
5
5
|

|
|
6
6
|

|
|
7
7
|
|
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
|
-
|
|
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
|
package/lib/builder.d.ts.map
CHANGED
|
@@ -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,MAAM,cAAc,CAAC;AAErC,OAAO,EAAC,aAAa,EAAE,OAAO,EAAC,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAC,oBAAoB,EAAC,MAAM,oCAAoC,CAAC;
|
|
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,YAA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,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
|
-
|
|
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
|
-
|
|
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();
|
package/lib/builder.js.map
CHANGED
|
@@ -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;
|
|
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;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AC,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;
|
package/lib/identity.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAA4B,MAAM,EAAC,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAC,eAAe,EAAC,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAA4B,MAAM,EAAC,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAC,eAAe,EAAC,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAC,MAAM,EAA0B,MAAM,4BAA4B,CAAC;AAC3E,OAAO,EAAC,YAAY,EAAE,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAe,MAAM,EAA2C,MAAM,iBAAiB,CAAC;AAE/F,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,SAAS,EACd,MAAM,EAAE,MAAM,EACd,EAAE,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(
|
|
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(
|
|
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
|
package/lib/identity.js.map
CHANGED
|
@@ -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;
|
|
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;AACzD,OAAO,EAAS,uBAAuB,EAAC,MAAM,4BAA4B,CAAC;AAE3E,OAAO,EAAC,YAAY,EAAU,YAAY,EAAE,YAAY,EAAE,KAAK,EAAE,KAAK,EAAC,MAAM,iBAAiB,CAAC;AAE/F,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,uBAAuB,EAAE,CAAC;QAC7D,MAAM,KAAK,CAAC,iCAAiC,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AAO,OAAO,CAAC;IACjB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,CAAC,YAAY,YAAY,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,EAAE,CAAC;YACzE,MAAM,CAAC,IAAI,CAAC,yBAAyB,EAAE,EAAC,OAAO,EAAE,CAAC,CAAC,OAAO,EAAC,CAAC,CAAC;YAC7D,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,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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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.
|
|
3
|
+
"version": "1.48.0-dev.262a9c1d16",
|
|
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.7.0",
|
|
51
|
+
"@lodestar/api": "^1.48.0-dev.262a9c1d16",
|
|
52
|
+
"@lodestar/config": "^1.48.0-dev.262a9c1d16",
|
|
53
|
+
"@lodestar/params": "^1.48.0-dev.262a9c1d16",
|
|
54
|
+
"@lodestar/state-transition": "^1.48.0-dev.262a9c1d16",
|
|
55
|
+
"@lodestar/types": "^1.48.0-dev.262a9c1d16",
|
|
56
|
+
"@lodestar/utils": "^1.48.0-dev.262a9c1d16"
|
|
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.262a9c1d16",
|
|
60
|
+
"@lodestar/test-utils": "^1.48.0-dev.262a9c1d16"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "4c6fa0c6fa0074f9bd060fee542bd01986f7cf78"
|
|
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
|
-
|
|
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(
|
|
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
|
+
}
|
|
@@ -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
|
+
}
|