@aztec/sequencer-client 0.0.1-commit.9593d84 → 0.0.1-commit.967fc6998

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 (115) hide show
  1. package/dest/client/sequencer-client.d.ts +21 -16
  2. package/dest/client/sequencer-client.d.ts.map +1 -1
  3. package/dest/client/sequencer-client.js +45 -27
  4. package/dest/config.d.ts +14 -8
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +83 -35
  7. package/dest/global_variable_builder/global_builder.d.ts +20 -13
  8. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  9. package/dest/global_variable_builder/global_builder.js +51 -41
  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 +41 -20
  14. package/dest/publisher/config.d.ts.map +1 -1
  15. package/dest/publisher/config.js +109 -39
  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 +15 -6
  31. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  32. package/dest/publisher/sequencer-publisher-factory.js +14 -3
  33. package/dest/publisher/sequencer-publisher-metrics.d.ts +3 -3
  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 +69 -47
  37. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  38. package/dest/publisher/sequencer-publisher.js +847 -145
  39. package/dest/sequencer/checkpoint_proposal_job.d.ts +102 -0
  40. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  41. package/dest/sequencer/checkpoint_proposal_job.js +1219 -0
  42. package/dest/sequencer/checkpoint_voter.d.ts +35 -0
  43. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  44. package/dest/sequencer/checkpoint_voter.js +109 -0
  45. package/dest/sequencer/config.d.ts +3 -2
  46. package/dest/sequencer/config.d.ts.map +1 -1
  47. package/dest/sequencer/events.d.ts +46 -0
  48. package/dest/sequencer/events.d.ts.map +1 -0
  49. package/dest/sequencer/events.js +1 -0
  50. package/dest/sequencer/index.d.ts +4 -2
  51. package/dest/sequencer/index.d.ts.map +1 -1
  52. package/dest/sequencer/index.js +3 -1
  53. package/dest/sequencer/metrics.d.ts +38 -6
  54. package/dest/sequencer/metrics.d.ts.map +1 -1
  55. package/dest/sequencer/metrics.js +216 -72
  56. package/dest/sequencer/sequencer.d.ts +119 -133
  57. package/dest/sequencer/sequencer.d.ts.map +1 -1
  58. package/dest/sequencer/sequencer.js +717 -625
  59. package/dest/sequencer/timetable.d.ts +51 -14
  60. package/dest/sequencer/timetable.d.ts.map +1 -1
  61. package/dest/sequencer/timetable.js +145 -59
  62. package/dest/sequencer/types.d.ts +3 -0
  63. package/dest/sequencer/types.d.ts.map +1 -0
  64. package/dest/sequencer/types.js +1 -0
  65. package/dest/sequencer/utils.d.ts +14 -8
  66. package/dest/sequencer/utils.d.ts.map +1 -1
  67. package/dest/sequencer/utils.js +7 -4
  68. package/dest/test/index.d.ts +6 -7
  69. package/dest/test/index.d.ts.map +1 -1
  70. package/dest/test/mock_checkpoint_builder.d.ts +97 -0
  71. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  72. package/dest/test/mock_checkpoint_builder.js +222 -0
  73. package/dest/test/utils.d.ts +53 -0
  74. package/dest/test/utils.d.ts.map +1 -0
  75. package/dest/test/utils.js +104 -0
  76. package/package.json +32 -30
  77. package/src/client/sequencer-client.ts +54 -47
  78. package/src/config.ts +95 -44
  79. package/src/global_variable_builder/global_builder.ts +65 -61
  80. package/src/index.ts +1 -7
  81. package/src/publisher/config.ts +131 -50
  82. package/src/publisher/index.ts +3 -0
  83. package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
  84. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +55 -0
  85. package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
  86. package/src/publisher/l1_tx_failed_store/index.ts +3 -0
  87. package/src/publisher/sequencer-publisher-factory.ts +28 -10
  88. package/src/publisher/sequencer-publisher-metrics.ts +19 -71
  89. package/src/publisher/sequencer-publisher.ts +528 -184
  90. package/src/sequencer/README.md +531 -0
  91. package/src/sequencer/checkpoint_proposal_job.ts +926 -0
  92. package/src/sequencer/checkpoint_voter.ts +130 -0
  93. package/src/sequencer/config.ts +2 -1
  94. package/src/sequencer/events.ts +27 -0
  95. package/src/sequencer/index.ts +3 -1
  96. package/src/sequencer/metrics.ts +268 -82
  97. package/src/sequencer/sequencer.ts +464 -831
  98. package/src/sequencer/timetable.ts +175 -80
  99. package/src/sequencer/types.ts +6 -0
  100. package/src/sequencer/utils.ts +18 -9
  101. package/src/test/index.ts +5 -6
  102. package/src/test/mock_checkpoint_builder.ts +320 -0
  103. package/src/test/utils.ts +167 -0
  104. package/dest/sequencer/block_builder.d.ts +0 -27
  105. package/dest/sequencer/block_builder.d.ts.map +0 -1
  106. package/dest/sequencer/block_builder.js +0 -134
  107. package/dest/tx_validator/nullifier_cache.d.ts +0 -14
  108. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  109. package/dest/tx_validator/nullifier_cache.js +0 -24
  110. package/dest/tx_validator/tx_validator_factory.d.ts +0 -17
  111. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  112. package/dest/tx_validator/tx_validator_factory.js +0 -53
  113. package/src/sequencer/block_builder.ts +0 -222
  114. package/src/tx_validator/nullifier_cache.ts +0 -30
  115. package/src/tx_validator/tx_validator_factory.ts +0 -132
