@aztec/sequencer-client 0.0.1-commit.b655e406 → 0.0.1-commit.b6e433891

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 (119) hide show
  1. package/dest/client/index.d.ts +1 -1
  2. package/dest/client/sequencer-client.d.ts +21 -16
  3. package/dest/client/sequencer-client.d.ts.map +1 -1
  4. package/dest/client/sequencer-client.js +75 -28
  5. package/dest/config.d.ts +35 -9
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +113 -42
  8. package/dest/global_variable_builder/global_builder.d.ts +20 -16
  9. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  10. package/dest/global_variable_builder/global_builder.js +54 -40
  11. package/dest/global_variable_builder/index.d.ts +1 -1
  12. package/dest/index.d.ts +2 -3
  13. package/dest/index.d.ts.map +1 -1
  14. package/dest/index.js +1 -2
  15. package/dest/publisher/config.d.ts +43 -20
  16. package/dest/publisher/config.d.ts.map +1 -1
  17. package/dest/publisher/config.js +109 -34
  18. package/dest/publisher/index.d.ts +2 -1
  19. package/dest/publisher/index.d.ts.map +1 -1
  20. package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
  21. package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
  22. package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
  23. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +59 -0
  24. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
  25. package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
  26. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
  27. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
  28. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
  29. package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
  30. package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
  31. package/dest/publisher/l1_tx_failed_store/index.js +2 -0
  32. package/dest/publisher/sequencer-publisher-factory.d.ts +15 -6
  33. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  34. package/dest/publisher/sequencer-publisher-factory.js +28 -3
  35. package/dest/publisher/sequencer-publisher-metrics.d.ts +3 -3
  36. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  37. package/dest/publisher/sequencer-publisher-metrics.js +23 -86
  38. package/dest/publisher/sequencer-publisher.d.ts +103 -69
  39. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  40. package/dest/publisher/sequencer-publisher.js +999 -190
  41. package/dest/sequencer/checkpoint_proposal_job.d.ts +108 -0
  42. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  43. package/dest/sequencer/checkpoint_proposal_job.js +1289 -0
  44. package/dest/sequencer/checkpoint_voter.d.ts +35 -0
  45. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  46. package/dest/sequencer/checkpoint_voter.js +109 -0
  47. package/dest/sequencer/config.d.ts +3 -2
  48. package/dest/sequencer/config.d.ts.map +1 -1
  49. package/dest/sequencer/errors.d.ts +1 -1
  50. package/dest/sequencer/errors.d.ts.map +1 -1
  51. package/dest/sequencer/events.d.ts +47 -0
  52. package/dest/sequencer/events.d.ts.map +1 -0
  53. package/dest/sequencer/events.js +1 -0
  54. package/dest/sequencer/index.d.ts +4 -2
  55. package/dest/sequencer/index.d.ts.map +1 -1
  56. package/dest/sequencer/index.js +3 -1
  57. package/dest/sequencer/metrics.d.ts +48 -3
  58. package/dest/sequencer/metrics.d.ts.map +1 -1
  59. package/dest/sequencer/metrics.js +243 -50
  60. package/dest/sequencer/sequencer.d.ts +127 -144
  61. package/dest/sequencer/sequencer.d.ts.map +1 -1
  62. package/dest/sequencer/sequencer.js +770 -545
  63. package/dest/sequencer/timetable.d.ts +54 -16
  64. package/dest/sequencer/timetable.d.ts.map +1 -1
  65. package/dest/sequencer/timetable.js +147 -62
  66. package/dest/sequencer/types.d.ts +3 -0
  67. package/dest/sequencer/types.d.ts.map +1 -0
  68. package/dest/sequencer/types.js +1 -0
  69. package/dest/sequencer/utils.d.ts +14 -8
  70. package/dest/sequencer/utils.d.ts.map +1 -1
  71. package/dest/sequencer/utils.js +7 -4
  72. package/dest/test/index.d.ts +6 -7
  73. package/dest/test/index.d.ts.map +1 -1
  74. package/dest/test/mock_checkpoint_builder.d.ts +95 -0
  75. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  76. package/dest/test/mock_checkpoint_builder.js +231 -0
  77. package/dest/test/utils.d.ts +53 -0
  78. package/dest/test/utils.d.ts.map +1 -0
  79. package/dest/test/utils.js +104 -0
  80. package/package.json +32 -30
  81. package/src/client/sequencer-client.ts +100 -52
  82. package/src/config.ts +132 -51
  83. package/src/global_variable_builder/global_builder.ts +69 -60
  84. package/src/index.ts +1 -7
  85. package/src/publisher/config.ts +139 -50
  86. package/src/publisher/index.ts +3 -0
  87. package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
  88. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +55 -0
  89. package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
  90. package/src/publisher/l1_tx_failed_store/index.ts +3 -0
  91. package/src/publisher/sequencer-publisher-factory.ts +45 -11
  92. package/src/publisher/sequencer-publisher-metrics.ts +19 -71
  93. package/src/publisher/sequencer-publisher.ts +717 -248
  94. package/src/sequencer/README.md +531 -0
  95. package/src/sequencer/checkpoint_proposal_job.ts +1049 -0
  96. package/src/sequencer/checkpoint_voter.ts +130 -0
  97. package/src/sequencer/config.ts +2 -1
  98. package/src/sequencer/events.ts +27 -0
  99. package/src/sequencer/index.ts +3 -1
  100. package/src/sequencer/metrics.ts +310 -61
  101. package/src/sequencer/sequencer.ts +541 -735
  102. package/src/sequencer/timetable.ts +178 -83
  103. package/src/sequencer/types.ts +6 -0
  104. package/src/sequencer/utils.ts +18 -9
  105. package/src/test/index.ts +5 -6
  106. package/src/test/mock_checkpoint_builder.ts +323 -0
  107. package/src/test/utils.ts +167 -0
  108. package/dest/sequencer/block_builder.d.ts +0 -27
  109. package/dest/sequencer/block_builder.d.ts.map +0 -1
  110. package/dest/sequencer/block_builder.js +0 -130
  111. package/dest/tx_validator/nullifier_cache.d.ts +0 -14
  112. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  113. package/dest/tx_validator/nullifier_cache.js +0 -24
  114. package/dest/tx_validator/tx_validator_factory.d.ts +0 -17
  115. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  116. package/dest/tx_validator/tx_validator_factory.js +0 -53
  117. package/src/sequencer/block_builder.ts +0 -218
  118. package/src/tx_validator/nullifier_cache.ts +0 -30
  119. package/src/tx_validator/tx_validator_factory.ts +0 -132
@@ -1,48 +1,65 @@
1
- import { L2Block } from '@aztec/aztec.js/block';
1
+ import type { BlobClientInterface } from '@aztec/blob-client/client';
2
2
  import { Blob, getBlobsPerL1Block, getPrefixedEthBlobCommitments } from '@aztec/blob-lib';
3
- import { type BlobSinkClientInterface, createBlobSinkClient } from '@aztec/blob-sink/client';
4
3
  import type { EpochCache } from '@aztec/epoch-cache';
4
+ import type { L1ContractsConfig } from '@aztec/ethereum/config';
5
5
  import {
6
6
  type EmpireSlashingProposerContract,
7
- FormattedViemError,
7
+ FeeAssetPriceOracle,
8
8
  type GovernanceProposerContract,
9
9
  type IEmpireBase,
10
- type L1BlobInputs,
11
- type L1ContractsConfig,
12
- type L1TxConfig,
13
- type L1TxRequest,
14
10
  MULTI_CALL_3_ADDRESS,
15
11
  Multicall3,
16
12
  RollupContract,
17
13
  type TallySlashingProposerContract,
18
- type TransactionStats,
19
14
  type ViemCommitteeAttestations,
20
15
  type ViemHeader,
21
- type ViemStateReference,
22
- formatViemError,
23
- tryExtractEvent,
24
- } from '@aztec/ethereum';
25
- import type { L1TxUtilsWithBlobs } from '@aztec/ethereum/l1-tx-utils-with-blobs';
16
+ } from '@aztec/ethereum/contracts';
17
+ import { type L1FeeAnalysisResult, L1FeeAnalyzer } from '@aztec/ethereum/l1-fee-analysis';
18
+ import {
19
+ type L1BlobInputs,
20
+ type L1TxConfig,
21
+ type L1TxRequest,
22
+ type L1TxUtils,
23
+ MAX_L1_TX_LIMIT,
24
+ type TransactionStats,
25
+ WEI_CONST,
26
+ } from '@aztec/ethereum/l1-tx-utils';
27
+ import { FormattedViemError, formatViemError, mergeAbis, tryExtractEvent } from '@aztec/ethereum/utils';
26
28
  import { sumBigint } from '@aztec/foundation/bigint';
27
29
  import { toHex as toPaddedHex } from '@aztec/foundation/bigint-buffer';
