@aztec/sequencer-client 0.0.1-commit.c2eed6949 → 0.0.1-commit.c52d6e7

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 (122) hide show
  1. package/README.md +281 -21
  2. package/dest/client/sequencer-client.d.ts +20 -5
  3. package/dest/client/sequencer-client.d.ts.map +1 -1
  4. package/dest/client/sequencer-client.js +26 -22
  5. package/dest/config.d.ts +12 -4
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +61 -26
  8. package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
  9. package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
  10. package/dest/global_variable_builder/fee_predictor.js +138 -0
  11. package/dest/global_variable_builder/fee_provider.d.ts +21 -0
  12. package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
  13. package/dest/global_variable_builder/fee_provider.js +80 -0
  14. package/dest/global_variable_builder/global_builder.d.ts +6 -25
  15. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  16. package/dest/global_variable_builder/global_builder.js +7 -65
  17. package/dest/global_variable_builder/index.d.ts +3 -1
  18. package/dest/global_variable_builder/index.d.ts.map +1 -1
  19. package/dest/global_variable_builder/index.js +2 -0
  20. package/dest/publisher/config.d.ts +7 -3
  21. package/dest/publisher/config.d.ts.map +1 -1
  22. package/dest/publisher/config.js +13 -3
  23. package/dest/publisher/l1_to_l2_messaging.d.ts +21 -0
  24. package/dest/publisher/l1_to_l2_messaging.d.ts.map +1 -0
  25. package/dest/publisher/l1_to_l2_messaging.js +70 -0
  26. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +50 -11
  27. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -1
  28. package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +68 -1
  29. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +2 -2
  30. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -1
  31. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +4 -2
  32. package/dest/publisher/l1_tx_failed_store/index.d.ts +2 -2
  33. package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -1
  34. package/dest/publisher/l1_tx_failed_store/index.js +1 -0
  35. package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
  36. package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
  37. package/dest/publisher/sequencer-bundle-simulator.js +198 -0
  38. package/dest/publisher/sequencer-publisher-factory.d.ts +1 -3
  39. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  40. package/dest/publisher/sequencer-publisher-factory.js +0 -1
  41. package/dest/publisher/sequencer-publisher.d.ts +101 -69
  42. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  43. package/dest/publisher/sequencer-publisher.js +635 -538
  44. package/dest/publisher/write_json.d.ts +11 -0
  45. package/dest/publisher/write_json.d.ts.map +1 -0
  46. package/dest/publisher/write_json.js +57 -0
  47. package/dest/sequencer/automine/automine_factory.d.ts +56 -0
  48. package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
  49. package/dest/sequencer/automine/automine_factory.js +85 -0
  50. package/dest/sequencer/automine/automine_sequencer.d.ts +189 -0
  51. package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
  52. package/dest/sequencer/automine/automine_sequencer.js +696 -0
  53. package/dest/sequencer/automine/index.d.ts +3 -0
  54. package/dest/sequencer/automine/index.d.ts.map +1 -0
  55. package/dest/sequencer/automine/index.js +2 -0
  56. package/dest/sequencer/checkpoint_proposal_job.d.ts +71 -21
  57. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  58. package/dest/sequencer/checkpoint_proposal_job.js +733 -213
  59. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
  60. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
  61. package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
  62. package/dest/sequencer/checkpoint_voter.d.ts +1 -2
  63. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
  64. package/dest/sequencer/checkpoint_voter.js +2 -5
  65. package/dest/sequencer/events.d.ts +61 -5
  66. package/dest/sequencer/events.d.ts.map +1 -1
  67. package/dest/sequencer/metrics.d.ts +9 -10
  68. package/dest/sequencer/metrics.d.ts.map +1 -1
  69. package/dest/sequencer/metrics.js +34 -20
  70. package/dest/sequencer/missing_committee.d.ts +72 -0
  71. package/dest/sequencer/missing_committee.d.ts.map +1 -0
  72. package/dest/sequencer/missing_committee.js +139 -0
  73. package/dest/sequencer/requests_tracker.d.ts +22 -0
  74. package/dest/sequencer/requests_tracker.d.ts.map +1 -0
  75. package/dest/sequencer/requests_tracker.js +33 -0
  76. package/dest/sequencer/sequencer.d.ts +158 -35
  77. package/dest/sequencer/sequencer.d.ts.map +1 -1
  78. package/dest/sequencer/sequencer.js +556 -162
  79. package/dest/sequencer/types.d.ts +2 -2
  80. package/dest/sequencer/types.d.ts.map +1 -1
  81. package/dest/test/index.d.ts +3 -3
  82. package/dest/test/index.d.ts.map +1 -1
  83. package/dest/test/utils.d.ts +15 -1
  84. package/dest/test/utils.d.ts.map +1 -1
  85. package/dest/test/utils.js +25 -7
  86. package/package.json +29 -28
  87. package/src/client/sequencer-client.ts +37 -27
  88. package/src/config.ts +71 -26
  89. package/src/global_variable_builder/README.md +44 -0
  90. package/src/global_variable_builder/fee_predictor.ts +182 -0
  91. package/src/global_variable_builder/fee_provider.ts +97 -0
  92. package/src/global_variable_builder/global_builder.ts +12 -80
  93. package/src/global_variable_builder/index.ts +2 -0
  94. package/src/publisher/config.ts +30 -7
  95. package/src/publisher/l1_to_l2_messaging.ts +85 -0
  96. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +117 -8
  97. package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +4 -3
  98. package/src/publisher/l1_tx_failed_store/index.ts +1 -1
  99. package/src/publisher/sequencer-bundle-simulator.ts +254 -0
  100. package/src/publisher/sequencer-publisher-factory.ts +0 -3
  101. package/src/publisher/sequencer-publisher.ts +735 -612
  102. package/src/publisher/write_json.ts +78 -0
  103. package/src/sequencer/README.md +162 -450
  104. package/src/sequencer/automine/README.md +60 -0
  105. package/src/sequencer/automine/automine_factory.ts +152 -0
  106. package/src/sequencer/automine/automine_sequencer.ts +800 -0
  107. package/src/sequencer/automine/index.ts +6 -0
  108. package/src/sequencer/checkpoint_proposal_job.ts +849 -242
  109. package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
  110. package/src/sequencer/checkpoint_voter.ts +1 -12
  111. package/src/sequencer/events.ts +66 -5
  112. package/src/sequencer/metrics.ts +43 -24
  113. package/src/sequencer/missing_committee.ts +192 -0
  114. package/src/sequencer/requests_tracker.ts +43 -0
  115. package/src/sequencer/sequencer.ts +639 -180
  116. package/src/sequencer/types.ts +1 -1
  117. package/src/test/index.ts +2 -2
  118. package/src/test/utils.ts +61 -10
  119. package/dest/sequencer/timetable.d.ts +0 -88
  120. package/dest/sequencer/timetable.d.ts.map +0 -1
  121. package/dest/sequencer/timetable.js +0 -222
  122. package/src/sequencer/timetable.ts +0 -283
@@ -3,66 +3,104 @@ import { Blob, getBlobsPerL1Block, getPrefixedEthBlobCommitments } from '@aztec/
3
3
  import type { EpochCache } from '@aztec/epoch-cache';
4
4
  import type { L1ContractsConfig } from '@aztec/ethereum/config';
5
5
  import {
6
- type EmpireSlashingProposerContract,
7
6
  FeeAssetPriceOracle,
8
7
  type GovernanceProposerContract,
9
- type IEmpireBase,
10
8
  MULTI_CALL_3_ADDRESS,
11
9
  Multicall3,
12
- RollupContract,
13
- type TallySlashingProposerContract,
14
- type ViemCommitteeAttestations,
15
- type ViemHeader,
10
+ MulticallForwarderRevertedError,
11
+ type PayloadProposalStatus,
12
+ type RollupContract,
13
+ type SimulationOverridesPlan,
14
+ type SlashingProposerContract,
15
+ buildSimulationOverridesStateOverride,
16
16
  } from '@aztec/ethereum/contracts';
17
- import { type L1FeeAnalysisResult, L1FeeAnalyzer } from '@aztec/ethereum/l1-fee-analysis';
17
+ import { type L1FeeAnalysisResult, L1FeeAnalyzer, captureWindowBlockFees } from '@aztec/ethereum/l1-fee-analysis';
18
18
  import {
19
19
  type L1BlobInputs,
20
20
  type L1TxConfig,
21
21
  type L1TxRequest,
22
+ L1TxTimeoutError,
22
23
  type L1TxUtils,
23
24
  MAX_L1_TX_LIMIT,
24
25
  type TransactionStats,
25
26
  WEI_CONST,
26
27
  } from '@aztec/ethereum/l1-tx-utils';
