@aztec/sequencer-client 0.0.1-commit.03f7ef2 → 0.0.1-commit.04852196a

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.
Files changed (106) hide show
  1. package/dest/client/sequencer-client.d.ts +26 -11
  2. package/dest/client/sequencer-client.d.ts.map +1 -1
  3. package/dest/client/sequencer-client.js +99 -16
  4. package/dest/config.d.ts +24 -6
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +45 -28
  7. package/dest/global_variable_builder/global_builder.d.ts +5 -7
  8. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  9. package/dest/global_variable_builder/global_builder.js +13 -13
  10. package/dest/index.d.ts +2 -3
  11. package/dest/index.d.ts.map +1 -1
  12. package/dest/index.js +1 -2
  13. package/dest/publisher/config.d.ts +35 -17
  14. package/dest/publisher/config.d.ts.map +1 -1
  15. package/dest/publisher/config.js +106 -42
  16. package/dest/publisher/index.d.ts +2 -1
  17. package/dest/publisher/index.d.ts.map +1 -1
  18. package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
  19. package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
  20. package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
  21. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +59 -0
  22. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
  23. package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
  24. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
  25. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
  26. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
  27. package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
  28. package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
  29. package/dest/publisher/l1_tx_failed_store/index.js +2 -0
  30. package/dest/publisher/sequencer-publisher-factory.d.ts +12 -4
  31. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  32. package/dest/publisher/sequencer-publisher-factory.js +27 -2
  33. package/dest/publisher/sequencer-publisher-metrics.d.ts +1 -1
  34. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  35. package/dest/publisher/sequencer-publisher-metrics.js +23 -86
  36. package/dest/publisher/sequencer-publisher.d.ts +44 -25
  37. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  38. package/dest/publisher/sequencer-publisher.js +781 -101
  39. package/dest/sequencer/checkpoint_proposal_job.d.ts +39 -13
  40. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  41. package/dest/sequencer/checkpoint_proposal_job.js +683 -79
  42. package/dest/sequencer/checkpoint_voter.d.ts +3 -2
  43. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
  44. package/dest/sequencer/checkpoint_voter.js +34 -10
  45. package/dest/sequencer/index.d.ts +1 -3
  46. package/dest/sequencer/index.d.ts.map +1 -1
  47. package/dest/sequencer/index.js +0 -2
  48. package/dest/sequencer/metrics.d.ts +19 -7
  49. package/dest/sequencer/metrics.d.ts.map +1 -1
  50. package/dest/sequencer/metrics.js +131 -141
  51. package/dest/sequencer/sequencer.d.ts +46 -23
  52. package/dest/sequencer/sequencer.d.ts.map +1 -1
  53. package/dest/sequencer/sequencer.js +514 -67
  54. package/dest/sequencer/timetable.d.ts +4 -6
  55. package/dest/sequencer/timetable.d.ts.map +1 -1
  56. package/dest/sequencer/timetable.js +7 -11
  57. package/dest/sequencer/types.d.ts +5 -2
  58. package/dest/sequencer/types.d.ts.map +1 -1
  59. package/dest/test/index.d.ts +4 -7
  60. package/dest/test/index.d.ts.map +1 -1
  61. package/dest/test/mock_checkpoint_builder.d.ts +28 -16
  62. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
  63. package/dest/test/mock_checkpoint_builder.js +86 -34
  64. package/dest/test/utils.d.ts +13 -9
  65. package/dest/test/utils.d.ts.map +1 -1
  66. package/dest/test/utils.js +27 -17
  67. package/package.json +30 -28
  68. package/src/client/sequencer-client.ts +139 -23
  69. package/src/config.ts +59 -38
  70. package/src/global_variable_builder/global_builder.ts +14 -14
  71. package/src/index.ts +1 -9
  72. package/src/publisher/config.ts +121 -43
  73. package/src/publisher/index.ts +3 -0
  74. package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
  75. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +55 -0
  76. package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
  77. package/src/publisher/l1_tx_failed_store/index.ts +3 -0
  78. package/src/publisher/sequencer-publisher-factory.ts +39 -7
  79. package/src/publisher/sequencer-publisher-metrics.ts +17 -69
  80. package/src/publisher/sequencer-publisher.ts +420 -137
  81. package/src/sequencer/checkpoint_proposal_job.ts +361 -104
  82. package/src/sequencer/checkpoint_voter.ts +32 -7
  83. package/src/sequencer/index.ts +0 -2
  84. package/src/sequencer/metrics.ts +132 -148
  85. package/src/sequencer/sequencer.ts +160 -69
  86. package/src/sequencer/timetable.ts +13 -12
  87. package/src/sequencer/types.ts +4 -1
  88. package/src/test/index.ts +3 -6
  89. package/src/test/mock_checkpoint_builder.ts +147 -71
  90. package/src/test/utils.ts +58 -28
  91. package/dest/sequencer/block_builder.d.ts +0 -26
  92. package/dest/sequencer/block_builder.d.ts.map +0 -1
  93. package/dest/sequencer/block_builder.js +0 -129
  94. package/dest/sequencer/checkpoint_builder.d.ts +0 -63
  95. package/dest/sequencer/checkpoint_builder.d.ts.map +0 -1
  96. package/dest/sequencer/checkpoint_builder.js +0 -131
  97. package/dest/tx_validator/nullifier_cache.d.ts +0 -14
  98. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  99. package/dest/tx_validator/nullifier_cache.js +0 -24
  100. package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
  101. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  102. package/dest/tx_validator/tx_validator_factory.js +0 -53
  103. package/src/sequencer/block_builder.ts +0 -217
  104. package/src/sequencer/checkpoint_builder.ts +0 -217
  105. package/src/tx_validator/nullifier_cache.ts +0 -30
  106. package/src/tx_validator/tx_validator_factory.ts +0 -133
