@aztec/validator-client 4.0.0-nightly.20260112 → 4.0.0-nightly.20260113
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 +256 -0
- package/dest/block_proposal_handler.d.ts +20 -10
- package/dest/block_proposal_handler.d.ts.map +1 -1
- package/dest/block_proposal_handler.js +333 -72
- package/dest/checkpoint_builder.d.ts +70 -0
- package/dest/checkpoint_builder.d.ts.map +1 -0
- package/dest/checkpoint_builder.js +155 -0
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +10 -0
- package/dest/duties/validation_service.d.ts +26 -10
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +51 -21
- package/dest/factory.d.ts +10 -7
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +2 -2
- package/dest/index.d.ts +3 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -0
- package/dest/tx_validator/index.d.ts +3 -0
- package/dest/tx_validator/index.d.ts.map +1 -0
- package/dest/tx_validator/index.js +2 -0
- package/dest/tx_validator/nullifier_cache.d.ts +14 -0
- package/dest/tx_validator/nullifier_cache.d.ts.map +1 -0
- package/dest/tx_validator/nullifier_cache.js +24 -0
- package/dest/tx_validator/tx_validator_factory.d.ts +18 -0
- package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -0
- package/dest/tx_validator/tx_validator_factory.js +53 -0
- package/dest/validator.d.ts +39 -15
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +297 -449
- package/package.json +16 -12
- package/src/block_proposal_handler.ts +249 -39
- package/src/checkpoint_builder.ts +267 -0
- package/src/config.ts +10 -0
- package/src/duties/validation_service.ts +79 -25
- package/src/factory.ts +13 -8
- package/src/index.ts +2 -0
- package/src/tx_validator/index.ts +2 -0
- package/src/tx_validator/nullifier_cache.ts +30 -0
- package/src/tx_validator/tx_validator_factory.ts +133 -0
- package/src/validator.ts +400 -94
package/dest/validator.js
CHANGED
|
@@ -1,385 +1,15 @@
|
|
|
1
|
-
function applyDecs2203RFactory() {
|
|
2
|
-
function createAddInitializerMethod(initializers, decoratorFinishedRef) {
|
|
3
|
-
return function addInitializer(initializer) {
|
|
4
|
-
assertNotFinished(decoratorFinishedRef, "addInitializer");
|
|
5
|
-
assertCallable(initializer, "An initializer");
|
|
6
|
-
initializers.push(initializer);
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
|
|
10
|
-
var kindStr;
|
|
11
|
-
switch(kind){
|
|
12
|
-
case 1:
|
|
13
|
-
kindStr = "accessor";
|
|
14
|
-
break;
|
|
15
|
-
case 2:
|
|
16
|
-
kindStr = "method";
|
|
17
|
-
break;
|
|
18
|
-
case 3:
|
|
19
|
-
kindStr = "getter";
|
|
20
|
-
break;
|
|
21
|
-
case 4:
|
|
22
|
-
kindStr = "setter";
|
|
23
|
-
break;
|
|
24
|
-
default:
|
|
25
|
-
kindStr = "field";
|
|
26
|
-
}
|
|
27
|
-
var ctx = {
|
|
28
|
-
kind: kindStr,
|
|
29
|
-
name: isPrivate ? "#" + name : name,
|
|
30
|
-
static: isStatic,
|
|
31
|
-
private: isPrivate,
|
|
32
|
-
metadata: metadata
|
|
33
|
-
};
|
|
34
|
-
var decoratorFinishedRef = {
|
|
35
|
-
v: false
|
|
36
|
-
};
|
|
37
|
-
ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
|
|
38
|
-
var get, set;
|
|
39
|
-
if (kind === 0) {
|
|
40
|
-
if (isPrivate) {
|
|
41
|
-
get = desc.get;
|
|
42
|
-
set = desc.set;
|
|
43
|
-
} else {
|
|
44
|
-
get = function() {
|
|
45
|
-
return this[name];
|
|
46
|
-
};
|
|
47
|
-
set = function(v) {
|
|
48
|
-
this[name] = v;
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
} else if (kind === 2) {
|
|
52
|
-
get = function() {
|
|
53
|
-
return desc.value;
|
|
54
|
-
};
|
|
55
|
-
} else {
|
|
56
|
-
if (kind === 1 || kind === 3) {
|
|
57
|
-
get = function() {
|
|
58
|
-
return desc.get.call(this);
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
if (kind === 1 || kind === 4) {
|
|
62
|
-
set = function(v) {
|
|
63
|
-
desc.set.call(this, v);
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
ctx.access = get && set ? {
|
|
68
|
-
get: get,
|
|
69
|
-
set: set
|
|
70
|
-
} : get ? {
|
|
71
|
-
get: get
|
|
72
|
-
} : {
|
|
73
|
-
set: set
|
|
74
|
-
};
|
|
75
|
-
try {
|
|
76
|
-
return dec(value, ctx);
|
|
77
|
-
} finally{
|
|
78
|
-
decoratorFinishedRef.v = true;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
function assertNotFinished(decoratorFinishedRef, fnName) {
|
|
82
|
-
if (decoratorFinishedRef.v) {
|
|
83
|
-
throw new Error("attempted to call " + fnName + " after decoration was finished");
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
function assertCallable(fn, hint) {
|
|
87
|
-
if (typeof fn !== "function") {
|
|
88
|
-
throw new TypeError(hint + " must be a function");
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
function assertValidReturnValue(kind, value) {
|
|
92
|
-
var type = typeof value;
|
|
93
|
-
if (kind === 1) {
|
|
94
|
-
if (type !== "object" || value === null) {
|
|
95
|
-
throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
96
|
-
}
|
|
97
|
-
if (value.get !== undefined) {
|
|
98
|
-
assertCallable(value.get, "accessor.get");
|
|
99
|
-
}
|
|
100
|
-
if (value.set !== undefined) {
|
|
101
|
-
assertCallable(value.set, "accessor.set");
|
|
102
|
-
}
|
|
103
|
-
if (value.init !== undefined) {
|
|
104
|
-
assertCallable(value.init, "accessor.init");
|
|
105
|
-
}
|
|
106
|
-
} else if (type !== "function") {
|
|
107
|
-
var hint;
|
|
108
|
-
if (kind === 0) {
|
|
109
|
-
hint = "field";
|
|
110
|
-
} else if (kind === 10) {
|
|
111
|
-
hint = "class";
|
|
112
|
-
} else {
|
|
113
|
-
hint = "method";
|
|
114
|
-
}
|
|
115
|
-
throw new TypeError(hint + " decorators must return a function or void 0");
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
|
|
119
|
-
var decs = decInfo[0];
|
|
120
|
-
var desc, init, value;
|
|
121
|
-
if (isPrivate) {
|
|
122
|
-
if (kind === 0 || kind === 1) {
|
|
123
|
-
desc = {
|
|
124
|
-
get: decInfo[3],
|
|
125
|
-
set: decInfo[4]
|
|
126
|
-
};
|
|
127
|
-
} else if (kind === 3) {
|
|
128
|
-
desc = {
|
|
129
|
-
get: decInfo[3]
|
|
130
|
-
};
|
|
131
|
-
} else if (kind === 4) {
|
|
132
|
-
desc = {
|
|
133
|
-
set: decInfo[3]
|
|
134
|
-
};
|
|
135
|
-
} else {
|
|
136
|
-
desc = {
|
|
137
|
-
value: decInfo[3]
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
} else if (kind !== 0) {
|
|
141
|
-
desc = Object.getOwnPropertyDescriptor(base, name);
|
|
142
|
-
}
|
|
143
|
-
if (kind === 1) {
|
|
144
|
-
value = {
|
|
145
|
-
get: desc.get,
|
|
146
|
-
set: desc.set
|
|
147
|
-
};
|
|
148
|
-
} else if (kind === 2) {
|
|
149
|
-
value = desc.value;
|
|
150
|
-
} else if (kind === 3) {
|
|
151
|
-
value = desc.get;
|
|
152
|
-
} else if (kind === 4) {
|
|
153
|
-
value = desc.set;
|
|
154
|
-
}
|
|
155
|
-
var newValue, get, set;
|
|
156
|
-
if (typeof decs === "function") {
|
|
157
|
-
newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
158
|
-
if (newValue !== void 0) {
|
|
159
|
-
assertValidReturnValue(kind, newValue);
|
|
160
|
-
if (kind === 0) {
|
|
161
|
-
init = newValue;
|
|
162
|
-
} else if (kind === 1) {
|
|
163
|
-
init = newValue.init;
|
|
164
|
-
get = newValue.get || value.get;
|
|
165
|
-
set = newValue.set || value.set;
|
|
166
|
-
value = {
|
|
167
|
-
get: get,
|
|
168
|
-
set: set
|
|
169
|
-
};
|
|
170
|
-
} else {
|
|
171
|
-
value = newValue;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
} else {
|
|
175
|
-
for(var i = decs.length - 1; i >= 0; i--){
|
|
176
|
-
var dec = decs[i];
|
|
177
|
-
newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
178
|
-
if (newValue !== void 0) {
|
|
179
|
-
assertValidReturnValue(kind, newValue);
|
|
180
|
-
var newInit;
|
|
181
|
-
if (kind === 0) {
|
|
182
|
-
newInit = newValue;
|
|
183
|
-
} else if (kind === 1) {
|
|
184
|
-
newInit = newValue.init;
|
|
185
|
-
get = newValue.get || value.get;
|
|
186
|
-
set = newValue.set || value.set;
|
|
187
|
-
value = {
|
|
188
|
-
get: get,
|
|
189
|
-
set: set
|
|
190
|
-
};
|
|
191
|
-
} else {
|
|
192
|
-
value = newValue;
|
|
193
|
-
}
|
|
194
|
-
if (newInit !== void 0) {
|
|
195
|
-
if (init === void 0) {
|
|
196
|
-
init = newInit;
|
|
197
|
-
} else if (typeof init === "function") {
|
|
198
|
-
init = [
|
|
199
|
-
init,
|
|
200
|
-
newInit
|
|
201
|
-
];
|
|
202
|
-
} else {
|
|
203
|
-
init.push(newInit);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
if (kind === 0 || kind === 1) {
|
|
210
|
-
if (init === void 0) {
|
|
211
|
-
init = function(instance, init) {
|
|
212
|
-
return init;
|
|
213
|
-
};
|
|
214
|
-
} else if (typeof init !== "function") {
|
|
215
|
-
var ownInitializers = init;
|
|
216
|
-
init = function(instance, init) {
|
|
217
|
-
var value = init;
|
|
218
|
-
for(var i = 0; i < ownInitializers.length; i++){
|
|
219
|
-
value = ownInitializers[i].call(instance, value);
|
|
220
|
-
}
|
|
221
|
-
return value;
|
|
222
|
-
};
|
|
223
|
-
} else {
|
|
224
|
-
var originalInitializer = init;
|
|
225
|
-
init = function(instance, init) {
|
|
226
|
-
return originalInitializer.call(instance, init);
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
ret.push(init);
|
|
230
|
-
}
|
|
231
|
-
if (kind !== 0) {
|
|
232
|
-
if (kind === 1) {
|
|
233
|
-
desc.get = value.get;
|
|
234
|
-
desc.set = value.set;
|
|
235
|
-
} else if (kind === 2) {
|
|
236
|
-
desc.value = value;
|
|
237
|
-
} else if (kind === 3) {
|
|
238
|
-
desc.get = value;
|
|
239
|
-
} else if (kind === 4) {
|
|
240
|
-
desc.set = value;
|
|
241
|
-
}
|
|
242
|
-
if (isPrivate) {
|
|
243
|
-
if (kind === 1) {
|
|
244
|
-
ret.push(function(instance, args) {
|
|
245
|
-
return value.get.call(instance, args);
|
|
246
|
-
});
|
|
247
|
-
ret.push(function(instance, args) {
|
|
248
|
-
return value.set.call(instance, args);
|
|
249
|
-
});
|
|
250
|
-
} else if (kind === 2) {
|
|
251
|
-
ret.push(value);
|
|
252
|
-
} else {
|
|
253
|
-
ret.push(function(instance, args) {
|
|
254
|
-
return value.call(instance, args);
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
} else {
|
|
258
|
-
Object.defineProperty(base, name, desc);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
function applyMemberDecs(Class, decInfos, metadata) {
|
|
263
|
-
var ret = [];
|
|
264
|
-
var protoInitializers;
|
|
265
|
-
var staticInitializers;
|
|
266
|
-
var existingProtoNonFields = new Map();
|
|
267
|
-
var existingStaticNonFields = new Map();
|
|
268
|
-
for(var i = 0; i < decInfos.length; i++){
|
|
269
|
-
var decInfo = decInfos[i];
|
|
270
|
-
if (!Array.isArray(decInfo)) continue;
|
|
271
|
-
var kind = decInfo[1];
|
|
272
|
-
var name = decInfo[2];
|
|
273
|
-
var isPrivate = decInfo.length > 3;
|
|
274
|
-
var isStatic = kind >= 5;
|
|
275
|
-
var base;
|
|
276
|
-
var initializers;
|
|
277
|
-
if (isStatic) {
|
|
278
|
-
base = Class;
|
|
279
|
-
kind = kind - 5;
|
|
280
|
-
staticInitializers = staticInitializers || [];
|
|
281
|
-
initializers = staticInitializers;
|
|
282
|
-
} else {
|
|
283
|
-
base = Class.prototype;
|
|
284
|
-
protoInitializers = protoInitializers || [];
|
|
285
|
-
initializers = protoInitializers;
|
|
286
|
-
}
|
|
287
|
-
if (kind !== 0 && !isPrivate) {
|
|
288
|
-
var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
|
|
289
|
-
var existingKind = existingNonFields.get(name) || 0;
|
|
290
|
-
if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) {
|
|
291
|
-
throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
|
|
292
|
-
} else if (!existingKind && kind > 2) {
|
|
293
|
-
existingNonFields.set(name, kind);
|
|
294
|
-
} else {
|
|
295
|
-
existingNonFields.set(name, true);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
|
|
299
|
-
}
|
|
300
|
-
pushInitializers(ret, protoInitializers);
|
|
301
|
-
pushInitializers(ret, staticInitializers);
|
|
302
|
-
return ret;
|
|
303
|
-
}
|
|
304
|
-
function pushInitializers(ret, initializers) {
|
|
305
|
-
if (initializers) {
|
|
306
|
-
ret.push(function(instance) {
|
|
307
|
-
for(var i = 0; i < initializers.length; i++){
|
|
308
|
-
initializers[i].call(instance);
|
|
309
|
-
}
|
|
310
|
-
return instance;
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
function applyClassDecs(targetClass, classDecs, metadata) {
|
|
315
|
-
if (classDecs.length > 0) {
|
|
316
|
-
var initializers = [];
|
|
317
|
-
var newClass = targetClass;
|
|
318
|
-
var name = targetClass.name;
|
|
319
|
-
for(var i = classDecs.length - 1; i >= 0; i--){
|
|
320
|
-
var decoratorFinishedRef = {
|
|
321
|
-
v: false
|
|
322
|
-
};
|
|
323
|
-
try {
|
|
324
|
-
var nextNewClass = classDecs[i](newClass, {
|
|
325
|
-
kind: "class",
|
|
326
|
-
name: name,
|
|
327
|
-
addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
|
|
328
|
-
metadata
|
|
329
|
-
});
|
|
330
|
-
} finally{
|
|
331
|
-
decoratorFinishedRef.v = true;
|
|
332
|
-
}
|
|
333
|
-
if (nextNewClass !== undefined) {
|
|
334
|
-
assertValidReturnValue(10, nextNewClass);
|
|
335
|
-
newClass = nextNewClass;
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
return [
|
|
339
|
-
defineMetadata(newClass, metadata),
|
|
340
|
-
function() {
|
|
341
|
-
for(var i = 0; i < initializers.length; i++){
|
|
342
|
-
initializers[i].call(newClass);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
];
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
function defineMetadata(Class, metadata) {
|
|
349
|
-
return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
|
|
350
|
-
configurable: true,
|
|
351
|
-
enumerable: true,
|
|
352
|
-
value: metadata
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
|
|
356
|
-
if (parentClass !== void 0) {
|
|
357
|
-
var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
358
|
-
}
|
|
359
|
-
var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
|
|
360
|
-
var e = applyMemberDecs(targetClass, memberDecs, metadata);
|
|
361
|
-
if (!classDecs.length) defineMetadata(targetClass, metadata);
|
|
362
|
-
return {
|
|
363
|
-
e: e,
|
|
364
|
-
get c () {
|
|
365
|
-
return applyClassDecs(targetClass, classDecs, metadata);
|
|
366
|
-
}
|
|
367
|
-
};
|
|
368
|
-
};
|
|
369
|
-
}
|
|
370
|
-
function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
371
|
-
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
372
|
-
}
|
|
373
|
-
var _dec, _initProto;
|
|
374
1
|
import { getBlobsPerL1Block } from '@aztec/blob-lib';
|
|
2
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { TimeoutError } from '@aztec/foundation/error';
|
|
375
4
|
import { createLogger } from '@aztec/foundation/log';
|
|
5
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
376
6
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
377
7
|
import { sleep } from '@aztec/foundation/sleep';
|
|
378
8
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
379
9
|
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
380
10
|
import { OffenseType, WANT_TO_SLASH_EVENT } from '@aztec/slasher';
|
|
381
11
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
382
|
-
import {
|
|
12
|
+
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
383
13
|
import { EventEmitter } from 'events';
|
|
384
14
|
import { BlockProposalHandler } from './block_proposal_handler.js';
|
|
385
15
|
import { ValidationService } from './duties/validation_service.js';
|
|
@@ -393,10 +23,6 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
393
23
|
'state_mismatch',
|
|
394
24
|
'failed_txs'
|
|
395
25
|
];
|
|
396
|
-
_dec = trackSpan('validator.attestToProposal', (proposal, proposalSender)=>({
|
|
397
|
-
[Attributes.BLOCK_HASH]: proposal.payload.header.hash.toString(),
|
|
398
|
-
[Attributes.PEER_ID]: proposalSender.toString()
|
|
399
|
-
}));
|
|
400
26
|
/**
|
|
401
27
|
* Validator Client
|
|
402
28
|
*/ export class ValidatorClient extends EventEmitter {
|
|
@@ -404,18 +30,13 @@ _dec = trackSpan('validator.attestToProposal', (proposal, proposalSender)=>({
|
|
|
404
30
|
epochCache;
|
|
405
31
|
p2pClient;
|
|
406
32
|
blockProposalHandler;
|
|
33
|
+
blockSource;
|
|
34
|
+
checkpointsBuilder;
|
|
35
|
+
worldState;
|
|
36
|
+
l1ToL2MessageSource;
|
|
407
37
|
config;
|
|
408
38
|
blobClient;
|
|
409
39
|
dateProvider;
|
|
410
|
-
static{
|
|
411
|
-
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
412
|
-
[
|
|
413
|
-
_dec,
|
|
414
|
-
2,
|
|
415
|
-
"attestToProposal"
|
|
416
|
-
]
|
|
417
|
-
], []));
|
|
418
|
-
}
|
|
419
40
|
tracer;
|
|
420
41
|
validationService;
|
|
421
42
|
metrics;
|
|
@@ -427,8 +48,12 @@ _dec = trackSpan('validator.attestToProposal', (proposal, proposalSender)=>({
|
|
|
427
48
|
lastEpochForCommitteeUpdateLoop;
|
|
428
49
|
epochCacheUpdateLoop;
|
|
429
50
|
proposersOfInvalidBlocks;
|
|
430
|
-
|
|
431
|
-
|
|
51
|
+
// TODO(palla/mbps): Remove this once checkpoint validation is stable and we can validate all blocks properly.
|
|
52
|
+
// Tracks slots for which we have successfully validated a block proposal, so we can attest to checkpoint proposals for those slots.
|
|
53
|
+
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
54
|
+
validatedBlockSlots;
|
|
55
|
+
constructor(keyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
|
|
56
|
+
super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.blockProposalHandler = blockProposalHandler, this.blockSource = blockSource, this.checkpointsBuilder = checkpointsBuilder, this.worldState = worldState, this.l1ToL2MessageSource = l1ToL2MessageSource, this.config = config, this.blobClient = blobClient, this.dateProvider = dateProvider, this.hasRegisteredHandlers = false, this.proposersOfInvalidBlocks = new Set(), this.validatedBlockSlots = new Set();
|
|
432
57
|
// Create child logger with fisherman prefix if in fisherman mode
|
|
433
58
|
this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
|
|
434
59
|
this.tracer = telemetry.getTracer('Validator');
|
|
@@ -482,13 +107,13 @@ _dec = trackSpan('validator.attestToProposal', (proposal, proposalSender)=>({
|
|
|
482
107
|
this.log.error(`Error updating epoch committee`, err);
|
|
483
108
|
}
|
|
484
109
|
}
|
|
485
|
-
static new(config,
|
|
110
|
+
static new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient()) {
|
|
486
111
|
const metrics = new ValidatorMetrics(telemetry);
|
|
487
112
|
const blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
488
113
|
txsPermitted: !config.disableTransactions
|
|
489
114
|
});
|
|
490
|
-
const blockProposalHandler = new BlockProposalHandler(
|
|
491
|
-
const validator = new ValidatorClient(NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager), epochCache, p2pClient, blockProposalHandler, config, blobClient, dateProvider, telemetry);
|
|
115
|
+
const blockProposalHandler = new BlockProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, config, metrics, dateProvider, telemetry);
|
|
116
|
+
const validator = new ValidatorClient(NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager), epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, dateProvider, telemetry);
|
|
492
117
|
return validator;
|
|
493
118
|
}
|
|
494
119
|
getValidatorAddresses() {
|
|
@@ -497,10 +122,6 @@ _dec = trackSpan('validator.attestToProposal', (proposal, proposalSender)=>({
|
|
|
497
122
|
getBlockProposalHandler() {
|
|
498
123
|
return this.blockProposalHandler;
|
|
499
124
|
}
|
|
500
|
-
// Proxy method for backwards compatibility with tests
|
|
501
|
-
reExecuteTransactions(proposal, blockNumber, txs, l1ToL2Messages) {
|
|
502
|
-
return this.blockProposalHandler.reexecuteTransactions(proposal, blockNumber, txs, l1ToL2Messages);
|
|
503
|
-
}
|
|
504
125
|
signWithAddress(addr, msg) {
|
|
505
126
|
return this.keyStore.signTypedDataWithAddress(addr, msg);
|
|
506
127
|
}
|
|
@@ -541,41 +162,50 @@ _dec = trackSpan('validator.attestToProposal', (proposal, proposalSender)=>({
|
|
|
541
162
|
if (!this.hasRegisteredHandlers) {
|
|
542
163
|
this.hasRegisteredHandlers = true;
|
|
543
164
|
this.log.debug(`Registering validator handlers for p2p client`);
|
|
544
|
-
|
|
545
|
-
this.
|
|
165
|
+
// Block proposal handler - validates but does NOT attest (validators only attest to checkpoints)
|
|
166
|
+
const blockHandler = (block, proposalSender)=>this.validateBlockProposal(block, proposalSender);
|
|
167
|
+
this.p2pClient.registerBlockProposalHandler(blockHandler);
|
|
168
|
+
// Checkpoint proposal handler - validates and creates attestations
|
|
169
|
+
// The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
|
|
170
|
+
// and processed separately via the block handler above.
|
|
171
|
+
const checkpointHandler = (checkpoint, proposalSender)=>this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
172
|
+
this.p2pClient.registerCheckpointProposalHandler(checkpointHandler);
|
|
546
173
|
const myAddresses = this.getValidatorAddresses();
|
|
547
174
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
548
175
|
await this.p2pClient.addReqRespSubProtocol(ReqRespSubProtocol.AUTH, this.handleAuthRequest.bind(this));
|
|
549
176
|
}
|
|
550
177
|
}
|
|
551
|
-
|
|
178
|
+
/**
|
|
179
|
+
* Validate a block proposal from a peer.
|
|
180
|
+
* Note: Validators do NOT attest to individual blocks - attestations are only for checkpoint proposals.
|
|
181
|
+
* @returns true if the proposal is valid, false otherwise
|
|
182
|
+
*/ async validateBlockProposal(proposal, proposalSender) {
|
|
552
183
|
const slotNumber = proposal.slotNumber;
|
|
553
184
|
const proposer = proposal.getSender();
|
|
554
185
|
// Reject proposals with invalid signatures
|
|
555
186
|
if (!proposer) {
|
|
556
|
-
this.log.warn(`Received proposal with invalid signature for slot ${slotNumber}`);
|
|
557
|
-
return
|
|
187
|
+
this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
|
|
188
|
+
return false;
|
|
558
189
|
}
|
|
559
|
-
// Check
|
|
190
|
+
// Check if we're in the committee (for metrics purposes)
|
|
560
191
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
561
192
|
const partOfCommittee = inCommittee.length > 0;
|
|
562
193
|
const proposalInfo = {
|
|
563
194
|
...proposal.toBlockInfo(),
|
|
564
195
|
proposer: proposer.toString()
|
|
565
196
|
};
|
|
566
|
-
this.log.info(`Received proposal for slot ${slotNumber}`, {
|
|
197
|
+
this.log.info(`Received block proposal for slot ${slotNumber}`, {
|
|
567
198
|
...proposalInfo,
|
|
568
199
|
txHashes: proposal.txHashes.map((t)=>t.toString()),
|
|
569
200
|
fishermanMode: this.config.fishermanMode || false
|
|
570
201
|
});
|
|
571
|
-
// Reexecute txs if we are part of the committee
|
|
572
|
-
// invalid proposals even when not in the committee, or if we are configured to always reexecute for monitoring purposes.
|
|
202
|
+
// Reexecute txs if we are part of the committee, or if slashing is enabled, or if we are configured to always reexecute.
|
|
573
203
|
// In fisherman mode, we always reexecute to validate proposals.
|
|
574
204
|
const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
|
|
575
205
|
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals || this.blobClient.canUpload();
|
|
576
206
|
const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute);
|
|
577
207
|
if (!validationResult.isValid) {
|
|
578
|
-
this.log.warn(`
|
|
208
|
+
this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
579
209
|
const reason = validationResult.reason || 'unknown';
|
|
580
210
|
// Classify failure reason: bad proposal vs node issue
|
|
581
211
|
const badProposalReasons = [
|
|
@@ -588,7 +218,7 @@ _dec = trackSpan('validator.attestToProposal', (proposal, proposalSender)=>({
|
|
|
588
218
|
if (badProposalReasons.includes(reason)) {
|
|
589
219
|
this.metrics.incFailedAttestationsBadProposal(1, reason, partOfCommittee);
|
|
590
220
|
} else {
|
|
591
|
-
// Node issues so we can't
|
|
221
|
+
// Node issues so we can't validate
|
|
592
222
|
this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
|
|
593
223
|
}
|
|
594
224
|
// Slash invalid block proposals (can happen even when not in committee)
|
|
@@ -596,35 +226,79 @@ _dec = trackSpan('validator.attestToProposal', (proposal, proposalSender)=>({
|
|
|
596
226
|
this.log.warn(`Slashing proposer for invalid block proposal`, proposalInfo);
|
|
597
227
|
this.slashInvalidBlock(proposal);
|
|
598
228
|
}
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
this.log.info(`Validated block proposal for slot ${slotNumber}`, {
|
|
232
|
+
...proposalInfo,
|
|
233
|
+
inCommittee: partOfCommittee,
|
|
234
|
+
fishermanMode: this.config.fishermanMode || false
|
|
235
|
+
});
|
|
236
|
+
// TODO(palla/mbps): Remove this once checkpoint validation is stable.
|
|
237
|
+
// Track that we successfully validated a block for this slot, so we can attest to checkpoint proposals for it.
|
|
238
|
+
this.validatedBlockSlots.add(slotNumber);
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Validate and attest to a checkpoint proposal from a peer.
|
|
243
|
+
* The proposal is received as CheckpointProposalCore (without lastBlock) since
|
|
244
|
+
* the lastBlock is extracted and processed separately via the block handler.
|
|
245
|
+
* @returns Checkpoint attestations if valid, undefined otherwise
|
|
246
|
+
*/ async attestToCheckpointProposal(proposal, _proposalSender) {
|
|
247
|
+
const slotNumber = proposal.slotNumber;
|
|
248
|
+
const proposer = proposal.getSender();
|
|
249
|
+
// Reject proposals with invalid signatures
|
|
250
|
+
if (!proposer) {
|
|
251
|
+
this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
|
|
599
252
|
return undefined;
|
|
600
253
|
}
|
|
601
254
|
// Check that I have any address in current committee before attesting
|
|
255
|
+
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
256
|
+
const partOfCommittee = inCommittee.length > 0;
|
|
257
|
+
const proposalInfo = {
|
|
258
|
+
slotNumber,
|
|
259
|
+
archive: proposal.archive.toString(),
|
|
260
|
+
proposer: proposer.toString(),
|
|
261
|
+
txCount: proposal.txHashes.length
|
|
262
|
+
};
|
|
263
|
+
this.log.info(`Received checkpoint proposal for slot ${slotNumber}`, {
|
|
264
|
+
...proposalInfo,
|
|
265
|
+
txHashes: proposal.txHashes.map((t)=>t.toString()),
|
|
266
|
+
fishermanMode: this.config.fishermanMode || false
|
|
267
|
+
});
|
|
268
|
+
// TODO(palla/mbps): Remove this once checkpoint validation is stable.
|
|
269
|
+
// Check that we have successfully validated a block for this slot before attesting to the checkpoint.
|
|
270
|
+
if (!this.validatedBlockSlots.has(slotNumber)) {
|
|
271
|
+
this.log.warn(`No validated block found for slot ${slotNumber}, refusing to attest to checkpoint`, proposalInfo);
|
|
272
|
+
return undefined;
|
|
273
|
+
}
|
|
274
|
+
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
|
|
275
|
+
// TODO(palla/mbps): Change default to false once checkpoint validation is stable.
|
|
276
|
+
if (this.config.skipCheckpointProposalValidation !== false) {
|
|
277
|
+
this.log.verbose(`Skipping checkpoint proposal validation for slot ${slotNumber}`, proposalInfo);
|
|
278
|
+
} else {
|
|
279
|
+
const validationResult = await this.validateCheckpointProposal(proposal, proposalInfo);
|
|
280
|
+
if (!validationResult.isValid) {
|
|
281
|
+
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
282
|
+
return undefined;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
// Upload blobs to filestore if we can (fire and forget)
|
|
286
|
+
if (this.blobClient.canUpload()) {
|
|
287
|
+
void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
288
|
+
}
|
|
289
|
+
// Check that I have any address in current committee before attesting
|
|
602
290
|
// In fisherman mode, we still create attestations for validation even if not in committee
|
|
603
291
|
if (!partOfCommittee && !this.config.fishermanMode) {
|
|
604
292
|
this.log.verbose(`No validator in the current committee, skipping attestation`, proposalInfo);
|
|
605
293
|
return undefined;
|
|
606
294
|
}
|
|
607
295
|
// Provided all of the above checks pass, we can attest to the proposal
|
|
608
|
-
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} proposal for slot ${slotNumber}`, {
|
|
296
|
+
this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${slotNumber}`, {
|
|
609
297
|
...proposalInfo,
|
|
610
298
|
inCommittee: partOfCommittee,
|
|
611
299
|
fishermanMode: this.config.fishermanMode || false
|
|
612
300
|
});
|
|
613
301
|
this.metrics.incSuccessfulAttestations(inCommittee.length);
|
|
614
|
-
// Upload blobs to filestore after successful re-execution (fire-and-forget)
|
|
615
|
-
if (validationResult.reexecutionResult?.block && this.blobClient.canUpload()) {
|
|
616
|
-
void Promise.resolve().then(async ()=>{
|
|
617
|
-
try {
|
|
618
|
-
const blobFields = validationResult.reexecutionResult.block.getCheckpointBlobFields();
|
|
619
|
-
const blobs = getBlobsPerL1Block(blobFields);
|
|
620
|
-
await this.blobClient.sendBlobsToFilestore(blobs);
|
|
621
|
-
this.log.debug(`Uploaded ${blobs.length} blobs to filestore from re-execution`, proposalInfo);
|
|
622
|
-
} catch (err) {
|
|
623
|
-
this.log.warn(`Failed to upload blobs from re-execution`, err);
|
|
624
|
-
}
|
|
625
|
-
});
|
|
626
|
-
}
|
|
627
|
-
// If the above function does not throw an error, then we can attest to the proposal
|
|
628
302
|
// Determine which validators should attest
|
|
629
303
|
let attestors;
|
|
630
304
|
if (partOfCommittee) {
|
|
@@ -641,13 +315,194 @@ _dec = trackSpan('validator.attestToProposal', (proposal, proposalSender)=>({
|
|
|
641
315
|
}
|
|
642
316
|
if (this.config.fishermanMode) {
|
|
643
317
|
// bail out early and don't save attestations to the pool in fisherman mode
|
|
644
|
-
this.log.info(`Creating attestations for
|
|
318
|
+
this.log.info(`Creating checkpoint attestations for slot ${slotNumber}`, {
|
|
645
319
|
...proposalInfo,
|
|
646
320
|
attestors: attestors.map((a)=>a.toString())
|
|
647
321
|
});
|
|
648
322
|
return undefined;
|
|
649
323
|
}
|
|
650
|
-
return this.
|
|
324
|
+
return this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
325
|
+
}
|
|
326
|
+
async createCheckpointAttestationsFromProposal(proposal, attestors = []) {
|
|
327
|
+
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
328
|
+
await this.p2pClient.addCheckpointAttestations(attestations);
|
|
329
|
+
return attestations;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
|
|
333
|
+
* @returns Validation result with isValid flag and reason if invalid.
|
|
334
|
+
*/ async validateCheckpointProposal(proposal, proposalInfo) {
|
|
335
|
+
const slot = proposal.slotNumber;
|
|
336
|
+
const timeoutSeconds = 10;
|
|
337
|
+
// Wait for last block to sync by archive
|
|
338
|
+
let lastBlockHeader;
|
|
339
|
+
try {
|
|
340
|
+
lastBlockHeader = await retryUntil(async ()=>{
|
|
341
|
+
await this.blockSource.syncImmediate();
|
|
342
|
+
return this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
343
|
+
}, `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`, timeoutSeconds, 0.5);
|
|
344
|
+
} catch (err) {
|
|
345
|
+
if (err instanceof TimeoutError) {
|
|
346
|
+
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
347
|
+
return {
|
|
348
|
+
isValid: false,
|
|
349
|
+
reason: 'last_block_not_found'
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
|
|
353
|
+
return {
|
|
354
|
+
isValid: false,
|
|
355
|
+
reason: 'block_fetch_error'
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
if (!lastBlockHeader) {
|
|
359
|
+
this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
|
|
360
|
+
return {
|
|
361
|
+
isValid: false,
|
|
362
|
+
reason: 'last_block_not_found'
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
// Get the last full block to determine checkpoint number
|
|
366
|
+
const lastBlock = await this.blockSource.getL2BlockNew(lastBlockHeader.getBlockNumber());
|
|
367
|
+
if (!lastBlock) {
|
|
368
|
+
this.log.warn(`Last block ${lastBlockHeader.getBlockNumber()} not found`, proposalInfo);
|
|
369
|
+
return {
|
|
370
|
+
isValid: false,
|
|
371
|
+
reason: 'last_block_not_found'
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
const checkpointNumber = lastBlock.checkpointNumber;
|
|
375
|
+
// Get all full blocks for the slot and checkpoint
|
|
376
|
+
const blocks = await this.getBlocksForSlot(slot, lastBlockHeader, checkpointNumber);
|
|
377
|
+
if (blocks.length === 0) {
|
|
378
|
+
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
379
|
+
return {
|
|
380
|
+
isValid: false,
|
|
381
|
+
reason: 'no_blocks_for_slot'
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
385
|
+
...proposalInfo,
|
|
386
|
+
blockNumbers: blocks.map((b)=>b.number)
|
|
387
|
+
});
|
|
388
|
+
// Get checkpoint constants from first block
|
|
389
|
+
const firstBlock = blocks[0];
|
|
390
|
+
const constants = this.extractCheckpointConstants(firstBlock);
|
|
391
|
+
// Get L1-to-L2 messages for this checkpoint
|
|
392
|
+
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
393
|
+
// Fork world state at the block before the first block
|
|
394
|
+
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
395
|
+
const fork = await this.worldState.fork(parentBlockNumber);
|
|
396
|
+
try {
|
|
397
|
+
// Create checkpoint builder with all existing blocks
|
|
398
|
+
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, l1ToL2Messages, fork, blocks);
|
|
399
|
+
// Complete the checkpoint to get computed values
|
|
400
|
+
const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
|
|
401
|
+
// Compare checkpoint header with proposal
|
|
402
|
+
if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
|
|
403
|
+
this.log.warn(`Checkpoint header mismatch`, {
|
|
404
|
+
...proposalInfo,
|
|
405
|
+
computed: computedCheckpoint.header.toInspect(),
|
|
406
|
+
proposal: proposal.checkpointHeader.toInspect()
|
|
407
|
+
});
|
|
408
|
+
return {
|
|
409
|
+
isValid: false,
|
|
410
|
+
reason: 'checkpoint_header_mismatch'
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
// Compare archive root with proposal
|
|
414
|
+
if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
|
|
415
|
+
this.log.warn(`Archive root mismatch`, {
|
|
416
|
+
...proposalInfo,
|
|
417
|
+
computed: computedCheckpoint.archive.root.toString(),
|
|
418
|
+
proposal: proposal.archive.toString()
|
|
419
|
+
});
|
|
420
|
+
return {
|
|
421
|
+
isValid: false,
|
|
422
|
+
reason: 'archive_mismatch'
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
426
|
+
return {
|
|
427
|
+
isValid: true
|
|
428
|
+
};
|
|
429
|
+
} finally{
|
|
430
|
+
await fork.close();
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Get all full blocks for a given slot and checkpoint by walking backwards from the last block.
|
|
435
|
+
* Returns blocks in ascending order (earliest to latest).
|
|
436
|
+
* TODO(palla/mbps): Add getL2BlocksForSlot() to L2BlockSource interface for efficiency.
|
|
437
|
+
*/ async getBlocksForSlot(slot, lastBlockHeader, checkpointNumber) {
|
|
438
|
+
const blocks = [];
|
|
439
|
+
let currentHeader = lastBlockHeader;
|
|
440
|
+
const { genesisArchiveRoot } = await this.blockSource.getGenesisValues();
|
|
441
|
+
while(currentHeader.getSlot() === slot){
|
|
442
|
+
const block = await this.blockSource.getL2BlockNew(currentHeader.getBlockNumber());
|
|
443
|
+
if (!block) {
|
|
444
|
+
this.log.warn(`Block ${currentHeader.getBlockNumber()} not found while getting blocks for slot ${slot}`);
|
|
445
|
+
break;
|
|
446
|
+
}
|
|
447
|
+
if (block.checkpointNumber !== checkpointNumber) {
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
450
|
+
blocks.unshift(block);
|
|
451
|
+
const prevArchive = currentHeader.lastArchive.root;
|
|
452
|
+
if (prevArchive.equals(genesisArchiveRoot)) {
|
|
453
|
+
break;
|
|
454
|
+
}
|
|
455
|
+
const prevHeader = await this.blockSource.getBlockHeaderByArchive(prevArchive);
|
|
456
|
+
if (!prevHeader || prevHeader.getSlot() !== slot) {
|
|
457
|
+
break;
|
|
458
|
+
}
|
|
459
|
+
currentHeader = prevHeader;
|
|
460
|
+
}
|
|
461
|
+
return blocks;
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Extract checkpoint global variables from a block.
|
|
465
|
+
*/ extractCheckpointConstants(block) {
|
|
466
|
+
const gv = block.header.globalVariables;
|
|
467
|
+
return {
|
|
468
|
+
chainId: gv.chainId,
|
|
469
|
+
version: gv.version,
|
|
470
|
+
slotNumber: gv.slotNumber,
|
|
471
|
+
coinbase: gv.coinbase,
|
|
472
|
+
feeRecipient: gv.feeRecipient,
|
|
473
|
+
gasFees: gv.gasFees
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
478
|
+
*/ async uploadBlobsForCheckpoint(proposal, proposalInfo) {
|
|
479
|
+
try {
|
|
480
|
+
const lastBlockHeader = await this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
481
|
+
if (!lastBlockHeader) {
|
|
482
|
+
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
// Get the last full block to determine checkpoint number
|
|
486
|
+
const lastBlock = await this.blockSource.getL2BlockNew(lastBlockHeader.getBlockNumber());
|
|
487
|
+
if (!lastBlock) {
|
|
488
|
+
this.log.warn(`Failed to get last block for blob upload`, proposalInfo);
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
const blocks = await this.getBlocksForSlot(proposal.slotNumber, lastBlockHeader, lastBlock.checkpointNumber);
|
|
492
|
+
if (blocks.length === 0) {
|
|
493
|
+
this.log.warn(`No blocks found for blob upload`, proposalInfo);
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
const blobFields = blocks.flatMap((b)=>b.toBlobFields());
|
|
497
|
+
const blobs = getBlobsPerL1Block(blobFields);
|
|
498
|
+
await this.blobClient.sendBlobsToFilestore(blobs);
|
|
499
|
+
this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
|
|
500
|
+
...proposalInfo,
|
|
501
|
+
numBlobs: blobs.length
|
|
502
|
+
});
|
|
503
|
+
} catch (err) {
|
|
504
|
+
this.log.warn(`Failed to upload blobs for checkpoint: ${err}`, proposalInfo);
|
|
505
|
+
}
|
|
651
506
|
}
|
|
652
507
|
slashInvalidBlock(proposal) {
|
|
653
508
|
const proposer = proposal.getSender();
|
|
@@ -671,25 +526,23 @@ _dec = trackSpan('validator.attestToProposal', (proposal, proposalSender)=>({
|
|
|
671
526
|
}
|
|
672
527
|
]);
|
|
673
528
|
}
|
|
674
|
-
|
|
675
|
-
async createBlockProposal(blockNumber, header, archive, txs, proposerAddress, options) {
|
|
529
|
+
async createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options) {
|
|
676
530
|
// TODO(palla/mbps): Prevent double proposals properly
|
|
677
|
-
// if (this.previousProposal?.slotNumber ===
|
|
531
|
+
// if (this.previousProposal?.slotNumber === blockHeader.globalVariables.slotNumber) {
|
|
678
532
|
// this.log.verbose(`Already made a proposal for the same slot, skipping proposal`);
|
|
679
533
|
// return Promise.resolve(undefined);
|
|
680
534
|
// }
|
|
681
|
-
this.log.info(`Assembling block proposal for block ${blockNumber} slot ${
|
|
682
|
-
const newProposal = await this.validationService.createBlockProposal(
|
|
535
|
+
this.log.info(`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`);
|
|
536
|
+
const newProposal = await this.validationService.createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
|
|
683
537
|
...options,
|
|
684
538
|
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
|
|
685
539
|
});
|
|
686
540
|
this.previousProposal = newProposal;
|
|
687
541
|
return newProposal;
|
|
688
542
|
}
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
this.
|
|
692
|
-
return this.createBlockProposal(0, header, archive, txs, proposerAddress, options);
|
|
543
|
+
async createCheckpointProposal(checkpointHeader, archive, lastBlockInfo, proposerAddress, options) {
|
|
544
|
+
this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
545
|
+
return await this.validationService.createCheckpointProposal(checkpointHeader, archive, lastBlockInfo, proposerAddress, options);
|
|
693
546
|
}
|
|
694
547
|
async broadcastBlockProposal(proposal) {
|
|
695
548
|
await this.p2pClient.broadcastProposal(proposal);
|
|
@@ -698,23 +551,23 @@ _dec = trackSpan('validator.attestToProposal', (proposal, proposalSender)=>({
|
|
|
698
551
|
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer);
|
|
699
552
|
}
|
|
700
553
|
async collectOwnAttestations(proposal) {
|
|
701
|
-
const slot = proposal.
|
|
554
|
+
const slot = proposal.slotNumber;
|
|
702
555
|
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
703
556
|
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, {
|
|
704
557
|
inCommittee
|
|
705
558
|
});
|
|
706
|
-
const attestations = await this.
|
|
559
|
+
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
707
560
|
// We broadcast our own attestations to our peers so, in case our block does not get mined on L1,
|
|
708
561
|
// other nodes can see that our validators did attest to this block proposal, and do not slash us
|
|
709
562
|
// due to inactivity for missed attestations.
|
|
710
|
-
void this.p2pClient.
|
|
563
|
+
void this.p2pClient.broadcastCheckpointAttestations(attestations).catch((err)=>{
|
|
711
564
|
this.log.error(`Failed to broadcast self-attestations for slot ${slot}`, err);
|
|
712
565
|
});
|
|
713
566
|
return attestations;
|
|
714
567
|
}
|
|
715
568
|
async collectAttestations(proposal, required, deadline) {
|
|
716
|
-
// Wait and poll the p2pClient's attestation pool for this
|
|
717
|
-
const slot = proposal.
|
|
569
|
+
// Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
|
|
570
|
+
const slot = proposal.slotNumber;
|
|
718
571
|
this.log.debug(`Collecting ${required} attestations for slot ${slot} with deadline ${deadline.toISOString()}`);
|
|
719
572
|
if (+deadline < this.dateProvider.now()) {
|
|
720
573
|
this.log.error(`Deadline ${deadline.toISOString()} for collecting ${required} attestations for slot ${slot} is in the past`);
|
|
@@ -725,13 +578,13 @@ _dec = trackSpan('validator.attestToProposal', (proposal, proposalSender)=>({
|
|
|
725
578
|
const myAddresses = this.getValidatorAddresses();
|
|
726
579
|
let attestations = [];
|
|
727
580
|
while(true){
|
|
728
|
-
// Filter out attestations with a mismatching
|
|
581
|
+
// Filter out attestations with a mismatching archive. This should NOT happen since we have verified
|
|
729
582
|
// the proposer signature (ie our own) before accepting the attestation into the pool via the p2p client.
|
|
730
|
-
const collectedAttestations = (await this.p2pClient.
|
|
731
|
-
if (!attestation.
|
|
732
|
-
this.log.warn(`Received attestation for slot ${slot} with mismatched
|
|
733
|
-
|
|
734
|
-
|
|
583
|
+
const collectedAttestations = (await this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalId)).filter((attestation)=>{
|
|
584
|
+
if (!attestation.archive.equals(proposal.archive)) {
|
|
585
|
+
this.log.warn(`Received attestation for slot ${slot} with mismatched archive from ${attestation.getSender()?.toString()}`, {
|
|
586
|
+
attestationArchive: attestation.archive.toString(),
|
|
587
|
+
proposalArchive: proposal.archive.toString()
|
|
735
588
|
});
|
|
736
589
|
return false;
|
|
737
590
|
}
|
|
@@ -763,11 +616,6 @@ _dec = trackSpan('validator.attestToProposal', (proposal, proposalSender)=>({
|
|
|
763
616
|
await sleep(this.config.attestationPollingIntervalMs);
|
|
764
617
|
}
|
|
765
618
|
}
|
|
766
|
-
async createBlockAttestationsFromProposal(proposal, attestors = []) {
|
|
767
|
-
const attestations = await this.validationService.attestToProposal(proposal, attestors);
|
|
768
|
-
await this.p2pClient.addAttestations(attestations);
|
|
769
|
-
return attestations;
|
|
770
|
-
}
|
|
771
619
|
async handleAuthRequest(peer, msg) {
|
|
772
620
|
const authRequest = AuthRequest.fromBuffer(msg);
|
|
773
621
|
const statusMessage = await this.p2pClient.handleAuthRequestFromPeer(authRequest, peer).catch((_)=>undefined);
|