@@ -1,19 +1,397 @@
1
+ function applyDecs2203RFactory() {
2
+ function createAddInitializerMethod(initializers, decoratorFinishedRef) {
3
+ return function addInitializer(initializer) {
4
+ assertNotFinished(decoratorFinishedRef, "addInitializer");
5
+ assertCallable(initializer, "An initializer");
6
+ initializers.push(initializer);
7
+ };
8
+ }
9
+ function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
10
+ var kindStr;
11
+ switch(kind){
12
+ case 1:
13
+ kindStr = "accessor";
14
+ break;
15
+ case 2:
16
+ kindStr = "method";
17
+ break;
18
+ case 3:
19
+ kindStr = "getter";
20
+ break;
21
+ case 4:
22
+ kindStr = "setter";
23
+ break;
24
+ default:
25
+ kindStr = "field";
26
+ }
27
+ var ctx = {
28
+ kind: kindStr,
29
+ name: isPrivate ? "#" + name : name,
30
+ static: isStatic,
31
+ private: isPrivate,
32
+ metadata: metadata
33
+ };
34
+ var decoratorFinishedRef = {
35
+ v: false
36
+ };
37
+ ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
38
+ var get, set;
39
+ if (kind === 0) {
40
+ if (isPrivate) {
41
+ get = desc.get;
42
+ set = desc.set;
43
+ } else {
44
+ get = function() {
45
+ return this[name];
46
+ };
47
+ set = function(v) {
48
+ this[name] = v;
49
+ };
50
+ }
51
+ } else if (kind === 2) {
52
+ get = function() {
53
+ return desc.value;
54
+ };
55
+ } else {
56
+ if (kind === 1 || kind === 3) {
57
+ get = function() {
58
+ return desc.get.call(this);
59
+ };
60
+ }
61
+ if (kind === 1 || kind === 4) {
62
+ set = function(v) {
63
+ desc.set.call(this, v);
64
+ };
65
+ }
66
+ }
67
+ ctx.access = get && set ? {
68
+ get: get,
69
+ set: set
70
+ } : get ? {
71
+ get: get
72
+ } : {
73
+ set: set
74
+ };
75
+ try {
76
+ return dec(value, ctx);
77
+ } finally{
78
+ decoratorFinishedRef.v = true;
79
+ }
80
+ }
81
+ function assertNotFinished(decoratorFinishedRef, fnName) {
82
+ if (decoratorFinishedRef.v) {
83
+ throw new Error("attempted to call " + fnName + " after decoration was finished");
84
+ }
85
+ }
86
+ function assertCallable(fn, hint) {
87
+ if (typeof fn !== "function") {
88
+ throw new TypeError(hint + " must be a function");
89
+ }
90
+ }
91
+ function assertValidReturnValue(kind, value) {
92
+ var type = typeof value;
93
+ if (kind === 1) {
94
+ if (type !== "object" || value === null) {
95
+ throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
96
+ }
97
+ if (value.get !== undefined) {
98
+ assertCallable(value.get, "accessor.get");
99
+ }
100
+ if (value.set !== undefined) {
101
+ assertCallable(value.set, "accessor.set");
102
+ }
103
+ if (value.init !== undefined) {
104
+ assertCallable(value.init, "accessor.init");
105
+ }
106
+ } else if (type !== "function") {
107
+ var hint;
108
+ if (kind === 0) {
109
+ hint = "field";
110
+ } else if (kind === 10) {
111
+ hint = "class";
112
+ } else {
113
+ hint = "method";
114
+ }
115
+ throw new TypeError(hint + " decorators must return a function or void 0");
116
+ }
117
+ }
118
+ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
119
+ var decs = decInfo[0];
120
+ var desc, init, value;
121
+ if (isPrivate) {
122
+ if (kind === 0 || kind === 1) {
123
+ desc = {
124
+ get: decInfo[3],
125
+ set: decInfo[4]
126
+ };
127
+ } else if (kind === 3) {
128
+ desc = {
129
+ get: decInfo[3]
130
+ };
131
+ } else if (kind === 4) {
132
+ desc = {
133
+ set: decInfo[3]
134
+ };
135
+ } else {
136
+ desc = {
137
+ value: decInfo[3]
138
+ };
139
+ }
140
+ } else if (kind !== 0) {
141
+ desc = Object.getOwnPropertyDescriptor(base, name);
142
+ }
143
+ if (kind === 1) {
144
+ value = {
145
+ get: desc.get,
146
+ set: desc.set
147
+ };
148
+ } else if (kind === 2) {
149
+ value = desc.value;
150
+ } else if (kind === 3) {
151
+ value = desc.get;
152
+ } else if (kind === 4) {
153
+ value = desc.set;
154
+ }
155
+ var newValue, get, set;
156
+ if (typeof decs === "function") {
157
+ newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
158
+ if (newValue !== void 0) {
159
+ assertValidReturnValue(kind, newValue);
160
+ if (kind === 0) {
161
+ init = newValue;
162
+ } else if (kind === 1) {
163
+ init = newValue.init;
164
+ get = newValue.get || value.get;
165
+ set = newValue.set || value.set;
166
+ value = {
167
+ get: get,
168
+ set: set
169
+ };
170
+ } else {
171
+ value = newValue;
172
+ }
173
+ }
174
+ } else {
175
+ for(var i = decs.length - 1; i >= 0; i--){
176
+ var dec = decs[i];
177
+ newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
178
+ if (newValue !== void 0) {
179
+ assertValidReturnValue(kind, newValue);
180
+ var newInit;
181
+ if (kind === 0) {
182
+ newInit = newValue;
183
+ } else if (kind === 1) {
184
+ newInit = newValue.init;
185
+ get = newValue.get || value.get;
186
+ set = newValue.set || value.set;
187
+ value = {
188
+ get: get,
189
+ set: set
190
+ };
191
+ } else {
192
+ value = newValue;
193
+ }
194
+ if (newInit !== void 0) {
195
+ if (init === void 0) {
196
+ init = newInit;
197
+ } else if (typeof init === "function") {
198
+ init = [
199
+ init,
200
+ newInit
201
+ ];
202
+ } else {
203
+ init.push(newInit);
204
+ }
205
+ }
206
+ }
207
+ }
208
+ }
209
+ if (kind === 0 || kind === 1) {
210
+ if (init === void 0) {
211
+ init = function(instance, init) {
212
+ return init;
213
+ };
214
+ } else if (typeof init !== "function") {
215
+ var ownInitializers = init;
216
+ init = function(instance, init) {
217
+ var value = init;
218
+ for(var i = 0; i < ownInitializers.length; i++){
219
+ value = ownInitializers[i].call(instance, value);
220
+ }
221
+ return value;
222
+ };
223
+ } else {
224
+ var originalInitializer = init;
225
+ init = function(instance, init) {
226
+ return originalInitializer.call(instance, init);
227
+ };
228
+ }
229
+ ret.push(init);
230
+ }
231
+ if (kind !== 0) {
232
+ if (kind === 1) {
233
+ desc.get = value.get;
234
+ desc.set = value.set;
235
+ } else if (kind === 2) {
236
+ desc.value = value;
237
+ } else if (kind === 3) {
238
+ desc.get = value;
239
+ } else if (kind === 4) {
240
+ desc.set = value;
241
+ }
242
+ if (isPrivate) {
243
+ if (kind === 1) {
244
+ ret.push(function(instance, args) {
245
+ return value.get.call(instance, args);
246
+ });
247
+ ret.push(function(instance, args) {
248
+ return value.set.call(instance, args);
249
+ });
250
+ } else if (kind === 2) {
251
+ ret.push(value);
252
+ } else {
253
+ ret.push(function(instance, args) {
254
+ return value.call(instance, args);
255
+ });
256
+ }
257
+ } else {
258
+ Object.defineProperty(base, name, desc);
259
+ }
260
+ }
261
+ }
262
+ function applyMemberDecs(Class, decInfos, metadata) {
263
+ var ret = [];
264
+ var protoInitializers;
265
+ var staticInitializers;
266
+ var existingProtoNonFields = new Map();
267
+ var existingStaticNonFields = new Map();
268
+ for(var i = 0; i < decInfos.length; i++){
269
+ var decInfo = decInfos[i];
270
+ if (!Array.isArray(decInfo)) continue;
271
+ var kind = decInfo[1];
272
+ var name = decInfo[2];
273
+ var isPrivate = decInfo.length > 3;
274
+ var isStatic = kind >= 5;
275
+ var base;
276
+ var initializers;
277
+ if (isStatic) {
278
+ base = Class;
279
+ kind = kind - 5;
280
+ staticInitializers = staticInitializers || [];
281
+ initializers = staticInitializers;
282
+ } else {
283
+ base = Class.prototype;
284
+ protoInitializers = protoInitializers || [];
285
+ initializers = protoInitializers;
286
+ }
287
+ if (kind !== 0 && !isPrivate) {
288
+ var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
289
+ var existingKind = existingNonFields.get(name) || 0;
290
+ if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) {
291
+ throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
292
+ } else if (!existingKind && kind > 2) {
293
+ existingNonFields.set(name, kind);
294
+ } else {
295
+ existingNonFields.set(name, true);
296
+ }
297
+ }
298
+ applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
299
+ }
300
+ pushInitializers(ret, protoInitializers);
301
+ pushInitializers(ret, staticInitializers);
302
+ return ret;
303
+ }
304
+ function pushInitializers(ret, initializers) {
305
+ if (initializers) {
306
+ ret.push(function(instance) {
307
+ for(var i = 0; i < initializers.length; i++){
308
+ initializers[i].call(instance);
309
+ }
310
+ return instance;
311
+ });
312
+ }
313
+ }
314
+ function applyClassDecs(targetClass, classDecs, metadata) {
315
+ if (classDecs.length > 0) {
316
+ var initializers = [];
317
+ var newClass = targetClass;
318
+ var name = targetClass.name;
319
+ for(var i = classDecs.length - 1; i >= 0; i--){
320
+ var decoratorFinishedRef = {
321
+ v: false
322
+ };
323
+ try {
324
+ var nextNewClass = classDecs[i](newClass, {
325
+ kind: "class",
326
+ name: name,
327
+ addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
328
+ metadata
329
+ });
330
+ } finally{
331
+ decoratorFinishedRef.v = true;
332
+ }
333
+ if (nextNewClass !== undefined) {
334
+ assertValidReturnValue(10, nextNewClass);
335
+ newClass = nextNewClass;
336
+ }
337
+ }
338
+ return [
339
+ defineMetadata(newClass, metadata),
340
+ function() {
341
+ for(var i = 0; i < initializers.length; i++){
342
+ initializers[i].call(newClass);
343
+ }
344
+ }
345
+ ];
346
+ }
347
+ }
348
+ function defineMetadata(Class, metadata) {
349
+ return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
350
+ configurable: true,
351
+ enumerable: true,
352
+ value: metadata
353
+ });
354
+ }
355
+ return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
356
+ if (parentClass !== void 0) {
357
+ var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
358
+ }
359
+ var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
360
+ var e = applyMemberDecs(targetClass, memberDecs, metadata);
361
+ if (!classDecs.length) defineMetadata(targetClass, metadata);
362
+ return {
363
+ e: e,
364
+ get c () {
365
+ return applyClassDecs(targetClass, classDecs, metadata);
366
+ }
367
+ };
368
+ };
369
+ }
370
+ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
371
+ return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
372
+ }
373
+ var _dec, _dec1, _dec2, _initProto;
1
374
  import { Blob, getBlobsPerL1Block, getPrefixedEthBlobCommitments } from '@aztec/blob-lib';
2
- import { createBlobSinkClient } from '@aztec/blob-sink/client';
3
- import { FormattedViemError, MULTI_CALL_3_ADDRESS, Multicall3, RollupContract, WEI_CONST, formatViemError, tryExtractEvent } from '@aztec/ethereum';
375
+ import { FeeAssetPriceOracle, MULTI_CALL_3_ADDRESS, Multicall3, RollupContract } from '@aztec/ethereum/contracts';
376
+ import { L1FeeAnalyzer } from '@aztec/ethereum/l1-fee-analysis';
377
+ import { MAX_L1_TX_LIMIT, WEI_CONST } from '@aztec/ethereum/l1-tx-utils';
378
+ import { FormattedViemError, formatViemError, mergeAbis, tryExtractEvent } from '@aztec/ethereum/utils';
4
379
  import { sumBigint } from '@aztec/foundation/bigint';
