@lodestar/builder 1.48.0-dev.acdde443d2 → 1.48.0-dev.af8bc602aa
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 +1 -11
- package/lib/builder.d.ts.map +1 -1
- package/lib/builder.js +2 -30
- package/lib/builder.js.map +1 -1
- package/lib/identity.d.ts +1 -0
- package/lib/identity.d.ts.map +1 -1
- package/lib/identity.js +4 -11
- package/lib/identity.js.map +1 -1
- package/package.json +11 -11
- package/src/builder.ts +3 -45
- package/src/identity.ts +6 -13
- package/lib/services/bidLedger.d.ts +0 -61
- package/lib/services/bidLedger.d.ts.map +0 -1
- package/lib/services/bidLedger.js +0 -154
- package/lib/services/bidLedger.js.map +0 -1
- package/lib/services/bidPolicy.d.ts +0 -30
- package/lib/services/bidPolicy.d.ts.map +0 -1
- package/lib/services/bidPolicy.js +0 -37
- package/lib/services/bidPolicy.js.map +0 -1
- package/lib/services/blockObserver.d.ts +0 -48
- package/lib/services/blockObserver.d.ts.map +0 -1
- package/lib/services/blockObserver.js +0 -172
- package/lib/services/blockObserver.js.map +0 -1
- package/lib/services/payloadStore.d.ts +0 -25
- package/lib/services/payloadStore.d.ts.map +0 -1
- package/lib/services/payloadStore.js +0 -25
- package/lib/services/payloadStore.js.map +0 -1
- package/lib/services/proposerPreferencesTracker.d.ts +0 -15
- package/lib/services/proposerPreferencesTracker.d.ts.map +0 -1
- package/lib/services/proposerPreferencesTracker.js +0 -68
- package/lib/services/proposerPreferencesTracker.js.map +0 -1
- package/src/services/bidLedger.ts +0 -245
- package/src/services/bidPolicy.ts +0 -65
- package/src/services/blockObserver.ts +0 -231
- package/src/services/payloadStore.ts +0 -51
- package/src/services/proposerPreferencesTracker.ts +0 -74
package/lib/builder.d.ts
CHANGED
|
@@ -4,20 +4,14 @@ import { ClockOptions, IClock } from "@lodestar/state-transition";
|
|
|
4
4
|
import { BuilderIndex, ExecutionAddress } from "@lodestar/types";
|
|
5
5
|
import { Logger } from "@lodestar/utils";
|
|
6
6
|
import { Metrics } from "./metrics.js";
|
|
7
|
-
import { BlockObserver } from "./services/blockObserver.js";
|
|
8
7
|
import { BuilderSigner, Keypair } from "./services/builderSigner.js";
|
|
9
8
|
import { BuilderStatusTracker } from "./services/builderStatusTracker.js";
|
|
10
|
-
import { PayloadStore } from "./services/payloadStore.js";
|
|
11
|
-
import { ProposerPreferencesTracker } from "./services/proposerPreferencesTracker.js";
|
|
12
9
|
export type BuilderModules = {
|
|
13
10
|
opts: BuilderOptions;
|
|
14
11
|
builderSigner: BuilderSigner;
|
|
15
|
-
blockObserver: BlockObserver;
|
|
16
12
|
builderStatusTracker: BuilderStatusTracker;
|
|
17
|
-
proposerPreferencesTracker: ProposerPreferencesTracker;
|
|
18
13
|
clock: IClock;
|
|
19
14
|
index: BuilderIndex;
|
|
20
|
-
store: PayloadStore;
|
|
21
15
|
};
|
|
22
16
|
export type BuilderOptions = {
|
|
23
17
|
logger: Logger;
|
|
@@ -34,18 +28,14 @@ export type BuilderOptions = {
|
|
|
34
28
|
*/
|
|
35
29
|
export declare class Builder {
|
|
36
30
|
readonly builderSigner: BuilderSigner;
|
|
37
|
-
readonly proposerPreferencesTracker: ProposerPreferencesTracker;
|
|
38
|
-
private readonly blockObserver;
|
|
39
31
|
private readonly builderStatusTracker;
|
|
40
32
|
private readonly controller;
|
|
41
33
|
private readonly clock;
|
|
42
34
|
private readonly index;
|
|
43
35
|
private readonly logger;
|
|
44
36
|
private readonly executionFeeRecipient;
|
|
45
|
-
|
|
46
|
-
constructor({ opts, builderSigner, blockObserver, builderStatusTracker, proposerPreferencesTracker, clock, index, store, }: BuilderModules);
|
|
37
|
+
constructor({ opts, builderSigner, builderStatusTracker, clock, index }: BuilderModules);
|
|
47
38
|
static init(opts: BuilderOptions): Promise<Builder>;
|
|
48
|
-
private onSlot;
|
|
49
39
|
close(): Promise<void>;
|
|
50
40
|
}
|
|
51
41
|
//# 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,
|
|
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;AAExE,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,cAAc,CAAC;IACrB,aAAa,EAAE,aAAa,CAAC;IAC7B,oBAAoB,EAAE,oBAAoB,CAAC;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,YAAY,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,eAAe,CAAC;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe,EAAE,eAAe,CAAC;IACjC,GAAG,EAAE,SAAS,CAAC;IACf,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,qBAAqB,EAAE,gBAAgB,CAAC;IACxC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,qBAAa,OAAO;IAClB,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAuB;IAC5D,OAAO,CAAC,QAAQ,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;IAEzD,YAAY,EAAC,IAAI,EAAE,aAAa,EAAE,oBAAoB,EAAE,KAAK,EAAE,KAAK,EAAC,EAAE,cAAc,EAiBpF;IAED,OAAa,IAAI,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CA+BxD;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAE3B;CACF"}
|
package/lib/builder.js
CHANGED
|
@@ -4,41 +4,29 @@ import { toHex, toRootHex } from "@lodestar/utils";
|
|
|
4
4
|
import { waitForGenesis } from "./genesis.js";
|
|
5
5
|
import { resolveBuilderIdentity } from "./identity.js";
|
|
6
6
|
import { logNodeVersion, waitForNodeReady } from "./readiness.js";
|
|
7
|
-
import { BlockObserver } from "./services/blockObserver.js";
|
|
8
7
|
import { BuilderSigner } from "./services/builderSigner.js";
|
|
9
8
|
import { BuilderStatusTracker } from "./services/builderStatusTracker.js";
|
|
10
|
-
import { PayloadStore } from "./services/payloadStore.js";
|
|
11
|
-
import { ProposerPreferencesTracker } from "./services/proposerPreferencesTracker.js";
|
|
12
9
|
/**
|
|
13
10
|
* Main class for the Builder client.
|
|
14
11
|
*/
|
|
15
12
|
export class Builder {
|
|
16
13
|
builderSigner;
|
|
17
|
-
proposerPreferencesTracker;
|
|
18
|
-
blockObserver;
|
|
19
14
|
builderStatusTracker;
|
|
20
15
|
controller;
|
|
21
16
|
clock;
|
|
22
17
|
index;
|
|
23
18
|
logger;
|
|
24
19
|
executionFeeRecipient;
|
|
25
|
-
|
|
26
|
-
constructor({ opts, builderSigner, blockObserver, builderStatusTracker, proposerPreferencesTracker, clock, index, store, }) {
|
|
20
|
+
constructor({ opts, builderSigner, builderStatusTracker, clock, index }) {
|
|
27
21
|
this.builderSigner = builderSigner;
|
|
28
|
-
this.blockObserver = blockObserver;
|
|
29
22
|
this.builderStatusTracker = builderStatusTracker;
|
|
30
|
-
this.proposerPreferencesTracker = proposerPreferencesTracker;
|
|
31
23
|
this.clock = clock;
|
|
32
24
|
this.controller = opts.abortController;
|
|
33
25
|
this.logger = opts.logger;
|
|
34
26
|
this.index = index;
|
|
35
|
-
this.store = store;
|
|
36
27
|
this.executionFeeRecipient = opts.executionFeeRecipient;
|
|
37
|
-
this.clock.runEverySlot(async (slot) => this.onSlot(slot));
|
|
38
28
|
this.clock.runEveryEpoch((epoch) => this.builderStatusTracker.poll(epoch));
|
|
39
29
|
this.clock.start(this.controller.signal);
|
|
40
|
-
this.blockObserver.start(this.controller.signal);
|
|
41
|
-
this.proposerPreferencesTracker.start(this.controller.signal);
|
|
42
30
|
this.logger.info("Builder client initialized", {
|
|
43
31
|
index: this.index,
|
|
44
32
|
executionFeeRecipient: toHex(this.executionFeeRecipient),
|
|
@@ -60,23 +48,7 @@ export class Builder {
|
|
|
60
48
|
const clock = new Clock(config, logger, { genesisTime: Number(genesis.genesisTime), ...opts.clock });
|
|
61
49
|
const index = await resolveBuilderIdentity(api, logger, builderSigner.getPubkeyHex(), opts.abortController.signal, clock, config);
|
|
62
50
|
const builderStatusTracker = new BuilderStatusTracker(api, logger, index, opts.metrics);
|
|
63
|
-
|
|
64
|
-
const proposerPreferencesTracker = new ProposerPreferencesTracker(api, logger);
|
|
65
|
-
const store = new PayloadStore();
|
|
66
|
-
return new Builder({
|
|
67
|
-
opts,
|
|
68
|
-
builderSigner,
|
|
69
|
-
blockObserver,
|
|
70
|
-
builderStatusTracker,
|
|
71
|
-
proposerPreferencesTracker,
|
|
72
|
-
clock,
|
|
73
|
-
index,
|
|
74
|
-
store,
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
async onSlot(slot) {
|
|
78
|
-
this.store.prune(slot);
|
|
79
|
-
this.proposerPreferencesTracker.prune(slot);
|
|
51
|
+
return new Builder({ opts, builderSigner, builderStatusTracker, clock, index });
|
|
80
52
|
}
|
|
81
53
|
async close() {
|
|
82
54
|
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,
|
|
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,O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5B,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,OAAO,IAAI,OAAO,CAAC,EAAC,IAAI,EAAE,aAAa,EAAE,oBAAoB,EAAE,KAAK,EAAE,KAAK,EAAC,CAAC,CAAC;IAChF,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;CACF"}
|
package/lib/identity.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ 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;
|
|
6
7
|
export declare function resolveBuilderIdentity(api: ApiClient, logger: Logger, id: routes.beacon.BuilderId, signal: AbortSignal, clock: IClock, config: ChainForkConfig): Promise<BuilderIndex>;
|
|
7
8
|
export declare function getBuilderStatus(api: ApiClient, logger: Logger, id: routes.beacon.BuilderId): Promise<{
|
|
8
9
|
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,EAAC,MAAM,4BAA4B,CAAC;AAClD,OAAO,EAAC,YAAY,EAAE,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAe,MAAM,EAA2C,MAAM,iBAAiB,CAAC;AAE/F,eAAO,MAAM,2BAA2B,QAAY,CAAC;AAErD,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";
|
|
4
3
|
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(WAITING_FOR_BUILDER_POLL_MS, 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(WAITING_FOR_BUILDER_POLL_MS, signal);
|
|
64
64
|
continue;
|
|
65
65
|
}
|
|
66
66
|
throw e;
|
|
@@ -73,12 +73,11 @@ 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);
|
|
77
76
|
}
|
|
78
77
|
else {
|
|
79
78
|
logger.info("Waiting for builder to be known to the beacon node", { id, slot: clock.getCurrentSlot() });
|
|
80
|
-
await sleep(msToNextSlotPoll(clock), signal);
|
|
81
79
|
}
|
|
80
|
+
await sleep(WAITING_FOR_BUILDER_POLL_MS, signal);
|
|
82
81
|
}
|
|
83
82
|
throw new ErrorAborted("waitForBuilder");
|
|
84
83
|
}
|
|
@@ -111,10 +110,4 @@ async function fetchBuilder(api, logger, id) {
|
|
|
111
110
|
throw e;
|
|
112
111
|
}
|
|
113
112
|
}
|
|
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
|
-
}
|
|
120
113
|
//# 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;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,uBAAuB,EAAE,CAAC;QAC7D,MAAM,KAAK,CAAC,iCAAiC,YAAY,CAAC,OAAO,CAAC,OAAO,cAAc,uBAAuB,EAAE,CAAC,CAAC;IACpH,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,2BAA2B,EAAE;QACvC,KAAK,EAAE,YAAY,CAAC,KAAK;QACzB,MAAM,EAAE,YAAY,CAAC,MAAM;QAC3B,WAAW,EAAE,YAAY,CAAC,OAAO,CAAC,OAAO;QACzC,gBAAgB,EAAE,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,gBAA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odestar/builder",
|
|
3
|
-
"version": "1.48.0-dev.
|
|
3
|
+
"version": "1.48.0-dev.af8bc602aa",
|
|
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.6.3",
|
|
51
|
+
"@lodestar/api": "^1.48.0-dev.af8bc602aa",
|
|
52
|
+
"@lodestar/config": "^1.48.0-dev.af8bc602aa",
|
|
53
|
+
"@lodestar/params": "^1.48.0-dev.af8bc602aa",
|
|
54
|
+
"@lodestar/state-transition": "^1.48.0-dev.af8bc602aa",
|
|
55
|
+
"@lodestar/types": "^1.48.0-dev.af8bc602aa",
|
|
56
|
+
"@lodestar/utils": "^1.48.0-dev.af8bc602aa"
|
|
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.af8bc602aa",
|
|
60
|
+
"@lodestar/test-utils": "^1.48.0-dev.af8bc602aa"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "c0820d99b0af1d6822d6ff21691c377bbf4ab611"
|
|
63
63
|
}
|
package/src/builder.ts
CHANGED
|
@@ -7,21 +7,15 @@ import {waitForGenesis} from "./genesis.js";
|
|
|
7
7
|
import {resolveBuilderIdentity} from "./identity.js";
|
|
8
8
|
import {Metrics} from "./metrics.js";
|
|
9
9
|
import {logNodeVersion, waitForNodeReady} from "./readiness.js";
|
|
10
|
-
import {BlockObserver} from "./services/blockObserver.js";
|
|
11
10
|
import {BuilderSigner, Keypair} from "./services/builderSigner.js";
|
|
12
11
|
import {BuilderStatusTracker} from "./services/builderStatusTracker.js";
|
|
13
|
-
import {PayloadStore} from "./services/payloadStore.js";
|
|
14
|
-
import {ProposerPreferencesTracker} from "./services/proposerPreferencesTracker.js";
|
|
15
12
|
|
|
16
13
|
export type BuilderModules = {
|
|
17
14
|
opts: BuilderOptions;
|
|
18
15
|
builderSigner: BuilderSigner;
|
|
19
|
-
blockObserver: BlockObserver;
|
|
20
16
|
builderStatusTracker: BuilderStatusTracker;
|
|
21
|
-
proposerPreferencesTracker: ProposerPreferencesTracker;
|
|
22
17
|
clock: IClock;
|
|
23
18
|
index: BuilderIndex;
|
|
24
|
-
store: PayloadStore;
|
|
25
19
|
};
|
|
26
20
|
|
|
27
21
|
export type BuilderOptions = {
|
|
@@ -40,43 +34,25 @@ export type BuilderOptions = {
|
|
|
40
34
|
*/
|
|
41
35
|
export class Builder {
|
|
42
36
|
readonly builderSigner: BuilderSigner;
|
|
43
|
-
readonly proposerPreferencesTracker: ProposerPreferencesTracker;
|
|
44
|
-
private readonly blockObserver: BlockObserver;
|
|
45
37
|
private readonly builderStatusTracker: BuilderStatusTracker;
|
|
46
38
|
private readonly controller: AbortController;
|
|
47
39
|
private readonly clock: IClock;
|
|
48
40
|
private readonly index: BuilderIndex;
|
|
49
41
|
private readonly logger: Logger;
|
|
50
42
|
private readonly executionFeeRecipient: ExecutionAddress;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
constructor({
|
|
54
|
-
opts,
|
|
55
|
-
builderSigner,
|
|
56
|
-
blockObserver,
|
|
57
|
-
builderStatusTracker,
|
|
58
|
-
proposerPreferencesTracker,
|
|
59
|
-
clock,
|
|
60
|
-
index,
|
|
61
|
-
store,
|
|
62
|
-
}: BuilderModules) {
|
|
43
|
+
|
|
44
|
+
constructor({opts, builderSigner, builderStatusTracker, clock, index}: BuilderModules) {
|
|
63
45
|
this.builderSigner = builderSigner;
|
|
64
|
-
this.blockObserver = blockObserver;
|
|
65
46
|
this.builderStatusTracker = builderStatusTracker;
|
|
66
|
-
this.proposerPreferencesTracker = proposerPreferencesTracker;
|
|
67
47
|
this.clock = clock;
|
|
68
48
|
this.controller = opts.abortController;
|
|
69
49
|
this.logger = opts.logger;
|
|
70
50
|
this.index = index;
|
|
71
|
-
this.store = store;
|
|
72
51
|
|
|
73
52
|
this.executionFeeRecipient = opts.executionFeeRecipient;
|
|
74
53
|
|
|
75
|
-
this.clock.runEverySlot(async (slot) => this.onSlot(slot));
|
|
76
54
|
this.clock.runEveryEpoch((epoch) => this.builderStatusTracker.poll(epoch));
|
|
77
55
|
this.clock.start(this.controller.signal);
|
|
78
|
-
this.blockObserver.start(this.controller.signal);
|
|
79
|
-
this.proposerPreferencesTracker.start(this.controller.signal);
|
|
80
56
|
|
|
81
57
|
this.logger.info("Builder client initialized", {
|
|
82
58
|
index: this.index,
|
|
@@ -113,26 +89,8 @@ export class Builder {
|
|
|
113
89
|
);
|
|
114
90
|
|
|
115
91
|
const builderStatusTracker = new BuilderStatusTracker(api, logger, index, opts.metrics);
|
|
116
|
-
const blockObserver = new BlockObserver(config, logger, api);
|
|
117
|
-
const proposerPreferencesTracker = new ProposerPreferencesTracker(api, logger);
|
|
118
|
-
|
|
119
|
-
const store = new PayloadStore();
|
|
120
|
-
|
|
121
|
-
return new Builder({
|
|
122
|
-
opts,
|
|
123
|
-
builderSigner,
|
|
124
|
-
blockObserver,
|
|
125
|
-
builderStatusTracker,
|
|
126
|
-
proposerPreferencesTracker,
|
|
127
|
-
clock,
|
|
128
|
-
index,
|
|
129
|
-
store,
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
92
|
|
|
133
|
-
|
|
134
|
-
this.store.prune(slot);
|
|
135
|
-
this.proposerPreferencesTracker.prune(slot);
|
|
93
|
+
return new Builder({opts, builderSigner, builderStatusTracker, clock, index});
|
|
136
94
|
}
|
|
137
95
|
|
|
138
96
|
async close(): Promise<void> {
|
package/src/identity.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
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
|
|
4
|
+
import {IClock} 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
|
+
|
|
8
10
|
export async function resolveBuilderIdentity(
|
|
9
11
|
api: ApiClient,
|
|
10
12
|
logger: Logger,
|
|
@@ -69,7 +71,7 @@ async function waitForBuilder(
|
|
|
69
71
|
currentEpoch,
|
|
70
72
|
slot: clock.getCurrentSlot(),
|
|
71
73
|
});
|
|
72
|
-
await sleep(
|
|
74
|
+
await sleep(WAITING_FOR_BUILDER_POLL_MS, signal);
|
|
73
75
|
continue;
|
|
74
76
|
}
|
|
75
77
|
|
|
@@ -85,7 +87,7 @@ async function waitForBuilder(
|
|
|
85
87
|
currentEpoch,
|
|
86
88
|
slot: clock.getCurrentSlot(),
|
|
87
89
|
});
|
|
88
|
-
await sleep(
|
|
90
|
+
await sleep(WAITING_FOR_BUILDER_POLL_MS, signal);
|
|
89
91
|
continue;
|
|
90
92
|
}
|
|
91
93
|
throw e;
|
|
@@ -99,11 +101,10 @@ async function waitForBuilder(
|
|
|
99
101
|
}
|
|
100
102
|
if (builder?.status === "pending") {
|
|
101
103
|
logger.info("Waiting for builder deposit to be finalized", {id, slot: clock.getCurrentSlot()});
|
|
102
|
-
await sleep(msToNextEpochPoll(clock), signal);
|
|
103
104
|
} else {
|
|
104
105
|
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);
|
|
107
108
|
}
|
|
108
109
|
throw new ErrorAborted("waitForBuilder");
|
|
109
110
|
}
|
|
@@ -144,11 +145,3 @@ async function fetchBuilder(
|
|
|
144
145
|
throw e;
|
|
145
146
|
}
|
|
146
147
|
}
|
|
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
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,EAAC,MAAM,iBAAiB,CAAC;AAE9C,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,IAAI,CAAC;IACX,eAAe,EAAE,OAAO,CAAC;IACzB,eAAe,EAAE,OAAO,CAAC;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,EAAE,MAAM,GAAG,iBAAiB,GAAG,iBAAiB,GAAG,WAAW,CAAC,CAAC;AAE3G,MAAM,MAAM,eAAe,GAAG,YAAY,GAAG;IAC3C,aAAa,EAAE,OAAO,EAAE,CAAC;CAC1B,CAAC;AAcF,oBAAY,kBAAkB;IA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AC,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,GAAG,OAAO,CAMhF;IAED,WAAW,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAEvC;IAED,kBAAkB,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAE9C;IAED,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,GAAG,IAAI,CAoB5F;IAED,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,GAAG,IAAI,CAMrG;IAED,qBAAqB,CAAC,YAAY,EAAE,KAAK,GAAG,MAAM,CAkBjD;IAED,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG,eAAe,EAAE,CAE5C;IAED,KAAK,CAAC,WAAW,EAAE,IAAI,GAAG,MAAM,CAwB/B;IAED,OAAO,CAAC,MAAM;CAGf"}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { SLOTS_PER_EPOCH } from "@lodestar/params";
|
|
2
|
-
import { LodestarError } from "@lodestar/utils";
|
|
3
|
-
export 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
|