@aztec/sequencer-client 0.0.1-commit.03f7ef2 → 0.0.1-commit.08c5969dc

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 (79) hide show
  1. package/dest/client/sequencer-client.d.ts +5 -6
  2. package/dest/client/sequencer-client.d.ts.map +1 -1
  3. package/dest/client/sequencer-client.js +1 -1
  4. package/dest/config.d.ts +1 -2
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +10 -9
  7. package/dest/global_variable_builder/global_builder.d.ts +4 -4
  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/sequencer-publisher-factory.d.ts +2 -2
  14. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  15. package/dest/publisher/sequencer-publisher-metrics.d.ts +1 -1
  16. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  17. package/dest/publisher/sequencer-publisher-metrics.js +23 -86
  18. package/dest/publisher/sequencer-publisher.d.ts +19 -19
  19. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  20. package/dest/publisher/sequencer-publisher.js +482 -71
  21. package/dest/sequencer/checkpoint_proposal_job.d.ts +40 -12
  22. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  23. package/dest/sequencer/checkpoint_proposal_job.js +610 -59
  24. package/dest/sequencer/checkpoint_voter.d.ts +3 -2
  25. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
  26. package/dest/sequencer/checkpoint_voter.js +34 -10
  27. package/dest/sequencer/index.d.ts +1 -3
  28. package/dest/sequencer/index.d.ts.map +1 -1
  29. package/dest/sequencer/index.js +0 -2
  30. package/dest/sequencer/metrics.d.ts +7 -4
  31. package/dest/sequencer/metrics.d.ts.map +1 -1
  32. package/dest/sequencer/metrics.js +72 -128
  33. package/dest/sequencer/sequencer.d.ts +27 -15
  34. package/dest/sequencer/sequencer.d.ts.map +1 -1
  35. package/dest/sequencer/sequencer.js +492 -43
  36. package/dest/sequencer/timetable.d.ts +1 -4
  37. package/dest/sequencer/timetable.d.ts.map +1 -1
  38. package/dest/sequencer/timetable.js +1 -4
  39. package/dest/test/index.d.ts +2 -3
  40. package/dest/test/index.d.ts.map +1 -1
  41. package/dest/test/mock_checkpoint_builder.d.ts +23 -11
  42. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
  43. package/dest/test/mock_checkpoint_builder.js +50 -9
  44. package/dest/test/utils.d.ts +13 -9
  45. package/dest/test/utils.d.ts.map +1 -1
  46. package/dest/test/utils.js +27 -17
  47. package/package.json +30 -28
  48. package/src/client/sequencer-client.ts +5 -6
  49. package/src/config.ts +14 -11
  50. package/src/global_variable_builder/global_builder.ts +13 -13
  51. package/src/index.ts +1 -9
  52. package/src/publisher/sequencer-publisher-factory.ts +1 -1
  53. package/src/publisher/sequencer-publisher-metrics.ts +17 -69
  54. package/src/publisher/sequencer-publisher.ts +121 -95
  55. package/src/sequencer/checkpoint_proposal_job.ts +263 -89
  56. package/src/sequencer/checkpoint_voter.ts +32 -7
  57. package/src/sequencer/index.ts +0 -2
  58. package/src/sequencer/metrics.ts +70 -136
  59. package/src/sequencer/sequencer.ts +133 -43
  60. package/src/sequencer/timetable.ts +6 -5
  61. package/src/test/index.ts +1 -2
  62. package/src/test/mock_checkpoint_builder.ts +91 -29
  63. package/src/test/utils.ts +56 -28
  64. package/dest/sequencer/block_builder.d.ts +0 -26
  65. package/dest/sequencer/block_builder.d.ts.map +0 -1
  66. package/dest/sequencer/block_builder.js +0 -129
  67. package/dest/sequencer/checkpoint_builder.d.ts +0 -63
  68. package/dest/sequencer/checkpoint_builder.d.ts.map +0 -1
  69. package/dest/sequencer/checkpoint_builder.js +0 -131
  70. package/dest/tx_validator/nullifier_cache.d.ts +0 -14
  71. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  72. package/dest/tx_validator/nullifier_cache.js +0 -24
  73. package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
  74. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  75. package/dest/tx_validator/tx_validator_factory.js +0 -53
  76. package/src/sequencer/block_builder.ts +0 -217
  77. package/src/sequencer/checkpoint_builder.ts +0 -217
  78. package/src/tx_validator/nullifier_cache.ts +0 -30
  79. package/src/tx_validator/tx_validator_factory.ts +0 -133
