@aztec/sequencer-client 5.0.0-private.20260319 → 5.0.0-rc.1

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 (105) hide show
  1. package/README.md +281 -21
  2. package/dest/client/sequencer-client.d.ts +8 -3
  3. package/dest/client/sequencer-client.d.ts.map +1 -1
  4. package/dest/client/sequencer-client.js +17 -32
  5. package/dest/config.d.ts +10 -4
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +48 -24
  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 +128 -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 +67 -0
  14. package/dest/global_variable_builder/global_builder.d.ts +14 -14
  15. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  16. package/dest/global_variable_builder/global_builder.js +16 -51
  17. package/dest/global_variable_builder/index.d.ts +4 -2
  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 +15 -3
  21. package/dest/publisher/config.d.ts.map +1 -1
  22. package/dest/publisher/config.js +19 -4
  23. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +3 -4
  24. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -1
  25. package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
  26. package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
  27. package/dest/publisher/sequencer-bundle-simulator.js +198 -0
  28. package/dest/publisher/sequencer-publisher-factory.d.ts +3 -5
  29. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  30. package/dest/publisher/sequencer-publisher-factory.js +2 -3
  31. package/dest/publisher/sequencer-publisher.d.ts +70 -64
  32. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  33. package/dest/publisher/sequencer-publisher.js +312 -533
  34. package/dest/sequencer/automine/automine_factory.d.ts +56 -0
  35. package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
  36. package/dest/sequencer/automine/automine_factory.js +85 -0
  37. package/dest/sequencer/automine/automine_sequencer.d.ts +184 -0
  38. package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
  39. package/dest/sequencer/automine/automine_sequencer.js +677 -0
  40. package/dest/sequencer/automine/index.d.ts +3 -0
  41. package/dest/sequencer/automine/index.d.ts.map +1 -0
  42. package/dest/sequencer/automine/index.js +2 -0
  43. package/dest/sequencer/chain_state_overrides.d.ts +61 -0
  44. package/dest/sequencer/chain_state_overrides.d.ts.map +1 -0
  45. package/dest/sequencer/chain_state_overrides.js +98 -0
  46. package/dest/sequencer/checkpoint_proposal_job.d.ts +73 -21
  47. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  48. package/dest/sequencer/checkpoint_proposal_job.js +709 -199
  49. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
  50. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
  51. package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
  52. package/dest/sequencer/checkpoint_voter.d.ts +1 -2
  53. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
  54. package/dest/sequencer/checkpoint_voter.js +2 -5
  55. package/dest/sequencer/errors.d.ts +1 -8
  56. package/dest/sequencer/errors.d.ts.map +1 -1
  57. package/dest/sequencer/errors.js +0 -9
  58. package/dest/sequencer/events.d.ts +61 -4
  59. package/dest/sequencer/events.d.ts.map +1 -1
  60. package/dest/sequencer/metrics.d.ts +9 -10
  61. package/dest/sequencer/metrics.d.ts.map +1 -1
  62. package/dest/sequencer/metrics.js +34 -20
  63. package/dest/sequencer/sequencer.d.ts +112 -27
  64. package/dest/sequencer/sequencer.d.ts.map +1 -1
  65. package/dest/sequencer/sequencer.js +467 -147
  66. package/dest/sequencer/types.d.ts +2 -2
  67. package/dest/sequencer/types.d.ts.map +1 -1
  68. package/dest/test/index.d.ts +3 -3
  69. package/dest/test/index.d.ts.map +1 -1
  70. package/dest/test/utils.d.ts +15 -1
  71. package/dest/test/utils.d.ts.map +1 -1
  72. package/dest/test/utils.js +23 -6
  73. package/package.json +28 -27
  74. package/src/client/sequencer-client.ts +29 -41
  75. package/src/config.ts +57 -24
  76. package/src/global_variable_builder/README.md +44 -0
  77. package/src/global_variable_builder/fee_predictor.ts +172 -0
  78. package/src/global_variable_builder/fee_provider.ts +80 -0
  79. package/src/global_variable_builder/global_builder.ts +25 -63
  80. package/src/global_variable_builder/index.ts +3 -1
  81. package/src/publisher/config.ts +40 -6
  82. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +3 -1
  83. package/src/publisher/sequencer-bundle-simulator.ts +254 -0
  84. package/src/publisher/sequencer-publisher-factory.ts +3 -6
  85. package/src/publisher/sequencer-publisher.ts +368 -577
  86. package/src/sequencer/automine/README.md +60 -0
  87. package/src/sequencer/automine/automine_factory.ts +152 -0
  88. package/src/sequencer/automine/automine_sequencer.ts +783 -0
  89. package/src/sequencer/automine/index.ts +6 -0
  90. package/src/sequencer/chain_state_overrides.ts +169 -0
  91. package/src/sequencer/checkpoint_proposal_job.ts +818 -224
  92. package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
  93. package/src/sequencer/checkpoint_voter.ts +1 -12
  94. package/src/sequencer/errors.ts +0 -15
  95. package/src/sequencer/events.ts +65 -4
  96. package/src/sequencer/metrics.ts +43 -24
  97. package/src/sequencer/sequencer.ts +542 -164
  98. package/src/sequencer/types.ts +1 -1
  99. package/src/test/index.ts +2 -2
  100. package/src/test/utils.ts +59 -10
  101. package/dest/sequencer/timetable.d.ts +0 -88
  102. package/dest/sequencer/timetable.d.ts.map +0 -1
  103. package/dest/sequencer/timetable.js +0 -222
  104. package/src/sequencer/README.md +0 -531
  105. package/src/sequencer/timetable.ts +0 -283