@@ -63,42 +63,430 @@ function _ts_dispose_resources(env) {
63
63
  return next();
64
64
  })(env);
65
65
  }
66
- import { BLOBS_PER_CHECKPOINT, FIELDS_PER_BLOB } from '@aztec/constants';
67
- import { BlockNumber } from '@aztec/foundation/branded-types';
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, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
68
440
  import { randomInt } from '@aztec/foundation/crypto/random';
69
- import { Signature } from '@aztec/foundation/eth-signature';
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';
71
444
  import { sleep, sleepUntil } from '@aztec/foundation/sleep';
72
445
  import { Timer } from '@aztec/foundation/timer';
73
- import { unfreeze } from '@aztec/foundation/types';
446
+ import { isErrorClass, unfreeze } from '@aztec/foundation/types';
74
447
  import { CommitteeAttestationsAndSigners, MaliciousCommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
448
+ import { validateCheckpoint } from '@aztec/stdlib/checkpoint';
75
449
  import { getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
76
450
  import { Gas } from '@aztec/stdlib/gas';
77
- import { orderAttestations } from '@aztec/stdlib/p2p';
451
+ import { NoValidTxsError } from '@aztec/stdlib/interfaces/server';
452
+ import { computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
453
+ import { orderAttestations, trimAttestations } from '@aztec/stdlib/p2p';
78
454
  import { AttestationTimeoutError } from '@aztec/stdlib/validators';
455
+ import { Attributes, trackSpan } from '@aztec/telemetry-client';
456
+ import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validator-ha-signer/errors';
79
457
  import { CheckpointVoter } from './checkpoint_voter.js';
80
458
  import { SequencerInterruptedError } from './errors.js';
81
459
  import { SequencerState } from './utils.js';
82
460
  /** How much time to sleep while waiting for min transactions to accumulate for a block */ const TXS_POLLING_MS = 500;
461
+ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('CheckpointProposalJob.proposeCheckpoint', function() {
462
+ return {
463
+ // nullish operator needed for tests
464
+ [Attributes.COINBASE]: this.validatorClient.getCoinbaseForAttestor(this.attestorAddress)?.toString(),
465
+ [Attributes.SLOT_NUMBER]: this.slot
466
+ };
467
+ }), _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
468
  /**
84
469
  * Handles the execution of a checkpoint proposal after the initial preparation phase.
85
470
  * This includes building blocks, collecting attestations, and publishing the checkpoint to L1,
86
471
  * as well as enqueueing votes for slashing and governance proposals. This class is created from
87
472
  * the Sequencer once the check for being the proposer for the slot has succeeded.
88
473
  */ export class CheckpointProposalJob {
474
+ epoch;
89
475
  slot;
90
476
  checkpointNumber;
91
477
  syncedToBlockNumber;
92
478
  proposer;
93
479
  publisher;
94
480
  attestorAddress;
95
- invalidateBlock;
481
+ invalidateCheckpoint;
96
482
  validatorClient;
97
483
  globalsBuilder;
98
484
  p2pClient;
99
485
  worldState;
100
486
  l1ToL2MessageSource;
487
+ l2BlockSource;
101
488
  checkpointsBuilder;
489
+ blockSink;
102
490
  l1Constants;
103
491
  config;
104
492
  timetable;
@@ -108,22 +496,70 @@ import { SequencerState } from './utils.js';
108
496
  metrics;
109
497
  eventEmitter;
110
498
  setStateFn;
499
+ tracer;
500
+ static{
501
+ ({ e: [_initProto] } = _apply_decs_2203_r(this, [
502
+ [
503
+ _dec,
504
+ 2,
505
+ "execute"
506
+ ],
507
+ [
508
+ _dec1,
509
+ 2,
510
+ "proposeCheckpoint"
511
+ ],
512
+ [
513
+ _dec2,
514
+ 2,
515
+ "buildBlocksForCheckpoint"
516
+ ],
517
+ [
518
+ _dec3,
519
+ 2,
520
+ "waitUntilNextSubslot"
521
+ ],
522
+ [
523
+ _dec4,
524
+ 2,
525
+ "buildSingleBlock"
526
+ ],
527
+ [
528
+ _dec5,
529
+ 2,
530
+ "waitForMinTxs"
531
+ ],
532
+ [
533
+ _dec6,
534
+ 2,
535
+ "waitForAttestations"
536
+ ],
537
+ [
538
+ _dec7,
539
+ 2,
540
+ "waitUntilTimeInSlot"
541
+ ]
542
+ ], []));
543
+ }
111
544
  log;
112
- constructor(slot, checkpointNumber, syncedToBlockNumber, // TODO(palla/mbps): Can we remove the proposer in favor of attestorAddress? Need to check fisherman-node flows.
113
- proposer, publisher, attestorAddress, invalidateBlock, validatorClient, globalsBuilder, p2pClient, worldState, l1ToL2MessageSource, checkpointsBuilder, l1Constants, config, timetable, slasherClient, epochCache, dateProvider, metrics, eventEmitter, setStateFn, log){
545
+ constructor(epoch, slot, checkpointNumber, syncedToBlockNumber, // TODO(palla/mbps): Can we remove the proposer in favor of attestorAddress? Need to check fisherman-node flows.
546
+ proposer, publisher, attestorAddress, invalidateCheckpoint, validatorClient, globalsBuilder, p2pClient, worldState, l1ToL2MessageSource, l2BlockSource, checkpointsBuilder, blockSink, l1Constants, config, timetable, slasherClient, epochCache, dateProvider, metrics, eventEmitter, setStateFn, tracer, bindings){
547
+ this.epoch = epoch;
114
548
  this.slot = slot;
115
549
  this.checkpointNumber = checkpointNumber;
116
550
  this.syncedToBlockNumber = syncedToBlockNumber;
117
551
  this.proposer = proposer;
118
552
  this.publisher = publisher;
119
553
  this.attestorAddress = attestorAddress;
120
- this.invalidateBlock = invalidateBlock;
554
+ this.invalidateCheckpoint = invalidateCheckpoint;
121
555
  this.validatorClient = validatorClient;
122
556
  this.globalsBuilder = globalsBuilder;
123
557
  this.p2pClient = p2pClient;
124
558
  this.worldState = worldState;
125
559
  this.l1ToL2MessageSource = l1ToL2MessageSource;
560
+ this.l2BlockSource = l2BlockSource;
126
561
  this.checkpointsBuilder = checkpointsBuilder;
562
+ this.blockSink = blockSink;
127
563
  this.l1Constants = l1Constants;
128
564
  this.config = config;
129
565
  this.timetable = timetable;
@@ -133,7 +569,12 @@ import { SequencerState } from './utils.js';
133
569
  this.metrics = metrics;
134
570
  this.eventEmitter = eventEmitter;
135
571
  this.setStateFn = setStateFn;
136
- this.log = log;
572
+ this.tracer = tracer;
573
+ _initProto(this);
574
+ this.log = createLogger('sequencer:checkpoint-proposal', {
575
+ ...bindings,
576
+ instanceId: `slot-${slot}`
577
+ });
137
578
  }
138
579
  /**
139
580
  * Executes the checkpoint proposal job.
@@ -147,6 +588,9 @@ import { SequencerState } from './utils.js';
147
588
  const checkpoint = await this.proposeCheckpoint();
148
589
  // Wait until the voting promises have resolved, so all requests are enqueued (not sent)
149
590
  await Promise.all(votesPromises);
591
+ if (checkpoint) {
592
+ this.metrics.recordCheckpointProposalSuccess();
593
+ }
150
594
  // Do not post anything to L1 if we are fishermen, but do perform L1 fee analysis
151
595
  if (this.config.fishermanMode) {
152
596
  await this.handleCheckpointEndAsFisherman(checkpoint);
@@ -185,26 +629,50 @@ import { SequencerState } from './utils.js';
185
629
  // Start the checkpoint
186
630
  this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.slot);
187
631
  this.metrics.incOpenSlot(this.slot, this.proposer?.toString() ?? 'unknown');
188
- // Enqueues block invalidation (constant for the whole slot)
189
- if (this.invalidateBlock && !this.config.skipInvalidateBlockAsProposer) {
190
- this.publisher.enqueueInvalidateBlock(this.invalidateBlock);
632
+ // Enqueues checkpoint invalidation (constant for the whole slot)
633
+ if (this.invalidateCheckpoint && !this.config.skipInvalidateBlockAsProposer) {
634
+ this.publisher.enqueueInvalidateCheckpoint(this.invalidateCheckpoint);
191
635
  }
192
636
  // Create checkpoint builder for the slot
193
637
  const checkpointGlobalVariables = await this.globalsBuilder.buildCheckpointGlobalVariables(coinbase, feeRecipient, this.slot);
194
- // Collect L1 to L2 messages for the checkpoint
638
+ // Collect L1 to L2 messages for the checkpoint and compute their hash
195
639
  const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(this.checkpointNumber);
640
+ const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
641
+ // Collect the out hashes of all the checkpoints before this one in the same epoch
642
+ const previousCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(this.epoch)).filter((c)=>c.checkpointNumber < this.checkpointNumber).map((c)=>c.checkpointOutHash);
643
+ // Get the fee asset price modifier from the oracle
644
+ const feeAssetPriceModifier = await this.publisher.getFeeAssetPriceModifier();
196
645
  const fork = _ts_add_disposable_resource(env, await this.worldState.fork(this.syncedToBlockNumber, {
197
646
  closeDelayMs: 12_000
198
- }), false);
647
+ }), true);
199
648
  // Create checkpoint builder for the entire slot
200
- const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(this.checkpointNumber, checkpointGlobalVariables, l1ToL2Messages, fork);
649
+ const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(this.checkpointNumber, checkpointGlobalVariables, feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, this.log.getBindings());
201
650
  // Options for the validator client when creating block and checkpoint proposals
202
651
  const blockProposalOptions = {
203
652
  publishFullTxs: !!this.config.publishTxsWithProposals,
204
653
  broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
205
654
  };
206
- // Main loop: build blocks for the checkpoint
207
- const { blocksInCheckpoint, pendingBroadcast } = await this.buildBlocksForCheckpoint(checkpointBuilder, checkpointGlobalVariables.timestamp, blockProposalOptions);
655
+ const checkpointProposalOptions = {
656
+ publishFullTxs: !!this.config.publishTxsWithProposals,
657
+ broadcastInvalidCheckpointProposal: this.config.broadcastInvalidBlockProposal
658
+ };
659
+ let blocksInCheckpoint = [];
660
+ let blockPendingBroadcast = undefined;
661
+ const checkpointBuildTimer = new Timer();
662
+ try {
663
+ // Main loop: build blocks for the checkpoint
664
+ const result = await this.buildBlocksForCheckpoint(checkpointBuilder, checkpointGlobalVariables.timestamp, inHash, blockProposalOptions);
665
+ blocksInCheckpoint = result.blocksInCheckpoint;
666
+ blockPendingBroadcast = result.blockPendingBroadcast;
667
+ } catch (err) {
668
+ // These errors are expected in HA mode, so we yield and let another HA node handle the slot
669
+ // The only distinction between the 2 errors is SlashingProtectionError throws when the payload is different,
670
+ // which is normal for block building (may have picked different txs)
671
+ if (this.handleHASigningError(err, 'Block proposal')) {
672
+ return undefined;
673
+ }
674
+ throw err;
675
+ }
208
676
  if (blocksInCheckpoint.length === 0) {
209
677
  this.log.warn(`No blocks were built for slot ${this.slot}`, {
210
678
  slot: this.slot
@@ -214,10 +682,36 @@ import { SequencerState } from './utils.js';
214
682
  });
215
683
  return undefined;
216
684
  }
685
+ const minBlocksForCheckpoint = this.config.minBlocksForCheckpoint;
686
+ if (minBlocksForCheckpoint !== undefined && blocksInCheckpoint.length < minBlocksForCheckpoint) {
687
+ this.log.warn(`Checkpoint has fewer blocks than minimum (${blocksInCheckpoint.length} < ${minBlocksForCheckpoint}), skipping proposal`, {
688
+ slot: this.slot,
689
+ blocksBuilt: blocksInCheckpoint.length,
690
+ minBlocksForCheckpoint
691
+ });
692
+ return undefined;
693
+ }
217
694
  // Assemble and broadcast the checkpoint proposal, including the last block that was not
218
695
  // broadcasted yet, and wait to collect the committee attestations.
219
696
  this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.slot);
220
697
  const checkpoint = await checkpointBuilder.completeCheckpoint();
698
+ // Final validation round for the checkpoint before we propose it, just for safety
699
+ try {
700
+ validateCheckpoint(checkpoint, {
701
+ rollupManaLimit: this.l1Constants.rollupManaLimit,
702
+ maxL2BlockGas: this.config.maxL2BlockGas,
703
+ maxDABlockGas: this.config.maxDABlockGas,
704
+ maxTxsPerBlock: this.config.maxTxsPerBlock,
705
+ maxTxsPerCheckpoint: this.config.maxTxsPerCheckpoint
706
+ });
707
+ } catch (err) {
708
+ this.log.error(`Built an invalid checkpoint at slot ${this.slot} (skipping proposal)`, err, {
709
+ checkpoint: checkpoint.header.toInspect()
710
+ });
711
+ return undefined;
712
+ }
713
+ // Record checkpoint-level build metrics
714
+ this.metrics.recordCheckpointBuild(checkpointBuildTimer.ms(), blocksInCheckpoint.length, checkpoint.getStats().txCount, Number(checkpoint.header.totalManaUsed.toBigInt()));
221
715
  // Do not collect attestations nor publish to L1 in fisherman mode
222
716
  if (this.config.fishermanMode) {
223
717
  this.log.info(`Built checkpoint for slot ${this.slot} with ${blocksInCheckpoint.length} blocks. ` + `Skipping proposal in fisherman mode.`, {
@@ -228,49 +722,78 @@ import { SequencerState } from './utils.js';
228
722
  this.metrics.recordCheckpointSuccess();
229
723
  return checkpoint;
230
724
  }
231
- // TODO(palla/mbps): Wire this to the new p2p API once available, including the pendingBroadcast.block
232
- const proposal = await this.validatorClient.createCheckpointProposal(checkpoint.header, checkpoint.archive.root, pendingBroadcast?.txs ?? [], this.proposer, blockProposalOptions);
725
+ // Include the block pending broadcast in the checkpoint proposal if any
726
+ const lastBlock = blockPendingBroadcast && {
727
+ blockHeader: blockPendingBroadcast.block.header,
728
+ indexWithinCheckpoint: blockPendingBroadcast.block.indexWithinCheckpoint,
729
+ txs: blockPendingBroadcast.txs
730
+ };
731
+ // Create the checkpoint proposal and broadcast it
732
+ const proposal = await this.validatorClient.createCheckpointProposal(checkpoint.header, checkpoint.archive.root, feeAssetPriceModifier, lastBlock, this.proposer, checkpointProposalOptions);
233
733
  const blockProposedAt = this.dateProvider.now();
234
- await this.p2pClient.broadcastProposal(proposal);
734
+ await this.p2pClient.broadcastCheckpointProposal(proposal);
235
735
  this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.slot);
236
736
  const attestations = await this.waitForAttestations(proposal);
237
737
  const blockAttestedAt = this.dateProvider.now();
238
- this.metrics.recordBlockAttestationDelay(blockAttestedAt - blockProposedAt);
738
+ this.metrics.recordCheckpointAttestationDelay(blockAttestedAt - blockProposedAt);
239
739
  // Proposer must sign over the attestations before pushing them to L1
240
740
  const signer = this.proposer ?? this.publisher.getSenderAddress();
241
- const attestationsSignature = await this.validatorClient.signAttestationsAndSigners(attestations, signer);
741
+ let attestationsSignature;
742
+ try {
743
+ attestationsSignature = await this.validatorClient.signAttestationsAndSigners(attestations, signer, this.slot, this.checkpointNumber);
744
+ } catch (err) {
745
+ // We shouldn't really get here since we yield to another HA node
746
+ // as soon as we see these errors when creating block or checkpoint proposals.
747
+ if (this.handleHASigningError(err, 'Attestations signature')) {
748
+ return undefined;
749
+ }
750
+ throw err;
751
+ }
242
752
  // Enqueue publishing the checkpoint to L1
243
753
  this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.slot);
244
754
  const aztecSlotDuration = this.l1Constants.slotDuration;
245
755
  const slotStartBuildTimestamp = this.getSlotStartBuildTimestamp();
246
756
  const txTimeoutAt = new Date((slotStartBuildTimestamp + 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 result = Math.max(0, randomInt(100));
760
+ if (result < this.config.skipPublishingCheckpointsPercent) {
761
+ this.log.warn(`Skipping publishing proposal for checkpoint ${checkpoint.number}. Configured percentage: ${this.config.skipPublishingCheckpointsPercent}, generated value: ${result}`);
762
+ return checkpoint;
763
+ }
764
+ }
247
765
  await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
248
766
  txTimeoutAt,
249
- forcePendingBlockNumber: this.invalidateBlock?.forcePendingBlockNumber
767
+ forcePendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber
250
768
  });
251
769
  return checkpoint;
252
770
  } catch (e) {
253
771
  env.error = e;
254
772
  env.hasError = true;
255
773
  } finally{
256
- _ts_dispose_resources(env);
774
+ const result = _ts_dispose_resources(env);
775
+ if (result) await result;
257
776
  }
258
777
  } catch (err) {
778
+ if (err && (err instanceof DutyAlreadySignedError || err instanceof SlashingProtectionError)) {
779
+ // swallow this error. It's already been logged by a function deeper in the stack
780
+ return undefined;
781
+ }
259
782
  this.log.error(`Error building checkpoint at slot ${this.slot}`, err);
260
783
  return undefined;
261
784
  }
262
785
  }
263
786
  /**
264
787
  * Builds blocks for a checkpoint within the current slot.
265
- */ async buildBlocksForCheckpoint(checkpointBuilder, timestamp, blockProposalOptions) {
788
+ */ async buildBlocksForCheckpoint(checkpointBuilder, timestamp, inHash, blockProposalOptions) {
266
789
  const blocksInCheckpoint = [];
267
790
  const txHashesAlreadyIncluded = new Set();
268
791
  const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
269
792
  // Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
270
- let pendingBroadcast = undefined;
793
+ let blockPendingBroadcast = undefined;
271
794
  while(true){
272
795
  const blocksBuilt = blocksInCheckpoint.length;
273
- const indexWithinCheckpoint = blocksBuilt;
796
+ const indexWithinCheckpoint = IndexWithinCheckpoint(blocksBuilt);
274
797
  const blockNumber = BlockNumber(initialBlockNumber + blocksBuilt);
275
798
  const secondsIntoSlot = this.getSecondsIntoSlot();
276
799
  const timingInfo = this.timetable.canStartNextBlock(secondsIntoSlot);
@@ -293,6 +816,7 @@ import { SequencerState } from './utils.js';
293
816
  indexWithinCheckpoint,
294
817
  txHashesAlreadyIncluded
295
818
  });
819
+ // TODO(palla/mbps): Review these conditions. We may want to keep trying in some scenarios.
296
820
  if (!buildResult && timingInfo.isLastBlock) {
297
821
  break;
298
822
  } else if (!buildResult && timingInfo.deadline !== undefined) {
@@ -317,7 +841,14 @@ import { SequencerState } from './utils.js';
317
841
  // Sync the proposed block to the archiver to make it available
318
842
  // Note that the checkpoint builder uses its own fork so it should not need to wait for this syncing
319
843
  // Eventually we should refactor the checkpoint builder to not need a separate long-lived fork
320
- await this.syncProposedBlockToArchiver(block);
844
+ // Fire and forget - don't block the critical path, but log errors
845
+ this.syncProposedBlockToArchiver(block).catch((err)=>{
846
+ this.log.error(`Failed to sync proposed block ${block.number} to archiver`, {
847
+ blockNumber: block.number,
848
+ err
849
+ });
850
+ });
851
+ usedTxs.forEach((tx)=>txHashesAlreadyIncluded.add(tx.txHash.toString()));
321
852
  // If this is the last block, exit the loop now so we start collecting attestations
322
853
  if (timingInfo.isLastBlock) {
323
854
  this.log.verbose(`Completed final block ${blockNumber} for slot ${this.slot}`, {
@@ -325,7 +856,7 @@ import { SequencerState } from './utils.js';
325
856
  blockNumber,
326
857
  blocksBuilt
327
858
  });
328
- pendingBroadcast = {
859
+ blockPendingBroadcast = {
329
860
  block,
330
861
  txs: usedTxs
331
862
  };
@@ -334,8 +865,7 @@ import { SequencerState } from './utils.js';
334
865
  // For non-last blocks, broadcast the block proposal (unless we're in fisherman mode)
335
866
  // If the block is the last one, we'll broadcast it along with the checkpoint at the end of the loop
336
867
  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);
868
+ const proposal = await this.validatorClient.createBlockProposal(block.header, block.indexWithinCheckpoint, inHash, block.archive.root, usedTxs, this.proposer, blockProposalOptions);
339
869
  await this.p2pClient.broadcastProposal(proposal);
340
870
  }
341
871
  // Wait until the next block's start time
@@ -347,7 +877,7 @@ import { SequencerState } from './utils.js';
347
877
  });
348
878
  return {
349
879
  blocksInCheckpoint,
350
- pendingBroadcast
880
+ blockPendingBroadcast
351
881
  };
352
882
  }
353
883
  /** Sleeps until it is time to produce the next block in the slot */ async waitUntilNextSubslot(nextSubslotStart) {
@@ -383,55 +913,56 @@ import { SequencerState } from './utils.js';
383
913
  }
384
914
  // Create iterator to pending txs. We filter out txs already included in previous blocks in the checkpoint
385
915
  // 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.iteratePendingTxs(), (tx)=>!txHashesAlreadyIncluded.has(tx.txHash.toString()));
916
+ const pendingTxs = filter(this.p2pClient.iterateEligiblePendingTxs(), (tx)=>!txHashesAlreadyIncluded.has(tx.txHash.toString()));
387
917
  this.log.debug(`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.slot} with ${availableTxs} available txs`, {
388
918
  slot: this.slot,
389
919
  blockNumber,
390
920
  indexWithinCheckpoint
391
921
  });
392
922
  this.setStateFn(SequencerState.CREATING_BLOCK, this.slot);
923
+ // Per-block limits derived at startup by computeBlockLimits(), further capped
924
+ // by remaining checkpoint-level budgets inside CheckpointBuilder before each block is built.
393
925
  const blockBuilderOptions = {
394
926
  maxTransactions: this.config.maxTxsPerBlock,
395
- maxBlockSize: this.config.maxBlockSizeInBytes,
396
- maxBlockGas: new Gas(this.config.maxDABlockGas, this.config.maxL2BlockGas),
397
- maxBlobFields: BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB,
398
- deadline: buildDeadline
927
+ maxBlockGas: this.config.maxL2BlockGas !== undefined || this.config.maxDABlockGas !== undefined ? new Gas(this.config.maxDABlockGas ?? Infinity, this.config.maxL2BlockGas ?? Infinity) : undefined,
928
+ deadline: buildDeadline,
929
+ isBuildingProposal: true
399
930
  };
400
931
  // Actually build the block by executing txs
401
- const workTimer = new Timer();
402
- const { publicGas, block, publicProcessorDuration, numTxs, blockBuildingTimer, usedTxs, failedTxs } = await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
403
- const blockBuildDuration = workTimer.ms();
932
+ const buildResult = await this.buildSingleBlockWithCheckpointBuilder(checkpointBuilder, pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
404
933
  // If any txs failed during execution, drop them from the mempool so we don't pick them up again
405
- await this.dropFailedTxsFromP2P(failedTxs);
934
+ await this.dropFailedTxsFromP2P(buildResult.failedTxs);
406
935
  // Check if we have created a block with enough txs. If there were invalid txs in the pool, or if execution took
407
936
  // too long, then we may not get to minTxsPerBlock after executing public functions.
408
937
  const minValidTxs = this.config.minValidTxsPerBlock ?? minTxs;
409
- if (!forceCreate && numTxs < minValidTxs) {
410
- this.log.warn(`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.slot} has too few valid txs to be proposed (got ${numTxs} but required ${minValidTxs})`, {
938
+ const numTxs = buildResult.status === 'no-valid-txs' ? 0 : buildResult.numTxs;
939
+ if (buildResult.status === 'no-valid-txs' || !forceCreate && numTxs < minValidTxs) {
940
+ this.log.warn(`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.slot} has too few valid txs to be proposed`, {
411
941
  slot: this.slot,
412
942
  blockNumber,
413
943
  numTxs,
414
- indexWithinCheckpoint
944
+ indexWithinCheckpoint,
945
+ minValidTxs,
946
+ buildResult: buildResult.status
415
947
  });
416
- this.eventEmitter.emit('block-tx-count-check-failed', {
417
- minTxs: minValidTxs,
418
- availableTxs: numTxs,
948
+ this.eventEmitter.emit('block-build-failed', {
949
+ reason: `Insufficient valid txs`,
419
950
  slot: this.slot
420
951
  });
421
952
  this.metrics.recordBlockProposalFailed('insufficient_valid_txs');
422
953
  return undefined;
423
954
  }
424
955
  // Block creation succeeded, emit stats and metrics
956
+ const { block, publicProcessorDuration, usedTxs, blockBuildDuration } = buildResult;
425
957
  const blockStats = {
426
958
  eventName: 'l2-block-built',
427
959
  duration: blockBuildDuration,
428
960
  publicProcessDuration: publicProcessorDuration,
429
- rollupCircuitsDuration: blockBuildingTimer.ms(),
430
961
  ...block.getStats()
431
962
  };
432
963
  const blockHash = await block.hash();
433
964
  const txHashes = block.body.txEffects.map((tx)=>tx.txHash);
434
- const manaPerSec = publicGas.l2Gas / (blockBuildDuration / 1000);
965
+ const manaPerSec = block.header.totalManaUsed.toNumberUnsafe() / (blockBuildDuration / 1000);
435
966
  this.log.info(`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.slot} with ${numTxs} txs`, {
436
967
  blockHash,
437
968
  txHashes,
@@ -442,7 +973,7 @@ import { SequencerState } from './utils.js';
442
973
  blockNumber: block.number,
443
974
  slot: this.slot
444
975
  });
445
- this.metrics.recordBuiltBlock(blockBuildDuration, publicGas.l2Gas);
976
+ this.metrics.recordBuiltBlock(blockBuildDuration, block.header.totalManaUsed.toNumberUnsafe());
446
977
  return {
447
978
  block,
448
979
  usedTxs
@@ -463,9 +994,30 @@ import { SequencerState } from './utils.js';
463
994
  };
464
995
  }
465
996
  }
997
+ /** Uses the checkpoint builder to build a block, catching specific txs */ async buildSingleBlockWithCheckpointBuilder(checkpointBuilder, pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions) {
998
+ try {
999
+ const workTimer = new Timer();
1000
+ const result = await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
1001
+ const blockBuildDuration = workTimer.ms();
1002
+ return {
1003
+ ...result,
1004
+ blockBuildDuration,
1005
+ status: 'success'
1006
+ };
1007
+ } catch (err) {
1008
+ if (isErrorClass(err, NoValidTxsError)) {
1009
+ return {
1010
+ failedTxs: err.failedTxs,
1011
+ status: 'no-valid-txs'
1012
+ };
1013
+ }
1014
+ throw err;
1015
+ }
1016
+ }
466
1017
  /** Waits until minTxs are available on the pool for building a block. */ async waitForMinTxs(opts) {
467
- const minTxs = this.config.minTxsPerBlock;
468
1018
  const { indexWithinCheckpoint, blockNumber, buildDeadline, forceCreate } = opts;
1019
+ // We only allow a block with 0 txs in the first block of the checkpoint
1020
+ const minTxs = indexWithinCheckpoint > 0 && this.config.minTxsPerBlock === 0 ? 1 : this.config.minTxsPerBlock;
469
1021
  // Deadline is undefined if we are not enforcing the timetable, meaning we'll exit immediately when out of time
470
1022
  const startBuildingDeadline = buildDeadline ? new Date(buildDeadline.getTime() - this.timetable.minExecutionTime * 1000) : undefined;
471
1023
  let availableTxs = await this.p2pClient.getPendingTxCount();
@@ -485,7 +1037,7 @@ import { SequencerState } from './utils.js';
485
1037
  slot: this.slot,
486
1038
  indexWithinCheckpoint
487
1039
  });
488
- await sleep(TXS_POLLING_MS);
1040
+ await this.waitForTxsPollingInterval();
489
1041
  availableTxs = await this.p2pClient.getPendingTxCount();
490
1042
  }
491
1043
  return {
@@ -520,19 +1072,24 @@ import { SequencerState } from './utils.js';
520
1072
  return new CommitteeAttestationsAndSigners(orderAttestations(attestations ?? [], committee));
521
1073
  }
522
1074
  const attestationTimeAllowed = this.config.enforceTimeTable ? this.timetable.getMaxAllowedTime(SequencerState.PUBLISHING_CHECKPOINT) : this.l1Constants.slotDuration;
523
- const attestationDeadline = new Date(this.dateProvider.now() + attestationTimeAllowed * 1000);
1075
+ const attestationDeadline = new Date((this.getSlotStartBuildTimestamp() + attestationTimeAllowed) * 1000);
524
1076
  this.metrics.recordRequiredAttestations(numberOfRequiredAttestations, attestationTimeAllowed);
525
1077
  const collectAttestationsTimer = new Timer();
526
1078
  let collectedAttestationsCount = 0;
527
1079
  try {
528
1080
  const attestations = await this.validatorClient.collectAttestations(proposal, numberOfRequiredAttestations, attestationDeadline);
529
1081
  collectedAttestationsCount = attestations.length;
1082
+ // Trim attestations to minimum required to save L1 calldata gas
1083
+ const localAddresses = this.validatorClient.getValidatorAddresses();
1084
+ const trimmed = trimAttestations(attestations, numberOfRequiredAttestations, this.attestorAddress, localAddresses);
1085
+ if (trimmed.length < attestations.length) {
1086
+ this.log.debug(`Trimmed attestations from ${attestations.length} to ${trimmed.length} for L1 submission`);
1087
+ }
530
1088
  // Rollup contract requires that the signatures are provided in the order of the committee
531
- const sorted = orderAttestations(attestations, committee);
1089
+ const sorted = orderAttestations(trimmed, committee);
532
1090
  // Manipulate the attestations if we've been configured to do so
533
- if (this.config.injectFakeAttestation || this.config.shuffleAttestationOrdering) {
534
- const checkpoint = proposal.payload.header;
535
- return this.manipulateAttestations(checkpoint, epoch, seed, committee, sorted);
1091
+ if (this.config.injectFakeAttestation || this.config.injectHighSValueAttestation || this.config.injectUnrecoverableSignatureAttestation || this.config.shuffleAttestationOrdering) {
1092
+ return this.manipulateAttestations(proposal.slotNumber, epoch, seed, committee, sorted);
536
1093
  }
537
1094
  return new CommitteeAttestationsAndSigners(sorted);
538
1095
  } catch (err) {
@@ -544,12 +1101,11 @@ import { SequencerState } from './utils.js';
544
1101
  this.metrics.recordCollectedAttestations(collectedAttestationsCount, collectAttestationsTimer.ms());
545
1102
  }
546
1103
  }
547
- /** Breaks the attestations before publishing based on attack configs */ manipulateAttestations(checkpoint, epoch, seed, committee, attestations) {
1104
+ /** Breaks the attestations before publishing based on attack configs */ manipulateAttestations(slotNumber, epoch, seed, committee, attestations) {
548
1105
  // Compute the proposer index in the committee, since we dont want to tweak it.
549
1106
  // Otherwise, the L1 rollup contract will reject the block outright.
550
- const { slotNumber } = checkpoint;
551
1107
  const proposerIndex = Number(this.epochCache.computeProposerIndex(slotNumber, epoch, seed, BigInt(committee.length)));
552
- if (this.config.injectFakeAttestation) {
1108
+ if (this.config.injectFakeAttestation || this.config.injectHighSValueAttestation || this.config.injectUnrecoverableSignatureAttestation) {
553
1109
  // Find non-empty attestations that are not from the proposer
554
1110
  const nonProposerIndices = [];
555
1111
  for(let i = 0; i < attestations.length; i++){
@@ -559,8 +1115,16 @@ import { SequencerState } from './utils.js';
559
1115
  }
560
1116
  if (nonProposerIndices.length > 0) {
561
1117
  const targetIndex = nonProposerIndices[randomInt(nonProposerIndices.length)];
562
- this.log.warn(`Injecting fake attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
563
- unfreeze(attestations[targetIndex]).signature = Signature.random();
1118
+ if (this.config.injectHighSValueAttestation) {
1119
+ this.log.warn(`Injecting high-s value attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
1120
+ unfreeze(attestations[targetIndex]).signature = flipSignature(attestations[targetIndex].signature);
1121
+ } else if (this.config.injectUnrecoverableSignatureAttestation) {
1122
+ this.log.warn(`Injecting unrecoverable signature attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
1123
+ unfreeze(attestations[targetIndex]).signature = generateUnrecoverableSignature();
1124
+ } else {
1125
+ this.log.warn(`Injecting fake attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
1126
+ unfreeze(attestations[targetIndex]).signature = generateRecoverableSignature();
1127
+ }
564
1128
  }
565
1129
  return new CommitteeAttestationsAndSigners(attestations);
566
1130
  }
@@ -569,14 +1133,25 @@ import { SequencerState } from './utils.js';
569
1133
  const shuffled = [
570
1134
  ...attestations
571
1135
  ];
572
- const [i, j] = [
573
- (proposerIndex + 1) % shuffled.length,
574
- (proposerIndex + 2) % shuffled.length
575
- ];
576
- const valueI = shuffled[i];
577
- const valueJ = shuffled[j];
578
- shuffled[i] = valueJ;
579
- shuffled[j] = valueI;
1136
+ // Find two non-proposer positions that both have non-empty signatures to swap.
1137
+ // This ensures the bitmap doesn't change, so the MaliciousCommitteeAttestationsAndSigners
1138
+ // signers array stays correctly aligned with L1's committee reconstruction.
1139
+ const swappable = [];
1140
+ for(let k = 0; k < shuffled.length; k++){
1141
+ if (!shuffled[k].signature.isEmpty() && k !== proposerIndex) {
1142
+ swappable.push(k);
1143
+ }
1144
+ }
1145
+ if (swappable.length >= 2) {
1146
+ const [i, j] = [
1147
+ swappable[0],
1148
+ swappable[1]
1149
+ ];
1150
+ [shuffled[i], shuffled[j]] = [
1151
+ shuffled[j],
1152
+ shuffled[i]
1153
+ ];
1154
+ }
580
1155
  const signers = new CommitteeAttestationsAndSigners(attestations).getSigners();
581
1156
  return new MaliciousCommitteeAttestationsAndSigners(shuffled, signers);
582
1157
  }
@@ -589,18 +1164,25 @@ import { SequencerState } from './utils.js';
589
1164
  const failedTxData = failedTxs.map((fail)=>fail.tx);
590
1165
  const failedTxHashes = failedTxData.map((tx)=>tx.getTxHash());
591
1166
  this.log.verbose(`Dropping failed txs ${failedTxHashes.join(', ')}`);
592
- await this.p2pClient.deleteTxs(failedTxHashes);
1167
+ await this.p2pClient.handleFailedExecution(failedTxHashes);
593
1168
  }
594
1169
  /**
595
- * Placeholder for pushing block to archiver and waiting for sync.
596
- * To be implemented when archiver and world-state support proposed blocks.
1170
+ * Adds the proposed block to the archiver so it's available via P2P.
1171
+ * Gossip doesn't echo messages back to the sender, so the proposer's archiver/world-state
1172
+ * would never receive its own block without this explicit sync.
597
1173
  */ async syncProposedBlockToArchiver(block) {
598
- this.log.debug(`Syncing proposed block ${block.number}`, {
1174
+ if (this.config.skipPushProposedBlocksToArchiver !== false) {
1175
+ this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
1176
+ blockNumber: block.number,
1177
+ slot: block.header.globalVariables.slotNumber
1178
+ });
1179
+ return;
1180
+ }
1181
+ this.log.debug(`Syncing proposed block ${block.number} to archiver`, {
599
1182
  blockNumber: block.number,
600
1183
  slot: block.header.globalVariables.slotNumber
601
1184
  });
602
- // TODO(palla/mbps): Implement actual sync to archiver and world-state
603
- await Promise.resolve();
1185
+ await this.blockSink.addBlock(block);
604
1186
  }
605
1187
  /** Runs fee analysis and logs checkpoint outcome as fisherman */ async handleCheckpointEndAsFisherman(checkpoint) {
606
1188
  // Perform L1 fee analysis before clearing requests
@@ -612,21 +1194,43 @@ import { SequencerState } from './utils.js';
612
1194
  ...checkpoint.getStats(),
613
1195
  feeAnalysisId: feeAnalysis?.id
614
1196
  });
615
- this.metrics.recordBlockProposalSuccess();
616
1197
  } else {
617
1198
  this.log.warn(`Validation block building FAILED for slot ${this.slot}`, {
618
1199
  slot: this.slot,
619
1200
  feeAnalysisId: feeAnalysis?.id
620
1201
  });
621
- this.metrics.recordBlockProposalFailed('block_build_failed');
1202
+ this.metrics.recordCheckpointProposalFailed('block_build_failed');
622
1203
  }
623
1204
  this.publisher.clearPendingRequests();
624
1205
  }
1206
+ /**
1207
+ * Helper to handle HA double-signing errors. Returns true if the error was handled (caller should yield).
1208
+ */ handleHASigningError(err, errorContext) {
1209
+ if (err instanceof DutyAlreadySignedError) {
1210
+ this.log.info(`${errorContext} for slot ${this.slot} already signed by another HA node, yielding`, {
1211
+ slot: this.slot,
1212
+ signedByNode: err.signedByNode
1213
+ });
1214
+ return true;
1215
+ }
1216
+ if (err instanceof SlashingProtectionError) {
1217
+ this.log.info(`${errorContext} for slot ${this.slot} blocked by slashing protection, yielding`, {
1218
+ slot: this.slot,
1219
+ existingMessageHash: err.existingMessageHash,
1220
+ attemptedMessageHash: err.attemptedMessageHash
1221
+ });
1222
+ return true;
1223
+ }
1224
+ return false;
1225
+ }
625
1226
  /** Waits until a specific time within the current slot */ async waitUntilTimeInSlot(targetSecondsIntoSlot) {
626
1227
  const slotStartTimestamp = this.getSlotStartBuildTimestamp();
627
1228
  const targetTimestamp = slotStartTimestamp + targetSecondsIntoSlot;
628
1229
  await sleepUntil(new Date(targetTimestamp * 1000), this.dateProvider.nowAsDate());
629
1230
  }
1231
+ /** Waits the polling interval for transactions. Extracted for test overriding. */ async waitForTxsPollingInterval() {
1232
+ await sleep(TXS_POLLING_MS);
1233
+ }
630
1234
  getSlotStartBuildTimestamp() {
631
1235
  return getSlotStartBuildTimestamp(this.slot, this.l1Constants);
632
1236
  }