@aztec/sequencer-client 0.0.0-test.1 → 0.0.1-commit.1142ef1

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 (139) hide show
  1. package/dest/client/index.d.ts +1 -1
  2. package/dest/client/sequencer-client.d.ts +31 -31
  3. package/dest/client/sequencer-client.d.ts.map +1 -1
  4. package/dest/client/sequencer-client.js +82 -60
  5. package/dest/config.d.ts +15 -16
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +120 -70
  8. package/dest/global_variable_builder/global_builder.d.ts +26 -15
  9. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  10. package/dest/global_variable_builder/global_builder.js +62 -44
  11. package/dest/global_variable_builder/index.d.ts +1 -1
  12. package/dest/index.d.ts +2 -4
  13. package/dest/index.d.ts.map +1 -1
  14. package/dest/index.js +1 -3
  15. package/dest/publisher/config.d.ts +15 -12
  16. package/dest/publisher/config.d.ts.map +1 -1
  17. package/dest/publisher/config.js +32 -19
  18. package/dest/publisher/index.d.ts +3 -1
  19. package/dest/publisher/index.d.ts.map +1 -1
  20. package/dest/publisher/index.js +3 -0
  21. package/dest/publisher/sequencer-publisher-factory.d.ts +44 -0
  22. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -0
  23. package/dest/publisher/sequencer-publisher-factory.js +51 -0
  24. package/dest/publisher/sequencer-publisher-metrics.d.ts +5 -4
  25. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  26. package/dest/publisher/sequencer-publisher-metrics.js +26 -62
  27. package/dest/publisher/sequencer-publisher.d.ts +134 -87
  28. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  29. package/dest/publisher/sequencer-publisher.js +1146 -249
  30. package/dest/sequencer/block_builder.d.ts +26 -0
  31. package/dest/sequencer/block_builder.d.ts.map +1 -0
  32. package/dest/sequencer/block_builder.js +129 -0
  33. package/dest/sequencer/checkpoint_proposal_job.d.ts +77 -0
  34. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  35. package/dest/sequencer/checkpoint_proposal_job.js +1089 -0
  36. package/dest/sequencer/checkpoint_voter.d.ts +34 -0
  37. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  38. package/dest/sequencer/checkpoint_voter.js +85 -0
  39. package/dest/sequencer/config.d.ts +7 -1
  40. package/dest/sequencer/config.d.ts.map +1 -1
  41. package/dest/sequencer/errors.d.ts +11 -0
  42. package/dest/sequencer/errors.d.ts.map +1 -0
  43. package/dest/sequencer/errors.js +15 -0
  44. package/dest/sequencer/events.d.ts +46 -0
  45. package/dest/sequencer/events.d.ts.map +1 -0
  46. package/dest/sequencer/events.js +1 -0
  47. package/dest/sequencer/index.d.ts +5 -2
  48. package/dest/sequencer/index.d.ts.map +1 -1
  49. package/dest/sequencer/index.js +4 -1
  50. package/dest/sequencer/metrics.d.ts +48 -12
  51. package/dest/sequencer/metrics.d.ts.map +1 -1
  52. package/dest/sequencer/metrics.js +204 -69
  53. package/dest/sequencer/sequencer.d.ts +136 -137
  54. package/dest/sequencer/sequencer.d.ts.map +1 -1
  55. package/dest/sequencer/sequencer.js +913 -527
  56. package/dest/sequencer/timetable.d.ts +76 -24
  57. package/dest/sequencer/timetable.d.ts.map +1 -1
  58. package/dest/sequencer/timetable.js +177 -61
  59. package/dest/sequencer/types.d.ts +3 -0
  60. package/dest/sequencer/types.d.ts.map +1 -0
  61. package/dest/sequencer/types.js +1 -0
  62. package/dest/sequencer/utils.d.ts +20 -38
  63. package/dest/sequencer/utils.d.ts.map +1 -1
  64. package/dest/sequencer/utils.js +12 -47
  65. package/dest/test/index.d.ts +9 -1
  66. package/dest/test/index.d.ts.map +1 -1
  67. package/dest/test/index.js +0 -4
  68. package/dest/test/mock_checkpoint_builder.d.ts +91 -0
  69. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  70. package/dest/test/mock_checkpoint_builder.js +202 -0
  71. package/dest/test/utils.d.ts +53 -0
  72. package/dest/test/utils.d.ts.map +1 -0
  73. package/dest/test/utils.js +103 -0
  74. package/package.json +45 -45
  75. package/src/client/sequencer-client.ts +106 -107
  76. package/src/config.ts +133 -81
  77. package/src/global_variable_builder/global_builder.ts +84 -55
  78. package/src/index.ts +6 -3
  79. package/src/publisher/config.ts +45 -32
  80. package/src/publisher/index.ts +4 -0
  81. package/src/publisher/sequencer-publisher-factory.ts +92 -0
  82. package/src/publisher/sequencer-publisher-metrics.ts +30 -64
  83. package/src/publisher/sequencer-publisher.ts +967 -295
  84. package/src/sequencer/README.md +531 -0
  85. package/src/sequencer/block_builder.ts +216 -0
  86. package/src/sequencer/checkpoint_proposal_job.ts +742 -0
  87. package/src/sequencer/checkpoint_voter.ts +105 -0
  88. package/src/sequencer/config.ts +8 -0
  89. package/src/sequencer/errors.ts +21 -0
  90. package/src/sequencer/events.ts +27 -0
  91. package/src/sequencer/index.ts +4 -1
  92. package/src/sequencer/metrics.ts +269 -72
  93. package/src/sequencer/sequencer.ts +640 -592
  94. package/src/sequencer/timetable.ts +221 -62
  95. package/src/sequencer/types.ts +6 -0
  96. package/src/sequencer/utils.ts +28 -60
  97. package/src/test/index.ts +12 -4
  98. package/src/test/mock_checkpoint_builder.ts +279 -0
  99. package/src/test/utils.ts +157 -0
  100. package/dest/sequencer/allowed.d.ts +0 -3
  101. package/dest/sequencer/allowed.d.ts.map +0 -1
  102. package/dest/sequencer/allowed.js +0 -27
  103. package/dest/slasher/factory.d.ts +0 -7
  104. package/dest/slasher/factory.d.ts.map +0 -1
  105. package/dest/slasher/factory.js +0 -8
  106. package/dest/slasher/index.d.ts +0 -3
  107. package/dest/slasher/index.d.ts.map +0 -1
  108. package/dest/slasher/index.js +0 -2
  109. package/dest/slasher/slasher_client.d.ts +0 -75
  110. package/dest/slasher/slasher_client.d.ts.map +0 -1
  111. package/dest/slasher/slasher_client.js +0 -132
  112. package/dest/tx_validator/archive_cache.d.ts +0 -14
  113. package/dest/tx_validator/archive_cache.d.ts.map +0 -1
  114. package/dest/tx_validator/archive_cache.js +0 -22
  115. package/dest/tx_validator/gas_validator.d.ts +0 -14
  116. package/dest/tx_validator/gas_validator.d.ts.map +0 -1
  117. package/dest/tx_validator/gas_validator.js +0 -78
  118. package/dest/tx_validator/nullifier_cache.d.ts +0 -16
  119. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  120. package/dest/tx_validator/nullifier_cache.js +0 -24
  121. package/dest/tx_validator/phases_validator.d.ts +0 -12
  122. package/dest/tx_validator/phases_validator.d.ts.map +0 -1
  123. package/dest/tx_validator/phases_validator.js +0 -80
  124. package/dest/tx_validator/test_utils.d.ts +0 -23
  125. package/dest/tx_validator/test_utils.d.ts.map +0 -1
  126. package/dest/tx_validator/test_utils.js +0 -26
  127. package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
  128. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  129. package/dest/tx_validator/tx_validator_factory.js +0 -50
  130. package/src/sequencer/allowed.ts +0 -36
  131. package/src/slasher/factory.ts +0 -15
  132. package/src/slasher/index.ts +0 -2
  133. package/src/slasher/slasher_client.ts +0 -193
  134. package/src/tx_validator/archive_cache.ts +0 -28
  135. package/src/tx_validator/gas_validator.ts +0 -101
  136. package/src/tx_validator/nullifier_cache.ts +0 -30
  137. package/src/tx_validator/phases_validator.ts +0 -98
  138. package/src/tx_validator/test_utils.ts +0 -48
  139. package/src/tx_validator/tx_validator_factory.ts +0 -120