@@ -0,0 +1,254 @@
1
+ import type { EpochCache } from '@aztec/epoch-cache';
2
+ import { Multicall3, type RollupContract, buildSimulationOverridesStateOverride } from '@aztec/ethereum/contracts';
3
+ import { type L1TxUtils, MAX_L1_TX_LIMIT } from '@aztec/ethereum/l1-tx-utils';
4
+ import { formatViemError } from '@aztec/ethereum/utils';
5
+ import type { SlotNumber } from '@aztec/foundation/branded-types';
6
+ import { type Logger, createLogger } from '@aztec/foundation/log';
7
+ import { getLastL1SlotTimestampForL2Slot } from '@aztec/stdlib/epoch-helpers';
8
+
9
+ import type { Hex, StateOverride } from 'viem';
10
+
11
+ import type { RequestWithExpiry } from './sequencer-publisher.js';
12
+
13
+ /** A request that was dropped by bundle simulation, with the decoded revert reason. */
14
+ export type DroppedRequest = {
15
+ request: RequestWithExpiry;
16
+ revertReason: string | undefined;
17
+ returnData: Hex | undefined;
18
+ };
19
+
20
+ /**
21
+ * Result of {@link SequencerBundleSimulator.simulate}.
22
+ *
23
+ * - `success`: simulation succeeded. `requests` is the filtered survivor list, `gasLimit` is
24
+ * the bumped gas limit derived from `gasUsed` (plus blob evaluation gas). `droppedRequests`
25
+ * lists the entries that were observed to revert in simulation.
26
+ * - `fallback`: the node does not support eth_simulateV1 (or the simulate call threw). The
27
+ * caller should send `requests` as-is with a safe gas limit (e.g. {@link MAX_L1_TX_LIMIT}).
28
+ * `droppedRequests` carries any entries that the first pass already proved reverted, so the
29
+ * caller does not re-include them when the second pass falls back.
30
+ * - `aborted`: the bundle cannot be sent. `droppedRequests` contains only entries that were
31
+ * actually observed to revert (so they can be reported as simulation failures); it is empty
32
+ * when the abort was caused by an empty input bundle.
33
+ */
34
+ export type BundleSimulateResult =
35
+ | { kind: 'success'; requests: RequestWithExpiry[]; gasLimit: bigint; droppedRequests: DroppedRequest[] }
36
+ | { kind: 'fallback'; requests: RequestWithExpiry[]; droppedRequests: DroppedRequest[] }
37
+ | { kind: 'aborted'; reason: AbortReason; droppedRequests: DroppedRequest[] };
38
+
39
+ export type AbortReason = 'empty-bundle' | 'all-reverted' | 'second-pass-reverts';
40
+
41
+ type SimulatePassResult =
42
+ | { kind: 'decoded'; survivors: RequestWithExpiry[]; droppedRequests: DroppedRequest[]; gasUsed: bigint }
43
+ | { kind: 'fallback' };
44
+
45
+ /**
46
+ * Bundle-level simulator for the aggregate3 payload that `SequencerPublisher` is about to send.
47
+ *
48
+ * Runs `eth_simulateV1` against `Multicall3.aggregate3`, drops entries that revert, and returns
49
+ * a gasLimit for the survivors. When `eth_simulateV1` is unavailable, signals fallback to the
50
+ * caller so it can send the bundle as-is with a conservative gas limit.
51
+ */
52
+ export class SequencerBundleSimulator {
53
+ private readonly log: Logger;
54
+
55
+ constructor(
56
+ private readonly deps: {
57
+ getL1TxUtils: () => L1TxUtils;
58
+ rollupContract: RollupContract;
59
+ epochCache: EpochCache;
60
+ log?: Logger;
61
+ },
62
+ ) {
63
+ this.log = deps.log ?? createLogger('sequencer:publisher:bundle-simulator');
64
+ }
65
+
66
+ /**
67
+ * Simulates the given bundle near the end of the target slot and filters out entries
68
+ * that revert.
69
+ *
70
+ * - If all entries pass on the first pass, returns `success` with the gasLimit.
71
+ * - If some entries revert, re-simulates the survivors. If the second pass is clean, returns
72
+ * `success` with the survivors and dropped entries. If the second pass surfaces any revert,
73
+ * returns `aborted` — we refuse to send a bundle whose composition still has internal
74
+ * reverts after one round of filtering.
75
+ * - If eth_simulateV1 is unavailable, returns `fallback`. The caller is expected to send the
76
+ * bundle as-is with a safe gas limit.
77
+ *
78
+ * The simulation `block.timestamp` is the last L1 slot timestamp inside the target L2 slot.
79
+ * This still maps to the target L2 slot for propose's `validateHeader` and EIP-712 signature
80
+ * checks, while avoiding eth_simulateV1 rejecting a child block whose timestamp is not strictly
81
+ * greater than the current L1 head.
82
+ *
83
+ * Known limitation: on networks where L1 is mining behind cadence (missed L1 slots, anvil with
84
+ * overridden timestamps), the actual `block.timestamp` at send time can land in the prior L2
85
+ * slot. In that case `propose` would revert silently inside the multicall. The simulator does
86
+ * not detect this case because it simulates inside the target slot — the prior implementation
87
+ * used `min(predictedNextL1Ts, targetTimestamp)` to surface this failure mode at simulate time.
88
+ */
89
+ public async simulate(validRequests: RequestWithExpiry[], targetSlot: SlotNumber): Promise<BundleSimulateResult> {
90
+ if (validRequests.length === 0) {
91
+ return { kind: 'aborted', reason: 'empty-bundle', droppedRequests: [] };
92
+ }
93
+ // Pin the publisher we'll use across the whole simulate call so that the publisher's rotation
94
+ // can't change l1TxUtils mid-flight.
95
+ const l1TxUtils = this.deps.getL1TxUtils();
96
+
97
+ const proposeRequest = validRequests.find(r => r.action === 'propose');
98
+ const simulateTimestamp = getLastL1SlotTimestampForL2Slot(targetSlot, this.deps.epochCache.getL1Constants());
99
+ const firstPassOverrides = await this.buildStateOverrides(!!proposeRequest);
100
+
101
+ const firstPass = await this.simulateAndDecode(l1TxUtils, validRequests, simulateTimestamp, firstPassOverrides);
102
+
103
+ if (firstPass.kind === 'fallback') {
104
+ this.log.warn('Bundle simulate fallback (eth_simulateV1 unavailable); caller will send bundle as-is', {
105
+ actions: validRequests.map(r => r.action),
106
+ });
107
+ return { kind: 'fallback', requests: validRequests, droppedRequests: [] };
108
+ }
109
+
110
+ if (firstPass.survivors.length === 0) {
111
+ this.log.warn('All bundle entries dropped in simulation; aborting send', {
112
+ actions: validRequests.map(r => r.action),
113
+ });
114
+ return { kind: 'aborted', reason: 'all-reverted', droppedRequests: firstPass.droppedRequests };
115
+ }
116
+
117
+ if (firstPass.droppedRequests.length === 0) {
118
+ return this.buildSuccessResult(l1TxUtils, firstPass.survivors, [], firstPass.gasUsed, proposeRequest);
119
+ }
120
+
121
+ this.log.warn('Some bundle entries reverted; re-simulating reduced bundle', {
122
+ droppedActions: firstPass.droppedRequests.map(d => d.request.action),
123
+ remainingActions: firstPass.survivors.map(r => r.action),
124
+ });
125
+
126
+ // Rebuild overrides for the reduced bundle: if propose was dropped, we no longer need the blob-check override
127
+ const proposeSurvived = proposeRequest !== undefined && firstPass.survivors.includes(proposeRequest);
128
+ const secondPassOverrides = proposeSurvived ? firstPassOverrides : await this.buildStateOverrides(false);
129
+ const secondPass = await this.simulateAndDecode(
130
+ l1TxUtils,
131
+ firstPass.survivors,
132
+ simulateTimestamp,
133
+ secondPassOverrides,
134
+ );
135
+
136
+ if (secondPass.kind === 'fallback') {
137
+ this.log.warn(
138
+ 'Bundle simulate errored on second pass (eth_simulateV1 unavailable); sending first-pass survivors as-is',
139
+ {
140
+ actions: firstPass.survivors.map(r => r.action),
141
+ droppedActions: firstPass.droppedRequests.map(d => d.request.action),
142
+ },
143
+ );
144
+ return { kind: 'fallback', requests: firstPass.survivors, droppedRequests: firstPass.droppedRequests };
145
+ }
146
+
147
+ // We refuse to chase reverts through repeated trimming: anything other than a clean second pass aborts the whole send
148
+ if (secondPass.droppedRequests.length > 0) {
149
+ this.log.error('Re-simulate surfaced reverts; aborting send', {
150
+ secondPassDroppedActions: secondPass.droppedRequests.map(d => d.request.action),
151
+ });
152
+ return {
153
+ kind: 'aborted',
154
+ reason: 'second-pass-reverts',
155
+ droppedRequests: [...firstPass.droppedRequests, ...secondPass.droppedRequests],
156
+ };
157
+ }
158
+
159
+ return this.buildSuccessResult(
160
+ l1TxUtils,
161
+ secondPass.survivors,
162
+ firstPass.droppedRequests,
163
+ secondPass.gasUsed,
164
+ proposeRequest,
165
+ );
166
+ }
167
+
168
+ private buildSuccessResult(
169
+ l1TxUtils: L1TxUtils,
170
+ survivors: RequestWithExpiry[],
171
+ droppedRequests: DroppedRequest[],
172
+ bundleGasUsed: bigint,
173
+ proposeRequest: RequestWithExpiry | undefined,
174
+ ): BundleSimulateResult {
175
+ const proposeSurvived = proposeRequest !== undefined && survivors.includes(proposeRequest);
176
+ const blobEvaluationGas = proposeSurvived ? (proposeRequest?.blobEvaluationGas ?? 0n) : 0n;
177
+ const gasLimit = this.computeGasLimit(l1TxUtils, bundleGasUsed, blobEvaluationGas);
178
+ this.log.debug('Bundle simulate complete', {
179
+ survivingRequests: survivors.length,
180
+ bundleGasUsed,
181
+ gasLimit,
182
+ actions: survivors.map(r => r.action),
183
+ });
184
+ return { kind: 'success', requests: survivors, gasLimit, droppedRequests };
185
+ }
186
+
187
+ /**
188
+ * `gasLimit = bumpGasLimit(ceil(gasUsed * 64 / 63))`, plus blob evaluation gas if a propose
189
+ * survived, capped at the L1 block gas limit.
190
+ */
191
+ private computeGasLimit(l1TxUtils: L1TxUtils, bundleGasUsed: bigint, blobEvaluationGas: bigint): bigint {
192
+ const gasUsedWithEip150 = (bundleGasUsed * 64n + 62n) / 63n;
193
+ const gasLimit = l1TxUtils.bumpGasLimit(gasUsedWithEip150) + blobEvaluationGas;
194
+ return gasLimit > MAX_L1_TX_LIMIT ? MAX_L1_TX_LIMIT : gasLimit;
195
+ }
196
+
197
+ /**
198
+ * eth_simulateV1 cannot carry blob sidecar data, so disable the rollup's on-chain blob check
199
+ * when a propose is in the bundle.
200
+ */
201
+ private buildStateOverrides(hasProposeAction: boolean): Promise<StateOverride> {
202
+ return buildSimulationOverridesStateOverride(
203
+ this.deps.rollupContract,
204
+ hasProposeAction ? { disableBlobCheck: true } : undefined,
205
+ );
206
+ }
207
+
208
+ private async simulateAndDecode(
209
+ l1TxUtils: L1TxUtils,
210
+ requests: RequestWithExpiry[],
211
+ simulateTimestamp: bigint,
212
+ stateOverrides: StateOverride,
213
+ ): Promise<SimulatePassResult> {
214
+ let simResult: Awaited<ReturnType<typeof Multicall3.simulateAggregate3>>;
215
+ try {
216
+ simResult = await Multicall3.simulateAggregate3(
217
+ requests.map(r => ({ to: r.request.to! as Hex, data: r.request.data! as Hex, abi: r.request.abi })),
218
+ l1TxUtils,
219
+ {
220
+ blockOverrides: { time: simulateTimestamp, gasLimit: MAX_L1_TX_LIMIT * 2n },
221
+ stateOverrides,
222
+ gas: MAX_L1_TX_LIMIT,
223
+ fallbackGasEstimate: MAX_L1_TX_LIMIT,
224
+ },
225
+ );
226
+ } catch (err) {
227
+ this.log.warn('Bundle simulate threw; treating as fallback', {
228
+ err: formatViemError(err),
229
+ actions: requests.map(r => r.action),
230
+ });
231
+ return { kind: 'fallback' };
232
+ }
233
+
234
+ if (simResult.kind === 'fallback') {
235
+ return { kind: 'fallback' };
236
+ }
237
+
238
+ const survivors: RequestWithExpiry[] = [];
239
+ const droppedRequests: DroppedRequest[] = [];
240
+ for (let i = 0; i < requests.length; i++) {
241
+ const entry = simResult.entries[i];
242
+ if (entry.success) {
243
+ survivors.push(requests[i]);
244
+ continue;
245
+ }
246
+ droppedRequests.push({
247
+ request: requests[i],
248
+ revertReason: entry.revertReason,
249
+ returnData: entry.returnData,
250
+ });
251
+ }
252
+ return { kind: 'decoded', survivors, droppedRequests, gasUsed: simResult.gasUsed };
253
+ }
254
+ }
@@ -7,7 +7,6 @@ import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
7
7
  import type { PublisherFilter, PublisherManager } from '@aztec/ethereum/publisher-manager';
