@chainsafe/lodestar 1.47.0-dev.4546ac1229 → 1.47.0-dev.57572140f8
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/.git-data.json +1 -1
- package/lib/cmds/dev/options.d.ts +4 -0
- package/lib/cmds/dev/options.d.ts.map +1 -1
- package/lib/cmds/validator/handler.d.ts.map +1 -1
- package/lib/cmds/validator/handler.js +15 -2
- package/lib/cmds/validator/handler.js.map +1 -1
- package/lib/cmds/validator/keymanager/impl.d.ts +13 -2
- package/lib/cmds/validator/keymanager/impl.d.ts.map +1 -1
- package/lib/cmds/validator/keymanager/impl.js +40 -3
- package/lib/cmds/validator/keymanager/impl.js.map +1 -1
- package/lib/cmds/validator/keymanager/persistedKeys.d.ts.map +1 -1
- package/lib/cmds/validator/keymanager/persistedKeys.js +3 -1
- package/lib/cmds/validator/keymanager/persistedKeys.js.map +1 -1
- package/lib/cmds/validator/options.d.ts +4 -0
- package/lib/cmds/validator/options.d.ts.map +1 -1
- package/lib/cmds/validator/options.js +24 -0
- package/lib/cmds/validator/options.js.map +1 -1
- package/lib/networks/chiado.d.ts.map +1 -1
- package/lib/networks/chiado.js +4 -10
- package/lib/networks/chiado.js.map +1 -1
- package/lib/options/beaconNodeOptions/chain.d.ts.map +1 -1
- package/lib/options/beaconNodeOptions/chain.js +1 -1
- package/lib/options/beaconNodeOptions/chain.js.map +1 -1
- package/lib/util/proposerConfig.d.ts +16 -11
- package/lib/util/proposerConfig.d.ts.map +1 -1
- package/lib/util/proposerConfig.js +128 -11
- package/lib/util/proposerConfig.js.map +1 -1
- package/package.json +20 -20
- package/src/cmds/validator/handler.ts +29 -2
- package/src/cmds/validator/keymanager/impl.ts +55 -3
- package/src/cmds/validator/keymanager/persistedKeys.ts +5 -1
- package/src/cmds/validator/options.ts +36 -0
- package/src/networks/chiado.ts +4 -10
- package/src/options/beaconNodeOptions/chain.ts +2 -1
- package/src/util/proposerConfig.ts +152 -13
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import {routes} from "@lodestar/api";
|
|
4
|
+
import {BuilderEntryConfig, builderConfigDataFromJson} from "@lodestar/api/keymanager";
|
|
5
|
+
import {MAX_BUILDER_AUTH_DATA_SIZE, MAX_BUILDER_ENTRIES, MAX_BUILDER_URL_SIZE} from "@lodestar/params";
|
|
6
|
+
import {fromHex, isValidAsciiHttpUrl, toHex} from "@lodestar/utils";
|
|
4
7
|
import {ValidatorProposerConfig} from "@lodestar/validator";
|
|
5
8
|
import {parseFeeRecipient} from "./feeRecipient.js";
|
|
6
9
|
import {readFile} from "./file.js";
|
|
7
10
|
|
|
11
|
+
const UINT64_MAX = 2n ** 64n - 1n;
|
|
12
|
+
const BUILDER_AUTH_DATA_PATTERN = new RegExp(`^0x(?:[a-fA-F0-9]{2}){1,${MAX_BUILDER_AUTH_DATA_SIZE}}$`);
|
|
13
|
+
|
|
8
14
|
type ProposerConfig = ValidatorProposerConfig["defaultConfig"];
|
|
9
15
|
|
|
10
16
|
type ProposerConfigFileSection = {
|
|
@@ -17,6 +23,9 @@ type ProposerConfigFileSection = {
|
|
|
17
23
|
gas_limit?: number;
|
|
18
24
|
selection?: routes.validator.BuilderSelection;
|
|
19
25
|
boost_factor?: bigint;
|
|
26
|
+
min_bid?: bigint;
|
|
27
|
+
max_execution_payment?: bigint;
|
|
28
|
+
builders?: unknown;
|
|
20
29
|
};
|
|
21
30
|
};
|
|
22
31
|
|
|
@@ -54,7 +63,14 @@ function parseProposerConfigSection(
|
|
|
54
63
|
overrideConfig?: ProposerConfig
|
|
55
64
|
): ProposerConfig {
|
|
56
65
|
const {graffiti, strict_fee_recipient_check, fee_recipient, builder} = proposerFileSection;
|
|
57
|
-
const {
|
|
66
|
+
const {
|
|
67
|
+
gas_limit,
|
|
68
|
+
selection: builderSelection,
|
|
69
|
+
boost_factor,
|
|
70
|
+
min_bid,
|
|
71
|
+
max_execution_payment,
|
|
72
|
+
builders,
|
|
73
|
+
} = builder || {};
|
|
58
74
|
|
|
59
75
|
if (graffiti !== undefined && typeof graffiti !== "string") {
|
|
60
76
|
throw Error("graffiti is not 'string");
|
|
@@ -79,6 +95,29 @@ function parseProposerConfigSection(
|
|
|
79
95
|
if (boost_factor !== undefined && typeof boost_factor !== "string") {
|
|
80
96
|
throw Error("boost_factor is not 'string");
|
|
81
97
|
}
|
|
98
|
+
if (min_bid !== undefined && typeof min_bid !== "string") {
|
|
99
|
+
throw Error("min_bid is not 'string");
|
|
100
|
+
}
|
|
101
|
+
if (max_execution_payment !== undefined && typeof max_execution_payment !== "string") {
|
|
102
|
+
throw Error("max_execution_payment is not 'string");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const parsedBuilder =
|
|
106
|
+
overrideConfig?.builder || builder
|
|
107
|
+
? {
|
|
108
|
+
gasLimit: overrideConfig?.builder?.gasLimit ?? (gas_limit !== undefined ? Number(gas_limit) : undefined),
|
|
109
|
+
selection: overrideConfig?.builder?.selection ?? parseBuilderSelection(builderSelection),
|
|
110
|
+
boostFactor: overrideConfig?.builder?.boostFactor ?? parseBuilderBoostFactor(boost_factor),
|
|
111
|
+
minBid: overrideConfig?.builder?.minBid ?? parseBuilderMinBid(min_bid),
|
|
112
|
+
maxExecutionPayment:
|
|
113
|
+
overrideConfig?.builder?.maxExecutionPayment ?? parseBuilderGweiAmount(max_execution_payment),
|
|
114
|
+
builders: overrideConfig?.builder?.builders ?? parseBuilderEntries(builders),
|
|
115
|
+
}
|
|
116
|
+
: undefined;
|
|
117
|
+
|
|
118
|
+
if (overrideConfig?.builder?.builders !== undefined && builders !== undefined) {
|
|
119
|
+
throw Error("Cannot configure both --builder.urls and builders in the proposer settings file");
|
|
120
|
+
}
|
|
82
121
|
|
|
83
122
|
return {
|
|
84
123
|
graffiti: overrideConfig?.graffiti ?? graffiti,
|
|
@@ -86,21 +125,27 @@ function parseProposerConfigSection(
|
|
|
86
125
|
overrideConfig?.strictFeeRecipientCheck ??
|
|
87
126
|
(strict_fee_recipient_check ? stringtoBool(strict_fee_recipient_check) : undefined),
|
|
88
127
|
feeRecipient: overrideConfig?.feeRecipient ?? (fee_recipient ? parseFeeRecipient(fee_recipient) : undefined),
|
|
89
|
-
builder:
|
|
90
|
-
overrideConfig?.builder || builder
|
|
91
|
-
? {
|
|
92
|
-
gasLimit: overrideConfig?.builder?.gasLimit ?? (gas_limit !== undefined ? Number(gas_limit) : undefined),
|
|
93
|
-
selection: overrideConfig?.builder?.selection ?? parseBuilderSelection(builderSelection),
|
|
94
|
-
boostFactor: overrideConfig?.builder?.boostFactor ?? parseBuilderBoostFactor(boost_factor),
|
|
95
|
-
}
|
|
96
|
-
: undefined,
|
|
128
|
+
builder: parsedBuilder,
|
|
97
129
|
};
|
|
98
130
|
}
|
|
99
131
|
|
|
100
|
-
export function readProposerConfigDir(filepath: string, filename: string):
|
|
132
|
+
export function readProposerConfigDir(filepath: string, filename: string): ProposerConfig {
|
|
101
133
|
const proposerConfigStr = fs.readFileSync(path.join(filepath, filename), "utf8");
|
|
102
|
-
|
|
103
|
-
|
|
134
|
+
// Persisted via `writeProposerConfig` with BigInt values serialized as strings
|
|
135
|
+
const persisted = JSON.parse(proposerConfigStr) as ProposerConfig;
|
|
136
|
+
if (persisted.builder) {
|
|
137
|
+
const {boostFactor, minBid, maxExecutionPayment, builders} = persisted.builder;
|
|
138
|
+
persisted.builder.boostFactor = boostFactor !== undefined ? BigInt(boostFactor) : undefined;
|
|
139
|
+
persisted.builder.minBid = minBid !== undefined ? BigInt(minBid) : undefined;
|
|
140
|
+
persisted.builder.maxExecutionPayment = maxExecutionPayment !== undefined ? BigInt(maxExecutionPayment) : undefined;
|
|
141
|
+
persisted.builder.builders = builders?.map((entry) => ({
|
|
142
|
+
...entry,
|
|
143
|
+
maxExecutionPayment: entry.maxExecutionPayment !== undefined ? BigInt(entry.maxExecutionPayment) : undefined,
|
|
144
|
+
minBid: entry.minBid !== undefined ? BigInt(entry.minBid) : undefined,
|
|
145
|
+
builderBoostFactor: entry.builderBoostFactor !== undefined ? BigInt(entry.builderBoostFactor) : undefined,
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
return persisted;
|
|
104
149
|
}
|
|
105
150
|
|
|
106
151
|
export function parseBuilderSelection(builderSelection?: string): routes.validator.BuilderSelection | undefined {
|
|
@@ -131,6 +176,100 @@ export function parseBuilderBoostFactor(boostFactor?: string): bigint | undefine
|
|
|
131
176
|
if (!/^\d+$/.test(boostFactor)) {
|
|
132
177
|
throw Error("Invalid input for builder boost factor, must be a valid number without decimals");
|
|
133
178
|
}
|
|
179
|
+
const parsed = BigInt(boostFactor);
|
|
180
|
+
if (parsed > UINT64_MAX) {
|
|
181
|
+
throw Error("Invalid input for builder boost factor, must not exceed 2**64 - 1");
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return parsed;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function parseBuilderMinBid(minBid?: string | bigint): bigint | undefined {
|
|
188
|
+
if (minBid === undefined) return;
|
|
189
|
+
|
|
190
|
+
if (!/^\d+$/.test(minBid.toString())) {
|
|
191
|
+
throw Error("Invalid input for builder min bid, must be a valid number without decimals");
|
|
192
|
+
}
|
|
193
|
+
const parsed = BigInt(minBid);
|
|
194
|
+
if (parsed > UINT64_MAX) {
|
|
195
|
+
throw Error("Invalid input for builder min bid, must not exceed 2**64 - 1");
|
|
196
|
+
}
|
|
134
197
|
|
|
135
|
-
return
|
|
198
|
+
return parsed;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function parseBuilderGweiAmount(amount?: string | bigint): bigint | undefined {
|
|
202
|
+
if (amount === undefined) return;
|
|
203
|
+
|
|
204
|
+
if (!/^\d+$/.test(amount.toString())) {
|
|
205
|
+
throw Error("Invalid input for builder Gwei amount, must be a valid number without decimals");
|
|
206
|
+
}
|
|
207
|
+
const parsed = BigInt(amount);
|
|
208
|
+
if (parsed > UINT64_MAX) {
|
|
209
|
+
throw Error("Invalid input for builder Gwei amount, must not exceed 2**64 - 1");
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return parsed;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Parse per-builder entries from the proposer settings file, same shape and validation as the
|
|
217
|
+
* keymanager builders api. No two entries may share both their url and their auth data, an
|
|
218
|
+
* omitted auth data is compared as the value derived from the entry url.
|
|
219
|
+
*/
|
|
220
|
+
export function parseBuilderEntries(builders?: unknown): BuilderEntryConfig[] | undefined {
|
|
221
|
+
if (builders === undefined) return undefined;
|
|
222
|
+
|
|
223
|
+
const {builders: entries} = builderConfigDataFromJson({builders});
|
|
224
|
+
const seenEntries = new Set<string>();
|
|
225
|
+
for (const entry of entries ?? []) {
|
|
226
|
+
if (!isValidAsciiHttpUrl(entry.url)) {
|
|
227
|
+
throw Error(`Invalid builder url: ${entry.url}`);
|
|
228
|
+
}
|
|
229
|
+
const authData = entry.authData !== undefined ? toHex(fromHex(entry.authData)) : toHex(Buffer.from(entry.url));
|
|
230
|
+
const entryKey = `${entry.url}|${authData}`;
|
|
231
|
+
if (seenEntries.has(entryKey)) {
|
|
232
|
+
throw Error(`Duplicate builder entry url=${entry.url}`);
|
|
233
|
+
}
|
|
234
|
+
seenEntries.add(entryKey);
|
|
235
|
+
}
|
|
236
|
+
return entries;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Parse builder urls into builder entries. Auth data agreed with a builder out of band may be
|
|
241
|
+
* appended as a hex fragment (`https://builder.example.com#0x0123`), it is stripped from the url
|
|
242
|
+
* and never sent on the wire. Without a fragment the auth data derives from the url.
|
|
243
|
+
*/
|
|
244
|
+
export function parseBuilderUrls(urls?: string[]): BuilderEntryConfig[] | undefined {
|
|
245
|
+
if (urls === undefined) return undefined;
|
|
246
|
+
|
|
247
|
+
const entries: BuilderEntryConfig[] = [];
|
|
248
|
+
const seenEntries = new Set<string>();
|
|
249
|
+
for (const value of urls) {
|
|
250
|
+
const fragmentIndex = value.indexOf("#");
|
|
251
|
+
const url = fragmentIndex === -1 ? value : value.slice(0, fragmentIndex);
|
|
252
|
+
const authData = fragmentIndex === -1 ? undefined : value.slice(fragmentIndex + 1);
|
|
253
|
+
if (!isValidAsciiHttpUrl(url)) {
|
|
254
|
+
throw Error(`Invalid builder url: ${url}`);
|
|
255
|
+
}
|
|
256
|
+
if (Buffer.byteLength(url, "utf8") > MAX_BUILDER_URL_SIZE) {
|
|
257
|
+
throw Error(`Invalid builder url, must not exceed ${MAX_BUILDER_URL_SIZE} bytes: ${url}`);
|
|
258
|
+
}
|
|
259
|
+
if (authData !== undefined && !BUILDER_AUTH_DATA_PATTERN.test(authData)) {
|
|
260
|
+
throw Error(
|
|
261
|
+
`Invalid builder url auth data, must be a 0x-prefixed hex string of 1 to ${MAX_BUILDER_AUTH_DATA_SIZE} bytes: ${url}`
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
const entryKey = `${url}|${authData !== undefined ? toHex(fromHex(authData)) : toHex(Buffer.from(url))}`;
|
|
265
|
+
if (seenEntries.has(entryKey)) {
|
|
266
|
+
throw Error(`Duplicate builder url: ${url}`);
|
|
267
|
+
}
|
|
268
|
+
seenEntries.add(entryKey);
|
|
269
|
+
entries.push({url, authData});
|
|
270
|
+
}
|
|
271
|
+
if (entries.length > MAX_BUILDER_ENTRIES) {
|
|
272
|
+
throw Error(`Number of builder urls must not exceed ${MAX_BUILDER_ENTRIES}, got ${entries.length}`);
|
|
273
|
+
}
|
|
274
|
+
return entries;
|
|
136
275
|
}
|