@@ -1,74 +1,505 @@
1
- import { Blob } from '@aztec/blob-lib';
2
- import { createBlobSinkClient } from '@aztec/blob-sink/client';
3
- import { FormattedViemError, RollupContract, formatViemError } from '@aztec/ethereum';
4
- import { toHex } from '@aztec/foundation/bigint-buffer';
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;
374
+ import { Blob, getBlobsPerL1Block, getPrefixedEthBlobCommitments } from '@aztec/blob-lib';
375
+ import { MULTI_CALL_3_ADDRESS, Multicall3, RollupContract } from '@aztec/ethereum/contracts';
376
+ import { L1FeeAnalyzer } from '@aztec/ethereum/l1-fee-analysis';
377
+ import { WEI_CONST } from '@aztec/ethereum/l1-tx-utils';
378
+ import { FormattedViemError, formatViemError, tryExtractEvent } from '@aztec/ethereum/utils';
379
+ import { sumBigint } from '@aztec/foundation/bigint';
380
+ import { toHex as toPaddedHex } from '@aztec/foundation/bigint-buffer';
381
+ import { CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
382
+ import { pick } from '@aztec/foundation/collection';
5
383
  import { EthAddress } from '@aztec/foundation/eth-address';
384
+ import { Signature } from '@aztec/foundation/eth-signature';
6
385
  import { createLogger } from '@aztec/foundation/log';
386
+ import { bufferToHex } from '@aztec/foundation/string';
7
387
  import { Timer } from '@aztec/foundation/timer';
8
- import { ForwarderAbi, RollupAbi } from '@aztec/l1-artifacts';
9
- import { ConsensusPayload, SignatureDomainSeparator, getHashedSignaturePayload } from '@aztec/stdlib/p2p';
10
- import { getTelemetryClient } from '@aztec/telemetry-client';
11
- import pick from 'lodash.pick';
12
- import { encodeFunctionData } from 'viem';
388
+ import { EmpireBaseAbi, ErrorsAbi, RollupAbi } from '@aztec/l1-artifacts';
389
+ import { encodeSlashConsensusVotes } from '@aztec/slasher';
390
+ import { CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
391
+ import { getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
392
+ import { encodeFunctionData, toHex } from 'viem';
13
393
  import { SequencerPublisherMetrics } from './sequencer-publisher-metrics.js';
14
- export var VoteType = /*#__PURE__*/ function(VoteType) {
15
- VoteType[VoteType["GOVERNANCE"] = 0] = "GOVERNANCE";
16
- VoteType[VoteType["SLASHING"] = 1] = "SLASHING";
17
- return VoteType;
18
- }({});
394
+ export const Actions = [
395
+ 'invalidate-by-invalid-attestation',
396
+ 'invalidate-by-insufficient-attestations',
397
+ 'propose',
398
+ 'governance-signal',
399
+ 'empire-slashing-signal',
400
+ 'create-empire-payload',
401
+ 'execute-empire-payload',
402
+ 'vote-offenses',
403
+ 'execute-slash'
404
+ ];
405
+ // Sorting for actions such that invalidations go before proposals, and proposals go before votes
406
+ export const compareActions = (a, b)=>Actions.indexOf(a) - Actions.indexOf(b);
407
+ _dec = trackSpan('SequencerPublisher.sendRequests'), _dec1 = trackSpan('SequencerPublisher.validateBlockHeader'), _dec2 = trackSpan('SequencerPublisher.validateCheckpointForSubmission');
19
408
  export class SequencerPublisher {
20
- interrupted = false;
409
+ config;
410
+ static{
411
+ ({ e: [_initProto] } = _apply_decs_2203_r(this, [
412
+ [
413
+ _dec,
414
+ 2,
415
+ "sendRequests"
416
+ ],
417
+ [
418
+ _dec1,
419
+ 2,
420
+ "validateBlockHeader"
421
+ ],
422
+ [
423
+ _dec2,
424
+ 2,
425
+ "validateCheckpointForSubmission"
426
+ ]
427
+ ], []));
428
+ }
429
+ interrupted;
21
430
  metrics;
22
431
  epochCache;
23
- forwarderContract;
24
- governanceLog = createLogger('sequencer:publisher:governance');
25
- governanceProposerAddress;
26
- governancePayload = EthAddress.ZERO;
27
- slashingLog = createLogger('sequencer:publisher:slashing');
28
- slashingProposerAddress;
29
- getSlashPayload = undefined;
30
- myLastVotes = {
31
- [0]: 0n,
32
- [1]: 0n
33
- };
34
- log = createLogger('sequencer:publisher');
432
+ governanceLog;
433
+ slashingLog;
434
+ lastActions;
435
+ isPayloadEmptyCache;
436
+ log;
35
437
  ethereumSlotDuration;
36
- blobSinkClient;
438
+ blobClient;
439
+ /** Address to use for simulations in fisherman mode (actual proposer's address) */ proposerAddressForSimulation;
440
+ /** L1 fee analyzer for fisherman mode */ l1FeeAnalyzer;
37
441
  // @note - with blobs, the below estimate seems too large.
38
442
  // Total used for full block from int_l1_pub e2e test: 1m (of which 86k is 1x blob)
39
443
  // Total used for emptier block from above test: 429k (of which 84k is 1x blob)
40
444
  static PROPOSE_GAS_GUESS = 12_000_000n;
445
+ // A CALL to a cold address is 2700 gas
446
+ static MULTICALL_OVERHEAD_GAS_GUESS = 5000n;
447
+ // Gas report for VotingWithSigTest shows a max gas of 100k, but we've seen it cost 700k+ in testnet
448
+ static VOTE_GAS_GUESS = 800_000n;
41
449
  l1TxUtils;
42
450
  rollupContract;
43
451
  govProposerContract;
44
452
  slashingProposerContract;
45
- requests = [];
453
+ slashFactoryContract;
454
+ tracer;
455
+ requests;
46
456
  constructor(config, deps){
457
+ this.config = config;
458
+ this.interrupted = (_initProto(this), false);
459
+ this.governanceLog = createLogger('sequencer:publisher:governance');
460
+ this.slashingLog = createLogger('sequencer:publisher:slashing');
461
+ this.lastActions = {};
462
+ this.isPayloadEmptyCache = new Map();
463
+ this.requests = [];
464
+ this.log = deps.log ?? createLogger('sequencer:publisher');
47
465
  this.ethereumSlotDuration = BigInt(config.ethereumSlotDuration);
48
466
  this.epochCache = deps.epochCache;
49
- this.blobSinkClient = deps.blobSinkClient ?? createBlobSinkClient(config);
467
+ this.lastActions = deps.lastActions;
468
+ this.blobClient = deps.blobClient;
50
469
  const telemetry = deps.telemetry ?? getTelemetryClient();
51
- this.metrics = new SequencerPublisherMetrics(telemetry, 'SequencerPublisher');
470
+ this.metrics = deps.metrics ?? new SequencerPublisherMetrics(telemetry, 'SequencerPublisher');
471
+ this.tracer = telemetry.getTracer('SequencerPublisher');
52
472
  this.l1TxUtils = deps.l1TxUtils;
53
473
  this.rollupContract = deps.rollupContract;
54
- this.forwarderContract = deps.forwarderContract;
55
474
  this.govProposerContract = deps.governanceProposerContract;
56
475
  this.slashingProposerContract = deps.slashingProposerContract;
476
+ this.rollupContract.listenToSlasherChanged(async ()=>{
477
+ this.log.info('Slashing proposer changed');
478
+ const newSlashingProposer = await this.rollupContract.getSlashingProposer();
479
+ this.slashingProposerContract = newSlashingProposer;
480
+ });
481
+ this.slashFactoryContract = deps.slashFactoryContract;
482
+ // Initialize L1 fee analyzer for fisherman mode
483
+ if (config.fishermanMode) {
484
+ this.l1FeeAnalyzer = new L1FeeAnalyzer(this.l1TxUtils.client, deps.dateProvider, createLogger('sequencer:publisher:fee-analyzer'));
485
+ }
57
486
  }
58
- registerSlashPayloadGetter(callback) {
59
- this.getSlashPayload = callback;
60
- }
61
- getForwarderAddress() {
62
- return EthAddress.fromString(this.forwarderContract.getAddress());
487
+ getRollupContract() {
488
+ return this.rollupContract;
63
489
  }
64
490
  getSenderAddress() {
65
- return EthAddress.fromString(this.l1TxUtils.getSenderAddress());
491
+ return this.l1TxUtils.getSenderAddress();
66
492
  }
67
- getGovernancePayload() {
68
- return this.governancePayload;
493
+ /**
494
+ * Gets the L1 fee analyzer instance (only available in fisherman mode)
495
+ */ getL1FeeAnalyzer() {
496
+ return this.l1FeeAnalyzer;
69
497
  }
70
- setGovernancePayload(payload) {
71
- this.governancePayload = payload;
498
+ /**
499
+ * Sets the proposer address to use for simulations in fisherman mode.
500
+ * @param proposerAddress - The actual proposer's address to use for balance lookups in simulations
501
+ */ setProposerAddressForSimulation(proposerAddress) {
502
+ this.proposerAddressForSimulation = proposerAddress;
72
503
  }
73
504
  addRequest(request) {
74
505
  this.requests.push(request);
@@ -77,6 +508,55 @@ export class SequencerPublisher {
77
508
  return this.epochCache.getEpochAndSlotNow().slot;
78
509
  }
79
510
  /**
511
+ * Clears all pending requests without sending them.
512
+ */ clearPendingRequests() {
513
+ const count = this.requests.length;
514
+ this.requests = [];
515
+ if (count > 0) {
516
+ this.log.debug(`Cleared ${count} pending request(s)`);
517
+ }
518
+ }
519
+ /**
520
+ * Analyzes L1 fees for the pending requests without sending them.
521
+ * This is used in fisherman mode to validate fee calculations.
522
+ * @param l2SlotNumber - The L2 slot number for this analysis
523
+ * @param onComplete - Optional callback to invoke when analysis completes (after block is mined)
524
+ * @returns The analysis result (incomplete until block mines), or undefined if no requests
525
+ */ async analyzeL1Fees(l2SlotNumber, onComplete) {
526
+ if (!this.l1FeeAnalyzer) {
527
+ this.log.warn('L1 fee analyzer not available (not in fisherman mode)');
528
+ return undefined;
529
+ }
530
+ const requestsToAnalyze = [
531
+ ...this.requests
532
+ ];
533
+ if (requestsToAnalyze.length === 0) {
534
+ this.log.debug('No requests to analyze for L1 fees');
535
+ return undefined;
536
+ }
537
+ // Extract blob config from requests (if any)
538
+ const blobConfigs = requestsToAnalyze.filter((request)=>request.blobConfig).map((request)=>request.blobConfig);
539
+ const blobConfig = blobConfigs[0];
540
+ // Get gas configs
541
+ const gasConfigs = requestsToAnalyze.filter((request)=>request.gasConfig).map((request)=>request.gasConfig);
542
+ const gasLimits = gasConfigs.map((g)=>g?.gasLimit).filter((g)=>g !== undefined);
543
+ const gasLimit = gasLimits.length > 0 ? gasLimits.reduce((sum, g)=>sum + g, 0n) : 0n;
544
+ // Get the transaction requests
545
+ const l1Requests = requestsToAnalyze.map((r)=>r.request);
546
+ // Start the analysis
547
+ const analysisId = await this.l1FeeAnalyzer.startAnalysis(l2SlotNumber, gasLimit > 0n ? gasLimit : SequencerPublisher.PROPOSE_GAS_GUESS, l1Requests, blobConfig, onComplete);
548
+ this.log.info('Started L1 fee analysis', {
549
+ analysisId,
550
+ l2SlotNumber: l2SlotNumber.toString(),
551
+ requestCount: requestsToAnalyze.length,
552
+ hasBlobConfig: !!blobConfig,
553
+ gasLimit: gasLimit.toString(),
554
+ actions: requestsToAnalyze.map((r)=>r.action)
555
+ });
556
+ // Return the analysis result (will be incomplete until block mines)
557
+ return this.l1FeeAnalyzer.getAnalysis(analysisId);
558
+ }
559
+ /**
80
560
  * Sends all requests that are still valid.
81
561
  * @returns one of:
82
562
  * - A receipt and stats if the tx succeeded
@@ -87,12 +567,14 @@ export class SequencerPublisher {
87
567
  ...this.requests
88
568
  ];
89
569
  this.requests = [];
90
- if (this.interrupted) {
570
+ if (this.interrupted || requestsToProcess.length === 0) {
91
571
  return undefined;
92
572
  }
93
573
  const currentL2Slot = this.getCurrentL2Slot();
94
- this.log.debug(`Current L2 slot: ${currentL2Slot}`);
574
+ this.log.debug(`Sending requests on L2 slot ${currentL2Slot}`);
95
575
  const validRequests = requestsToProcess.filter((request)=>request.lastValidL2Slot >= currentL2Slot);
576
+ const validActions = validRequests.map((x)=>x.action);
577
+ const expiredActions = requestsToProcess.filter((request)=>request.lastValidL2Slot < currentL2Slot).map((x)=>x.action);
96
578
  if (validRequests.length !== requestsToProcess.length) {
97
579
  this.log.warn(`Some requests were expired for slot ${currentL2Slot}`, {
98
580
  validRequests: validRequests.map((request)=>({
@@ -109,56 +591,98 @@ export class SequencerPublisher {
109
591
  this.log.debug(`No valid requests to send`);
110
592
  return undefined;
111
593
  }
112
- // @note - we can only have one gas config and one blob config per bundle
594
+ // @note - we can only have one blob config per bundle
113
595
  // find requests with gas and blob configs
114
596
  // See https://github.com/AztecProtocol/aztec-packages/issues/11513
115
- const gasConfigs = requestsToProcess.filter((request)=>request.gasConfig);
116
- const blobConfigs = requestsToProcess.filter((request)=>request.blobConfig);
117
- if (gasConfigs.length > 1 || blobConfigs.length > 1) {
118
- throw new Error('Multiple gas or blob configs found');
597
+ const gasConfigs = requestsToProcess.filter((request)=>request.gasConfig).map((request)=>request.gasConfig);
598
+ const blobConfigs = requestsToProcess.filter((request)=>request.blobConfig).map((request)=>request.blobConfig);
599
+ if (blobConfigs.length > 1) {
600
+ throw new Error('Multiple blob configs found');
119
601
  }
120
- const gasConfig = gasConfigs[0]?.gasConfig;
121
- const blobConfig = blobConfigs[0]?.blobConfig;
602
+ const blobConfig = blobConfigs[0];
603
+ // Merge gasConfigs. Yields the sum of gasLimits, and the earliest txTimeoutAt, or undefined if no gasConfig sets them.
604
+ const gasLimits = gasConfigs.map((g)=>g?.gasLimit).filter((g)=>g !== undefined);
605
+ const gasLimit = gasLimits.length > 0 ? sumBigint(gasLimits) : undefined; // sum
606
+ const txTimeoutAts = gasConfigs.map((g)=>g?.txTimeoutAt).filter((g)=>g !== undefined);
607
+ const txTimeoutAt = txTimeoutAts.length > 0 ? new Date(Math.min(...txTimeoutAts.map((g)=>g.getTime()))) : undefined; // earliest
608
+ const txConfig = {
609
+ gasLimit,
610
+ txTimeoutAt
611
+ };
612
+ // Sort the requests so that proposals always go first
613
+ // This ensures the committee gets precomputed correctly
614
+ validRequests.sort((a, b)=>compareActions(a.action, b.action));
122
615
  try {
123
616
  this.log.debug('Forwarding transactions', {
124
- validRequests: validRequests.map((request)=>request.action)
617
+ validRequests: validRequests.map((request)=>request.action),
618
+ txConfig
125
619
  });
126
- const result = await this.forwarderContract.forward(validRequests.map((request)=>request.request), this.l1TxUtils, gasConfig, blobConfig, this.log);
127
- this.callbackBundledTransactions(validRequests, result);
128
- return result;
620
+ const result = await Multicall3.forward(validRequests.map((request)=>request.request), this.l1TxUtils, txConfig, blobConfig, this.rollupContract.address, this.log);
621
+ const { successfulActions = [], failedActions = [] } = this.callbackBundledTransactions(validRequests, result);
622
+ return {
623
+ result,
624
+ expiredActions,
625
+ sentActions: validActions,
626
+ successfulActions,
627
+ failedActions
628
+ };
129
629
  } catch (err) {
130
630
  const viemError = formatViemError(err);
131
631
  this.log.error(`Failed to publish bundled transactions`, viemError);
132
632
  return undefined;
133
633
  } finally{
134
634
  try {
135
- this.metrics.recordSenderBalance(await this.l1TxUtils.getSenderBalance(), this.l1TxUtils.getSenderAddress());
635
+ this.metrics.recordSenderBalance(await this.l1TxUtils.getSenderBalance(), this.l1TxUtils.getSenderAddress().toString());
136
636
  } catch (err) {
137
637
  this.log.warn(`Failed to record balance after sending tx: ${err}`);
138
638
  }
139
639
  }
140
640
  }
141
641
  callbackBundledTransactions(requests, result) {
142
- const success = result?.receipt.status === 'success';
143
- const logger = success ? this.log.info : this.log.error;
144
- for (const request of requests){
145
- logger(`Bundled [${request.action}] transaction [${success ? 'succeeded' : 'failed'}]`);
146
- request.onResult?.(request.request, result);
642
+ const actionsListStr = requests.map((r)=>r.action).join(', ');
643
+ if (result instanceof FormattedViemError) {
644
+ this.log.error(`Failed to publish bundled transactions (${actionsListStr})`, result);
645
+ return {
646
+ failedActions: requests.map((r)=>r.action)
647
+ };
648
+ } else {
649
+ this.log.verbose(`Published bundled transactions (${actionsListStr})`, {
650
+ result,
651
+ requests
652
+ });
653
+ const successfulActions = [];
654
+ const failedActions = [];
655
+ for (const request of requests){
656
+ if (request.checkSuccess(request.request, result)) {
657
+ successfulActions.push(request.action);
658
+ } else {
659
+ failedActions.push(request.action);
660
+ }
661
+ }
662
+ return {
663
+ successfulActions,
664
+ failedActions
665
+ };
147
666
  }
148
667
  }
149
668
  /**
150
669
  * @notice Will call `canProposeAtNextEthBlock` to make sure that it is possible to propose
151
670
  * @param tipArchive - The archive to check
152
671
  * @returns The slot and block number if it is possible to propose, undefined otherwise
153
- */ canProposeAtNextEthBlock(tipArchive) {
672
+ */ canProposeAtNextEthBlock(tipArchive, msgSender, opts = {}) {
673
+ // TODO: #14291 - should loop through multiple keys to check if any of them can propose
154
674
  const ignoredErrors = [
155
675
  'SlotAlreadyInChain',
156
676
  'InvalidProposer',
157
677
  'InvalidArchive'
158
678
  ];
159
- return this.rollupContract.canProposeAtNextEthBlock(tipArchive, this.getForwarderAddress().toString(), this.ethereumSlotDuration).catch((err)=>{
679
+ return this.rollupContract.canProposeAtNextEthBlock(tipArchive.toBuffer(), msgSender.toString(), Number(this.ethereumSlotDuration), {
680
+ forcePendingCheckpointNumber: opts.forcePendingCheckpointNumber
681
+ }).catch((err)=>{
160
682
  if (err instanceof FormattedViemError && ignoredErrors.find((e)=>err.message.includes(e))) {
161
- this.log.debug(err.message);
683
+ this.log.warn(`Failed canProposeAtTime check with ${ignoredErrors.find((e)=>err.message.includes(e))}`, {
684
+ error: err.message
685
+ });
162
686
  } else {
163
687
  this.log.error(err.name, err);
164
688
  }
@@ -166,135 +690,482 @@ export class SequencerPublisher {
166
690
  });
167
691
  }
168
692
  /**
169
- * @notice Will call `validateHeader` to make sure that it is possible to propose
170
- *
171
- * @dev Throws if unable to propose
172
- *
173
- * @param header - The header to propose
174
- * @param digest - The digest that attestations are signing over
175
- *
176
- */ async validateBlockForSubmission(header, attestationData = {
177
- digest: Buffer.alloc(32),
178
- signatures: []
179
- }) {
180
- const ts = BigInt((await this.l1TxUtils.getBlock()).timestamp + this.ethereumSlotDuration);
181
- const formattedSignatures = attestationData.signatures.map((attest)=>attest.toViemSignature());
693
+ * @notice Will simulate `validateHeader` to make sure that the block header is valid
694
+ * @dev This is a convenience function that can be used by the sequencer to validate a "partial" header.
695
+ * It will throw if the block header is invalid.
696
+ * @param header - The block header to validate
697
+ */ async validateBlockHeader(header, opts) {
182
698
  const flags = {
183
699
  ignoreDA: true,
184
- ignoreSignatures: formattedSignatures.length == 0
700
+ ignoreSignatures: true
185
701
  };
186
702
  const args = [
187
- `0x${header.toBuffer().toString('hex')}`,
188
- formattedSignatures,
189
- `0x${attestationData.digest.toString('hex')}`,
190
- ts,
191
- `0x${header.contentCommitment.blobsHash.toString('hex')}`,
703
+ header.toViem(),
704
+ CommitteeAttestationsAndSigners.empty().getPackedAttestations(),
705
+ [],
706
+ Signature.empty().toViemSignature(),
707
+ `0x${'0'.repeat(64)}`,
708
+ header.blobsHash.toString(),
192
709
  flags
193
710
  ];
194
- await this.rollupContract.validateHeader(args, this.getForwarderAddress().toString());
195
- return ts;
711
+ const ts = BigInt((await this.l1TxUtils.getBlock()).timestamp + this.ethereumSlotDuration);
712
+ const stateOverrides = await this.rollupContract.makePendingCheckpointNumberOverride(opts?.forcePendingCheckpointNumber);
713
+ let balance = 0n;
714
+ if (this.config.fishermanMode) {
715
+ // In fisherman mode, we can't know where the proposer is publishing from
716
+ // so we just add sufficient balance to the multicall3 address
717
+ balance = 10n * WEI_CONST * WEI_CONST; // 10 ETH
718
+ } else {
719
+ balance = await this.l1TxUtils.getSenderBalance();
720
+ }
721
+ stateOverrides.push({
722
+ address: MULTI_CALL_3_ADDRESS,
723
+ balance
724
+ });
725
+ await this.l1TxUtils.simulate({
726
+ to: this.rollupContract.address,
727
+ data: encodeFunctionData({
728
+ abi: RollupAbi,
729
+ functionName: 'validateHeaderWithAttestations',
730
+ args
731
+ }),
732
+ from: MULTI_CALL_3_ADDRESS
733
+ }, {
734
+ time: ts + 1n
735
+ }, stateOverrides);
736
+ this.log.debug(`Simulated validateHeader`);
737
+ }
738
+ /**
739
+ * Simulate making a call to invalidate a checkpoint with invalid attestations. Returns undefined if no need to invalidate.
740
+ * @param validationResult - The validation result indicating which checkpoint to invalidate (as returned by the archiver)
741
+ */ async simulateInvalidateCheckpoint(validationResult) {
742
+ if (validationResult.valid) {
743
+ return undefined;
744
+ }
745
+ const { reason, checkpoint } = validationResult;
746
+ const checkpointNumber = checkpoint.checkpointNumber;
747
+ const logData = {
748
+ ...checkpoint,
749
+ reason
750
+ };
751
+ const currentCheckpointNumber = await this.rollupContract.getCheckpointNumber();
752
+ if (currentCheckpointNumber < checkpointNumber) {
753
+ this.log.verbose(`Skipping checkpoint ${checkpointNumber} invalidation since it has already been removed from the pending chain`, {
754
+ currentCheckpointNumber,
755
+ ...logData
756
+ });
757
+ return undefined;
758
+ }
759
+ const request = this.buildInvalidateCheckpointRequest(validationResult);
760
+ this.log.debug(`Simulating invalidate checkpoint ${checkpointNumber}`, {
761
+ ...logData,
762
+ request
763
+ });
764
+ try {
765
+ const { gasUsed } = await this.l1TxUtils.simulate(request, undefined, undefined, ErrorsAbi);
766
+ this.log.verbose(`Simulation for invalidate checkpoint ${checkpointNumber} succeeded`, {
767
+ ...logData,
768
+ request,
769
+ gasUsed
770
+ });
771
+ return {
772
+ request,
773
+ gasUsed,
774
+ checkpointNumber,
775
+ forcePendingCheckpointNumber: CheckpointNumber(checkpointNumber - 1),
776
+ reason
777
+ };
778
+ } catch (err) {
779
+ const viemError = formatViemError(err);
780
+ // If the error is due to the checkpoint not being in the pending chain, and it was indeed removed by someone else,
781
+ // we can safely ignore it and return undefined so we go ahead with checkpoint building.
782
+ if (viemError.message?.includes('Rollup__BlockNotInPendingChain')) {
783
+ this.log.verbose(`Simulation for invalidate checkpoint ${checkpointNumber} failed due to checkpoint not being in pending chain`, {
784
+ ...logData,
785
+ request,
786
+ error: viemError.message
787
+ });
788
+ const latestPendingCheckpointNumber = await this.rollupContract.getCheckpointNumber();
789
+ if (latestPendingCheckpointNumber < checkpointNumber) {
790
+ this.log.verbose(`Checkpoint ${checkpointNumber} has already been invalidated`, {
791
+ ...logData
792
+ });
793
+ return undefined;
794
+ } else {
795
+ this.log.error(`Simulation for invalidate checkpoint ${checkpointNumber} failed and it is still in pending chain`, viemError, logData);
796
+ throw new Error(`Failed to simulate invalidate checkpoint ${checkpointNumber} while it is still in pending chain`, {
797
+ cause: viemError
798
+ });
799
+ }
800
+ }
801
+ // Otherwise, throw. We cannot build the next checkpoint if we cannot invalidate the previous one.
802
+ this.log.error(`Simulation for invalidate checkpoint ${checkpointNumber} failed`, viemError, logData);
803
+ throw new Error(`Failed to simulate invalidate checkpoint ${checkpointNumber}`, {
804
+ cause: viemError
805
+ });
806
+ }
196
807
  }
197
- async getCurrentEpochCommittee() {
198
- const committee = await this.rollupContract.getCurrentEpochCommittee();
199
- return committee.map(EthAddress.fromString);
808
+ buildInvalidateCheckpointRequest(validationResult) {
809
+ if (validationResult.valid) {
810
+ throw new Error('Cannot invalidate a valid checkpoint');
811
+ }
812
+ const { checkpoint, committee, reason } = validationResult;
813
+ const logData = {
814
+ ...checkpoint,
815
+ reason
816
+ };
817
+ this.log.debug(`Building invalidate checkpoint ${checkpoint.checkpointNumber} request`, logData);
818
+ const attestationsAndSigners = new CommitteeAttestationsAndSigners(validationResult.attestations).getPackedAttestations();
819
+ if (reason === 'invalid-attestation') {
820
+ return this.rollupContract.buildInvalidateBadAttestationRequest(checkpoint.checkpointNumber, attestationsAndSigners, committee, validationResult.invalidIndex);
821
+ } else if (reason === 'insufficient-attestations') {
822
+ return this.rollupContract.buildInvalidateInsufficientAttestationsRequest(checkpoint.checkpointNumber, attestationsAndSigners, committee);
823
+ } else {
824
+ const _ = reason;
825
+ throw new Error(`Unknown reason for invalidation`);
826
+ }
200
827
  }
201
- async enqueueCastVoteHelper(slotNumber, timestamp, voteType, payload, base) {
202
- if (this.myLastVotes[voteType] >= slotNumber) {
828
+ /** Simulates `propose` to make sure that the checkpoint is valid for submission */ async validateCheckpointForSubmission(checkpoint, attestationsAndSigners, attestationsAndSignersSignature, options) {
829
+ const ts = BigInt((await this.l1TxUtils.getBlock()).timestamp + this.ethereumSlotDuration);
830
+ // TODO(palla/mbps): This should not be needed, there's no flow where we propose with zero attestations. Or is there?
831
+ // If we have no attestations, we still need to provide the empty attestations
832
+ // so that the committee is recalculated correctly
833
+ // const ignoreSignatures = attestationsAndSigners.attestations.length === 0;
834
+ // if (ignoreSignatures) {
835
+ // const { committee } = await this.epochCache.getCommittee(block.header.globalVariables.slotNumber);
836
+ // if (!committee) {
837
+ // this.log.warn(`No committee found for slot ${block.header.globalVariables.slotNumber}`);
838
+ // throw new Error(`No committee found for slot ${block.header.globalVariables.slotNumber}`);
839
+ // }
840
+ // attestationsAndSigners.attestations = committee.map(committeeMember =>
841
+ // CommitteeAttestation.fromAddress(committeeMember),
842
+ // );
843
+ // }
844
+ const blobFields = checkpoint.toBlobFields();
845
+ const blobs = getBlobsPerL1Block(blobFields);
846
+ const blobInput = getPrefixedEthBlobCommitments(blobs);
847
+ const args = [
848
+ {
849
+ header: checkpoint.header.toViem(),
850
+ archive: toHex(checkpoint.archive.root.toBuffer()),
851
+ oracleInput: {
852
+ feeAssetPriceModifier: 0n
853
+ }
854
+ },
855
+ attestationsAndSigners.getPackedAttestations(),
856
+ attestationsAndSigners.getSigners().map((signer)=>signer.toString()),
857
+ attestationsAndSignersSignature.toViemSignature(),
858
+ blobInput
859
+ ];
860
+ await this.simulateProposeTx(args, ts, options);
861
+ return ts;
862
+ }
863
+ async enqueueCastSignalHelper(slotNumber, timestamp, signalType, payload, base, signerAddress, signer) {
864
+ if (this.lastActions[signalType] && this.lastActions[signalType] === slotNumber) {
865
+ this.log.debug(`Skipping duplicate vote cast signal ${signalType} for slot ${slotNumber}`);
203
866
  return false;
204
867
  }
205
868
  if (payload.equals(EthAddress.ZERO)) {
206
869
  return false;
207
870
  }
871
+ if (signerAddress.equals(EthAddress.ZERO)) {
872
+ this.log.warn(`Cannot enqueue vote cast signal ${signalType} for address zero at slot ${slotNumber}`);
873
+ return false;
874
+ }
208
875
  const round = await base.computeRound(slotNumber);
209
- const [proposer, roundInfo] = await Promise.all([
210
- this.rollupContract.getProposerAt(timestamp),
211
- base.getRoundInfo(this.rollupContract.address, round)
212
- ]);
213
- if (proposer.toLowerCase() !== this.getForwarderAddress().toString().toLowerCase()) {
876
+ const roundInfo = await base.getRoundInfo(this.rollupContract.address, round);
877
+ if (roundInfo.quorumReached) {
214
878
  return false;
215
879
  }
216
- if (roundInfo.lastVote >= slotNumber) {
880
+ if (roundInfo.lastSignalSlot >= slotNumber) {
217
881
  return false;
218
882
  }
219
- const cachedLastVote = this.myLastVotes[voteType];
220
- this.myLastVotes[voteType] = slotNumber;
883
+ if (await this.isPayloadEmpty(payload)) {
884
+ this.log.warn(`Skipping vote cast for payload with empty code`);
885
+ return false;
886
+ }
887
+ const cachedLastVote = this.lastActions[signalType];
888
+ this.lastActions[signalType] = slotNumber;
889
+ const action = signalType;
890
+ const request = await base.createSignalRequestWithSignature(payload.toString(), slotNumber, this.config.l1ChainId, signerAddress.toString(), signer);
891
+ this.log.debug(`Created ${action} request with signature`, {
892
+ request,
893
+ round,
894
+ signer: this.l1TxUtils.client.account?.address,
895
+ lastValidL2Slot: slotNumber
896
+ });
897
+ try {
898
+ await this.l1TxUtils.simulate(request, {
899
+ time: timestamp
900
+ }, [], ErrorsAbi);
901
+ this.log.debug(`Simulation for ${action} at slot ${slotNumber} succeeded`, {
902
+ request
903
+ });
904
+ } catch (err) {
905
+ this.log.error(`Failed simulation for ${action} at slot ${slotNumber} (enqueuing the action anyway)`, err);
906
+ // Yes, we enqueue the request anyway, in case there was a bug with the simulation itself
907
+ }
908
+ // TODO(palla/slash): All votes (governance and slashing) should txTimeoutAt at the end of the slot.
221
909
  this.addRequest({
222
- action: voteType === 0 ? 'governance-vote' : 'slashing-vote',
223
- request: base.createVoteRequest(payload.toString()),
910
+ gasConfig: {
911
+ gasLimit: SequencerPublisher.VOTE_GAS_GUESS
912
+ },
913
+ action,
914
+ request,
224
915
  lastValidL2Slot: slotNumber,
225
- onResult: (_request, result)=>{
226
- if (!result || result.receipt.status !== 'success') {
227
- this.myLastVotes[voteType] = cachedLastVote;
916
+ checkSuccess: (_request, result)=>{
917
+ const success = result && result.receipt && result.receipt.status === 'success' && tryExtractEvent(result.receipt.logs, base.address.toString(), EmpireBaseAbi, 'SignalCast');
918
+ const logData = {
919
+ ...result,
920
+ slotNumber,
921
+ round,
922
+ payload: payload.toString()
923
+ };
924
+ if (!success) {
925
+ this.log.error(`Signaling in ${action} for ${payload} at slot ${slotNumber} in round ${round} failed`, logData);
926
+ this.lastActions[signalType] = cachedLastVote;
927
+ return false;
228
928
  } else {
229
- this.log.info(`Cast [${voteType}] vote for slot ${slotNumber}`);
929
+ this.log.info(`Signaling in ${action} for ${payload} at slot ${slotNumber} in round ${round} succeeded`, logData);
930
+ return true;
230
931
  }
231
932
  }
232
933
  });
233
934
  return true;
234
935
  }
235
- async getVoteConfig(slotNumber, voteType) {
236
- if (voteType === 0) {
237
- return {
238
- payload: this.governancePayload,
239
- base: this.govProposerContract
240
- };
241
- } else if (voteType === 1) {
242
- if (!this.getSlashPayload) {
243
- return undefined;
244
- }
245
- const slashPayload = await this.getSlashPayload(slotNumber);
246
- if (!slashPayload) {
247
- return undefined;
248
- }
249
- return {
250
- payload: slashPayload,
251
- base: this.slashingProposerContract
252
- };
936
+ async isPayloadEmpty(payload) {
937
+ const key = payload.toString();
938
+ const cached = this.isPayloadEmptyCache.get(key);
939
+ if (cached) {
940
+ return cached;
253
941
  }
254
- throw new Error('Unreachable: Invalid vote type');
942
+ const isEmpty = !await this.l1TxUtils.getCode(payload);
943
+ this.isPayloadEmptyCache.set(key, isEmpty);
944
+ return isEmpty;
255
945
  }
256
946
  /**
257
- * Enqueues a castVote transaction to cast a vote for a given slot number.
258
- * @param slotNumber - The slot number to cast a vote for.
259
- * @param timestamp - The timestamp of the slot to cast a vote for.
260
- * @param voteType - The type of vote to cast.
261
- * @returns True if the vote was successfully enqueued, false otherwise.
262
- */ async enqueueCastVote(slotNumber, timestamp, voteType) {
263
- const voteConfig = await this.getVoteConfig(slotNumber, voteType);
264
- if (!voteConfig) {
947
+ * Enqueues a governance castSignal transaction to cast a signal for a given slot number.
948
+ * @param slotNumber - The slot number to cast a signal for.
949
+ * @param timestamp - The timestamp of the slot to cast a signal for.
950
+ * @returns True if the signal was successfully enqueued, false otherwise.
951
+ */ enqueueGovernanceCastSignal(governancePayload, slotNumber, timestamp, signerAddress, signer) {
952
+ return this.enqueueCastSignalHelper(slotNumber, timestamp, 'governance-signal', governancePayload, this.govProposerContract, signerAddress, signer);
953
+ }
954
+ /** Enqueues all slashing actions as returned by the slasher client. */ async enqueueSlashingActions(actions, slotNumber, timestamp, signerAddress, signer) {
955
+ if (actions.length === 0) {
956
+ this.log.debug(`No slashing actions to enqueue for slot ${slotNumber}`);
265
957
  return false;
266
958
  }
267
- const { payload, base } = voteConfig;
268
- return this.enqueueCastVoteHelper(slotNumber, timestamp, voteType, payload, base);
959
+ for (const action of actions){
960
+ switch(action.type){
961
+ case 'vote-empire-payload':
962
+ {
963
+ if (this.slashingProposerContract?.type !== 'empire') {
964
+ this.log.error('Cannot vote for empire payload on non-empire slashing contract');
965
+ break;
966
+ }
967
+ this.log.debug(`Enqueuing slashing vote for payload ${action.payload} at slot ${slotNumber}`, {
968
+ signerAddress
969
+ });
970
+ await this.enqueueCastSignalHelper(slotNumber, timestamp, 'empire-slashing-signal', action.payload, this.slashingProposerContract, signerAddress, signer);
971
+ break;
972
+ }
973
+ case 'create-empire-payload':
974
+ {
975
+ this.log.debug(`Enqueuing slashing create payload at slot ${slotNumber}`, {
976
+ slotNumber,
977
+ signerAddress
978
+ });
979
+ const request = this.slashFactoryContract.buildCreatePayloadRequest(action.data);
980
+ await this.simulateAndEnqueueRequest('create-empire-payload', request, (receipt)=>!!this.slashFactoryContract.tryExtractSlashPayloadCreatedEvent(receipt.logs), slotNumber, timestamp);
981
+ break;
982
+ }
983
+ case 'execute-empire-payload':
984
+ {
985
+ this.log.debug(`Enqueuing slashing execute payload at slot ${slotNumber}`, {
986
+ slotNumber,
987
+ signerAddress
988
+ });
989
+ if (this.slashingProposerContract?.type !== 'empire') {
990
+ this.log.error('Cannot execute slashing payload on non-empire slashing contract');
991
+ return false;
992
+ }
993
+ const empireSlashingProposer = this.slashingProposerContract;
994
+ const request = empireSlashingProposer.buildExecuteRoundRequest(action.round);
995
+ await this.simulateAndEnqueueRequest('execute-empire-payload', request, (receipt)=>!!empireSlashingProposer.tryExtractPayloadSubmittedEvent(receipt.logs), slotNumber, timestamp);
996
+ break;
997
+ }
998
+ case 'vote-offenses':
999
+ {
1000
+ this.log.debug(`Enqueuing slashing vote for ${action.votes.length} votes at slot ${slotNumber}`, {
1001
+ slotNumber,
1002
+ round: action.round,
1003
+ votesCount: action.votes.length,
1004
+ signerAddress
1005
+ });
1006
+ if (this.slashingProposerContract?.type !== 'tally') {
1007
+ this.log.error('Cannot vote for slashing offenses on non-tally slashing contract');
1008
+ return false;
1009
+ }
1010
+ const tallySlashingProposer = this.slashingProposerContract;
1011
+ const votes = bufferToHex(encodeSlashConsensusVotes(action.votes));
1012
+ const request = await tallySlashingProposer.buildVoteRequestFromSigner(votes, slotNumber, signer);
1013
+ await this.simulateAndEnqueueRequest('vote-offenses', request, (receipt)=>!!tallySlashingProposer.tryExtractVoteCastEvent(receipt.logs), slotNumber, timestamp);
1014
+ break;
1015
+ }
1016
+ case 'execute-slash':
1017
+ {
1018
+ this.log.debug(`Enqueuing slash execution for round ${action.round} at slot ${slotNumber}`, {
1019
+ slotNumber,
1020
+ round: action.round,
1021
+ signerAddress
1022
+ });
1023
+ if (this.slashingProposerContract?.type !== 'tally') {
1024
+ this.log.error('Cannot execute slashing offenses on non-tally slashing contract');
1025
+ return false;
1026
+ }
1027
+ const tallySlashingProposer = this.slashingProposerContract;
1028
+ const request = tallySlashingProposer.buildExecuteRoundRequest(action.round, action.committees);
1029
+ await this.simulateAndEnqueueRequest('execute-slash', request, (receipt)=>!!tallySlashingProposer.tryExtractRoundExecutedEvent(receipt.logs), slotNumber, timestamp);
1030
+ break;
1031
+ }
1032
+ default:
1033
+ {
1034
+ const _ = action;
1035
+ throw new Error(`Unknown slashing action type: ${action.type}`);
1036
+ }
1037
+ }
1038
+ }
1039
+ return true;
269
1040
  }
270
- /**
271
- * Proposes a L2 block on L1.
272
- *
273
- * @param block - L2 block to propose.
274
- * @returns True if the tx has been enqueued, throws otherwise. See #9315
275
- */ async enqueueProposeL2Block(block, attestations, txHashes, opts = {}) {
276
- const consensusPayload = new ConsensusPayload(block.header, block.archive.root, txHashes ?? []);
277
- const digest = await getHashedSignaturePayload(consensusPayload, SignatureDomainSeparator.blockAttestation);
278
- const blobs = await Blob.getBlobs(block.body.toBlobFields());
1041
+ /** Simulates and enqueues a proposal for a checkpoint on L1 */ async enqueueProposeCheckpoint(checkpoint, attestationsAndSigners, attestationsAndSignersSignature, opts = {}) {
1042
+ const checkpointHeader = checkpoint.header;
1043
+ const blobFields = checkpoint.toBlobFields();
1044
+ const blobs = getBlobsPerL1Block(blobFields);
279
1045
  const proposeTxArgs = {
280
- header: block.header.toBuffer(),
281
- archive: block.archive.root.toBuffer(),
282
- blockHash: (await block.header.hash()).toBuffer(),
283
- body: block.body.toBuffer(),
1046
+ header: checkpointHeader,
1047
+ archive: checkpoint.archive.root.toBuffer(),
284
1048
  blobs,
285
- attestations,
286
- txHashes: txHashes ?? []
1049
+ attestationsAndSigners,
1050
+ attestationsAndSignersSignature
287
1051
  };
288
- // @note This will make sure that we are passing the checks for our header ASSUMING that the data is also made available
289
- // This means that we can avoid the simulation issues in later checks.
290
- // By simulation issue, I mean the fact that the block.timestamp is equal to the last block, not the next, which
291
- // make time consistency checks break.
292
- const ts = await this.validateBlockForSubmission(block.header, {
293
- digest: digest.toBuffer(),
294
- signatures: attestations ?? []
1052
+ let ts;
1053
+ try {
1054
+ // @note This will make sure that we are passing the checks for our header ASSUMING that the data is also made available
1055
+ // This means that we can avoid the simulation issues in later checks.
1056
+ // By simulation issue, I mean the fact that the block.timestamp is equal to the last block, not the next, which
1057
+ // make time consistency checks break.
1058
+ // TODO(palla): Check whether we're validating twice, once here and once within addProposeTx, since we call simulateProposeTx in both places.
1059
+ ts = await this.validateCheckpointForSubmission(checkpoint, attestationsAndSigners, attestationsAndSignersSignature, opts);
1060
+ } catch (err) {
1061
+ this.log.error(`Checkpoint validation failed. ${err instanceof Error ? err.message : 'No error message'}`, err, {
1062
+ ...checkpoint.getStats(),
1063
+ slotNumber: checkpoint.header.slotNumber,
1064
+ forcePendingCheckpointNumber: opts.forcePendingCheckpointNumber
1065
+ });
1066
+ throw err;
1067
+ }
1068
+ this.log.verbose(`Enqueuing checkpoint propose transaction`, {
1069
+ ...checkpoint.toCheckpointInfo(),
1070
+ ...opts
1071
+ });
1072
+ await this.addProposeTx(checkpoint, proposeTxArgs, opts, ts);
1073
+ }
1074
+ enqueueInvalidateCheckpoint(request, opts = {}) {
1075
+ if (!request) {
1076
+ return;
1077
+ }
1078
+ // We issued the simulation against the rollup contract, so we need to account for the overhead of the multicall3
1079
+ const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(request.gasUsed) * 64 / 63)));
1080
+ const { gasUsed, checkpointNumber } = request;
1081
+ const logData = {
1082
+ gasUsed,
1083
+ checkpointNumber,
1084
+ gasLimit,
1085
+ opts
1086
+ };
1087
+ this.log.verbose(`Enqueuing invalidate checkpoint request`, logData);
1088
+ this.addRequest({
1089
+ action: `invalidate-by-${request.reason}`,
1090
+ request: request.request,
1091
+ gasConfig: {
1092
+ gasLimit,
1093
+ txTimeoutAt: opts.txTimeoutAt
1094
+ },
1095
+ lastValidL2Slot: SlotNumber(this.getCurrentL2Slot() + 2),
1096
+ checkSuccess: (_req, result)=>{
1097
+ const success = result && result.receipt && result.receipt.status === 'success' && tryExtractEvent(result.receipt.logs, this.rollupContract.address, RollupAbi, 'CheckpointInvalidated');
1098
+ if (!success) {
1099
+ this.log.warn(`Invalidate checkpoint ${request.checkpointNumber} failed`, {
1100
+ ...result,
1101
+ ...logData
1102
+ });
1103
+ } else {
1104
+ this.log.info(`Invalidate checkpoint ${request.checkpointNumber} succeeded`, {
1105
+ ...result,
1106
+ ...logData
1107
+ });
1108
+ }
1109
+ return !!success;
1110
+ }
1111
+ });
1112
+ }
1113
+ async simulateAndEnqueueRequest(action, request, checkSuccess, slotNumber, timestamp) {
1114
+ const logData = {
1115
+ slotNumber,
1116
+ timestamp,
1117
+ gasLimit: undefined
1118
+ };
1119
+ if (this.lastActions[action] && this.lastActions[action] === slotNumber) {
1120
+ this.log.debug(`Skipping duplicate action ${action} for slot ${slotNumber}`);
1121
+ return false;
1122
+ }
1123
+ const cachedLastActionSlot = this.lastActions[action];
1124
+ this.lastActions[action] = slotNumber;
1125
+ this.log.debug(`Simulating ${action} for slot ${slotNumber}`, logData);
1126
+ let gasUsed;
1127
+ try {
1128
+ ({ gasUsed } = await this.l1TxUtils.simulate(request, {
1129
+ time: timestamp
1130
+ }, [], ErrorsAbi)); // TODO(palla/slash): Check the timestamp logic
1131
+ this.log.verbose(`Simulation for ${action} succeeded`, {
1132
+ ...logData,
1133
+ request,
1134
+ gasUsed
1135
+ });
1136
+ } catch (err) {
1137
+ const viemError = formatViemError(err);
1138
+ this.log.error(`Simulation for ${action} at ${slotNumber} failed`, viemError, logData);
1139
+ return false;
1140
+ }
1141
+ // We issued the simulation against the rollup contract, so we need to account for the overhead of the multicall3
1142
+ const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(gasUsed) * 64 / 63)));
1143
+ logData.gasLimit = gasLimit;
1144
+ this.log.debug(`Enqueuing ${action}`, logData);
1145
+ this.addRequest({
1146
+ action,
1147
+ request,
1148
+ gasConfig: {
1149
+ gasLimit
1150
+ },
1151
+ lastValidL2Slot: slotNumber,
1152
+ checkSuccess: (_req, result)=>{
1153
+ const success = result && result.receipt && result.receipt.status === 'success' && checkSuccess(result.receipt);
1154
+ if (!success) {
1155
+ this.log.warn(`Action ${action} at ${slotNumber} failed`, {
1156
+ ...result,
1157
+ ...logData
1158
+ });
1159
+ this.lastActions[action] = cachedLastActionSlot;
1160
+ } else {
1161
+ this.log.info(`Action ${action} at ${slotNumber} succeeded`, {
1162
+ ...result,
1163
+ ...logData
1164
+ });
1165
+ }
1166
+ return !!success;
1167
+ }
295
1168
  });
296
- this.log.debug(`Submitting propose transaction`);
297
- await this.addProposeTx(block, proposeTxArgs, opts, ts);
298
1169
  return true;
299
1170
  }
300
1171
  /**
@@ -310,172 +1181,198 @@ export class SequencerPublisher {
310
1181
  this.interrupted = false;
311
1182
  this.l1TxUtils.restart();
312
1183
  }
313
- async prepareProposeTx(encodedData, timestamp) {
1184
+ async prepareProposeTx(encodedData, timestamp, options) {
314
1185
  const kzg = Blob.getViemKzgInstance();
315
- const blobInput = Blob.getEthBlobEvaluationInputs(encodedData.blobs);
1186
+ const blobInput = getPrefixedEthBlobCommitments(encodedData.blobs);
316
1187
  this.log.debug('Validating blob input', {
317
1188
  blobInput
318
1189
  });
319
- const blobEvaluationGas = await this.l1TxUtils.estimateGas(this.l1TxUtils.walletClient.account, {
320
- to: this.rollupContract.address,
321
- data: encodeFunctionData({
322
- abi: RollupAbi,
323
- functionName: 'validateBlobs',
324
- args: [
325
- blobInput
326
- ]
327
- })
328
- }, {}, {
329
- blobs: encodedData.blobs.map((b)=>b.data),
330
- kzg
331
- }).catch((err)=>{
332
- const { message, metaMessages } = formatViemError(err);
333
- this.log.error(`Failed to validate blobs`, message, {
334
- metaMessages
1190
+ // Get blob evaluation gas
1191
+ let blobEvaluationGas;
1192
+ if (this.config.fishermanMode) {
1193
+ // In fisherman mode, we can't estimate blob gas because estimateGas doesn't support state overrides
1194
+ // Use a fixed estimate.
1195
+ blobEvaluationGas = BigInt(encodedData.blobs.length) * 21_000n;
1196
+ this.log.debug(`Using fixed blob evaluation gas estimate in fisherman mode: ${blobEvaluationGas}`);
1197
+ } else {
1198
+ // Normal mode - use estimateGas with blob inputs
1199
+ blobEvaluationGas = await this.l1TxUtils.estimateGas(this.getSenderAddress().toString(), {
1200
+ to: this.rollupContract.address,
1201
+ data: encodeFunctionData({
1202
+ abi: RollupAbi,
1203
+ functionName: 'validateBlobs',
1204
+ args: [
1205
+ blobInput
1206
+ ]
1207
+ })
1208
+ }, {}, {
1209
+ blobs: encodedData.blobs.map((b)=>b.data),
1210
+ kzg
1211
+ }).catch((err)=>{
1212
+ const { message, metaMessages } = formatViemError(err);
1213
+ this.log.error(`Failed to validate blobs`, message, {
1214
+ metaMessages
1215
+ });
1216
+ throw new Error('Failed to validate blobs');
335
1217
  });
336
- throw new Error('Failed to validate blobs');
337
- });
338
- const attestations = encodedData.attestations ? encodedData.attestations.map((attest)=>attest.toViemSignature()) : [];
339
- const txHashes = encodedData.txHashes ? encodedData.txHashes.map((txHash)=>txHash.toString()) : [];
1218
+ }
1219
+ const signers = encodedData.attestationsAndSigners.getSigners().map((signer)=>signer.toString());
340
1220
  const args = [
341
1221
  {
342
- header: `0x${encodedData.header.toString('hex')}`,
343
- archive: `0x${encodedData.archive.toString('hex')}`,
1222
+ header: encodedData.header.toViem(),
1223
+ archive: toHex(encodedData.archive),
344
1224
  oracleInput: {
345
1225
  // We are currently not modifying these. See #9963
346
1226
  feeAssetPriceModifier: 0n
347
- },
348
- blockHash: `0x${encodedData.blockHash.toString('hex')}`,
349
- txHashes
1227
+ }
350
1228
  },
351
- attestations,
1229
+ encodedData.attestationsAndSigners.getPackedAttestations(),
1230
+ signers,
1231
+ encodedData.attestationsAndSignersSignature.toViemSignature(),
352
1232
  blobInput
353
1233
  ];
1234
+ const { rollupData, simulationResult } = await this.simulateProposeTx(args, timestamp, options);
1235
+ return {
1236
+ args,
1237
+ blobEvaluationGas,
1238
+ rollupData,
1239
+ simulationResult
1240
+ };
1241
+ }
1242
+ /**
1243
+ * Simulates the propose tx with eth_simulateV1
1244
+ * @param args - The propose tx args
1245
+ * @param timestamp - The timestamp to simulate proposal at
1246
+ * @returns The simulation result
1247
+ */ async simulateProposeTx(args, timestamp, options) {
354
1248
  const rollupData = encodeFunctionData({
355
1249
  abi: RollupAbi,
356
1250
  functionName: 'propose',
357
1251
  args
358
1252
  });
359
- const forwarderData = encodeFunctionData({
360
- abi: ForwarderAbi,
361
- functionName: 'forward',
362
- args: [
363
- [
364
- this.rollupContract.address
365
- ],
366
- [
367
- rollupData
368
- ]
369
- ]
370
- });
371
- const simulationResult = await this.l1TxUtils.simulateGasUsed({
372
- to: this.getForwarderAddress().toString(),
373
- data: forwarderData,
374
- gas: SequencerPublisher.PROPOSE_GAS_GUESS
375
- }, {
376
- // @note we add 1n to the timestamp because geth implementation doesn't like simulation timestamp to be equal to the current block timestamp
377
- time: timestamp + 1n,
378
- // @note reth should have a 30m gas limit per block but throws errors that this tx is beyond limit
379
- gasLimit: SequencerPublisher.PROPOSE_GAS_GUESS * 2n
380
- }, [
1253
+ // override the pending checkpoint number if requested
1254
+ const forcePendingCheckpointNumberStateDiff = (options.forcePendingCheckpointNumber !== undefined ? await this.rollupContract.makePendingCheckpointNumberOverride(options.forcePendingCheckpointNumber) : []).flatMap((override)=>override.stateDiff ?? []);
1255
+ const stateOverrides = [
381
1256
  {
382
1257
  address: this.rollupContract.address,
383
1258
  // @note we override checkBlob to false since blobs are not part simulate()
384
1259
  stateDiff: [
385
1260
  {
386
- slot: toHex(RollupContract.checkBlobStorageSlot, true),
387
- value: toHex(0n, true)
388
- }
1261
+ slot: toPaddedHex(RollupContract.checkBlobStorageSlot, true),
1262
+ value: toPaddedHex(0n, true)
1263
+ },
1264
+ ...forcePendingCheckpointNumberStateDiff
389
1265
  ]
390
1266
  }
391
- ], {
1267
+ ];
1268
+ // In fisherman mode, simulate as the proposer but with sufficient balance
1269
+ if (this.proposerAddressForSimulation) {
1270
+ stateOverrides.push({
1271
+ address: this.proposerAddressForSimulation.toString(),
1272
+ balance: 10n * WEI_CONST * WEI_CONST
1273
+ });
1274
+ }
1275
+ const simulationResult = await this.l1TxUtils.simulate({
1276
+ to: this.rollupContract.address,
1277
+ data: rollupData,
1278
+ gas: SequencerPublisher.PROPOSE_GAS_GUESS,
1279
+ ...this.proposerAddressForSimulation && {
1280
+ from: this.proposerAddressForSimulation.toString()
1281
+ }
1282
+ }, {
1283
+ // @note we add 1n to the timestamp because geth implementation doesn't like simulation timestamp to be equal to the current block timestamp
1284
+ time: timestamp + 1n,
1285
+ // @note reth should have a 30m gas limit per block but throws errors that this tx is beyond limit so we increase here
1286
+ gasLimit: SequencerPublisher.PROPOSE_GAS_GUESS * 2n
1287
+ }, stateOverrides, RollupAbi, {
392
1288
  // @note fallback gas estimate to use if the node doesn't support simulation API
393
1289
  fallbackGasEstimate: SequencerPublisher.PROPOSE_GAS_GUESS
394
1290
  }).catch((err)=>{
395
- const { message, metaMessages } = formatViemError(err);
396
- this.log.error(`Failed to simulate gas used`, message, {
397
- metaMessages
398
- });
399
- throw new Error('Failed to simulate gas used');
1291
+ // In fisherman mode, we expect ValidatorSelection__MissingProposerSignature since fisherman doesn't have proposer signature
1292
+ const viemError = formatViemError(err);
1293
+ if (this.config.fishermanMode && viemError.message?.includes('ValidatorSelection__MissingProposerSignature')) {
1294
+ this.log.debug(`Ignoring expected ValidatorSelection__MissingProposerSignature error in fisherman mode`);
1295
+ // Return a minimal simulation result with the fallback gas estimate
1296
+ return {
1297
+ gasUsed: SequencerPublisher.PROPOSE_GAS_GUESS,
1298
+ logs: []
1299
+ };
1300
+ }
1301
+ this.log.error(`Failed to simulate propose tx`, viemError);
1302
+ throw err;
400
1303
  });
401
1304
  return {
402
- args,
403
- blobEvaluationGas,
404
1305
  rollupData,
405
1306
  simulationResult
406
1307
  };
407
1308
  }
408
- async addProposeTx(block, encodedData, opts = {}, timestamp) {
1309
+ async addProposeTx(checkpoint, encodedData, opts = {}, timestamp) {
1310
+ const slot = checkpoint.header.slotNumber;
409
1311
  const timer = new Timer();
410
1312
  const kzg = Blob.getViemKzgInstance();
411
- const { rollupData, simulationResult, blobEvaluationGas } = await this.prepareProposeTx(encodedData, timestamp);
1313
+ const { rollupData, simulationResult, blobEvaluationGas } = await this.prepareProposeTx(encodedData, timestamp, opts);
412
1314
  const startBlock = await this.l1TxUtils.getBlockNumber();
413
- const blockHash = await block.hash();
1315
+ const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil(Number(simulationResult.gasUsed) * 64 / 63)) + blobEvaluationGas + SequencerPublisher.MULTICALL_OVERHEAD_GAS_GUESS);
1316
+ // Send the blobs to the blob client preemptively. This helps in tests where the sequencer mistakingly thinks that the propose
1317
+ // tx fails but it does get mined. We make sure that the blobs are sent to the blob client regardless of the tx outcome.
1318
+ void Promise.resolve().then(()=>this.blobClient.sendBlobsToFilestore(encodedData.blobs).catch((_err)=>{
1319
+ this.log.error('Failed to send blobs to blob client');
1320
+ }));
414
1321
  return this.addRequest({
415
1322
  action: 'propose',
416
1323
  request: {
417
1324
  to: this.rollupContract.address,
418
1325
  data: rollupData
419
1326
  },
420
- lastValidL2Slot: block.header.globalVariables.slotNumber.toBigInt(),
1327
+ lastValidL2Slot: checkpoint.header.slotNumber,
421
1328
  gasConfig: {
422
1329
  ...opts,
423
- gasLimit: this.l1TxUtils.bumpGasLimit(simulationResult + blobEvaluationGas)
1330
+ gasLimit
424
1331
  },
425
1332
  blobConfig: {
426
1333
  blobs: encodedData.blobs.map((b)=>b.data),
427
1334
  kzg
428
1335
  },
429
- onResult: (request, result)=>{
1336
+ checkSuccess: (_request, result)=>{
430
1337
  if (!result) {
431
- return;
1338
+ return false;
432
1339
  }
433
1340
  const { receipt, stats, errorMsg } = result;
434
- if (receipt.status === 'success') {
1341
+ const success = receipt && receipt.status === 'success' && tryExtractEvent(receipt.logs, this.rollupContract.address, RollupAbi, 'CheckpointProposed');
1342
+ if (success) {
435
1343
  const endBlock = receipt.blockNumber;
436
1344
  const inclusionBlocks = Number(endBlock - startBlock);
1345
+ const { calldataGas, calldataSize, sender } = stats;
437
1346
  const publishStats = {
438
1347
  gasPrice: receipt.effectiveGasPrice,
439
1348
  gasUsed: receipt.gasUsed,
440
1349
  blobGasUsed: receipt.blobGasUsed ?? 0n,
441
1350
  blobDataGas: receipt.blobGasPrice ?? 0n,
442
1351
  transactionHash: receipt.transactionHash,
443
- ...pick(stats, 'calldataGas', 'calldataSize', 'sender'),
444
- ...block.getStats(),
1352
+ calldataGas,
1353
+ calldataSize,
1354
+ sender,
1355
+ ...checkpoint.getStats(),
445
1356
  eventName: 'rollup-published-to-l1',
446
1357
  blobCount: encodedData.blobs.length,
447
1358
  inclusionBlocks
448
1359
  };
449
- this.log.verbose(`Published L2 block to L1 rollup contract`, {
1360
+ this.log.info(`Published checkpoint ${checkpoint.number} at slot ${slot} to rollup contract`, {
450
1361
  ...stats,
451
- ...block.getStats()
1362
+ ...checkpoint.getStats(),
1363
+ ...pick(receipt, 'transactionHash', 'blockHash')
452
1364
  });
453
1365
  this.metrics.recordProcessBlockTx(timer.ms(), publishStats);
454
- // Send the blobs to the blob sink
455
- this.sendBlobsToBlobSink(receipt.blockHash, encodedData.blobs).catch((_err)=>{
456
- this.log.error('Failed to send blobs to blob sink');
457
- });
458
1366
  return true;
459
1367
  } else {
460
1368
  this.metrics.recordFailedTx('process');
461
- this.log.error(`Rollup process tx reverted. ${errorMsg ?? 'No error message'}`, undefined, {
462
- ...block.getStats(),
463
- txHash: receipt.transactionHash,
464
- blockHash,
465
- slotNumber: block.header.globalVariables.slotNumber.toBigInt()
1369
+ this.log.error(`Publishing checkpoint at slot ${slot} failed with ${errorMsg ?? 'no error message'}`, undefined, {
1370
+ ...checkpoint.getStats(),
1371
+ ...receipt
466
1372
  });
1373
+ return false;
467
1374
  }
468
1375
  }
469
1376
  });
470
1377
  }
471
- /**
472
- * Send blobs to the blob sink
473
- *
474
- * If a blob sink url is configured, then we send blobs to the blob sink
475
- * - for now we use the blockHash as the identifier for the blobs;
476
- * In the future this will move to be the beacon block id - which takes a bit more work
477
- * to calculate and will need to be mocked in e2e tests
478
- */ sendBlobsToBlobSink(blockHash, blobs) {
479
- return this.blobSinkClient.sendBlobsToBlobSink(blockHash, blobs);
480
- }
481
1378
  }