8
8
  import { SlotNumber } from '@aztec/foundation/branded-types';
9
9
  import type { DateProvider } from '@aztec/foundation/timer';
10
- import type { SlashFactoryContract } from '@aztec/stdlib/l1-contracts';
11
10
  import type { TelemetryClient } from '@aztec/telemetry-client';
12
11
  import { NodeKeystoreAdapter } from '@aztec/validator-client';
13
12
 
@@ -40,7 +39,6 @@ export class SequencerPublisherFactory {
40
39
  epochCache: EpochCache;
41
40
  rollupContract: RollupContract;
42
41
  governanceProposerContract: GovernanceProposerContract;
43
- slashFactoryContract: SlashFactoryContract;
44
42
  nodeKeyStore: NodeKeystoreAdapter;
45
43
  logger?: Logger;
46
44
  },
@@ -104,7 +102,6 @@ export class SequencerPublisherFactory {
104
102
  epochCache: this.deps.epochCache,
105
103
  governanceProposerContract: this.deps.governanceProposerContract,
106
104
  slashingProposerContract,
107
- slashFactoryContract: this.deps.slashFactoryContract,
108
105
  dateProvider: this.deps.dateProvider,
109
106
  metrics: this.publisherMetrics,
110
107
  lastActions: this.lastActions,
@@ -117,8 +114,8 @@ export class SequencerPublisherFactory {
117
114
  };
118
115
  }
119
116
 
120
- /** Interrupts all publishers managed by this factory. Used during sequencer shutdown. */
121
- public interruptAll(): void {
122
- this.deps.publisherManager.interrupt();
117
+ /** Stops all publishers managed by this factory. Used during sequencer shutdown. */
118
+ public async stopAll(): Promise<void> {
119
+ await this.deps.publisherManager.stop();
123
120
  }
124
121
  }