@aztec/sequencer-client 3.0.3 → 3.9.9-nightly.20260312
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/dest/client/sequencer-client.d.ts +32 -15
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +116 -27
- package/dest/config.d.ts +29 -4
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +103 -40
- package/dest/global_variable_builder/global_builder.d.ts +17 -11
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +48 -39
- package/dest/index.d.ts +2 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- package/dest/publisher/config.d.ts +33 -19
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +102 -43
- package/dest/publisher/sequencer-publisher-factory.d.ts +13 -5
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +14 -3
- package/dest/publisher/sequencer-publisher-metrics.d.ts +3 -3
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +23 -86
- package/dest/publisher/sequencer-publisher.d.ts +58 -45
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +628 -139
- package/dest/sequencer/checkpoint_proposal_job.d.ts +100 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job.js +1234 -0
- package/dest/sequencer/checkpoint_voter.d.ts +35 -0
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_voter.js +109 -0
- package/dest/sequencer/events.d.ts +46 -0
- package/dest/sequencer/events.d.ts.map +1 -0
- package/dest/sequencer/events.js +1 -0
- package/dest/sequencer/index.d.ts +4 -2
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +3 -1
- package/dest/sequencer/metrics.d.ts +37 -5
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +216 -72
- package/dest/sequencer/sequencer.d.ts +122 -131
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +705 -635
- package/dest/sequencer/timetable.d.ts +54 -16
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +147 -62
- package/dest/sequencer/types.d.ts +3 -0
- package/dest/sequencer/types.d.ts.map +1 -0
- package/dest/sequencer/types.js +1 -0
- package/dest/sequencer/utils.d.ts +14 -8
- package/dest/sequencer/utils.d.ts.map +1 -1
- package/dest/sequencer/utils.js +7 -4
- package/dest/test/index.d.ts +5 -6
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +95 -0
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
- package/dest/test/mock_checkpoint_builder.js +233 -0
- package/dest/test/utils.d.ts +53 -0
- package/dest/test/utils.d.ts.map +1 -0
- package/dest/test/utils.js +104 -0
- package/package.json +30 -28
- package/src/client/sequencer-client.ts +154 -45
- package/src/config.ts +119 -45
- package/src/global_variable_builder/global_builder.ts +57 -51
- package/src/index.ts +1 -7
- package/src/publisher/config.ts +115 -46
- package/src/publisher/sequencer-publisher-factory.ts +26 -9
- package/src/publisher/sequencer-publisher-metrics.ts +19 -71
- package/src/publisher/sequencer-publisher.ts +334 -176
- package/src/sequencer/README.md +531 -0
- package/src/sequencer/checkpoint_proposal_job.ts +950 -0
- package/src/sequencer/checkpoint_voter.ts +130 -0
- package/src/sequencer/events.ts +27 -0
- package/src/sequencer/index.ts +3 -1
- package/src/sequencer/metrics.ts +267 -81
- package/src/sequencer/sequencer.ts +444 -834
- package/src/sequencer/timetable.ts +178 -83
- package/src/sequencer/types.ts +6 -0
- package/src/sequencer/utils.ts +18 -9
- package/src/test/index.ts +4 -5
- package/src/test/mock_checkpoint_builder.ts +325 -0
- package/src/test/utils.ts +167 -0
- package/dest/sequencer/block_builder.d.ts +0 -28
- package/dest/sequencer/block_builder.d.ts.map +0 -1
- package/dest/sequencer/block_builder.js +0 -127
- package/dest/tx_validator/nullifier_cache.d.ts +0 -14
- package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
- package/dest/tx_validator/nullifier_cache.js +0 -24
- package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -53
- package/src/sequencer/block_builder.ts +0 -214
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -133
|
@@ -1,48 +1,411 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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);
|
|
6
372
|
}
|
|
373
|
+
var _dec, _dec1, _dec2, _dec3, _initProto;
|
|
7
374
|
import { getKzg } from '@aztec/blob-lib';
|
|
8
|
-
import {
|
|
375
|
+
import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
9
376
|
import { NoCommitteeError } from '@aztec/ethereum/contracts';
|
|
10
|
-
import { FormattedViemError } from '@aztec/ethereum/utils';
|
|
11
377
|
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
12
|
-
import { omit, pick } from '@aztec/foundation/collection';
|
|
13
|
-
import { randomInt } from '@aztec/foundation/crypto/random';
|
|
378
|
+
import { merge, omit, pick } from '@aztec/foundation/collection';
|
|
14
379
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
15
380
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
16
|
-
import { Signature } from '@aztec/foundation/eth-signature';
|
|
17
381
|
import { createLogger } from '@aztec/foundation/log';
|
|
18
382
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
19
|
-
import {
|
|
20
|
-
import { unfreeze } from '@aztec/foundation/types';
|
|
21
|
-
import { CommitteeAttestationsAndSigners, MaliciousCommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
|
|
22
|
-
import { getSlotAtTimestamp, getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
23
|
-
import { Gas } from '@aztec/stdlib/gas';
|
|
383
|
+
import { getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
24
384
|
import { SequencerConfigSchema } from '@aztec/stdlib/interfaces/server';
|
|
25
|
-
import { orderAttestations } from '@aztec/stdlib/p2p';
|
|
26
|
-
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
27
385
|
import { pickFromSchema } from '@aztec/stdlib/schemas';
|
|
28
386
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
29
|
-
import { ContentCommitment } from '@aztec/stdlib/tx';
|
|
30
|
-
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
31
387
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
32
388
|
import EventEmitter from 'node:events';
|
|
389
|
+
import { DefaultSequencerConfig } from '../config.js';
|
|
390
|
+
import { CheckpointProposalJob } from './checkpoint_proposal_job.js';
|
|
391
|
+
import { CheckpointVoter } from './checkpoint_voter.js';
|
|
33
392
|
import { SequencerInterruptedError, SequencerTooSlowError } from './errors.js';
|
|
34
393
|
import { SequencerMetrics } from './metrics.js';
|
|
35
394
|
import { SequencerTimetable } from './timetable.js';
|
|
36
395
|
import { SequencerState } from './utils.js';
|
|
37
396
|
export { SequencerState };
|
|
397
|
+
_dec = trackSpan('Sequencer.work'), _dec1 = trackSpan('Sequencer.prepareCheckpointProposal'), _dec2 = trackSpan('Seqeuencer.tryVoteWhenSyncFails', ({ slot })=>({
|
|
398
|
+
[Attributes.SLOT_NUMBER]: slot
|
|
399
|
+
})), _dec3 = trackSpan('Sequencer.tryVoteWhenEscapeHatchOpen', ({ slot })=>({
|
|
400
|
+
[Attributes.SLOT_NUMBER]: slot
|
|
401
|
+
}));
|
|
38
402
|
/**
|
|
39
403
|
* Sequencer client
|
|
40
|
-
* -
|
|
41
|
-
* -
|
|
42
|
-
* -
|
|
43
|
-
* -
|
|
44
|
-
* -
|
|
45
|
-
* - Publishes L1 tx(s) to the rollup contract via RollupPublisher.
|
|
404
|
+
* - Checks whether it is elected as proposer for the next slot
|
|
405
|
+
* - Builds multiple blocks and broadcasts them
|
|
406
|
+
* - Collects attestations for the checkpoint
|
|
407
|
+
* - Publishes the checkpoint to L1
|
|
408
|
+
* - Votes for proposals and slashes on L1
|
|
46
409
|
*/ export class Sequencer extends EventEmitter {
|
|
47
410
|
publisherFactory;
|
|
48
411
|
validatorClient;
|
|
@@ -52,152 +415,166 @@ export { SequencerState };
|
|
|
52
415
|
slasherClient;
|
|
53
416
|
l2BlockSource;
|
|
54
417
|
l1ToL2MessageSource;
|
|
55
|
-
|
|
418
|
+
checkpointsBuilder;
|
|
56
419
|
l1Constants;
|
|
57
420
|
dateProvider;
|
|
58
421
|
epochCache;
|
|
59
422
|
rollupContract;
|
|
60
|
-
config;
|
|
61
423
|
telemetry;
|
|
62
424
|
log;
|
|
425
|
+
static{
|
|
426
|
+
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
427
|
+
[
|
|
428
|
+
_dec,
|
|
429
|
+
2,
|
|
430
|
+
"work"
|
|
431
|
+
],
|
|
432
|
+
[
|
|
433
|
+
_dec1,
|
|
434
|
+
2,
|
|
435
|
+
"prepareCheckpointProposal"
|
|
436
|
+
],
|
|
437
|
+
[
|
|
438
|
+
_dec2,
|
|
439
|
+
2,
|
|
440
|
+
"tryVoteWhenSyncFails"
|
|
441
|
+
],
|
|
442
|
+
[
|
|
443
|
+
_dec3,
|
|
444
|
+
2,
|
|
445
|
+
"tryVoteWhenEscapeHatchOpen"
|
|
446
|
+
]
|
|
447
|
+
], []));
|
|
448
|
+
}
|
|
63
449
|
runningPromise;
|
|
64
|
-
pollingIntervalMs;
|
|
65
|
-
maxTxsPerBlock;
|
|
66
|
-
minTxsPerBlock;
|
|
67
|
-
maxL1TxInclusionTimeIntoSlot;
|
|
68
450
|
state;
|
|
69
|
-
maxBlockSizeInBytes;
|
|
70
|
-
maxBlockGas;
|
|
71
451
|
metrics;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
/** The last slot for which we
|
|
75
|
-
/**
|
|
452
|
+
/** The last slot for which we attempted to perform our voting duties with degraded block production */ lastSlotForFallbackVote;
|
|
453
|
+
/** The last slot for which we logged "no committee" warning, to avoid spam */ lastSlotForNoCommitteeWarning;
|
|
454
|
+
/** The last slot for which we triggered a checkpoint proposal job, to prevent duplicate attempts. */ lastSlotForCheckpointProposalJob;
|
|
455
|
+
/** Last successful checkpoint proposed */ lastCheckpointProposed;
|
|
456
|
+
/** The last epoch for which we logged strategy comparison in fisherman mode. */ lastEpochForStrategyComparison;
|
|
76
457
|
/** The maximum number of seconds that the sequencer can be into a slot to transition to a particular state. */ timetable;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
// As long as those tests only configure a single publisher they will continue to work.
|
|
81
|
-
// This will get re-assigned every time the sequencer goes to build a new block to a publisher that is valid
|
|
82
|
-
// for the block proposer.
|
|
83
|
-
publisher;
|
|
84
|
-
constructor(publisherFactory, validatorClient, globalsBuilder, p2pClient, worldState, slasherClient, l2BlockSource, l1ToL2MessageSource, blockBuilder, l1Constants, dateProvider, epochCache, rollupContract, config, telemetry = getTelemetryClient(), log = createLogger('sequencer')){
|
|
85
|
-
super(), this.publisherFactory = publisherFactory, this.validatorClient = validatorClient, this.globalsBuilder = globalsBuilder, this.p2pClient = p2pClient, this.worldState = worldState, this.slasherClient = slasherClient, this.l2BlockSource = l2BlockSource, this.l1ToL2MessageSource = l1ToL2MessageSource, this.blockBuilder = blockBuilder, this.l1Constants = l1Constants, this.dateProvider = dateProvider, this.epochCache = epochCache, this.rollupContract = rollupContract, this.config = config, this.telemetry = telemetry, this.log = log, this.pollingIntervalMs = 1000, this.maxTxsPerBlock = 32, this.minTxsPerBlock = 1, this.maxL1TxInclusionTimeIntoSlot = 0, this.state = SequencerState.STOPPED, this.maxBlockSizeInBytes = 1024 * 1024, this.maxBlockGas = new Gas(100e9, 100e9), this.enforceTimeTable = false;
|
|
458
|
+
/** Config for the sequencer */ config;
|
|
459
|
+
constructor(publisherFactory, validatorClient, globalsBuilder, p2pClient, worldState, slasherClient, l2BlockSource, l1ToL2MessageSource, checkpointsBuilder, l1Constants, dateProvider, epochCache, rollupContract, config, telemetry = getTelemetryClient(), log = createLogger('sequencer')){
|
|
460
|
+
super(), this.publisherFactory = publisherFactory, this.validatorClient = validatorClient, this.globalsBuilder = globalsBuilder, this.p2pClient = p2pClient, this.worldState = worldState, this.slasherClient = slasherClient, this.l2BlockSource = l2BlockSource, this.l1ToL2MessageSource = l1ToL2MessageSource, this.checkpointsBuilder = checkpointsBuilder, this.l1Constants = l1Constants, this.dateProvider = dateProvider, this.epochCache = epochCache, this.rollupContract = rollupContract, this.telemetry = telemetry, this.log = log, this.state = (_initProto(this), SequencerState.STOPPED), this.config = DefaultSequencerConfig;
|
|
86
461
|
// Add [FISHERMAN] prefix to logger if in fisherman mode
|
|
87
|
-
if (
|
|
462
|
+
if (config.fishermanMode) {
|
|
88
463
|
this.log = log.createChild('[FISHERMAN]');
|
|
89
464
|
}
|
|
90
465
|
this.metrics = new SequencerMetrics(telemetry, this.rollupContract, 'Sequencer');
|
|
91
|
-
|
|
92
|
-
this.updateConfig(this.config);
|
|
466
|
+
this.updateConfig(config);
|
|
93
467
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return this.validatorClient?.getValidatorAddresses();
|
|
99
|
-
}
|
|
100
|
-
getConfig() {
|
|
101
|
-
return this.config;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Updates sequencer config by the defined values in the config on input.
|
|
105
|
-
* @param config - New parameters.
|
|
106
|
-
*/ updateConfig(config) {
|
|
107
|
-
this.log.info(`Sequencer config set`, omit(pickFromSchema(config, SequencerConfigSchema), 'txPublicSetupAllowList'));
|
|
108
|
-
if (config.transactionPollingIntervalMS !== undefined) {
|
|
109
|
-
this.pollingIntervalMs = config.transactionPollingIntervalMS;
|
|
110
|
-
}
|
|
111
|
-
if (config.maxTxsPerBlock !== undefined) {
|
|
112
|
-
this.maxTxsPerBlock = config.maxTxsPerBlock;
|
|
113
|
-
}
|
|
114
|
-
if (config.minTxsPerBlock !== undefined) {
|
|
115
|
-
this.minTxsPerBlock = config.minTxsPerBlock;
|
|
116
|
-
}
|
|
117
|
-
if (config.maxDABlockGas !== undefined) {
|
|
118
|
-
this.maxBlockGas = new Gas(config.maxDABlockGas, this.maxBlockGas.l2Gas);
|
|
119
|
-
}
|
|
120
|
-
if (config.maxL2BlockGas !== undefined) {
|
|
121
|
-
this.maxBlockGas = new Gas(this.maxBlockGas.daGas, config.maxL2BlockGas);
|
|
122
|
-
}
|
|
123
|
-
if (config.maxBlockSizeInBytes !== undefined) {
|
|
124
|
-
this.maxBlockSizeInBytes = config.maxBlockSizeInBytes;
|
|
125
|
-
}
|
|
126
|
-
if (config.governanceProposerPayload) {
|
|
127
|
-
this.governanceProposerPayload = config.governanceProposerPayload;
|
|
128
|
-
}
|
|
129
|
-
if (config.maxL1TxInclusionTimeIntoSlot !== undefined) {
|
|
130
|
-
this.maxL1TxInclusionTimeIntoSlot = config.maxL1TxInclusionTimeIntoSlot;
|
|
131
|
-
}
|
|
132
|
-
if (config.enforceTimeTable !== undefined) {
|
|
133
|
-
this.enforceTimeTable = config.enforceTimeTable;
|
|
134
|
-
}
|
|
135
|
-
this.setTimeTable();
|
|
136
|
-
// TODO: Just read everything from the config object as needed instead of copying everything into local vars.
|
|
137
|
-
// Update all values on this.config that are populated in the config object.
|
|
138
|
-
Object.assign(this.config, config);
|
|
139
|
-
}
|
|
140
|
-
setTimeTable() {
|
|
468
|
+
/** Updates sequencer config by the defined values and updates the timetable */ updateConfig(config) {
|
|
469
|
+
const filteredConfig = pickFromSchema(config, SequencerConfigSchema);
|
|
470
|
+
this.log.info(`Updated sequencer config`, omit(filteredConfig, 'txPublicSetupAllowListExtend'));
|
|
471
|
+
this.config = merge(this.config, filteredConfig);
|
|
141
472
|
this.timetable = new SequencerTimetable({
|
|
142
473
|
ethereumSlotDuration: this.l1Constants.ethereumSlotDuration,
|
|
143
474
|
aztecSlotDuration: this.aztecSlotDuration,
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
475
|
+
l1PublishingTime: this.l1PublishingTime,
|
|
476
|
+
p2pPropagationTime: this.config.attestationPropagationTime,
|
|
477
|
+
blockDurationMs: this.config.blockDurationMs,
|
|
478
|
+
enforce: this.config.enforceTimeTable
|
|
147
479
|
}, this.metrics, this.log);
|
|
148
480
|
}
|
|
149
|
-
|
|
150
|
-
// Takes ~3s to precompute some tables.
|
|
481
|
+
/** Initializes the sequencer (precomputes tables). Takes about 3s. */ init() {
|
|
151
482
|
getKzg();
|
|
152
|
-
this.publisher = (await this.publisherFactory.create(undefined)).publisher;
|
|
153
483
|
}
|
|
154
|
-
/**
|
|
155
|
-
|
|
156
|
-
*/ start() {
|
|
157
|
-
this.runningPromise = new RunningPromise(this.safeWork.bind(this), this.log, this.pollingIntervalMs);
|
|
484
|
+
/** Starts the sequencer and moves to IDLE state. */ start() {
|
|
485
|
+
this.runningPromise = new RunningPromise(this.safeWork.bind(this), this.log, this.config.sequencerPollingIntervalMS);
|
|
158
486
|
this.setState(SequencerState.IDLE, undefined, {
|
|
159
487
|
force: true
|
|
160
488
|
});
|
|
161
489
|
this.runningPromise.start();
|
|
162
490
|
this.log.info('Started sequencer');
|
|
163
491
|
}
|
|
164
|
-
/**
|
|
165
|
-
* Stops the sequencer from processing txs and moves to STOPPED state.
|
|
166
|
-
*/ async stop() {
|
|
492
|
+
/** Stops the sequencer from building blocks and moves to STOPPED state. */ async stop() {
|
|
167
493
|
this.log.info(`Stopping sequencer`);
|
|
168
494
|
this.setState(SequencerState.STOPPING, undefined, {
|
|
169
495
|
force: true
|
|
170
496
|
});
|
|
171
|
-
this.
|
|
497
|
+
this.publisherFactory.interruptAll();
|
|
172
498
|
await this.runningPromise?.stop();
|
|
173
499
|
this.setState(SequencerState.STOPPED, undefined, {
|
|
174
500
|
force: true
|
|
175
501
|
});
|
|
176
502
|
this.log.info('Stopped sequencer');
|
|
177
503
|
}
|
|
178
|
-
/**
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
504
|
+
/** Main sequencer loop with a try/catch */ async safeWork() {
|
|
505
|
+
try {
|
|
506
|
+
await this.work();
|
|
507
|
+
} catch (err) {
|
|
508
|
+
this.emit('checkpoint-error', {
|
|
509
|
+
error: err
|
|
510
|
+
});
|
|
511
|
+
if (err instanceof SequencerTooSlowError) {
|
|
512
|
+
// Log as warn only if we had to abort halfway through the block proposal
|
|
513
|
+
const logLvl = [
|
|
514
|
+
SequencerState.INITIALIZING_CHECKPOINT,
|
|
515
|
+
SequencerState.PROPOSER_CHECK
|
|
516
|
+
].includes(err.proposedState) ? 'debug' : 'warn';
|
|
517
|
+
this.log[logLvl](err.message, {
|
|
518
|
+
now: this.dateProvider.nowInSeconds()
|
|
519
|
+
});
|
|
520
|
+
} else {
|
|
521
|
+
// Re-throw other errors
|
|
522
|
+
throw err;
|
|
523
|
+
}
|
|
524
|
+
} finally{
|
|
525
|
+
this.setState(SequencerState.IDLE, undefined);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
/** Returns the current state of the sequencer. */ status() {
|
|
182
529
|
return {
|
|
183
530
|
state: this.state
|
|
184
531
|
};
|
|
185
532
|
}
|
|
186
533
|
/**
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
534
|
+
* Main sequencer loop:
|
|
535
|
+
* - Checks if we are up to date
|
|
536
|
+
* - If we are and we are the sequencer, collect txs and build blocks
|
|
537
|
+
* - Build multiple blocks per slot when configured
|
|
538
|
+
* - Collect attestations for the final block
|
|
539
|
+
* - Submit checkpoint
|
|
193
540
|
*/ async work() {
|
|
194
541
|
this.setState(SequencerState.SYNCHRONIZING, undefined);
|
|
195
|
-
const { slot, ts, now } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
196
|
-
// Check we
|
|
197
|
-
|
|
198
|
-
|
|
542
|
+
const { slot, ts, now, epoch } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
543
|
+
// Check if we are synced and it's our slot, grab a publisher, check previous block invalidation, etc
|
|
544
|
+
const checkpointProposalJob = await this.prepareCheckpointProposal(epoch, slot, ts, now);
|
|
545
|
+
if (!checkpointProposalJob) {
|
|
199
546
|
return;
|
|
200
547
|
}
|
|
548
|
+
// Execute the checkpoint proposal job
|
|
549
|
+
const checkpoint = await checkpointProposalJob.execute();
|
|
550
|
+
// Update last checkpoint proposed (currently unused)
|
|
551
|
+
if (checkpoint) {
|
|
552
|
+
this.lastCheckpointProposed = checkpoint;
|
|
553
|
+
}
|
|
554
|
+
// Log fee strategy comparison if on fisherman
|
|
555
|
+
if (this.config.fishermanMode && (this.lastEpochForStrategyComparison === undefined || epoch > this.lastEpochForStrategyComparison)) {
|
|
556
|
+
this.logStrategyComparison(epoch, checkpointProposalJob.getPublisher());
|
|
557
|
+
this.lastEpochForStrategyComparison = epoch;
|
|
558
|
+
}
|
|
559
|
+
return checkpoint;
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Prepares the checkpoint proposal by performing all necessary checks and setup.
|
|
563
|
+
* This is the initial step in the main loop.
|
|
564
|
+
* @returns CheckpointProposalJob if successful, undefined if we are not yet synced or are not the proposer.
|
|
565
|
+
*/ async prepareCheckpointProposal(epoch, slot, ts, now) {
|
|
566
|
+
// Check we have not already processed this slot (cheapest check)
|
|
567
|
+
// We only check this if enforce timetable is set, since we want to keep processing the same slot if we are not
|
|
568
|
+
// running against actual time (eg when we use sandbox-style automining)
|
|
569
|
+
if (this.lastSlotForCheckpointProposalJob && this.lastSlotForCheckpointProposalJob >= slot && this.config.enforceTimeTable) {
|
|
570
|
+
this.log.trace(`Slot ${slot} has already been processed`);
|
|
571
|
+
return undefined;
|
|
572
|
+
}
|
|
573
|
+
// But if we have already proposed for this slot, the we definitely have to skip it, automining or not
|
|
574
|
+
if (this.lastCheckpointProposed && this.lastCheckpointProposed.header.slotNumber >= slot) {
|
|
575
|
+
this.log.trace(`Slot ${slot} has already been published as checkpoint ${this.lastCheckpointProposed.number}`);
|
|
576
|
+
return undefined;
|
|
577
|
+
}
|
|
201
578
|
// Check all components are synced to latest as seen by the archiver (queries all subsystems)
|
|
202
579
|
const syncedTo = await this.checkSync({
|
|
203
580
|
ts,
|
|
@@ -208,236 +585,130 @@ export { SequencerState };
|
|
|
208
585
|
slot,
|
|
209
586
|
ts
|
|
210
587
|
});
|
|
211
|
-
return;
|
|
588
|
+
return undefined;
|
|
589
|
+
}
|
|
590
|
+
// If escape hatch is open for this epoch, do not start checkpoint proposal work and do not attempt invalidations.
|
|
591
|
+
// Still perform governance/slashing voting (as proposer) once per slot.
|
|
592
|
+
const isEscapeHatchOpen = await this.epochCache.isEscapeHatchOpen(epoch);
|
|
593
|
+
if (isEscapeHatchOpen) {
|
|
594
|
+
this.setState(SequencerState.PROPOSER_CHECK, slot);
|
|
595
|
+
const [canPropose, proposer] = await this.checkCanPropose(slot);
|
|
596
|
+
if (canPropose) {
|
|
597
|
+
await this.tryVoteWhenEscapeHatchOpen({
|
|
598
|
+
slot,
|
|
599
|
+
proposer
|
|
600
|
+
});
|
|
601
|
+
} else {
|
|
602
|
+
this.log.trace(`Escape hatch open but we are not proposer, skipping vote-only actions`, {
|
|
603
|
+
slot,
|
|
604
|
+
epoch,
|
|
605
|
+
proposer
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
return undefined;
|
|
212
609
|
}
|
|
213
|
-
|
|
214
|
-
const
|
|
215
|
-
const
|
|
610
|
+
// Next checkpoint follows from the last synced one
|
|
611
|
+
const checkpointNumber = CheckpointNumber(syncedTo.checkpointNumber + 1);
|
|
612
|
+
const logCtx = {
|
|
216
613
|
now,
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
l1SlotDuration: this.l1Constants.ethereumSlotDuration,
|
|
222
|
-
newBlockNumber,
|
|
614
|
+
syncedToL2Slot: syncedTo.syncedL2Slot,
|
|
615
|
+
slot,
|
|
616
|
+
slotTs: ts,
|
|
617
|
+
checkpointNumber,
|
|
223
618
|
isPendingChainValid: pick(syncedTo.pendingChainValidationStatus, 'valid', 'reason', 'invalidIndex')
|
|
224
619
|
};
|
|
225
620
|
// Check that we are a proposer for the next slot
|
|
226
621
|
this.setState(SequencerState.PROPOSER_CHECK, slot);
|
|
227
622
|
const [canPropose, proposer] = await this.checkCanPropose(slot);
|
|
228
|
-
// If we are not a proposer check if we should invalidate
|
|
623
|
+
// If we are not a proposer check if we should invalidate an invalid checkpoint, and bail
|
|
229
624
|
if (!canPropose) {
|
|
230
|
-
await this.
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
// In fisherman mode, check if we've already validated this slot to prevent duplicate attempts
|
|
234
|
-
if (this.config.fishermanMode) {
|
|
235
|
-
if (this.lastSlotForValidationBlock === slot) {
|
|
236
|
-
this.log.trace(`Already validated block building for slot ${slot} (skipping)`, {
|
|
237
|
-
slot
|
|
238
|
-
});
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
this.log.debug(`Building validation block for slot ${slot} (actual proposer: ${proposer?.toString() ?? 'none'})`, {
|
|
242
|
-
slot,
|
|
243
|
-
proposer: proposer?.toString()
|
|
244
|
-
});
|
|
245
|
-
// Mark this slot as being validated
|
|
246
|
-
this.lastSlotForValidationBlock = slot;
|
|
625
|
+
await this.considerInvalidatingCheckpoint(syncedTo, slot);
|
|
626
|
+
return undefined;
|
|
247
627
|
}
|
|
248
628
|
// Check that the slot is not taken by a block already (should never happen, since only us can propose for this slot)
|
|
249
|
-
if (syncedTo.
|
|
629
|
+
if (syncedTo.blockData && syncedTo.blockData.header.getSlot() >= slot) {
|
|
250
630
|
this.log.warn(`Cannot propose block at next L2 slot ${slot} since that slot was taken by block ${syncedTo.blockNumber}`, {
|
|
251
|
-
...
|
|
252
|
-
block: syncedTo.
|
|
631
|
+
...logCtx,
|
|
632
|
+
block: syncedTo.blockData.header.toInspect()
|
|
253
633
|
});
|
|
254
|
-
this.metrics.
|
|
255
|
-
return;
|
|
634
|
+
this.metrics.recordCheckpointPrecheckFailed('slot_already_taken');
|
|
635
|
+
return undefined;
|
|
256
636
|
}
|
|
257
637
|
// We now need to get ourselves a publisher.
|
|
258
638
|
// The returned attestor will be the one we provided if we provided one.
|
|
259
639
|
// Otherwise it will be a valid attestor for the returned publisher.
|
|
260
640
|
// In fisherman mode, pass undefined to use the fisherman's own keystore instead of the actual proposer's
|
|
261
|
-
const
|
|
641
|
+
const proposerForPublisher = this.config.fishermanMode ? undefined : proposer;
|
|
642
|
+
const { attestorAddress, publisher } = await this.publisherFactory.create(proposerForPublisher);
|
|
262
643
|
this.log.verbose(`Created publisher at address ${publisher.getSenderAddress()} for attestor ${attestorAddress}`);
|
|
263
|
-
this.publisher = publisher;
|
|
264
644
|
// In fisherman mode, set the actual proposer's address for simulations
|
|
265
|
-
if (this.config.fishermanMode) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
this.log.debug(`Set proposer address ${proposer} for simulation in fisherman mode`);
|
|
269
|
-
}
|
|
645
|
+
if (this.config.fishermanMode && proposer) {
|
|
646
|
+
publisher.setProposerAddressForSimulation(proposer);
|
|
647
|
+
this.log.debug(`Set proposer address ${proposer} for simulation in fisherman mode`);
|
|
270
648
|
}
|
|
271
|
-
// Get proposer credentials
|
|
272
|
-
const coinbase = this.validatorClient.getCoinbaseForAttestor(attestorAddress);
|
|
273
|
-
const feeRecipient = this.validatorClient.getFeeRecipientForAttestor(attestorAddress);
|
|
274
649
|
// Prepare invalidation request if the pending chain is invalid (returns undefined if no need)
|
|
275
|
-
const
|
|
276
|
-
// Check with the rollup if we can indeed propose at the next L2 slot. This check should not fail
|
|
650
|
+
const invalidateCheckpoint = await publisher.simulateInvalidateCheckpoint(syncedTo.pendingChainValidationStatus);
|
|
651
|
+
// Check with the rollup contract if we can indeed propose at the next L2 slot. This check should not fail
|
|
277
652
|
// if all the previous checks are good, but we do it just in case.
|
|
278
|
-
const canProposeCheck = await publisher.canProposeAtNextEthBlock(
|
|
653
|
+
const canProposeCheck = await publisher.canProposeAtNextEthBlock(syncedTo.archive, proposer ?? EthAddress.ZERO, invalidateCheckpoint);
|
|
279
654
|
if (canProposeCheck === undefined) {
|
|
280
|
-
this.log.warn(`Cannot propose
|
|
655
|
+
this.log.warn(`Cannot propose checkpoint ${checkpointNumber} at slot ${slot} due to failed rollup contract check`, logCtx);
|
|
281
656
|
this.emit('proposer-rollup-check-failed', {
|
|
282
|
-
reason: 'Rollup contract check failed'
|
|
657
|
+
reason: 'Rollup contract check failed',
|
|
658
|
+
slot
|
|
283
659
|
});
|
|
284
|
-
this.metrics.
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
660
|
+
this.metrics.recordCheckpointPrecheckFailed('rollup_contract_check_failed');
|
|
661
|
+
return undefined;
|
|
662
|
+
}
|
|
663
|
+
if (canProposeCheck.slot !== slot) {
|
|
287
664
|
this.log.warn(`Cannot propose block due to slot mismatch with rollup contract (this can be caused by a clock out of sync). Expected slot ${slot} but got ${canProposeCheck.slot}.`, {
|
|
288
|
-
...
|
|
665
|
+
...logCtx,
|
|
289
666
|
rollup: canProposeCheck,
|
|
290
|
-
newBlockNumber,
|
|
291
667
|
expectedSlot: slot
|
|
292
668
|
});
|
|
293
669
|
this.emit('proposer-rollup-check-failed', {
|
|
294
|
-
reason: 'Slot mismatch'
|
|
670
|
+
reason: 'Slot mismatch',
|
|
671
|
+
slot
|
|
295
672
|
});
|
|
296
|
-
this.metrics.
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
|
|
673
|
+
this.metrics.recordCheckpointPrecheckFailed('slot_mismatch');
|
|
674
|
+
return undefined;
|
|
675
|
+
}
|
|
676
|
+
if (canProposeCheck.checkpointNumber !== checkpointNumber) {
|
|
677
|
+
this.log.warn(`Cannot propose due to block mismatch with rollup contract (this can be caused by a pending archiver sync). Expected checkpoint ${checkpointNumber} but got ${canProposeCheck.checkpointNumber}.`, {
|
|
678
|
+
...logCtx,
|
|
301
679
|
rollup: canProposeCheck,
|
|
302
|
-
newBlockNumber,
|
|
303
680
|
expectedSlot: slot
|
|
304
681
|
});
|
|
305
682
|
this.emit('proposer-rollup-check-failed', {
|
|
306
|
-
reason: 'Block mismatch'
|
|
683
|
+
reason: 'Block mismatch',
|
|
684
|
+
slot
|
|
307
685
|
});
|
|
308
|
-
this.metrics.
|
|
309
|
-
return;
|
|
686
|
+
this.metrics.recordCheckpointPrecheckFailed('block_number_mismatch');
|
|
687
|
+
return undefined;
|
|
310
688
|
}
|
|
311
|
-
this.
|
|
312
|
-
|
|
689
|
+
this.lastSlotForCheckpointProposalJob = slot;
|
|
690
|
+
await this.p2pClient.prepareForSlot(slot);
|
|
691
|
+
this.log.info(`Preparing checkpoint proposal ${checkpointNumber} at slot ${slot}`, {
|
|
692
|
+
...logCtx,
|
|
693
|
+
proposer
|
|
313
694
|
});
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
// In fisherman mode, we simulate slashing but don't actually publish to L1
|
|
317
|
-
const votesPromises = this.enqueueGovernanceAndSlashingVotes(publisher, attestorAddress, slot, newGlobalVariables.timestamp);
|
|
318
|
-
// Enqueues block invalidation
|
|
319
|
-
if (invalidateBlock && !this.config.skipInvalidateBlockAsProposer) {
|
|
320
|
-
publisher.enqueueInvalidateBlock(invalidateBlock);
|
|
321
|
-
}
|
|
322
|
-
// Actual block building
|
|
323
|
-
this.setState(SequencerState.INITIALIZING_PROPOSAL, slot);
|
|
324
|
-
this.metrics.incOpenSlot(slot, proposer?.toString() ?? 'unknown');
|
|
325
|
-
const block = await this.tryBuildBlockAndEnqueuePublish(slot, proposer, newBlockNumber, publisher, newGlobalVariables, chainTipArchive, invalidateBlock);
|
|
326
|
-
// Wait until the voting promises have resolved, so all requests are enqueued
|
|
327
|
-
await Promise.all(votesPromises);
|
|
328
|
-
// In fisherman mode, we don't publish to L1
|
|
329
|
-
if (this.config.fishermanMode) {
|
|
330
|
-
// Clear pending requests
|
|
331
|
-
publisher.clearPendingRequests();
|
|
332
|
-
if (block) {
|
|
333
|
-
this.log.info(`Validation block building SUCCEEDED for slot ${slot}`, {
|
|
334
|
-
blockNumber: newBlockNumber,
|
|
335
|
-
slot: Number(slot),
|
|
336
|
-
archive: block.archive.toString(),
|
|
337
|
-
txCount: block.body.txEffects.length
|
|
338
|
-
});
|
|
339
|
-
this.lastBlockPublished = block;
|
|
340
|
-
this.metrics.recordBlockProposalSuccess();
|
|
341
|
-
} else {
|
|
342
|
-
// Block building failed in fisherman mode
|
|
343
|
-
this.log.warn(`Validation block building FAILED for slot ${slot}`, {
|
|
344
|
-
blockNumber: newBlockNumber,
|
|
345
|
-
slot: Number(slot)
|
|
346
|
-
});
|
|
347
|
-
this.metrics.recordBlockProposalFailed('block_build_failed');
|
|
348
|
-
}
|
|
349
|
-
} else {
|
|
350
|
-
// Normal mode: send the tx to L1
|
|
351
|
-
const l1Response = await publisher.sendRequests();
|
|
352
|
-
const proposedBlock = l1Response?.successfulActions.find((a)=>a === 'propose');
|
|
353
|
-
if (proposedBlock) {
|
|
354
|
-
this.lastBlockPublished = block;
|
|
355
|
-
this.emit('block-published', {
|
|
356
|
-
blockNumber: newBlockNumber,
|
|
357
|
-
slot: Number(slot)
|
|
358
|
-
});
|
|
359
|
-
await this.metrics.incFilledSlot(publisher.getSenderAddress().toString(), coinbase);
|
|
360
|
-
} else if (block) {
|
|
361
|
-
this.emit('block-publish-failed', l1Response ?? {});
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
this.setState(SequencerState.IDLE, undefined);
|
|
695
|
+
// Create and return the checkpoint proposal job
|
|
696
|
+
return this.createCheckpointProposalJob(epoch, slot, checkpointNumber, syncedTo.blockNumber, proposer, publisher, attestorAddress, invalidateCheckpoint);
|
|
365
697
|
}
|
|
366
|
-
|
|
367
|
-
this.
|
|
368
|
-
proposer,
|
|
369
|
-
publisher: publisher.getSenderAddress(),
|
|
370
|
-
globalVariables: newGlobalVariables.toInspect(),
|
|
371
|
-
chainTipArchive,
|
|
372
|
-
blockNumber: newBlockNumber,
|
|
373
|
-
slot
|
|
374
|
-
});
|
|
375
|
-
const proposalHeader = CheckpointHeader.from({
|
|
376
|
-
...newGlobalVariables,
|
|
377
|
-
timestamp: newGlobalVariables.timestamp,
|
|
378
|
-
lastArchiveRoot: chainTipArchive,
|
|
379
|
-
blockHeadersHash: Fr.ZERO,
|
|
380
|
-
contentCommitment: ContentCommitment.empty(),
|
|
381
|
-
totalManaUsed: Fr.ZERO
|
|
382
|
-
});
|
|
383
|
-
let block;
|
|
384
|
-
const pendingTxCount = await this.p2pClient.getPendingTxCount();
|
|
385
|
-
if (pendingTxCount >= this.minTxsPerBlock) {
|
|
386
|
-
// We don't fetch exactly maxTxsPerBlock txs here because we may not need all of them if we hit a limit before,
|
|
387
|
-
// and also we may need to fetch more if we don't have enough valid txs.
|
|
388
|
-
const pendingTxs = this.p2pClient.iteratePendingTxs();
|
|
389
|
-
try {
|
|
390
|
-
block = await this.buildBlockAndEnqueuePublish(pendingTxs, proposalHeader, newGlobalVariables, proposer, invalidateBlock, publisher);
|
|
391
|
-
} catch (err) {
|
|
392
|
-
this.emit('block-build-failed', {
|
|
393
|
-
reason: err.message
|
|
394
|
-
});
|
|
395
|
-
if (err instanceof FormattedViemError) {
|
|
396
|
-
this.log.verbose(`Unable to build/enqueue block ${err.message}`);
|
|
397
|
-
} else {
|
|
398
|
-
this.log.error(`Error building/enqueuing block`, err, {
|
|
399
|
-
blockNumber: newBlockNumber,
|
|
400
|
-
slot
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
this.metrics.recordBlockProposalFailed(err.name || 'unknown_error');
|
|
404
|
-
}
|
|
405
|
-
} else {
|
|
406
|
-
this.log.verbose(`Not enough txs to build block ${newBlockNumber} at slot ${slot} (got ${pendingTxCount} txs, need ${this.minTxsPerBlock})`, {
|
|
407
|
-
chainTipArchive,
|
|
408
|
-
blockNumber: newBlockNumber,
|
|
409
|
-
slot
|
|
410
|
-
});
|
|
411
|
-
this.emit('tx-count-check-failed', {
|
|
412
|
-
minTxs: this.minTxsPerBlock,
|
|
413
|
-
availableTxs: pendingTxCount
|
|
414
|
-
});
|
|
415
|
-
this.metrics.recordBlockProposalFailed('insufficient_txs');
|
|
416
|
-
}
|
|
417
|
-
return block;
|
|
698
|
+
createCheckpointProposalJob(epoch, slot, checkpointNumber, syncedToBlockNumber, proposer, publisher, attestorAddress, invalidateCheckpoint) {
|
|
699
|
+
return new CheckpointProposalJob(epoch, slot, checkpointNumber, syncedToBlockNumber, proposer, publisher, attestorAddress, invalidateCheckpoint, this.validatorClient, this.globalsBuilder, this.p2pClient, this.worldState, this.l1ToL2MessageSource, this.l2BlockSource, this.checkpointsBuilder, this.l2BlockSource, this.l1Constants, this.config, this.timetable, this.slasherClient, this.epochCache, this.dateProvider, this.metrics, this, this.setState.bind(this), this.tracer, this.log.getBindings());
|
|
418
700
|
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
if (err instanceof SequencerTooSlowError) {
|
|
424
|
-
// Log as warn only if we had to abort halfway through the block proposal
|
|
425
|
-
const logLvl = [
|
|
426
|
-
SequencerState.INITIALIZING_PROPOSAL,
|
|
427
|
-
SequencerState.PROPOSER_CHECK
|
|
428
|
-
].includes(err.proposedState) ? 'debug' : 'warn';
|
|
429
|
-
this.log[logLvl](err.message, {
|
|
430
|
-
now: this.dateProvider.nowInSeconds()
|
|
431
|
-
});
|
|
432
|
-
} else {
|
|
433
|
-
// Re-throw other errors
|
|
434
|
-
throw err;
|
|
435
|
-
}
|
|
436
|
-
} finally{
|
|
437
|
-
this.setState(SequencerState.IDLE, undefined);
|
|
438
|
-
}
|
|
701
|
+
/**
|
|
702
|
+
* Returns the current sequencer state.
|
|
703
|
+
*/ getState() {
|
|
704
|
+
return this.state;
|
|
439
705
|
}
|
|
440
|
-
|
|
706
|
+
/**
|
|
707
|
+
* Internal helper for setting the sequencer state and checks if we have enough time left in the slot to transition to the new state.
|
|
708
|
+
* @param proposedState - The new state to transition to.
|
|
709
|
+
* @param slotNumber - The current slot number.
|
|
710
|
+
* @param force - Whether to force the transition even if the sequencer is stopped.
|
|
711
|
+
*/ setState(proposedState, slotNumber, opts = {}) {
|
|
441
712
|
if (this.state === SequencerState.STOPPING && proposedState !== SequencerState.STOPPED && !opts.force) {
|
|
442
713
|
this.log.warn(`Cannot set sequencer to ${proposedState} as it is stopping.`);
|
|
443
714
|
throw new SequencerInterruptedError();
|
|
@@ -464,235 +735,23 @@ export { SequencerState };
|
|
|
464
735
|
oldState: this.state,
|
|
465
736
|
newState: proposedState,
|
|
466
737
|
secondsIntoSlot,
|
|
467
|
-
slotNumber
|
|
738
|
+
slot: slotNumber
|
|
468
739
|
});
|
|
469
740
|
this.state = proposedState;
|
|
470
741
|
}
|
|
471
|
-
async dropFailedTxsFromP2P(failedTxs) {
|
|
472
|
-
if (failedTxs.length === 0) {
|
|
473
|
-
return;
|
|
474
|
-
}
|
|
475
|
-
const failedTxData = failedTxs.map((fail)=>fail.tx);
|
|
476
|
-
const failedTxHashes = failedTxData.map((tx)=>tx.getTxHash());
|
|
477
|
-
this.log.verbose(`Dropping failed txs ${failedTxHashes.join(', ')}`);
|
|
478
|
-
await this.p2pClient.deleteTxs(failedTxHashes);
|
|
479
|
-
}
|
|
480
|
-
getBlockBuilderOptions(slot) {
|
|
481
|
-
// Deadline for processing depends on whether we're proposing a block
|
|
482
|
-
const secondsIntoSlot = this.getSecondsIntoSlot(slot);
|
|
483
|
-
const processingEndTimeWithinSlot = this.timetable.getBlockProposalExecTimeEnd(secondsIntoSlot);
|
|
484
|
-
// Deadline is only set if enforceTimeTable is enabled.
|
|
485
|
-
const deadline = this.enforceTimeTable ? new Date((this.getSlotStartBuildTimestamp(slot) + processingEndTimeWithinSlot) * 1000) : undefined;
|
|
486
|
-
return {
|
|
487
|
-
maxTransactions: this.maxTxsPerBlock,
|
|
488
|
-
maxBlockSize: this.maxBlockSizeInBytes,
|
|
489
|
-
maxBlockGas: this.maxBlockGas,
|
|
490
|
-
maxBlobFields: BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB,
|
|
491
|
-
deadline
|
|
492
|
-
};
|
|
493
|
-
}
|
|
494
|
-
/**
|
|
495
|
-
* @notice Build and propose a block to the chain
|
|
496
|
-
*
|
|
497
|
-
* @dev MUST throw instead of exiting early to ensure that world-state
|
|
498
|
-
* is being rolled back if the block is dropped.
|
|
499
|
-
*
|
|
500
|
-
* @param pendingTxs - Iterable of pending transactions to construct the block from
|
|
501
|
-
* @param proposalHeader - The partial header constructed for the proposal
|
|
502
|
-
* @param newGlobalVariables - The global variables for the new block
|
|
503
|
-
* @param proposerAddress - The address of the proposer
|
|
504
|
-
*/ async buildBlockAndEnqueuePublish(pendingTxs, proposalHeader, newGlobalVariables, proposerAddress, invalidateBlock, publisher) {
|
|
505
|
-
await publisher.validateBlockHeader(proposalHeader, invalidateBlock);
|
|
506
|
-
const blockNumber = newGlobalVariables.blockNumber;
|
|
507
|
-
const checkpointNumber = CheckpointNumber.fromBlockNumber(blockNumber);
|
|
508
|
-
const slot = proposalHeader.slotNumber;
|
|
509
|
-
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
510
|
-
const workTimer = new Timer();
|
|
511
|
-
this.setState(SequencerState.CREATING_BLOCK, slot);
|
|
512
|
-
try {
|
|
513
|
-
const blockBuilderOptions = this.getBlockBuilderOptions(slot);
|
|
514
|
-
const buildBlockRes = await this.blockBuilder.buildBlock(pendingTxs, l1ToL2Messages, newGlobalVariables, blockBuilderOptions);
|
|
515
|
-
const { publicGas, block, publicProcessorDuration, numTxs, numMsgs, blockBuildingTimer, usedTxs, failedTxs } = buildBlockRes;
|
|
516
|
-
const blockBuildDuration = workTimer.ms();
|
|
517
|
-
await this.dropFailedTxsFromP2P(failedTxs);
|
|
518
|
-
const minTxsPerBlock = this.minTxsPerBlock;
|
|
519
|
-
if (numTxs < minTxsPerBlock) {
|
|
520
|
-
this.log.warn(`Block ${blockNumber} has too few txs to be proposed (got ${numTxs} but required ${minTxsPerBlock})`, {
|
|
521
|
-
slot,
|
|
522
|
-
blockNumber,
|
|
523
|
-
numTxs
|
|
524
|
-
});
|
|
525
|
-
throw new Error(`Block has too few successful txs to be proposed`);
|
|
526
|
-
}
|
|
527
|
-
// TODO(@PhilWindle) We should probably periodically check for things like another
|
|
528
|
-
// block being published before ours instead of just waiting on our block
|
|
529
|
-
await publisher.validateBlockHeader(block.getCheckpointHeader(), invalidateBlock);
|
|
530
|
-
const blockStats = {
|
|
531
|
-
eventName: 'l2-block-built',
|
|
532
|
-
creator: proposerAddress?.toString() ?? publisher.getSenderAddress().toString(),
|
|
533
|
-
duration: workTimer.ms(),
|
|
534
|
-
publicProcessDuration: publicProcessorDuration,
|
|
535
|
-
rollupCircuitsDuration: blockBuildingTimer.ms(),
|
|
536
|
-
...block.getStats()
|
|
537
|
-
};
|
|
538
|
-
const blockHash = await block.hash();
|
|
539
|
-
const txHashes = block.body.txEffects.map((tx)=>tx.txHash);
|
|
540
|
-
this.log.info(`Built block ${block.number} for slot ${slot} with ${numTxs} txs and ${numMsgs} messages. ${publicGas.l2Gas / workTimer.s()} mana/s`, {
|
|
541
|
-
blockHash,
|
|
542
|
-
globalVariables: block.header.globalVariables.toInspect(),
|
|
543
|
-
txHashes,
|
|
544
|
-
...blockStats
|
|
545
|
-
});
|
|
546
|
-
// In fisherman mode, skip attestation collection
|
|
547
|
-
let attestationsAndSigners;
|
|
548
|
-
if (this.config.fishermanMode) {
|
|
549
|
-
this.log.debug('Skipping attestation collection');
|
|
550
|
-
attestationsAndSigners = CommitteeAttestationsAndSigners.empty();
|
|
551
|
-
} else {
|
|
552
|
-
this.log.debug('Collecting attestations');
|
|
553
|
-
attestationsAndSigners = await this.collectAttestations(block, usedTxs, proposerAddress);
|
|
554
|
-
this.log.verbose(`Collected ${attestationsAndSigners.attestations.length} attestations for block ${blockNumber} at slot ${slot}`, {
|
|
555
|
-
blockHash,
|
|
556
|
-
blockNumber,
|
|
557
|
-
slot
|
|
558
|
-
});
|
|
559
|
-
}
|
|
560
|
-
// In fisherman mode, skip attestation signing
|
|
561
|
-
const attestationsAndSignersSignature = this.config.fishermanMode || !this.validatorClient ? Signature.empty() : await this.validatorClient.signAttestationsAndSigners(attestationsAndSigners, proposerAddress ?? publisher.getSenderAddress());
|
|
562
|
-
await this.enqueuePublishL2Block(block, attestationsAndSigners, attestationsAndSignersSignature, invalidateBlock, publisher);
|
|
563
|
-
this.metrics.recordBuiltBlock(blockBuildDuration, publicGas.l2Gas);
|
|
564
|
-
return block;
|
|
565
|
-
} catch (err) {
|
|
566
|
-
this.metrics.recordFailedBlock();
|
|
567
|
-
throw err;
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
async collectAttestations(block, txs, proposerAddress) {
|
|
571
|
-
const { committee, seed, epoch } = await this.epochCache.getCommittee(block.slot);
|
|
572
|
-
// We checked above that the committee is defined, so this should never happen.
|
|
573
|
-
if (!committee) {
|
|
574
|
-
throw new Error('No committee when collecting attestations');
|
|
575
|
-
}
|
|
576
|
-
if (committee.length === 0) {
|
|
577
|
-
this.log.verbose(`Attesting committee is empty`);
|
|
578
|
-
return CommitteeAttestationsAndSigners.empty();
|
|
579
|
-
} else {
|
|
580
|
-
this.log.debug(`Attesting committee length is ${committee.length}`);
|
|
581
|
-
}
|
|
582
|
-
if (!this.validatorClient) {
|
|
583
|
-
throw new Error('Missing validator client: Cannot collect attestations');
|
|
584
|
-
}
|
|
585
|
-
const numberOfRequiredAttestations = Math.floor(committee.length * 2 / 3) + 1;
|
|
586
|
-
const slotNumber = block.header.globalVariables.slotNumber;
|
|
587
|
-
this.setState(SequencerState.COLLECTING_ATTESTATIONS, slotNumber);
|
|
588
|
-
this.log.debug('Creating block proposal for validators');
|
|
589
|
-
const blockProposalOptions = {
|
|
590
|
-
publishFullTxs: !!this.config.publishTxsWithProposals,
|
|
591
|
-
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
|
|
592
|
-
};
|
|
593
|
-
const proposal = await this.validatorClient.createBlockProposal(block.header.globalVariables.blockNumber, block.getCheckpointHeader(), block.archive.root, txs, proposerAddress, blockProposalOptions);
|
|
594
|
-
if (!proposal) {
|
|
595
|
-
throw new Error(`Failed to create block proposal`);
|
|
596
|
-
}
|
|
597
|
-
if (this.config.skipCollectingAttestations) {
|
|
598
|
-
this.log.warn('Skipping attestation collection as per config (attesting with own keys only)');
|
|
599
|
-
const attestations = await this.validatorClient?.collectOwnAttestations(proposal);
|
|
600
|
-
return new CommitteeAttestationsAndSigners(orderAttestations(attestations ?? [], committee));
|
|
601
|
-
}
|
|
602
|
-
this.log.debug('Broadcasting block proposal to validators');
|
|
603
|
-
await this.validatorClient.broadcastBlockProposal(proposal);
|
|
604
|
-
const attestationTimeAllowed = this.enforceTimeTable ? this.timetable.getMaxAllowedTime(SequencerState.PUBLISHING_BLOCK) : this.aztecSlotDuration;
|
|
605
|
-
this.metrics.recordRequiredAttestations(numberOfRequiredAttestations, attestationTimeAllowed);
|
|
606
|
-
const timer = new Timer();
|
|
607
|
-
let collectedAttestationsCount = 0;
|
|
608
|
-
try {
|
|
609
|
-
const attestationDeadline = new Date(this.dateProvider.now() + attestationTimeAllowed * 1000);
|
|
610
|
-
const attestations = await this.validatorClient.collectAttestations(proposal, numberOfRequiredAttestations, attestationDeadline);
|
|
611
|
-
collectedAttestationsCount = attestations.length;
|
|
612
|
-
// note: the smart contract requires that the signatures are provided in the order of the committee
|
|
613
|
-
const sorted = orderAttestations(attestations, committee);
|
|
614
|
-
// manipulate the attestations if we've been configured to do so
|
|
615
|
-
if (this.config.injectFakeAttestation || this.config.shuffleAttestationOrdering) {
|
|
616
|
-
return this.manipulateAttestations(block, epoch, seed, committee, sorted);
|
|
617
|
-
}
|
|
618
|
-
return new CommitteeAttestationsAndSigners(sorted);
|
|
619
|
-
} catch (err) {
|
|
620
|
-
if (err && err instanceof AttestationTimeoutError) {
|
|
621
|
-
collectedAttestationsCount = err.collectedCount;
|
|
622
|
-
}
|
|
623
|
-
throw err;
|
|
624
|
-
} finally{
|
|
625
|
-
this.metrics.recordCollectedAttestations(collectedAttestationsCount, timer.ms());
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
/** Breaks the attestations before publishing based on attack configs */ manipulateAttestations(block, epoch, seed, committee, attestations) {
|
|
629
|
-
// Compute the proposer index in the committee, since we dont want to tweak it.
|
|
630
|
-
// Otherwise, the L1 rollup contract will reject the block outright.
|
|
631
|
-
const proposerIndex = Number(this.epochCache.computeProposerIndex(block.slot, epoch, seed, BigInt(committee.length)));
|
|
632
|
-
if (this.config.injectFakeAttestation) {
|
|
633
|
-
// Find non-empty attestations that are not from the proposer
|
|
634
|
-
const nonProposerIndices = [];
|
|
635
|
-
for(let i = 0; i < attestations.length; i++){
|
|
636
|
-
if (!attestations[i].signature.isEmpty() && i !== proposerIndex) {
|
|
637
|
-
nonProposerIndices.push(i);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
if (nonProposerIndices.length > 0) {
|
|
641
|
-
const targetIndex = nonProposerIndices[randomInt(nonProposerIndices.length)];
|
|
642
|
-
this.log.warn(`Injecting fake attestation in block ${block.number} at index ${targetIndex}`);
|
|
643
|
-
unfreeze(attestations[targetIndex]).signature = Signature.random();
|
|
644
|
-
}
|
|
645
|
-
return new CommitteeAttestationsAndSigners(attestations);
|
|
646
|
-
}
|
|
647
|
-
if (this.config.shuffleAttestationOrdering) {
|
|
648
|
-
this.log.warn(`Shuffling attestation ordering in block ${block.number} (proposer index ${proposerIndex})`);
|
|
649
|
-
const shuffled = [
|
|
650
|
-
...attestations
|
|
651
|
-
];
|
|
652
|
-
const [i, j] = [
|
|
653
|
-
(proposerIndex + 1) % shuffled.length,
|
|
654
|
-
(proposerIndex + 2) % shuffled.length
|
|
655
|
-
];
|
|
656
|
-
const valueI = shuffled[i];
|
|
657
|
-
const valueJ = shuffled[j];
|
|
658
|
-
shuffled[i] = valueJ;
|
|
659
|
-
shuffled[j] = valueI;
|
|
660
|
-
const signers = new CommitteeAttestationsAndSigners(attestations).getSigners();
|
|
661
|
-
return new MaliciousCommitteeAttestationsAndSigners(shuffled, signers);
|
|
662
|
-
}
|
|
663
|
-
return new CommitteeAttestationsAndSigners(attestations);
|
|
664
|
-
}
|
|
665
|
-
/**
|
|
666
|
-
* Publishes the L2Block to the rollup contract.
|
|
667
|
-
* @param block - The L2Block to be published.
|
|
668
|
-
*/ async enqueuePublishL2Block(block, attestationsAndSigners, attestationsAndSignersSignature, invalidateBlock, publisher) {
|
|
669
|
-
// Publishes new block to the network and awaits the tx to be mined
|
|
670
|
-
this.setState(SequencerState.PUBLISHING_BLOCK, block.header.globalVariables.slotNumber);
|
|
671
|
-
// Time out tx at the end of the slot
|
|
672
|
-
const slot = block.header.globalVariables.slotNumber;
|
|
673
|
-
const txTimeoutAt = new Date((this.getSlotStartBuildTimestamp(slot) + this.aztecSlotDuration) * 1000);
|
|
674
|
-
const enqueued = await publisher.enqueueProposeL2Block(block, attestationsAndSigners, attestationsAndSignersSignature, {
|
|
675
|
-
txTimeoutAt,
|
|
676
|
-
forcePendingBlockNumber: invalidateBlock?.forcePendingBlockNumber
|
|
677
|
-
});
|
|
678
|
-
if (!enqueued) {
|
|
679
|
-
throw new Error(`Failed to enqueue publish of block ${block.number}`);
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
742
|
/**
|
|
683
743
|
* Returns whether all dependencies have caught up.
|
|
684
744
|
* We don't check against the previous block submitted since it may have been reorg'd out.
|
|
685
745
|
*/ async checkSync(args) {
|
|
686
|
-
// Check that the archiver
|
|
746
|
+
// Check that the archiver has fully synced the L2 slot before the one we want to propose in.
|
|
687
747
|
// TODO(#14766): Archiver reports L1 timestamp based on L1 blocks seen, which means that a missed L1 block will
|
|
688
748
|
// cause the archiver L1 timestamp to fall behind, and cause this sequencer to start processing one L1 slot later.
|
|
689
|
-
const
|
|
690
|
-
const { slot
|
|
691
|
-
if (
|
|
749
|
+
const syncedL2Slot = await this.l2BlockSource.getSyncedL2SlotNumber();
|
|
750
|
+
const { slot } = args;
|
|
751
|
+
if (syncedL2Slot === undefined || syncedL2Slot + 1 < slot) {
|
|
692
752
|
this.log.debug(`Cannot propose block at next L2 slot ${slot} due to pending sync from L1`, {
|
|
693
753
|
slot,
|
|
694
|
-
|
|
695
|
-
l1Timestamp
|
|
754
|
+
syncedL2Slot
|
|
696
755
|
});
|
|
697
756
|
return undefined;
|
|
698
757
|
}
|
|
@@ -701,14 +760,15 @@ export { SequencerState };
|
|
|
701
760
|
number: syncSummary.latestBlockNumber,
|
|
702
761
|
hash: syncSummary.latestBlockHash
|
|
703
762
|
})),
|
|
704
|
-
this.l2BlockSource.getL2Tips().then((t)=>t.
|
|
763
|
+
this.l2BlockSource.getL2Tips().then((t)=>t.proposed),
|
|
705
764
|
this.p2pClient.getStatus().then((p2p)=>p2p.syncedToL2Block),
|
|
706
|
-
this.l1ToL2MessageSource.getL2Tips().then((t)=>t.
|
|
765
|
+
this.l1ToL2MessageSource.getL2Tips().then((t)=>t.proposed),
|
|
707
766
|
this.l2BlockSource.getPendingChainValidationStatus()
|
|
708
767
|
]);
|
|
709
768
|
const [worldState, l2BlockSource, p2p, l1ToL2MessageSource, pendingChainValidationStatus] = syncedBlocks;
|
|
710
769
|
// Handle zero as a special case, since the block hash won't match across services if we're changing the prefilled data for the genesis block,
|
|
711
770
|
// as the world state can compute the new genesis block hash, but other components use the hardcoded constant.
|
|
771
|
+
// TODO(palla/mbps): Fix the above. All components should be able to handle dynamic genesis block hashes.
|
|
712
772
|
const result = l2BlockSource.number === 0 && worldState.number === 0 && p2p.number === 0 && l1ToL2MessageSource.number === 0 || worldState.hash === l2BlockSource.hash && p2p.hash === l2BlockSource.hash && l1ToL2MessageSource.hash === l2BlockSource.hash;
|
|
713
773
|
if (!result) {
|
|
714
774
|
this.log.debug(`Sequencer sync check failed`, {
|
|
@@ -724,73 +784,29 @@ export { SequencerState };
|
|
|
724
784
|
if (blockNumber < INITIAL_L2_BLOCK_NUM) {
|
|
725
785
|
const archive = new Fr((await this.worldState.getCommitted().getTreeInfo(MerkleTreeId.ARCHIVE)).root);
|
|
726
786
|
return {
|
|
727
|
-
|
|
787
|
+
checkpointNumber: CheckpointNumber.ZERO,
|
|
788
|
+
blockNumber: BlockNumber.ZERO,
|
|
728
789
|
archive,
|
|
729
|
-
|
|
790
|
+
syncedL2Slot,
|
|
730
791
|
pendingChainValidationStatus
|
|
731
792
|
};
|
|
732
793
|
}
|
|
733
|
-
const
|
|
734
|
-
if (!
|
|
794
|
+
const blockData = await this.l2BlockSource.getBlockData(blockNumber);
|
|
795
|
+
if (!blockData) {
|
|
735
796
|
// this shouldn't really happen because a moment ago we checked that all components were in sync
|
|
736
|
-
this.log.error(`Failed to get L2 block ${blockNumber} from the archiver with all components in sync`);
|
|
797
|
+
this.log.error(`Failed to get L2 block data ${blockNumber} from the archiver with all components in sync`);
|
|
737
798
|
return undefined;
|
|
738
799
|
}
|
|
739
800
|
return {
|
|
740
|
-
|
|
741
|
-
blockNumber:
|
|
742
|
-
|
|
743
|
-
|
|
801
|
+
blockData,
|
|
802
|
+
blockNumber: blockData.header.getBlockNumber(),
|
|
803
|
+
checkpointNumber: blockData.checkpointNumber,
|
|
804
|
+
archive: blockData.archive.root,
|
|
805
|
+
syncedL2Slot,
|
|
744
806
|
pendingChainValidationStatus
|
|
745
807
|
};
|
|
746
808
|
}
|
|
747
809
|
/**
|
|
748
|
-
* Enqueues governance and slashing votes with the publisher. Does not block.
|
|
749
|
-
* @param publisher - The publisher to enqueue votes with
|
|
750
|
-
* @param attestorAddress - The attestor address to use for signing
|
|
751
|
-
* @param slot - The slot number
|
|
752
|
-
* @param timestamp - The timestamp for the votes
|
|
753
|
-
* @param context - Optional context for logging (e.g., block number)
|
|
754
|
-
* @returns A tuple of [governanceEnqueued, slashingEnqueued]
|
|
755
|
-
*/ enqueueGovernanceAndSlashingVotes(publisher, attestorAddress, slot, timestamp) {
|
|
756
|
-
try {
|
|
757
|
-
const signerFn = (msg)=>this.validatorClient.signWithAddress(attestorAddress, msg).then((s)=>s.toString());
|
|
758
|
-
const enqueueGovernancePromise = this.governanceProposerPayload && !this.governanceProposerPayload.isZero() ? publisher.enqueueGovernanceCastSignal(this.governanceProposerPayload, slot, timestamp, attestorAddress, signerFn).catch((err)=>{
|
|
759
|
-
this.log.error(`Error enqueuing governance vote`, err, {
|
|
760
|
-
slot
|
|
761
|
-
});
|
|
762
|
-
return false;
|
|
763
|
-
}) : undefined;
|
|
764
|
-
const enqueueSlashingPromise = this.slasherClient ? this.slasherClient.getProposerActions(slot).then((actions)=>{
|
|
765
|
-
// Record metrics for fisherman mode
|
|
766
|
-
if (this.config.fishermanMode && actions.length > 0) {
|
|
767
|
-
this.log.debug(`Fisherman mode: simulating ${actions.length} slashing action(s) for slot ${slot}`, {
|
|
768
|
-
slot,
|
|
769
|
-
actionCount: actions.length
|
|
770
|
-
});
|
|
771
|
-
this.metrics.recordSlashingAttempt(actions.length);
|
|
772
|
-
}
|
|
773
|
-
// Enqueue the actions to fully simulate L1 tx building (they won't be sent in fisherman mode)
|
|
774
|
-
return publisher.enqueueSlashingActions(actions, slot, timestamp, attestorAddress, signerFn);
|
|
775
|
-
}).catch((err)=>{
|
|
776
|
-
this.log.error(`Error enqueuing slashing actions`, err, {
|
|
777
|
-
slot
|
|
778
|
-
});
|
|
779
|
-
return false;
|
|
780
|
-
}) : undefined;
|
|
781
|
-
return [
|
|
782
|
-
enqueueGovernancePromise,
|
|
783
|
-
enqueueSlashingPromise
|
|
784
|
-
];
|
|
785
|
-
} catch (err) {
|
|
786
|
-
this.log.error(`Error enqueueing governance and slashing votes`, err);
|
|
787
|
-
return [
|
|
788
|
-
undefined,
|
|
789
|
-
undefined
|
|
790
|
-
];
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
/**
|
|
794
810
|
* Checks if we are the proposer for the next slot.
|
|
795
811
|
* @returns True if we can propose, and the proposer address (undefined if anyone can propose)
|
|
796
812
|
*/ async checkCanPropose(slot) {
|
|
@@ -799,7 +815,10 @@ export { SequencerState };
|
|
|
799
815
|
proposer = await this.epochCache.getProposerAttesterAddressInSlot(slot);
|
|
800
816
|
} catch (e) {
|
|
801
817
|
if (e instanceof NoCommitteeError) {
|
|
802
|
-
this.
|
|
818
|
+
if (this.lastSlotForNoCommitteeWarning !== slot) {
|
|
819
|
+
this.lastSlotForNoCommitteeWarning = slot;
|
|
820
|
+
this.log.warn(`Cannot propose at next L2 slot ${slot} since the committee does not exist on L1`);
|
|
821
|
+
}
|
|
803
822
|
return [
|
|
804
823
|
false,
|
|
805
824
|
undefined
|
|
@@ -846,49 +865,50 @@ export { SequencerState };
|
|
|
846
865
|
* Tries to vote on slashing actions and governance when the sync check fails but we're past the max time for initializing a proposal.
|
|
847
866
|
* This allows the sequencer to participate in governance/slashing votes even when it cannot build blocks.
|
|
848
867
|
*/ async tryVoteWhenSyncFails(args) {
|
|
849
|
-
const { slot
|
|
868
|
+
const { slot } = args;
|
|
850
869
|
// Prevent duplicate attempts in the same slot
|
|
851
|
-
if (this.
|
|
852
|
-
this.log.
|
|
870
|
+
if (this.lastSlotForFallbackVote === slot) {
|
|
871
|
+
this.log.trace(`Already attempted to vote in slot ${slot} (skipping)`);
|
|
853
872
|
return;
|
|
854
873
|
}
|
|
855
874
|
// Check if we're past the max time for initializing a proposal
|
|
856
875
|
const secondsIntoSlot = this.getSecondsIntoSlot(slot);
|
|
857
|
-
const maxAllowedTime = this.timetable.getMaxAllowedTime(SequencerState.
|
|
876
|
+
const maxAllowedTime = this.timetable.getMaxAllowedTime(SequencerState.INITIALIZING_CHECKPOINT);
|
|
858
877
|
// If we haven't exceeded the time limit for initializing a proposal, don't proceed with voting
|
|
859
878
|
// We use INITIALIZING_PROPOSAL time limit because if we're past that, we can't build a block anyway
|
|
860
879
|
if (maxAllowedTime === undefined || secondsIntoSlot <= maxAllowedTime) {
|
|
861
|
-
this.log.trace(`Not attempting to vote since there is still for block building`, {
|
|
880
|
+
this.log.trace(`Not attempting to vote since there is still time for block building`, {
|
|
862
881
|
secondsIntoSlot,
|
|
863
882
|
maxAllowedTime
|
|
864
883
|
});
|
|
865
884
|
return;
|
|
866
885
|
}
|
|
867
|
-
this.log.
|
|
886
|
+
this.log.trace(`Sync for slot ${slot} failed, checking for voting opportunities`, {
|
|
868
887
|
secondsIntoSlot,
|
|
869
888
|
maxAllowedTime
|
|
870
889
|
});
|
|
871
890
|
// Check if we're a proposer or proposal is open
|
|
872
891
|
const [canPropose, proposer] = await this.checkCanPropose(slot);
|
|
873
892
|
if (!canPropose) {
|
|
874
|
-
this.log.
|
|
893
|
+
this.log.trace(`Cannot vote in slot ${slot} since we are not a proposer`, {
|
|
875
894
|
slot,
|
|
876
895
|
proposer
|
|
877
896
|
});
|
|
878
897
|
return;
|
|
879
898
|
}
|
|
880
899
|
// Mark this slot as attempted
|
|
881
|
-
this.
|
|
900
|
+
this.lastSlotForFallbackVote = slot;
|
|
882
901
|
// Get a publisher for voting
|
|
883
902
|
const { attestorAddress, publisher } = await this.publisherFactory.create(proposer);
|
|
884
903
|
this.log.debug(`Attempting to vote despite sync failure at slot ${slot}`, {
|
|
885
904
|
attestorAddress,
|
|
886
905
|
slot
|
|
887
906
|
});
|
|
888
|
-
// Enqueue governance and slashing votes
|
|
889
|
-
const
|
|
890
|
-
|
|
891
|
-
|
|
907
|
+
// Enqueue governance and slashing votes
|
|
908
|
+
const voter = new CheckpointVoter(slot, publisher, attestorAddress, this.validatorClient, this.slasherClient, this.l1Constants, this.config, this.metrics, this.log);
|
|
909
|
+
const votesPromises = voter.enqueueVotes();
|
|
910
|
+
const votes = await Promise.all(votesPromises);
|
|
911
|
+
if (votes.every((p)=>!p)) {
|
|
892
912
|
this.log.debug(`No votes to enqueue for slot ${slot}`);
|
|
893
913
|
return;
|
|
894
914
|
}
|
|
@@ -898,24 +918,53 @@ export { SequencerState };
|
|
|
898
918
|
await publisher.sendRequests();
|
|
899
919
|
}
|
|
900
920
|
/**
|
|
921
|
+
* Tries to vote on slashing actions and governance proposals when escape hatch is open.
|
|
922
|
+
* This allows the sequencer to participate in voting without performing checkpoint proposal work.
|
|
923
|
+
*/ async tryVoteWhenEscapeHatchOpen(args) {
|
|
924
|
+
const { slot, proposer } = args;
|
|
925
|
+
// Prevent duplicate attempts in the same slot
|
|
926
|
+
if (this.lastSlotForFallbackVote === slot) {
|
|
927
|
+
this.log.trace(`Already attempted to vote in slot ${slot} (escape hatch open, skipping)`);
|
|
928
|
+
return;
|
|
929
|
+
}
|
|
930
|
+
// Mark this slot as attempted
|
|
931
|
+
this.lastSlotForFallbackVote = slot;
|
|
932
|
+
const { attestorAddress, publisher } = await this.publisherFactory.create(proposer);
|
|
933
|
+
this.log.debug(`Escape hatch open for slot ${slot}, attempting vote-only actions`, {
|
|
934
|
+
slot,
|
|
935
|
+
attestorAddress
|
|
936
|
+
});
|
|
937
|
+
const voter = new CheckpointVoter(slot, publisher, attestorAddress, this.validatorClient, this.slasherClient, this.l1Constants, this.config, this.metrics, this.log);
|
|
938
|
+
const votesPromises = voter.enqueueVotes();
|
|
939
|
+
const votes = await Promise.all(votesPromises);
|
|
940
|
+
if (votes.every((p)=>!p)) {
|
|
941
|
+
this.log.debug(`No votes to enqueue for slot ${slot} (escape hatch open)`);
|
|
942
|
+
return;
|
|
943
|
+
}
|
|
944
|
+
this.log.info(`Voting in slot ${slot} (escape hatch open)`, {
|
|
945
|
+
slot
|
|
946
|
+
});
|
|
947
|
+
await publisher.sendRequests();
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
901
950
|
* Considers invalidating a block if the pending chain is invalid. Depends on how long the invalid block
|
|
902
951
|
* has been there without being invalidated and whether the sequencer is in the committee or not. We always
|
|
903
952
|
* have the proposer try to invalidate, but if they fail, the sequencers in the committee are expected to try,
|
|
904
953
|
* and if they fail, any sequencer will try as well.
|
|
905
|
-
*/ async
|
|
906
|
-
const { pendingChainValidationStatus,
|
|
954
|
+
*/ async considerInvalidatingCheckpoint(syncedTo, currentSlot) {
|
|
955
|
+
const { pendingChainValidationStatus, syncedL2Slot } = syncedTo;
|
|
907
956
|
if (pendingChainValidationStatus.valid) {
|
|
908
957
|
return;
|
|
909
958
|
}
|
|
910
|
-
const
|
|
911
|
-
const
|
|
912
|
-
const timeSinceChainInvalid = this.dateProvider.nowInSeconds() - Number(
|
|
959
|
+
const invalidCheckpointNumber = pendingChainValidationStatus.checkpoint.checkpointNumber;
|
|
960
|
+
const invalidCheckpointTimestamp = pendingChainValidationStatus.checkpoint.timestamp;
|
|
961
|
+
const timeSinceChainInvalid = this.dateProvider.nowInSeconds() - Number(invalidCheckpointTimestamp);
|
|
913
962
|
const ourValidatorAddresses = this.validatorClient.getValidatorAddresses();
|
|
914
963
|
const { secondsBeforeInvalidatingBlockAsCommitteeMember, secondsBeforeInvalidatingBlockAsNonCommitteeMember } = this.config;
|
|
915
964
|
const logData = {
|
|
916
|
-
invalidL1Timestamp:
|
|
917
|
-
|
|
918
|
-
|
|
965
|
+
invalidL1Timestamp: invalidCheckpointTimestamp,
|
|
966
|
+
syncedL2Slot,
|
|
967
|
+
invalidCheckpoint: pendingChainValidationStatus.checkpoint,
|
|
919
968
|
secondsBeforeInvalidatingBlockAsCommitteeMember,
|
|
920
969
|
secondsBeforeInvalidatingBlockAsNonCommitteeMember,
|
|
921
970
|
ourValidatorAddresses,
|
|
@@ -943,20 +992,46 @@ export { SequencerState };
|
|
|
943
992
|
validatorToUse = ourValidatorAddresses[0];
|
|
944
993
|
}
|
|
945
994
|
const { publisher } = await this.publisherFactory.create(validatorToUse);
|
|
946
|
-
const
|
|
947
|
-
if (!
|
|
948
|
-
this.log.warn(`Failed to simulate invalidate
|
|
995
|
+
const invalidateCheckpoint = await publisher.simulateInvalidateCheckpoint(pendingChainValidationStatus);
|
|
996
|
+
if (!invalidateCheckpoint) {
|
|
997
|
+
this.log.warn(`Failed to simulate invalidate checkpoint`, logData);
|
|
949
998
|
return;
|
|
950
999
|
}
|
|
951
|
-
this.log.info(invalidateAsCommitteeMember ? `Invalidating
|
|
952
|
-
publisher.
|
|
1000
|
+
this.log.info(invalidateAsCommitteeMember ? `Invalidating checkpoint ${invalidCheckpointNumber} as committee member` : `Invalidating checkpoint ${invalidCheckpointNumber} as non-committee member`, logData);
|
|
1001
|
+
publisher.enqueueInvalidateCheckpoint(invalidateCheckpoint);
|
|
953
1002
|
if (!this.config.fishermanMode) {
|
|
954
1003
|
await publisher.sendRequests();
|
|
955
1004
|
} else {
|
|
956
|
-
this.log.info('Invalidating
|
|
1005
|
+
this.log.info('Invalidating checkpoint in fisherman mode, clearing pending requests');
|
|
957
1006
|
publisher.clearPendingRequests();
|
|
958
1007
|
}
|
|
959
1008
|
}
|
|
1009
|
+
logStrategyComparison(epoch, publisher) {
|
|
1010
|
+
const feeAnalyzer = publisher.getL1FeeAnalyzer();
|
|
1011
|
+
if (!feeAnalyzer) {
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
const comparison = feeAnalyzer.getStrategyComparison();
|
|
1015
|
+
if (comparison.length === 0) {
|
|
1016
|
+
this.log.debug(`No strategy data available yet for epoch ${epoch}`);
|
|
1017
|
+
return;
|
|
1018
|
+
}
|
|
1019
|
+
this.log.info(`L1 Fee Strategy Performance Report - End of Epoch ${epoch}`, {
|
|
1020
|
+
epoch: Number(epoch),
|
|
1021
|
+
totalAnalyses: comparison[0]?.totalAnalyses,
|
|
1022
|
+
strategies: comparison.map((s)=>({
|
|
1023
|
+
id: s.strategyId,
|
|
1024
|
+
name: s.strategyName,
|
|
1025
|
+
inclusionRate: `${(s.inclusionRate * 100).toFixed(1)}%`,
|
|
1026
|
+
inclusionCount: `${s.inclusionCount}/${s.totalAnalyses}`,
|
|
1027
|
+
avgCostEth: s.avgEstimatedCostEth.toFixed(6),
|
|
1028
|
+
totalCostEth: s.totalEstimatedCostEth.toFixed(6),
|
|
1029
|
+
avgOverpaymentEth: s.avgOverpaymentEth.toFixed(6),
|
|
1030
|
+
totalOverpaymentEth: s.totalOverpaymentEth.toFixed(6),
|
|
1031
|
+
avgPriorityFeeDeltaGwei: s.avgPriorityFeeDeltaGwei.toFixed(2)
|
|
1032
|
+
}))
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
960
1035
|
getSlotStartBuildTimestamp(slotNumber) {
|
|
961
1036
|
return getSlotStartBuildTimestamp(slotNumber, this.l1Constants);
|
|
962
1037
|
}
|
|
@@ -973,24 +1048,19 @@ export { SequencerState };
|
|
|
973
1048
|
getSlasherClient() {
|
|
974
1049
|
return this.slasherClient;
|
|
975
1050
|
}
|
|
1051
|
+
get tracer() {
|
|
1052
|
+
return this.metrics.tracer;
|
|
1053
|
+
}
|
|
1054
|
+
getValidatorAddresses() {
|
|
1055
|
+
return this.validatorClient?.getValidatorAddresses();
|
|
1056
|
+
}
|
|
1057
|
+
/** Updates the publisher factory's node keystore adapter after a keystore reload. */ updatePublisherNodeKeyStore(adapter) {
|
|
1058
|
+
this.publisherFactory.updateNodeKeyStore(adapter);
|
|
1059
|
+
}
|
|
1060
|
+
getConfig() {
|
|
1061
|
+
return this.config;
|
|
1062
|
+
}
|
|
1063
|
+
get l1PublishingTime() {
|
|
1064
|
+
return this.config.l1PublishingTime ?? this.l1Constants.ethereumSlotDuration;
|
|
1065
|
+
}
|
|
976
1066
|
}
|
|
977
|
-
_ts_decorate([
|
|
978
|
-
trackSpan('Sequencer.work')
|
|
979
|
-
], Sequencer.prototype, "safeWork", null);
|
|
980
|
-
_ts_decorate([
|
|
981
|
-
trackSpan('Sequencer.buildBlockAndEnqueuePublish', (_validTxs, _proposalHeader, newGlobalVariables)=>({
|
|
982
|
-
[Attributes.BLOCK_NUMBER]: newGlobalVariables.blockNumber
|
|
983
|
-
}))
|
|
984
|
-
], Sequencer.prototype, "buildBlockAndEnqueuePublish", null);
|
|
985
|
-
_ts_decorate([
|
|
986
|
-
trackSpan('Sequencer.collectAttestations', (block, txHashes)=>({
|
|
987
|
-
[Attributes.BLOCK_NUMBER]: block.number,
|
|
988
|
-
[Attributes.BLOCK_ARCHIVE]: block.archive.toString(),
|
|
989
|
-
[Attributes.BLOCK_TXS_COUNT]: txHashes.length
|
|
990
|
-
}))
|
|
991
|
-
], Sequencer.prototype, "collectAttestations", null);
|
|
992
|
-
_ts_decorate([
|
|
993
|
-
trackSpan('Sequencer.enqueuePublishL2Block', (block)=>({
|
|
994
|
-
[Attributes.BLOCK_NUMBER]: block.number
|
|
995
|
-
}))
|
|
996
|
-
], Sequencer.prototype, "enqueuePublishL2Block", null);
|