5
380
  import { toHex as toPaddedHex } from '@aztec/foundation/bigint-buffer';
6
- import { SlotNumber } from '@aztec/foundation/branded-types';
381
+ import { CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
382
+ import { pick } from '@aztec/foundation/collection';
7
383
  import { EthAddress } from '@aztec/foundation/eth-address';
8
384
  import { Signature } from '@aztec/foundation/eth-signature';
9
385
  import { createLogger } from '@aztec/foundation/log';
386
+ import { makeBackoff, retry } from '@aztec/foundation/retry';
10
387
  import { bufferToHex } from '@aztec/foundation/string';
11
388
  import { Timer } from '@aztec/foundation/timer';
12
389
  import { EmpireBaseAbi, ErrorsAbi, RollupAbi } from '@aztec/l1-artifacts';
13
390
  import { encodeSlashConsensusVotes } from '@aztec/slasher';
14
- import { CommitteeAttestation, CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
15
- import { getTelemetryClient } from '@aztec/telemetry-client';
16
- import { encodeFunctionData, toHex } from 'viem';
391
+ import { CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
392
+ import { getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
393
+ import { encodeFunctionData, keccak256, multicall3Abi, toHex } from 'viem';
394
+ import { createL1TxFailedStore } from './l1_tx_failed_store/index.js';
17
395
  import { SequencerPublisherMetrics } from './sequencer-publisher-metrics.js';
18
396
  export const Actions = [
19
397
  'invalidate-by-invalid-attestation',
@@ -28,22 +406,43 @@ export const Actions = [
28
406
  ];
29
407
  // Sorting for actions such that invalidations go before proposals, and proposals go before votes
30
408
  export const compareActions = (a, b)=>Actions.indexOf(a) - Actions.indexOf(b);
409
+ _dec = trackSpan('SequencerPublisher.sendRequests'), _dec1 = trackSpan('SequencerPublisher.validateBlockHeader'), _dec2 = trackSpan('SequencerPublisher.validateCheckpointForSubmission');
31
410
  export class SequencerPublisher {
32
411
  config;
412
+ static{
413
+ ({ e: [_initProto] } = _apply_decs_2203_r(this, [
414
+ [
415
+ _dec,
416
+ 2,
417
+ "sendRequests"
418
+ ],
419
+ [
420
+ _dec1,
421
+ 2,
422
+ "validateBlockHeader"
423
+ ],
424
+ [
425
+ _dec2,
426
+ 2,
427
+ "validateCheckpointForSubmission"
428
+ ]
429
+ ], []));
430
+ }
33
431
  interrupted;
34
432
  metrics;
35
433
  epochCache;
434
+ failedTxStore;
36
435
  governanceLog;
37
436
  slashingLog;
38
437
  lastActions;
438
+ isPayloadEmptyCache;
439
+ payloadProposedCache;
39
440
  log;
40
441
  ethereumSlotDuration;
41
- blobSinkClient;
442
+ blobClient;
42
443
  /** Address to use for simulations in fisherman mode (actual proposer's address) */ proposerAddressForSimulation;
43
- // @note - with blobs, the below estimate seems too large.
44
- // Total used for full block from int_l1_pub e2e test: 1m (of which 86k is 1x blob)
45
- // Total used for emptier block from above test: 429k (of which 84k is 1x blob)
46
- static PROPOSE_GAS_GUESS = 12_000_000n;
444
+ /** L1 fee analyzer for fisherman mode */ l1FeeAnalyzer;
445
+ /** Fee asset price oracle for computing price modifiers from Uniswap V4 */ feeAssetPriceOracle;
47
446
  // A CALL to a cold address is 2700 gas
48
447
  static MULTICALL_OVERHEAD_GAS_GUESS = 5000n;
49
448
  // Gas report for VotingWithSigTest shows a max gas of 100k, but we've seen it cost 700k+ in testnet
@@ -53,23 +452,25 @@ export class SequencerPublisher {
53
452
  govProposerContract;
54
453
  slashingProposerContract;
55
454
  slashFactoryContract;
455
+ tracer;
56
456
  requests;
57
457
  constructor(config, deps){
58
458
  this.config = config;
59
- this.interrupted = false;
459
+ this.interrupted = (_initProto(this), false);
60
460
  this.governanceLog = createLogger('sequencer:publisher:governance');
61
461
  this.slashingLog = createLogger('sequencer:publisher:slashing');
62
462
  this.lastActions = {};
463
+ this.isPayloadEmptyCache = new Map();
464
+ this.payloadProposedCache = new Set();
63
465
  this.requests = [];
64
466
  this.log = deps.log ?? createLogger('sequencer:publisher');
65
467
  this.ethereumSlotDuration = BigInt(config.ethereumSlotDuration);
66
468
  this.epochCache = deps.epochCache;
67
469
  this.lastActions = deps.lastActions;
68
- this.blobSinkClient = deps.blobSinkClient ?? createBlobSinkClient(config, {
69
- logger: createLogger('sequencer:blob-sink:client')
70
- });
470
+ this.blobClient = deps.blobClient;
71
471
  const telemetry = deps.telemetry ?? getTelemetryClient();
72
472
  this.metrics = deps.metrics ?? new SequencerPublisherMetrics(telemetry, 'SequencerPublisher');
473
+ this.tracer = telemetry.getTracer('SequencerPublisher');
73
474
  this.l1TxUtils = deps.l1TxUtils;
74
475
  this.rollupContract = deps.rollupContract;
75
476
  this.govProposerContract = deps.governanceProposerContract;
@@ -80,14 +481,49 @@ export class SequencerPublisher {
80
481
  this.slashingProposerContract = newSlashingProposer;
81
482
  });
82
483
  this.slashFactoryContract = deps.slashFactoryContract;
484
+ // Initialize L1 fee analyzer for fisherman mode
485
+ if (config.fishermanMode) {
486
+ this.l1FeeAnalyzer = new L1FeeAnalyzer(this.l1TxUtils.client, deps.dateProvider, createLogger('sequencer:publisher:fee-analyzer'));
487
+ }
488
+ // Initialize fee asset price oracle
489
+ this.feeAssetPriceOracle = new FeeAssetPriceOracle(this.l1TxUtils.client, this.rollupContract, createLogger('sequencer:publisher:price-oracle'));
490
+ // Initialize failed L1 tx store (optional, for test networks)
491
+ this.failedTxStore = createL1TxFailedStore(config.l1TxFailedStore, this.log);
492
+ }
493
+ /**
494
+ * Backs up a failed L1 transaction to the configured store for debugging.
495
+ * Does nothing if no store is configured.
496
+ */ backupFailedTx(failedTx) {
497
+ if (!this.failedTxStore) {
498
+ return;
499
+ }
500
+ const tx = {
501
+ ...failedTx,
502
+ timestamp: Date.now()
503
+ };
504
+ // Fire and forget - don't block on backup
505
+ void this.failedTxStore.then((store)=>store?.saveFailedTx(tx)).catch((err)=>{
506
+ this.log.warn(`Failed to backup failed L1 tx to store`, err);
507
+ });
83
508
  }
84
509
  getRollupContract() {
85
510
  return this.rollupContract;
86
511
  }
512
+ /**
513
+ * Gets the fee asset price modifier from the oracle.
514
+ * Returns 0n if the oracle query fails.
515
+ */ getFeeAssetPriceModifier() {
516
+ return this.feeAssetPriceOracle.computePriceModifier();
517
+ }
87
518
  getSenderAddress() {
88
519
  return this.l1TxUtils.getSenderAddress();
89
520
  }
90
521
  /**
522
+ * Gets the L1 fee analyzer instance (only available in fisherman mode)
523
+ */ getL1FeeAnalyzer() {
524
+ return this.l1FeeAnalyzer;
525
+ }
526
+ /**
91
527
  * Sets the proposer address to use for simulations in fisherman mode.
92
528
  * @param proposerAddress - The actual proposer's address to use for balance lookups in simulations
93
529
  */ setProposerAddressForSimulation(proposerAddress) {
@@ -109,6 +545,46 @@ export class SequencerPublisher {
109
545
  }
110
546
  }
111
547
  /**
548
+ * Analyzes L1 fees for the pending requests without sending them.
549
+ * This is used in fisherman mode to validate fee calculations.
550
+ * @param l2SlotNumber - The L2 slot number for this analysis
551
+ * @param onComplete - Optional callback to invoke when analysis completes (after block is mined)
552
+ * @returns The analysis result (incomplete until block mines), or undefined if no requests
553
+ */ async analyzeL1Fees(l2SlotNumber, onComplete) {
554
+ if (!this.l1FeeAnalyzer) {
555
+ this.log.warn('L1 fee analyzer not available (not in fisherman mode)');
556
+ return undefined;
557
+ }
558
+ const requestsToAnalyze = [
559
+ ...this.requests
560
+ ];
561
+ if (requestsToAnalyze.length === 0) {
562
+ this.log.debug('No requests to analyze for L1 fees');
563
+ return undefined;
564
+ }
565
+ // Extract blob config from requests (if any)
566
+ const blobConfigs = requestsToAnalyze.filter((request)=>request.blobConfig).map((request)=>request.blobConfig);
567
+ const blobConfig = blobConfigs[0];
568
+ // Get gas configs
569
+ const gasConfigs = requestsToAnalyze.filter((request)=>request.gasConfig).map((request)=>request.gasConfig);
570
+ const gasLimits = gasConfigs.map((g)=>g?.gasLimit).filter((g)=>g !== undefined);
571
+ const gasLimit = gasLimits.length > 0 ? gasLimits.reduce((sum, g)=>sum + g, 0n) : 0n;
572
+ // Get the transaction requests
573
+ const l1Requests = requestsToAnalyze.map((r)=>r.request);
574
+ // Start the analysis
575
+ const analysisId = await this.l1FeeAnalyzer.startAnalysis(l2SlotNumber, gasLimit > 0n ? gasLimit : MAX_L1_TX_LIMIT, l1Requests, blobConfig, onComplete);
576
+ this.log.info('Started L1 fee analysis', {
577
+ analysisId,
578
+ l2SlotNumber: l2SlotNumber.toString(),
579
+ requestCount: requestsToAnalyze.length,
580
+ hasBlobConfig: !!blobConfig,
581
+ gasLimit: gasLimit.toString(),
582
+ actions: requestsToAnalyze.map((r)=>r.action)
583
+ });
584
+ // Return the analysis result (will be incomplete until block mines)
585
+ return this.l1FeeAnalyzer.getAnalysis(analysisId);
586
+ }
587
+ /**
112
588
  * Sends all requests that are still valid.
113
589
  * @returns one of:
114
590
  * - A receipt and stats if the tx succeeded
@@ -119,7 +595,7 @@ export class SequencerPublisher {
119
595
  ...this.requests
120
596
  ];
121
597
  this.requests = [];
122
- if (this.interrupted) {
598
+ if (this.interrupted || requestsToProcess.length === 0) {
123
599
  return undefined;
124
600
  }
125
601
  const currentL2Slot = this.getCurrentL2Slot();
@@ -154,7 +630,16 @@ export class SequencerPublisher {
154
630
  const blobConfig = blobConfigs[0];
155
631
  // Merge gasConfigs. Yields the sum of gasLimits, and the earliest txTimeoutAt, or undefined if no gasConfig sets them.
156
632
  const gasLimits = gasConfigs.map((g)=>g?.gasLimit).filter((g)=>g !== undefined);
157
- const gasLimit = gasLimits.length > 0 ? sumBigint(gasLimits) : undefined; // sum
633
+ let gasLimit = gasLimits.length > 0 ? sumBigint(gasLimits) : undefined; // sum
634
+ // Cap at L1 block gas limit so the node accepts the tx ("gas limit too high" otherwise).
635
+ const maxGas = MAX_L1_TX_LIMIT;
636
+ if (gasLimit !== undefined && gasLimit > maxGas) {
637
+ this.log.debug('Capping bundled tx gas limit to L1 max', {
638
+ requested: gasLimit,
639
+ capped: maxGas
640
+ });
641
+ gasLimit = maxGas;
642
+ }
158
643
  const txTimeoutAts = gasConfigs.map((g)=>g?.txTimeoutAt).filter((g)=>g !== undefined);
159
644
  const txTimeoutAt = txTimeoutAts.length > 0 ? new Date(Math.min(...txTimeoutAts.map((g)=>g.getTime()))) : undefined; // earliest
160
645
  const txConfig = {
@@ -165,12 +650,31 @@ export class SequencerPublisher {
165
650
  // This ensures the committee gets precomputed correctly
166
651
  validRequests.sort((a, b)=>compareActions(a.action, b.action));
167
652
  try {
653
+ // Capture context for failed tx backup before sending
654
+ const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
655
+ const multicallData = encodeFunctionData({
656
+ abi: multicall3Abi,
657
+ functionName: 'aggregate3',
658
+ args: [
659
+ validRequests.map((r)=>({
660
+ target: r.request.to,
661
+ callData: r.request.data,
662
+ allowFailure: true
663
+ }))
664
+ ]
665
+ });
666
+ const blobDataHex = blobConfig?.blobs?.map((b)=>toHex(b));
168
667
  this.log.debug('Forwarding transactions', {
169
668
  validRequests: validRequests.map((request)=>request.action),
170
669
  txConfig
171
670
  });
172
671
  const result = await Multicall3.forward(validRequests.map((request)=>request.request), this.l1TxUtils, txConfig, blobConfig, this.rollupContract.address, this.log);
173
- const { successfulActions = [], failedActions = [] } = this.callbackBundledTransactions(validRequests, result);
672
+ const txContext = {
673
+ multicallData,
674
+ blobData: blobDataHex,
675
+ l1BlockNumber
676
+ };
677
+ const { successfulActions = [], failedActions = [] } = this.callbackBundledTransactions(validRequests, result, txContext);
174
678
  return {
175
679
  result,
176
680
  expiredActions,
@@ -190,10 +694,33 @@ export class SequencerPublisher {
190
694
  }
191
695
  }
192
696
  }
193
- callbackBundledTransactions(requests, result) {
697
+ callbackBundledTransactions(requests, result, txContext) {
194
698
  const actionsListStr = requests.map((r)=>r.action).join(', ');
195
699
  if (result instanceof FormattedViemError) {
196
700
  this.log.error(`Failed to publish bundled transactions (${actionsListStr})`, result);
701
+ this.backupFailedTx({
702
+ id: keccak256(txContext.multicallData),
703
+ failureType: 'send-error',
704
+ request: {
705
+ to: MULTI_CALL_3_ADDRESS,
706
+ data: txContext.multicallData
707
+ },
708
+ blobData: txContext.blobData,
709
+ l1BlockNumber: txContext.l1BlockNumber.toString(),
710
+ error: {
711
+ message: result.message,
712
+ name: result.name
713
+ },
714
+ context: {
715
+ actions: requests.map((r)=>r.action),
716
+ requests: requests.map((r)=>({
717
+ action: r.action,
718
+ to: r.request.to,
719
+ data: r.request.data
720
+ })),
721
+ sender: this.getSenderAddress().toString()
722
+ }
723
+ });
197
724
  return {
198
725
  failedActions: requests.map((r)=>r.action)
199
726
  };
@@ -211,6 +738,37 @@ export class SequencerPublisher {
211
738
  failedActions.push(request.action);
212
739
  }
213
740
  }
741
+ // Single backup for the whole reverted tx
742
+ if (failedActions.length > 0 && result?.receipt?.status === 'reverted') {
743
+ this.backupFailedTx({
744
+ id: result.receipt.transactionHash,
745
+ failureType: 'revert',
746
+ request: {
747
+ to: MULTI_CALL_3_ADDRESS,
748
+ data: txContext.multicallData
749
+ },
750
+ blobData: txContext.blobData,
751
+ l1BlockNumber: result.receipt.blockNumber.toString(),
752
+ receipt: {
753
+ transactionHash: result.receipt.transactionHash,
754
+ blockNumber: result.receipt.blockNumber.toString(),
755
+ gasUsed: (result.receipt.gasUsed ?? 0n).toString(),
756
+ status: 'reverted'
757
+ },
758
+ error: {
759
+ message: result.errorMsg ?? 'Transaction reverted'
760
+ },
761
+ context: {
762
+ actions: failedActions,
763
+ requests: requests.filter((r)=>failedActions.includes(r.action)).map((r)=>({
764
+ action: r.action,
765
+ to: r.request.to,
766
+ data: r.request.data
767
+ })),
768
+ sender: this.getSenderAddress().toString()
769
+ }
770
+ });
771
+ }
214
772
  return {
215
773
  successfulActions,
216
774
  failedActions
@@ -229,7 +787,7 @@ export class SequencerPublisher {
229
787
  'InvalidArchive'
230
788
  ];
231
789
  return this.rollupContract.canProposeAtNextEthBlock(tipArchive.toBuffer(), msgSender.toString(), Number(this.ethereumSlotDuration), {
232
- forcePendingCheckpointNumber: opts.forcePendingBlockNumber
790
+ forcePendingCheckpointNumber: opts.forcePendingCheckpointNumber
233
791
  }).catch((err)=>{
234
792
  if (err instanceof FormattedViemError && ignoredErrors.find((e)=>err.message.includes(e))) {
235
793
  this.log.warn(`Failed canProposeAtTime check with ${ignoredErrors.find((e)=>err.message.includes(e))}`, {
@@ -257,11 +815,11 @@ export class SequencerPublisher {
257
815
  [],
258
816
  Signature.empty().toViemSignature(),
259
817
  `0x${'0'.repeat(64)}`,
260
- header.contentCommitment.blobsHash.toString(),
818
+ header.blobsHash.toString(),
261
819
  flags
262
820
  ];
263
821
  const ts = BigInt((await this.l1TxUtils.getBlock()).timestamp + this.ethereumSlotDuration);
264
- const stateOverrides = await this.rollupContract.makePendingCheckpointNumberOverride(opts?.forcePendingBlockNumber);
822
+ const stateOverrides = await this.rollupContract.makePendingCheckpointNumberOverride(opts?.forcePendingCheckpointNumber);
265
823
  let balance = 0n;
266
824
  if (this.config.fishermanMode) {
267
825
  // In fisherman mode, we can't know where the proposer is publishing from
@@ -288,34 +846,38 @@ export class SequencerPublisher {
288
846
  this.log.debug(`Simulated validateHeader`);
289
847
  }
290
848
  /**
291
- * Simulate making a call to invalidate a block with invalid attestations. Returns undefined if no need to invalidate.
292
- * @param block - The block to invalidate and the criteria for invalidation (as returned by the archiver)
293
- */ async simulateInvalidateBlock(validationResult) {
849
+ * Simulate making a call to invalidate a checkpoint with invalid attestations. Returns undefined if no need to invalidate.
850
+ * @param validationResult - The validation result indicating which checkpoint to invalidate (as returned by the archiver)
851
+ */ async simulateInvalidateCheckpoint(validationResult) {
294
852
  if (validationResult.valid) {
295
853
  return undefined;
296
854
  }
297
- const { reason, block } = validationResult;
298
- const blockNumber = block.blockNumber;
855
+ const { reason, checkpoint } = validationResult;
856
+ const checkpointNumber = checkpoint.checkpointNumber;
299
857
  const logData = {
300
- ...block,
858
+ ...checkpoint,
301
859
  reason
302
860
  };
303
- const currentBlockNumber = await this.rollupContract.getCheckpointNumber();
304
- if (currentBlockNumber < validationResult.block.blockNumber) {
305
- this.log.verbose(`Skipping block ${blockNumber} invalidation since it has already been removed from the pending chain`, {
306
- currentBlockNumber,
861
+ const currentCheckpointNumber = await this.rollupContract.getCheckpointNumber();
862
+ if (currentCheckpointNumber < checkpointNumber) {
863
+ this.log.verbose(`Skipping checkpoint ${checkpointNumber} invalidation since it has already been removed from the pending chain`, {
864
+ currentCheckpointNumber,
307
865
  ...logData
308
866
  });
309
867
  return undefined;
310
868
  }
311
- const request = this.buildInvalidateBlockRequest(validationResult);
312
- this.log.debug(`Simulating invalidate block ${blockNumber}`, {
869
+ const request = this.buildInvalidateCheckpointRequest(validationResult);
870
+ this.log.debug(`Simulating invalidate checkpoint ${checkpointNumber}`, {
313
871
  ...logData,
314
872
  request
315
873
  });
874
+ const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
316
875
  try {
317
- const { gasUsed } = await this.l1TxUtils.simulate(request, undefined, undefined, ErrorsAbi);
318
- this.log.verbose(`Simulation for invalidate block ${blockNumber} succeeded`, {
876
+ const { gasUsed } = await this.l1TxUtils.simulate(request, undefined, undefined, mergeAbis([
877
+ request.abi ?? [],
878
+ ErrorsAbi
879
+ ]));
880
+ this.log.verbose(`Simulation for invalidate checkpoint ${checkpointNumber} succeeded`, {
319
881
  ...logData,
320
882
  request,
321
883
  gasUsed
@@ -323,90 +885,92 @@ export class SequencerPublisher {
323
885
  return {
324
886
  request,
325
887
  gasUsed,
326
- blockNumber,
327
- forcePendingBlockNumber: blockNumber - 1,
888
+ checkpointNumber,
889
+ forcePendingCheckpointNumber: CheckpointNumber(checkpointNumber - 1),
328
890
  reason
329
891
  };
330
892
  } catch (err) {
331
893
  const viemError = formatViemError(err);
332
- // If the error is due to the block not being in the pending chain, and it was indeed removed by someone else,
333
- // we can safely ignore it and return undefined so we go ahead with block building.
334
- if (viemError.message?.includes('Rollup__BlockNotInPendingChain')) {
335
- this.log.verbose(`Simulation for invalidate block ${blockNumber} failed due to block not being in pending chain`, {
894
+ // If the error is due to the checkpoint not being in the pending chain, and it was indeed removed by someone else,
895
+ // we can safely ignore it and return undefined so we go ahead with checkpoint building.
896
+ if (viemError.message?.includes('Rollup__CheckpointNotInPendingChain')) {
897
+ this.log.verbose(`Simulation for invalidate checkpoint ${checkpointNumber} failed due to checkpoint not being in pending chain`, {
336
898
  ...logData,
337
899
  request,
338
900
  error: viemError.message
339
901
  });
340
- const latestPendingBlockNumber = await this.rollupContract.getCheckpointNumber();
341
- if (latestPendingBlockNumber < blockNumber) {
342
- this.log.verbose(`Block number ${blockNumber} has already been invalidated`, {
902
+ const latestPendingCheckpointNumber = await this.rollupContract.getCheckpointNumber();
903
+ if (latestPendingCheckpointNumber < checkpointNumber) {
904
+ this.log.verbose(`Checkpoint ${checkpointNumber} has already been invalidated`, {
343
905
  ...logData
344
906
  });
345
907
  return undefined;
346
908
  } else {
347
- this.log.error(`Simulation for invalidate ${blockNumber} failed and it is still in pending chain`, viemError, logData);
348
- throw new Error(`Failed to simulate invalidate block ${blockNumber} while it is still in pending chain`, {
909
+ this.log.error(`Simulation for invalidate checkpoint ${checkpointNumber} failed and it is still in pending chain`, viemError, logData);
910
+ throw new Error(`Failed to simulate invalidate checkpoint ${checkpointNumber} while it is still in pending chain`, {
349
911
  cause: viemError
350
912
  });
351
913
  }
352
914
  }
353
- // Otherwise, throw. We cannot build the next block if we cannot invalidate the previous one.
354
- this.log.error(`Simulation for invalidate block ${blockNumber} failed`, viemError, logData);
355
- throw new Error(`Failed to simulate invalidate block ${blockNumber}`, {
915
+ // Otherwise, throw. We cannot build the next checkpoint if we cannot invalidate the previous one.
916
+ this.log.error(`Simulation for invalidate checkpoint ${checkpointNumber} failed`, viemError, logData);
917
+ this.backupFailedTx({
918
+ id: keccak256(request.data),
919
+ failureType: 'simulation',
920
+ request: {
921
+ to: request.to,
922
+ data: request.data,
923
+ value: request.value?.toString()
924
+ },
925
+ l1BlockNumber: l1BlockNumber.toString(),
926
+ error: {
927
+ message: viemError.message,
928
+ name: viemError.name
929
+ },
930
+ context: {
931
+ actions: [
932
+ `invalidate-${reason}`
933
+ ],
934
+ checkpointNumber,
935
+ sender: this.getSenderAddress().toString()
936
+ }
937
+ });
938
+ throw new Error(`Failed to simulate invalidate checkpoint ${checkpointNumber}`, {
356
939
  cause: viemError
357
940
  });
358
941
  }
359
942
  }
360
- buildInvalidateBlockRequest(validationResult) {
943
+ buildInvalidateCheckpointRequest(validationResult) {
361
944
  if (validationResult.valid) {
362
- throw new Error('Cannot invalidate a valid block');
945
+ throw new Error('Cannot invalidate a valid checkpoint');
363
946
  }
364
- const { block, committee, reason } = validationResult;
947
+ const { checkpoint, committee, reason } = validationResult;
365
948
  const logData = {
366
- ...block,
949
+ ...checkpoint,
367
950
  reason
368
951
  };
369
- this.log.debug(`Simulating invalidate block ${block.blockNumber}`, logData);
952
+ this.log.debug(`Building invalidate checkpoint ${checkpoint.checkpointNumber} request`, logData);
370
953
  const attestationsAndSigners = new CommitteeAttestationsAndSigners(validationResult.attestations).getPackedAttestations();
371
954
  if (reason === 'invalid-attestation') {
372
- return this.rollupContract.buildInvalidateBadAttestationRequest(block.blockNumber, attestationsAndSigners, committee, validationResult.invalidIndex);
955
+ return this.rollupContract.buildInvalidateBadAttestationRequest(checkpoint.checkpointNumber, attestationsAndSigners, committee, validationResult.invalidIndex);
373
956
  } else if (reason === 'insufficient-attestations') {
374
- return this.rollupContract.buildInvalidateInsufficientAttestationsRequest(block.blockNumber, attestationsAndSigners, committee);
957
+ return this.rollupContract.buildInvalidateInsufficientAttestationsRequest(checkpoint.checkpointNumber, attestationsAndSigners, committee);
375
958
  } else {
376
959
  const _ = reason;
377
960
  throw new Error(`Unknown reason for invalidation`);
378
961
  }
379
962
  }
380
- /**
381
- * @notice Will simulate `propose` to make sure that the block is valid for submission
382
- *
383
- * @dev Throws if unable to propose
384
- *
385
- * @param block - The block to propose
386
- * @param attestationData - The block's attestation data
387
- *
388
- */ async validateBlockForSubmission(block, attestationsAndSigners, attestationsAndSignersSignature, options) {
963
+ /** Simulates `propose` to make sure that the checkpoint is valid for submission */ async validateCheckpointForSubmission(checkpoint, attestationsAndSigners, attestationsAndSignersSignature, options) {
389
964
  const ts = BigInt((await this.l1TxUtils.getBlock()).timestamp + this.ethereumSlotDuration);
390
- // If we have no attestations, we still need to provide the empty attestations
391
- // so that the committee is recalculated correctly
392
- const ignoreSignatures = attestationsAndSigners.attestations.length === 0;
393
- if (ignoreSignatures) {
394
- const { committee } = await this.epochCache.getCommittee(block.header.globalVariables.slotNumber);
395
- if (!committee) {
396
- this.log.warn(`No committee found for slot ${block.header.globalVariables.slotNumber}`);
397
- throw new Error(`No committee found for slot ${block.header.globalVariables.slotNumber}`);
398
- }
399
- attestationsAndSigners.attestations = committee.map((committeeMember)=>CommitteeAttestation.fromAddress(committeeMember));
400
- }
401
- const blobFields = block.getCheckpointBlobFields();
402
- const blobs = getBlobsPerL1Block(blobFields);
965
+ const blobFields = checkpoint.toBlobFields();
966
+ const blobs = await getBlobsPerL1Block(blobFields);
403
967
  const blobInput = getPrefixedEthBlobCommitments(blobs);
404
968
  const args = [
405
969
  {
406
- header: block.getCheckpointHeader().toViem(),
407
- archive: toHex(block.archive.root.toBuffer()),
970
+ header: checkpoint.header.toViem(),
971
+ archive: toHex(checkpoint.archive.root.toBuffer()),
408
972
  oracleInput: {
409
- feeAssetPriceModifier: 0n
973
+ feeAssetPriceModifier: checkpoint.feeAssetPriceModifier
410
974
  }
411
975
  },
412
976
  attestationsAndSigners.getPackedAttestations(),
@@ -431,9 +995,38 @@ export class SequencerPublisher {
431
995
  }
432
996
  const round = await base.computeRound(slotNumber);
433
997
  const roundInfo = await base.getRoundInfo(this.rollupContract.address, round);
998
+ if (roundInfo.quorumReached) {
999
+ return false;
1000
+ }
434
1001
  if (roundInfo.lastSignalSlot >= slotNumber) {
435
1002
  return false;
436
1003
  }
1004
+ if (await this.isPayloadEmpty(payload)) {
1005
+ this.log.warn(`Skipping vote cast for payload with empty code`);
1006
+ return false;
1007
+ }
1008
+ // Check if payload was already submitted to governance
1009
+ const cacheKey = payload.toString();
1010
+ if (!this.payloadProposedCache.has(cacheKey)) {
1011
+ try {
1012
+ const l1StartBlock = await this.rollupContract.getL1StartBlock();
1013
+ const proposed = await retry(()=>base.hasPayloadBeenProposed(payload.toString(), l1StartBlock), 'Check if payload was proposed', makeBackoff([
1014
+ 0,
1015
+ 1,
1016
+ 2
1017
+ ]), this.log, true);
1018
+ if (proposed) {
1019
+ this.payloadProposedCache.add(cacheKey);
1020
+ }
1021
+ } catch (err) {
1022
+ this.log.warn(`Failed to check if payload ${payload} was proposed after retries, skipping signal`, err);
1023
+ return false;
1024
+ }
1025
+ }
1026
+ if (this.payloadProposedCache.has(cacheKey)) {
1027
+ this.log.info(`Payload ${payload} was already proposed to governance, stopping signals`);
1028
+ return false;
1029
+ }
437
1030
  const cachedLastVote = this.lastActions[signalType];
438
1031
  this.lastActions[signalType] = slotNumber;
439
1032
  const action = signalType;
@@ -444,15 +1037,41 @@ export class SequencerPublisher {
444
1037
  signer: this.l1TxUtils.client.account?.address,
445
1038
  lastValidL2Slot: slotNumber
446
1039
  });
1040
+ const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
447
1041
  try {
448
1042
  await this.l1TxUtils.simulate(request, {
449
1043
  time: timestamp
450
- }, [], ErrorsAbi);
1044
+ }, [], mergeAbis([
1045
+ request.abi ?? [],
1046
+ ErrorsAbi
1047
+ ]));
451
1048
  this.log.debug(`Simulation for ${action} at slot ${slotNumber} succeeded`, {
452
1049
  request
453
1050
  });
454
1051
  } catch (err) {
455
- this.log.error(`Failed simulation for ${action} at slot ${slotNumber} (enqueuing the action anyway)`, err);
1052
+ const viemError = formatViemError(err);
1053
+ this.log.error(`Failed simulation for ${action} at slot ${slotNumber} (enqueuing the action anyway)`, viemError);
1054
+ this.backupFailedTx({
1055
+ id: keccak256(request.data),
1056
+ failureType: 'simulation',
1057
+ request: {
1058
+ to: request.to,
1059
+ data: request.data,
1060
+ value: request.value?.toString()
1061
+ },
1062
+ l1BlockNumber: l1BlockNumber.toString(),
1063
+ error: {
1064
+ message: viemError.message,
1065
+ name: viemError.name
1066
+ },
1067
+ context: {
1068
+ actions: [
1069
+ action
1070
+ ],
1071
+ slot: slotNumber,
1072
+ sender: this.getSenderAddress().toString()
1073
+ }
1074
+ });
456
1075
  // Yes, we enqueue the request anyway, in case there was a bug with the simulation itself
457
1076
  }
458
1077
  // TODO(palla/slash): All votes (governance and slashing) should txTimeoutAt at the end of the slot.
@@ -472,17 +1091,27 @@ export class SequencerPublisher {
472
1091
  payload: payload.toString()
473
1092
  };
474
1093
  if (!success) {
475
- this.log.error(`Signaling in [${action}] for ${payload} at slot ${slotNumber} in round ${round} failed`, logData);
1094
+ this.log.error(`Signaling in ${action} for ${payload} at slot ${slotNumber} in round ${round} failed`, logData);
476
1095
  this.lastActions[signalType] = cachedLastVote;
477
1096
  return false;
478
1097
  } else {
479
- this.log.info(`Signaling in [${action}] for ${payload} at slot ${slotNumber} in round ${round} succeeded`, logData);
1098
+ this.log.info(`Signaling in ${action} for ${payload} at slot ${slotNumber} in round ${round} succeeded`, logData);
480
1099
  return true;
481
1100
  }
482
1101
  }
483
1102
  });
484
1103
  return true;
485
1104
  }
1105
+ async isPayloadEmpty(payload) {
1106
+ const key = payload.toString();
1107
+ const cached = this.isPayloadEmptyCache.get(key);
1108
+ if (cached) {
1109
+ return cached;
1110
+ }
1111
+ const isEmpty = !await this.l1TxUtils.getCode(payload);
1112
+ this.isPayloadEmptyCache.set(key, isEmpty);
1113
+ return isEmpty;
1114
+ }
486
1115
  /**
487
1116
  * Enqueues a governance castSignal transaction to cast a signal for a given slot number.
488
1117
  * @param slotNumber - The slot number to cast a signal for.
@@ -578,22 +1207,17 @@ export class SequencerPublisher {
578
1207
  }
579
1208
  return true;
580
1209
  }
581
- /**
582
- * Proposes a L2 block on L1.
583
- *
584
- * @param block - L2 block to propose.
585
- * @returns True if the tx has been enqueued, throws otherwise. See #9315
586
- */ async enqueueProposeL2Block(block, attestationsAndSigners, attestationsAndSignersSignature, opts = {}) {
587
- const checkpointHeader = block.getCheckpointHeader();
588
- const blobFields = block.getCheckpointBlobFields();
589
- const blobs = getBlobsPerL1Block(blobFields);
1210
+ /** Simulates and enqueues a proposal for a checkpoint on L1 */ async enqueueProposeCheckpoint(checkpoint, attestationsAndSigners, attestationsAndSignersSignature, opts = {}) {
1211
+ const checkpointHeader = checkpoint.header;
1212
+ const blobFields = checkpoint.toBlobFields();
1213
+ const blobs = await getBlobsPerL1Block(blobFields);
590
1214
  const proposeTxArgs = {
591
1215
  header: checkpointHeader,
592
- archive: block.archive.root.toBuffer(),
593
- body: block.body.toBuffer(),
1216
+ archive: checkpoint.archive.root.toBuffer(),
594
1217
  blobs,
595
1218
  attestationsAndSigners,
596
- attestationsAndSignersSignature
1219
+ attestationsAndSignersSignature,
1220
+ feeAssetPriceModifier: checkpoint.feeAssetPriceModifier
597
1221
  };
598
1222
  let ts;
599
1223
  try {
@@ -602,36 +1226,35 @@ export class SequencerPublisher {
602
1226
  // By simulation issue, I mean the fact that the block.timestamp is equal to the last block, not the next, which
603
1227
  // make time consistency checks break.
604
1228
  // TODO(palla): Check whether we're validating twice, once here and once within addProposeTx, since we call simulateProposeTx in both places.
605
- ts = await this.validateBlockForSubmission(block, attestationsAndSigners, attestationsAndSignersSignature, opts);
1229
+ ts = await this.validateCheckpointForSubmission(checkpoint, attestationsAndSigners, attestationsAndSignersSignature, opts);
606
1230
  } catch (err) {
607
- this.log.error(`Block validation failed. ${err instanceof Error ? err.message : 'No error message'}`, err, {
608
- ...block.getStats(),
609
- slotNumber: block.header.globalVariables.slotNumber,
610
- forcePendingBlockNumber: opts.forcePendingBlockNumber
1231
+ this.log.error(`Checkpoint validation failed. ${err instanceof Error ? err.message : 'No error message'}`, err, {
1232
+ ...checkpoint.getStats(),
1233
+ slotNumber: checkpoint.header.slotNumber,
1234
+ forcePendingCheckpointNumber: opts.forcePendingCheckpointNumber
611
1235
  });
612
1236
  throw err;
613
1237
  }
614
- this.log.verbose(`Enqueuing block propose transaction`, {
615
- ...block.toBlockInfo(),
1238
+ this.log.verbose(`Enqueuing checkpoint propose transaction`, {
1239
+ ...checkpoint.toCheckpointInfo(),
616
1240
  ...opts
617
1241
  });
618
- await this.addProposeTx(block, proposeTxArgs, opts, ts);
619
- return true;
1242
+ await this.addProposeTx(checkpoint, proposeTxArgs, opts, ts);
620
1243
  }
621
- enqueueInvalidateBlock(request, opts = {}) {
1244
+ enqueueInvalidateCheckpoint(request, opts = {}) {
622
1245
  if (!request) {
623
1246
  return;
624
1247
  }
625
1248
  // We issued the simulation against the rollup contract, so we need to account for the overhead of the multicall3
626
1249
  const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(request.gasUsed) * 64 / 63)));
627
- const { gasUsed, blockNumber } = request;
1250
+ const { gasUsed, checkpointNumber } = request;
628
1251
  const logData = {
629
1252
  gasUsed,
630
- blockNumber,
1253
+ checkpointNumber,
631
1254
  gasLimit,
632
1255
  opts
633
1256
  };
634
- this.log.verbose(`Enqueuing invalidate block request`, logData);
1257
+ this.log.verbose(`Enqueuing invalidate checkpoint request`, logData);
635
1258
  this.addRequest({
636
1259
  action: `invalidate-by-${request.reason}`,
637
1260
  request: request.request,
@@ -643,12 +1266,12 @@ export class SequencerPublisher {
643
1266
  checkSuccess: (_req, result)=>{
644
1267
  const success = result && result.receipt && result.receipt.status === 'success' && tryExtractEvent(result.receipt.logs, this.rollupContract.address, RollupAbi, 'CheckpointInvalidated');
645
1268
  if (!success) {
646
- this.log.warn(`Invalidate block ${request.blockNumber} failed`, {
1269
+ this.log.warn(`Invalidate checkpoint ${request.checkpointNumber} failed`, {
647
1270
  ...result,
648
1271
  ...logData
649
1272
  });
650
1273
  } else {
651
- this.log.info(`Invalidate block ${request.blockNumber} succeeded`, {
1274
+ this.log.info(`Invalidate checkpoint ${request.checkpointNumber} succeeded`, {
652
1275
  ...result,
653
1276
  ...logData
654
1277
  });
@@ -670,28 +1293,60 @@ export class SequencerPublisher {
670
1293
  const cachedLastActionSlot = this.lastActions[action];
671
1294
  this.lastActions[action] = slotNumber;
672
1295
  this.log.debug(`Simulating ${action} for slot ${slotNumber}`, logData);
1296
+ const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
673
1297
  let gasUsed;
1298
+ const simulateAbi = mergeAbis([
1299
+ request.abi ?? [],
1300
+ ErrorsAbi
1301
+ ]);
674
1302
  try {
675
1303
  ({ gasUsed } = await this.l1TxUtils.simulate(request, {
676
1304
  time: timestamp
677
- }, [], ErrorsAbi)); // TODO(palla/slash): Check the timestamp logic
1305
+ }, [], simulateAbi)); // TODO(palla/slash): Check the timestamp logic
678
1306
  this.log.verbose(`Simulation for ${action} succeeded`, {
679
1307
  ...logData,
680
1308
  request,
681
1309
  gasUsed
682
1310
  });
683
1311
  } catch (err) {
684
- const viemError = formatViemError(err);
1312
+ const viemError = formatViemError(err, simulateAbi);
685
1313
  this.log.error(`Simulation for ${action} at ${slotNumber} failed`, viemError, logData);
1314
+ this.backupFailedTx({
1315
+ id: keccak256(request.data),
1316
+ failureType: 'simulation',
1317
+ request: {
1318
+ to: request.to,
1319
+ data: request.data,
1320
+ value: request.value?.toString()
1321
+ },
1322
+ l1BlockNumber: l1BlockNumber.toString(),
1323
+ error: {
1324
+ message: viemError.message,
1325
+ name: viemError.name
1326
+ },
1327
+ context: {
1328
+ actions: [
1329
+ action
1330
+ ],
1331
+ slot: slotNumber,
1332
+ sender: this.getSenderAddress().toString()
1333
+ }
1334
+ });
686
1335
  return false;
687
1336
  }
688
1337
  // We issued the simulation against the rollup contract, so we need to account for the overhead of the multicall3
689
1338
  const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(gasUsed) * 64 / 63)));
690
1339
  logData.gasLimit = gasLimit;
1340
+ // Store the ABI used for simulation on the request so Multicall3.forward can decode errors
1341
+ // when the tx is sent and a revert is diagnosed via simulation.
1342
+ const requestWithAbi = {
1343
+ ...request,
1344
+ abi: simulateAbi
1345
+ };
691
1346
  this.log.debug(`Enqueuing ${action}`, logData);
692
1347
  this.addRequest({
693
1348
  action,
694
- request,
1349
+ request: requestWithAbi,
695
1350
  gasConfig: {
696
1351
  gasLimit
697
1352
  },
@@ -755,10 +1410,38 @@ export class SequencerPublisher {
755
1410
  }, {}, {
756
1411
  blobs: encodedData.blobs.map((b)=>b.data),
757
1412
  kzg
758
- }).catch((err)=>{
759
- const { message, metaMessages } = formatViemError(err);
760
- this.log.error(`Failed to validate blobs`, message, {
761
- metaMessages
1413
+ }).catch(async (err)=>{
1414
+ const viemError = formatViemError(err);
1415
+ this.log.error(`Failed to validate blobs`, viemError.message, {
1416
+ metaMessages: viemError.metaMessages
1417
+ });
1418
+ const validateBlobsData = encodeFunctionData({
1419
+ abi: RollupAbi,
1420
+ functionName: 'validateBlobs',
1421
+ args: [
1422
+ blobInput
1423
+ ]
1424
+ });
1425
+ const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
1426
+ this.backupFailedTx({
1427
+ id: keccak256(validateBlobsData),
1428
+ failureType: 'simulation',
1429
+ request: {
1430
+ to: this.rollupContract.address,
1431
+ data: validateBlobsData
1432
+ },
1433
+ blobData: encodedData.blobs.map((b)=>toHex(b.data)),
1434
+ l1BlockNumber: l1BlockNumber.toString(),
1435
+ error: {
1436
+ message: viemError.message,
1437
+ name: viemError.name
1438
+ },
1439
+ context: {
1440
+ actions: [
1441
+ 'validate-blobs'
1442
+ ],
1443
+ sender: this.getSenderAddress().toString()
1444
+ }
762
1445
  });
763
1446
  throw new Error('Failed to validate blobs');
764
1447
  });
@@ -769,8 +1452,7 @@ export class SequencerPublisher {
769
1452
  header: encodedData.header.toViem(),
770
1453
  archive: toHex(encodedData.archive),
771
1454
  oracleInput: {
772
- // We are currently not modifying these. See #9963
773
- feeAssetPriceModifier: 0n
1455
+ feeAssetPriceModifier: encodedData.feeAssetPriceModifier
774
1456
  }
775
1457
  },
776
1458
  encodedData.attestationsAndSigners.getPackedAttestations(),
@@ -797,8 +1479,8 @@ export class SequencerPublisher {
797
1479
  functionName: 'propose',
798
1480
  args
799
1481
  });
800
- // override the pending block number if requested
801
- const forcePendingBlockNumberStateDiff = (options.forcePendingBlockNumber !== undefined ? await this.rollupContract.makePendingCheckpointNumberOverride(options.forcePendingBlockNumber) : []).flatMap((override)=>override.stateDiff ?? []);
1482
+ // override the pending checkpoint number if requested
1483
+ const forcePendingCheckpointNumberStateDiff = (options.forcePendingCheckpointNumber !== undefined ? await this.rollupContract.makePendingCheckpointNumberOverride(options.forcePendingCheckpointNumber) : []).flatMap((override)=>override.stateDiff ?? []);
802
1484
  const stateOverrides = [
803
1485
  {
804
1486
  address: this.rollupContract.address,
@@ -808,7 +1490,7 @@ export class SequencerPublisher {
808
1490
  slot: toPaddedHex(RollupContract.checkBlobStorageSlot, true),
809
1491
  value: toPaddedHex(0n, true)
810
1492
  },
811
- ...forcePendingBlockNumberStateDiff
1493
+ ...forcePendingCheckpointNumberStateDiff
812
1494
  ]
813
1495
  }
814
1496
  ];
@@ -819,10 +1501,11 @@ export class SequencerPublisher {
819
1501
  balance: 10n * WEI_CONST * WEI_CONST
820
1502
  });
821
1503
  }
1504
+ const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
822
1505
  const simulationResult = await this.l1TxUtils.simulate({
823
1506
  to: this.rollupContract.address,
824
1507
  data: rollupData,
825
- gas: SequencerPublisher.PROPOSE_GAS_GUESS,
1508
+ gas: MAX_L1_TX_LIMIT,
826
1509
  ...this.proposerAddressForSimulation && {
827
1510
  from: this.proposerAddressForSimulation.toString()
828
1511
  }
@@ -830,10 +1513,10 @@ export class SequencerPublisher {
830
1513
  // @note we add 1n to the timestamp because geth implementation doesn't like simulation timestamp to be equal to the current block timestamp
831
1514
  time: timestamp + 1n,
832
1515
  // @note reth should have a 30m gas limit per block but throws errors that this tx is beyond limit so we increase here
833
- gasLimit: SequencerPublisher.PROPOSE_GAS_GUESS * 2n
1516
+ gasLimit: MAX_L1_TX_LIMIT * 2n
834
1517
  }, stateOverrides, RollupAbi, {
835
1518
  // @note fallback gas estimate to use if the node doesn't support simulation API
836
- fallbackGasEstimate: SequencerPublisher.PROPOSE_GAS_GUESS
1519
+ fallbackGasEstimate: MAX_L1_TX_LIMIT
837
1520
  }).catch((err)=>{
838
1521
  // In fisherman mode, we expect ValidatorSelection__MissingProposerSignature since fisherman doesn't have proposer signature
839
1522
  const viemError = formatViemError(err);
@@ -841,11 +1524,31 @@ export class SequencerPublisher {
841
1524
  this.log.debug(`Ignoring expected ValidatorSelection__MissingProposerSignature error in fisherman mode`);
842
1525
  // Return a minimal simulation result with the fallback gas estimate
843
1526
  return {
844
- gasUsed: SequencerPublisher.PROPOSE_GAS_GUESS,
1527
+ gasUsed: MAX_L1_TX_LIMIT,
845
1528
  logs: []
846
1529
  };
847
1530
  }
848
1531
  this.log.error(`Failed to simulate propose tx`, viemError);
1532
+ this.backupFailedTx({
1533
+ id: keccak256(rollupData),
1534
+ failureType: 'simulation',
1535
+ request: {
1536
+ to: this.rollupContract.address,
1537
+ data: rollupData
1538
+ },
1539
+ l1BlockNumber: l1BlockNumber.toString(),
1540
+ error: {
1541
+ message: viemError.message,
1542
+ name: viemError.name
1543
+ },
1544
+ context: {
1545
+ actions: [
1546
+ 'propose'
1547
+ ],
1548
+ slot: Number(args[0].header.slotNumber),
1549
+ sender: this.getSenderAddress().toString()
1550
+ }
1551
+ });
849
1552
  throw err;
850
1553
  });
851
1554
  return {
@@ -853,24 +1556,25 @@ export class SequencerPublisher {
853
1556
  simulationResult
854
1557
  };
855
1558
  }
856
- async addProposeTx(block, encodedData, opts = {}, timestamp) {
1559
+ async addProposeTx(checkpoint, encodedData, opts = {}, timestamp) {
1560
+ const slot = checkpoint.header.slotNumber;
857
1561
  const timer = new Timer();
858
1562
  const kzg = Blob.getViemKzgInstance();
859
1563
  const { rollupData, simulationResult, blobEvaluationGas } = await this.prepareProposeTx(encodedData, timestamp, opts);
860
1564
  const startBlock = await this.l1TxUtils.getBlockNumber();
861
1565
  const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(simulationResult.gasUsed) * 64 / 63)) + blobEvaluationGas + SequencerPublisher.MULTICALL_OVERHEAD_GAS_GUESS);
862
- // Send the blobs to the blob sink preemptively. This helps in tests where the sequencer mistakingly thinks that the propose
863
- // tx fails but it does get mined. We make sure that the blobs are sent to the blob sink regardless of the tx outcome.
864
- void this.blobSinkClient.sendBlobsToBlobSink(encodedData.blobs).catch((_err)=>{
865
- this.log.error('Failed to send blobs to blob sink');
866
- });
1566
+ // Send the blobs to the blob client preemptively. This helps in tests where the sequencer mistakingly thinks that the propose
1567
+ // tx fails but it does get mined. We make sure that the blobs are sent to the blob client regardless of the tx outcome.
1568
+ void Promise.resolve().then(()=>this.blobClient.sendBlobsToFilestore(encodedData.blobs).catch((_err)=>{
1569
+ this.log.error('Failed to send blobs to blob client');
1570
+ }));
867
1571
  return this.addRequest({
868
1572
  action: 'propose',
869
1573
  request: {
870
1574
  to: this.rollupContract.address,
871
1575
  data: rollupData
872
1576
  },
873
- lastValidL2Slot: block.header.globalVariables.slotNumber,
1577
+ lastValidL2Slot: checkpoint.header.slotNumber,
874
1578
  gasConfig: {
875
1579
  ...opts,
876
1580
  gasLimit
@@ -898,25 +1602,23 @@ export class SequencerPublisher {
898
1602
  calldataGas,
899
1603
  calldataSize,
900
1604
  sender,
901
- ...block.getStats(),
1605
+ ...checkpoint.getStats(),
902
1606
  eventName: 'rollup-published-to-l1',
903
1607
  blobCount: encodedData.blobs.length,
904
1608
  inclusionBlocks
905
1609
  };
906
- this.log.info(`Published L2 block to L1 rollup contract`, {
1610
+ this.log.info(`Published checkpoint ${checkpoint.number} at slot ${slot} to rollup contract`, {
907
1611
  ...stats,
908
- ...block.getStats(),
909
- ...receipt
1612
+ ...checkpoint.getStats(),
1613
+ ...pick(receipt, 'transactionHash', 'blockHash')
910
1614
  });
911
1615
  this.metrics.recordProcessBlockTx(timer.ms(), publishStats);
912
1616
  return true;
913
1617
  } else {
914
1618
  this.metrics.recordFailedTx('process');
915
- this.log.error(`Rollup process tx failed: ${errorMsg ?? 'no error message'}`, undefined, {
916
- ...block.getStats(),
917
- receipt,
918
- txHash: receipt.transactionHash,
919
- slotNumber: block.header.globalVariables.slotNumber
1619
+ this.log.error(`Publishing checkpoint at slot ${slot} failed with ${errorMsg ?? 'no error message'}`, undefined, {
1620
+ ...checkpoint.getStats(),
1621
+ ...receipt
920
1622
  });
921
1623
  return false;
922
1624
  }