27
- import { FormattedViemError, formatViemError, mergeAbis, tryExtractEvent } from '@aztec/ethereum/utils';
28
- import { sumBigint } from '@aztec/foundation/bigint';
29
- import { toHex as toPaddedHex } from '@aztec/foundation/bigint-buffer';
28
+ import {
29
+ FormattedViemError,
30
+ formatViemError,
31
+ mergeAbis,
32
+ tryDecodeRevertReason,
33
+ tryExtractEvent,
34
+ } from '@aztec/ethereum/utils';
30
35
  import { CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
31
36
  import { trimmedBytesLength } from '@aztec/foundation/buffer';
32
37
  import { pick } from '@aztec/foundation/collection';
33
38
  import type { Fr } from '@aztec/foundation/curves/bn254';
34
39
  import { TimeoutError } from '@aztec/foundation/error';
35
40
  import { EthAddress } from '@aztec/foundation/eth-address';
36
- import { Signature, type ViemSignature } from '@aztec/foundation/eth-signature';
41
+ import { Signature } from '@aztec/foundation/eth-signature';
37
42
  import { type Logger, createLogger } from '@aztec/foundation/log';
38
- import { makeBackoff, retry } from '@aztec/foundation/retry';
43
+ import { InterruptibleSleep } from '@aztec/foundation/sleep';
39
44
  import { bufferToHex } from '@aztec/foundation/string';
40
- import { DateProvider, Timer } from '@aztec/foundation/timer';
41
- import { EmpireBaseAbi, ErrorsAbi, RollupAbi } from '@aztec/l1-artifacts';
45
+ import { type DateProvider, Timer } from '@aztec/foundation/timer';
46
+ import { EmpireBaseAbi, ErrorsAbi, RollupAbi, SlashingProposerAbi } from '@aztec/l1-artifacts';
42
47
  import { type ProposerSlashAction, encodeSlashConsensusVotes } from '@aztec/slasher';
43
48
  import { CommitteeAttestationsAndSigners, type ValidateCheckpointResult } from '@aztec/stdlib/block';
44
49
  import type { Checkpoint } from '@aztec/stdlib/checkpoint';
45
- import { getNextL1SlotTimestamp } from '@aztec/stdlib/epoch-helpers';
46
- import { SlashFactoryContract } from '@aztec/stdlib/l1-contracts';
50
+ import type { SequencerConfig } from '@aztec/stdlib/config';
51
+ import {
52
+ getLastL1SlotTimestampForL2Slot,
53
+ getNextL1SlotTimestamp,
54
+ getTimestampForSlot,
55
+ } from '@aztec/stdlib/epoch-helpers';
47
56
  import type { CheckpointHeader } from '@aztec/stdlib/rollup';
48
57
  import type { L1PublishCheckpointStats } from '@aztec/stdlib/stats';
49
58
  import { type TelemetryClient, type Tracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
50
59
 
51
60
  import {
61
+ type Abi,
52
62
  type Hex,
53
- type StateOverride,
54
63
  type TransactionReceipt,
55
64
  type TypedDataDefinition,
56
65
  encodeFunctionData,
57
66
  keccak256,
58
- multicall3Abi,
59
67
  toHex,
60
68
  } from 'viem';
61
69
 
62
70
  import type { SequencerPublisherConfig } from './config.js';
63
71
  import { type FailedL1Tx, type L1TxFailedStore, createL1TxFailedStore } from './l1_tx_failed_store/index.js';
72
+ import { type DroppedRequest, SequencerBundleSimulator } from './sequencer-bundle-simulator.js';
64
73
  import { SequencerPublisherMetrics } from './sequencer-publisher-metrics.js';
65
74
 
75
+ /**
76
+ * Returns true if the receipt indicates a successful send AND the expected event was emitted
77
+ * by the target contract. Both pieces are required: an aggregate3 entry that reverted will
78
+ * have receipt.status === 'success' but no event log.
79
+ */
80
+ function extractEventSuccess(
81
+ receipt: TransactionReceipt | undefined,
82
+ opts: { address: string; abi: Abi; eventName: string },
83
+ ): boolean {
84
+ if (!receipt || receipt.status !== 'success') {
85
+ return false;
86
+ }
87
+ return !!tryExtractEvent(receipt.logs, opts.address.toString() as Hex, opts.abi, opts.eventName);
88
+ }
89
+
90
+ /** Result of a sendRequests call, returned by both sendRequests() and sendRequestsAt(). */
91
+ export type SendRequestsResult = {
92
+ /** The L1 transaction receipt from the bundled multicall. */
93
+ result: { receipt: TransactionReceipt };
94
+ /** Actions that expired (past their deadline) before the request was sent. */
95
+ expiredActions: Action[];
96
+ /** Actions that were included in the sent L1 transaction. */
97
+ sentActions: Action[];
98
+ /** Actions whose L1 simulation succeeded (subset of sentActions). */
99
+ successfulActions: Action[];
100
+ /** Actions whose L1 simulation failed (subset of sentActions). */
101
+ failedActions: Action[];
102
+ };
103
+
66
104
  /** Arguments to the process method of the rollup contract */
67
105
  type L1ProcessArgs = {
68
106
  /** The L2 block header. */
@@ -82,18 +120,16 @@ type L1ProcessArgs = {
82
120
  export const Actions = [
83
121
  'invalidate-by-invalid-attestation',
84
122
  'invalidate-by-insufficient-attestations',
123
+ 'prune',
85
124
  'propose',
86
125
  'governance-signal',
87
- 'empire-slashing-signal',
88
- 'create-empire-payload',
89
- 'execute-empire-payload',
90
126
  'vote-offenses',
91
127
  'execute-slash',
92
128
  ] as const;
93
129
 
94
130
  export type Action = (typeof Actions)[number];
95
131
 
96
- type GovernanceSignalAction = Extract<Action, 'governance-signal' | 'empire-slashing-signal'>;
132
+ type GovernanceSignalAction = Extract<Action, 'governance-signal'>;
97
133
 
98
134
  // Sorting for actions such that invalidations go before proposals, and proposals go before votes
99
135
  export const compareActions = (a: Action, b: Action) => Actions.indexOf(a) - Actions.indexOf(b);
@@ -104,14 +140,22 @@ export type InvalidateCheckpointRequest = {
104
140
  gasUsed: bigint;
105
141
  checkpointNumber: CheckpointNumber;
106
142
  forcePendingCheckpointNumber: CheckpointNumber;
143
+ /** Archive at the rollback target checkpoint (checkpoint N-1). */
144
+ lastArchive: Fr;
145
+ };
146
+
147
+ type EnqueueProposeCheckpointOpts = {
148
+ txTimeoutAt?: Date;
107
149
  };
108
150
 
109
- interface RequestWithExpiry {
151
+ export interface RequestWithExpiry {
110
152
  action: Action;
111
153
  request: L1TxRequest;
112
154
  lastValidL2Slot: SlotNumber;
113
155
  gasConfig?: Pick<L1TxConfig, 'txTimeoutAt' | 'gasLimit'>;
114
156
  blobConfig?: L1BlobInputs;
157
+ /** Gas consumed by validateBlobs; stashed for the bundle simulate at send time. */
158
+ blobEvaluationGas?: bigint;
115
159
  checkSuccess: (
116
160
  request: L1TxRequest,
117
161
  result?: { receipt: TransactionReceipt; stats?: TransactionStats; errorMsg?: string },
@@ -121,26 +165,29 @@ interface RequestWithExpiry {
121
165
  export class SequencerPublisher {
122
166
  private interrupted = false;
123
167
  private metrics: SequencerPublisherMetrics;
168
+ private bundleSimulator: SequencerBundleSimulator;
124
169
  public epochCache: EpochCache;
125
170
  private failedTxStore?: Promise<L1TxFailedStore | undefined>;
126
171
 
127
- protected governanceLog = createLogger('sequencer:publisher:governance');
128
- protected slashingLog = createLogger('sequencer:publisher:slashing');
172
+ /**
173
+ * ABI used to decode raw revert payloads from dropped bundle entries when the original
174
+ * request did not carry an abi (e.g. the propose request). Merges every contract the
175
+ * publisher can route to so any of their custom errors decode against it.
176
+ */
177
+ private readonly revertDecoderAbi: Abi = mergeAbis([RollupAbi, SlashingProposerAbi, EmpireBaseAbi, ErrorsAbi]);
129
178
 
130
179
  protected lastActions: Partial<Record<Action, SlotNumber>> = {};
131
180
 
132
- private isPayloadEmptyCache: Map<string, boolean> = new Map<string, boolean>();
133
- private payloadProposedCache: Set<string> = new Set<string>();
134
-
135
181
  protected log: Logger;
136
182
  protected ethereumSlotDuration: bigint;
137
183
  protected aztecSlotDuration: bigint;
138
- private dateProvider: DateProvider;
184
+ private readonly previousL1BlockWaitTimeoutMs: number;
185
+ private readonly previousL1BlockWaitPollIntervalMs: number;
139
186
 
140
- private blobClient: BlobClientInterface;
187
+ /** Date provider for wall-clock time. */
188
+ private readonly dateProvider: DateProvider;
141
189
 
142
- /** Address to use for simulations in fisherman mode (actual proposer's address) */
143
- private proposerAddressForSimulation?: EthAddress;
190
+ private blobClient: BlobClientInterface;
144
191
 
145
192
  /** Optional callback to obtain a replacement publisher when the current one fails to send. */
146
193
  private getNextPublisher?: (excludeAddresses: EthAddress[]) => Promise<L1TxUtils | undefined>;
@@ -151,33 +198,35 @@ export class SequencerPublisher {
151
198
  /** Fee asset price oracle for computing price modifiers from Uniswap V4 */
152
199
  private feeAssetPriceOracle: FeeAssetPriceOracle;
153
200
 
154
- // A CALL to a cold address is 2700 gas
155
- public static MULTICALL_OVERHEAD_GAS_GUESS = 5000n;
156
-
157
- // Gas report for VotingWithSigTest shows a max gas of 100k, but we've seen it cost 700k+ in testnet
158
- public static VOTE_GAS_GUESS: bigint = 800_000n;
201
+ /** Interruptible sleep used by sendRequestsAt to wait until a target timestamp. */
202
+ private readonly interruptibleSleep = new InterruptibleSleep();
159
203
 
160
204
  public l1TxUtils: L1TxUtils;
161
205
  public rollupContract: RollupContract;
162
206
  public govProposerContract: GovernanceProposerContract;
163
- public slashingProposerContract: EmpireSlashingProposerContract | TallySlashingProposerContract | undefined;
164
- public slashFactoryContract: SlashFactoryContract;
207
+ public slashingProposerContract: SlashingProposerContract | undefined;
165
208
 
166
209
  public readonly tracer: Tracer;
167
210
 
168
211
  protected requests: RequestWithExpiry[] = [];
169
212
 
170
213
  constructor(
171
- private config: Pick<SequencerPublisherConfig, 'fishermanMode' | 'l1TxFailedStore'> &
214
+ private config: Pick<
215
+ SequencerPublisherConfig,
216
+ | 'fishermanMode'
217
+ | 'l1TxFailedStore'
218
+ | 'sequencerPublisherPreviousL1BlockWaitTimeoutMs'
219
+ | 'sequencerPublisherPreviousL1BlockWaitPollIntervalMs'
220
+ > &
221
+ Pick<SequencerConfig, 'governanceProposerForcePayloadVote'> &
172
222
  Pick<L1ContractsConfig, 'ethereumSlotDuration' | 'aztecSlotDuration'> & { l1ChainId: number },
173
223
  deps: {
174
224
  telemetry?: TelemetryClient;
175
225
  blobClient: BlobClientInterface;
176
226
  l1TxUtils: L1TxUtils;
177
227
  rollupContract: RollupContract;
178
- slashingProposerContract: EmpireSlashingProposerContract | TallySlashingProposerContract | undefined;
228
+ slashingProposerContract: SlashingProposerContract | undefined;
179
229
  governanceProposerContract: GovernanceProposerContract;
180
- slashFactoryContract: SlashFactoryContract;
181
230
  epochCache: EpochCache;
182
231
  dateProvider: DateProvider;
183
232
  metrics: SequencerPublisherMetrics;
@@ -189,11 +238,14 @@ export class SequencerPublisher {
189
238
  this.log = deps.log ?? createLogger('sequencer:publisher');
190
239
  this.ethereumSlotDuration = BigInt(config.ethereumSlotDuration);
191
240
  this.aztecSlotDuration = BigInt(config.aztecSlotDuration);
241
+ this.previousL1BlockWaitTimeoutMs = config.sequencerPublisherPreviousL1BlockWaitTimeoutMs;
242
+ this.previousL1BlockWaitPollIntervalMs = config.sequencerPublisherPreviousL1BlockWaitPollIntervalMs;
192
243
  this.dateProvider = deps.dateProvider;
193
244
  this.epochCache = deps.epochCache;
194
245
  this.lastActions = deps.lastActions;
195
246
 
196
247
  this.blobClient = deps.blobClient;
248
+ this.dateProvider = deps.dateProvider;
197
249
 
198
250
  const telemetry = deps.telemetry ?? getTelemetryClient();
199
251
  this.metrics = deps.metrics ?? new SequencerPublisherMetrics(telemetry, 'SequencerPublisher');
@@ -211,14 +263,12 @@ export class SequencerPublisher {
211
263
  const newSlashingProposer = await this.rollupContract.getSlashingProposer();
212
264
  this.slashingProposerContract = newSlashingProposer;
213
265
  });
214
- this.slashFactoryContract = deps.slashFactoryContract;
215
-
216
266
  // Initialize L1 fee analyzer for fisherman mode
217
267
  if (config.fishermanMode) {
218
268
  this.l1FeeAnalyzer = new L1FeeAnalyzer(
219
269
  this.l1TxUtils.client,
220
270
  deps.dateProvider,
221
- createLogger('sequencer:publisher:fee-analyzer'),
271
+ this.log.createChild('fee-analyzer'),
222
272
  );
223
273
  }
224
274
 
@@ -226,33 +276,112 @@ export class SequencerPublisher {
226
276
  this.feeAssetPriceOracle = new FeeAssetPriceOracle(
227
277
  this.l1TxUtils.client,
228
278
  this.rollupContract,
229
- createLogger('sequencer:publisher:price-oracle'),
279
+ this.log.createChild('price-oracle'),
230
280
  );
231
281
 
232
282
  // Initialize failed L1 tx store (optional, for test networks)
233
283
  this.failedTxStore = createL1TxFailedStore(config.l1TxFailedStore, this.log);
284
+
285
+ this.bundleSimulator = new SequencerBundleSimulator({
286
+ getL1TxUtils: () => this.l1TxUtils,
287
+ rollupContract: this.rollupContract,
288
+ epochCache: this.epochCache,
289
+ log: this.log.createChild('bundle-simulator'),
290
+ });
234
291
  }
235
292
 
236
293
  /**
237
- * Backs up a failed L1 transaction to the configured store for debugging.
238
- * Does nothing if no store is configured.
294
+ * Logs the gas-pricing data of a failed L1 transaction at warn so underpricing is diagnosable
295
+ * from logs even with no failed-tx store configured — and backs the record up to the store when
296
+ * one is. When captureFeeSummary is true, also records the fee data of the already-mined L1
297
+ * blocks in the target slot's inclusion window.
239
298
  */
240
- private backupFailedTx(failedTx: Omit<FailedL1Tx, 'timestamp'>): void {
241
- if (!this.failedTxStore) {
242
- return;
243
- }
244
-
299
+ private backupFailedTx(
300
+ failedTx: Omit<FailedL1Tx, 'timestamp'>,
301
+ opts?: { captureFeeSummary?: boolean; targetSlot?: SlotNumber; sharedFeeSummary?: FailedL1Tx['gasInfo'] },
302
+ ): void {
245
303
  const tx: FailedL1Tx = {
246
304
  ...failedTx,
247
305
  timestamp: Date.now(),
248
306
  };
249
307
 
250
308
  // Fire and forget - don't block on backup
251
- void this.failedTxStore
252
- .then(store => store?.saveFailedTx(tx))
253
- .catch(err => {
309
+ void (async () => {
310
+ try {
311
+ // Prefer a pre-captured summary (shared across a batch of failures in the same slot) so we
312
+ // don't re-read the fee window per record. A capture error must not lose the record itself.
313
+ const feeSummary =
314
+ opts?.sharedFeeSummary ??
315
+ (opts?.captureFeeSummary
316
+ ? await this.captureFeeEnvironment(opts.targetSlot).catch(() => undefined)
317
+ : undefined);
318
+ if (feeSummary) {
319
+ tx.gasInfo = { ...tx.gasInfo, ...feeSummary };
320
+ }
321
+ if (tx.gasInfo) {
322
+ this.log.warn(`Gas pricing data for failed L1 tx (${tx.failureType})`, {
323
+ failureType: tx.failureType,
324
+ actions: tx.context.actions,
325
+ slot: tx.context.slot,
326
+ ...tx.gasInfo,
327
+ ...tx.timing,
328
+ });
329
+ }
330
+ const store = await this.failedTxStore;
331
+ if (store) {
332
+ await store.saveFailedTx(tx);
333
+ }
334
+ } catch (err) {
254
335
  this.log.warn(`Failed to backup failed L1 tx to store`, err);
255
- });
336
+ }
337
+ })();
338
+ }
339
+
340
+ /**
341
+ * Captures per-block fee data for the L1 blocks in the target slot's inclusion window (the blocks the
342
+ * tx could have landed in) for underpricing diagnostics. Reads only already-mined blocks, so it never
343
+ * waits on the chain. Safe to call off the critical path: the underlying capture never throws, and this
344
+ * returns undefined when there is no target slot or the window is not yet mined (e.g. an early send
345
+ * failure), in which case the record simply carries no window data.
346
+ */
347
+ private async captureFeeEnvironment(targetL2Slot: SlotNumber | undefined): Promise<FailedL1Tx['gasInfo']> {
348
+ if (targetL2Slot === undefined) {
349
+ return undefined;
350
+ }
351
+ const l1Constants = this.epochCache.getL1Constants();
352
+ // The inclusion window is [start of slot N, start of slot N+1): all L1 blocks that can include a tx
353
+ // for this L2 slot. getTimestampForSlot returns seconds, matching block.timestamp.
354
+ const windowStartS = getTimestampForSlot(targetL2Slot, l1Constants);
355
+ const windowEndS = getTimestampForSlot(SlotNumber(Number(targetL2Slot) + 1), l1Constants);
356
+ const windowBlocks = await captureWindowBlockFees(this.l1TxUtils.client, windowStartS, windowEndS);
357
+ if (windowBlocks.length === 0) {
358
+ return undefined;
359
+ }
360
+ return { windowBlocks };
361
+ }
362
+
363
+ /** Computes timing info relative to the L2 slot deadline. */
364
+ private computeTimingInfo(targetL2Slot: SlotNumber | undefined): FailedL1Tx['timing'] {
365
+ if (targetL2Slot === undefined) {
366
+ return undefined;
367
+ }
368
+ const l1Constants = this.epochCache.getL1Constants();
369
+ const slotDeadlineS = getTimestampForSlot(SlotNumber(Number(targetL2Slot) + 1), l1Constants);
370
+ const slotDeadlineMs = Number(slotDeadlineS) * 1000;
371
+ return {
372
+ targetL2Slot: Number(targetL2Slot),
373
+ slotDeadlineTimestampS: slotDeadlineS,
374
+ msUntilSlotDeadline: slotDeadlineMs - this.dateProvider.now(),
375
+ };
376
+ }
377
+
378
+ /**
379
+ * Builds an id for a synthetic failure record (send-error/timeout) that has no on-chain tx hash.
380
+ * Includes the failure time so each attempt — including retries of the same slot — is stored as its
381
+ * own record rather than overwriting the previous one.
382
+ */
383
+ private failureRecordId(actions: string[], targetSlot: SlotNumber | undefined): Hex {
384
+ return keccak256(toHex(`${actions.join(',')}:${targetSlot ?? ''}:${Date.now()}`));
256
385
  }
257
386
 
258
387
  public getRollupContract(): RollupContract {
@@ -261,10 +390,14 @@ export class SequencerPublisher {
261
390
 
262
391
  /**
263
392
  * Gets the fee asset price modifier from the oracle.
264
- * Returns 0n if the oracle query fails.
393
+ *
394
+ * @param predictedParentEthPerFeeAssetE12 - Optional predicted parent eth-per-fee-asset (E12).
395
+ * Pipelined proposers should pass the value from the predicted parent fee header so the
396
+ * modifier matches the parent L1 will use when applying it.
397
+ * @returns The fee asset price modifier in basis points, or 0n if the oracle query fails.
265
398
  */
266
- public getFeeAssetPriceModifier(): Promise<bigint> {
267
- return this.feeAssetPriceOracle.computePriceModifier();
399
+ public getFeeAssetPriceModifier(predictedParentEthPerFeeAssetE12?: bigint): Promise<bigint> {
400
+ return this.feeAssetPriceOracle.computePriceModifier(predictedParentEthPerFeeAssetE12);
268
401
  }
269
402
 
270
403
  public getSenderAddress() {
@@ -278,14 +411,6 @@ export class SequencerPublisher {
278
411
  return this.l1FeeAnalyzer;
279
412
  }
280
413
 
281
- /**
282
- * Sets the proposer address to use for simulations in fisherman mode.
283
- * @param proposerAddress - The actual proposer's address to use for balance lookups in simulations
284
- */
285
- public setProposerAddressForSimulation(proposerAddress: EthAddress | undefined) {
286
- this.proposerAddressForSimulation = proposerAddress;
287
- }
288
-
289
414
  public addRequest(request: RequestWithExpiry) {
290
415
  this.requests.push(request);
291
416
  }
@@ -363,22 +488,26 @@ export class SequencerPublisher {
363
488
 
364
489
  /**
365
490
  * Sends all requests that are still valid.
491
+ * @param targetSlot - The target L2 slot for this send. When provided (the production path, via
492
+ * sendRequestsAt), it is threaded into bundleSimulate so the block.timestamp override matches
493
+ * the slot the propose is built for. When omitted, falls back to getCurrentL2Slot() for the
494
+ * AutomineSequencer, which publishes synchronously within the current slot.
366
495
  * @returns one of:
367
496
  * - A receipt and stats if the tx succeeded
368
497
  * - a receipt and errorMsg if it failed on L1
369
498
  * - undefined if no valid requests are found OR the tx failed to send.
370
499
  */
371
500
  @trackSpan('SequencerPublisher.sendRequests')
372
- public async sendRequests() {
501
+ public async sendRequests(targetSlot?: SlotNumber): Promise<SendRequestsResult | undefined> {
373
502
  const requestsToProcess = [...this.requests];
374
503
  this.requests = [];
504
+
375
505
  if (this.interrupted || requestsToProcess.length === 0) {
376
506
  return undefined;
377
507
  }
378
- const currentL2Slot = this.getCurrentL2Slot();
508
+ const currentL2Slot = targetSlot ?? this.getCurrentL2Slot();
379
509
  this.log.debug(`Sending requests on L2 slot ${currentL2Slot}`);
380
510
  const validRequests = requestsToProcess.filter(request => request.lastValidL2Slot >= currentL2Slot);
381
- const validActions = validRequests.map(x => x.action);
382
511
  const expiredActions = requestsToProcess
383
512
  .filter(request => request.lastValidL2Slot < currentL2Slot)
384
513
  .map(x => x.action);
@@ -401,73 +530,101 @@ export class SequencerPublisher {
401
530
  return undefined;
402
531
  }
403
532
 
404
- // @note - we can only have one blob config per bundle
405
- // find requests with gas and blob configs
406
- // See https://github.com/AztecProtocol/aztec-packages/issues/11513
533
+ // Collect earliest txTimeoutAt across all requests.
407
534
  const gasConfigs = validRequests.filter(request => request.gasConfig).map(request => request.gasConfig);
408
- const blobConfigs = validRequests.filter(request => request.blobConfig).map(request => request.blobConfig);
409
-
410
- if (blobConfigs.length > 1) {
411
- throw new Error('Multiple blob configs found');
412
- }
413
-
414
- const blobConfig = blobConfigs[0];
415
-
416
- // Merge gasConfigs. Yields the sum of gasLimits, and the earliest txTimeoutAt, or undefined if no gasConfig sets them.
417
- const gasLimits = gasConfigs.map(g => g?.gasLimit).filter((g): g is bigint => g !== undefined);
418
- let gasLimit = gasLimits.length > 0 ? sumBigint(gasLimits) : undefined; // sum
419
- // Cap at L1 block gas limit so the node accepts the tx ("gas limit too high" otherwise).
420
- const maxGas = MAX_L1_TX_LIMIT;
421
- if (gasLimit !== undefined && gasLimit > maxGas) {
422
- this.log.debug('Capping bundled tx gas limit to L1 max', {
423
- requested: gasLimit,
424
- capped: maxGas,
425
- });
426
- gasLimit = maxGas;
427
- }
428
535
  const txTimeoutAts = gasConfigs.map(g => g?.txTimeoutAt).filter((g): g is Date => g !== undefined);
429
- const txTimeoutAt = txTimeoutAts.length > 0 ? new Date(Math.min(...txTimeoutAts.map(g => g.getTime()))) : undefined; // earliest
430
- const txConfig: RequestWithExpiry['gasConfig'] = { gasLimit, txTimeoutAt };
536
+ const txTimeoutAt = txTimeoutAts.length > 0 ? new Date(Math.min(...txTimeoutAts.map(g => g.getTime()))) : undefined;
431
537
 
432
538
  // Sort the requests so that proposals always go first
433
539
  // This ensures the committee gets precomputed correctly
434
540
  validRequests.sort((a, b) => compareActions(a.action, b.action));
435
541
 
436
542
  try {
437
- // Capture context for failed tx backup before sending
438
- const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
439
- const multicallData = encodeFunctionData({
440
- abi: multicall3Abi,
441
- functionName: 'aggregate3',
442
- args: [
443
- validRequests.map(r => ({
444
- target: r.request.to!,
445
- callData: r.request.data!,
446
- allowFailure: true,
447
- })),
448
- ],
449
- });
450
- const blobDataHex = blobConfig?.blobs?.map(b => toHex(b)) as Hex[] | undefined;
543
+ // Bundle-level eth_simulateV1: filters out entries that revert and derives the gasLimit.
544
+ const bundleResult = await this.bundleSimulator.simulate(validRequests, currentL2Slot);
545
+
546
+ if (bundleResult.kind === 'aborted') {
547
+ this.logDroppedInSim(bundleResult.droppedRequests);
548
+ void this.backupDroppedInSim(bundleResult.droppedRequests, currentL2Slot).catch(err =>
549
+ this.log.error(`Failed to backup requests dropped in simulation`, err),
550
+ );
551
+ return undefined;
552
+ }
451
553
 
452
- const txContext = { multicallData, blobData: blobDataHex, l1BlockNumber };
554
+ const { requests, droppedRequests, gasLimit } =
555
+ bundleResult.kind === 'fallback'
556
+ ? {
557
+ requests: bundleResult.requests,
558
+ droppedRequests: bundleResult.droppedRequests,
559
+ gasLimit: MAX_L1_TX_LIMIT,
560
+ }
561
+ : bundleResult;
562
+
563
+ this.logDroppedInSim(droppedRequests);
564
+
565
+ // Compute blobConfig from survivors (not original validRequests) so that if the propose
566
+ // entry was dropped by bundleSimulate we don't attach a blob-typed config to a non-blob tx.
567
+ const [blobConfig] = requests.filter(r => r.blobConfig).map(r => r.blobConfig);
568
+ const txConfig: RequestWithExpiry['gasConfig'] = { gasLimit, txTimeoutAt };
453
569
 
454
570
  this.log.debug('Forwarding transactions', {
455
- validRequests: validRequests.map(request => request.action),
571
+ requests: requests.map(request => request.action),
456
572
  txConfig,
457
573
  });
458
- const result = await this.forwardWithPublisherRotation(validRequests, txConfig, blobConfig);
574
+ const result = await this.forwardWithPublisherRotation(requests, txConfig, blobConfig, currentL2Slot);
459
575
  if (result === undefined) {
460
576
  return undefined;
461
577
  }
462
- const { successfulActions = [], failedActions = [] } = this.callbackBundledTransactions(
463
- validRequests,
578
+ const { successfulActions = [], failedActions = [] } = this.callbackBundledTransactions(requests, result);
579
+ const allFailedActions = [...failedActions, ...droppedRequests.map(d => d.request.action)];
580
+ return {
464
581
  result,
465
- txContext,
466
- );
467
- return { result, expiredActions, sentActions: validActions, successfulActions, failedActions };
582
+ expiredActions,
583
+ sentActions: requests.map(x => x.action),
584
+ successfulActions,
585
+ failedActions: allFailedActions,
586
+ };
468
587
  } catch (err) {
469
588
  const viemError = formatViemError(err);
470
589
  this.log.error(`Failed to publish bundled transactions`, viemError);
590
+ if (err instanceof TimeoutError) {
591
+ const timeoutState = err instanceof L1TxTimeoutError ? err.txState : undefined;
592
+ void (async () => {
593
+ // The RPC is likely degraded right after a timeout, so back up without the block number
594
+ // rather than leaking an unhandled rejection.
595
+ const l1BlockNumber = await this.l1TxUtils.getBlockNumber().catch(() => 0n);
596
+ this.backupFailedTx(
597
+ {
598
+ id: this.failureRecordId(
599
+ validRequests.map(r => r.action),
600
+ currentL2Slot,
601
+ ),
602
+ failureType: 'timeout',
603
+ request: { to: MULTI_CALL_3_ADDRESS as Hex, data: '0x' as Hex },
604
+ l1BlockNumber,
605
+ error: { message: viemError.message, name: 'TimeoutError' },
606
+ context: {
607
+ actions: validRequests.map(r => r.action),
608
+ requests: validRequests
609
+ .filter(r => r.request.to !== null)
610
+ .map(r => ({ action: r.action, to: r.request.to! as Hex, data: r.request.data! })),
611
+ sender: this.getSenderAddress().toString(),
612
+ slot: Number(currentL2Slot),
613
+ },
614
+ timing: this.computeTimingInfo(currentL2Slot),
615
+ gasInfo: timeoutState
616
+ ? {
617
+ sentGasPriceLadder: timeoutState.gasPriceHistory,
618
+ attempts: timeoutState.attempts,
619
+ gasLimit: timeoutState.gasLimit,
620
+ nonce: timeoutState.nonce,
621
+ }
622
+ : undefined,
623
+ },
624
+ { captureFeeSummary: true, targetSlot: currentL2Slot },
625
+ );
626
+ })();
627
+ }
471
628
  return undefined;
472
629
  } finally {
473
630
  try {
@@ -481,6 +638,54 @@ export class SequencerPublisher {
481
638
  }
482
639
  }
483
640
 
641
+ /** Logs entries dropped by bundle simulation as warnings on the publisher's logger. */
642
+ private logDroppedInSim(dropped: DroppedRequest[]): void {
643
+ for (const drop of dropped) {
644
+ const revertReasonDecoded = drop.revertReason ?? tryDecodeRevertReason(drop.returnData, this.revertDecoderAbi);
645
+ this.log.warn('Bundle entry dropped: action reverted in sim', {
646
+ action: drop.request.action,
647
+ revertReason: revertReasonDecoded ?? drop.returnData,
648
+ revertReasonDecoded,
649
+ returnData: drop.returnData,
650
+ });
651
+ }
652
+ }
653
+
654
+ /** Backs up entries dropped by bundle simulation, one record per dropped action. */
655
+ private async backupDroppedInSim(dropped: DroppedRequest[], targetSlot?: SlotNumber): Promise<void> {
656
+ if (dropped.length === 0) {
657
+ return;
658
+ }
659
+ // Invoked as `void backupDroppedInSim(...)` on the publish path, so it must not throw.
660
+ try {
661
+ const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
662
+ // Every dropped entry failed in the same slot against the same L1 fee conditions, so capture
663
+ // the fee environment once and share it rather than re-reading the window per entry.
664
+ const sharedFeeSummary = await this.captureFeeEnvironment(targetSlot).catch(() => undefined);
665
+ const timing = this.computeTimingInfo(targetSlot);
666
+ for (const { request: req } of dropped) {
667
+ this.backupFailedTx(
668
+ {
669
+ id: keccak256(req.request.data!),
670
+ failureType: 'simulation',
671
+ request: { to: req.request.to! as Hex, data: req.request.data! },
672
+ l1BlockNumber,
673
+ error: { message: 'Bundle entry dropped: action reverted in sim' },
674
+ context: {
675
+ actions: [req.action],
676
+ sender: this.getSenderAddress().toString(),
677
+ slot: targetSlot !== undefined ? Number(targetSlot) : undefined,
678
+ },
679
+ timing,
680
+ },
681
+ { sharedFeeSummary },
682
+ );
683
+ }
684
+ } catch (err) {
685
+ this.log.warn(`Failed to back up dropped-in-sim entries`, err);
686
+ }
687
+ }
688
+
484
689
  /**
485
690
  * Forwards transactions via Multicall3, rotating to the next available publisher if a send
486
691
  * failure occurs (i.e. the tx never reached the chain).
@@ -490,20 +695,32 @@ export class SequencerPublisher {
490
695
  validRequests: RequestWithExpiry[],
491
696
  txConfig: RequestWithExpiry['gasConfig'],
492
697
  blobConfig: L1BlobInputs | undefined,
698
+ targetSlot?: SlotNumber,
493
699
  ) {
700
+ if (!txConfig?.gasLimit) {
701
+ throw new Error('gasLimit is required for bundled transactions');
702
+ }
703
+ const txConfigWithGasLimit = txConfig as L1TxConfig & { gasLimit: bigint };
704
+
494
705
  const triedAddresses: EthAddress[] = [];
495
706
  let currentPublisher = this.l1TxUtils;
496
707
 
497
708
  while (true) {
709
+ if (txConfig.txTimeoutAt && new Date() > txConfig.txTimeoutAt) {
710
+ this.log.warn(`Tx timeout (${txConfig.txTimeoutAt.toISOString()}) elapsed; stopping publisher rotation`, {
711
+ triedAddresses: triedAddresses.map(a => a.toString()),
712
+ });
713
+ return undefined;
714
+ }
498
715
  triedAddresses.push(currentPublisher.getSenderAddress());
716
+
499
717
  try {
500
718
  const result = await Multicall3.forward(
501
719
  validRequests.map(r => r.request),
502
720
  currentPublisher,
503
- txConfig,
721
+ txConfigWithGasLimit,
504
722
  blobConfig,
505
- this.rollupContract.address,
506
- this.log,
723
+ { gasLimitRequired: true },
507
724
  );
508
725
  this.l1TxUtils = currentPublisher;
509
726
  return result;
@@ -511,9 +728,17 @@ export class SequencerPublisher {
511
728
  if (err instanceof TimeoutError) {
512
729
  throw err;
513
730
  }
731
+ if (err instanceof MulticallForwarderRevertedError) {
732
+ this.log.error('Forwarder transaction reverted on-chain; not rotating publisher', err, {
733
+ transactionHash: err.receipt.transactionHash,
734
+ });
735
+ this.backupRevertFailure(validRequests, err, currentPublisher, targetSlot);
736
+ return undefined;
737
+ }
514
738
  const viemError = formatViemError(err);
515
739
  if (!this.getNextPublisher) {
516
740
  this.log.error('Failed to publish bundled transactions', viemError);
741
+ this.backupSendFailure(validRequests, viemError, currentPublisher, targetSlot);
517
742
  return undefined;
518
743
  }
519
744
  this.log.warn(
@@ -522,7 +747,12 @@ export class SequencerPublisher {
522
747
  );
523
748
  const nextPublisher = await this.getNextPublisher([...triedAddresses]);
524
749
  if (!nextPublisher) {
525
- this.log.error('All available publishers exhausted, failed to publish bundled transactions');
750
+ this.log.error(
751
+ `All available publishers exhausted (tried ${triedAddresses.length}), failed to publish bundled transactions`,
752
+ viemError,
753
+ { triedAddresses: triedAddresses.map(a => a.toString()) },
754
+ );
755
+ this.backupSendFailure(validRequests, viemError, currentPublisher, targetSlot);
526
756
  return undefined;
527
757
  }
528
758
  currentPublisher = nextPublisher;
@@ -530,74 +760,179 @@ export class SequencerPublisher {
530
760
  }
531
761
  }
532
762
 
533
- private callbackBundledTransactions(
763
+ /** Backs up an on-chain revert failure to the failed tx store. */
764
+ private backupRevertFailure(
534
765
  requests: RequestWithExpiry[],
535
- result: { receipt: TransactionReceipt; errorMsg?: string } | FormattedViemError | undefined,
536
- txContext: { multicallData: Hex; blobData?: Hex[]; l1BlockNumber: bigint },
537
- ) {
538
- const actionsListStr = requests.map(r => r.action).join(', ');
539
- if (result instanceof FormattedViemError) {
540
- this.log.error(`Failed to publish bundled transactions (${actionsListStr})`, result);
541
- this.backupFailedTx({
542
- id: keccak256(txContext.multicallData),
543
- failureType: 'send-error',
544
- request: { to: MULTI_CALL_3_ADDRESS, data: txContext.multicallData },
545
- blobData: txContext.blobData,
546
- l1BlockNumber: txContext.l1BlockNumber.toString(),
547
- error: { message: result.message, name: result.name },
766
+ err: MulticallForwarderRevertedError,
767
+ publisher: L1TxUtils,
768
+ targetSlot?: SlotNumber,
769
+ ): void {
770
+ this.backupFailedTx(
771
+ {
772
+ id: err.receipt.transactionHash,
773
+ failureType: 'revert',
774
+ request: { to: MULTI_CALL_3_ADDRESS as Hex, data: '0x' as Hex },
775
+ l1BlockNumber: err.receipt.blockNumber,
776
+ receipt: {
777
+ transactionHash: err.receipt.transactionHash,
778
+ blockNumber: err.receipt.blockNumber,
779
+ gasUsed: err.receipt.gasUsed,
780
+ status: 'reverted',
781
+ },
782
+ error: { message: err.message, name: err.name },
548
783
  context: {
549
784
  actions: requests.map(r => r.action),
550
- requests: requests.map(r => ({ action: r.action, to: r.request.to! as Hex, data: r.request.data! })),
551
- sender: this.getSenderAddress().toString(),
785
+ requests: requests
786
+ .filter(r => r.request.to !== null)
787
+ .map(r => ({ action: r.action, to: r.request.to! as Hex, data: r.request.data! })),
788
+ sender: publisher.getSenderAddress().toString(),
789
+ slot: targetSlot !== undefined ? Number(targetSlot) : undefined,
552
790
  },
791
+ gasInfo: err.txState
792
+ ? {
793
+ sentGasPrice: err.txState.gasPrice,
794
+ gasLimit: err.txState.gasLimit,
795
+ nonce: err.txState.nonce,
796
+ }
797
+ : undefined,
798
+ timing: this.computeTimingInfo(targetSlot),
799
+ },
800
+ { captureFeeSummary: true, targetSlot },
801
+ );
802
+ }
803
+
804
+ /** Backs up a send failure (tx never reached chain) to the failed tx store. */
805
+ private backupSendFailure(
806
+ requests: RequestWithExpiry[],
807
+ error: FormattedViemError | Error,
808
+ publisher: L1TxUtils,
809
+ targetSlot?: SlotNumber,
810
+ ): void {
811
+ // If we can't get the block number, still back up without it.
812
+ void this.l1TxUtils
813
+ .getBlockNumber()
814
+ .catch(() => 0n)
815
+ .then(l1BlockNumber => {
816
+ this.backupFailedTx(
817
+ {
818
+ id: this.failureRecordId(
819
+ requests.map(r => r.action),
820
+ targetSlot,
821
+ ),
822
+ failureType: 'send-error',
823
+ request: { to: MULTI_CALL_3_ADDRESS as Hex, data: '0x' as Hex },
824
+ l1BlockNumber,
825
+ error: {
826
+ message: error.message,
827
+ name: 'name' in error ? error.name : undefined,
828
+ },
829
+ context: {
830
+ actions: requests.map(r => r.action),
831
+ requests: requests
832
+ .filter(r => r.request.to !== null)
833
+ .map(r => ({ action: r.action, to: r.request.to! as Hex, data: r.request.data! })),
834
+ sender: publisher.getSenderAddress().toString(),
835
+ slot: targetSlot !== undefined ? Number(targetSlot) : undefined,
836
+ },
837
+ timing: this.computeTimingInfo(targetSlot),
838
+ },
839
+ { captureFeeSummary: true, targetSlot },
840
+ );
553
841
  });
554
- return { failedActions: requests.map(r => r.action) };
555
- } else {
556
- this.log.verbose(`Published bundled transactions (${actionsListStr})`, {
557
- result,
558
- requests: requests.map(r => ({
559
- ...r,
560
- // Avoid logging large blob data
561
- blobConfig: r.blobConfig
562
- ? { ...r.blobConfig, blobs: r.blobConfig.blobs.map(b => ({ size: trimmedBytesLength(b) })) }
563
- : undefined,
564
- })),
565
- });
566
- const successfulActions: Action[] = [];
567
- const failedActions: Action[] = [];
568
- for (const request of requests) {
569
- if (request.checkSuccess(request.request, result)) {
570
- successfulActions.push(request.action);
571
- } else {
572
- failedActions.push(request.action);
842
+ }
843
+
844
+ /*
845
+ * Schedules sending all enqueued requests at (or after) the start of the given L2 slot.
846
+ */
847
+ public async sendRequestsAt(targetSlot: SlotNumber): Promise<SendRequestsResult | undefined> {
848
+ await this.waitForTargetSlot(targetSlot);
849
+ if (this.interrupted) {
850
+ return undefined;
851
+ }
852
+
853
+ return this.sendRequests(targetSlot);
854
+ }
855
+
856
+ /**
857
+ * Sleeps until one L1 slot before the L2 slot boundary, and then waits for that L1 block
858
+ * to be mined, so we don't risk being included in it. If that block never gets mined after
859
+ * a timeout, we assume it got skipped on L1, so we send the tx anyway.
860
+ */
861
+ private async waitForTargetSlot(targetSlot: SlotNumber): Promise<void> {
862
+ const l1Constants = this.epochCache.getL1Constants();
863
+ const nowInSeconds = this.dateProvider.nowInSeconds();
864
+ const startOfTargetSlotTs = getTimestampForSlot(targetSlot, l1Constants);
865
+ const previousL1BlockTs = startOfTargetSlotTs - this.ethereumSlotDuration;
866
+ const waitDeadlineTs = previousL1BlockTs + BigInt(this.previousL1BlockWaitTimeoutMs / 1000);
867
+ const logCtx = { targetSlot, startOfTargetSlotTs, nowInSeconds, previousL1BlockTs, waitDeadlineTs };
868
+
869
+ // Check if we are already past time
870
+ if (nowInSeconds >= startOfTargetSlotTs) {
871
+ this.log.verbose(`Target slot ${targetSlot} already started, sending requests immediately`, logCtx);
872
+ return;
873
+ }
874
+
875
+ // Otherwise we wait
876
+ this.log.debug(`Waiting for slot ${targetSlot} before sending requests`, logCtx);
877
+
878
+ // Wait until previous L1 block timestamp first
879
+ const sleepMs = (Number(previousL1BlockTs) - nowInSeconds) * 1000;
880
+ if (sleepMs > 0 && !this.interrupted) {
881
+ this.log.trace(`Sleeping ${sleepMs}ms before waiting for previous L1 block`, logCtx);
882
+ await this.interruptibleSleep.sleep(sleepMs);
883
+ }
884
+
885
+ // Then loop until we see the previous L1 block, so we know that we cannot be included in it.
886
+ // We time out after a while, once we are sure that that block is skipped in L1.
887
+ while (!this.interrupted) {
888
+ try {
889
+ const nowInSeconds = this.dateProvider.nowInSeconds();
890
+ logCtx.nowInSeconds = nowInSeconds;
891
+
892
+ if (nowInSeconds >= waitDeadlineTs) {
893
+ this.log.warn(`Timed out waiting for previous L1 block before sending requests, proceeding`, logCtx);
894
+ return;
895
+ }
896
+
897
+ const latestBlockTs = await this.l1TxUtils.getBlock().then(b => b.timestamp);
898
+ if (latestBlockTs >= previousL1BlockTs) {
899
+ this.log.debug(`Previous L1 block mined, proceeding to send requests`, { ...logCtx, latestBlockTs });
900
+ return;
573
901
  }
902
+ this.log.trace(`Previous L1 block not mined yet, continuing to wait`, { ...logCtx, latestBlockTs });
903
+ } catch (err) {
904
+ this.log.error(`Error while waiting for previous L1 block before sending requests; retrying`, err, logCtx);
905
+ } finally {
906
+ await this.interruptibleSleep.sleep(this.previousL1BlockWaitPollIntervalMs);
574
907
  }
575
- // Single backup for the whole reverted tx
576
- if (failedActions.length > 0 && result?.receipt?.status === 'reverted') {
577
- this.backupFailedTx({
578
- id: result.receipt.transactionHash,
579
- failureType: 'revert',
580
- request: { to: MULTI_CALL_3_ADDRESS, data: txContext.multicallData },
581
- blobData: txContext.blobData,
582
- l1BlockNumber: result.receipt.blockNumber.toString(),
583
- receipt: {
584
- transactionHash: result.receipt.transactionHash,
585
- blockNumber: result.receipt.blockNumber.toString(),
586
- gasUsed: (result.receipt.gasUsed ?? 0n).toString(),
587
- status: 'reverted',
588
- },
589
- error: { message: result.errorMsg ?? 'Transaction reverted' },
590
- context: {
591
- actions: failedActions,
592
- requests: requests
593
- .filter(r => failedActions.includes(r.action))
594
- .map(r => ({ action: r.action, to: r.request.to! as Hex, data: r.request.data! })),
595
- sender: this.getSenderAddress().toString(),
596
- },
597
- });
908
+ }
909
+ }
910
+
911
+ private callbackBundledTransactions(
912
+ requests: RequestWithExpiry[],
913
+ result: { receipt: TransactionReceipt; multicallData: Hex },
914
+ ) {
915
+ const actionsListStr = requests.map(r => r.action).join(', ');
916
+ this.log.verbose(`Published bundled transactions (${actionsListStr})`, {
917
+ result,
918
+ requests: requests.map(r => ({
919
+ ...r,
920
+ // Avoid logging large blob data
921
+ blobConfig: r.blobConfig
922
+ ? { ...r.blobConfig, blobs: r.blobConfig.blobs.map(b => ({ size: trimmedBytesLength(b) })) }
923
+ : undefined,
924
+ })),
925
+ });
926
+ const successfulActions: Action[] = [];
927
+ const failedActions: Action[] = [];
928
+ for (const request of requests) {
929
+ if (request.checkSuccess(request.request, result)) {
930
+ successfulActions.push(request.action);
931
+ } else {
932
+ failedActions.push(request.action);
598
933
  }
599
- return { successfulActions, failedActions };
600
934
  }
935
+ return { successfulActions, failedActions };
601
936
  }
602
937
 
603
938
  /**
@@ -605,25 +940,27 @@ export class SequencerPublisher {
605
940
  * @param tipArchive - The archive to check
606
941
  * @returns The slot and block number if it is possible to propose, undefined otherwise
607
942
  */
608
- public canProposeAt(
609
- tipArchive: Fr,
610
- msgSender: EthAddress,
611
- opts: { forcePendingCheckpointNumber?: CheckpointNumber; pipelined?: boolean } = {},
612
- ) {
943
+ public async canProposeAt(tipArchive: Fr, msgSender: EthAddress, simulationOverridesPlan?: SimulationOverridesPlan) {
613
944
  // TODO: #14291 - should loop through multiple keys to check if any of them can propose
614
- const ignoredErrors = ['SlotAlreadyInChain', 'InvalidProposer', 'InvalidArchive'];
945
+ // These errors are expected when we cannot actually propose right now — usually because our
946
+ // local view of the chain is ahead of L1 (proposed parent hasn't landed yet, or someone
947
+ // else has just landed the slot, or the archive override doesn't match). We log a warn and
948
+ // skip the proposal; we do NOT treat these as bugs.
949
+ const expectedErrors = ['SlotAlreadyInChain', 'InvalidProposer', 'InvalidArchive'];
615
950
 
616
- const pipelined = opts.pipelined ?? this.epochCache.isProposerPipeliningEnabled();
617
- const slotOffset = pipelined ? this.aztecSlotDuration : 0n;
951
+ const slotOffset = this.aztecSlotDuration;
618
952
  const nextL1SlotTs = this.getNextL1SlotTimestamp() + slotOffset;
619
953
 
620
954
  return this.rollupContract
621
- .canProposeAt(tipArchive.toBuffer(), msgSender.toString(), nextL1SlotTs, {
622
- forcePendingCheckpointNumber: opts.forcePendingCheckpointNumber,
623
- })
955
+ .canProposeAt(
956
+ tipArchive.toBuffer(),
957
+ msgSender.toString(),
958
+ nextL1SlotTs,
959
+ await buildSimulationOverridesStateOverride(this.rollupContract, simulationOverridesPlan),
960
+ )
624
961
  .catch(err => {
625
- if (err instanceof FormattedViemError && ignoredErrors.find(e => err.message.includes(e))) {
626
- this.log.warn(`Failed canProposeAtTime check with ${ignoredErrors.find(e => err.message.includes(e))}`, {
962
+ if (err instanceof FormattedViemError && expectedErrors.find(e => err.message.includes(e))) {
963
+ this.log.warn(`Failed canProposeAtTime check with ${expectedErrors.find(e => err.message.includes(e))}`, {
627
964
  error: err.message,
628
965
  });
629
966
  } else {
@@ -642,13 +979,13 @@ export class SequencerPublisher {
642
979
  @trackSpan('SequencerPublisher.validateBlockHeader')
643
980
  public async validateBlockHeader(
644
981
  header: CheckpointHeader,
645
- opts?: { forcePendingCheckpointNumber: CheckpointNumber | undefined },
982
+ simulationOverridesPlan?: SimulationOverridesPlan,
646
983
  ): Promise<void> {
647
984
  const flags = { ignoreDA: true, ignoreSignatures: true };
648
985
 
649
986
  const args = [
650
987
  header.toViem(),
651
- CommitteeAttestationsAndSigners.empty().getPackedAttestations(),
988
+ CommitteeAttestationsAndSigners.packAttestations([]),
652
989
  [], // no signers
653
990
  Signature.empty().toViemSignature(),
654
991
  `0x${'0'.repeat(64)}`, // 32 empty bytes
@@ -656,10 +993,9 @@ export class SequencerPublisher {
656
993
  flags,
657
994
  ] as const;
658
995
 
659
- const ts = this.getNextL1SlotTimestamp();
660
- const stateOverrides = await this.rollupContract.makePendingCheckpointNumberOverride(
661
- opts?.forcePendingCheckpointNumber,
662
- );
996
+ const l1Constants = this.epochCache.getL1Constants();
997
+ const ts = getLastL1SlotTimestampForL2Slot(header.slotNumber, l1Constants);
998
+ const stateOverrides = await buildSimulationOverridesStateOverride(this.rollupContract, simulationOverridesPlan);
663
999
  let balance = 0n;
664
1000
  if (this.config.fishermanMode) {
665
1001
  // In fisherman mode, we can't know where the proposer is publishing from
@@ -679,7 +1015,7 @@ export class SequencerPublisher {
679
1015
  data: encodeFunctionData({ abi: RollupAbi, functionName: 'validateHeaderWithAttestations', args }),
680
1016
  from: MULTI_CALL_3_ADDRESS,
681
1017
  },
682
- { time: ts + 1n },
1018
+ { time: ts },
683
1019
  stateOverrides,
684
1020
  );
685
1021
  this.log.debug(`Simulated validateHeader`);
@@ -732,6 +1068,7 @@ export class SequencerPublisher {
732
1068
  gasUsed,
733
1069
  checkpointNumber,
734
1070
  forcePendingCheckpointNumber: CheckpointNumber(checkpointNumber - 1),
1071
+ lastArchive: validationResult.checkpoint.lastArchive,
735
1072
  reason,
736
1073
  };
737
1074
  } catch (err) {
@@ -744,8 +1081,8 @@ export class SequencerPublisher {
744
1081
  `Simulation for invalidate checkpoint ${checkpointNumber} failed due to checkpoint not being in pending chain`,
745
1082
  { ...logData, request, error: viemError.message },
746
1083
  );
747
- const latestPendingCheckpointNumber = await this.rollupContract.getCheckpointNumber();
748
- if (latestPendingCheckpointNumber < checkpointNumber) {
1084
+ const latestProposedCheckpointNumber = await this.rollupContract.getCheckpointNumber();
1085
+ if (latestProposedCheckpointNumber < checkpointNumber) {
749
1086
  this.log.verbose(`Checkpoint ${checkpointNumber} has already been invalidated`, { ...logData });
750
1087
  return undefined;
751
1088
  } else {
@@ -765,18 +1102,22 @@ export class SequencerPublisher {
765
1102
 
766
1103
  // Otherwise, throw. We cannot build the next checkpoint if we cannot invalidate the previous one.
767
1104
  this.log.error(`Simulation for invalidate checkpoint ${checkpointNumber} failed`, viemError, logData);
768
- this.backupFailedTx({
769
- id: keccak256(request.data!),
770
- failureType: 'simulation',
771
- request: { to: request.to!, data: request.data!, value: request.value?.toString() },
772
- l1BlockNumber: l1BlockNumber.toString(),
773
- error: { message: viemError.message, name: viemError.name },
774
- context: {
775
- actions: [`invalidate-${reason}`],
776
- checkpointNumber,
777
- sender: this.getSenderAddress().toString(),
1105
+ this.backupFailedTx(
1106
+ {
1107
+ id: keccak256(request.data!),
1108
+ failureType: 'simulation',
1109
+ request: { to: request.to!, data: request.data!, value: request.value },
1110
+ l1BlockNumber,
1111
+ error: { message: viemError.message, name: viemError.name },
1112
+ context: {
1113
+ actions: [`invalidate-${reason}`],
1114
+ checkpointNumber,
1115
+ sender: this.getSenderAddress().toString(),
1116
+ },
1117
+ timing: this.computeTimingInfo(this.getCurrentL2Slot()),
778
1118
  },
779
- });
1119
+ { captureFeeSummary: true, targetSlot: this.getCurrentL2Slot() },
1120
+ );
780
1121
  throw new Error(`Failed to simulate invalidate checkpoint ${checkpointNumber}`, { cause: viemError });
781
1122
  }
782
1123
  }
@@ -790,9 +1131,11 @@ export class SequencerPublisher {
790
1131
  const logData = { ...checkpoint, reason };
791
1132
  this.log.debug(`Building invalidate checkpoint ${checkpoint.checkpointNumber} request`, logData);
792
1133
 
793
- const attestationsAndSigners = new CommitteeAttestationsAndSigners(
794
- validationResult.attestations,
795
- ).getPackedAttestations();
1134
+ // Use the exact packed tuple posted to L1 verbatim. A repack via `packAttestations` is not a
1135
+ // byte-faithful inverse of `fromPacked` (a canonicalized yParity byte or an all-zero signature slot
1136
+ // round-trips differently), so it would diverge from the stored `attestationsHash` and revert the
1137
+ // invalidation.
1138
+ const attestationsAndSigners = validationResult.verbatimAttestations;
796
1139
 
797
1140
  if (reason === 'invalid-attestation') {
798
1141
  return this.rollupContract.buildInvalidateBadAttestationRequest(
@@ -813,45 +1156,11 @@ export class SequencerPublisher {
813
1156
  }
814
1157
  }
815
1158
 
816
- /** Simulates `propose` to make sure that the checkpoint is valid for submission */
817
- @trackSpan('SequencerPublisher.validateCheckpointForSubmission')
818
- public async validateCheckpointForSubmission(
819
- checkpoint: Checkpoint,
820
- attestationsAndSigners: CommitteeAttestationsAndSigners,
821
- attestationsAndSignersSignature: Signature,
822
- options: { forcePendingCheckpointNumber?: CheckpointNumber },
823
- ): Promise<bigint> {
824
- // Anchor the simulation timestamp to the checkpoint's own slot start time
825
- // rather than the current L1 block timestamp, which may overshoot into the next slot if the build ran late.
826
- const ts = checkpoint.header.timestamp;
827
- const blobFields = checkpoint.toBlobFields();
828
- const blobs = await getBlobsPerL1Block(blobFields);
829
- const blobInput = getPrefixedEthBlobCommitments(blobs);
830
-
831
- const args = [
832
- {
833
- header: checkpoint.header.toViem(),
834
- archive: toHex(checkpoint.archive.root.toBuffer()),
835
- oracleInput: {
836
- feeAssetPriceModifier: checkpoint.feeAssetPriceModifier,
837
- },
838
- },
839
- attestationsAndSigners.getPackedAttestations(),
840
- attestationsAndSigners.getSigners().map(signer => signer.toString()),
841
- attestationsAndSignersSignature.toViemSignature(),
842
- blobInput,
843
- ] as const;
844
-
845
- await this.simulateProposeTx(args, ts, options);
846
- return ts;
847
- }
848
-
849
1159
  private async enqueueCastSignalHelper(
850
1160
  slotNumber: SlotNumber,
851
- timestamp: bigint,
852
1161
  signalType: GovernanceSignalAction,
853
1162
  payload: EthAddress,
854
- base: IEmpireBase,
1163
+ base: GovernanceProposerContract,
855
1164
  signerAddress: EthAddress,
856
1165
  signer: (msg: TypedDataDefinition) => Promise<`0x${string}`>,
857
1166
  ): Promise<boolean> {
@@ -866,6 +1175,19 @@ export class SequencerPublisher {
866
1175
  this.log.warn(`Cannot enqueue vote cast signal ${signalType} for address zero at slot ${slotNumber}`);
867
1176
  return false;
868
1177
  }
1178
+
1179
+ const canonicalRollup = await base.getRollupAddress();
1180
+ if (!canonicalRollup.equals(EthAddress.fromString(this.rollupContract.address))) {
1181
+ this.log.warn(`Rollup ${this.rollupContract.address} is not canonical, skipping governance signal`, {
1182
+ slotNumber,
1183
+ signalType,
1184
+ canonicalRollup,
1185
+ targetRollup: this.rollupContract.address,
1186
+ payload: payload.toString(),
1187
+ });
1188
+ return false;
1189
+ }
1190
+
869
1191
  const round = await base.computeRound(slotNumber);
870
1192
  const roundInfo = await base.getRoundInfo(this.rollupContract.address, round);
871
1193
 
@@ -877,34 +1199,43 @@ export class SequencerPublisher {
877
1199
  return false;
878
1200
  }
879
1201
 
880
- if (await this.isPayloadEmpty(payload)) {
1202
+ if (await base.isPayloadEmpty(payload)) {
881
1203
  this.log.warn(`Skipping vote cast for payload with empty code`);
882
1204
  return false;
883
1205
  }
884
1206
 
885
- // Check if payload was already submitted to governance
886
- const cacheKey = payload.toString();
887
- if (!this.payloadProposedCache.has(cacheKey)) {
888
- try {
889
- const l1StartBlock = await this.rollupContract.getL1StartBlock();
890
- const proposed = await retry(
891
- () => base.hasPayloadBeenProposed(payload.toString(), l1StartBlock),
892
- 'Check if payload was proposed',
893
- makeBackoff([0, 1, 2]),
894
- this.log,
895
- true,
896
- );
897
- if (proposed) {
898
- this.payloadProposedCache.add(cacheKey);
899
- }
900
- } catch (err) {
901
- this.log.warn(`Failed to check if payload ${payload} was proposed after retries, skipping signal`, err);
902
- return false;
903
- }
1207
+ // Classify the payload against the Governance proposal history so we stop signalling once its
1208
+ // proposal is live or was already executed, while still re-signalling one whose proposal was
1209
+ // merely rejected/dropped/expired.
1210
+ let status: PayloadProposalStatus = 'none';
1211
+ try {
1212
+ status = await base.getPayloadProposalStatus(payload.toString());
1213
+ } catch (err) {
1214
+ // We deliberately swallow the error and proceed to signal. Failing closed (skipping the
1215
+ // signal) on transient RPC errors would let a flaky L1 endpoint silence governance
1216
+ // participation entirely; failing open at worst produces a duplicate signal that the
1217
+ // contract will simply count alongside others in the round.
1218
+ this.log.error(`Failed to check governance proposal status for payload ${payload} (signalling anyway)`, err, {
1219
+ slotNumber,
1220
+ signalType,
1221
+ });
904
1222
  }
905
1223
 
906
- if (this.payloadProposedCache.has(cacheKey)) {
907
- this.log.info(`Payload ${payload} was already proposed to governance, stopping signals`);
1224
+ if (status === 'live') {
1225
+ this.log.info(`Payload ${payload} has a live governance proposal, stopping signals`, {
1226
+ slotNumber,
1227
+ signalType,
1228
+ payload: payload.toString(),
1229
+ });
1230
+ return false;
1231
+ }
1232
+
1233
+ if (status === 'executed' && !this.config.governanceProposerForcePayloadVote) {
1234
+ this.log.info(
1235
+ `Payload ${payload} was executed by governance within lookback, stopping signals ` +
1236
+ `(set GOVERNANCE_PROPOSER_FORCE_PAYLOAD_VOTE to re-signal)`,
1237
+ { slotNumber, signalType, payload: payload.toString() },
1238
+ );
908
1239
  return false;
909
1240
  }
910
1241
 
@@ -926,41 +1257,19 @@ export class SequencerPublisher {
926
1257
  lastValidL2Slot: slotNumber,
927
1258
  });
928
1259
 
929
- const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
930
-
931
- try {
932
- await this.l1TxUtils.simulate(request, { time: timestamp }, [], mergeAbis([request.abi ?? [], ErrorsAbi]));
933
- this.log.debug(`Simulation for ${action} at slot ${slotNumber} succeeded`, { request });
934
- } catch (err) {
935
- const viemError = formatViemError(err);
936
- this.log.error(`Failed simulation for ${action} at slot ${slotNumber} (enqueuing the action anyway)`, viemError);
937
- this.backupFailedTx({
938
- id: keccak256(request.data!),
939
- failureType: 'simulation',
940
- request: { to: request.to!, data: request.data!, value: request.value?.toString() },
941
- l1BlockNumber: l1BlockNumber.toString(),
942
- error: { message: viemError.message, name: viemError.name },
943
- context: {
944
- actions: [action],
945
- slot: slotNumber,
946
- sender: this.getSenderAddress().toString(),
947
- },
948
- });
949
- // Yes, we enqueue the request anyway, in case there was a bug with the simulation itself
950
- }
951
-
952
1260
  // TODO(palla/slash): All votes (governance and slashing) should txTimeoutAt at the end of the slot.
953
1261
  this.addRequest({
954
- gasConfig: { gasLimit: SequencerPublisher.VOTE_GAS_GUESS },
955
1262
  action,
956
1263
  request,
957
1264
  lastValidL2Slot: slotNumber,
958
1265
  checkSuccess: (_request, result) => {
959
1266
  const success =
960
1267
  result &&
961
- result.receipt &&
962
- result.receipt.status === 'success' &&
963
- tryExtractEvent(result.receipt.logs, base.address.toString(), EmpireBaseAbi, 'SignalCast');
1268
+ extractEventSuccess(result.receipt, {
1269
+ address: base.address.toString(),
1270
+ abi: EmpireBaseAbi,
1271
+ eventName: 'SignalCast',
1272
+ });
964
1273
 
965
1274
  const logData = { ...result, slotNumber, round, payload: payload.toString() };
966
1275
  if (!success) {
@@ -982,33 +1291,19 @@ export class SequencerPublisher {
982
1291
  return true;
983
1292
  }
984
1293
 
985
- private async isPayloadEmpty(payload: EthAddress): Promise<boolean> {
986
- const key = payload.toString();
987
- const cached = this.isPayloadEmptyCache.get(key);
988
- if (cached) {
989
- return cached;
990
- }
991
- const isEmpty = !(await this.l1TxUtils.getCode(payload));
992
- this.isPayloadEmptyCache.set(key, isEmpty);
993
- return isEmpty;
994
- }
995
-
996
1294
  /**
997
1295
  * Enqueues a governance castSignal transaction to cast a signal for a given slot number.
998
1296
  * @param slotNumber - The slot number to cast a signal for.
999
- * @param timestamp - The timestamp of the slot to cast a signal for.
1000
1297
  * @returns True if the signal was successfully enqueued, false otherwise.
1001
1298
  */
1002
1299
  public enqueueGovernanceCastSignal(
1003
1300
  governancePayload: EthAddress,
1004
1301
  slotNumber: SlotNumber,
1005
- timestamp: bigint,
1006
1302
  signerAddress: EthAddress,
1007
1303
  signer: (msg: TypedDataDefinition) => Promise<`0x${string}`>,
1008
1304
  ): Promise<boolean> {
1009
1305
  return this.enqueueCastSignalHelper(
1010
1306
  slotNumber,
1011
- timestamp,
1012
1307
  'governance-signal',
1013
1308
  governancePayload,
1014
1309
  this.govProposerContract,
@@ -1017,11 +1312,51 @@ export class SequencerPublisher {
1017
1312
  );
1018
1313
  }
1019
1314
 
1315
+ /**
1316
+ * Enqueues a `prune()` transaction if the rollup is prunable at the given slot's L1 timestamp.
1317
+ * `prune()` is permissionless and idempotent — if the chain is no longer prunable by send time the
1318
+ * bundle simulation usually drops the entry; on a node without `eth_simulateV1` the bundle is sent
1319
+ * as-is and the prune reverts `Rollup__NothingToPrune` inside `aggregate3(allowFailure: true)`
1320
+ * (a failed action, never a whole-tx revert). Used by the failed-sync fallback so a stuck pending
1321
+ * chain (e.g. bad data blocking sync) can be wound back to recover.
1322
+ * @returns true if a prune request was enqueued, false otherwise.
1323
+ */
1324
+ public async enqueuePruneIfPrunable(slotNumber: SlotNumber): Promise<boolean> {
1325
+ if (this.lastActions['prune'] === slotNumber) {
1326
+ this.log.debug(`Skipping duplicate prune for slot ${slotNumber}`, { slotNumber });
1327
+ return false;
1328
+ }
1329
+ // Use the SAME timestamp the bundle simulator overrides block.timestamp with at send time
1330
+ // (sequencer-bundle-simulator.ts) so this upfront check and the send-time sim agree. Slot-start
1331
+ // and last-L1-slot both fall within the same L2 slot (and epoch, which is what `canPruneAtTime`
1332
+ // derives), so they agree today; matching the simulator keeps it robust if the contract ever uses
1333
+ // the timestamp more granularly.
1334
+ const ts = getLastL1SlotTimestampForL2Slot(slotNumber, this.epochCache.getL1Constants());
1335
+ const canPrune = await this.rollupContract.canPruneAtTime(ts).catch(err => {
1336
+ this.log.error(`Failed to check canPruneAtTime for slot ${slotNumber}`, err, { slotNumber });
1337
+ return false;
1338
+ });
1339
+ if (!canPrune) {
1340
+ this.log.debug(`Rollup not prunable at slot ${slotNumber}`, { slotNumber });
1341
+ return false;
1342
+ }
1343
+ const request: L1TxRequest = {
1344
+ to: this.rollupContract.address,
1345
+ data: encodeFunctionData({ abi: RollupAbi, functionName: 'prune', args: [] }),
1346
+ };
1347
+ this.log.info(`Enqueuing rollup prune for slot ${slotNumber}`, { slotNumber });
1348
+ return this.enqueueRequest(
1349
+ 'prune',
1350
+ request,
1351
+ { address: this.rollupContract.address, abi: RollupAbi, eventName: 'PrunedPending' },
1352
+ slotNumber,
1353
+ );
1354
+ }
1355
+
1020
1356
  /** Enqueues all slashing actions as returned by the slasher client. */
1021
1357
  public async enqueueSlashingActions(
1022
1358
  actions: ProposerSlashAction[],
1023
1359
  slotNumber: SlotNumber,
1024
- timestamp: bigint,
1025
1360
  signerAddress: EthAddress,
1026
1361
  signer: (msg: TypedDataDefinition) => Promise<`0x${string}`>,
1027
1362
  ): Promise<boolean> {
@@ -1032,58 +1367,6 @@ export class SequencerPublisher {
1032
1367
 
1033
1368
  for (const action of actions) {
1034
1369
  switch (action.type) {
1035
- case 'vote-empire-payload': {
1036
- if (this.slashingProposerContract?.type !== 'empire') {
1037
- this.log.error('Cannot vote for empire payload on non-empire slashing contract');
1038
- break;
1039
- }
1040
- this.log.debug(`Enqueuing slashing vote for payload ${action.payload} at slot ${slotNumber}`, {
1041
- signerAddress,
1042
- });
1043
- await this.enqueueCastSignalHelper(
1044
- slotNumber,
1045
- timestamp,
1046
- 'empire-slashing-signal',
1047
- action.payload,
1048
- this.slashingProposerContract,
1049
- signerAddress,
1050
- signer,
1051
- );
1052
- break;
1053
- }
1054
-
1055
- case 'create-empire-payload': {
1056
- this.log.debug(`Enqueuing slashing create payload at slot ${slotNumber}`, { slotNumber, signerAddress });
1057
- const request = this.slashFactoryContract.buildCreatePayloadRequest(action.data);
1058
- await this.simulateAndEnqueueRequest(
1059
- 'create-empire-payload',
1060
- request,
1061
- (receipt: TransactionReceipt) =>
1062
- !!this.slashFactoryContract.tryExtractSlashPayloadCreatedEvent(receipt.logs),
1063
- slotNumber,
1064
- timestamp,
1065
- );
1066
- break;
1067
- }
1068
-
1069
- case 'execute-empire-payload': {
1070
- this.log.debug(`Enqueuing slashing execute payload at slot ${slotNumber}`, { slotNumber, signerAddress });
1071
- if (this.slashingProposerContract?.type !== 'empire') {
1072
- this.log.error('Cannot execute slashing payload on non-empire slashing contract');
1073
- return false;
1074
- }
1075
- const empireSlashingProposer = this.slashingProposerContract as EmpireSlashingProposerContract;
1076
- const request = empireSlashingProposer.buildExecuteRoundRequest(action.round);
1077
- await this.simulateAndEnqueueRequest(
1078
- 'execute-empire-payload',
1079
- request,
1080
- (receipt: TransactionReceipt) => !!empireSlashingProposer.tryExtractPayloadSubmittedEvent(receipt.logs),
1081
- slotNumber,
1082
- timestamp,
1083
- );
1084
- break;
1085
- }
1086
-
1087
1370
  case 'vote-offenses': {
1088
1371
  this.log.debug(`Enqueuing slashing vote for ${action.votes.length} votes at slot ${slotNumber}`, {
1089
1372
  slotNumber,
@@ -1091,19 +1374,21 @@ export class SequencerPublisher {
1091
1374
  votesCount: action.votes.length,
1092
1375
  signerAddress,
1093
1376
  });
1094
- if (this.slashingProposerContract?.type !== 'tally') {
1095
- this.log.error('Cannot vote for slashing offenses on non-tally slashing contract');
1377
+ if (!this.slashingProposerContract) {
1378
+ this.log.error('No slashing proposer contract available');
1096
1379
  return false;
1097
1380
  }
1098
- const tallySlashingProposer = this.slashingProposerContract as TallySlashingProposerContract;
1099
1381
  const votes = bufferToHex(encodeSlashConsensusVotes(action.votes));
1100
- const request = await tallySlashingProposer.buildVoteRequestFromSigner(votes, slotNumber, signer);
1101
- await this.simulateAndEnqueueRequest(
1382
+ const request = await this.slashingProposerContract.buildVoteRequestFromSigner(votes, slotNumber, signer);
1383
+ this.enqueueRequest(
1102
1384
  'vote-offenses',
1103
1385
  request,
1104
- (receipt: TransactionReceipt) => !!tallySlashingProposer.tryExtractVoteCastEvent(receipt.logs),
1386
+ {
1387
+ address: this.slashingProposerContract.address.toString(),
1388
+ abi: SlashingProposerAbi,
1389
+ eventName: 'VoteCast',
1390
+ },
1105
1391
  slotNumber,
1106
- timestamp,
1107
1392
  );
1108
1393
  break;
1109
1394
  }
@@ -1114,18 +1399,23 @@ export class SequencerPublisher {
1114
1399
  round: action.round,
1115
1400
  signerAddress,
1116
1401
  });
1117
- if (this.slashingProposerContract?.type !== 'tally') {
1118
- this.log.error('Cannot execute slashing offenses on non-tally slashing contract');
1402
+ if (!this.slashingProposerContract) {
1403
+ this.log.error('No slashing proposer contract available');
1119
1404
  return false;
1120
1405
  }
1121
- const tallySlashingProposer = this.slashingProposerContract as TallySlashingProposerContract;
1122
- const request = tallySlashingProposer.buildExecuteRoundRequest(action.round, action.committees);
1123
- await this.simulateAndEnqueueRequest(
1406
+ const executeRequest = this.slashingProposerContract.buildExecuteRoundRequest(
1407
+ action.round,
1408
+ action.committees,
1409
+ );
1410
+ this.enqueueRequest(
1124
1411
  'execute-slash',
1125
- request,
1126
- (receipt: TransactionReceipt) => !!tallySlashingProposer.tryExtractRoundExecutedEvent(receipt.logs),
1412
+ executeRequest,
1413
+ {
1414
+ address: this.slashingProposerContract.address.toString(),
1415
+ abi: SlashingProposerAbi,
1416
+ eventName: 'RoundExecuted',
1417
+ },
1127
1418
  slotNumber,
1128
- timestamp,
1129
1419
  );
1130
1420
  break;
1131
1421
  }
@@ -1140,12 +1430,12 @@ export class SequencerPublisher {
1140
1430
  return true;
1141
1431
  }
1142
1432
 
1143
- /** Simulates and enqueues a proposal for a checkpoint on L1 */
1433
+ /** Enqueues a proposal for a checkpoint on L1 */
1144
1434
  public async enqueueProposeCheckpoint(
1145
1435
  checkpoint: Checkpoint,
1146
1436
  attestationsAndSigners: CommitteeAttestationsAndSigners,
1147
1437
  attestationsAndSignersSignature: Signature,
1148
- opts: { txTimeoutAt?: Date; forcePendingCheckpointNumber?: CheckpointNumber } = {},
1438
+ opts: EnqueueProposeCheckpointOpts = {},
1149
1439
  ): Promise<void> {
1150
1440
  const checkpointHeader = checkpoint.header;
1151
1441
 
@@ -1161,31 +1451,11 @@ export class SequencerPublisher {
1161
1451
  feeAssetPriceModifier: checkpoint.feeAssetPriceModifier,
1162
1452
  };
1163
1453
 
1164
- let ts: bigint;
1165
-
1166
- try {
1167
- // @note This will make sure that we are passing the checks for our header ASSUMING that the data is also made available
1168
- // This means that we can avoid the simulation issues in later checks.
1169
- // By simulation issue, I mean the fact that the block.timestamp is equal to the last block, not the next, which
1170
- // make time consistency checks break.
1171
- // TODO(palla): Check whether we're validating twice, once here and once within addProposeTx, since we call simulateProposeTx in both places.
1172
- ts = await this.validateCheckpointForSubmission(
1173
- checkpoint,
1174
- attestationsAndSigners,
1175
- attestationsAndSignersSignature,
1176
- opts,
1177
- );
1178
- } catch (err: any) {
1179
- this.log.error(`Checkpoint validation failed. ${err instanceof Error ? err.message : 'No error message'}`, err, {
1180
- ...checkpoint.getStats(),
1181
- slotNumber: checkpoint.header.slotNumber,
1182
- forcePendingCheckpointNumber: opts.forcePendingCheckpointNumber,
1183
- });
1184
- throw err;
1185
- }
1186
-
1187
- this.log.verbose(`Enqueuing checkpoint propose transaction`, { ...checkpoint.toCheckpointInfo(), ...opts });
1188
- await this.addProposeTx(checkpoint, proposeTxArgs, opts, ts);
1454
+ this.log.verbose(`Enqueuing checkpoint propose transaction`, {
1455
+ ...checkpoint.toCheckpointInfo(),
1456
+ txTimeoutAt: opts.txTimeoutAt,
1457
+ });
1458
+ await this.addProposeTx(checkpoint, proposeTxArgs, { txTimeoutAt: opts.txTimeoutAt });
1189
1459
  }
1190
1460
 
1191
1461
  public enqueueInvalidateCheckpoint(
@@ -1196,23 +1466,22 @@ export class SequencerPublisher {
1196
1466
  return;
1197
1467
  }
1198
1468
 
1199
- // We issued the simulation against the rollup contract, so we need to account for the overhead of the multicall3
1200
- const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil((Number(request.gasUsed) * 64) / 63)));
1201
-
1202
1469
  const { gasUsed, checkpointNumber } = request;
1203
- const logData = { gasUsed, checkpointNumber, gasLimit, opts };
1470
+ const logData = { gasUsed, checkpointNumber, opts };
1204
1471
  this.log.verbose(`Enqueuing invalidate checkpoint request`, logData);
1205
1472
  this.addRequest({
1206
1473
  action: `invalidate-by-${request.reason}`,
1207
1474
  request: request.request,
1208
- gasConfig: { gasLimit, txTimeoutAt: opts.txTimeoutAt },
1475
+ gasConfig: opts.txTimeoutAt ? { txTimeoutAt: opts.txTimeoutAt } : undefined,
1209
1476
  lastValidL2Slot: SlotNumber(this.getCurrentL2Slot() + 2),
1210
1477
  checkSuccess: (_req, result) => {
1211
1478
  const success =
1212
1479
  result &&
1213
- result.receipt &&
1214
- result.receipt.status === 'success' &&
1215
- tryExtractEvent(result.receipt.logs, this.rollupContract.address, RollupAbi, 'CheckpointInvalidated');
1480
+ extractEventSuccess(result.receipt, {
1481
+ address: this.rollupContract.address,
1482
+ abi: RollupAbi,
1483
+ eventName: 'CheckpointInvalidated',
1484
+ });
1216
1485
  if (!success) {
1217
1486
  this.log.warn(`Invalidate checkpoint ${request.checkpointNumber} failed`, { ...result, ...logData });
1218
1487
  } else {
@@ -1223,72 +1492,36 @@ export class SequencerPublisher {
1223
1492
  });
1224
1493
  }
1225
1494
 
1226
- private async simulateAndEnqueueRequest(
1495
+ /**
1496
+ * Dedup-checked enqueue helper for actions that are simulated at bundle-send time rather
1497
+ * than at enqueue time. Validates the (action, slot) dedup key, sets `lastActions`, and
1498
+ * enqueues without a gasLimit so the bundle simulate sets the only gasLimit that matters.
1499
+ */
1500
+ private enqueueRequest(
1227
1501
  action: Action,
1228
1502
  request: L1TxRequest,
1229
- checkSuccess: (receipt: TransactionReceipt) => boolean | undefined,
1503
+ eventOpts: { address: string; abi: Abi; eventName: string },
1230
1504
  slotNumber: SlotNumber,
1231
- timestamp: bigint,
1232
- ) {
1233
- const logData = { slotNumber, timestamp, gasLimit: undefined as bigint | undefined };
1505
+ ): boolean {
1234
1506
  if (this.lastActions[action] && this.lastActions[action] === slotNumber) {
1235
1507
  this.log.debug(`Skipping duplicate action ${action} for slot ${slotNumber}`);
1236
1508
  return false;
1237
1509
  }
1238
-
1239
1510
  const cachedLastActionSlot = this.lastActions[action];
1240
1511
  this.lastActions[action] = slotNumber;
1241
1512
 
1242
- this.log.debug(`Simulating ${action} for slot ${slotNumber}`, logData);
1243
-
1244
- const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
1245
-
1246
- let gasUsed: bigint;
1247
- const simulateAbi = mergeAbis([request.abi ?? [], ErrorsAbi]);
1248
- try {
1249
- ({ gasUsed } = await this.l1TxUtils.simulate(request, { time: timestamp }, [], simulateAbi)); // TODO(palla/slash): Check the timestamp logic
1250
- this.log.verbose(`Simulation for ${action} succeeded`, { ...logData, request, gasUsed });
1251
- } catch (err) {
1252
- const viemError = formatViemError(err, simulateAbi);
1253
- this.log.error(`Simulation for ${action} at ${slotNumber} failed`, viemError, logData);
1254
-
1255
- this.backupFailedTx({
1256
- id: keccak256(request.data!),
1257
- failureType: 'simulation',
1258
- request: { to: request.to!, data: request.data!, value: request.value?.toString() },
1259
- l1BlockNumber: l1BlockNumber.toString(),
1260
- error: { message: viemError.message, name: viemError.name },
1261
- context: {
1262
- actions: [action],
1263
- slot: slotNumber,
1264
- sender: this.getSenderAddress().toString(),
1265
- },
1266
- });
1267
-
1268
- return false;
1269
- }
1270
-
1271
- // We issued the simulation against the rollup contract, so we need to account for the overhead of the multicall3
1272
- const gasLimit = this.l1TxUtils.bumpGasLimit(BigInt(Math.ceil((Number(gasUsed) * 64) / 63)));
1273
- logData.gasLimit = gasLimit;
1274
-
1275
- // Store the ABI used for simulation on the request so Multicall3.forward can decode errors
1276
- // when the tx is sent and a revert is diagnosed via simulation.
1277
- const requestWithAbi = { ...request, abi: simulateAbi };
1278
-
1279
- this.log.debug(`Enqueuing ${action}`, logData);
1513
+ this.log.debug(`Enqueuing ${action}`, { slotNumber });
1280
1514
  this.addRequest({
1281
1515
  action,
1282
- request: requestWithAbi,
1283
- gasConfig: { gasLimit },
1516
+ request,
1284
1517
  lastValidL2Slot: slotNumber,
1285
- checkSuccess: (_req, result) => {
1286
- const success = result && result.receipt && result.receipt.status === 'success' && checkSuccess(result.receipt);
1518
+ checkSuccess: (_request, result) => {
1519
+ const success = result && extractEventSuccess(result.receipt, eventOpts);
1287
1520
  if (!success) {
1288
- this.log.warn(`Action ${action} at ${slotNumber} failed`, { ...result, ...logData });
1521
+ this.log.warn(`Action ${action} at ${slotNumber} failed`, { ...result, slotNumber });
1289
1522
  this.lastActions[action] = cachedLastActionSlot;
1290
1523
  } else {
1291
- this.log.info(`Action ${action} at ${slotNumber} succeeded`, { ...result, ...logData });
1524
+ this.log.info(`Action ${action} at ${slotNumber} succeeded`, { ...result, slotNumber });
1292
1525
  }
1293
1526
  return !!success;
1294
1527
  },
@@ -1304,6 +1537,7 @@ export class SequencerPublisher {
1304
1537
  */
1305
1538
  public interrupt() {
1306
1539
  this.interrupted = true;
1540
+ this.interruptibleSleep.interrupt();
1307
1541
  this.l1TxUtils.interrupt();
1308
1542
  }
1309
1543
 
@@ -1313,11 +1547,7 @@ export class SequencerPublisher {
1313
1547
  this.l1TxUtils.restart();
1314
1548
  }
1315
1549
 
1316
- private async prepareProposeTx(
1317
- encodedData: L1ProcessArgs,
1318
- timestamp: bigint,
1319
- options: { forcePendingCheckpointNumber?: CheckpointNumber },
1320
- ) {
1550
+ private async prepareProposeTx(encodedData: L1ProcessArgs) {
1321
1551
  const kzg = Blob.getViemKzgInstance();
1322
1552
  const blobInput = getPrefixedEthBlobCommitments(encodedData.blobs);
1323
1553
  this.log.debug('Validating blob input', { blobInput });
@@ -1330,7 +1560,11 @@ export class SequencerPublisher {
1330
1560
  blobEvaluationGas = BigInt(encodedData.blobs.length) * 21_000n;
1331
1561
  this.log.debug(`Using fixed blob evaluation gas estimate in fisherman mode: ${blobEvaluationGas}`);
1332
1562
  } else {
1333
- // Normal mode - use estimateGas with blob inputs
1563
+ // We call validateBlobs via estimateGas with real blob+kzg sidecars as a consistency check
1564
+ // that our locally-built blob commitments match the blob data. The bundle simulate at send
1565
+ // time uses eth_simulateV1, which cannot carry blob inputs, so the rollup's on-chain blob
1566
+ // check is forced off there — making this the only pre-flight detector of a commitment/data
1567
+ // mismatch. The returned gas estimate is stashed on the request for the bundle path to read.
1334
1568
  blobEvaluationGas = await this.l1TxUtils
1335
1569
  .estimateGas(
1336
1570
  this.getSenderAddress().toString(),
@@ -1357,18 +1591,22 @@ export class SequencerPublisher {
1357
1591
  args: [blobInput],
1358
1592
  });
1359
1593
  const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
1360
- this.backupFailedTx({
1361
- id: keccak256(validateBlobsData),
1362
- failureType: 'simulation',
1363
- request: { to: this.rollupContract.address as Hex, data: validateBlobsData },
1364
- blobData: encodedData.blobs.map(b => toHex(b.data)) as Hex[],
1365
- l1BlockNumber: l1BlockNumber.toString(),
1366
- error: { message: viemError.message, name: viemError.name },
1367
- context: {
1368
- actions: ['validate-blobs'],
1369
- sender: this.getSenderAddress().toString(),
1594
+ this.backupFailedTx(
1595
+ {
1596
+ id: keccak256(validateBlobsData),
1597
+ failureType: 'simulation',
1598
+ request: { to: this.rollupContract.address as Hex, data: validateBlobsData },
1599
+ blobData: encodedData.blobs.map(b => toHex(b.data)) as Hex[],
1600
+ l1BlockNumber,
1601
+ error: { message: viemError.message, name: viemError.name },
1602
+ context: {
1603
+ actions: ['validate-blobs'],
1604
+ sender: this.getSenderAddress().toString(),
1605
+ },
1606
+ timing: this.computeTimingInfo(this.getCurrentL2Slot()),
1370
1607
  },
1371
- });
1608
+ { captureFeeSummary: true, targetSlot: this.getCurrentL2Slot() },
1609
+ );
1372
1610
  throw new Error('Failed to validate blobs');
1373
1611
  });
1374
1612
  }
@@ -1388,138 +1626,21 @@ export class SequencerPublisher {
1388
1626
  blobInput,
1389
1627
  ] as const;
1390
1628
 
1391
- const { rollupData, simulationResult } = await this.simulateProposeTx(args, timestamp, options);
1629
+ const rollupData = encodeFunctionData({ abi: RollupAbi, functionName: 'propose', args });
1392
1630
 
1393
- return { args, blobEvaluationGas, rollupData, simulationResult };
1394
- }
1395
-
1396
- /**
1397
- * Simulates the propose tx with eth_simulateV1
1398
- * @param args - The propose tx args
1399
- * @param timestamp - The timestamp to simulate proposal at
1400
- * @returns The simulation result
1401
- */
1402
- private async simulateProposeTx(
1403
- args: readonly [
1404
- {
1405
- readonly header: ViemHeader;
1406
- readonly archive: `0x${string}`;
1407
- readonly oracleInput: {
1408
- readonly feeAssetPriceModifier: bigint;
1409
- };
1410
- },
1411
- ViemCommitteeAttestations,
1412
- `0x${string}`[], // Signers
1413
- ViemSignature,
1414
- `0x${string}`,
1415
- ],
1416
- timestamp: bigint,
1417
- options: { forcePendingCheckpointNumber?: CheckpointNumber },
1418
- ) {
1419
- const rollupData = encodeFunctionData({
1420
- abi: RollupAbi,
1421
- functionName: 'propose',
1422
- args,
1423
- });
1424
-
1425
- // override the pending checkpoint number if requested
1426
- const forcePendingCheckpointNumberStateDiff = (
1427
- options.forcePendingCheckpointNumber !== undefined
1428
- ? await this.rollupContract.makePendingCheckpointNumberOverride(options.forcePendingCheckpointNumber)
1429
- : []
1430
- ).flatMap(override => override.stateDiff ?? []);
1431
-
1432
- const stateOverrides: StateOverride = [
1433
- {
1434
- address: this.rollupContract.address,
1435
- // @note we override checkBlob to false since blobs are not part simulate()
1436
- stateDiff: [
1437
- { slot: toPaddedHex(RollupContract.checkBlobStorageSlot, true), value: toPaddedHex(0n, true) },
1438
- ...forcePendingCheckpointNumberStateDiff,
1439
- ],
1440
- },
1441
- ];
1442
- // In fisherman mode, simulate as the proposer but with sufficient balance
1443
- if (this.proposerAddressForSimulation) {
1444
- stateOverrides.push({
1445
- address: this.proposerAddressForSimulation.toString(),
1446
- balance: 10n * WEI_CONST * WEI_CONST, // 10 ETH
1447
- });
1448
- }
1449
-
1450
- const l1BlockNumber = await this.l1TxUtils.getBlockNumber();
1451
-
1452
- const simulationResult = await this.l1TxUtils
1453
- .simulate(
1454
- {
1455
- to: this.rollupContract.address,
1456
- data: rollupData,
1457
- gas: MAX_L1_TX_LIMIT,
1458
- ...(this.proposerAddressForSimulation && { from: this.proposerAddressForSimulation.toString() }),
1459
- },
1460
- {
1461
- // @note we add 1n to the timestamp because geth implementation doesn't like simulation timestamp to be equal to the current block timestamp
1462
- time: timestamp + 1n,
1463
- // @note reth should have a 30m gas limit per block but throws errors that this tx is beyond limit so we increase here
1464
- gasLimit: MAX_L1_TX_LIMIT * 2n,
1465
- },
1466
- stateOverrides,
1467
- RollupAbi,
1468
- {
1469
- // @note fallback gas estimate to use if the node doesn't support simulation API
1470
- fallbackGasEstimate: MAX_L1_TX_LIMIT,
1471
- },
1472
- )
1473
- .catch(err => {
1474
- // In fisherman mode, we expect ValidatorSelection__MissingProposerSignature since fisherman doesn't have proposer signature
1475
- const viemError = formatViemError(err);
1476
- if (this.config.fishermanMode && viemError.message?.includes('ValidatorSelection__MissingProposerSignature')) {
1477
- this.log.debug(`Ignoring expected ValidatorSelection__MissingProposerSignature error in fisherman mode`);
1478
- // Return a minimal simulation result with the fallback gas estimate
1479
- return {
1480
- gasUsed: MAX_L1_TX_LIMIT,
1481
- logs: [],
1482
- };
1483
- }
1484
- this.log.error(`Failed to simulate propose tx`, viemError);
1485
- this.backupFailedTx({
1486
- id: keccak256(rollupData),
1487
- failureType: 'simulation',
1488
- request: { to: this.rollupContract.address, data: rollupData },
1489
- l1BlockNumber: l1BlockNumber.toString(),
1490
- error: { message: viemError.message, name: viemError.name },
1491
- context: {
1492
- actions: ['propose'],
1493
- slot: Number(args[0].header.slotNumber),
1494
- sender: this.getSenderAddress().toString(),
1495
- },
1496
- });
1497
- throw err;
1498
- });
1499
-
1500
- return { rollupData, simulationResult };
1631
+ return { args, blobEvaluationGas, rollupData };
1501
1632
  }
1502
1633
 
1503
1634
  private async addProposeTx(
1504
1635
  checkpoint: Checkpoint,
1505
1636
  encodedData: L1ProcessArgs,
1506
- opts: { txTimeoutAt?: Date; forcePendingCheckpointNumber?: CheckpointNumber } = {},
1507
- timestamp: bigint,
1637
+ opts: EnqueueProposeCheckpointOpts = {},
1508
1638
  ): Promise<void> {
1509
1639
  const slot = checkpoint.header.slotNumber;
1510
1640
  const timer = new Timer();
1511
1641
  const kzg = Blob.getViemKzgInstance();
1512
- const { rollupData, simulationResult, blobEvaluationGas } = await this.prepareProposeTx(
1513
- encodedData,
1514
- timestamp,
1515
- opts,
1516
- );
1642
+ const { rollupData, blobEvaluationGas } = await this.prepareProposeTx(encodedData);
1517
1643
  const startBlock = await this.l1TxUtils.getBlockNumber();
1518
- const gasLimit = this.l1TxUtils.bumpGasLimit(
1519
- BigInt(Math.ceil((Number(simulationResult.gasUsed) * 64) / 63)) +
1520
- blobEvaluationGas +
1521
- SequencerPublisher.MULTICALL_OVERHEAD_GAS_GUESS, // We issue the simulation against the rollup contract, so we need to account for the overhead of the multicall3
1522
- );
1523
1644
 
1524
1645
  // Send the blobs to the blob client preemptively. This helps in tests where the sequencer mistakingly thinks that the propose
1525
1646
  // tx fails but it does get mined. We make sure that the blobs are sent to the blob client regardless of the tx outcome.
@@ -1536,7 +1657,8 @@ export class SequencerPublisher {
1536
1657
  data: rollupData,
1537
1658
  },
1538
1659
  lastValidL2Slot: checkpoint.header.slotNumber,
1539
- gasConfig: { ...opts, gasLimit },
1660
+ gasConfig: { txTimeoutAt: opts.txTimeoutAt, gasLimit: undefined },
1661
+ blobEvaluationGas,
1540
1662
  blobConfig: {
1541
1663
  blobs: encodedData.blobs.map(b => b.data),
1542
1664
  kzg,
@@ -1546,10 +1668,11 @@ export class SequencerPublisher {
1546
1668
  return false;
1547
1669
  }
1548
1670
  const { receipt, stats, errorMsg } = result;
1549
- const success =
1550
- receipt &&
1551
- receipt.status === 'success' &&
1552
- tryExtractEvent(receipt.logs, this.rollupContract.address, RollupAbi, 'CheckpointProposed');
1671
+ const success = extractEventSuccess(receipt, {
1672
+ address: this.rollupContract.address,
1673
+ abi: RollupAbi,
1674
+ eventName: 'CheckpointProposed',
1675
+ });
1553
1676
 
1554
1677
  if (success) {
1555
1678
  const endBlock = receipt.blockNumber;
@@ -1590,7 +1713,7 @@ export class SequencerPublisher {
1590
1713
  });
1591
1714
  }
1592
1715
 
1593
- /** Returns the timestamp to use when simulating L1 proposal calls */
1716
+ /** Returns the timestamp of the next L1 slot boundary after now. */
1594
1717
  private getNextL1SlotTimestamp(): bigint {
1595
1718
  const l1Constants = this.epochCache.getL1Constants();
1596
1719
  return getNextL1SlotTimestamp(this.dateProvider.nowInSeconds(), l1Constants);