@aztec/sequencer-client 0.0.1-commit.03f7ef2 → 0.0.1-commit.04d373f
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 +282 -21
- package/dest/client/sequencer-client.d.ts +20 -11
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +67 -33
- package/dest/config.d.ts +29 -7
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +82 -37
- package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
- package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_predictor.js +128 -0
- package/dest/global_variable_builder/fee_provider.d.ts +21 -0
- package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_provider.js +58 -0
- package/dest/global_variable_builder/global_builder.d.ts +14 -16
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +16 -50
- package/dest/global_variable_builder/index.d.ts +4 -2
- package/dest/global_variable_builder/index.d.ts.map +1 -1
- package/dest/global_variable_builder/index.js +2 -0
- 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 +47 -17
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +121 -42
- package/dest/publisher/index.d.ts +2 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
- package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +58 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/index.js +2 -0
- package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
- package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
- package/dest/publisher/sequencer-bundle-simulator.js +198 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +12 -6
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +27 -3
- package/dest/publisher/sequencer-publisher-metrics.d.ts +1 -1
- 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 +108 -81
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +876 -403
- package/dest/sequencer/automine/automine_factory.d.ts +54 -0
- package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_factory.js +84 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts +151 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_sequencer.js +506 -0
- package/dest/sequencer/chain_state_overrides.d.ts +61 -0
- package/dest/sequencer/chain_state_overrides.d.ts.map +1 -0
- package/dest/sequencer/chain_state_overrides.js +98 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +87 -16
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +1331 -203
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
- package/dest/sequencer/checkpoint_voter.d.ts +3 -3
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_voter.js +34 -13
- package/dest/sequencer/events.d.ts +47 -2
- package/dest/sequencer/events.d.ts.map +1 -1
- package/dest/sequencer/index.d.ts +3 -3
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +2 -2
- package/dest/sequencer/metrics.d.ts +23 -8
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +158 -143
- package/dest/sequencer/sequencer.d.ts +92 -29
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +818 -157
- package/dest/sequencer/timetable.d.ts +17 -6
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +51 -46
- package/dest/sequencer/types.d.ts +2 -2
- package/dest/sequencer/types.d.ts.map +1 -1
- package/dest/test/index.d.ts +4 -7
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +29 -17
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +86 -34
- package/dest/test/utils.d.ts +13 -9
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +31 -20
- package/package.json +29 -28
- package/src/client/sequencer-client.ts +94 -38
- package/src/config.ts +107 -46
- package/src/global_variable_builder/README.md +44 -0
- package/src/global_variable_builder/fee_predictor.ts +172 -0
- package/src/global_variable_builder/fee_provider.ts +75 -0
- package/src/global_variable_builder/global_builder.ts +26 -63
- package/src/global_variable_builder/index.ts +3 -1
- package/src/index.ts +5 -4
- package/src/publisher/config.ts +157 -45
- package/src/publisher/index.ts +3 -0
- package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +57 -0
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
- package/src/publisher/l1_tx_failed_store/index.ts +3 -0
- package/src/publisher/sequencer-bundle-simulator.ts +254 -0
- package/src/publisher/sequencer-publisher-factory.ts +39 -10
- package/src/publisher/sequencer-publisher-metrics.ts +17 -69
- package/src/publisher/sequencer-publisher.ts +611 -521
- package/src/sequencer/README.md +152 -450
- package/src/sequencer/automine/README.md +46 -0
- package/src/sequencer/automine/automine_factory.ts +145 -0
- package/src/sequencer/automine/automine_sequencer.ts +592 -0
- package/src/sequencer/chain_state_overrides.ts +162 -0
- package/src/sequencer/checkpoint_proposal_job.ts +1138 -230
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/checkpoint_voter.ts +31 -17
- package/src/sequencer/events.ts +50 -2
- package/src/sequencer/index.ts +2 -2
- package/src/sequencer/metrics.ts +168 -151
- package/src/sequencer/sequencer.ts +535 -162
- package/src/sequencer/timetable.ts +70 -57
- package/src/sequencer/types.ts +1 -1
- package/src/test/index.ts +3 -6
- package/src/test/mock_checkpoint_builder.ts +149 -73
- package/src/test/utils.ts +78 -30
- package/dest/sequencer/block_builder.d.ts +0 -26
- package/dest/sequencer/block_builder.d.ts.map +0 -1
- package/dest/sequencer/block_builder.js +0 -129
- package/dest/sequencer/checkpoint_builder.d.ts +0 -63
- package/dest/sequencer/checkpoint_builder.d.ts.map +0 -1
- package/dest/sequencer/checkpoint_builder.js +0 -131
- 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 -217
- package/src/sequencer/checkpoint_builder.ts +0 -217
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -133
|
@@ -63,112 +63,828 @@ function _ts_dispose_resources(env) {
|
|
|
63
63
|
return next();
|
|
64
64
|
})(env);
|
|
65
65
|
}
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
function applyDecs2203RFactory() {
|
|
67
|
+
function createAddInitializerMethod(initializers, decoratorFinishedRef) {
|
|
68
|
+
return function addInitializer(initializer) {
|
|
69
|
+
assertNotFinished(decoratorFinishedRef, "addInitializer");
|
|
70
|
+
assertCallable(initializer, "An initializer");
|
|
71
|
+
initializers.push(initializer);
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
|
|
75
|
+
var kindStr;
|
|
76
|
+
switch(kind){
|
|
77
|
+
case 1:
|
|
78
|
+
kindStr = "accessor";
|
|
79
|
+
break;
|
|
80
|
+
case 2:
|
|
81
|
+
kindStr = "method";
|
|
82
|
+
break;
|
|
83
|
+
case 3:
|
|
84
|
+
kindStr = "getter";
|
|
85
|
+
break;
|
|
86
|
+
case 4:
|
|
87
|
+
kindStr = "setter";
|
|
88
|
+
break;
|
|
89
|
+
default:
|
|
90
|
+
kindStr = "field";
|
|
91
|
+
}
|
|
92
|
+
var ctx = {
|
|
93
|
+
kind: kindStr,
|
|
94
|
+
name: isPrivate ? "#" + name : name,
|
|
95
|
+
static: isStatic,
|
|
96
|
+
private: isPrivate,
|
|
97
|
+
metadata: metadata
|
|
98
|
+
};
|
|
99
|
+
var decoratorFinishedRef = {
|
|
100
|
+
v: false
|
|
101
|
+
};
|
|
102
|
+
ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
|
|
103
|
+
var get, set;
|
|
104
|
+
if (kind === 0) {
|
|
105
|
+
if (isPrivate) {
|
|
106
|
+
get = desc.get;
|
|
107
|
+
set = desc.set;
|
|
108
|
+
} else {
|
|
109
|
+
get = function() {
|
|
110
|
+
return this[name];
|
|
111
|
+
};
|
|
112
|
+
set = function(v) {
|
|
113
|
+
this[name] = v;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
} else if (kind === 2) {
|
|
117
|
+
get = function() {
|
|
118
|
+
return desc.value;
|
|
119
|
+
};
|
|
120
|
+
} else {
|
|
121
|
+
if (kind === 1 || kind === 3) {
|
|
122
|
+
get = function() {
|
|
123
|
+
return desc.get.call(this);
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
if (kind === 1 || kind === 4) {
|
|
127
|
+
set = function(v) {
|
|
128
|
+
desc.set.call(this, v);
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
ctx.access = get && set ? {
|
|
133
|
+
get: get,
|
|
134
|
+
set: set
|
|
135
|
+
} : get ? {
|
|
136
|
+
get: get
|
|
137
|
+
} : {
|
|
138
|
+
set: set
|
|
139
|
+
};
|
|
140
|
+
try {
|
|
141
|
+
return dec(value, ctx);
|
|
142
|
+
} finally{
|
|
143
|
+
decoratorFinishedRef.v = true;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function assertNotFinished(decoratorFinishedRef, fnName) {
|
|
147
|
+
if (decoratorFinishedRef.v) {
|
|
148
|
+
throw new Error("attempted to call " + fnName + " after decoration was finished");
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function assertCallable(fn, hint) {
|
|
152
|
+
if (typeof fn !== "function") {
|
|
153
|
+
throw new TypeError(hint + " must be a function");
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function assertValidReturnValue(kind, value) {
|
|
157
|
+
var type = typeof value;
|
|
158
|
+
if (kind === 1) {
|
|
159
|
+
if (type !== "object" || value === null) {
|
|
160
|
+
throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
161
|
+
}
|
|
162
|
+
if (value.get !== undefined) {
|
|
163
|
+
assertCallable(value.get, "accessor.get");
|
|
164
|
+
}
|
|
165
|
+
if (value.set !== undefined) {
|
|
166
|
+
assertCallable(value.set, "accessor.set");
|
|
167
|
+
}
|
|
168
|
+
if (value.init !== undefined) {
|
|
169
|
+
assertCallable(value.init, "accessor.init");
|
|
170
|
+
}
|
|
171
|
+
} else if (type !== "function") {
|
|
172
|
+
var hint;
|
|
173
|
+
if (kind === 0) {
|
|
174
|
+
hint = "field";
|
|
175
|
+
} else if (kind === 10) {
|
|
176
|
+
hint = "class";
|
|
177
|
+
} else {
|
|
178
|
+
hint = "method";
|
|
179
|
+
}
|
|
180
|
+
throw new TypeError(hint + " decorators must return a function or void 0");
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
|
|
184
|
+
var decs = decInfo[0];
|
|
185
|
+
var desc, init, value;
|
|
186
|
+
if (isPrivate) {
|
|
187
|
+
if (kind === 0 || kind === 1) {
|
|
188
|
+
desc = {
|
|
189
|
+
get: decInfo[3],
|
|
190
|
+
set: decInfo[4]
|
|
191
|
+
};
|
|
192
|
+
} else if (kind === 3) {
|
|
193
|
+
desc = {
|
|
194
|
+
get: decInfo[3]
|
|
195
|
+
};
|
|
196
|
+
} else if (kind === 4) {
|
|
197
|
+
desc = {
|
|
198
|
+
set: decInfo[3]
|
|
199
|
+
};
|
|
200
|
+
} else {
|
|
201
|
+
desc = {
|
|
202
|
+
value: decInfo[3]
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
} else if (kind !== 0) {
|
|
206
|
+
desc = Object.getOwnPropertyDescriptor(base, name);
|
|
207
|
+
}
|
|
208
|
+
if (kind === 1) {
|
|
209
|
+
value = {
|
|
210
|
+
get: desc.get,
|
|
211
|
+
set: desc.set
|
|
212
|
+
};
|
|
213
|
+
} else if (kind === 2) {
|
|
214
|
+
value = desc.value;
|
|
215
|
+
} else if (kind === 3) {
|
|
216
|
+
value = desc.get;
|
|
217
|
+
} else if (kind === 4) {
|
|
218
|
+
value = desc.set;
|
|
219
|
+
}
|
|
220
|
+
var newValue, get, set;
|
|
221
|
+
if (typeof decs === "function") {
|
|
222
|
+
newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
223
|
+
if (newValue !== void 0) {
|
|
224
|
+
assertValidReturnValue(kind, newValue);
|
|
225
|
+
if (kind === 0) {
|
|
226
|
+
init = newValue;
|
|
227
|
+
} else if (kind === 1) {
|
|
228
|
+
init = newValue.init;
|
|
229
|
+
get = newValue.get || value.get;
|
|
230
|
+
set = newValue.set || value.set;
|
|
231
|
+
value = {
|
|
232
|
+
get: get,
|
|
233
|
+
set: set
|
|
234
|
+
};
|
|
235
|
+
} else {
|
|
236
|
+
value = newValue;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
} else {
|
|
240
|
+
for(var i = decs.length - 1; i >= 0; i--){
|
|
241
|
+
var dec = decs[i];
|
|
242
|
+
newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
243
|
+
if (newValue !== void 0) {
|
|
244
|
+
assertValidReturnValue(kind, newValue);
|
|
245
|
+
var newInit;
|
|
246
|
+
if (kind === 0) {
|
|
247
|
+
newInit = newValue;
|
|
248
|
+
} else if (kind === 1) {
|
|
249
|
+
newInit = newValue.init;
|
|
250
|
+
get = newValue.get || value.get;
|
|
251
|
+
set = newValue.set || value.set;
|
|
252
|
+
value = {
|
|
253
|
+
get: get,
|
|
254
|
+
set: set
|
|
255
|
+
};
|
|
256
|
+
} else {
|
|
257
|
+
value = newValue;
|
|
258
|
+
}
|
|
259
|
+
if (newInit !== void 0) {
|
|
260
|
+
if (init === void 0) {
|
|
261
|
+
init = newInit;
|
|
262
|
+
} else if (typeof init === "function") {
|
|
263
|
+
init = [
|
|
264
|
+
init,
|
|
265
|
+
newInit
|
|
266
|
+
];
|
|
267
|
+
} else {
|
|
268
|
+
init.push(newInit);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (kind === 0 || kind === 1) {
|
|
275
|
+
if (init === void 0) {
|
|
276
|
+
init = function(instance, init) {
|
|
277
|
+
return init;
|
|
278
|
+
};
|
|
279
|
+
} else if (typeof init !== "function") {
|
|
280
|
+
var ownInitializers = init;
|
|
281
|
+
init = function(instance, init) {
|
|
282
|
+
var value = init;
|
|
283
|
+
for(var i = 0; i < ownInitializers.length; i++){
|
|
284
|
+
value = ownInitializers[i].call(instance, value);
|
|
285
|
+
}
|
|
286
|
+
return value;
|
|
287
|
+
};
|
|
288
|
+
} else {
|
|
289
|
+
var originalInitializer = init;
|
|
290
|
+
init = function(instance, init) {
|
|
291
|
+
return originalInitializer.call(instance, init);
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
ret.push(init);
|
|
295
|
+
}
|
|
296
|
+
if (kind !== 0) {
|
|
297
|
+
if (kind === 1) {
|
|
298
|
+
desc.get = value.get;
|
|
299
|
+
desc.set = value.set;
|
|
300
|
+
} else if (kind === 2) {
|
|
301
|
+
desc.value = value;
|
|
302
|
+
} else if (kind === 3) {
|
|
303
|
+
desc.get = value;
|
|
304
|
+
} else if (kind === 4) {
|
|
305
|
+
desc.set = value;
|
|
306
|
+
}
|
|
307
|
+
if (isPrivate) {
|
|
308
|
+
if (kind === 1) {
|
|
309
|
+
ret.push(function(instance, args) {
|
|
310
|
+
return value.get.call(instance, args);
|
|
311
|
+
});
|
|
312
|
+
ret.push(function(instance, args) {
|
|
313
|
+
return value.set.call(instance, args);
|
|
314
|
+
});
|
|
315
|
+
} else if (kind === 2) {
|
|
316
|
+
ret.push(value);
|
|
317
|
+
} else {
|
|
318
|
+
ret.push(function(instance, args) {
|
|
319
|
+
return value.call(instance, args);
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
} else {
|
|
323
|
+
Object.defineProperty(base, name, desc);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
function applyMemberDecs(Class, decInfos, metadata) {
|
|
328
|
+
var ret = [];
|
|
329
|
+
var protoInitializers;
|
|
330
|
+
var staticInitializers;
|
|
331
|
+
var existingProtoNonFields = new Map();
|
|
332
|
+
var existingStaticNonFields = new Map();
|
|
333
|
+
for(var i = 0; i < decInfos.length; i++){
|
|
334
|
+
var decInfo = decInfos[i];
|
|
335
|
+
if (!Array.isArray(decInfo)) continue;
|
|
336
|
+
var kind = decInfo[1];
|
|
337
|
+
var name = decInfo[2];
|
|
338
|
+
var isPrivate = decInfo.length > 3;
|
|
339
|
+
var isStatic = kind >= 5;
|
|
340
|
+
var base;
|
|
341
|
+
var initializers;
|
|
342
|
+
if (isStatic) {
|
|
343
|
+
base = Class;
|
|
344
|
+
kind = kind - 5;
|
|
345
|
+
staticInitializers = staticInitializers || [];
|
|
346
|
+
initializers = staticInitializers;
|
|
347
|
+
} else {
|
|
348
|
+
base = Class.prototype;
|
|
349
|
+
protoInitializers = protoInitializers || [];
|
|
350
|
+
initializers = protoInitializers;
|
|
351
|
+
}
|
|
352
|
+
if (kind !== 0 && !isPrivate) {
|
|
353
|
+
var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
|
|
354
|
+
var existingKind = existingNonFields.get(name) || 0;
|
|
355
|
+
if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) {
|
|
356
|
+
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);
|
|
357
|
+
} else if (!existingKind && kind > 2) {
|
|
358
|
+
existingNonFields.set(name, kind);
|
|
359
|
+
} else {
|
|
360
|
+
existingNonFields.set(name, true);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
|
|
364
|
+
}
|
|
365
|
+
pushInitializers(ret, protoInitializers);
|
|
366
|
+
pushInitializers(ret, staticInitializers);
|
|
367
|
+
return ret;
|
|
368
|
+
}
|
|
369
|
+
function pushInitializers(ret, initializers) {
|
|
370
|
+
if (initializers) {
|
|
371
|
+
ret.push(function(instance) {
|
|
372
|
+
for(var i = 0; i < initializers.length; i++){
|
|
373
|
+
initializers[i].call(instance);
|
|
374
|
+
}
|
|
375
|
+
return instance;
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
function applyClassDecs(targetClass, classDecs, metadata) {
|
|
380
|
+
if (classDecs.length > 0) {
|
|
381
|
+
var initializers = [];
|
|
382
|
+
var newClass = targetClass;
|
|
383
|
+
var name = targetClass.name;
|
|
384
|
+
for(var i = classDecs.length - 1; i >= 0; i--){
|
|
385
|
+
var decoratorFinishedRef = {
|
|
386
|
+
v: false
|
|
387
|
+
};
|
|
388
|
+
try {
|
|
389
|
+
var nextNewClass = classDecs[i](newClass, {
|
|
390
|
+
kind: "class",
|
|
391
|
+
name: name,
|
|
392
|
+
addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
|
|
393
|
+
metadata
|
|
394
|
+
});
|
|
395
|
+
} finally{
|
|
396
|
+
decoratorFinishedRef.v = true;
|
|
397
|
+
}
|
|
398
|
+
if (nextNewClass !== undefined) {
|
|
399
|
+
assertValidReturnValue(10, nextNewClass);
|
|
400
|
+
newClass = nextNewClass;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return [
|
|
404
|
+
defineMetadata(newClass, metadata),
|
|
405
|
+
function() {
|
|
406
|
+
for(var i = 0; i < initializers.length; i++){
|
|
407
|
+
initializers[i].call(newClass);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
];
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function defineMetadata(Class, metadata) {
|
|
414
|
+
return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
|
|
415
|
+
configurable: true,
|
|
416
|
+
enumerable: true,
|
|
417
|
+
value: metadata
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
|
|
421
|
+
if (parentClass !== void 0) {
|
|
422
|
+
var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
423
|
+
}
|
|
424
|
+
var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
|
|
425
|
+
var e = applyMemberDecs(targetClass, memberDecs, metadata);
|
|
426
|
+
if (!classDecs.length) defineMetadata(targetClass, metadata);
|
|
427
|
+
return {
|
|
428
|
+
e: e,
|
|
429
|
+
get c () {
|
|
430
|
+
return applyClassDecs(targetClass, classDecs, metadata);
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
436
|
+
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
437
|
+
}
|
|
438
|
+
var _dec, _dec1, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _initProto;
|
|
439
|
+
import { BlockNumber, CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
|
|
68
440
|
import { randomInt } from '@aztec/foundation/crypto/random';
|
|
69
|
-
import {
|
|
441
|
+
import { flipSignature, generateRecoverableSignature, generateUnrecoverableSignature } from '@aztec/foundation/crypto/secp256k1-signer';
|
|
70
442
|
import { filter } from '@aztec/foundation/iterator';
|
|
443
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
444
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
71
445
|
import { sleep, sleepUntil } from '@aztec/foundation/sleep';
|
|
72
446
|
import { Timer } from '@aztec/foundation/timer';
|
|
73
|
-
import { unfreeze } from '@aztec/foundation/types';
|
|
447
|
+
import { isErrorClass, unfreeze } from '@aztec/foundation/types';
|
|
74
448
|
import { CommitteeAttestationsAndSigners, MaliciousCommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
|
|
75
|
-
import {
|
|
449
|
+
import { getPreviousCheckpointOutHashes, validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
450
|
+
import { computeQuorum, getSlotStartBuildTimestamp, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
76
451
|
import { Gas } from '@aztec/stdlib/gas';
|
|
77
|
-
import {
|
|
452
|
+
import { InsufficientValidTxsError } from '@aztec/stdlib/interfaces/server';
|
|
453
|
+
import { computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
454
|
+
import { orderAttestations, trimAttestations } from '@aztec/stdlib/p2p';
|
|
78
455
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
456
|
+
import { Attributes, trackSpan } from '@aztec/telemetry-client';
|
|
457
|
+
import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validator-ha-signer/errors';
|
|
458
|
+
import { buildCheckpointSimulationOverridesPlan } from './chain_state_overrides.js';
|
|
79
459
|
import { CheckpointVoter } from './checkpoint_voter.js';
|
|
80
460
|
import { SequencerInterruptedError } from './errors.js';
|
|
81
461
|
import { SequencerState } from './utils.js';
|
|
82
462
|
/** How much time to sleep while waiting for min transactions to accumulate for a block */ const TXS_POLLING_MS = 500;
|
|
463
|
+
_dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('CheckpointProposalJob.proposeCheckpoint', function() {
|
|
464
|
+
return {
|
|
465
|
+
// nullish operator needed for tests
|
|
466
|
+
[Attributes.COINBASE]: this.validatorClient.getCoinbaseForAttestor(this.attestorAddress)?.toString(),
|
|
467
|
+
[Attributes.SLOT_NUMBER]: this.targetSlot
|
|
468
|
+
};
|
|
469
|
+
}), _dec2 = trackSpan('CheckpointProposalJob.buildBlocksForCheckpoint'), _dec3 = trackSpan('CheckpointProposalJob.waitUntilNextSubslot'), _dec4 = trackSpan('CheckpointProposalJob.buildSingleBlock'), _dec5 = trackSpan('CheckpointProposalJob.waitForMinTxs'), _dec6 = trackSpan('CheckpointProposalJob.waitForAttestations'), _dec7 = trackSpan('CheckpointProposalJob.waitUntilTimeInSlot');
|
|
83
470
|
/**
|
|
84
471
|
* Handles the execution of a checkpoint proposal after the initial preparation phase.
|
|
85
472
|
* This includes building blocks, collecting attestations, and publishing the checkpoint to L1,
|
|
86
473
|
* as well as enqueueing votes for slashing and governance proposals. This class is created from
|
|
87
474
|
* the Sequencer once the check for being the proposer for the slot has succeeded.
|
|
88
475
|
*/ export class CheckpointProposalJob {
|
|
89
|
-
|
|
476
|
+
slotNow;
|
|
477
|
+
targetSlot;
|
|
478
|
+
targetEpoch;
|
|
90
479
|
checkpointNumber;
|
|
91
480
|
syncedToBlockNumber;
|
|
481
|
+
checkpointedCheckpointNumber;
|
|
92
482
|
proposer;
|
|
93
483
|
publisher;
|
|
94
484
|
attestorAddress;
|
|
95
|
-
|
|
485
|
+
invalidateCheckpoint;
|
|
96
486
|
validatorClient;
|
|
97
487
|
globalsBuilder;
|
|
98
488
|
p2pClient;
|
|
99
489
|
worldState;
|
|
100
490
|
l1ToL2MessageSource;
|
|
491
|
+
l2BlockSource;
|
|
101
492
|
checkpointsBuilder;
|
|
493
|
+
blockSink;
|
|
102
494
|
l1Constants;
|
|
495
|
+
signatureContext;
|
|
103
496
|
config;
|
|
104
497
|
timetable;
|
|
105
498
|
slasherClient;
|
|
106
499
|
epochCache;
|
|
107
500
|
dateProvider;
|
|
108
501
|
metrics;
|
|
502
|
+
checkpointMetrics;
|
|
109
503
|
eventEmitter;
|
|
110
504
|
setStateFn;
|
|
505
|
+
tracer;
|
|
506
|
+
proposedCheckpointData;
|
|
507
|
+
static{
|
|
508
|
+
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
509
|
+
[
|
|
510
|
+
_dec,
|
|
511
|
+
2,
|
|
512
|
+
"execute"
|
|
513
|
+
],
|
|
514
|
+
[
|
|
515
|
+
_dec1,
|
|
516
|
+
2,
|
|
517
|
+
"proposeCheckpoint"
|
|
518
|
+
],
|
|
519
|
+
[
|
|
520
|
+
_dec2,
|
|
521
|
+
2,
|
|
522
|
+
"buildBlocksForCheckpoint"
|
|
523
|
+
],
|
|
524
|
+
[
|
|
525
|
+
_dec3,
|
|
526
|
+
2,
|
|
527
|
+
"waitUntilNextSubslot"
|
|
528
|
+
],
|
|
529
|
+
[
|
|
530
|
+
_dec4,
|
|
531
|
+
2,
|
|
532
|
+
"buildSingleBlock"
|
|
533
|
+
],
|
|
534
|
+
[
|
|
535
|
+
_dec5,
|
|
536
|
+
2,
|
|
537
|
+
"waitForMinTxs"
|
|
538
|
+
],
|
|
539
|
+
[
|
|
540
|
+
_dec6,
|
|
541
|
+
2,
|
|
542
|
+
"waitForAttestations"
|
|
543
|
+
],
|
|
544
|
+
[
|
|
545
|
+
_dec7,
|
|
546
|
+
2,
|
|
547
|
+
"waitUntilTimeInSlot"
|
|
548
|
+
]
|
|
549
|
+
], []));
|
|
550
|
+
}
|
|
111
551
|
log;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
552
|
+
checkpointEventLog;
|
|
553
|
+
/** Tracks the fire-and-forget L1 submission promise so it can be awaited during shutdown. */ pendingL1Submission;
|
|
554
|
+
/**
|
|
555
|
+
* Chain state overrides built once per slot in proposeCheckpoint after the checkpoint is
|
|
556
|
+
* complete. Carries the pending parent override (archive + slot + fee header) for pipelining,
|
|
557
|
+
* or the invalidation pending override when rolling back. Consumed by
|
|
558
|
+
* publisher.validateBlockHeader before broadcast.
|
|
559
|
+
*/ checkpointSimulationOverridesPlan;
|
|
560
|
+
getSignatureContext() {
|
|
561
|
+
return this.signatureContext;
|
|
562
|
+
}
|
|
563
|
+
constructor(slotNow, targetSlot, targetEpoch, checkpointNumber, syncedToBlockNumber, checkpointedCheckpointNumber, // TODO(palla/mbps): Can we remove the proposer in favor of attestorAddress? Need to check fisherman-node flows.
|
|
564
|
+
proposer, publisher, attestorAddress, invalidateCheckpoint, validatorClient, globalsBuilder, p2pClient, worldState, l1ToL2MessageSource, l2BlockSource, checkpointsBuilder, blockSink, l1Constants, signatureContext, config, timetable, slasherClient, epochCache, dateProvider, metrics, checkpointMetrics, eventEmitter, setStateFn, tracer, bindings, proposedCheckpointData){
|
|
565
|
+
this.slotNow = slotNow;
|
|
566
|
+
this.targetSlot = targetSlot;
|
|
567
|
+
this.targetEpoch = targetEpoch;
|
|
115
568
|
this.checkpointNumber = checkpointNumber;
|
|
116
569
|
this.syncedToBlockNumber = syncedToBlockNumber;
|
|
570
|
+
this.checkpointedCheckpointNumber = checkpointedCheckpointNumber;
|
|
117
571
|
this.proposer = proposer;
|
|
118
572
|
this.publisher = publisher;
|
|
119
573
|
this.attestorAddress = attestorAddress;
|
|
120
|
-
this.
|
|
574
|
+
this.invalidateCheckpoint = invalidateCheckpoint;
|
|
121
575
|
this.validatorClient = validatorClient;
|
|
122
576
|
this.globalsBuilder = globalsBuilder;
|
|
123
577
|
this.p2pClient = p2pClient;
|
|
124
578
|
this.worldState = worldState;
|
|
125
579
|
this.l1ToL2MessageSource = l1ToL2MessageSource;
|
|
580
|
+
this.l2BlockSource = l2BlockSource;
|
|
126
581
|
this.checkpointsBuilder = checkpointsBuilder;
|
|
582
|
+
this.blockSink = blockSink;
|
|
127
583
|
this.l1Constants = l1Constants;
|
|
584
|
+
this.signatureContext = signatureContext;
|
|
128
585
|
this.config = config;
|
|
129
586
|
this.timetable = timetable;
|
|
130
587
|
this.slasherClient = slasherClient;
|
|
131
588
|
this.epochCache = epochCache;
|
|
132
589
|
this.dateProvider = dateProvider;
|
|
133
590
|
this.metrics = metrics;
|
|
591
|
+
this.checkpointMetrics = checkpointMetrics;
|
|
134
592
|
this.eventEmitter = eventEmitter;
|
|
135
593
|
this.setStateFn = setStateFn;
|
|
136
|
-
this.
|
|
594
|
+
this.tracer = tracer;
|
|
595
|
+
this.proposedCheckpointData = proposedCheckpointData;
|
|
596
|
+
_initProto(this);
|
|
597
|
+
this.log = createLogger('sequencer:checkpoint-proposal', {
|
|
598
|
+
...bindings,
|
|
599
|
+
instanceId: `slot-${this.slotNow}`
|
|
600
|
+
});
|
|
601
|
+
this.checkpointEventLog = createLogger('sequencer:checkpoint-events', {
|
|
602
|
+
...bindings,
|
|
603
|
+
instanceId: `slot-${this.slotNow}`
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
/** Awaits the pending L1 submission if one is in progress. Call during shutdown. */ async awaitPendingSubmission() {
|
|
607
|
+
this.log.info('Awaiting pending L1 payload submission');
|
|
608
|
+
await this.pendingL1Submission;
|
|
609
|
+
}
|
|
610
|
+
logCheckpointEvent(eventName, message, fields) {
|
|
611
|
+
this.checkpointEventLog.debug(message, {
|
|
612
|
+
eventName: `sequencer-checkpoint-${eventName}`,
|
|
613
|
+
...fields
|
|
614
|
+
});
|
|
137
615
|
}
|
|
138
616
|
/**
|
|
139
617
|
* Executes the checkpoint proposal job.
|
|
140
|
-
*
|
|
618
|
+
* Builds blocks, assembles checkpoint, and broadcasts the proposal (blocking).
|
|
619
|
+
* Attestation collection, signing, and L1 submission are backgrounded so the
|
|
620
|
+
* work loop can return to IDLE immediately for consecutive slot proposals.
|
|
621
|
+
* Returns the built checkpoint if successful, undefined otherwise.
|
|
141
622
|
*/ async execute() {
|
|
142
623
|
// Enqueue governance and slashing votes (returns promises that will be awaited later)
|
|
143
624
|
// In fisherman mode, we simulate slashing but don't actually publish to L1
|
|
144
625
|
// These are constant for the whole slot, so we only enqueue them once
|
|
145
|
-
const votesPromises = new CheckpointVoter(this.
|
|
146
|
-
// Build
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
626
|
+
const votesPromises = new CheckpointVoter(this.targetSlot, this.publisher, this.attestorAddress, this.validatorClient, this.slasherClient, this.l1Constants, this.config, this.metrics, this.log).enqueueVotes();
|
|
627
|
+
// Build blocks, assemble checkpoint, and broadcast proposal (BLOCKING).
|
|
628
|
+
// Returns after broadcast — attestation collection is deferred.
|
|
629
|
+
const broadcast = await this.proposeCheckpoint();
|
|
630
|
+
if (!broadcast) {
|
|
631
|
+
await Promise.all(votesPromises);
|
|
632
|
+
// Still submit votes even without a checkpoint.
|
|
633
|
+
// Under proposer pipelining, vote-offenses signatures are EIP-712-bound to `targetSlot`
|
|
634
|
+
// (the pipelined slot in which the multicall is expected to mine). Submitting at the
|
|
635
|
+
// wall-clock time would let the multicall mine in a different L2 slot, causing
|
|
636
|
+
// signature verification to fail silently inside Multicall3. Delay submission to the
|
|
637
|
+
// start of `targetSlot` so the tx mines in the slot the vote was signed for.
|
|
638
|
+
if (!this.config.fishermanMode) {
|
|
639
|
+
this.pendingL1Submission = this.publisher.sendRequestsAt(this.targetSlot).then(()=>{});
|
|
640
|
+
}
|
|
641
|
+
return undefined;
|
|
642
|
+
}
|
|
643
|
+
const { checkpoint } = broadcast;
|
|
644
|
+
this.metrics.recordCheckpointProposalSuccess();
|
|
150
645
|
// Do not post anything to L1 if we are fishermen, but do perform L1 fee analysis
|
|
151
646
|
if (this.config.fishermanMode) {
|
|
152
647
|
await this.handleCheckpointEndAsFisherman(checkpoint);
|
|
153
|
-
return;
|
|
648
|
+
return checkpoint;
|
|
154
649
|
}
|
|
155
|
-
//
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
650
|
+
// Background the attestation → signing → L1 pipeline so the work loop is unblocked
|
|
651
|
+
this.pendingL1Submission = this.waitForAttestationsAndEnqueueSubmissionAsync(broadcast, votesPromises);
|
|
652
|
+
// Return the built checkpoint immediately — the work loop is now unblocked
|
|
653
|
+
return checkpoint;
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Background pipeline: collects attestations, signs them, enqueues the checkpoint, and submits to L1.
|
|
657
|
+
* Runs as a fire-and-forget task stored in `pendingL1Submission` so the work loop is unblocked.
|
|
658
|
+
*/ async waitForAttestationsAndEnqueueSubmissionAsync(broadcast, votesPromises) {
|
|
659
|
+
const { checkpoint } = broadcast;
|
|
660
|
+
const isPipelining = this.epochCache.isProposerPipeliningEnabled();
|
|
661
|
+
try {
|
|
662
|
+
// Wait for all votes actions, enqueued at the beginning, to resolve
|
|
663
|
+
await Promise.all(votesPromises);
|
|
664
|
+
// Try to collect attestations from the committee
|
|
665
|
+
const signedAttestations = await this.getSignedCommitteeAttestations(broadcast);
|
|
666
|
+
// If pipelining, wait for the previous checkpoint to land on L1 before submitting,
|
|
667
|
+
// so we can check it matches the proposed checkpoint we used as parent, and has valid attestations.
|
|
668
|
+
if (signedAttestations && (!isPipelining || await this.waitForValidParentCheckpointOnL1())) {
|
|
669
|
+
await this.enqueueCheckpointForSubmission({
|
|
670
|
+
checkpoint,
|
|
671
|
+
...signedAttestations
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
// If we failed to collect attestations, at least check if we need to issue an invalidation
|
|
675
|
+
// Note that if we are not pipelining, we enqueued the invalidation at the beginning
|
|
676
|
+
if (!signedAttestations && isPipelining && await this.waitForSyncedL2SlotNumber(this.slotNow)) {
|
|
677
|
+
const validationStatus = await this.l2BlockSource.getPendingChainValidationStatus();
|
|
678
|
+
if (!validationStatus.valid) {
|
|
679
|
+
this.log.warn(`Checkpoint ${validationStatus.checkpoint.checkpointNumber} has invalid attestations, enqueuing invalidation in spite of attestation collection failure`, {
|
|
680
|
+
checkpoint: validationStatus.checkpoint,
|
|
681
|
+
reason: validationStatus.reason
|
|
682
|
+
});
|
|
683
|
+
await this.enqueueInvalidation(validationStatus);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
// Send whatever was enqueued: votes + (propose | invalidation | nothing).
|
|
687
|
+
const l1Response = await this.publisher.sendRequestsAt(this.targetSlot);
|
|
688
|
+
const proposedAction = l1Response?.successfulActions.find((a)=>a === 'propose');
|
|
689
|
+
if (proposedAction) {
|
|
690
|
+
this.logCheckpointEvent('published', `Checkpoint published for slot ${this.targetSlot}`, {
|
|
691
|
+
slot: this.targetSlot,
|
|
692
|
+
checkpointNumber: this.checkpointNumber,
|
|
693
|
+
successfulActions: l1Response?.successfulActions,
|
|
694
|
+
sentActions: l1Response?.sentActions
|
|
695
|
+
});
|
|
696
|
+
this.eventEmitter.emit('checkpoint-published', {
|
|
697
|
+
checkpoint: this.checkpointNumber,
|
|
698
|
+
slot: this.targetSlot
|
|
699
|
+
});
|
|
700
|
+
const coinbase = checkpoint.header.coinbase;
|
|
701
|
+
await this.metrics.incFilledSlot(this.publisher.getSenderAddress().toString(), coinbase);
|
|
702
|
+
} else {
|
|
703
|
+
this.logCheckpointEvent('publish-failed', `Checkpoint publish failed for slot ${this.targetSlot}`, {
|
|
704
|
+
slot: this.targetSlot,
|
|
705
|
+
checkpointNumber: this.checkpointNumber,
|
|
706
|
+
successfulActions: l1Response?.successfulActions,
|
|
707
|
+
failedActions: l1Response?.failedActions,
|
|
708
|
+
sentActions: l1Response?.sentActions,
|
|
709
|
+
expiredActions: l1Response?.expiredActions,
|
|
710
|
+
reason: 'propose_action_not_successful'
|
|
711
|
+
});
|
|
712
|
+
this.log.warn(`Checkpoint publish failed for slot ${this.targetSlot}`, {
|
|
713
|
+
slot: this.targetSlot,
|
|
714
|
+
checkpointNumber: this.checkpointNumber,
|
|
715
|
+
successfulActions: l1Response?.successfulActions,
|
|
716
|
+
failedActions: l1Response?.failedActions,
|
|
717
|
+
sentActions: l1Response?.sentActions,
|
|
718
|
+
expiredActions: l1Response?.expiredActions,
|
|
719
|
+
reason: 'propose_action_not_successful'
|
|
720
|
+
});
|
|
721
|
+
this.eventEmitter.emit('checkpoint-publish-failed', {
|
|
722
|
+
...l1Response,
|
|
723
|
+
slot: this.targetSlot
|
|
724
|
+
});
|
|
725
|
+
if (isPipelining) {
|
|
726
|
+
this.metrics.recordPipelineDiscard();
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
} catch (err) {
|
|
730
|
+
if (err instanceof SequencerInterruptedError) {
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
this.logCheckpointEvent('publish-failed', `Checkpoint publish failed for slot ${this.targetSlot}`, {
|
|
734
|
+
slot: this.targetSlot,
|
|
735
|
+
checkpointNumber: this.checkpointNumber,
|
|
736
|
+
reason: err instanceof Error ? err.message : String(err)
|
|
737
|
+
});
|
|
738
|
+
this.log.error(`Background attestation/L1 pipeline failed for slot ${this.targetSlot}`, err, {
|
|
739
|
+
slot: this.targetSlot,
|
|
740
|
+
checkpointNumber: this.checkpointNumber,
|
|
741
|
+
reason: err instanceof Error ? err.message : String(err)
|
|
162
742
|
});
|
|
163
|
-
const coinbase = checkpoint?.header.coinbase;
|
|
164
|
-
await this.metrics.incFilledSlot(this.publisher.getSenderAddress().toString(), coinbase);
|
|
165
|
-
return checkpoint;
|
|
166
|
-
} else if (checkpoint) {
|
|
167
743
|
this.eventEmitter.emit('checkpoint-publish-failed', {
|
|
168
|
-
|
|
169
|
-
|
|
744
|
+
slot: this.targetSlot
|
|
745
|
+
});
|
|
746
|
+
if (isPipelining) {
|
|
747
|
+
this.metrics.recordPipelineDiscard();
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
/** Enqueues the checkpoint for L1 submission. Called after pipeline sleep in execute(). */ async enqueueCheckpointForSubmission(result) {
|
|
752
|
+
const { checkpoint, attestations, attestationsSignature } = result;
|
|
753
|
+
this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.targetSlot);
|
|
754
|
+
const aztecSlotDuration = this.l1Constants.slotDuration;
|
|
755
|
+
const submissionSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
|
|
756
|
+
const txTimeoutAt = new Date((submissionSlotStart + aztecSlotDuration) * 1000);
|
|
757
|
+
// If we have been configured to potentially skip publishing checkpoint then roll the dice here
|
|
758
|
+
if (this.config.skipPublishingCheckpointsPercent !== undefined && this.config.skipPublishingCheckpointsPercent > 0) {
|
|
759
|
+
const roll = Math.max(0, randomInt(100));
|
|
760
|
+
if (roll < this.config.skipPublishingCheckpointsPercent) {
|
|
761
|
+
this.log.warn(`Skipping publishing proposal for checkpoint ${checkpoint.number}. Configured percentage: ${this.config.skipPublishingCheckpointsPercent}, generated value: ${roll}`);
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
|
|
766
|
+
txTimeoutAt
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Wait until the archiver syncs past the given L2 slot number.
|
|
771
|
+
* The deadline is the end of `this.targetSlot`, beyond which any pipelined work would miss its
|
|
772
|
+
* L1 submission window and is no longer useful.
|
|
773
|
+
*/ async waitForSyncedL2SlotNumber(waitForSlot) {
|
|
774
|
+
const targetSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
|
|
775
|
+
const targetSlotEndMs = (targetSlotStart + this.l1Constants.slotDuration) * 1000;
|
|
776
|
+
const syncDelayTolerance = this.l1Constants.ethereumSlotDuration * 2 * 1000;
|
|
777
|
+
const timeoutSeconds = Math.max(0.1, (targetSlotEndMs + syncDelayTolerance - this.dateProvider.now()) / 1000);
|
|
778
|
+
try {
|
|
779
|
+
return await retryUntil(async ()=>{
|
|
780
|
+
const syncedSlot = await this.l2BlockSource.getSyncedL2SlotNumber();
|
|
781
|
+
return syncedSlot !== undefined && syncedSlot >= waitForSlot;
|
|
782
|
+
}, `archiver sync past slot ${waitForSlot}`, timeoutSeconds, 0.2);
|
|
783
|
+
} catch {
|
|
784
|
+
this.log.warn(`Archiver did not sync L1 past slot ${waitForSlot} before slot ${this.targetSlot} expired, discarding pipelined work`, {
|
|
785
|
+
checkpointNumber: this.checkpointNumber
|
|
786
|
+
});
|
|
787
|
+
this.emitPipelinedCheckpointDiscarded('archiver-sync-timeout');
|
|
788
|
+
return false;
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* Waits for the parent checkpoint to land on L1 before submitting a pipelined checkpoint.
|
|
793
|
+
* Polls until the archiver has synced L1 past the parent's slot, then verifies:
|
|
794
|
+
* - If we built on a proposed parent: it must have landed on L1 with matching hash and valid attestations.
|
|
795
|
+
* - If we built without a proposed parent: no new checkpoint must have appeared for that slot.
|
|
796
|
+
* If the parent has invalid attestations, enqueues an invalidation. Returns whether to proceed with the proposal.
|
|
797
|
+
*/ async waitForValidParentCheckpointOnL1() {
|
|
798
|
+
if (this.config.skipWaitForValidParentCheckpointOnL1) {
|
|
799
|
+
this.log.warn(`Skipping waitForValidParentCheckpointOnL1 due to test configuration`, {
|
|
800
|
+
checkpointNumber: this.checkpointNumber
|
|
801
|
+
});
|
|
802
|
+
return true;
|
|
803
|
+
}
|
|
804
|
+
const parentCheckpointNumber = CheckpointNumber(this.checkpointNumber - 1);
|
|
805
|
+
// Wait until archiver has synced L1 past the parent's slot (slotNow)
|
|
806
|
+
if (!await this.waitForSyncedL2SlotNumber(this.slotNow)) {
|
|
807
|
+
return false;
|
|
808
|
+
}
|
|
809
|
+
const tips = await this.l2BlockSource.getL2Tips();
|
|
810
|
+
const checkpointedNumber = tips.checkpointed.checkpoint.number;
|
|
811
|
+
// We built on top of a proposed checkpoint. Verify it landed on L1 as expected.
|
|
812
|
+
if (this.proposedCheckpointData) {
|
|
813
|
+
// After syncing from L1 we see the chain tip has invalid attestations. This means the parent checkpoint was posted
|
|
814
|
+
// with invalid attestations, or it built on top of something with invalid attestations and didnt invalidate them.
|
|
815
|
+
// Either way, we thought our parent would be valid, so we have to throw away our work. But at least we'll try and
|
|
816
|
+
// invalidate on L1 so we clean up the chain for the next proposer. And we'll slash them, but that's handled elsewhere.
|
|
817
|
+
const validationStatus = await this.l2BlockSource.getPendingChainValidationStatus();
|
|
818
|
+
if (!validationStatus.valid) {
|
|
819
|
+
this.log.warn(`Parent checkpoint ${parentCheckpointNumber} has invalid attestations, discarding pipelined work`, {
|
|
820
|
+
checkpointNumber: this.checkpointNumber,
|
|
821
|
+
reason: validationStatus.reason
|
|
822
|
+
});
|
|
823
|
+
this.emitPipelinedCheckpointDiscarded('parent-invalid-attestations');
|
|
824
|
+
await this.enqueueInvalidation(validationStatus);
|
|
825
|
+
return false;
|
|
826
|
+
}
|
|
827
|
+
// The pending chain is valid. But did the parent checkpoint land on L1 at all?
|
|
828
|
+
if (checkpointedNumber < parentCheckpointNumber) {
|
|
829
|
+
this.log.warn(`Parent checkpoint ${parentCheckpointNumber} did not land on L1, discarding pipelined work`, {
|
|
830
|
+
checkpointNumber: this.checkpointNumber,
|
|
831
|
+
checkpointedNumber
|
|
832
|
+
});
|
|
833
|
+
this.emitPipelinedCheckpointDiscarded('parent-not-on-l1');
|
|
834
|
+
return false;
|
|
835
|
+
}
|
|
836
|
+
// It landed. But is it the one we were expecting?
|
|
837
|
+
const expectedHash = this.proposedCheckpointData.header.hash().toString();
|
|
838
|
+
if (tips.checkpointed.checkpoint.hash !== expectedHash) {
|
|
839
|
+
this.log.warn(`Parent checkpoint ${parentCheckpointNumber} hash mismatch on L1, discarding pipelined work`, {
|
|
840
|
+
checkpointNumber: this.checkpointNumber,
|
|
841
|
+
expectedHash,
|
|
842
|
+
actualHash: tips.checkpointed.checkpoint.hash
|
|
843
|
+
});
|
|
844
|
+
this.emitPipelinedCheckpointDiscarded('parent-hash-mismatch');
|
|
845
|
+
return false;
|
|
846
|
+
}
|
|
847
|
+
return true;
|
|
848
|
+
} else {
|
|
849
|
+
// We didn't see a proposed checkpoint at build time, so we built on checkpointed parent from two slots ago.
|
|
850
|
+
// But if a new checkpoint for the previous slot appeared on L1 in the meantime, our checkpoint assumed the wrong parent,
|
|
851
|
+
// so we have to discard our work. This can happen if we're somehow cut off from p2p and fail to see the checkpoint
|
|
852
|
+
// proposal for the previous slot.
|
|
853
|
+
if (checkpointedNumber > parentCheckpointNumber) {
|
|
854
|
+
this.log.warn(`Unexpected checkpoint ${checkpointedNumber} landed on L1 after we built on top of parent ${parentCheckpointNumber}, discarding pipelined work`, {
|
|
855
|
+
checkpointNumber: this.checkpointNumber,
|
|
856
|
+
checkpointedNumber
|
|
857
|
+
});
|
|
858
|
+
this.emitPipelinedCheckpointDiscarded('unexpected-parent-appeared');
|
|
859
|
+
return false;
|
|
860
|
+
}
|
|
861
|
+
return true;
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
/** Emits the pipelined-checkpoint-discarded event and records the metric. */ emitPipelinedCheckpointDiscarded(reason) {
|
|
865
|
+
this.metrics.recordPipelineParentCheckpointMismatch(reason);
|
|
866
|
+
this.eventEmitter.emit('pipelined-checkpoint-discarded', {
|
|
867
|
+
slot: this.targetSlot,
|
|
868
|
+
checkpointNumber: this.checkpointNumber,
|
|
869
|
+
reason
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
/** Simulates and enqueues an invalidation request for the invalid parent checkpoint. */ async enqueueInvalidation(validationStatus) {
|
|
873
|
+
if (this.config.skipInvalidateBlockAsProposer) {
|
|
874
|
+
this.log.warn(`Skipping checkpoint invalidation as proposer due to test configuration`);
|
|
875
|
+
return;
|
|
876
|
+
}
|
|
877
|
+
const invalidateRequest = await this.publisher.simulateInvalidateCheckpoint(validationStatus);
|
|
878
|
+
if (invalidateRequest) {
|
|
879
|
+
const submissionSlotStart = Number(getTimestampForSlot(this.targetSlot, this.l1Constants));
|
|
880
|
+
const txTimeoutAt = new Date((submissionSlotStart + this.l1Constants.slotDuration) * 1000);
|
|
881
|
+
this.publisher.enqueueInvalidateCheckpoint(invalidateRequest, {
|
|
882
|
+
txTimeoutAt
|
|
883
|
+
});
|
|
884
|
+
} else {
|
|
885
|
+
this.log.info(`Invalidation simulation returned undefined, checkpoint may have been removed already`, {
|
|
886
|
+
checkpointNumber: this.checkpointNumber
|
|
170
887
|
});
|
|
171
|
-
return undefined;
|
|
172
888
|
}
|
|
173
889
|
}
|
|
174
890
|
async proposeCheckpoint() {
|
|
@@ -179,104 +895,282 @@ import { SequencerState } from './utils.js';
|
|
|
179
895
|
hasError: false
|
|
180
896
|
};
|
|
181
897
|
try {
|
|
898
|
+
const now = this.dateProvider.now();
|
|
899
|
+
if (this.epochCache.isProposerPipeliningEnabled() && this.proposedCheckpointData) {
|
|
900
|
+
// Measure against the wall-clock slot whose build window we are currently using.
|
|
901
|
+
// In pipelining mode `targetSlot` is intentionally one slot ahead, which makes the
|
|
902
|
+
// target-slot boundary a full slot away from the actual build start time.
|
|
903
|
+
const slotBoundaryMs = Number(getTimestampForSlot(this.slotNow, this.l1Constants)) * 1000;
|
|
904
|
+
this.checkpointMetrics.recordPipelinedCheckpointBuildStartOffsetFromSlotBoundary(now - slotBoundaryMs);
|
|
905
|
+
}
|
|
906
|
+
this.checkpointMetrics.startCheckpointTiming(now);
|
|
182
907
|
// Get operator configured coinbase and fee recipient for this attestor
|
|
183
908
|
const coinbase = this.validatorClient.getCoinbaseForAttestor(this.attestorAddress);
|
|
184
909
|
const feeRecipient = this.validatorClient.getFeeRecipientForAttestor(this.attestorAddress);
|
|
185
910
|
// Start the checkpoint
|
|
186
|
-
this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.
|
|
187
|
-
this.
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
this.
|
|
911
|
+
this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.targetSlot);
|
|
912
|
+
this.logCheckpointEvent('slot-started', `Starting checkpoint proposal for slot ${this.targetSlot}`, {
|
|
913
|
+
buildSlot: this.slotNow,
|
|
914
|
+
submissionSlot: this.targetSlot,
|
|
915
|
+
slot: this.targetSlot,
|
|
916
|
+
checkpointNumber: this.checkpointNumber,
|
|
917
|
+
pipelining: this.epochCache.isProposerPipeliningEnabled(),
|
|
918
|
+
proposer: this.proposer?.toString(),
|
|
919
|
+
attestorAddress: this.attestorAddress.toString(),
|
|
920
|
+
publisherAddress: this.publisher.getSenderAddress().toString(),
|
|
921
|
+
coinbase: coinbase.toString()
|
|
922
|
+
});
|
|
923
|
+
this.metrics.incOpenSlot(this.targetSlot, this.proposer?.toString() ?? 'unknown');
|
|
924
|
+
// Enqueues checkpoint invalidation (constant for the whole slot)
|
|
925
|
+
if (this.invalidateCheckpoint && !this.config.skipInvalidateBlockAsProposer) {
|
|
926
|
+
this.publisher.enqueueInvalidateCheckpoint(this.invalidateCheckpoint);
|
|
191
927
|
}
|
|
192
|
-
//
|
|
193
|
-
|
|
194
|
-
//
|
|
928
|
+
// Build the simulation plan for this slot. When pipelining, this overrides L1's view of
|
|
929
|
+
// pending/archive/fee-header to "as if the proposed parent had landed", so both the
|
|
930
|
+
// mana-min-fee simulation (in the globals builder) and the pre-broadcast
|
|
931
|
+
// validateBlockHeader see the chain tip the eventual L1 send will see.
|
|
932
|
+
const isPipelining = this.epochCache.isProposerPipeliningEnabled();
|
|
933
|
+
this.checkpointSimulationOverridesPlan = await buildCheckpointSimulationOverridesPlan({
|
|
934
|
+
checkpointNumber: this.checkpointNumber,
|
|
935
|
+
proposedCheckpointData: isPipelining ? this.proposedCheckpointData : undefined,
|
|
936
|
+
invalidateToPendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
937
|
+
checkpointedCheckpointNumber: this.checkpointedCheckpointNumber,
|
|
938
|
+
rollup: this.publisher.rollupContract,
|
|
939
|
+
signatureContext: this.signatureContext,
|
|
940
|
+
log: this.log
|
|
941
|
+
});
|
|
942
|
+
const checkpointGlobalVariables = await this.globalsBuilder.buildCheckpointGlobalVariables(coinbase, feeRecipient, this.targetSlot, this.checkpointSimulationOverridesPlan);
|
|
943
|
+
// Collect L1 to L2 messages for the checkpoint and compute their hash
|
|
195
944
|
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(this.checkpointNumber);
|
|
945
|
+
const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
|
|
946
|
+
// Collect the out hashes of all the checkpoints before this one in the same epoch.
|
|
947
|
+
// Under pipelining the parent checkpoint may not be on L1 yet at build time, so the helper
|
|
948
|
+
// splices in the parent's checkpointOutHash from the locally-known proposed checkpoint so
|
|
949
|
+
// the resulting `epochOutHash` matches what validators (and L1) compute once the parent
|
|
950
|
+
// lands on L1.
|
|
951
|
+
const previousCheckpointOutHashes = await getPreviousCheckpointOutHashes({
|
|
952
|
+
blockSource: this.l2BlockSource,
|
|
953
|
+
epoch: this.targetEpoch,
|
|
954
|
+
checkpointNumber: this.checkpointNumber,
|
|
955
|
+
l1Constants: this.epochCache.getL1Constants(),
|
|
956
|
+
pipeliningEnabled: this.epochCache.isProposerPipeliningEnabled(),
|
|
957
|
+
proposedCheckpointData: this.proposedCheckpointData,
|
|
958
|
+
log: this.log
|
|
959
|
+
});
|
|
960
|
+
// Anchor the modifier to the predicted parent fee header: L1 will apply it against
|
|
961
|
+
// that, not against the latest published checkpoint (which lags by one under pipelining).
|
|
962
|
+
const predictedParentEthPerFeeAssetE12 = this.checkpointSimulationOverridesPlan?.pendingCheckpointState?.feeHeader?.ethPerFeeAsset;
|
|
963
|
+
const feeAssetPriceModifier = await this.publisher.getFeeAssetPriceModifier(predictedParentEthPerFeeAssetE12);
|
|
196
964
|
const fork = _ts_add_disposable_resource(env, await this.worldState.fork(this.syncedToBlockNumber, {
|
|
197
965
|
closeDelayMs: 12_000
|
|
198
|
-
}),
|
|
966
|
+
}), true);
|
|
199
967
|
// Create checkpoint builder for the entire slot
|
|
200
|
-
const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(this.checkpointNumber, checkpointGlobalVariables, l1ToL2Messages, fork);
|
|
968
|
+
const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(this.checkpointNumber, checkpointGlobalVariables, feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, this.log.getBindings());
|
|
201
969
|
// Options for the validator client when creating block and checkpoint proposals
|
|
202
970
|
const blockProposalOptions = {
|
|
203
971
|
publishFullTxs: !!this.config.publishTxsWithProposals,
|
|
204
972
|
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
|
|
205
973
|
};
|
|
206
|
-
|
|
207
|
-
|
|
974
|
+
const checkpointProposalOptions = {
|
|
975
|
+
publishFullTxs: !!this.config.publishTxsWithProposals,
|
|
976
|
+
broadcastInvalidCheckpointProposal: this.config.broadcastInvalidCheckpointProposalOnly || this.config.broadcastInvalidBlockProposal
|
|
977
|
+
};
|
|
978
|
+
let blocksInCheckpoint = [];
|
|
979
|
+
let blockPendingBroadcast = undefined;
|
|
980
|
+
const checkpointBuildTimer = new Timer();
|
|
981
|
+
try {
|
|
982
|
+
// Main loop: build blocks for the checkpoint
|
|
983
|
+
const result = await this.buildBlocksForCheckpoint(checkpointBuilder, checkpointGlobalVariables.timestamp, inHash, blockProposalOptions);
|
|
984
|
+
blocksInCheckpoint = result.blocksInCheckpoint;
|
|
985
|
+
blockPendingBroadcast = result.blockPendingBroadcast;
|
|
986
|
+
} catch (err) {
|
|
987
|
+
// These errors are expected in HA mode, so we yield and let another HA node handle the slot
|
|
988
|
+
// The only distinction between the 2 errors is SlashingProtectionError throws when the payload is different,
|
|
989
|
+
// which is normal for block building (may have picked different txs)
|
|
990
|
+
if (this.handleHASigningError(err, 'Block proposal')) {
|
|
991
|
+
return undefined;
|
|
992
|
+
}
|
|
993
|
+
throw err;
|
|
994
|
+
}
|
|
208
995
|
if (blocksInCheckpoint.length === 0) {
|
|
209
|
-
this.
|
|
210
|
-
slot: this.
|
|
996
|
+
this.logCheckpointEvent('build-failed', `Checkpoint build failed for slot ${this.targetSlot}`, {
|
|
997
|
+
slot: this.targetSlot,
|
|
998
|
+
checkpointNumber: this.checkpointNumber,
|
|
999
|
+
reason: 'no_blocks_built'
|
|
1000
|
+
});
|
|
1001
|
+
this.log.warn(`No blocks were built for slot ${this.targetSlot}`, {
|
|
1002
|
+
slot: this.targetSlot,
|
|
1003
|
+
checkpointNumber: this.checkpointNumber,
|
|
1004
|
+
reason: 'no_blocks_built'
|
|
211
1005
|
});
|
|
212
1006
|
this.eventEmitter.emit('checkpoint-empty', {
|
|
213
|
-
slot: this.
|
|
1007
|
+
slot: this.targetSlot
|
|
1008
|
+
});
|
|
1009
|
+
return undefined;
|
|
1010
|
+
}
|
|
1011
|
+
const minBlocksForCheckpoint = this.config.minBlocksForCheckpoint;
|
|
1012
|
+
if (minBlocksForCheckpoint !== undefined && blocksInCheckpoint.length < minBlocksForCheckpoint) {
|
|
1013
|
+
this.logCheckpointEvent('build-failed', `Checkpoint build failed for slot ${this.targetSlot}`, {
|
|
1014
|
+
slot: this.targetSlot,
|
|
1015
|
+
checkpointNumber: this.checkpointNumber,
|
|
1016
|
+
blocksBuilt: blocksInCheckpoint.length,
|
|
1017
|
+
minBlocksForCheckpoint,
|
|
1018
|
+
reason: 'min_blocks_not_met'
|
|
1019
|
+
});
|
|
1020
|
+
this.log.warn(`Checkpoint has fewer blocks than minimum (${blocksInCheckpoint.length} < ${minBlocksForCheckpoint}), skipping proposal`, {
|
|
1021
|
+
slot: this.targetSlot,
|
|
1022
|
+
checkpointNumber: this.checkpointNumber,
|
|
1023
|
+
blocksBuilt: blocksInCheckpoint.length,
|
|
1024
|
+
minBlocksForCheckpoint,
|
|
1025
|
+
reason: 'min_blocks_not_met'
|
|
214
1026
|
});
|
|
215
1027
|
return undefined;
|
|
216
1028
|
}
|
|
217
1029
|
// Assemble and broadcast the checkpoint proposal, including the last block that was not
|
|
218
1030
|
// broadcasted yet, and wait to collect the committee attestations.
|
|
219
|
-
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.
|
|
1031
|
+
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.targetSlot);
|
|
220
1032
|
const checkpoint = await checkpointBuilder.completeCheckpoint();
|
|
221
|
-
//
|
|
1033
|
+
// Final validation: per-block limits are only checked if the operator set them explicitly.
|
|
1034
|
+
// Otherwise, checkpoint-level budgets were already enforced by the redistribution logic.
|
|
1035
|
+
try {
|
|
1036
|
+
validateCheckpoint(checkpoint, {
|
|
1037
|
+
rollupManaLimit: this.l1Constants.rollupManaLimit,
|
|
1038
|
+
maxL2BlockGas: this.config.maxL2BlockGas,
|
|
1039
|
+
maxDABlockGas: this.config.maxDABlockGas,
|
|
1040
|
+
maxTxsPerBlock: this.config.maxTxsPerBlock,
|
|
1041
|
+
maxTxsPerCheckpoint: this.config.maxTxsPerCheckpoint
|
|
1042
|
+
});
|
|
1043
|
+
} catch (err) {
|
|
1044
|
+
this.logCheckpointEvent('build-failed', `Checkpoint build failed for slot ${this.targetSlot}`, {
|
|
1045
|
+
slot: this.targetSlot,
|
|
1046
|
+
checkpointNumber: this.checkpointNumber,
|
|
1047
|
+
blocksBuilt: blocksInCheckpoint.length,
|
|
1048
|
+
reason: 'invalid_checkpoint',
|
|
1049
|
+
checkpoint: checkpoint.header.toInspect()
|
|
1050
|
+
});
|
|
1051
|
+
this.log.error(`Built an invalid checkpoint at slot ${this.slotNow} (skipping proposal)`, err, {
|
|
1052
|
+
slot: this.targetSlot,
|
|
1053
|
+
checkpointNumber: this.checkpointNumber,
|
|
1054
|
+
blocksBuilt: blocksInCheckpoint.length,
|
|
1055
|
+
reason: 'invalid_checkpoint',
|
|
1056
|
+
checkpoint: checkpoint.header.toInspect()
|
|
1057
|
+
});
|
|
1058
|
+
return undefined;
|
|
1059
|
+
}
|
|
1060
|
+
// Record checkpoint-level build metrics
|
|
1061
|
+
this.checkpointMetrics.recordCheckpointBuild(checkpointBuildTimer.ms(), blocksInCheckpoint.length, checkpoint.getStats().txCount, Number(checkpoint.header.totalManaUsed.toBigInt()));
|
|
1062
|
+
this.logCheckpointEvent('built', `Checkpoint built for slot ${this.targetSlot}`, {
|
|
1063
|
+
slot: this.targetSlot,
|
|
1064
|
+
buildSlot: this.slotNow,
|
|
1065
|
+
checkpointNumber: this.checkpointNumber,
|
|
1066
|
+
proposer: this.proposer?.toString(),
|
|
1067
|
+
attestorAddress: this.attestorAddress.toString(),
|
|
1068
|
+
publisherAddress: this.publisher.getSenderAddress().toString(),
|
|
1069
|
+
blocksBuilt: blocksInCheckpoint.length,
|
|
1070
|
+
txCount: checkpoint.getStats().txCount,
|
|
1071
|
+
totalMana: Number(checkpoint.header.totalManaUsed.toBigInt())
|
|
1072
|
+
});
|
|
1073
|
+
// In fisherman mode, return the checkpoint without broadcasting or collecting attestations
|
|
222
1074
|
if (this.config.fishermanMode) {
|
|
223
|
-
this.log.info(`Built checkpoint for slot ${this.
|
|
224
|
-
slot: this.
|
|
1075
|
+
this.log.info(`Built checkpoint for slot ${this.targetSlot} with ${blocksInCheckpoint.length} blocks. ` + `Skipping proposal in fisherman mode.`, {
|
|
1076
|
+
slot: this.targetSlot,
|
|
225
1077
|
checkpoint: checkpoint.header.toInspect(),
|
|
226
1078
|
blocksBuilt: blocksInCheckpoint.length
|
|
227
1079
|
});
|
|
228
1080
|
this.metrics.recordCheckpointSuccess();
|
|
229
|
-
|
|
1081
|
+
// Return a broadcast result with a dummy proposal — fisherman mode skips attestation collection
|
|
1082
|
+
return {
|
|
1083
|
+
checkpoint,
|
|
1084
|
+
proposal: undefined,
|
|
1085
|
+
blockProposedAt: this.dateProvider.now()
|
|
1086
|
+
};
|
|
230
1087
|
}
|
|
231
|
-
//
|
|
232
|
-
|
|
1088
|
+
// Validate the header against L1 state before broadcasting.
|
|
1089
|
+
// If this fails the slot is aborted before any gossip work; state drift between here
|
|
1090
|
+
// and the eventual L1 send is caught by the bundle simulate at send time.
|
|
1091
|
+
try {
|
|
1092
|
+
await this.publisher.validateBlockHeader(checkpoint.header, this.checkpointSimulationOverridesPlan);
|
|
1093
|
+
} catch (err) {
|
|
1094
|
+
this.log.error(`Pre-broadcast header validation failed for slot ${this.targetSlot}; aborting`, err, {
|
|
1095
|
+
slot: this.targetSlot,
|
|
1096
|
+
checkpointNumber: this.checkpointNumber
|
|
1097
|
+
});
|
|
1098
|
+
this.metrics.recordCheckpointProposalFailed('header_validation_failed');
|
|
1099
|
+
this.eventEmitter.emit('header-validation-failed', {
|
|
1100
|
+
slot: this.targetSlot,
|
|
1101
|
+
checkpointNumber: this.checkpointNumber,
|
|
1102
|
+
reason: err instanceof Error ? err.message : String(err)
|
|
1103
|
+
});
|
|
1104
|
+
return undefined;
|
|
1105
|
+
}
|
|
1106
|
+
// Create the checkpoint proposal and broadcast it
|
|
1107
|
+
const proposal = await this.validatorClient.createCheckpointProposal(checkpoint.header, checkpoint.archive.root, this.checkpointNumber, feeAssetPriceModifier, blockPendingBroadcast, this.proposer, checkpointProposalOptions);
|
|
1108
|
+
// Advance our own optimistic proposed-checkpoint tip locally before gossiping. Gossipsub
|
|
1109
|
+
// doesn't echo our own messages back, so this is how the proposer makes its own proposed
|
|
1110
|
+
// checkpoint visible for pipelining the next slot. Built from local checkpoint data — never
|
|
1111
|
+
// from the broadcast proposal archive, which may be deliberately corrupted under test flags.
|
|
1112
|
+
// Fail closed: if this throws, the outer catch aborts the slot before gossiping.
|
|
1113
|
+
await this.syncProposedCheckpointToArchiver(checkpoint, blocksInCheckpoint.length, feeAssetPriceModifier);
|
|
233
1114
|
const blockProposedAt = this.dateProvider.now();
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
1115
|
+
if (this.config.skipBroadcastCheckpointProposal) {
|
|
1116
|
+
// Test-only: suppress the CheckpointProposal so peers never see a proposed checkpoint for
|
|
1117
|
+
// this slot, but still broadcast the held last block standalone so peers' archivers ingest
|
|
1118
|
+
// it as a proposed-but-uncheckpointed tip — the exact orphan-block state that
|
|
1119
|
+
// pruneOrphanProposedBlocks / checkSync must handle.
|
|
1120
|
+
if (blockPendingBroadcast && !this.config.skipBroadcastProposals) {
|
|
1121
|
+
await this.p2pClient.broadcastProposal(blockPendingBroadcast);
|
|
1122
|
+
}
|
|
1123
|
+
} else if (!this.config.skipBroadcastProposals) {
|
|
1124
|
+
await this.p2pClient.broadcastCheckpointProposal(proposal);
|
|
1125
|
+
this.checkpointMetrics.noteCheckpointBroadcast(this.dateProvider.now());
|
|
1126
|
+
}
|
|
1127
|
+
// Return immediately after broadcast — attestation collection happens in the background
|
|
1128
|
+
return {
|
|
1129
|
+
checkpoint,
|
|
1130
|
+
proposal,
|
|
1131
|
+
blockProposedAt
|
|
1132
|
+
};
|
|
252
1133
|
} catch (e) {
|
|
253
1134
|
env.error = e;
|
|
254
1135
|
env.hasError = true;
|
|
255
1136
|
} finally{
|
|
256
|
-
_ts_dispose_resources(env);
|
|
1137
|
+
const result = _ts_dispose_resources(env);
|
|
1138
|
+
if (result) await result;
|
|
257
1139
|
}
|
|
258
1140
|
} catch (err) {
|
|
259
|
-
|
|
1141
|
+
if (err && (err instanceof DutyAlreadySignedError || err instanceof SlashingProtectionError)) {
|
|
1142
|
+
// swallow this error. It's already been logged by a function deeper in the stack
|
|
1143
|
+
return undefined;
|
|
1144
|
+
}
|
|
1145
|
+
this.log.error(`Error building checkpoint at slot ${this.targetSlot}`, err);
|
|
260
1146
|
return undefined;
|
|
261
1147
|
}
|
|
262
1148
|
}
|
|
263
1149
|
/**
|
|
264
1150
|
* Builds blocks for a checkpoint within the current slot.
|
|
265
|
-
*/ async buildBlocksForCheckpoint(checkpointBuilder, timestamp, blockProposalOptions) {
|
|
1151
|
+
*/ async buildBlocksForCheckpoint(checkpointBuilder, timestamp, inHash, blockProposalOptions) {
|
|
266
1152
|
const blocksInCheckpoint = [];
|
|
267
1153
|
const txHashesAlreadyIncluded = new Set();
|
|
268
1154
|
const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
|
|
269
1155
|
// Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
|
|
270
|
-
let
|
|
1156
|
+
let blockPendingBroadcast = undefined;
|
|
271
1157
|
while(true){
|
|
272
1158
|
const blocksBuilt = blocksInCheckpoint.length;
|
|
273
|
-
const indexWithinCheckpoint = blocksBuilt;
|
|
1159
|
+
const indexWithinCheckpoint = IndexWithinCheckpoint(blocksBuilt);
|
|
274
1160
|
const blockNumber = BlockNumber(initialBlockNumber + blocksBuilt);
|
|
1161
|
+
if (blocksBuilt >= this.config.maxBlocksPerCheckpoint) {
|
|
1162
|
+
this.log.debug(`Reached max blocks per checkpoint`, {
|
|
1163
|
+
slot: this.targetSlot,
|
|
1164
|
+
blocksBuilt,
|
|
1165
|
+
maxBlocksPerCheckpoint: this.config.maxBlocksPerCheckpoint
|
|
1166
|
+
});
|
|
1167
|
+
break;
|
|
1168
|
+
}
|
|
275
1169
|
const secondsIntoSlot = this.getSecondsIntoSlot();
|
|
276
1170
|
const timingInfo = this.timetable.canStartNextBlock(secondsIntoSlot);
|
|
277
1171
|
if (!timingInfo.canStart) {
|
|
278
1172
|
this.log.debug(`Not enough time left in slot to start another block`, {
|
|
279
|
-
slot: this.
|
|
1173
|
+
slot: this.targetSlot,
|
|
280
1174
|
blocksBuilt,
|
|
281
1175
|
secondsIntoSlot
|
|
282
1176
|
});
|
|
@@ -293,19 +1187,22 @@ import { SequencerState } from './utils.js';
|
|
|
293
1187
|
indexWithinCheckpoint,
|
|
294
1188
|
txHashesAlreadyIncluded
|
|
295
1189
|
});
|
|
296
|
-
if
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
1190
|
+
// If we failed to build the block due to insufficient txs, we try again if there is still time left in the slot
|
|
1191
|
+
if ('failure' in buildResult) {
|
|
1192
|
+
// If this was the last subslot, or we're running with a single block per slot, we're done
|
|
1193
|
+
if (timingInfo.isLastBlock || timingInfo.deadline === undefined) {
|
|
1194
|
+
break;
|
|
1195
|
+
}
|
|
1196
|
+
// Otherwise, if there is still time for more blocks, we wait until the next subslot and try again
|
|
300
1197
|
await this.waitUntilNextSubslot(timingInfo.deadline);
|
|
301
1198
|
continue;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
1199
|
+
}
|
|
1200
|
+
// If there was an error building the block, we just exit the loop and give up the rest of the slot.
|
|
1201
|
+
// We don't want to risk building more blocks if something went wrong.
|
|
1202
|
+
if ('error' in buildResult) {
|
|
306
1203
|
if (!(buildResult.error instanceof SequencerInterruptedError)) {
|
|
307
|
-
this.log.warn(`Halting block building for slot ${this.
|
|
308
|
-
slot: this.
|
|
1204
|
+
this.log.warn(`Halting block building for slot ${this.targetSlot}`, {
|
|
1205
|
+
slot: this.targetSlot,
|
|
309
1206
|
blocksBuilt,
|
|
310
1207
|
error: buildResult.error
|
|
311
1208
|
});
|
|
@@ -313,136 +1210,184 @@ import { SequencerState } from './utils.js';
|
|
|
313
1210
|
break;
|
|
314
1211
|
}
|
|
315
1212
|
const { block, usedTxs } = buildResult;
|
|
1213
|
+
this.checkpointMetrics.noteCheckpointBlockBuilt(this.dateProvider.now(), {
|
|
1214
|
+
isFirstBlock: blocksBuilt === 0,
|
|
1215
|
+
isLastBlock: timingInfo.isLastBlock
|
|
1216
|
+
});
|
|
316
1217
|
blocksInCheckpoint.push(block);
|
|
317
|
-
|
|
318
|
-
//
|
|
319
|
-
|
|
1218
|
+
usedTxs.forEach((tx)=>txHashesAlreadyIncluded.add(tx.txHash.toString()));
|
|
1219
|
+
// Sign the block proposal. This will throw if HA signing fails.
|
|
1220
|
+
const proposal = await this.createBlockProposal(block, inHash, usedTxs, {
|
|
1221
|
+
...blockProposalOptions,
|
|
1222
|
+
broadcastInvalidBlockProposal: blockProposalOptions.broadcastInvalidBlockProposal || block.indexWithinCheckpoint === this.config.invalidBlockProposalIndexWithinCheckpoint
|
|
1223
|
+
});
|
|
1224
|
+
// Sync the proposed block to the archiver to make it available, only after we've managed to sign the proposal,
|
|
1225
|
+
// so we avoid polluting our archive with a block that would fail.
|
|
1226
|
+
// We wait for the sync to succeed, as this helps catch consistency errors, even if it means we lose some time for block-building.
|
|
1227
|
+
// If this throws, we abort the entire checkpoint.
|
|
320
1228
|
await this.syncProposedBlockToArchiver(block);
|
|
321
|
-
// If this is the last block,
|
|
1229
|
+
// If this is the last block, do not broadcast it, since it will be included in the checkpoint proposal.
|
|
322
1230
|
if (timingInfo.isLastBlock) {
|
|
323
|
-
this.log.verbose(`Completed final block ${blockNumber} for slot ${this.
|
|
324
|
-
slot: this.
|
|
1231
|
+
this.log.verbose(`Completed final block ${blockNumber} for slot ${this.targetSlot}`, {
|
|
1232
|
+
slot: this.targetSlot,
|
|
325
1233
|
blockNumber,
|
|
326
1234
|
blocksBuilt
|
|
327
1235
|
});
|
|
328
|
-
|
|
329
|
-
block,
|
|
330
|
-
txs: usedTxs
|
|
331
|
-
};
|
|
1236
|
+
blockPendingBroadcast = proposal;
|
|
332
1237
|
break;
|
|
333
1238
|
}
|
|
334
|
-
//
|
|
335
|
-
|
|
336
|
-
if (!this.config.fishermanMode) {
|
|
337
|
-
// TODO(palla/mbps): Wire this to the new p2p API once available
|
|
338
|
-
const proposal = await this.validatorClient.createBlockProposal(block.header.globalVariables.blockNumber, (await checkpointBuilder.getCheckpoint()).header, block.archive.root, usedTxs, this.proposer, blockProposalOptions);
|
|
1239
|
+
// Once we have a signed proposal and the archiver agreed with our proposed block, then we broadcast it.
|
|
1240
|
+
if (proposal && !this.config.skipBroadcastProposals) {
|
|
339
1241
|
await this.p2pClient.broadcastProposal(proposal);
|
|
340
1242
|
}
|
|
341
1243
|
// Wait until the next block's start time
|
|
342
1244
|
await this.waitUntilNextSubslot(timingInfo.deadline);
|
|
343
1245
|
}
|
|
344
|
-
this.log.verbose(`Block building loop completed for slot ${this.
|
|
345
|
-
slot: this.
|
|
1246
|
+
this.log.verbose(`Block building loop completed for slot ${this.targetSlot}`, {
|
|
1247
|
+
slot: this.targetSlot,
|
|
346
1248
|
blocksBuilt: blocksInCheckpoint.length
|
|
347
1249
|
});
|
|
348
1250
|
return {
|
|
349
1251
|
blocksInCheckpoint,
|
|
350
|
-
|
|
1252
|
+
blockPendingBroadcast
|
|
351
1253
|
};
|
|
352
1254
|
}
|
|
1255
|
+
/** Creates a block proposal for a given block via the validator client (unless in fisherman mode) */ createBlockProposal(block, inHash, usedTxs, blockProposalOptions) {
|
|
1256
|
+
if (this.config.fishermanMode) {
|
|
1257
|
+
this.log.info(`Skipping block proposal for block ${block.number} in fisherman mode`);
|
|
1258
|
+
return Promise.resolve(undefined);
|
|
1259
|
+
}
|
|
1260
|
+
return this.validatorClient.createBlockProposal(block.header, this.checkpointNumber, block.indexWithinCheckpoint, inHash, block.archive.root, usedTxs, this.proposer, blockProposalOptions);
|
|
1261
|
+
}
|
|
353
1262
|
/** Sleeps until it is time to produce the next block in the slot */ async waitUntilNextSubslot(nextSubslotStart) {
|
|
354
|
-
this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.
|
|
1263
|
+
this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.targetSlot);
|
|
355
1264
|
this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, {
|
|
356
|
-
slot: this.
|
|
1265
|
+
slot: this.targetSlot
|
|
357
1266
|
});
|
|
358
1267
|
await this.waitUntilTimeInSlot(nextSubslotStart);
|
|
359
1268
|
}
|
|
360
1269
|
/** Builds a single block. Called from the main block building loop. */ async buildSingleBlock(checkpointBuilder, opts) {
|
|
361
1270
|
const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded } = opts;
|
|
362
|
-
this.log.verbose(`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.
|
|
1271
|
+
this.log.verbose(`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot}`, {
|
|
363
1272
|
...checkpointBuilder.getConstantData(),
|
|
364
1273
|
...opts
|
|
365
1274
|
});
|
|
366
1275
|
try {
|
|
367
1276
|
// Wait until we have enough txs to build the block
|
|
368
|
-
const minTxs = this.
|
|
369
|
-
const { availableTxs, canStartBuilding } = await this.waitForMinTxs(opts);
|
|
1277
|
+
const { availableTxs, canStartBuilding, minTxs } = await this.waitForMinTxs(opts);
|
|
370
1278
|
if (!canStartBuilding) {
|
|
371
|
-
this.
|
|
1279
|
+
this.logCheckpointEvent('block-build-failed', `Block build failed for slot ${this.targetSlot}`, {
|
|
1280
|
+
reason: 'insufficient_txs',
|
|
1281
|
+
blockNumber,
|
|
1282
|
+
slot: this.targetSlot,
|
|
1283
|
+
checkpointNumber: this.checkpointNumber,
|
|
1284
|
+
indexWithinCheckpoint,
|
|
1285
|
+
availableTxs,
|
|
1286
|
+
minTxs
|
|
1287
|
+
});
|
|
1288
|
+
this.log.warn(`Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (got ${availableTxs} txs but needs ${minTxs})`, {
|
|
1289
|
+
reason: 'insufficient_txs',
|
|
372
1290
|
blockNumber,
|
|
373
|
-
slot: this.
|
|
374
|
-
|
|
1291
|
+
slot: this.targetSlot,
|
|
1292
|
+
checkpointNumber: this.checkpointNumber,
|
|
1293
|
+
indexWithinCheckpoint,
|
|
1294
|
+
availableTxs,
|
|
1295
|
+
minTxs
|
|
375
1296
|
});
|
|
376
1297
|
this.eventEmitter.emit('block-tx-count-check-failed', {
|
|
377
1298
|
minTxs,
|
|
378
1299
|
availableTxs,
|
|
379
|
-
slot: this.
|
|
1300
|
+
slot: this.targetSlot
|
|
380
1301
|
});
|
|
381
1302
|
this.metrics.recordBlockProposalFailed('insufficient_txs');
|
|
382
|
-
return
|
|
1303
|
+
return {
|
|
1304
|
+
failure: 'insufficient-txs'
|
|
1305
|
+
};
|
|
383
1306
|
}
|
|
384
1307
|
// Create iterator to pending txs. We filter out txs already included in previous blocks in the checkpoint
|
|
385
1308
|
// just in case p2p failed to sync the provisional block and didn't get to remove those txs from the mempool yet.
|
|
386
|
-
const pendingTxs = filter(this.p2pClient.
|
|
387
|
-
this.log.debug(`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.
|
|
388
|
-
slot: this.
|
|
1309
|
+
const pendingTxs = filter(this.p2pClient.iterateEligiblePendingTxs(), (tx)=>!txHashesAlreadyIncluded.has(tx.txHash.toString()));
|
|
1310
|
+
this.log.debug(`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.targetSlot} with ${availableTxs} available txs`, {
|
|
1311
|
+
slot: this.targetSlot,
|
|
389
1312
|
blockNumber,
|
|
390
1313
|
indexWithinCheckpoint
|
|
391
1314
|
});
|
|
392
|
-
this.setStateFn(SequencerState.CREATING_BLOCK, this.
|
|
1315
|
+
this.setStateFn(SequencerState.CREATING_BLOCK, this.targetSlot);
|
|
1316
|
+
// Per-block limits are operator overrides (from SEQ_MAX_L2_BLOCK_GAS etc.) further capped
|
|
1317
|
+
// by remaining checkpoint-level budgets inside CheckpointBuilder before each block is built.
|
|
1318
|
+
// minValidTxs is passed into the builder so it can reject the block *before* updating state.
|
|
1319
|
+
const minValidTxs = forceCreate ? 0 : this.config.minValidTxsPerBlock ?? minTxs;
|
|
393
1320
|
const blockBuilderOptions = {
|
|
394
1321
|
maxTransactions: this.config.maxTxsPerBlock,
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
1322
|
+
maxBlockGas: this.config.maxL2BlockGas !== undefined || this.config.maxDABlockGas !== undefined ? new Gas(this.config.maxDABlockGas ?? Infinity, this.config.maxL2BlockGas ?? Infinity) : undefined,
|
|
1323
|
+
deadline: buildDeadline,
|
|
1324
|
+
isBuildingProposal: true,
|
|
1325
|
+
minValidTxs,
|
|
1326
|
+
maxBlocksPerCheckpoint: this.timetable.maxNumberOfBlocks,
|
|
1327
|
+
perBlockAllocationMultiplier: this.config.perBlockAllocationMultiplier
|
|
399
1328
|
};
|
|
400
|
-
// Actually build the block by executing txs
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
const
|
|
1329
|
+
// Actually build the block by executing txs. The builder throws InsufficientValidTxsError
|
|
1330
|
+
// if the number of successfully processed txs is below minValidTxs, ensuring state is not
|
|
1331
|
+
// updated for blocks that will be discarded.
|
|
1332
|
+
const buildResult = await this.buildSingleBlockWithCheckpointBuilder(checkpointBuilder, pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
|
|
404
1333
|
// If any txs failed during execution, drop them from the mempool so we don't pick them up again
|
|
405
|
-
await this.dropFailedTxsFromP2P(failedTxs);
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
slot: this.slot,
|
|
1334
|
+
await this.dropFailedTxsFromP2P(buildResult.failedTxs);
|
|
1335
|
+
if (buildResult.status === 'insufficient-valid-txs') {
|
|
1336
|
+
this.logCheckpointEvent('block-build-failed', `Block build failed for slot ${this.targetSlot}`, {
|
|
1337
|
+
reason: 'insufficient_valid_txs',
|
|
1338
|
+
slot: this.targetSlot,
|
|
1339
|
+
checkpointNumber: this.checkpointNumber,
|
|
412
1340
|
blockNumber,
|
|
413
|
-
numTxs,
|
|
414
|
-
indexWithinCheckpoint
|
|
1341
|
+
numTxs: buildResult.processedCount,
|
|
1342
|
+
indexWithinCheckpoint,
|
|
1343
|
+
minValidTxs
|
|
415
1344
|
});
|
|
416
|
-
this.
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
1345
|
+
this.log.warn(`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.targetSlot} has too few valid txs to be proposed`, {
|
|
1346
|
+
reason: 'insufficient_valid_txs',
|
|
1347
|
+
slot: this.targetSlot,
|
|
1348
|
+
checkpointNumber: this.checkpointNumber,
|
|
1349
|
+
blockNumber,
|
|
1350
|
+
numTxs: buildResult.processedCount,
|
|
1351
|
+
indexWithinCheckpoint,
|
|
1352
|
+
minValidTxs
|
|
1353
|
+
});
|
|
1354
|
+
this.eventEmitter.emit('block-build-failed', {
|
|
1355
|
+
reason: `Insufficient valid txs`,
|
|
1356
|
+
slot: this.targetSlot
|
|
420
1357
|
});
|
|
421
1358
|
this.metrics.recordBlockProposalFailed('insufficient_valid_txs');
|
|
422
|
-
return
|
|
1359
|
+
return {
|
|
1360
|
+
failure: 'insufficient-valid-txs'
|
|
1361
|
+
};
|
|
423
1362
|
}
|
|
424
1363
|
// Block creation succeeded, emit stats and metrics
|
|
1364
|
+
const { block, publicProcessorDuration, usedTxs, blockBuildDuration, numTxs } = buildResult;
|
|
425
1365
|
const blockStats = {
|
|
426
1366
|
eventName: 'l2-block-built',
|
|
427
1367
|
duration: blockBuildDuration,
|
|
428
1368
|
publicProcessDuration: publicProcessorDuration,
|
|
429
|
-
rollupCircuitsDuration: blockBuildingTimer.ms(),
|
|
430
1369
|
...block.getStats()
|
|
431
1370
|
};
|
|
432
1371
|
const blockHash = await block.hash();
|
|
433
1372
|
const txHashes = block.body.txEffects.map((tx)=>tx.txHash);
|
|
434
|
-
const manaPerSec =
|
|
435
|
-
this.log.info(`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.
|
|
1373
|
+
const manaPerSec = block.header.totalManaUsed.toNumberUnsafe() / (blockBuildDuration / 1000);
|
|
1374
|
+
this.log.info(`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.targetSlot} with ${numTxs} txs`, {
|
|
436
1375
|
blockHash,
|
|
437
1376
|
txHashes,
|
|
438
1377
|
manaPerSec,
|
|
439
1378
|
...blockStats
|
|
440
1379
|
});
|
|
1380
|
+
// `slot` is the target/submission slot (may be one ahead when pipelining),
|
|
1381
|
+
// `buildSlot` is the wall-clock slot during which the block was actually built.
|
|
441
1382
|
this.eventEmitter.emit('block-proposed', {
|
|
442
1383
|
blockNumber: block.number,
|
|
443
|
-
|
|
1384
|
+
blockHash,
|
|
1385
|
+
checkpointNumber: this.checkpointNumber,
|
|
1386
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
1387
|
+
slot: this.targetSlot,
|
|
1388
|
+
buildSlot: this.slotNow
|
|
444
1389
|
});
|
|
445
|
-
this.metrics.recordBuiltBlock(blockBuildDuration,
|
|
1390
|
+
this.metrics.recordBuiltBlock(blockBuildDuration, block.header.totalManaUsed.toNumberUnsafe(), this.targetSlot);
|
|
446
1391
|
return {
|
|
447
1392
|
block,
|
|
448
1393
|
usedTxs
|
|
@@ -450,11 +1395,19 @@ import { SequencerState } from './utils.js';
|
|
|
450
1395
|
} catch (err) {
|
|
451
1396
|
this.eventEmitter.emit('block-build-failed', {
|
|
452
1397
|
reason: err.message,
|
|
453
|
-
slot: this.
|
|
1398
|
+
slot: this.targetSlot
|
|
1399
|
+
});
|
|
1400
|
+
this.logCheckpointEvent('block-build-failed', `Block build failed for slot ${this.targetSlot}`, {
|
|
1401
|
+
reason: err instanceof Error ? err.message : String(err),
|
|
1402
|
+
slot: this.targetSlot,
|
|
1403
|
+
checkpointNumber: this.checkpointNumber,
|
|
1404
|
+
blockNumber
|
|
454
1405
|
});
|
|
455
1406
|
this.log.error(`Error building block`, err, {
|
|
456
|
-
|
|
457
|
-
slot: this.
|
|
1407
|
+
reason: err instanceof Error ? err.message : String(err),
|
|
1408
|
+
slot: this.targetSlot,
|
|
1409
|
+
checkpointNumber: this.checkpointNumber,
|
|
1410
|
+
blockNumber
|
|
458
1411
|
});
|
|
459
1412
|
this.metrics.recordBlockProposalFailed(err.name || 'unknown_error');
|
|
460
1413
|
this.metrics.recordFailedBlock();
|
|
@@ -463,9 +1416,31 @@ import { SequencerState } from './utils.js';
|
|
|
463
1416
|
};
|
|
464
1417
|
}
|
|
465
1418
|
}
|
|
1419
|
+
/** Uses the checkpoint builder to build a block, catching InsufficientValidTxsError. */ async buildSingleBlockWithCheckpointBuilder(checkpointBuilder, pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions) {
|
|
1420
|
+
try {
|
|
1421
|
+
const workTimer = new Timer();
|
|
1422
|
+
const result = await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
|
|
1423
|
+
const blockBuildDuration = workTimer.ms();
|
|
1424
|
+
return {
|
|
1425
|
+
...result,
|
|
1426
|
+
blockBuildDuration,
|
|
1427
|
+
status: 'success'
|
|
1428
|
+
};
|
|
1429
|
+
} catch (err) {
|
|
1430
|
+
if (isErrorClass(err, InsufficientValidTxsError)) {
|
|
1431
|
+
return {
|
|
1432
|
+
failedTxs: err.failedTxs,
|
|
1433
|
+
processedCount: err.processedCount,
|
|
1434
|
+
status: 'insufficient-valid-txs'
|
|
1435
|
+
};
|
|
1436
|
+
}
|
|
1437
|
+
throw err;
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
466
1440
|
/** Waits until minTxs are available on the pool for building a block. */ async waitForMinTxs(opts) {
|
|
467
|
-
const minTxs = this.config.minTxsPerBlock;
|
|
468
1441
|
const { indexWithinCheckpoint, blockNumber, buildDeadline, forceCreate } = opts;
|
|
1442
|
+
// We only allow a block with 0 txs in the first block of the checkpoint
|
|
1443
|
+
const minTxs = indexWithinCheckpoint > 0 && this.config.minTxsPerBlock === 0 ? 1 : this.config.minTxsPerBlock;
|
|
469
1444
|
// Deadline is undefined if we are not enforcing the timetable, meaning we'll exit immediately when out of time
|
|
470
1445
|
const startBuildingDeadline = buildDeadline ? new Date(buildDeadline.getTime() - this.timetable.minExecutionTime * 1000) : undefined;
|
|
471
1446
|
let availableTxs = await this.p2pClient.getPendingTxCount();
|
|
@@ -475,31 +1450,57 @@ import { SequencerState } from './utils.js';
|
|
|
475
1450
|
if (startBuildingDeadline === undefined || now >= startBuildingDeadline) {
|
|
476
1451
|
return {
|
|
477
1452
|
canStartBuilding: false,
|
|
478
|
-
availableTxs
|
|
1453
|
+
availableTxs,
|
|
1454
|
+
minTxs
|
|
479
1455
|
};
|
|
480
1456
|
}
|
|
481
1457
|
// Wait a bit before checking again
|
|
482
|
-
this.setStateFn(SequencerState.WAITING_FOR_TXS, this.
|
|
483
|
-
this.log.verbose(`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.
|
|
1458
|
+
this.setStateFn(SequencerState.WAITING_FOR_TXS, this.targetSlot);
|
|
1459
|
+
this.log.verbose(`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.targetSlot} (have ${availableTxs} but need ${minTxs})`, {
|
|
484
1460
|
blockNumber,
|
|
485
|
-
slot: this.
|
|
1461
|
+
slot: this.targetSlot,
|
|
486
1462
|
indexWithinCheckpoint
|
|
487
1463
|
});
|
|
488
|
-
await
|
|
1464
|
+
await this.waitForTxsPollingInterval();
|
|
489
1465
|
availableTxs = await this.p2pClient.getPendingTxCount();
|
|
490
1466
|
}
|
|
491
1467
|
return {
|
|
492
1468
|
canStartBuilding: true,
|
|
493
|
-
availableTxs
|
|
1469
|
+
availableTxs,
|
|
1470
|
+
minTxs
|
|
494
1471
|
};
|
|
495
1472
|
}
|
|
1473
|
+
async getSignedCommitteeAttestations(broadcast) {
|
|
1474
|
+
const { proposal, blockProposedAt } = broadcast;
|
|
1475
|
+
this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.targetSlot);
|
|
1476
|
+
const attestations = await this.waitForAttestations(proposal);
|
|
1477
|
+
if (!attestations) {
|
|
1478
|
+
return undefined;
|
|
1479
|
+
}
|
|
1480
|
+
this.checkpointMetrics.recordCheckpointAttestationDelay(this.dateProvider.now() - blockProposedAt);
|
|
1481
|
+
// Proposer must sign over the attestations before pushing them to L1
|
|
1482
|
+
const signer = this.proposer ?? this.publisher.getSenderAddress();
|
|
1483
|
+
try {
|
|
1484
|
+
const attestationsSignature = await this.validatorClient.signAttestationsAndSigners(attestations, signer, this.targetSlot, this.checkpointNumber);
|
|
1485
|
+
return {
|
|
1486
|
+
attestations,
|
|
1487
|
+
attestationsSignature
|
|
1488
|
+
};
|
|
1489
|
+
} catch (err) {
|
|
1490
|
+
if (this.handleHASigningError(err, 'Attestations signature')) {
|
|
1491
|
+
return;
|
|
1492
|
+
}
|
|
1493
|
+
this.log.error(`Error signing attestations for checkpoint proposal at slot ${proposal.slotNumber}`, err);
|
|
1494
|
+
return undefined;
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
496
1497
|
/**
|
|
497
1498
|
* Waits for enough attestations to be collected via p2p.
|
|
498
1499
|
* This is run after all blocks for the checkpoint have been built.
|
|
499
1500
|
*/ async waitForAttestations(proposal) {
|
|
500
1501
|
if (this.config.fishermanMode) {
|
|
501
1502
|
this.log.debug('Skipping attestation collection in fisherman mode');
|
|
502
|
-
return CommitteeAttestationsAndSigners.empty();
|
|
1503
|
+
return CommitteeAttestationsAndSigners.empty(this.getSignatureContext());
|
|
503
1504
|
}
|
|
504
1505
|
const slotNumber = proposal.slotNumber;
|
|
505
1506
|
const { committee, seed, epoch } = await this.epochCache.getCommittee(slotNumber);
|
|
@@ -507,49 +1508,91 @@ import { SequencerState } from './utils.js';
|
|
|
507
1508
|
throw new Error('No committee when collecting attestations');
|
|
508
1509
|
} else if (committee.length === 0) {
|
|
509
1510
|
this.log.verbose(`Attesting committee is empty`);
|
|
510
|
-
return CommitteeAttestationsAndSigners.empty();
|
|
1511
|
+
return CommitteeAttestationsAndSigners.empty(this.getSignatureContext());
|
|
511
1512
|
} else {
|
|
512
1513
|
this.log.debug(`Attesting committee length is ${committee.length}`, {
|
|
513
1514
|
committee
|
|
514
1515
|
});
|
|
515
1516
|
}
|
|
516
|
-
const numberOfRequiredAttestations =
|
|
1517
|
+
const numberOfRequiredAttestations = computeQuorum(committee.length);
|
|
517
1518
|
if (this.config.skipCollectingAttestations) {
|
|
518
1519
|
this.log.warn('Skipping attestation collection as per config (attesting with own keys only)');
|
|
519
|
-
const attestations = await this.validatorClient?.collectOwnAttestations(proposal);
|
|
520
|
-
|
|
1520
|
+
const attestations = await this.validatorClient?.collectOwnAttestations(proposal, this.checkpointNumber);
|
|
1521
|
+
this.logCheckpointAttestations('collected', committee, attestations ?? [], numberOfRequiredAttestations, {
|
|
1522
|
+
reason: 'collect_own_only'
|
|
1523
|
+
});
|
|
1524
|
+
return new CommitteeAttestationsAndSigners(orderAttestations(attestations ?? [], committee), this.getSignatureContext());
|
|
521
1525
|
}
|
|
522
|
-
const attestationTimeAllowed = this.config.enforceTimeTable ? this.timetable.
|
|
523
|
-
const attestationDeadline = new Date(this.
|
|
1526
|
+
const attestationTimeAllowed = this.config.enforceTimeTable ? this.timetable.getCheckpointAttestationDeadline() : this.l1Constants.slotDuration;
|
|
1527
|
+
const attestationDeadline = new Date((this.getSlotStartBuildTimestamp() + attestationTimeAllowed) * 1000);
|
|
524
1528
|
this.metrics.recordRequiredAttestations(numberOfRequiredAttestations, attestationTimeAllowed);
|
|
525
1529
|
const collectAttestationsTimer = new Timer();
|
|
526
1530
|
let collectedAttestationsCount = 0;
|
|
527
1531
|
try {
|
|
528
|
-
const attestations = await this.validatorClient.collectAttestations(proposal, numberOfRequiredAttestations, attestationDeadline);
|
|
1532
|
+
const attestations = await this.validatorClient.collectAttestations(proposal, numberOfRequiredAttestations, attestationDeadline, this.checkpointNumber);
|
|
529
1533
|
collectedAttestationsCount = attestations.length;
|
|
1534
|
+
// Trim attestations to minimum required to save L1 calldata gas
|
|
1535
|
+
const localAddresses = this.validatorClient.getValidatorAddresses();
|
|
1536
|
+
const trimmed = trimAttestations(attestations, numberOfRequiredAttestations, this.attestorAddress, localAddresses);
|
|
1537
|
+
if (trimmed.length < attestations.length) {
|
|
1538
|
+
this.log.debug(`Trimmed attestations from ${attestations.length} to ${trimmed.length} for L1 submission`);
|
|
1539
|
+
}
|
|
530
1540
|
// Rollup contract requires that the signatures are provided in the order of the committee
|
|
531
|
-
const sorted = orderAttestations(
|
|
1541
|
+
const sorted = orderAttestations(trimmed, committee);
|
|
1542
|
+
this.logCheckpointAttestations('collected', committee, attestations, numberOfRequiredAttestations, {
|
|
1543
|
+
submittedCount: trimmed.length
|
|
1544
|
+
});
|
|
532
1545
|
// Manipulate the attestations if we've been configured to do so
|
|
533
|
-
if (this.config.injectFakeAttestation || this.config.shuffleAttestationOrdering) {
|
|
534
|
-
|
|
535
|
-
return this.manipulateAttestations(checkpoint, epoch, seed, committee, sorted);
|
|
1546
|
+
if (this.config.injectFakeAttestation || this.config.injectHighSValueAttestation || this.config.injectUnrecoverableSignatureAttestation || this.config.shuffleAttestationOrdering) {
|
|
1547
|
+
return this.manipulateAttestations(proposal.slotNumber, epoch, seed, committee, sorted);
|
|
536
1548
|
}
|
|
537
|
-
return new CommitteeAttestationsAndSigners(sorted);
|
|
1549
|
+
return new CommitteeAttestationsAndSigners(sorted, this.getSignatureContext());
|
|
538
1550
|
} catch (err) {
|
|
539
1551
|
if (err && err instanceof AttestationTimeoutError) {
|
|
540
1552
|
collectedAttestationsCount = err.collectedCount;
|
|
1553
|
+
this.logCheckpointAttestations('failed', committee, undefined, numberOfRequiredAttestations, {
|
|
1554
|
+
collectedCount: collectedAttestationsCount,
|
|
1555
|
+
reason: 'timeout'
|
|
1556
|
+
});
|
|
1557
|
+
this.log.error(`Timeout while waiting for attestations for checkpoint proposal at slot ${proposal.slotNumber} (collected ${collectedAttestationsCount}/${numberOfRequiredAttestations})`, err);
|
|
1558
|
+
} else {
|
|
1559
|
+
this.logCheckpointAttestations('failed', committee, undefined, numberOfRequiredAttestations, {
|
|
1560
|
+
collectedCount: collectedAttestationsCount,
|
|
1561
|
+
reason: err instanceof Error ? err.message : String(err)
|
|
1562
|
+
});
|
|
1563
|
+
this.log.error(`Error collecting attestations for checkpoint proposal at slot ${proposal.slotNumber}`, err);
|
|
541
1564
|
}
|
|
542
|
-
|
|
1565
|
+
return undefined;
|
|
543
1566
|
} finally{
|
|
544
1567
|
this.metrics.recordCollectedAttestations(collectedAttestationsCount, collectAttestationsTimer.ms());
|
|
545
1568
|
}
|
|
546
1569
|
}
|
|
547
|
-
|
|
1570
|
+
logCheckpointAttestations(status, committee, attestations, requiredAttestations, opts = {}) {
|
|
1571
|
+
const signedValidators = attestations?.map((attestation)=>attestation.getSender()?.toString()).filter((address)=>address !== undefined) ?? [];
|
|
1572
|
+
const collectedCount = opts.collectedCount ?? new Set(signedValidators).size;
|
|
1573
|
+
const missingValidatorCount = status === 'failed' ? Math.max(0, requiredAttestations - collectedCount) : undefined;
|
|
1574
|
+
this.logCheckpointEvent(`attestations-${status}`, `Checkpoint attestations ${status} for slot ${this.targetSlot}`, {
|
|
1575
|
+
slot: this.targetSlot,
|
|
1576
|
+
checkpointNumber: this.checkpointNumber,
|
|
1577
|
+
committeeSize: committee.length,
|
|
1578
|
+
requiredAttestations,
|
|
1579
|
+
collectedAttestations: collectedCount,
|
|
1580
|
+
...opts.submittedCount !== undefined && {
|
|
1581
|
+
submittedAttestations: opts.submittedCount
|
|
1582
|
+
},
|
|
1583
|
+
...missingValidatorCount !== undefined && {
|
|
1584
|
+
missingValidatorCount
|
|
1585
|
+
},
|
|
1586
|
+
...opts.reason !== undefined && {
|
|
1587
|
+
reason: opts.reason
|
|
1588
|
+
}
|
|
1589
|
+
});
|
|
1590
|
+
}
|
|
1591
|
+
/** Breaks the attestations before publishing based on attack configs */ manipulateAttestations(slotNumber, epoch, seed, committee, attestations) {
|
|
548
1592
|
// Compute the proposer index in the committee, since we dont want to tweak it.
|
|
549
1593
|
// Otherwise, the L1 rollup contract will reject the block outright.
|
|
550
|
-
const { slotNumber } = checkpoint;
|
|
551
1594
|
const proposerIndex = Number(this.epochCache.computeProposerIndex(slotNumber, epoch, seed, BigInt(committee.length)));
|
|
552
|
-
if (this.config.injectFakeAttestation) {
|
|
1595
|
+
if (this.config.injectFakeAttestation || this.config.injectHighSValueAttestation || this.config.injectUnrecoverableSignatureAttestation) {
|
|
553
1596
|
// Find non-empty attestations that are not from the proposer
|
|
554
1597
|
const nonProposerIndices = [];
|
|
555
1598
|
for(let i = 0; i < attestations.length; i++){
|
|
@@ -559,28 +1602,47 @@ import { SequencerState } from './utils.js';
|
|
|
559
1602
|
}
|
|
560
1603
|
if (nonProposerIndices.length > 0) {
|
|
561
1604
|
const targetIndex = nonProposerIndices[randomInt(nonProposerIndices.length)];
|
|
562
|
-
this.
|
|
563
|
-
|
|
1605
|
+
if (this.config.injectHighSValueAttestation) {
|
|
1606
|
+
this.log.warn(`Injecting high-s value attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
|
|
1607
|
+
unfreeze(attestations[targetIndex]).signature = flipSignature(attestations[targetIndex].signature);
|
|
1608
|
+
} else if (this.config.injectUnrecoverableSignatureAttestation) {
|
|
1609
|
+
this.log.warn(`Injecting unrecoverable signature attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
|
|
1610
|
+
unfreeze(attestations[targetIndex]).signature = generateUnrecoverableSignature();
|
|
1611
|
+
} else {
|
|
1612
|
+
this.log.warn(`Injecting fake attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
|
|
1613
|
+
unfreeze(attestations[targetIndex]).signature = generateRecoverableSignature();
|
|
1614
|
+
}
|
|
564
1615
|
}
|
|
565
|
-
return new CommitteeAttestationsAndSigners(attestations);
|
|
1616
|
+
return new CommitteeAttestationsAndSigners(attestations, this.getSignatureContext());
|
|
566
1617
|
}
|
|
567
1618
|
if (this.config.shuffleAttestationOrdering) {
|
|
568
1619
|
this.log.warn(`Shuffling attestation ordering in checkpoint for slot ${slotNumber} (proposer #${proposerIndex})`);
|
|
569
1620
|
const shuffled = [
|
|
570
1621
|
...attestations
|
|
571
1622
|
];
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
];
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
1623
|
+
// Find two non-proposer positions that both have non-empty signatures to swap.
|
|
1624
|
+
// This ensures the bitmap doesn't change, so the MaliciousCommitteeAttestationsAndSigners
|
|
1625
|
+
// signers array stays correctly aligned with L1's committee reconstruction.
|
|
1626
|
+
const swappable = [];
|
|
1627
|
+
for(let k = 0; k < shuffled.length; k++){
|
|
1628
|
+
if (!shuffled[k].signature.isEmpty() && k !== proposerIndex) {
|
|
1629
|
+
swappable.push(k);
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
if (swappable.length >= 2) {
|
|
1633
|
+
const [i, j] = [
|
|
1634
|
+
swappable[0],
|
|
1635
|
+
swappable[1]
|
|
1636
|
+
];
|
|
1637
|
+
[shuffled[i], shuffled[j]] = [
|
|
1638
|
+
shuffled[j],
|
|
1639
|
+
shuffled[i]
|
|
1640
|
+
];
|
|
1641
|
+
}
|
|
1642
|
+
const signers = new CommitteeAttestationsAndSigners(attestations, this.getSignatureContext()).getSigners();
|
|
1643
|
+
return new MaliciousCommitteeAttestationsAndSigners(shuffled, signers, this.getSignatureContext());
|
|
582
1644
|
}
|
|
583
|
-
return new CommitteeAttestationsAndSigners(attestations);
|
|
1645
|
+
return new CommitteeAttestationsAndSigners(attestations, this.getSignatureContext());
|
|
584
1646
|
}
|
|
585
1647
|
async dropFailedTxsFromP2P(failedTxs) {
|
|
586
1648
|
if (failedTxs.length === 0) {
|
|
@@ -589,46 +1651,112 @@ import { SequencerState } from './utils.js';
|
|
|
589
1651
|
const failedTxData = failedTxs.map((fail)=>fail.tx);
|
|
590
1652
|
const failedTxHashes = failedTxData.map((tx)=>tx.getTxHash());
|
|
591
1653
|
this.log.verbose(`Dropping failed txs ${failedTxHashes.join(', ')}`);
|
|
592
|
-
await this.p2pClient.
|
|
1654
|
+
await this.p2pClient.handleFailedExecution(failedTxHashes);
|
|
593
1655
|
}
|
|
594
1656
|
/**
|
|
595
|
-
*
|
|
596
|
-
*
|
|
1657
|
+
* Adds the proposed block to the archiver so it's available via P2P.
|
|
1658
|
+
* Gossip doesn't echo messages back to the sender, so the proposer's archiver/world-state
|
|
1659
|
+
* would never receive its own block without this explicit sync.
|
|
1660
|
+
*
|
|
1661
|
+
* In fisherman mode we skip this push: the fisherman builds blocks locally for validation
|
|
1662
|
+
* and fee analysis only, and pushing them to the archiver causes spurious reorg cascades
|
|
1663
|
+
* whenever the real proposer's block arrives from L1.
|
|
597
1664
|
*/ async syncProposedBlockToArchiver(block) {
|
|
598
|
-
this.
|
|
1665
|
+
if (this.config.skipPushProposedBlocksToArchiver || this.config.fishermanMode) {
|
|
1666
|
+
this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
|
|
1667
|
+
blockNumber: block.number,
|
|
1668
|
+
slot: block.header.globalVariables.slotNumber
|
|
1669
|
+
});
|
|
1670
|
+
return;
|
|
1671
|
+
}
|
|
1672
|
+
this.log.debug(`Syncing proposed block ${block.number} to archiver`, {
|
|
599
1673
|
blockNumber: block.number,
|
|
600
1674
|
slot: block.header.globalVariables.slotNumber
|
|
601
1675
|
});
|
|
602
|
-
|
|
603
|
-
|
|
1676
|
+
await this.blockSink.addBlock(block);
|
|
1677
|
+
}
|
|
1678
|
+
/**
|
|
1679
|
+
* Adds the proposed checkpoint to the archiver so the proposer's optimistic proposed-checkpoint
|
|
1680
|
+
* tip advances locally. Gossip doesn't echo our own messages back, so without this the proposer
|
|
1681
|
+
* would never see its own proposed checkpoint and couldn't pipeline the next slot.
|
|
1682
|
+
*
|
|
1683
|
+
* Only runs under proposer pipelining (the proposed tip is a pipelining-only concept) and is
|
|
1684
|
+
* skipped whenever proposed blocks aren't pushed (`skipPushProposedBlocksToArchiver`, fisherman
|
|
1685
|
+
* mode): the archiver derives the checkpoint archive from its stored blocks, so without them the
|
|
1686
|
+
* push would fail. All blocks were already added (and awaited) during block building, so this
|
|
1687
|
+
* needs no retry — they are guaranteed present by the time we get here.
|
|
1688
|
+
*/ async syncProposedCheckpointToArchiver(checkpoint, blockCount, feeAssetPriceModifier) {
|
|
1689
|
+
if (this.config.skipPushProposedBlocksToArchiver || this.config.fishermanMode) {
|
|
1690
|
+
return;
|
|
1691
|
+
}
|
|
1692
|
+
if (!this.epochCache.isProposerPipeliningEnabled()) {
|
|
1693
|
+
return;
|
|
1694
|
+
}
|
|
1695
|
+
const startBlock = BlockNumber(this.syncedToBlockNumber + 1);
|
|
1696
|
+
this.log.debug(`Syncing proposed checkpoint ${this.checkpointNumber} to archiver`, {
|
|
1697
|
+
checkpointNumber: this.checkpointNumber,
|
|
1698
|
+
slot: this.targetSlot,
|
|
1699
|
+
startBlock,
|
|
1700
|
+
blockCount
|
|
1701
|
+
});
|
|
1702
|
+
await this.blockSink.addProposedCheckpoint({
|
|
1703
|
+
header: checkpoint.header,
|
|
1704
|
+
checkpointNumber: this.checkpointNumber,
|
|
1705
|
+
startBlock,
|
|
1706
|
+
blockCount,
|
|
1707
|
+
totalManaUsed: checkpoint.header.totalManaUsed.toBigInt(),
|
|
1708
|
+
feeAssetPriceModifier
|
|
1709
|
+
});
|
|
604
1710
|
}
|
|
605
1711
|
/** Runs fee analysis and logs checkpoint outcome as fisherman */ async handleCheckpointEndAsFisherman(checkpoint) {
|
|
606
1712
|
// Perform L1 fee analysis before clearing requests
|
|
607
1713
|
// The callback is invoked asynchronously after the next block is mined
|
|
608
|
-
const feeAnalysis = await this.publisher.analyzeL1Fees(this.
|
|
1714
|
+
const feeAnalysis = await this.publisher.analyzeL1Fees(this.targetSlot, (analysis)=>this.metrics.recordFishermanFeeAnalysis(analysis));
|
|
609
1715
|
if (checkpoint) {
|
|
610
|
-
this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.
|
|
1716
|
+
this.log.info(`Validation checkpoint building SUCCEEDED for slot ${this.targetSlot}`, {
|
|
611
1717
|
...checkpoint.toCheckpointInfo(),
|
|
612
1718
|
...checkpoint.getStats(),
|
|
613
1719
|
feeAnalysisId: feeAnalysis?.id
|
|
614
1720
|
});
|
|
615
|
-
this.metrics.recordBlockProposalSuccess();
|
|
616
1721
|
} else {
|
|
617
|
-
this.log.warn(`Validation block building FAILED for slot ${this.
|
|
618
|
-
slot: this.
|
|
1722
|
+
this.log.warn(`Validation block building FAILED for slot ${this.targetSlot}`, {
|
|
1723
|
+
slot: this.targetSlot,
|
|
619
1724
|
feeAnalysisId: feeAnalysis?.id
|
|
620
1725
|
});
|
|
621
|
-
this.metrics.
|
|
1726
|
+
this.metrics.recordCheckpointProposalFailed('block_build_failed');
|
|
622
1727
|
}
|
|
623
1728
|
this.publisher.clearPendingRequests();
|
|
624
1729
|
}
|
|
1730
|
+
/**
|
|
1731
|
+
* Helper to handle HA double-signing errors. Returns true if the error was handled (caller should yield).
|
|
1732
|
+
*/ handleHASigningError(err, errorContext) {
|
|
1733
|
+
if (err instanceof DutyAlreadySignedError) {
|
|
1734
|
+
this.log.info(`${errorContext} for slot ${this.targetSlot} already signed by another HA node, yielding`, {
|
|
1735
|
+
slot: this.targetSlot,
|
|
1736
|
+
signedByNode: err.signedByNode
|
|
1737
|
+
});
|
|
1738
|
+
return true;
|
|
1739
|
+
}
|
|
1740
|
+
if (err instanceof SlashingProtectionError) {
|
|
1741
|
+
this.log.info(`${errorContext} for slot ${this.targetSlot} blocked by slashing protection, yielding`, {
|
|
1742
|
+
slot: this.targetSlot,
|
|
1743
|
+
existingMessageHash: err.existingMessageHash,
|
|
1744
|
+
attemptedMessageHash: err.attemptedMessageHash
|
|
1745
|
+
});
|
|
1746
|
+
return true;
|
|
1747
|
+
}
|
|
1748
|
+
return false;
|
|
1749
|
+
}
|
|
625
1750
|
/** Waits until a specific time within the current slot */ async waitUntilTimeInSlot(targetSecondsIntoSlot) {
|
|
626
1751
|
const slotStartTimestamp = this.getSlotStartBuildTimestamp();
|
|
627
1752
|
const targetTimestamp = slotStartTimestamp + targetSecondsIntoSlot;
|
|
628
1753
|
await sleepUntil(new Date(targetTimestamp * 1000), this.dateProvider.nowAsDate());
|
|
629
1754
|
}
|
|
1755
|
+
/** Waits the polling interval for transactions. Extracted for test overriding. */ async waitForTxsPollingInterval() {
|
|
1756
|
+
await sleep(TXS_POLLING_MS);
|
|
1757
|
+
}
|
|
630
1758
|
getSlotStartBuildTimestamp() {
|
|
631
|
-
return getSlotStartBuildTimestamp(this.
|
|
1759
|
+
return getSlotStartBuildTimestamp(this.slotNow, this.l1Constants);
|
|
632
1760
|
}
|
|
633
1761
|
getSecondsIntoSlot() {
|
|
634
1762
|
const slotStartTimestamp = this.getSlotStartBuildTimestamp();
|