@@ -63,42 +63,431 @@ function _ts_dispose_resources(env) {
63
63
  return next();
64
64
  })(env);
65
65
  }
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 { NUM_CHECKPOINT_END_MARKER_FIELDS, getNumBlockEndBlobFields } from '@aztec/blob-lib/encoding';
66
440
  import { BLOBS_PER_CHECKPOINT, FIELDS_PER_BLOB } from '@aztec/constants';
67
- import { BlockNumber } from '@aztec/foundation/branded-types';
441
+ import { BlockNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
68
442
  import { randomInt } from '@aztec/foundation/crypto/random';
69
443
  import { Signature } from '@aztec/foundation/eth-signature';
70
444
  import { filter } from '@aztec/foundation/iterator';
445
+ import { createLogger } from '@aztec/foundation/log';
71
446
  import { sleep, sleepUntil } from '@aztec/foundation/sleep';
72
447
  import { Timer } from '@aztec/foundation/timer';
73
- import { unfreeze } from '@aztec/foundation/types';
448
+ import { isErrorClass, unfreeze } from '@aztec/foundation/types';
74
449
  import { CommitteeAttestationsAndSigners, MaliciousCommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
75
450
  import { getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
76
451
  import { Gas } from '@aztec/stdlib/gas';
452
+ import { NoValidTxsError } from '@aztec/stdlib/interfaces/server';
453
+ import { computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
77
454
  import { orderAttestations } 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';
79
458
  import { CheckpointVoter } from './checkpoint_voter.js';
80
459
  import { SequencerInterruptedError } from './errors.js';
81
460
  import { SequencerState } from './utils.js';
82
461
  /** How much time to sleep while waiting for min transactions to accumulate for a block */ const TXS_POLLING_MS = 500;
462
+ _dec = trackSpan('CheckpointProposalJob.execute'), _dec1 = trackSpan('CheckpointProposalJob.proposeCheckpoint', function() {
463
+ return {
464
+ // nullish operator needed for tests
465
+ [Attributes.COINBASE]: this.validatorClient.getCoinbaseForAttestor(this.attestorAddress)?.toString(),
466
+ [Attributes.SLOT_NUMBER]: this.slot
467
+ };
468
+ }), _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
469
  /**
84
470
  * Handles the execution of a checkpoint proposal after the initial preparation phase.
85
471
  * This includes building blocks, collecting attestations, and publishing the checkpoint to L1,
86
472
  * as well as enqueueing votes for slashing and governance proposals. This class is created from
87
473
  * the Sequencer once the check for being the proposer for the slot has succeeded.
88
474
  */ export class CheckpointProposalJob {
475
+ epoch;
89
476
  slot;
90
477
  checkpointNumber;
91
478
  syncedToBlockNumber;
92
479
  proposer;
93
480
  publisher;
94
481
  attestorAddress;
95
- invalidateBlock;
482
+ invalidateCheckpoint;
96
483
  validatorClient;
97
484
  globalsBuilder;
98
485
  p2pClient;
99
486
  worldState;
100
487
  l1ToL2MessageSource;
488
+ l2BlockSource;
101
489
  checkpointsBuilder;
490
+ blockSink;
102
491
  l1Constants;
103
492
  config;
104
493
  timetable;
@@ -108,22 +497,70 @@ import { SequencerState } from './utils.js';
108
497
  metrics;
109
498
  eventEmitter;
110
499
  setStateFn;
500
+ tracer;
501
+ static{
502
+ ({ e: [_initProto] } = _apply_decs_2203_r(this, [
503
+ [
504
+ _dec,
505
+ 2,
506
+ "execute"
507
+ ],
508
+ [
509
+ _dec1,
510
+ 2,
511
+ "proposeCheckpoint"
512
+ ],
513
+ [
514
+ _dec2,
515
+ 2,
516
+ "buildBlocksForCheckpoint"
517
+ ],
518
+ [
519
+ _dec3,
520
+ 2,
521
+ "waitUntilNextSubslot"
522
+ ],
523
+ [
524
+ _dec4,
525
+ 2,
526
+ "buildSingleBlock"
527
+ ],
528
+ [
529
+ _dec5,
530
+ 2,
531
+ "waitForMinTxs"
532
+ ],
533
+ [
534
+ _dec6,
535
+ 2,
536
+ "waitForAttestations"
537
+ ],
538
+ [
539
+ _dec7,
540
+ 2,
541
+ "waitUntilTimeInSlot"
542
+ ]
543
+ ], []));
544
+ }
111
545
  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){
546
+ constructor(epoch, slot, checkpointNumber, syncedToBlockNumber, // TODO(palla/mbps): Can we remove the proposer in favor of attestorAddress? Need to check fisherman-node flows.
547
+ proposer, publisher, attestorAddress, invalidateCheckpoint, validatorClient, globalsBuilder, p2pClient, worldState, l1ToL2MessageSource, l2BlockSource, checkpointsBuilder, blockSink, l1Constants, config, timetable, slasherClient, epochCache, dateProvider, metrics, eventEmitter, setStateFn, tracer, bindings){
548
+ this.epoch = epoch;
114
549
  this.slot = slot;
115
550
  this.checkpointNumber = checkpointNumber;
116
551
  this.syncedToBlockNumber = syncedToBlockNumber;
117
552
  this.proposer = proposer;
118
553
  this.publisher = publisher;
119
554
  this.attestorAddress = attestorAddress;
120
- this.invalidateBlock = invalidateBlock;
555
+ this.invalidateCheckpoint = invalidateCheckpoint;
121
556
  this.validatorClient = validatorClient;
122
557
  this.globalsBuilder = globalsBuilder;
123
558
  this.p2pClient = p2pClient;
124
559
  this.worldState = worldState;
125
560
  this.l1ToL2MessageSource = l1ToL2MessageSource;
561
+ this.l2BlockSource = l2BlockSource;
126
562
  this.checkpointsBuilder = checkpointsBuilder;
563
+ this.blockSink = blockSink;
127
564
  this.l1Constants = l1Constants;
128
565
  this.config = config;
129
566
  this.timetable = timetable;
@@ -133,7 +570,12 @@ import { SequencerState } from './utils.js';
133
570
  this.metrics = metrics;
134
571
  this.eventEmitter = eventEmitter;
135
572
  this.setStateFn = setStateFn;
136
- this.log = log;
573
+ this.tracer = tracer;
574
+ _initProto(this);
575
+ this.log = createLogger('sequencer:checkpoint-proposal', {
576
+ ...bindings,
577
+ instanceId: `slot-${slot}`
578
+ });
137
579
  }
138
580
  /**
139
581
  * Executes the checkpoint proposal job.
@@ -147,6 +589,9 @@ import { SequencerState } from './utils.js';
147
589
  const checkpoint = await this.proposeCheckpoint();
148
590
  // Wait until the voting promises have resolved, so all requests are enqueued (not sent)
149
591
  await Promise.all(votesPromises);
592
+ if (checkpoint) {
593
+ this.metrics.recordBlockProposalSuccess();
594
+ }
150
595
  // Do not post anything to L1 if we are fishermen, but do perform L1 fee analysis
151
596
  if (this.config.fishermanMode) {
152
597
  await this.handleCheckpointEndAsFisherman(checkpoint);
@@ -185,26 +630,48 @@ import { SequencerState } from './utils.js';
185
630
  // Start the checkpoint
186
631
  this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.slot);
187
632
  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);
633
+ // Enqueues checkpoint invalidation (constant for the whole slot)
634
+ if (this.invalidateCheckpoint && !this.config.skipInvalidateBlockAsProposer) {
635
+ this.publisher.enqueueInvalidateCheckpoint(this.invalidateCheckpoint);
191
636
  }
192
637
  // Create checkpoint builder for the slot
193
638
  const checkpointGlobalVariables = await this.globalsBuilder.buildCheckpointGlobalVariables(coinbase, feeRecipient, this.slot);
194
- // Collect L1 to L2 messages for the checkpoint
639
+ // Collect L1 to L2 messages for the checkpoint and compute their hash
195
640
  const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(this.checkpointNumber);
641
+ const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
642
+ // Collect the out hashes of all the checkpoints before this one in the same epoch
643
+ const previousCheckpoints = (await this.l2BlockSource.getCheckpointsForEpoch(this.epoch)).filter((c)=>c.number < this.checkpointNumber);
644
+ const previousCheckpointOutHashes = previousCheckpoints.map((c)=>c.getCheckpointOutHash());
196
645
  const fork = _ts_add_disposable_resource(env, await this.worldState.fork(this.syncedToBlockNumber, {
197
646
  closeDelayMs: 12_000
198
647
  }), false);
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, 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
+ try {
662
+ // Main loop: build blocks for the checkpoint
663
+ const result = await this.buildBlocksForCheckpoint(checkpointBuilder, checkpointGlobalVariables.timestamp, inHash, blockProposalOptions);
664
+ blocksInCheckpoint = result.blocksInCheckpoint;
665
+ blockPendingBroadcast = result.blockPendingBroadcast;
666
+ } catch (err) {
667
+ // These errors are expected in HA mode, so we yield and let another HA node handle the slot
668
+ // The only distinction between the 2 errors is SlashingProtectionError throws when the payload is different,
669
+ // which is normal for block building (may have picked different txs)
670
+ if (this.handleHASigningError(err, 'Block proposal')) {
671
+ return undefined;
672
+ }
673
+ throw err;
674
+ }
208
675
  if (blocksInCheckpoint.length === 0) {
209
676
  this.log.warn(`No blocks were built for slot ${this.slot}`, {
210
677
  slot: this.slot
@@ -228,17 +695,33 @@ import { SequencerState } from './utils.js';
228
695
  this.metrics.recordCheckpointSuccess();
229
696
  return checkpoint;
230
697
  }
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);
698
+ // Include the block pending broadcast in the checkpoint proposal if any
699
+ const lastBlock = blockPendingBroadcast && {
700
+ blockHeader: blockPendingBroadcast.block.header,
701
+ indexWithinCheckpoint: blockPendingBroadcast.block.indexWithinCheckpoint,
702
+ txs: blockPendingBroadcast.txs
703
+ };
704
+ // Create the checkpoint proposal and broadcast it
705
+ const proposal = await this.validatorClient.createCheckpointProposal(checkpoint.header, checkpoint.archive.root, lastBlock, this.proposer, checkpointProposalOptions);
233
706
  const blockProposedAt = this.dateProvider.now();
234
- await this.p2pClient.broadcastProposal(proposal);
707
+ await this.p2pClient.broadcastCheckpointProposal(proposal);
235
708
  this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.slot);
236
709
  const attestations = await this.waitForAttestations(proposal);
237
710
  const blockAttestedAt = this.dateProvider.now();
238
- this.metrics.recordBlockAttestationDelay(blockAttestedAt - blockProposedAt);
711
+ this.metrics.recordCheckpointAttestationDelay(blockAttestedAt - blockProposedAt);
239
712
  // Proposer must sign over the attestations before pushing them to L1
240
713
  const signer = this.proposer ?? this.publisher.getSenderAddress();
241
- const attestationsSignature = await this.validatorClient.signAttestationsAndSigners(attestations, signer);
714
+ let attestationsSignature;
715
+ try {
716
+ attestationsSignature = await this.validatorClient.signAttestationsAndSigners(attestations, signer, this.slot, this.checkpointNumber);
717
+ } catch (err) {
718
+ // We shouldn't really get here since we yield to another HA node
719
+ // as soon as we see these errors when creating block or checkpoint proposals.
720
+ if (this.handleHASigningError(err, 'Attestations signature')) {
721
+ return undefined;
722
+ }
723
+ throw err;
724
+ }
242
725
  // Enqueue publishing the checkpoint to L1
243
726
  this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.slot);
244
727
  const aztecSlotDuration = this.l1Constants.slotDuration;
@@ -246,7 +729,7 @@ import { SequencerState } from './utils.js';
246
729
  const txTimeoutAt = new Date((slotStartBuildTimestamp + aztecSlotDuration) * 1000);
247
730
  await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
248
731
  txTimeoutAt,
249
- forcePendingBlockNumber: this.invalidateBlock?.forcePendingBlockNumber
732
+ forcePendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber
250
733
  });
251
734
  return checkpoint;
252
735
  } catch (e) {
@@ -256,21 +739,27 @@ import { SequencerState } from './utils.js';
256
739
  _ts_dispose_resources(env);
257
740
  }
258
741
  } catch (err) {
742
+ if (err && (err instanceof DutyAlreadySignedError || err instanceof SlashingProtectionError)) {
743
+ // swallow this error. It's already been logged by a function deeper in the stack
744
+ return undefined;
745
+ }
259
746
  this.log.error(`Error building checkpoint at slot ${this.slot}`, err);
260
747
  return undefined;
261
748
  }
262
749
  }
263
750
  /**
264
751
  * Builds blocks for a checkpoint within the current slot.
265
- */ async buildBlocksForCheckpoint(checkpointBuilder, timestamp, blockProposalOptions) {
752
+ */ async buildBlocksForCheckpoint(checkpointBuilder, timestamp, inHash, blockProposalOptions) {
266
753
  const blocksInCheckpoint = [];
267
754
  const txHashesAlreadyIncluded = new Set();
268
755
  const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
756
+ // Remaining blob fields available for blocks (checkpoint end marker already subtracted)
757
+ let remainingBlobFields = BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB - NUM_CHECKPOINT_END_MARKER_FIELDS;
269
758
  // 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;
759
+ let blockPendingBroadcast = undefined;
271
760
  while(true){
272
761
  const blocksBuilt = blocksInCheckpoint.length;
273
- const indexWithinCheckpoint = blocksBuilt;
762
+ const indexWithinCheckpoint = IndexWithinCheckpoint(blocksBuilt);
274
763
  const blockNumber = BlockNumber(initialBlockNumber + blocksBuilt);
275
764
  const secondsIntoSlot = this.getSecondsIntoSlot();
276
765
  const timingInfo = this.timetable.canStartNextBlock(secondsIntoSlot);
@@ -291,8 +780,10 @@ import { SequencerState } from './utils.js';
291
780
  buildDeadline: timingInfo.deadline ? new Date((this.getSlotStartBuildTimestamp() + timingInfo.deadline) * 1000) : undefined,
292
781
  blockNumber,
293
782
  indexWithinCheckpoint,
294
- txHashesAlreadyIncluded
783
+ txHashesAlreadyIncluded,
784
+ remainingBlobFields
295
785
  });
786
+ // TODO(palla/mbps): Review these conditions. We may want to keep trying in some scenarios.
296
787
  if (!buildResult && timingInfo.isLastBlock) {
297
788
  break;
298
789
  } else if (!buildResult && timingInfo.deadline !== undefined) {
@@ -312,12 +803,21 @@ import { SequencerState } from './utils.js';
312
803
  }
313
804
  break;
314
805
  }
315
- const { block, usedTxs } = buildResult;
806
+ const { block, usedTxs, remainingBlobFields: newRemainingBlobFields } = buildResult;
316
807
  blocksInCheckpoint.push(block);
808
+ // Update remaining blob fields for the next block
809
+ remainingBlobFields = newRemainingBlobFields;
317
810
  // Sync the proposed block to the archiver to make it available
318
811
  // Note that the checkpoint builder uses its own fork so it should not need to wait for this syncing
319
812
  // Eventually we should refactor the checkpoint builder to not need a separate long-lived fork
320
- await this.syncProposedBlockToArchiver(block);
813
+ // Fire and forget - don't block the critical path, but log errors
814
+ this.syncProposedBlockToArchiver(block).catch((err)=>{
815
+ this.log.error(`Failed to sync proposed block ${block.number} to archiver`, {
816
+ blockNumber: block.number,
817
+ err
818
+ });
819
+ });
820
+ usedTxs.forEach((tx)=>txHashesAlreadyIncluded.add(tx.txHash.toString()));
321
821
  // If this is the last block, exit the loop now so we start collecting attestations
322
822
  if (timingInfo.isLastBlock) {
323
823
  this.log.verbose(`Completed final block ${blockNumber} for slot ${this.slot}`, {
@@ -325,7 +825,7 @@ import { SequencerState } from './utils.js';
325
825
  blockNumber,
326
826
  blocksBuilt
327
827
  });
328
- pendingBroadcast = {
828
+ blockPendingBroadcast = {
329
829
  block,
330
830
  txs: usedTxs
331
831
  };
@@ -334,8 +834,7 @@ import { SequencerState } from './utils.js';
334
834
  // For non-last blocks, broadcast the block proposal (unless we're in fisherman mode)
335
835
  // If the block is the last one, we'll broadcast it along with the checkpoint at the end of the loop
336
836
  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);
837
+ const proposal = await this.validatorClient.createBlockProposal(block.header, block.indexWithinCheckpoint, inHash, block.archive.root, usedTxs, this.proposer, blockProposalOptions);
339
838
  await this.p2pClient.broadcastProposal(proposal);
340
839
  }
341
840
  // Wait until the next block's start time
@@ -347,7 +846,7 @@ import { SequencerState } from './utils.js';
347
846
  });
348
847
  return {
349
848
  blocksInCheckpoint,
350
- pendingBroadcast
849
+ blockPendingBroadcast
351
850
  };
352
851
  }
353
852
  /** Sleeps until it is time to produce the next block in the slot */ async waitUntilNextSubslot(nextSubslotStart) {
@@ -358,7 +857,7 @@ import { SequencerState } from './utils.js';
358
857
  await this.waitUntilTimeInSlot(nextSubslotStart);
359
858
  }
360
859
  /** Builds a single block. Called from the main block building loop. */ async buildSingleBlock(checkpointBuilder, opts) {
361
- const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded } = opts;
860
+ const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded, remainingBlobFields } = opts;
362
861
  this.log.verbose(`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.slot}`, {
363
862
  ...checkpointBuilder.getConstantData(),
364
863
  ...opts
@@ -383,50 +882,53 @@ import { SequencerState } from './utils.js';
383
882
  }
384
883
  // Create iterator to pending txs. We filter out txs already included in previous blocks in the checkpoint
385
884
  // 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()));
885
+ const pendingTxs = filter(this.p2pClient.iterateEligiblePendingTxs(), (tx)=>!txHashesAlreadyIncluded.has(tx.txHash.toString()));
387
886
  this.log.debug(`Building block ${blockNumber} at index ${indexWithinCheckpoint} for slot ${this.slot} with ${availableTxs} available txs`, {
388
887
  slot: this.slot,
389
888
  blockNumber,
390
889
  indexWithinCheckpoint
391
890
  });
392
891
  this.setStateFn(SequencerState.CREATING_BLOCK, this.slot);
892
+ // Calculate blob fields limit for txs (remaining capacity - this block's end overhead)
893
+ const blockEndOverhead = getNumBlockEndBlobFields(indexWithinCheckpoint === 0);
894
+ const maxBlobFieldsForTxs = remainingBlobFields - blockEndOverhead;
393
895
  const blockBuilderOptions = {
394
896
  maxTransactions: this.config.maxTxsPerBlock,
395
897
  maxBlockSize: this.config.maxBlockSizeInBytes,
396
898
  maxBlockGas: new Gas(this.config.maxDABlockGas, this.config.maxL2BlockGas),
397
- maxBlobFields: BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB,
899
+ maxBlobFields: maxBlobFieldsForTxs,
398
900
  deadline: buildDeadline
399
901
  };
400
902
  // 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();
903
+ const buildResult = await this.buildSingleBlockWithCheckpointBuilder(checkpointBuilder, pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
404
904
  // If any txs failed during execution, drop them from the mempool so we don't pick them up again
405
- await this.dropFailedTxsFromP2P(failedTxs);
905
+ await this.dropFailedTxsFromP2P(buildResult.failedTxs);
406
906
  // Check if we have created a block with enough txs. If there were invalid txs in the pool, or if execution took
407
907
  // too long, then we may not get to minTxsPerBlock after executing public functions.
408
908
  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})`, {
909
+ const numTxs = buildResult.status === 'no-valid-txs' ? 0 : buildResult.numTxs;
910
+ if (buildResult.status === 'no-valid-txs' || !forceCreate && numTxs < minValidTxs) {
911
+ this.log.warn(`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.slot} has too few valid txs to be proposed`, {
411
912
  slot: this.slot,
412
913
  blockNumber,
413
914
  numTxs,
414
- indexWithinCheckpoint
915
+ indexWithinCheckpoint,
916
+ minValidTxs,
917
+ buildResult: buildResult.status
415
918
  });
416
- this.eventEmitter.emit('block-tx-count-check-failed', {
417
- minTxs: minValidTxs,
418
- availableTxs: numTxs,
919
+ this.eventEmitter.emit('block-build-failed', {
920
+ reason: `Insufficient valid txs`,
419
921
  slot: this.slot
420
922
  });
421
923
  this.metrics.recordBlockProposalFailed('insufficient_valid_txs');
422
924
  return undefined;
423
925
  }
424
926
  // Block creation succeeded, emit stats and metrics
927
+ const { publicGas, block, publicProcessorDuration, usedTxs, usedTxBlobFields, blockBuildDuration } = buildResult;
425
928
  const blockStats = {
426
929
  eventName: 'l2-block-built',
427
930
  duration: blockBuildDuration,
428
931
  publicProcessDuration: publicProcessorDuration,
429
- rollupCircuitsDuration: blockBuildingTimer.ms(),
430
932
  ...block.getStats()
431
933
  };
432
934
  const blockHash = await block.hash();
@@ -445,7 +947,8 @@ import { SequencerState } from './utils.js';
445
947
  this.metrics.recordBuiltBlock(blockBuildDuration, publicGas.l2Gas);
446
948
  return {
447
949
  block,
448
- usedTxs
950
+ usedTxs,
951
+ remainingBlobFields: maxBlobFieldsForTxs - usedTxBlobFields
449
952
  };
450
953
  } catch (err) {
451
954
  this.eventEmitter.emit('block-build-failed', {
@@ -463,9 +966,30 @@ import { SequencerState } from './utils.js';
463
966
  };
464
967
  }
465
968
  }
969
+ /** Uses the checkpoint builder to build a block, catching specific txs */ async buildSingleBlockWithCheckpointBuilder(checkpointBuilder, pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions) {
970
+ try {
971
+ const workTimer = new Timer();
972
+ const result = await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
973
+ const blockBuildDuration = workTimer.ms();
974
+ return {
975
+ ...result,
976
+ blockBuildDuration,
977
+ status: 'success'
978
+ };
979
+ } catch (err) {
980
+ if (isErrorClass(err, NoValidTxsError)) {
981
+ return {
982
+ failedTxs: err.failedTxs,
983
+ status: 'no-valid-txs'
984
+ };
985
+ }
986
+ throw err;
987
+ }
988
+ }
466
989
  /** Waits until minTxs are available on the pool for building a block. */ async waitForMinTxs(opts) {
467
- const minTxs = this.config.minTxsPerBlock;
468
990
  const { indexWithinCheckpoint, blockNumber, buildDeadline, forceCreate } = opts;
991
+ // We only allow a block with 0 txs in the first block of the checkpoint
992
+ const minTxs = indexWithinCheckpoint > 0 && this.config.minTxsPerBlock === 0 ? 1 : this.config.minTxsPerBlock;
469
993
  // Deadline is undefined if we are not enforcing the timetable, meaning we'll exit immediately when out of time
470
994
  const startBuildingDeadline = buildDeadline ? new Date(buildDeadline.getTime() - this.timetable.minExecutionTime * 1000) : undefined;
471
995
  let availableTxs = await this.p2pClient.getPendingTxCount();
@@ -485,7 +1009,7 @@ import { SequencerState } from './utils.js';
485
1009
  slot: this.slot,
486
1010
  indexWithinCheckpoint
487
1011
  });
488
- await sleep(TXS_POLLING_MS);
1012
+ await this.waitForTxsPollingInterval();
489
1013
  availableTxs = await this.p2pClient.getPendingTxCount();
490
1014
  }
491
1015
  return {
@@ -520,7 +1044,7 @@ import { SequencerState } from './utils.js';
520
1044
  return new CommitteeAttestationsAndSigners(orderAttestations(attestations ?? [], committee));
521
1045
  }
522
1046
  const attestationTimeAllowed = this.config.enforceTimeTable ? this.timetable.getMaxAllowedTime(SequencerState.PUBLISHING_CHECKPOINT) : this.l1Constants.slotDuration;
523
- const attestationDeadline = new Date(this.dateProvider.now() + attestationTimeAllowed * 1000);
1047
+ const attestationDeadline = new Date((this.getSlotStartBuildTimestamp() + attestationTimeAllowed) * 1000);
524
1048
  this.metrics.recordRequiredAttestations(numberOfRequiredAttestations, attestationTimeAllowed);
525
1049
  const collectAttestationsTimer = new Timer();
526
1050
  let collectedAttestationsCount = 0;
@@ -531,8 +1055,7 @@ import { SequencerState } from './utils.js';
531
1055
  const sorted = orderAttestations(attestations, committee);
532
1056
  // Manipulate the attestations if we've been configured to do so
533
1057
  if (this.config.injectFakeAttestation || this.config.shuffleAttestationOrdering) {
534
- const checkpoint = proposal.payload.header;
535
- return this.manipulateAttestations(checkpoint, epoch, seed, committee, sorted);
1058
+ return this.manipulateAttestations(proposal.slotNumber, epoch, seed, committee, sorted);
536
1059
  }
537
1060
  return new CommitteeAttestationsAndSigners(sorted);
538
1061
  } catch (err) {
@@ -544,10 +1067,9 @@ import { SequencerState } from './utils.js';
544
1067
  this.metrics.recordCollectedAttestations(collectedAttestationsCount, collectAttestationsTimer.ms());
545
1068
  }
546
1069
  }
547
- /** Breaks the attestations before publishing based on attack configs */ manipulateAttestations(checkpoint, epoch, seed, committee, attestations) {
1070
+ /** Breaks the attestations before publishing based on attack configs */ manipulateAttestations(slotNumber, epoch, seed, committee, attestations) {
548
1071
  // Compute the proposer index in the committee, since we dont want to tweak it.
549
1072
  // Otherwise, the L1 rollup contract will reject the block outright.
550
- const { slotNumber } = checkpoint;
551
1073
  const proposerIndex = Number(this.epochCache.computeProposerIndex(slotNumber, epoch, seed, BigInt(committee.length)));
552
1074
  if (this.config.injectFakeAttestation) {
553
1075
  // Find non-empty attestations that are not from the proposer
@@ -589,18 +1111,25 @@ import { SequencerState } from './utils.js';
589
1111
  const failedTxData = failedTxs.map((fail)=>fail.tx);
590
1112
  const failedTxHashes = failedTxData.map((tx)=>tx.getTxHash());
591
1113
  this.log.verbose(`Dropping failed txs ${failedTxHashes.join(', ')}`);
592
- await this.p2pClient.deleteTxs(failedTxHashes);
1114
+ await this.p2pClient.handleFailedExecution(failedTxHashes);
593
1115
  }
594
1116
  /**
595
- * Placeholder for pushing block to archiver and waiting for sync.
596
- * To be implemented when archiver and world-state support proposed blocks.
1117
+ * Adds the proposed block to the archiver so it's available via P2P.
1118
+ * Gossip doesn't echo messages back to the sender, so the proposer's archiver/world-state
1119
+ * would never receive its own block without this explicit sync.
597
1120
  */ async syncProposedBlockToArchiver(block) {
598
- this.log.debug(`Syncing proposed block ${block.number}`, {
1121
+ if (this.config.skipPushProposedBlocksToArchiver !== false) {
1122
+ this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
1123
+ blockNumber: block.number,
1124
+ slot: block.header.globalVariables.slotNumber
1125
+ });
1126
+ return;
1127
+ }
1128
+ this.log.debug(`Syncing proposed block ${block.number} to archiver`, {
599
1129
  blockNumber: block.number,
600
1130
  slot: block.header.globalVariables.slotNumber
601
1131
  });
602
- // TODO(palla/mbps): Implement actual sync to archiver and world-state
603
- await Promise.resolve();
1132
+ await this.blockSink.addBlock(block);
604
1133
  }
605
1134
  /** Runs fee analysis and logs checkpoint outcome as fisherman */ async handleCheckpointEndAsFisherman(checkpoint) {
606
1135
  // Perform L1 fee analysis before clearing requests
@@ -612,7 +1141,6 @@ import { SequencerState } from './utils.js';
612
1141
  ...checkpoint.getStats(),
613
1142
  feeAnalysisId: feeAnalysis?.id
614
1143
  });
615
- this.metrics.recordBlockProposalSuccess();
616
1144
  } else {
617
1145
  this.log.warn(`Validation block building FAILED for slot ${this.slot}`, {
618
1146
  slot: this.slot,
@@ -622,11 +1150,34 @@ import { SequencerState } from './utils.js';
622
1150
  }
623
1151
  this.publisher.clearPendingRequests();
624
1152
  }
1153
+ /**
1154
+ * Helper to handle HA double-signing errors. Returns true if the error was handled (caller should yield).
1155
+ */ handleHASigningError(err, errorContext) {
1156
+ if (err instanceof DutyAlreadySignedError) {
1157
+ this.log.info(`${errorContext} for slot ${this.slot} already signed by another HA node, yielding`, {
1158
+ slot: this.slot,
1159
+ signedByNode: err.signedByNode
1160
+ });
1161
+ return true;
1162
+ }
1163
+ if (err instanceof SlashingProtectionError) {
1164
+ this.log.info(`${errorContext} for slot ${this.slot} blocked by slashing protection, yielding`, {
1165
+ slot: this.slot,
1166
+ existingMessageHash: err.existingMessageHash,
1167
+ attemptedMessageHash: err.attemptedMessageHash
1168
+ });
1169
+ return true;
1170
+ }
1171
+ return false;
1172
+ }
625
1173
  /** Waits until a specific time within the current slot */ async waitUntilTimeInSlot(targetSecondsIntoSlot) {
626
1174
  const slotStartTimestamp = this.getSlotStartBuildTimestamp();
627
1175
  const targetTimestamp = slotStartTimestamp + targetSecondsIntoSlot;
628
1176
  await sleepUntil(new Date(targetTimestamp * 1000), this.dateProvider.nowAsDate());
629
1177
  }
1178
+ /** Waits the polling interval for transactions. Extracted for test overriding. */ async waitForTxsPollingInterval() {
1179
+ await sleep(TXS_POLLING_MS);
1180
+ }
630
1181
  getSlotStartBuildTimestamp() {
631
1182
  return getSlotStartBuildTimestamp(this.slot, this.l1Constants);
632
1183
  }