30
+ import { CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
31
+ import { trimmedBytesLength } from '@aztec/foundation/buffer';
32
+ import { pick } from '@aztec/foundation/collection';
33
+ import type { Fr } from '@aztec/foundation/curves/bn254';
34
+ import { TimeoutError } from '@aztec/foundation/error';
28
35
  import { EthAddress } from '@aztec/foundation/eth-address';
29
36
  import { Signature, type ViemSignature } from '@aztec/foundation/eth-signature';
30
- import type { Fr } from '@aztec/foundation/fields';
31
37
  import { type Logger, createLogger } from '@aztec/foundation/log';
38
+ import { makeBackoff, retry } from '@aztec/foundation/retry';
32
39
  import { bufferToHex } from '@aztec/foundation/string';
33
40
  import { DateProvider, Timer } from '@aztec/foundation/timer';
34
41
  import { EmpireBaseAbi, ErrorsAbi, RollupAbi } from '@aztec/l1-artifacts';
35
42
  import { type ProposerSlashAction, encodeSlashConsensusVotes } from '@aztec/slasher';
36
- import { CommitteeAttestation, CommitteeAttestationsAndSigners, type ValidateBlockResult } from '@aztec/stdlib/block';
43
+ import { CommitteeAttestationsAndSigners, type ValidateCheckpointResult } from '@aztec/stdlib/block';
44
+ import type { Checkpoint } from '@aztec/stdlib/checkpoint';
37
45
  import { SlashFactoryContract } from '@aztec/stdlib/l1-contracts';
38
46
  import type { CheckpointHeader } from '@aztec/stdlib/rollup';
39
- import type { L1PublishBlockStats } from '@aztec/stdlib/stats';
40
- import { StateReference } from '@aztec/stdlib/tx';
41
- import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
42
-
43
- import { type TransactionReceipt, type TypedDataDefinition, encodeFunctionData, toHex } from 'viem';
47
+ import type { L1PublishCheckpointStats } from '@aztec/stdlib/stats';
48
+ import { type TelemetryClient, type Tracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
44
49
 
45
- import type { PublisherConfig, TxSenderConfig } from './config.js';
50
+ import {
51
+ type Hex,
52
+ type StateOverride,
53
+ type TransactionReceipt,
54
+ type TypedDataDefinition,
55
+ encodeFunctionData,
56
+ keccak256,
57
+ multicall3Abi,
58
+ toHex,
59
+ } from 'viem';
60
+
61
+ import type { SequencerPublisherConfig } from './config.js';
62
+ import { type FailedL1Tx, type L1TxFailedStore, createL1TxFailedStore } from './l1_tx_failed_store/index.js';
46
63
  import { SequencerPublisherMetrics } from './sequencer-publisher-metrics.js';
47
64
 
48
65
  /** Arguments to the process method of the rollup contract */
@@ -51,14 +68,14 @@ type L1ProcessArgs = {
51
68
  header: CheckpointHeader;
52
69
  /** A root of the archive tree after the L2 block is applied. */
53
70
  archive: Buffer;
54
- /** State reference after the L2 block is applied. */
55
- stateReference: StateReference;
56
71
  /** L2 block blobs containing all tx effects. */
57
72
  blobs: Blob[];
58
73
  /** Attestations */
59
74
  attestationsAndSigners: CommitteeAttestationsAndSigners;
60
75
  /** Attestations and signers signature */
61
76
  attestationsAndSignersSignature: Signature;
77
+ /** The fee asset price modifier in basis points (from oracle) */
78
+ feeAssetPriceModifier: bigint;
62
79
  };
63
80
 
64
81
  export const Actions = [
@@ -80,18 +97,18 @@ type GovernanceSignalAction = Extract<Action, 'governance-signal' | 'empire-slas
80
97
  // Sorting for actions such that invalidations go before proposals, and proposals go before votes
81
98
  export const compareActions = (a: Action, b: Action) => Actions.indexOf(a) - Actions.indexOf(b);
82
99
 
83
- export type InvalidateBlockRequest = {
100
+ export type InvalidateCheckpointRequest = {
84
101
  request: L1TxRequest;
85
102
  reason: 'invalid-attestation' | 'insufficient-attestations';
86
103
  gasUsed: bigint;
87
- blockNumber: number;
88
- forcePendingBlockNumber: number;
104
+ checkpointNumber: CheckpointNumber;
105
+ forcePendingCheckpointNumber: CheckpointNumber;
89
106
  };
90
107
 
91
108
  interface RequestWithExpiry {
92
109
  action: Action;
93
110
  request: L1TxRequest;
94
- lastValidL2Slot: bigint;
111
+ lastValidL2Slot: SlotNumber;
95
112
  gasConfig?: Pick<L1TxConfig, 'txTimeoutAt' | 'gasLimit'>;
96
113
  blobConfig?: L1BlobInputs;
97
114
  checkSuccess: (
@@ -104,20 +121,33 @@ export class SequencerPublisher {
104
121
  private interrupted = false;
105
122
  private metrics: SequencerPublisherMetrics;
106
123
  public epochCache: EpochCache;
124
+ private failedTxStore?: Promise<L1TxFailedStore | undefined>;
107
125
 
108
126
  protected governanceLog = createLogger('sequencer:publisher:governance');
109
127
  protected slashingLog = createLogger('sequencer:publisher:slashing');
110
128
 
111
- protected lastActions: Partial<Record<Action, bigint>> = {};
129
+ protected lastActions: Partial<Record<Action, SlotNumber>> = {};
130
+
131
+ private isPayloadEmptyCache: Map<string, boolean> = new Map<string, boolean>();
132
+ private payloadProposedCache: Set<string> = new Set<string>();
112
133
 
113
134
  protected log: Logger;
114
135
  protected ethereumSlotDuration: bigint;
136
+ protected aztecSlotDuration: bigint;
137
+
138
+ private blobClient: BlobClientInterface;
115
139
 
116
- private blobSinkClient: BlobSinkClientInterface;
117
- // @note - with blobs, the below estimate seems too large.
118
- // Total used for full block from int_l1_pub e2e test: 1m (of which 86k is 1x blob)
119
- // Total used for emptier block from above test: 429k (of which 84k is 1x blob)
120
- public static PROPOSE_GAS_GUESS: bigint = 12_000_000n;
140
+ /** Address to use for simulations in fisherman mode (actual proposer's address) */
141
+ private proposerAddressForSimulation?: EthAddress;
142
+
143
+ /** Optional callback to obtain a replacement publisher when the current one fails to send. */
144
+ private getNextPublisher?: (excludeAddresses: EthAddress[]) => Promise<L1TxUtils | undefined>;
145
+
146
+ /** L1 fee analyzer for fisherman mode */
147
+ private l1FeeAnalyzer?: L1FeeAnalyzer;
148
+
149
+ /** Fee asset price oracle for computing price modifiers from Uniswap V4 */
150
+ private feeAssetPriceOracle: FeeAssetPriceOracle;
121
151
 
122
152
  // A CALL to a cold address is 2700 gas
123
153
  public static MULTICALL_OVERHEAD_GAS_GUESS = 5000n;
@@ -125,20 +155,23 @@ export class SequencerPublisher {
125
155
  // Gas report for VotingWithSigTest shows a max gas of 100k, but we've seen it cost 700k+ in testnet
126
156
  public static VOTE_GAS_GUESS: bigint = 800_000n;
127
157
 
128
- public l1TxUtils: L1TxUtilsWithBlobs;
158
+ public l1TxUtils: L1TxUtils;
129
159
  public rollupContract: RollupContract;
130
160
  public govProposerContract: GovernanceProposerContract;
131
161
  public slashingProposerContract: EmpireSlashingProposerContract | TallySlashingProposerContract | undefined;
132
162
  public slashFactoryContract: SlashFactoryContract;
133
163
 
164
+ public readonly tracer: Tracer;
165
+
134
166
  protected requests: RequestWithExpiry[] = [];
135
167
 
136
168
  constructor(
137
- private config: TxSenderConfig & PublisherConfig & Pick<L1ContractsConfig, 'ethereumSlotDuration'>,
169
+ private config: Pick<SequencerPublisherConfig, 'fishermanMode' | 'l1TxFailedStore'> &
170
+ Pick<L1ContractsConfig, 'ethereumSlotDuration' | 'aztecSlotDuration'> & { l1ChainId: number },
138
171
  deps: {
139
172
  telemetry?: TelemetryClient;
140
- blobSinkClient?: BlobSinkClientInterface;
141
- l1TxUtils: L1TxUtilsWithBlobs;
173
+ blobClient: BlobClientInterface;
174
+ l1TxUtils: L1TxUtils;
142
175
  rollupContract: RollupContract;
143
176
  slashingProposerContract: EmpireSlashingProposerContract | TallySlashingProposerContract | undefined;
144
177
  governanceProposerContract: GovernanceProposerContract;
@@ -146,21 +179,24 @@ export class SequencerPublisher {
146
179
  epochCache: EpochCache;
147
180
  dateProvider: DateProvider;
148
181
  metrics: SequencerPublisherMetrics;
149
- lastActions: Partial<Record<Action, bigint>>;
182
+ lastActions: Partial<Record<Action, SlotNumber>>;
150
183
  log?: Logger;
184
+ getNextPublisher?: (excludeAddresses: EthAddress[]) => Promise<L1TxUtils | undefined>;
151
185
  },
152
186
  ) {
153
187
  this.log = deps.log ?? createLogger('sequencer:publisher');
154
188
  this.ethereumSlotDuration = BigInt(config.ethereumSlotDuration);
189
+ this.aztecSlotDuration = BigInt(config.aztecSlotDuration);
155
190
  this.epochCache = deps.epochCache;
156
191
  this.lastActions = deps.lastActions;
157
192
 
158
- this.blobSinkClient =
159
- deps.blobSinkClient ?? createBlobSinkClient(config, { logger: createLogger('sequencer:blob-sink:client') });
193
+ this.blobClient = deps.blobClient;
160
194
 
161
195
  const telemetry = deps.telemetry ?? getTelemetryClient();
162
196
  this.metrics = deps.metrics ?? new SequencerPublisherMetrics(telemetry, 'SequencerPublisher');
197
+ this.tracer = telemetry.getTracer('SequencerPublisher');
163
198
  this.l1TxUtils = deps.l1TxUtils;
199
+ this.getNextPublisher = deps.getNextPublisher;
164
200
 
165
201
  this.rollupContract = deps.rollupContract;
166
202
 
@@ -173,22 +209,153 @@ export class SequencerPublisher {
173
209
  this.slashingProposerContract = newSlashingProposer;
174
210
  });
175
211
  this.slashFactoryContract = deps.slashFactoryContract;
212
+
213
+ // Initialize L1 fee analyzer for fisherman mode
214
+ if (config.fishermanMode) {
215
+ this.l1FeeAnalyzer = new L1FeeAnalyzer(
216
+ this.l1TxUtils.client,
217
+ deps.dateProvider,
218
+ createLogger('sequencer:publisher:fee-analyzer'),
219
+ );
220
+ }
221
+
222
+ // Initialize fee asset price oracle
223
+ this.feeAssetPriceOracle = new FeeAssetPriceOracle(
224
+ this.l1TxUtils.client,
225
+ this.rollupContract,
226
+ createLogger('sequencer:publisher:price-oracle'),
227
+ );
228
+
229
+ // Initialize failed L1 tx store (optional, for test networks)
230
+ this.failedTxStore = createL1TxFailedStore(config.l1TxFailedStore, this.log);
231
+ }
232
+
233
+ /**
234
+ * Backs up a failed L1 transaction to the configured store for debugging.
235
+ * Does nothing if no store is configured.
236
+ */
237
+ private backupFailedTx(failedTx: Omit<FailedL1Tx, 'timestamp'>): void {
238
+ if (!this.failedTxStore) {
239
+ return;
240
+ }
241
+
242
+ const tx: FailedL1Tx = {
243
+ ...failedTx,
244
+ timestamp: Date.now(),
245
+ };
246
+
247
+ // Fire and forget - don't block on backup
248
+ void this.failedTxStore
249
+ .then(store => store?.saveFailedTx(tx))
250
+ .catch(err => {
251
+ this.log.warn(`Failed to backup failed L1 tx to store`, err);
252
+ });
176
253
  }
177
254
 
178
255
  public getRollupContract(): RollupContract {
179
256
  return this.rollupContract;
180
257
  }
181
258
 
259
+ /**
260
+ * Gets the fee asset price modifier from the oracle.
261
+ * Returns 0n if the oracle query fails.
262
+ */
263
+ public getFeeAssetPriceModifier(): Promise<bigint> {
264
+ return this.feeAssetPriceOracle.computePriceModifier();
265
+ }
266
+
182
267
  public getSenderAddress() {
183
268
  return this.l1TxUtils.getSenderAddress();
184
269
  }
185
270
 
271
+ /**
272
+ * Gets the L1 fee analyzer instance (only available in fisherman mode)
273
+ */
274
+ public getL1FeeAnalyzer(): L1FeeAnalyzer | undefined {
275
+ return this.l1FeeAnalyzer;
276
+ }
277
+
278
+ /**
279
+ * Sets the proposer address to use for simulations in fisherman mode.
280
+ * @param proposerAddress - The actual proposer's address to use for balance lookups in simulations
281
+ */
282
+ public setProposerAddressForSimulation(proposerAddress: EthAddress | undefined) {
283
+ this.proposerAddressForSimulation = proposerAddress;
284
+ }
285
+
186
286
  public addRequest(request: RequestWithExpiry) {
187
287
  this.requests.push(request);
188
288
  }
189
289
 
190
- public getCurrentL2Slot(): bigint {
191
- return this.epochCache.getEpochAndSlotNow().slot;
290
+ public getCurrentL2Slot(): SlotNumber {
291
+ return this.epochCache.getSlotNow();
292
+ }
293
+
294
+ /**
295
+ * Clears all pending requests without sending them.
296
+ */
297
+ public clearPendingRequests(): void {
298
+ const count = this.requests.length;
299
+ this.requests = [];
300
+ if (count > 0) {
301
+ this.log.debug(`Cleared ${count} pending request(s)`);
302
+ }
303
+ }
304
+
305
+ /**
306
+ * Analyzes L1 fees for the pending requests without sending them.
307
+ * This is used in fisherman mode to validate fee calculations.
308
+ * @param l2SlotNumber - The L2 slot number for this analysis
309
+ * @param onComplete - Optional callback to invoke when analysis completes (after block is mined)
310
+ * @returns The analysis result (incomplete until block mines), or undefined if no requests
311
+ */
312
+ public async analyzeL1Fees(
313
+ l2SlotNumber: SlotNumber,
314
+ onComplete?: (analysis: L1FeeAnalysisResult) => void,
315
+ ): Promise<L1FeeAnalysisResult | undefined> {
316
+ if (!this.l1FeeAnalyzer) {
317
+ this.log.warn('L1 fee analyzer not available (not in fisherman mode)');
318
+ return undefined;
319
+ }
320
+
321
+ const requestsToAnalyze = [...this.requests];
322
+ if (requestsToAnalyze.length === 0) {
323
+ this.log.debug('No requests to analyze for L1 fees');
324
+ return undefined;
325
+ }
326
+
327
+ // Extract blob config from requests (if any)
328
+ const blobConfigs = requestsToAnalyze.filter(request => request.blobConfig).map(request => request.blobConfig);
329
+ const blobConfig = blobConfigs[0];
330
+
331
+ // Get gas configs
332
+ const gasConfigs = requestsToAnalyze.filter(request => request.gasConfig).map(request => request.gasConfig);
333
+ const gasLimits = gasConfigs.map(g => g?.gasLimit).filter((g): g is bigint => g !== undefined);
334
+ const gasLimit = gasLimits.length > 0 ? gasLimits.reduce((sum, g) => sum + g, 0n) : 0n;
335
+
336
+ // Get the transaction requests
337
+ const l1Requests = requestsToAnalyze.map(r => r.request);
338
+
339
+ // Start the analysis
340
+ const analysisId = await this.l1FeeAnalyzer.startAnalysis(
341
+ l2SlotNumber,
342
+ gasLimit > 0n ? gasLimit : MAX_L1_TX_LIMIT,
343
+ l1Requests,
344
+ blobConfig,
345
+ onComplete,
346
+ );
347
+
348
+ this.log.info('Started L1 fee analysis', {
349
+ analysisId,
350
+ l2SlotNumber: l2SlotNumber.toString(),
351
+ requestCount: requestsToAnalyze.length,
352
+ hasBlobConfig: !!blobConfig,
353
+ gasLimit: gasLimit.toString(),
354
+ actions: requestsToAnalyze.map(r => r.action),
355
+ });
356
+
357
+ // Return the analysis result (will be incomplete until block mines)
358
+ return this.l1FeeAnalyzer.getAnalysis(analysisId);
192
359
  }
193
360
 
194
361
  /**
@@ -198,10 +365,11 @@ export class SequencerPublisher {
198
365
  * - a receipt and errorMsg if it failed on L1
199
366
  * - undefined if no valid requests are found OR the tx failed to send.
200
367
  */
368
+ @trackSpan('SequencerPublisher.sendRequests')
201
369
  public async sendRequests() {
202
370
  const requestsToProcess = [...this.requests];
203
371
  this.requests = [];
204
- if (this.interrupted) {
372
+ if (this.interrupted || requestsToProcess.length === 0) {
205
373
  return undefined;
206
374
  }
207
375
  const currentL2Slot = this.getCurrentL2Slot();
@@ -233,8 +401,8 @@ export class SequencerPublisher {
233
401
  // @note - we can only have one blob config per bundle
234
402
  // find requests with gas and blob configs
235
403
  // See https://github.com/AztecProtocol/aztec-packages/issues/11513
236
- const gasConfigs = requestsToProcess.filter(request => request.gasConfig).map(request => request.gasConfig);
237
- const blobConfigs = requestsToProcess.filter(request => request.blobConfig).map(request => request.blobConfig);
404
+ const gasConfigs = validRequests.filter(request => request.gasConfig).map(request => request.gasConfig);
405
+ const blobConfigs = validRequests.filter(request => request.blobConfig).map(request => request.blobConfig);
238
406
 
239
407
  if (blobConfigs.length > 1) {
240
408
  throw new Error('Multiple blob configs found');
@@ -244,7 +412,16 @@ export class SequencerPublisher {
244
412
 
245
413
  // Merge gasConfigs. Yields the sum of gasLimits, and the earliest txTimeoutAt, or undefined if no gasConfig sets them.
246
414
  const gasLimits = gasConfigs.map(g => g?.gasLimit).filter((g): g is bigint => g !== undefined);
247
- const gasLimit = gasLimits.length > 0 ? sumBigint(gasLimits) : undefined; // sum
415
+ let gasLimit = gasLimits.length > 0 ? sumBigint(gasLimits) : undefined; // sum
416
+ // Cap at L1 block gas limit so the node accepts the tx ("gas limit too high" otherwise).
417
+ const maxGas = MAX_L1_TX_LIMIT;
418
+ if (gasLimit !== undefined && gasLimit > maxGas) {
419
+ this.log.debug('Capping bundled tx gas limit to L1 max', {
420
+ requested: gasLimit,
421
+ capped: maxGas,
422
+ });
423
+ gasLimit = maxGas;
424
+ }
248
425
  const txTimeoutAts = gasConfigs.map(g => g?.txTimeoutAt).filter((g): g is Date => g !== undefined);
249
426
  const txTimeoutAt = txTimeoutAts.length > 0 ? new Date(Math.min(...txTimeoutAts.map(g => g.getTime()))) : undefined; // earliest
250
427
  const txConfig: RequestWithExpiry['gasConfig'] = { gasLimit, txTimeoutAt };
@@ -254,19 +431,36 @@ export class SequencerPublisher {
254
431
  validRequests.sort((a, b) => compareActions(a.action, b.action));
255
432
 
256
433
  try {
434
+ // Capture context for failed tx backup before sending
435
+ const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
436
+ const multicallData = encodeFunctionData({
437
+ abi: multicall3Abi,
438
+ functionName: 'aggregate3',
439
+ args: [
440
+ validRequests.map(r => ({
441
+ target: r.request.to!,
442
+ callData: r.request.data!,
443
+ allowFailure: true,
444
+ })),
445
+ ],
446
+ });
447
+ const blobDataHex = blobConfig?.blobs?.map(b => toHex(b)) as Hex[] | undefined;
448
+
449
+ const txContext = { multicallData, blobData: blobDataHex, l1BlockNumber };
450
+
257
451
  this.log.debug('Forwarding transactions', {
258
452
  validRequests: validRequests.map(request => request.action),
259
453
  txConfig,
260
454
  });
261
- const result = await Multicall3.forward(
262
- validRequests.map(request => request.request),
263
- this.l1TxUtils,
264
- txConfig,
265
- blobConfig,
266
- this.rollupContract.address,
267
- this.log,
455
+ const result = await this.forwardWithPublisherRotation(validRequests, txConfig, blobConfig);
456
+ if (result === undefined) {
457
+ return undefined;
458
+ }
459
+ const { successfulActions = [], failedActions = [] } = this.callbackBundledTransactions(
460
+ validRequests,
461
+ result,
462
+ txContext,
268
463
  );
269
- const { successfulActions = [], failedActions = [] } = this.callbackBundledTransactions(validRequests, result);
270
464
  return { result, expiredActions, sentActions: validActions, successfulActions, failedActions };
271
465
  } catch (err) {
272
466
  const viemError = formatViemError(err);
@@ -284,16 +478,88 @@ export class SequencerPublisher {
284
478
  }
285
479
  }
286
480
 
481
+ /**
482
+ * Forwards transactions via Multicall3, rotating to the next available publisher if a send
483
+ * failure occurs (i.e. the tx never reached the chain).
484
+ * On-chain reverts and simulation errors are returned as-is without rotation.
485
+ */
486
+ private async forwardWithPublisherRotation(
487
+ validRequests: RequestWithExpiry[],
488
+ txConfig: RequestWithExpiry['gasConfig'],
489
+ blobConfig: L1BlobInputs | undefined,
490
+ ) {
491
+ const triedAddresses: EthAddress[] = [];
492
+ let currentPublisher = this.l1TxUtils;
493
+
494
+ while (true) {
495
+ triedAddresses.push(currentPublisher.getSenderAddress());
496
+ try {
497
+ const result = await Multicall3.forward(
498
+ validRequests.map(r => r.request),
499
+ currentPublisher,
500
+ txConfig,
501
+ blobConfig,
502
+ this.rollupContract.address,
503
+ this.log,
504
+ );
505
+ this.l1TxUtils = currentPublisher;
506
+ return result;
507
+ } catch (err) {
508
+ if (err instanceof TimeoutError) {
509
+ throw err;
510
+ }
511
+ const viemError = formatViemError(err);
512
+ if (!this.getNextPublisher) {
513
+ this.log.error('Failed to publish bundled transactions', viemError);
514
+ return undefined;
515
+ }
516
+ this.log.warn(
517
+ `Publisher ${currentPublisher.getSenderAddress()} failed to send, rotating to next publisher`,
518
+ viemError,
519
+ );
520
+ const nextPublisher = await this.getNextPublisher([...triedAddresses]);
521
+ if (!nextPublisher) {
522
+ this.log.error('All available publishers exhausted, failed to publish bundled transactions');
523
+ return undefined;
524
+ }
525
+ currentPublisher = nextPublisher;
526
+ }
527
+ }
528
+ }
529
+
287
530
  private callbackBundledTransactions(
288
531
  requests: RequestWithExpiry[],
289
- result?: { receipt: TransactionReceipt } | FormattedViemError,
532
+ result: { receipt: TransactionReceipt; errorMsg?: string } | FormattedViemError | undefined,
533
+ txContext: { multicallData: Hex; blobData?: Hex[]; l1BlockNumber: bigint },
290
534
  ) {
291
535
  const actionsListStr = requests.map(r => r.action).join(', ');
292
536
  if (result instanceof FormattedViemError) {
293
537
  this.log.error(`Failed to publish bundled transactions (${actionsListStr})`, result);
538
+ this.backupFailedTx({
539
+ id: keccak256(txContext.multicallData),
540
+ failureType: 'send-error',
541
+ request: { to: MULTI_CALL_3_ADDRESS, data: txContext.multicallData },
542
+ blobData: txContext.blobData,
543
+ l1BlockNumber: txContext.l1BlockNumber.toString(),
544
+ error: { message: result.message, name: result.name },
545
+ context: {
546
+ actions: requests.map(r => r.action),
547
+ requests: requests.map(r => ({ action: r.action, to: r.request.to! as Hex, data: r.request.data! })),
548
+ sender: this.getSenderAddress().toString(),
549
+ },
550
+ });
294
551
  return { failedActions: requests.map(r => r.action) };
295
552
  } else {
296
- this.log.verbose(`Published bundled transactions (${actionsListStr})`, { result, requests });
553
+ this.log.verbose(`Published bundled transactions (${actionsListStr})`, {
554
+ result,
555
+ requests: requests.map(r => ({
556
+ ...r,
557
+ // Avoid logging large blob data
558
+ blobConfig: r.blobConfig
559
+ ? { ...r.blobConfig, blobs: r.blobConfig.blobs.map(b => ({ size: trimmedBytesLength(b) })) }
560
+ : undefined,
561
+ })),
562
+ });
297
563
  const successfulActions: Action[] = [];
298
564
  const failedActions: Action[] = [];
299
565
  for (const request of requests) {
@@ -303,25 +569,54 @@ export class SequencerPublisher {
303
569
  failedActions.push(request.action);
304
570
  }
305
571
  }
572
+ // Single backup for the whole reverted tx
573
+ if (failedActions.length > 0 && result?.receipt?.status === 'reverted') {
574
+ this.backupFailedTx({
575
+ id: result.receipt.transactionHash,
576
+ failureType: 'revert',
577
+ request: { to: MULTI_CALL_3_ADDRESS, data: txContext.multicallData },
578
+ blobData: txContext.blobData,
579
+ l1BlockNumber: result.receipt.blockNumber.toString(),
580
+ receipt: {
581
+ transactionHash: result.receipt.transactionHash,
582
+ blockNumber: result.receipt.blockNumber.toString(),
583
+ gasUsed: (result.receipt.gasUsed ?? 0n).toString(),
584
+ status: 'reverted',
585
+ },
586
+ error: { message: result.errorMsg ?? 'Transaction reverted' },
587
+ context: {
588
+ actions: failedActions,
589
+ requests: requests
590
+ .filter(r => failedActions.includes(r.action))
591
+ .map(r => ({ action: r.action, to: r.request.to! as Hex, data: r.request.data! })),
592
+ sender: this.getSenderAddress().toString(),
593
+ },
594
+ });
595
+ }
306
596
  return { successfulActions, failedActions };
307
597
  }
308
598
  }
309
599
 
310
600
  /**
311
- * @notice Will call `canProposeAtNextEthBlock` to make sure that it is possible to propose
601
+ * @notice Will call `canProposeAt` to make sure that it is possible to propose
312
602
  * @param tipArchive - The archive to check
313
603
  * @returns The slot and block number if it is possible to propose, undefined otherwise
314
604
  */
315
- public canProposeAtNextEthBlock(
605
+ public canProposeAt(
316
606
  tipArchive: Fr,
317
607
  msgSender: EthAddress,
318
- opts: { forcePendingBlockNumber?: number } = {},
608
+ opts: { forcePendingCheckpointNumber?: CheckpointNumber; pipelined?: boolean } = {},
319
609
  ) {
320
610
  // TODO: #14291 - should loop through multiple keys to check if any of them can propose
321
611
  const ignoredErrors = ['SlotAlreadyInChain', 'InvalidProposer', 'InvalidArchive'];
322
612
 
613
+ const pipelined = opts.pipelined ?? this.epochCache.isProposerPipeliningEnabled();
614
+ const slotOffset = pipelined ? this.aztecSlotDuration : 0n;
615
+
323
616
  return this.rollupContract
324
- .canProposeAtNextEthBlock(tipArchive.toBuffer(), msgSender.toString(), this.ethereumSlotDuration, opts)
617
+ .canProposeAt(tipArchive.toBuffer(), msgSender.toString(), this.ethereumSlotDuration, slotOffset, {
618
+ forcePendingCheckpointNumber: opts.forcePendingCheckpointNumber,
619
+ })
325
620
  .catch(err => {
326
621
  if (err instanceof FormattedViemError && ignoredErrors.find(e => err.message.includes(e))) {
327
622
  this.log.warn(`Failed canProposeAtTime check with ${ignoredErrors.find(e => err.message.includes(e))}`, {
@@ -333,13 +628,18 @@ export class SequencerPublisher {
333
628
  return undefined;
334
629
  });
335
630
  }
631
+
336
632
  /**
337
633
  * @notice Will simulate `validateHeader` to make sure that the block header is valid
338
634
  * @dev This is a convenience function that can be used by the sequencer to validate a "partial" header.
339
635
  * It will throw if the block header is invalid.
340
636
  * @param header - The block header to validate
341
637
  */
342
- public async validateBlockHeader(header: CheckpointHeader, opts?: { forcePendingBlockNumber: number | undefined }) {
638
+ @trackSpan('SequencerPublisher.validateBlockHeader')
639
+ public async validateBlockHeader(
640
+ header: CheckpointHeader,
641
+ opts?: { forcePendingCheckpointNumber: CheckpointNumber | undefined },
642
+ ): Promise<void> {
343
643
  const flags = { ignoreDA: true, ignoreSignatures: true };
344
644
 
345
645
  const args = [
@@ -348,15 +648,27 @@ export class SequencerPublisher {
348
648
  [], // no signers
349
649
  Signature.empty().toViemSignature(),
350
650
  `0x${'0'.repeat(64)}`, // 32 empty bytes
351
- header.contentCommitment.blobsHash.toString(),
651
+ header.blobsHash.toString(),
352
652
  flags,
353
653
  ] as const;
354
654
 
355
655
  const ts = BigInt((await this.l1TxUtils.getBlock()).timestamp + this.ethereumSlotDuration);
656
+ const stateOverrides = await this.rollupContract.makePendingCheckpointNumberOverride(
657
+ opts?.forcePendingCheckpointNumber,
658
+ );
659
+ let balance = 0n;
660
+ if (this.config.fishermanMode) {
661
+ // In fisherman mode, we can't know where the proposer is publishing from
662
+ // so we just add sufficient balance to the multicall3 address
663
+ balance = 10n * WEI_CONST * WEI_CONST; // 10 ETH
664
+ } else {
665
+ balance = await this.l1TxUtils.getSenderBalance();
666
+ }
667
+ stateOverrides.push({
668
+ address: MULTI_CALL_3_ADDRESS,
669
+ balance,
670
+ });
356
671
 
357
- // use sender balance to simulate
358
- const balance = await this.l1TxUtils.getSenderBalance();
359
- this.log.debug(`Simulating validateHeader with balance: ${balance}`);
360
672
  await this.l1TxUtils.simulate(
361
673
  {
362
674
  to: this.rollupContract.address,
@@ -364,86 +676,115 @@ export class SequencerPublisher {
364
676
  from: MULTI_CALL_3_ADDRESS,
365
677
  },
366
678
  { time: ts + 1n },
367
- [
368
- { address: MULTI_CALL_3_ADDRESS, balance },
369
- ...(await this.rollupContract.makePendingBlockNumberOverride(opts?.forcePendingBlockNumber)),
370
- ],
679
+ stateOverrides,
371
680
  );
372
681
  this.log.debug(`Simulated validateHeader`);
373
682
  }
374
683
 
375
684
  /**
376
- * Simulate making a call to invalidate a block with invalid attestations. Returns undefined if no need to invalidate.
377
- * @param block - The block to invalidate and the criteria for invalidation (as returned by the archiver)
685
+ * Simulate making a call to invalidate a checkpoint with invalid attestations. Returns undefined if no need to invalidate.
686
+ * @param validationResult - The validation result indicating which checkpoint to invalidate (as returned by the archiver)
378
687
  */
379
- public async simulateInvalidateBlock(
380
- validationResult: ValidateBlockResult,
381
- ): Promise<InvalidateBlockRequest | undefined> {
688
+ public async simulateInvalidateCheckpoint(
689
+ validationResult: ValidateCheckpointResult,
690
+ ): Promise<InvalidateCheckpointRequest | undefined> {
382
691
  if (validationResult.valid) {
383
692
  return undefined;
384
693
  }
385
694
 
386
- const { reason, block } = validationResult;
387
- const blockNumber = block.blockNumber;
388
- const logData = { ...block, reason };
695
+ const { reason, checkpoint } = validationResult;
696
+ const checkpointNumber = checkpoint.checkpointNumber;
697
+ const logData = { ...checkpoint, reason };
389
698
 
390
- const currentBlockNumber = await this.rollupContract.getBlockNumber();
391
- if (currentBlockNumber < validationResult.block.blockNumber) {
699
+ const currentCheckpointNumber = await this.rollupContract.getCheckpointNumber();
700
+ if (currentCheckpointNumber < checkpointNumber) {
392
701
  this.log.verbose(
393
- `Skipping block ${blockNumber} invalidation since it has already been removed from the pending chain`,
394
- { currentBlockNumber, ...logData },
702
+ `Skipping checkpoint ${checkpointNumber} invalidation since it has already been removed from the pending chain`,
703
+ { currentCheckpointNumber, ...logData },
395
704
  );
396
705
  return undefined;
397
706
  }
398
707
 
399
- const request = this.buildInvalidateBlockRequest(validationResult);
400
- this.log.debug(`Simulating invalidate block ${blockNumber}`, { ...logData, request });
708
+ const request = this.buildInvalidateCheckpointRequest(validationResult);
709
+ this.log.debug(`Simulating invalidate checkpoint ${checkpointNumber}`, { ...logData, request });
710
+
711
+ const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
401
712
 
402
713
  try {
403
- const { gasUsed } = await this.l1TxUtils.simulate(request, undefined, undefined, ErrorsAbi);
404
- this.log.verbose(`Simulation for invalidate block ${blockNumber} succeeded`, { ...logData, request, gasUsed });
714
+ const { gasUsed } = await this.l1TxUtils.simulate(
715
+ request,
716
+ undefined,
717
+ undefined,
718
+ mergeAbis([request.abi ?? [], ErrorsAbi]),
719
+ );
720
+ this.log.verbose(`Simulation for invalidate checkpoint ${checkpointNumber} succeeded`, {
721
+ ...logData,
722
+ request,
723
+ gasUsed,
724
+ });
405
725
 
406
- return { request, gasUsed, blockNumber, forcePendingBlockNumber: blockNumber - 1, reason };
726
+ return {
727
+ request,
728
+ gasUsed,
729
+ checkpointNumber,
730
+ forcePendingCheckpointNumber: CheckpointNumber(checkpointNumber - 1),
731
+ reason,
732
+ };
407
733
  } catch (err) {
408
734
  const viemError = formatViemError(err);
409
735
 
410
- // If the error is due to the block not being in the pending chain, and it was indeed removed by someone else,
411
- // we can safely ignore it and return undefined so we go ahead with block building.
412
- if (viemError.message?.includes('Rollup__BlockNotInPendingChain')) {
736
+ // If the error is due to the checkpoint not being in the pending chain, and it was indeed removed by someone else,
737
+ // we can safely ignore it and return undefined so we go ahead with checkpoint building.
738
+ if (viemError.message?.includes('Rollup__CheckpointNotInPendingChain')) {
413
739
  this.log.verbose(
414
- `Simulation for invalidate block ${blockNumber} failed due to block not being in pending chain`,
740
+ `Simulation for invalidate checkpoint ${checkpointNumber} failed due to checkpoint not being in pending chain`,
415
741
  { ...logData, request, error: viemError.message },
416
742
  );
417
- const latestPendingBlockNumber = await this.rollupContract.getBlockNumber();
418
- if (latestPendingBlockNumber < blockNumber) {
419
- this.log.verbose(`Block number ${blockNumber} has already been invalidated`, { ...logData });
743
+ const latestPendingCheckpointNumber = await this.rollupContract.getCheckpointNumber();
744
+ if (latestPendingCheckpointNumber < checkpointNumber) {
745
+ this.log.verbose(`Checkpoint ${checkpointNumber} has already been invalidated`, { ...logData });
420
746
  return undefined;
421
747
  } else {
422
748
  this.log.error(
423
- `Simulation for invalidate ${blockNumber} failed and it is still in pending chain`,
749
+ `Simulation for invalidate checkpoint ${checkpointNumber} failed and it is still in pending chain`,
424
750
  viemError,
425
751
  logData,
426
752
  );
427
- throw new Error(`Failed to simulate invalidate block ${blockNumber} while it is still in pending chain`, {
428
- cause: viemError,
429
- });
753
+ throw new Error(
754
+ `Failed to simulate invalidate checkpoint ${checkpointNumber} while it is still in pending chain`,
755
+ {
756
+ cause: viemError,
757
+ },
758
+ );
430
759
  }
431
760
  }
432
761
 
433
- // Otherwise, throw. We cannot build the next block if we cannot invalidate the previous one.
434
- this.log.error(`Simulation for invalidate block ${blockNumber} failed`, viemError, logData);
435
- throw new Error(`Failed to simulate invalidate block ${blockNumber}`, { cause: viemError });
762
+ // Otherwise, throw. We cannot build the next checkpoint if we cannot invalidate the previous one.
763
+ this.log.error(`Simulation for invalidate checkpoint ${checkpointNumber} failed`, viemError, logData);
764
+ this.backupFailedTx({
765
+ id: keccak256(request.data!),
766
+ failureType: 'simulation',
767
+ request: { to: request.to!, data: request.data!, value: request.value?.toString() },
768
+ l1BlockNumber: l1BlockNumber.toString(),
769
+ error: { message: viemError.message, name: viemError.name },
770
+ context: {
771
+ actions: [`invalidate-${reason}`],
772
+ checkpointNumber,
773
+ sender: this.getSenderAddress().toString(),
774
+ },
775
+ });
776
+ throw new Error(`Failed to simulate invalidate checkpoint ${checkpointNumber}`, { cause: viemError });
436
777
  }
437
778
  }
438
779
 
439
- private buildInvalidateBlockRequest(validationResult: ValidateBlockResult) {
780
+ private buildInvalidateCheckpointRequest(validationResult: ValidateCheckpointResult) {
440
781
  if (validationResult.valid) {
441
- throw new Error('Cannot invalidate a valid block');
782
+ throw new Error('Cannot invalidate a valid checkpoint');
442
783
  }
443
784
 
444
- const { block, committee, reason } = validationResult;
445
- const logData = { ...block, reason };
446
- this.log.debug(`Simulating invalidate block ${block.blockNumber}`, logData);
785
+ const { checkpoint, committee, reason } = validationResult;
786
+ const logData = { ...checkpoint, reason };
787
+ this.log.debug(`Building invalidate checkpoint ${checkpoint.checkpointNumber} request`, logData);
447
788
 
448
789
  const attestationsAndSigners = new CommitteeAttestationsAndSigners(
449
790
  validationResult.attestations,
@@ -451,14 +792,14 @@ export class SequencerPublisher {
451
792
 
452
793
  if (reason === 'invalid-attestation') {
453
794
  return this.rollupContract.buildInvalidateBadAttestationRequest(
454
- block.blockNumber,
795
+ checkpoint.checkpointNumber,
455
796
  attestationsAndSigners,
456
797
  committee,
457
798
  validationResult.invalidIndex,
458
799
  );
459
800
  } else if (reason === 'insufficient-attestations') {
460
801
  return this.rollupContract.buildInvalidateInsufficientAttestationsRequest(
461
- block.blockNumber,
802
+ checkpoint.checkpointNumber,
462
803
  attestationsAndSigners,
463
804
  committee,
464
805
  );
@@ -468,48 +809,27 @@ export class SequencerPublisher {
468
809
  }
469
810
  }
470
811
 
471
- /**
472
- * @notice Will simulate `propose` to make sure that the block is valid for submission
473
- *
474
- * @dev Throws if unable to propose
475
- *
476
- * @param block - The block to propose
477
- * @param attestationData - The block's attestation data
478
- *
479
- */
480
- public async validateBlockForSubmission(
481
- block: L2Block,
812
+ /** Simulates `propose` to make sure that the checkpoint is valid for submission */
813
+ @trackSpan('SequencerPublisher.validateCheckpointForSubmission')
814
+ public async validateCheckpointForSubmission(
815
+ checkpoint: Checkpoint,
482
816
  attestationsAndSigners: CommitteeAttestationsAndSigners,
483
817
  attestationsAndSignersSignature: Signature,
484
- options: { forcePendingBlockNumber?: number },
818
+ options: { forcePendingCheckpointNumber?: CheckpointNumber },
485
819
  ): Promise<bigint> {
486
- const ts = BigInt((await this.l1TxUtils.getBlock()).timestamp + this.ethereumSlotDuration);
487
-
488
- // If we have no attestations, we still need to provide the empty attestations
489
- // so that the committee is recalculated correctly
490
- const ignoreSignatures = attestationsAndSigners.attestations.length === 0;
491
- if (ignoreSignatures) {
492
- const { committee } = await this.epochCache.getCommittee(block.header.globalVariables.slotNumber.toBigInt());
493
- if (!committee) {
494
- this.log.warn(`No committee found for slot ${block.header.globalVariables.slotNumber.toBigInt()}`);
495
- throw new Error(`No committee found for slot ${block.header.globalVariables.slotNumber.toBigInt()}`);
496
- }
497
- attestationsAndSigners.attestations = committee.map(committeeMember =>
498
- CommitteeAttestation.fromAddress(committeeMember),
499
- );
500
- }
501
-
502
- const blobFields = block.getCheckpointBlobFields();
503
- const blobs = getBlobsPerL1Block(blobFields);
820
+ // Anchor the simulation timestamp to the checkpoint's own slot start time
821
+ // rather than the current L1 block timestamp, which may overshoot into the next slot if the build ran late.
822
+ const ts = checkpoint.header.timestamp;
823
+ const blobFields = checkpoint.toBlobFields();
824
+ const blobs = await getBlobsPerL1Block(blobFields);
504
825
  const blobInput = getPrefixedEthBlobCommitments(blobs);
505
826
 
506
827
  const args = [
507
828
  {
508
- header: block.getCheckpointHeader().toViem(),
509
- archive: toHex(block.archive.root.toBuffer()),
510
- stateReference: block.header.state.toViem(),
829
+ header: checkpoint.header.toViem(),
830
+ archive: toHex(checkpoint.archive.root.toBuffer()),
511
831
  oracleInput: {
512
- feeAssetPriceModifier: 0n,
832
+ feeAssetPriceModifier: checkpoint.feeAssetPriceModifier,
513
833
  },
514
834
  },
515
835
  attestationsAndSigners.getPackedAttestations(),
@@ -523,7 +843,7 @@ export class SequencerPublisher {
523
843
  }
524
844
 
525
845
  private async enqueueCastSignalHelper(
526
- slotNumber: bigint,
846
+ slotNumber: SlotNumber,
527
847
  timestamp: bigint,
528
848
  signalType: GovernanceSignalAction,
529
849
  payload: EthAddress,
@@ -545,10 +865,45 @@ export class SequencerPublisher {
545
865
  const round = await base.computeRound(slotNumber);
546
866
  const roundInfo = await base.getRoundInfo(this.rollupContract.address, round);
547
867
 
868
+ if (roundInfo.quorumReached) {
869
+ return false;
870
+ }
871
+
548
872
  if (roundInfo.lastSignalSlot >= slotNumber) {
549
873
  return false;
550
874
  }
551
875
 
876
+ if (await this.isPayloadEmpty(payload)) {
877
+ this.log.warn(`Skipping vote cast for payload with empty code`);
878
+ return false;
879
+ }
880
+
881
+ // Check if payload was already submitted to governance
882
+ const cacheKey = payload.toString();
883
+ if (!this.payloadProposedCache.has(cacheKey)) {
884
+ try {
885
+ const l1StartBlock = await this.rollupContract.getL1StartBlock();
886
+ const proposed = await retry(
887
+ () => base.hasPayloadBeenProposed(payload.toString(), l1StartBlock),
888
+ 'Check if payload was proposed',
889
+ makeBackoff([0, 1, 2]),
890
+ this.log,
891
+ true,
892
+ );
893
+ if (proposed) {
894
+ this.payloadProposedCache.add(cacheKey);
895
+ }
896
+ } catch (err) {
897
+ this.log.warn(`Failed to check if payload ${payload} was proposed after retries, skipping signal`, err);
898
+ return false;
899
+ }
900
+ }
901
+
902
+ if (this.payloadProposedCache.has(cacheKey)) {
903
+ this.log.info(`Payload ${payload} was already proposed to governance, stopping signals`);
904
+ return false;
905
+ }
906
+
552
907
  const cachedLastVote = this.lastActions[signalType];
553
908
  this.lastActions[signalType] = slotNumber;
554
909
  const action = signalType;
@@ -567,11 +922,26 @@ export class SequencerPublisher {
567
922
  lastValidL2Slot: slotNumber,
568
923
  });
569
924
 
925
+ const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
926
+
570
927
  try {
571
- await this.l1TxUtils.simulate(request, { time: timestamp }, [], ErrorsAbi);
928
+ await this.l1TxUtils.simulate(request, { time: timestamp }, [], mergeAbis([request.abi ?? [], ErrorsAbi]));
572
929
  this.log.debug(`Simulation for ${action} at slot ${slotNumber} succeeded`, { request });
573
930
  } catch (err) {
574
- this.log.error(`Failed simulation for ${action} at slot ${slotNumber} (enqueuing the action anyway)`, err);
931
+ const viemError = formatViemError(err);
932
+ this.log.error(`Failed simulation for ${action} at slot ${slotNumber} (enqueuing the action anyway)`, viemError);
933
+ this.backupFailedTx({
934
+ id: keccak256(request.data!),
935
+ failureType: 'simulation',
936
+ request: { to: request.to!, data: request.data!, value: request.value?.toString() },
937
+ l1BlockNumber: l1BlockNumber.toString(),
938
+ error: { message: viemError.message, name: viemError.name },
939
+ context: {
940
+ actions: [action],
941
+ slot: slotNumber,
942
+ sender: this.getSenderAddress().toString(),
943
+ },
944
+ });
575
945
  // Yes, we enqueue the request anyway, in case there was a bug with the simulation itself
576
946
  }
577
947
 
@@ -591,14 +961,14 @@ export class SequencerPublisher {
591
961
  const logData = { ...result, slotNumber, round, payload: payload.toString() };
592
962
  if (!success) {
593
963
  this.log.error(
594
- `Signaling in [${action}] for ${payload} at slot ${slotNumber} in round ${round} failed`,
964
+ `Signaling in ${action} for ${payload} at slot ${slotNumber} in round ${round} failed`,
595
965
  logData,
596
966
  );
597
967
  this.lastActions[signalType] = cachedLastVote;
598
968
  return false;
599
969
  } else {
600
970
  this.log.info(
601
- `Signaling in [${action}] for ${payload} at slot ${slotNumber} in round ${round} succeeded`,
971
+ `Signaling in ${action} for ${payload} at slot ${slotNumber} in round ${round} succeeded`,
602
972
  logData,
603
973
  );
604
974
  return true;
@@ -608,6 +978,17 @@ export class SequencerPublisher {
608
978
  return true;
609
979
  }
610
980
 
981
+ private async isPayloadEmpty(payload: EthAddress): Promise<boolean> {
982
+ const key = payload.toString();
983
+ const cached = this.isPayloadEmptyCache.get(key);
984
+ if (cached) {
985
+ return cached;
986
+ }
987
+ const isEmpty = !(await this.l1TxUtils.getCode(payload));
988
+ this.isPayloadEmptyCache.set(key, isEmpty);
989
+ return isEmpty;
990
+ }
991
+
611
992
  /**
612
993
  * Enqueues a governance castSignal transaction to cast a signal for a given slot number.
613
994
  * @param slotNumber - The slot number to cast a signal for.
@@ -616,7 +997,7 @@ export class SequencerPublisher {
616
997
  */
617
998
  public enqueueGovernanceCastSignal(
618
999
  governancePayload: EthAddress,
619
- slotNumber: bigint,
1000
+ slotNumber: SlotNumber,
620
1001
  timestamp: bigint,
621
1002
  signerAddress: EthAddress,
622
1003
  signer: (msg: TypedDataDefinition) => Promise<`0x${string}`>,
@@ -635,7 +1016,7 @@ export class SequencerPublisher {
635
1016
  /** Enqueues all slashing actions as returned by the slasher client. */
636
1017
  public async enqueueSlashingActions(
637
1018
  actions: ProposerSlashAction[],
638
- slotNumber: bigint,
1019
+ slotNumber: SlotNumber,
639
1020
  timestamp: bigint,
640
1021
  signerAddress: EthAddress,
641
1022
  signer: (msg: TypedDataDefinition) => Promise<`0x${string}`>,
@@ -755,31 +1136,25 @@ export class SequencerPublisher {
755
1136
  return true;
756
1137
  }
757
1138
 
758
- /**
759
- * Proposes a L2 block on L1.
760
- *
761
- * @param block - L2 block to propose.
762
- * @returns True if the tx has been enqueued, throws otherwise. See #9315
763
- */
764
- public async enqueueProposeL2Block(
765
- block: L2Block,
1139
+ /** Simulates and enqueues a proposal for a checkpoint on L1 */
1140
+ public async enqueueProposeCheckpoint(
1141
+ checkpoint: Checkpoint,
766
1142
  attestationsAndSigners: CommitteeAttestationsAndSigners,
767
1143
  attestationsAndSignersSignature: Signature,
768
- opts: { txTimeoutAt?: Date; forcePendingBlockNumber?: number } = {},
769
- ): Promise<boolean> {
770
- const checkpointHeader = block.getCheckpointHeader();
1144
+ opts: { txTimeoutAt?: Date; forcePendingCheckpointNumber?: CheckpointNumber } = {},
1145
+ ): Promise<void> {
1146
+ const checkpointHeader = checkpoint.header;
771
1147
 
772
- const blobFields = block.getCheckpointBlobFields();
773
- const blobs = getBlobsPerL1Block(blobFields);
1148
+ const blobFields = checkpoint.toBlobFields();
1149
+ const blobs = await getBlobsPerL1Block(blobFields);
774
1150
 
775
- const proposeTxArgs = {
1151
+ const proposeTxArgs: L1ProcessArgs = {
776
1152
  header: checkpointHeader,
777
- archive: block.archive.root.toBuffer(),
778
- stateReference: block.header.state,
779
- body: block.body.toBuffer(),
1153
+ archive: checkpoint.archive.root.toBuffer(),
780
1154
  blobs,
781
1155
  attestationsAndSigners,
782
1156
  attestationsAndSignersSignature,
1157
+ feeAssetPriceModifier: checkpoint.feeAssetPriceModifier,
783
1158
  };
784
1159
 
785
1160
  let ts: bigint;
@@ -790,22 +1165,29 @@ export class SequencerPublisher {
790
1165
  // By simulation issue, I mean the fact that the block.timestamp is equal to the last block, not the next, which
791
1166
  // make time consistency checks break.
792
1167
  // TODO(palla): Check whether we're validating twice, once here and once within addProposeTx, since we call simulateProposeTx in both places.
793
- ts = await this.validateBlockForSubmission(block, attestationsAndSigners, attestationsAndSignersSignature, opts);
1168
+ ts = await this.validateCheckpointForSubmission(
1169
+ checkpoint,
1170
+ attestationsAndSigners,
1171
+ attestationsAndSignersSignature,
1172
+ opts,
1173
+ );
794
1174
  } catch (err: any) {
795
- this.log.error(`Block validation failed. ${err instanceof Error ? err.message : 'No error message'}`, err, {
796
- ...block.getStats(),
797
- slotNumber: block.header.globalVariables.slotNumber.toBigInt(),
798
- forcePendingBlockNumber: opts.forcePendingBlockNumber,
1175
+ this.log.error(`Checkpoint validation failed. ${err instanceof Error ? err.message : 'No error message'}`, err, {
1176
+ ...checkpoint.getStats(),
1177
+ slotNumber: checkpoint.header.slotNumber,
1178
+ forcePendingCheckpointNumber: opts.forcePendingCheckpointNumber,
799
1179
  });
800
1180
  throw err;
801
1181
  }
802
1182
 
803
- this.log.verbose(`Enqueuing block propose transaction`, { ...block.toBlockInfo(), ...opts });
804
- await this.addProposeTx(block, proposeTxArgs, opts, ts);
805
- return true;
1183
+ this.log.verbose(`Enqueuing checkpoint propose transaction`, { ...checkpoint.toCheckpointInfo(), ...opts });
1184
+ await this.addProposeTx(checkpoint, proposeTxArgs, opts, ts);
806
1185
  }
807
1186
 
808
- public enqueueInvalidateBlock(request: InvalidateBlockRequest | undefined, opts: { txTimeoutAt?: Date } = {}) {
1187
+ public enqueueInvalidateCheckpoint(
1188
+ request: InvalidateCheckpointRequest | undefined,
1189
+ opts: { txTimeoutAt?: Date } = {},
1190
+ ) {
809
1191
  if (!request) {
810
1192
  return;
811
1193
  }
@@ -813,24 +1195,24 @@ export class SequencerPublisher {
813
1195
  // We issued the simulation against the rollup contract, so we need to account for the overhead of the multicall3
814
1196
  const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil((Number(request.gasUsed) * 64) / 63)));
815
1197
 
816
- const { gasUsed, blockNumber } = request;
817
- const logData = { gasUsed, blockNumber, gasLimit, opts };
818
- this.log.verbose(`Enqueuing invalidate block request`, logData);
1198
+ const { gasUsed, checkpointNumber } = request;
1199
+ const logData = { gasUsed, checkpointNumber, gasLimit, opts };
1200
+ this.log.verbose(`Enqueuing invalidate checkpoint request`, logData);
819
1201
  this.addRequest({
820
1202
  action: `invalidate-by-${request.reason}`,
821
1203
  request: request.request,
822
1204
  gasConfig: { gasLimit, txTimeoutAt: opts.txTimeoutAt },
823
- lastValidL2Slot: this.getCurrentL2Slot() + 2n,
1205
+ lastValidL2Slot: SlotNumber(this.getCurrentL2Slot() + 2),
824
1206
  checkSuccess: (_req, result) => {
825
1207
  const success =
826
1208
  result &&
827
1209
  result.receipt &&
828
1210
  result.receipt.status === 'success' &&
829
- tryExtractEvent(result.receipt.logs, this.rollupContract.address, RollupAbi, 'BlockInvalidated');
1211
+ tryExtractEvent(result.receipt.logs, this.rollupContract.address, RollupAbi, 'CheckpointInvalidated');
830
1212
  if (!success) {
831
- this.log.warn(`Invalidate block ${request.blockNumber} failed`, { ...result, ...logData });
1213
+ this.log.warn(`Invalidate checkpoint ${request.checkpointNumber} failed`, { ...result, ...logData });
832
1214
  } else {
833
- this.log.info(`Invalidate block ${request.blockNumber} succeeded`, { ...result, ...logData });
1215
+ this.log.info(`Invalidate checkpoint ${request.checkpointNumber} succeeded`, { ...result, ...logData });
834
1216
  }
835
1217
  return !!success;
836
1218
  },
@@ -841,7 +1223,7 @@ export class SequencerPublisher {
841
1223
  action: Action,
842
1224
  request: L1TxRequest,
843
1225
  checkSuccess: (receipt: TransactionReceipt) => boolean | undefined,
844
- slotNumber: bigint,
1226
+ slotNumber: SlotNumber,
845
1227
  timestamp: bigint,
846
1228
  ) {
847
1229
  const logData = { slotNumber, timestamp, gasLimit: undefined as bigint | undefined };
@@ -855,13 +1237,30 @@ export class SequencerPublisher {
855
1237
 
856
1238
  this.log.debug(`Simulating ${action} for slot ${slotNumber}`, logData);
857
1239
 
1240
+ const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
1241
+
858
1242
  let gasUsed: bigint;
1243
+ const simulateAbi = mergeAbis([request.abi ?? [], ErrorsAbi]);
859
1244
  try {
860
- ({ gasUsed } = await this.l1TxUtils.simulate(request, { time: timestamp }, [], ErrorsAbi)); // TODO(palla/slash): Check the timestamp logic
1245
+ ({ gasUsed } = await this.l1TxUtils.simulate(request, { time: timestamp }, [], simulateAbi)); // TODO(palla/slash): Check the timestamp logic
861
1246
  this.log.verbose(`Simulation for ${action} succeeded`, { ...logData, request, gasUsed });
862
1247
  } catch (err) {
863
- const viemError = formatViemError(err);
1248
+ const viemError = formatViemError(err, simulateAbi);
864
1249
  this.log.error(`Simulation for ${action} at ${slotNumber} failed`, viemError, logData);
1250
+
1251
+ this.backupFailedTx({
1252
+ id: keccak256(request.data!),
1253
+ failureType: 'simulation',
1254
+ request: { to: request.to!, data: request.data!, value: request.value?.toString() },
1255
+ l1BlockNumber: l1BlockNumber.toString(),
1256
+ error: { message: viemError.message, name: viemError.name },
1257
+ context: {
1258
+ actions: [action],
1259
+ slot: slotNumber,
1260
+ sender: this.getSenderAddress().toString(),
1261
+ },
1262
+ });
1263
+
865
1264
  return false;
866
1265
  }
867
1266
 
@@ -869,10 +1268,14 @@ export class SequencerPublisher {
869
1268
  const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil((Number(gasUsed) * 64) / 63)));
870
1269
  logData.gasLimit = gasLimit;
871
1270
 
1271
+ // Store the ABI used for simulation on the request so Multicall3.forward can decode errors
1272
+ // when the tx is sent and a revert is diagnosed via simulation.
1273
+ const requestWithAbi = { ...request, abi: simulateAbi };
1274
+
872
1275
  this.log.debug(`Enqueuing ${action}`, logData);
873
1276
  this.addRequest({
874
1277
  action,
875
- request,
1278
+ request: requestWithAbi,
876
1279
  gasConfig: { gasLimit },
877
1280
  lastValidL2Slot: slotNumber,
878
1281
  checkSuccess: (_req, result) => {
@@ -909,44 +1312,70 @@ export class SequencerPublisher {
909
1312
  private async prepareProposeTx(
910
1313
  encodedData: L1ProcessArgs,
911
1314
  timestamp: bigint,
912
- options: { forcePendingBlockNumber?: number },
1315
+ options: { forcePendingCheckpointNumber?: CheckpointNumber },
913
1316
  ) {
914
1317
  const kzg = Blob.getViemKzgInstance();
915
1318
  const blobInput = getPrefixedEthBlobCommitments(encodedData.blobs);
916
1319
  this.log.debug('Validating blob input', { blobInput });
917
- const blobEvaluationGas = await this.l1TxUtils
918
- .estimateGas(
919
- this.getSenderAddress().toString(),
920
- {
921
- to: this.rollupContract.address,
922
- data: encodeFunctionData({
1320
+
1321
+ // Get blob evaluation gas
1322
+ let blobEvaluationGas: bigint;
1323
+ if (this.config.fishermanMode) {
1324
+ // In fisherman mode, we can't estimate blob gas because estimateGas doesn't support state overrides
1325
+ // Use a fixed estimate.
1326
+ blobEvaluationGas = BigInt(encodedData.blobs.length) * 21_000n;
1327
+ this.log.debug(`Using fixed blob evaluation gas estimate in fisherman mode: ${blobEvaluationGas}`);
1328
+ } else {
1329
+ // Normal mode - use estimateGas with blob inputs
1330
+ blobEvaluationGas = await this.l1TxUtils
1331
+ .estimateGas(
1332
+ this.getSenderAddress().toString(),
1333
+ {
1334
+ to: this.rollupContract.address,
1335
+ data: encodeFunctionData({
1336
+ abi: RollupAbi,
1337
+ functionName: 'validateBlobs',
1338
+ args: [blobInput],
1339
+ }),
1340
+ },
1341
+ {},
1342
+ {
1343
+ blobs: encodedData.blobs.map(b => b.data),
1344
+ kzg,
1345
+ },
1346
+ )
1347
+ .catch(async err => {
1348
+ const viemError = formatViemError(err);
1349
+ this.log.error(`Failed to validate blobs`, viemError.message, { metaMessages: viemError.metaMessages });
1350
+ const validateBlobsData = encodeFunctionData({
923
1351
  abi: RollupAbi,
924
1352
  functionName: 'validateBlobs',
925
1353
  args: [blobInput],
926
- }),
927
- },
928
- {},
929
- {
930
- blobs: encodedData.blobs.map(b => b.data),
931
- kzg,
932
- },
933
- )
934
- .catch(err => {
935
- const { message, metaMessages } = formatViemError(err);
936
- this.log.error(`Failed to validate blobs`, message, { metaMessages });
937
- throw new Error('Failed to validate blobs');
938
- });
939
-
1354
+ });
1355
+ const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
1356
+ this.backupFailedTx({
1357
+ id: keccak256(validateBlobsData),
1358
+ failureType: 'simulation',
1359
+ request: { to: this.rollupContract.address as Hex, data: validateBlobsData },
1360
+ blobData: encodedData.blobs.map(b => toHex(b.data)) as Hex[],
1361
+ l1BlockNumber: l1BlockNumber.toString(),
1362
+ error: { message: viemError.message, name: viemError.name },
1363
+ context: {
1364
+ actions: ['validate-blobs'],
1365
+ sender: this.getSenderAddress().toString(),
1366
+ },
1367
+ });
1368
+ throw new Error('Failed to validate blobs');
1369
+ });
1370
+ }
940
1371
  const signers = encodedData.attestationsAndSigners.getSigners().map(signer => signer.toString());
941
1372
 
942
1373
  const args = [
943
1374
  {
944
1375
  header: encodedData.header.toViem(),
945
1376
  archive: toHex(encodedData.archive),
946
- stateReference: encodedData.stateReference.toViem(),
947
1377
  oracleInput: {
948
- // We are currently not modifying these. See #9963
949
- feeAssetPriceModifier: 0n,
1378
+ feeAssetPriceModifier: encodedData.feeAssetPriceModifier,
950
1379
  },
951
1380
  },
952
1381
  encodedData.attestationsAndSigners.getPackedAttestations(),
@@ -971,9 +1400,8 @@ export class SequencerPublisher {
971
1400
  {
972
1401
  readonly header: ViemHeader;
973
1402
  readonly archive: `0x${string}`;
974
- readonly stateReference: ViemStateReference;
975
1403
  readonly oracleInput: {
976
- readonly feeAssetPriceModifier: 0n;
1404
+ readonly feeAssetPriceModifier: bigint;
977
1405
  };
978
1406
  },
979
1407
  ViemCommitteeAttestations,
@@ -982,7 +1410,7 @@ export class SequencerPublisher {
982
1410
  `0x${string}`,
983
1411
  ],
984
1412
  timestamp: bigint,
985
- options: { forcePendingBlockNumber?: number },
1413
+ options: { forcePendingCheckpointNumber?: CheckpointNumber },
986
1414
  ) {
987
1415
  const rollupData = encodeFunctionData({
988
1416
  abi: RollupAbi,
@@ -990,44 +1418,78 @@ export class SequencerPublisher {
990
1418
  args,
991
1419
  });
992
1420
 
993
- // override the pending block number if requested
994
- const forcePendingBlockNumberStateDiff = (
995
- options.forcePendingBlockNumber !== undefined
996
- ? await this.rollupContract.makePendingBlockNumberOverride(options.forcePendingBlockNumber)
1421
+ // override the pending checkpoint number if requested
1422
+ const forcePendingCheckpointNumberStateDiff = (
1423
+ options.forcePendingCheckpointNumber !== undefined
1424
+ ? await this.rollupContract.makePendingCheckpointNumberOverride(options.forcePendingCheckpointNumber)
997
1425
  : []
998
1426
  ).flatMap(override => override.stateDiff ?? []);
999
1427
 
1428
+ const stateOverrides: StateOverride = [
1429
+ {
1430
+ address: this.rollupContract.address,
1431
+ // @note we override checkBlob to false since blobs are not part simulate()
1432
+ stateDiff: [
1433
+ { slot: toPaddedHex(RollupContract.checkBlobStorageSlot, true), value: toPaddedHex(0n, true) },
1434
+ ...forcePendingCheckpointNumberStateDiff,
1435
+ ],
1436
+ },
1437
+ ];
1438
+ // In fisherman mode, simulate as the proposer but with sufficient balance
1439
+ if (this.proposerAddressForSimulation) {
1440
+ stateOverrides.push({
1441
+ address: this.proposerAddressForSimulation.toString(),
1442
+ balance: 10n * WEI_CONST * WEI_CONST, // 10 ETH
1443
+ });
1444
+ }
1445
+
1446
+ const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
1447
+
1000
1448
  const simulationResult = await this.l1TxUtils
1001
1449
  .simulate(
1002
1450
  {
1003
1451
  to: this.rollupContract.address,
1004
1452
  data: rollupData,
1005
- gas: SequencerPublisher.PROPOSE_GAS_GUESS,
1453
+ gas: MAX_L1_TX_LIMIT,
1454
+ ...(this.proposerAddressForSimulation && { from: this.proposerAddressForSimulation.toString() }),
1006
1455
  },
1007
1456
  {
1008
1457
  // @note we add 1n to the timestamp because geth implementation doesn't like simulation timestamp to be equal to the current block timestamp
1009
1458
  time: timestamp + 1n,
1010
1459
  // @note reth should have a 30m gas limit per block but throws errors that this tx is beyond limit so we increase here
1011
- gasLimit: SequencerPublisher.PROPOSE_GAS_GUESS * 2n,
1460
+ gasLimit: MAX_L1_TX_LIMIT * 2n,
1012
1461
  },
1013
- [
1014
- {
1015
- address: this.rollupContract.address,
1016
- // @note we override checkBlob to false since blobs are not part simulate()
1017
- stateDiff: [
1018
- { slot: toPaddedHex(RollupContract.checkBlobStorageSlot, true), value: toPaddedHex(0n, true) },
1019
- ...forcePendingBlockNumberStateDiff,
1020
- ],
1021
- },
1022
- ],
1462
+ stateOverrides,
1023
1463
  RollupAbi,
1024
1464
  {
1025
1465
  // @note fallback gas estimate to use if the node doesn't support simulation API
1026
- fallbackGasEstimate: SequencerPublisher.PROPOSE_GAS_GUESS,
1466
+ fallbackGasEstimate: MAX_L1_TX_LIMIT,
1027
1467
  },
1028
1468
  )
1029
1469
  .catch(err => {
1030
- this.log.error(`Failed to simulate propose tx`, err);
1470
+ // In fisherman mode, we expect ValidatorSelection__MissingProposerSignature since fisherman doesn't have proposer signature
1471
+ const viemError = formatViemError(err);
1472
+ if (this.config.fishermanMode && viemError.message?.includes('ValidatorSelection__MissingProposerSignature')) {
1473
+ this.log.debug(`Ignoring expected ValidatorSelection__MissingProposerSignature error in fisherman mode`);
1474
+ // Return a minimal simulation result with the fallback gas estimate
1475
+ return {
1476
+ gasUsed: MAX_L1_TX_LIMIT,
1477
+ logs: [],
1478
+ };
1479
+ }
1480
+ this.log.error(`Failed to simulate propose tx`, viemError);
1481
+ this.backupFailedTx({
1482
+ id: keccak256(rollupData),
1483
+ failureType: 'simulation',
1484
+ request: { to: this.rollupContract.address, data: rollupData },
1485
+ l1BlockNumber: l1BlockNumber.toString(),
1486
+ error: { message: viemError.message, name: viemError.name },
1487
+ context: {
1488
+ actions: ['propose'],
1489
+ slot: Number(args[0].header.slotNumber),
1490
+ sender: this.getSenderAddress().toString(),
1491
+ },
1492
+ });
1031
1493
  throw err;
1032
1494
  });
1033
1495
 
@@ -1035,11 +1497,12 @@ export class SequencerPublisher {
1035
1497
  }
1036
1498
 
1037
1499
  private async addProposeTx(
1038
- block: L2Block,
1500
+ checkpoint: Checkpoint,
1039
1501
  encodedData: L1ProcessArgs,
1040
- opts: { txTimeoutAt?: Date; forcePendingBlockNumber?: number } = {},
1502
+ opts: { txTimeoutAt?: Date; forcePendingCheckpointNumber?: CheckpointNumber } = {},
1041
1503
  timestamp: bigint,
1042
1504
  ): Promise<void> {
1505
+ const slot = checkpoint.header.slotNumber;
1043
1506
  const timer = new Timer();
1044
1507
  const kzg = Blob.getViemKzgInstance();
1045
1508
  const { rollupData, simulationResult, blobEvaluationGas } = await this.prepareProposeTx(
@@ -1054,11 +1517,13 @@ export class SequencerPublisher {
1054
1517
  SequencerPublisher.MULTICALL_OVERHEAD_GAS_GUESS, // We issue the simulation against the rollup contract, so we need to account for the overhead of the multicall3
1055
1518
  );
1056
1519
 
1057
- // Send the blobs to the blob sink preemptively. This helps in tests where the sequencer mistakingly thinks that the propose
1058
- // tx fails but it does get mined. We make sure that the blobs are sent to the blob sink regardless of the tx outcome.
1059
- void this.blobSinkClient.sendBlobsToBlobSink(encodedData.blobs).catch(_err => {
1060
- this.log.error('Failed to send blobs to blob sink');
1061
- });
1520
+ // Send the blobs to the blob client preemptively. This helps in tests where the sequencer mistakingly thinks that the propose
1521
+ // tx fails but it does get mined. We make sure that the blobs are sent to the blob client regardless of the tx outcome.
1522
+ void Promise.resolve().then(() =>
1523
+ this.blobClient.sendBlobsToFilestore(encodedData.blobs).catch(_err => {
1524
+ this.log.error('Failed to send blobs to blob client');
1525
+ }),
1526
+ );
1062
1527
 
1063
1528
  return this.addRequest({
1064
1529
  action: 'propose',
@@ -1066,7 +1531,7 @@ export class SequencerPublisher {
1066
1531
  to: this.rollupContract.address,
1067
1532
  data: rollupData,
1068
1533
  },
1069
- lastValidL2Slot: block.header.globalVariables.slotNumber.toBigInt(),
1534
+ lastValidL2Slot: checkpoint.header.slotNumber,
1070
1535
  gasConfig: { ...opts, gasLimit },
1071
1536
  blobConfig: {
1072
1537
  blobs: encodedData.blobs.map(b => b.data),
@@ -1080,12 +1545,13 @@ export class SequencerPublisher {
1080
1545
  const success =
1081
1546
  receipt &&
1082
1547
  receipt.status === 'success' &&
1083
- tryExtractEvent(receipt.logs, this.rollupContract.address, RollupAbi, 'L2BlockProposed');
1548
+ tryExtractEvent(receipt.logs, this.rollupContract.address, RollupAbi, 'CheckpointProposed');
1549
+
1084
1550
  if (success) {
1085
1551
  const endBlock = receipt.blockNumber;
1086
1552
  const inclusionBlocks = Number(endBlock - startBlock);
1087
1553
  const { calldataGas, calldataSize, sender } = stats!;
1088
- const publishStats: L1PublishBlockStats = {
1554
+ const publishStats: L1PublishCheckpointStats = {
1089
1555
  gasPrice: receipt.effectiveGasPrice,
1090
1556
  gasUsed: receipt.gasUsed,
1091
1557
  blobGasUsed: receipt.blobGasUsed ?? 0n,
@@ -1094,23 +1560,26 @@ export class SequencerPublisher {
1094
1560
  calldataGas,
1095
1561
  calldataSize,
1096
1562
  sender,
1097
- ...block.getStats(),
1563
+ ...checkpoint.getStats(),
1098
1564
  eventName: 'rollup-published-to-l1',
1099
1565
  blobCount: encodedData.blobs.length,
1100
1566
  inclusionBlocks,
1101
1567
  };
1102
- this.log.info(`Published L2 block to L1 rollup contract`, { ...stats, ...block.getStats(), ...receipt });
1568
+ this.log.info(`Published checkpoint ${checkpoint.number} at slot ${slot} to rollup contract`, {
1569
+ ...stats,
1570
+ ...checkpoint.getStats(),
1571
+ ...pick(receipt, 'transactionHash', 'blockHash'),
1572
+ });
1103
1573
  this.metrics.recordProcessBlockTx(timer.ms(), publishStats);
1104
1574
 
1105
1575
  return true;
1106
1576
  } else {
1107
1577
  this.metrics.recordFailedTx('process');
1108
- this.log.error(`Rollup process tx failed: ${errorMsg ?? 'no error message'}`, undefined, {
1109
- ...block.getStats(),
1110
- receipt,
1111
- txHash: receipt.transactionHash,
1112
- slotNumber: block.header.globalVariables.slotNumber.toBigInt(),
1113
- });
1578
+ this.log.error(
1579
+ `Publishing checkpoint at slot ${slot} failed with ${errorMsg ?? 'no error message'}`,
1580
+ undefined,
1581
+ { ...checkpoint.getStats(), ...receipt },
1582
+ );
1114
1583
  return false;
1115
1584
  }
1116
1585
  },