@aztec/sequencer-client 0.0.1-commit.2f68f620 → 0.0.1-commit.3100065

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 (94) hide show
  1. package/README.md +27 -27
  2. package/dest/client/sequencer-client.d.ts +16 -3
  3. package/dest/client/sequencer-client.d.ts.map +1 -1
  4. package/dest/client/sequencer-client.js +17 -12
  5. package/dest/config.d.ts +6 -2
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +23 -14
  8. package/dest/global_variable_builder/fee_predictor.d.ts +1 -1
  9. package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -1
  10. package/dest/global_variable_builder/fee_predictor.js +11 -1
  11. package/dest/global_variable_builder/fee_provider.d.ts +1 -1
  12. package/dest/global_variable_builder/fee_provider.d.ts.map +1 -1
  13. package/dest/global_variable_builder/fee_provider.js +27 -5
  14. package/dest/global_variable_builder/global_builder.d.ts +3 -16
  15. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  16. package/dest/global_variable_builder/global_builder.js +2 -25
  17. package/dest/index.d.ts +2 -2
  18. package/dest/index.d.ts.map +1 -1
  19. package/dest/index.js +1 -1
  20. package/dest/publisher/config.d.ts +5 -1
  21. package/dest/publisher/config.d.ts.map +1 -1
  22. package/dest/publisher/config.js +11 -1
  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/sequencer-publisher.d.ts +17 -4
  27. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  28. package/dest/publisher/sequencer-publisher.js +119 -22
  29. package/dest/publisher/write_json.d.ts +11 -0
  30. package/dest/publisher/write_json.d.ts.map +1 -0
  31. package/dest/publisher/write_json.js +57 -0
  32. package/dest/sequencer/automine/automine_factory.d.ts +5 -3
  33. package/dest/sequencer/automine/automine_factory.d.ts.map +1 -1
  34. package/dest/sequencer/automine/automine_factory.js +2 -1
  35. package/dest/sequencer/automine/automine_sequencer.d.ts +43 -5
  36. package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -1
  37. package/dest/sequencer/automine/automine_sequencer.js +199 -18
  38. package/dest/sequencer/automine/index.d.ts +3 -0
  39. package/dest/sequencer/automine/index.d.ts.map +1 -0
  40. package/dest/sequencer/automine/index.js +2 -0
  41. package/dest/sequencer/checkpoint_proposal_job.d.ts +24 -16
  42. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  43. package/dest/sequencer/checkpoint_proposal_job.js +98 -90
  44. package/dest/sequencer/errors.d.ts +1 -8
  45. package/dest/sequencer/errors.d.ts.map +1 -1
  46. package/dest/sequencer/errors.js +0 -9
  47. package/dest/sequencer/events.d.ts +16 -5
  48. package/dest/sequencer/events.d.ts.map +1 -1
  49. package/dest/sequencer/index.d.ts +1 -3
  50. package/dest/sequencer/index.d.ts.map +1 -1
  51. package/dest/sequencer/index.js +0 -2
  52. package/dest/sequencer/requests_tracker.d.ts +22 -0
  53. package/dest/sequencer/requests_tracker.d.ts.map +1 -0
  54. package/dest/sequencer/requests_tracker.js +33 -0
  55. package/dest/sequencer/sequencer.d.ts +110 -36
  56. package/dest/sequencer/sequencer.d.ts.map +1 -1
  57. package/dest/sequencer/sequencer.js +329 -174
  58. package/dest/test/index.d.ts +3 -3
  59. package/dest/test/index.d.ts.map +1 -1
  60. package/dest/test/utils.d.ts +15 -1
  61. package/dest/test/utils.d.ts.map +1 -1
  62. package/dest/test/utils.js +18 -1
  63. package/package.json +28 -27
  64. package/src/client/sequencer-client.ts +20 -13
  65. package/src/config.ts +25 -12
  66. package/src/global_variable_builder/fee_predictor.ts +11 -1
  67. package/src/global_variable_builder/fee_provider.ts +27 -5
  68. package/src/global_variable_builder/global_builder.ts +2 -34
  69. package/src/index.ts +1 -10
  70. package/src/publisher/config.ts +22 -1
  71. package/src/publisher/l1_to_l2_messaging.ts +85 -0
  72. package/src/publisher/sequencer-publisher.ts +116 -23
  73. package/src/publisher/write_json.ts +78 -0
  74. package/src/sequencer/automine/README.md +18 -4
  75. package/src/sequencer/automine/automine_factory.ts +8 -1
  76. package/src/sequencer/automine/automine_sequencer.ts +221 -20
  77. package/src/sequencer/automine/index.ts +6 -0
  78. package/src/sequencer/checkpoint_proposal_job.ts +119 -100
  79. package/src/sequencer/errors.ts +0 -15
  80. package/src/sequencer/events.ts +16 -4
  81. package/src/sequencer/index.ts +0 -2
  82. package/src/sequencer/requests_tracker.ts +43 -0
  83. package/src/sequencer/sequencer.ts +360 -187
  84. package/src/test/index.ts +2 -2
  85. package/src/test/utils.ts +33 -0
  86. package/dest/sequencer/chain_state_overrides.d.ts +0 -61
  87. package/dest/sequencer/chain_state_overrides.d.ts.map +0 -1
  88. package/dest/sequencer/chain_state_overrides.js +0 -98
  89. package/dest/sequencer/timetable.d.ts +0 -98
  90. package/dest/sequencer/timetable.d.ts.map +0 -1
  91. package/dest/sequencer/timetable.js +0 -227
  92. package/src/sequencer/README.md +0 -243
  93. package/src/sequencer/chain_state_overrides.ts +0 -162
  94. package/src/sequencer/timetable.ts +0 -288
@@ -1,243 +0,0 @@
1
- # Sequencer Timing Model
2
-
3
- This document covers how the sequencer schedules its work within a slot. See the [package README](../../README.md) for the high-level architecture; this one focuses on the timing math and the state-machine deadlines.
4
-
5
- The model described here is for **proposer pipelining**, the only mode the production sequencer runs in (the proposer always builds for `slot + 1`). The deterministic single-sequencer `AutomineSequencer` used in some e2e tests publishes synchronously in-slot and does not use this timing model.
6
-
7
- ## Overview
8
-
9
- Block production runs on three nested clocks:
10
-
11
- - A **slot** is a fixed window (e.g. 72 s) during which one elected proposer is allowed to build.
12
- - A slot contains several equal-length **sub-slots** (e.g. 8 s). Each sub-slot owns the budget for one L2 block and has a deadline fixed relative to the slot start.
13
- - All blocks built within one slot make up one **checkpoint**, which is what eventually goes on L1.
14
-
15
- Under pipelining, the proposer for slot `N` does its building inside slot `N - 1` ("build slot"). Slot `N` ("target slot") is only used to mine the L1 transaction. This shifts work like this:
16
-
17
- | Phase | When |
18
- | ------------------------------ | -------------- |
19
- | Initialization | slot `N - 1` |
20
- | Block building | slot `N - 1` |
21
- | Checkpoint proposal broadcast | slot `N - 1` |
22
- | Last-block re-execution | slot `N - 1` |
23
- | Attestation collection | slot `N - 1` |
24
- | L1 submission | slot `N` |
25
-
26
- The wall-clock slot the sequencer is reasoning about ("build slot") and the slot the checkpoint commits to ("target slot") are always `N - 1` and `N` respectively.
27
-
28
- ## Sub-slots
29
-
30
- Each sub-slot has a fixed start time and a fixed deadline, both relative to the slot start:
31
-
32
- ```
33
- subSlotStart[k] = initializationOffset + (k - 1) * blockDuration
34
- subSlotDeadline[k] = initializationOffset + k * blockDuration
35
- ```
36
-
37
- with `k = 1, 2, ..., maxNumberOfBlocks`. Deadlines do **not** shift based on when the previous block finished. If a block finishes early, the sequencer waits for the next sub-slot to begin (so validators see a regular cadence). If it finishes late, the next block has correspondingly less time.
38
-
39
- `canStartNextBlock(secondsIntoSlot)` walks the sub-slot list and returns the first one with at least `minExecutionTime` left before its deadline. Sub-slots that no longer have enough headroom are skipped entirely.
40
-
41
- ### Number of sub-slots
42
-
43
- The maximum number of buildable blocks per slot is:
44
-
45
- ```
46
- timeReservedAtEnd = checkpointAssembleTime
47
- + 2 * p2pPropagationTime // proposal out + attestations back
48
- + blockDuration // last-block re-execution
49
-
50
- timeAvailableForBlocks = aztecSlotDuration
51
- - checkpointInitializationTime
52
- - timeReservedAtEnd
53
-
54
- maxNumberOfBlocks = floor(timeAvailableForBlocks / blockDuration)
55
- ```
56
-
57
- The reservation at the end of the slot is sized so that, on the happy path, attestations are in hand by the time the target slot starts. The enforced `COLLECTING_ATTESTATIONS` and `PUBLISHING_CHECKPOINT` deadlines are softer (see the deadline table below) and let a late attestation spill into the target slot. L1 publishing is **not** included in `timeReservedAtEnd` — that is paid for by the target slot.
58
-
59
- ### Cooldown after the last sub-slot
60
-
61
- All `maxNumberOfBlocks` sub-slots build a block. The cooldown lives in the `timeReservedAtEnd` window that follows the last sub-slot:
62
-
63
- - 1 × `checkpointAssembleTime` to assemble and sign the checkpoint,
64
- - 1 × `p2pPropagationTime` for the `CheckpointProposal` to reach the committee,
65
- - 1 × `blockDuration` for the committee to re-execute the last block,
66
- - 1 × `p2pPropagationTime` for attestations to come back.
67
-
68
- These four windows total `checkpointAssembleTime + blockDuration + 2 * p2pPropagationTime`, exactly the `timeReservedAtEnd` formula above. The block built in the last sub-slot is *not* broadcast as a regular `BlockProposal`; the proposer holds it as `blockPendingBroadcast` so it travels bundled inside the `CheckpointProposal`.
69
-
70
- ## Timing constants
71
-
72
- These constants come from `@aztec/stdlib/timetable` (see `stdlib/src/timetable/index.ts`). Some are fixed across the network, some are inputs from configuration.
73
-
74
- | Constant | Source | Typical value | Purpose |
75
- | --------------------------------- | --------------------------------------- | ------------- | ---------------------------------------------------- |
76
- | `aztecSlotDuration` | L1 rollup contract | 72 s | Length of one Aztec slot. |
77
- | `ethereumSlotDuration` | L1 rollup contract | 12 s | Length of one Ethereum slot. |
78
- | `blockDuration` | `blockDurationMs` config | 6–8 s | Sub-slot length. |
79
- | `checkpointInitializationTime` | constant (`CHECKPOINT_INITIALIZATION_TIME`) | 1 s | Estimated sync + proposer check time. |
80
- | `checkpointAssembleTime` | constant (`CHECKPOINT_ASSEMBLE_TIME`) | 1 s | Time to assemble and sign the checkpoint after the last block. |
81
- | `p2pPropagationTime` | `attestationPropagationTime` config | 2 s | One-way p2p estimate (proposals, attestations). |
82
- | `l1PublishingTime` | `l1PublishingTime` config | 12 s | Time reserved for the L1 tx to land. Used by the target slot, not the build slot. |
83
- | `minExecutionTime` | constant (`MIN_EXECUTION_TIME`) | 2 s | Minimum headroom to start a block. |
84
- | `initializationOffset` | `=checkpointInitializationTime` | 1 s | Where sub-slot 1 starts. |
85
-
86
- ## Deadlines
87
-
88
- `SequencerTimetable.getMaxAllowedTime(state)` returns the latest second-into-slot a given state is allowed to be entered. `assertTimeLeft()` throws `SequencerTooSlowError` if the slot has already advanced past that deadline. Sub-slot scheduling is measured against the build slot (`slotNow`); state assertions, however, are measured against whichever slot `setState` was called with — for the publishing path that is the target slot, which is why the publishing deadline is allowed to exceed `aztecSlotDuration`.
89
-
90
- | State | Max allowed time (seconds into build slot) |
91
- | --------------------------- | --------------------------------------------------------------------------- |
92
- | `PROPOSER_CHECK` | `initializeDeadline = aztecSlotDuration - (checkpointInitializationTime + 2*minExecutionTime)` |
93
- | `INITIALIZING_CHECKPOINT` | same as `PROPOSER_CHECK` |
94
- | `WAITING_FOR_TXS` | `initializeDeadline + checkpointInitializationTime` |
95
- | `CREATING_BLOCK` | same as `WAITING_FOR_TXS` |
96
- | `WAITING_UNTIL_NEXT_BLOCK` | same as `WAITING_FOR_TXS` |
97
- | `ASSEMBLING_CHECKPOINT` | `aztecSlotDuration + pipeliningAttestationGracePeriod` |
98
- | `COLLECTING_ATTESTATIONS` | same as `ASSEMBLING_CHECKPOINT` |
99
- | `PUBLISHING_CHECKPOINT` | `2 * aztecSlotDuration - ethereumSlotDuration` (extends into the target slot) |
100
-
101
- In production-like timing, `pipeliningAttestationGracePeriod` is zero, so `ASSEMBLING_CHECKPOINT` and
102
- `COLLECTING_ATTESTATIONS` must be *entered* before the build-slot boundary. Local networks with
103
- `l1PublishingTime < ethereumSlotDuration` can use the target-slot attestation window as grace while preserving the
104
- L1-geometry publishing cutoff. Once entered, attestation collection itself has its own
105
- `checkpointAttestationDeadline = 2 * aztecSlotDuration - ethereumSlotDuration`, so a late attestation arriving after
106
- the boundary is still accepted. The publishing deadline extends into the target slot because that is when the L1 tx is
107
- actually submitted.
108
-
109
- ## Example: 72 s slot, 8 s sub-slots
110
-
111
- With typical pipelining values:
112
-
113
- ```
114
- checkpointInitializationTime = 1s
115
- blockDuration = 8s
116
- checkpointAssembleTime = 1s
117
- p2pPropagationTime = 2s
118
- l1PublishingTime = 12s
119
-
120
- timeReservedAtEnd = 1 + 2*2 + 8 = 13s
121
- timeAvailableForBlocks = 72 - 1 - 13 = 58s
122
- maxNumberOfBlocks = floor(58 / 8) = 7
123
- ```
124
-
125
- Seven sub-slots, all of which build a block:
126
-
127
- ```
128
- Sub-slot 1: starts 1s, deadline 9s (Block 1)
129
- Sub-slot 2: starts 9s, deadline 17s (Block 2)
130
- Sub-slot 3: starts 17s, deadline 25s (Block 3)
131
- Sub-slot 4: starts 25s, deadline 33s (Block 4)
132
- Sub-slot 5: starts 33s, deadline 41s (Block 5)
133
- Sub-slot 6: starts 41s, deadline 49s (Block 6)
134
- Sub-slot 7: starts 49s, deadline 57s (Block 7 — held for the checkpoint proposal)
135
-
136
- 57s: Block 7 done, ASSEMBLING_CHECKPOINT (1s)
137
- 58s: CheckpointProposal broadcast
138
- 60s: Committee receives proposal (+2s p2p)
139
- 60-68s: Committee re-executes Block 7
140
- 68s: Committee sends attestations
141
- 70s: Proposer has the quorum (+2s p2p)
142
-
143
- 70-72s: Slack
144
- 72s: Build slot ends → L1 submission starts (target slot begins)
145
- 84s: L1 tx mined inside the target slot (+12s)
146
- ```
147
-
148
- ## Parallel execution: proposer vs committee
149
-
150
- While the proposer builds block `k+1`, the committee is re-executing block `k`. The pipeline keeps both sides busy except for the cooldown sub-slot.
151
-
152
- ```
153
- Time | Proposer | Committee
154
- -----|------------------------------|--------------------------------------
155
- 1s | Start Block 1 | (idle)
156
- 9s | Finish Block 1, broadcast |
157
- 9s | Start Block 2 |
158
- 11s | | Receive Block 1 (9s + 2s)
159
- | | Re-execute Block 1
160
- 17s | Finish Block 2, broadcast |
161
- 17s | Start Block 3 |
162
- 19s | | Finish Block 1 (11s + 8s)
163
- | | Receive Block 2 (17s + 2s)
164
- | | Re-execute Block 2
165
- ...
166
- 49s | Finish Block 6, broadcast |
167
- 49s | Start Block 7 (last) |
168
- 51s | | Receive Block 6 (49s + 2s)
169
- | | Re-execute Block 6
170
- 57s | Finish Block 7 (held) |
171
- | ASSEMBLING_CHECKPOINT (1s) |
172
- 58s | Broadcast CheckpointProposal |
173
- 59s | | Finish Block 6 (51s + 8s)
174
- 60s | | Receive Block 7 + Checkpoint (58s + 2s)
175
- | | Re-execute Block 7
176
- 68s | | Send attestations (60s + 8s)
177
- 70s | Receive attestations |
178
- 70-72s| Slack |
179
- 72s | L1 tx submitted |
180
- 84s | L1 tx mined |
181
- ```
182
-
183
- **Observations**:
184
-
185
- - Validators always lag the proposer by ~2 s (one p2p hop).
186
- - For the last block there is no `k+1` to build alongside; once the proposer broadcasts the `CheckpointProposal`, it just waits while the committee re-executes.
187
- - L1 publishing happens entirely inside the next slot and does not steal time from block building.
188
-
189
- ## Handling timing variations
190
-
191
- ### Fast initialization (0.5 s instead of 1 s)
192
-
193
- Sub-slot 1's deadline is still 9 s, so Block 1 gets a 0.5 s bonus before hitting its deadline. No structural change.
194
-
195
- ### Slow initialization (2 s instead of 1 s)
196
-
197
- Block 1 has 7 s of build time instead of 8 s. Still well above `minExecutionTime`, so the block still gets built. No sub-slots are skipped.
198
-
199
- ### Very slow initialization (8 s)
200
-
201
- Sub-slot 1's deadline (9 s) is closer than `minExecutionTime` (2 s), so it is skipped entirely. The first attempted block runs in sub-slot 2 with the usual budget. The checkpoint will have one fewer block.
202
-
203
- ### Block takes longer than its budget
204
-
205
- `CheckpointBuilder` enforces the deadline by stopping public-tx execution; in practice a block can only overrun by the time it takes to finalize the block (typically < 1 s). The next sub-slot starts as scheduled but with proportionally less headroom. If that headroom drops below `minExecutionTime`, the next sub-slot is skipped.
206
-
207
- ### Block finishes early
208
-
209
- The sequencer transitions to `WAITING_UNTIL_NEXT_BLOCK` and sleeps until the next sub-slot start. This keeps the cadence regular and gives validators predictable arrival times for re-execution.
210
-
211
- ### Block proposal returns insufficient txs
212
-
213
- The current sub-slot is dropped without committing anything. The loop retries on the next sub-slot. If `buildCheckpointIfEmpty` is true, the last sub-slot is forced through with whatever is available, including zero txs.
214
-
215
- ### Build slot ends before attestations arrive
216
-
217
- `assertTimeLeft` will reject `PUBLISHING_CHECKPOINT` if the attestation deadline has passed; the slot is abandoned, and
218
- `checkpoint-publish-failed` is emitted. The `PUBLISHING_CHECKPOINT` deadline allows spillover into the target slot
219
- (`2 * aztecSlotDuration - ethereumSlotDuration`) precisely to absorb a small overrun.
220
-
221
- ### Pipelined parent fails on L1
222
-
223
- Before submitting, the job calls `waitForValidParentCheckpointOnL1`. If the parent we built on top of did not land cleanly (wrong archive, missing attestations, etc.) the job discards its checkpoint, emits `pipelined-checkpoint-discarded`, and enqueues an invalidation for the parent so the next proposer doesn't get stuck on the same bad ancestor.
224
-
225
- ## Configuration constraints
226
-
227
- `initializeDeadline` must be positive, so `aztecSlotDuration > checkpointInitializationTime + 2 * minExecutionTime`. With defaults that lower bound is 5 s, far below any realistic slot length.
228
-
229
- For multi-block production to make sense, `maxNumberOfBlocks ≥ 2`:
230
-
231
- ```
232
- aztecSlotDuration ≥ checkpointInitializationTime
233
- + 2 * blockDuration // two blocks
234
- + checkpointAssembleTime
235
- + 2 * p2pPropagationTime
236
- + blockDuration // last-block re-execution window
237
- ```
238
-
239
- Block duration should be ≥ `minExecutionTime` (otherwise no sub-slot ever has enough headroom). `p2pPropagationTime` should be measured against the deployment's actual p2p latency: it directly determines how much of each slot is spent on the cooldown.
240
-
241
- `l1PublishingTime` should fit inside the Ethereum slot the target slot maps to. The default of 12 s lines up with one
242
- Ethereum slot; fast local networks may reduce it to use the target-slot attestation window as assembly and attestation
243
- grace.
@@ -1,162 +0,0 @@
1
- import { RollupContract, SimulationOverridesBuilder, type SimulationOverridesPlan } from '@aztec/ethereum/contracts';
2
- import { CheckpointNumber } from '@aztec/foundation/branded-types';
3
- import type { Logger } from '@aztec/foundation/log';
4
- import { type ProposedCheckpointData, computeCheckpointPayloadDigest } from '@aztec/stdlib/checkpoint';
5
- import type { CoordinationSignatureContext } from '@aztec/stdlib/p2p';
6
-
7
- type CheckpointSimulationOverridesPlanInput = {
8
- /** Target rollup contract. */
9
- rollup: RollupContract;
10
- /** Checkpoint number to be proposed. */
11
- checkpointNumber: CheckpointNumber;
12
- /** Logger instance. */
13
- log: Logger;
14
- /**
15
- * The proposed parent checkpoint when pipelining. Its `checkpointNumber` must equal
16
- * `checkpointNumber - 1`; the helper enforces this. Mutually exclusive with
17
- * `invalidateToPendingCheckpointNumber`.
18
- */
19
- proposedCheckpointData?: ProposedCheckpointData;
20
- /**
21
- * The pending checkpoint number we'll end up at after invalidation lands. Mutually exclusive
22
- * with `proposedCheckpointData`.
23
- */
24
- invalidateToPendingCheckpointNumber?: CheckpointNumber;
25
- /**
26
- * The real on-chain pending checkpoint number (typically `syncedTo.checkpointedCheckpointNumber`).
27
- * Used as the snapshot we pin both `pending` and `proven` to avoid prunes in simulation.
28
- */
29
- checkpointedCheckpointNumber: CheckpointNumber;
30
- /**
31
- * Chain-level consensus signature context. Used to recompute the parent's `payloadDigest` for the
32
- * pipelined simulation override so it matches what `propose` will write into `tempCheckpointLogs[parent]`
33
- * once the parent lands.
34
- */
35
- signatureContext: CoordinationSignatureContext;
36
- };
37
-
38
- /**
39
- * Builds the SimulationOverridesPlan describing the simulated L1 rollup state for a checkpoint's
40
- * enqueue-time simulations: `canProposeAt` (in Sequencer.doWork) and the propose-related sims
41
- * (validateBlockHeader, simulateProposeTx). The plan reflects "as if our pipelined parent
42
- * checkpoint has landed and any required invalidation has executed" — the gap that needs to be
43
- * bridged at enqueue time.
44
- *
45
- * Pipelining (`proposedCheckpointData`) and invalidation (`invalidateToPendingCheckpointNumber`)
46
- * are mutually exclusive; passing both throws.
47
- */
48
- export async function buildCheckpointSimulationOverridesPlan(
49
- input: CheckpointSimulationOverridesPlanInput,
50
- ): Promise<SimulationOverridesPlan | undefined> {
51
- if (input.proposedCheckpointData && input.invalidateToPendingCheckpointNumber !== undefined) {
52
- throw new Error(
53
- 'Error in buildCheckpointSimulationOverridesPlan: proposedCheckpointData and invalidateToPendingCheckpointNumber are mutually exclusive',
54
- );
55
- }
56
-
57
- const builder = new SimulationOverridesBuilder();
58
- const pendingCheckpointNumber = derivePendingCheckpointNumber(input);
59
-
60
- // Override the latest checkpoint number when invalidating or pipelining, so our checkpoint
61
- // follows from it. We also override the proven chain tip so we dont need to worry about
62
- // prunes kicking in that would break out simulation if there's a prune pending. We always
63
- // assume that a proof will land in time. If we don't have a pending checkpoint number to force,
64
- // we still set both tips to the current checkpoint number to avoid the prune trigger.
65
- const overridenChainTip = pendingCheckpointNumber ?? input.checkpointedCheckpointNumber;
66
- builder.withChainTips({ pending: overridenChainTip, proven: overridenChainTip });
67
-
68
- if (input.proposedCheckpointData) {
69
- const { header, archive, checkpointOutHash, feeAssetPriceModifier } = input.proposedCheckpointData;
70
- builder.withPendingArchive(archive.root);
71
- // Override every locally-derivable `tempCheckpointLogs[parent]` field that L1 will eventually
72
- // write. `slotNumber` is load-bearing for `STFLib.canPruneAtTime`: without it the cell reads
73
- // slotNumber 0, the contract treats the pending tip as belonging to an expired epoch, and
74
- // `getEffectivePendingCheckpointNumber` silently collapses pending back to proven — producing
75
- // a spurious `Rollup__InvalidArchive` against the on-chain genesis archive. The other fields
76
- // (headerHash, outHash, payloadDigest) are not strictly load-bearing for `canProposeAt` /
77
- // `validateBlockHeader`, but mirroring the full cell keeps the simulation byte-faithful with
78
- // what the actual `propose()` send will observe, which is a defense against future reads
79
- // taking dependencies on them.
80
- builder.withPendingTempCheckpointLogFields({
81
- headerHash: header.hash(),
82
- outHash: checkpointOutHash,
83
- slotNumber: header.slotNumber,
84
- payloadDigest: computeCheckpointPayloadDigest({
85
- header,
86
- archiveRoot: archive.root,
87
- feeAssetPriceModifier,
88
- signatureContext: input.signatureContext,
89
- }),
90
- });
91
-
92
- const feeHeader = await computePipelinedParentFeeHeader({
93
- checkpointNumber: input.checkpointNumber,
94
- proposedCheckpointData: input.proposedCheckpointData,
95
- rollup: input.rollup,
96
- log: input.log,
97
- });
98
- if (feeHeader) {
99
- builder.withPendingFeeHeader(feeHeader);
100
- }
101
- }
102
-
103
- return builder.build();
104
- }
105
-
106
- function derivePendingCheckpointNumber(input: CheckpointSimulationOverridesPlanInput): CheckpointNumber | undefined {
107
- if (input.invalidateToPendingCheckpointNumber !== undefined) {
108
- return input.invalidateToPendingCheckpointNumber;
109
- }
110
- if (!input.proposedCheckpointData) {
111
- return undefined;
112
- }
113
- if (input.checkpointNumber < 1) {
114
- throw new Error(`Cannot build simulation override for checkpoint ${input.checkpointNumber}: no parent exists`);
115
- }
116
- const expectedParent = CheckpointNumber(input.checkpointNumber - 1);
117
- if (input.proposedCheckpointData.checkpointNumber !== expectedParent) {
118
- throw new Error(
119
- `Cannot build simulation override for checkpoint ${input.checkpointNumber}: proposedCheckpointData.checkpointNumber (${input.proposedCheckpointData.checkpointNumber}) does not match expected parent ${expectedParent}`,
120
- );
121
- }
122
- return expectedParent;
123
- }
124
-
125
- type PipelinedParentFeeHeaderInput = {
126
- checkpointNumber: CheckpointNumber;
127
- proposedCheckpointData: ProposedCheckpointData;
128
- rollup: RollupContract;
129
- log: Logger;
130
- };
131
-
132
- /**
133
- * Derives the pending parent fee header used during pipelined proposal simulation. Returns
134
- * `undefined` only when no grandparent exists (i.e. the proposed parent is the genesis
135
- * checkpoint); all other failure modes (missing grandparent state, missing fee header, RPC
136
- * errors) throw so callers don't silently desync the fee-header override.
137
- */
138
- export async function computePipelinedParentFeeHeader(input: PipelinedParentFeeHeaderInput) {
139
- if (input.checkpointNumber < 2) {
140
- return undefined;
141
- }
142
-
143
- const grandparentCheckpointNumber = CheckpointNumber(input.checkpointNumber - 2);
144
-
145
- const [grandparentCheckpoint, manaTarget] = await Promise.all([
146
- input.rollup.getCheckpoint(grandparentCheckpointNumber),
147
- input.rollup.getManaTarget(),
148
- ]);
149
-
150
- if (!grandparentCheckpoint?.feeHeader) {
151
- throw new Error(
152
- `Grandparent checkpoint or feeHeader missing for checkpoint ${grandparentCheckpointNumber.toString()}`,
153
- );
154
- }
155
-
156
- return RollupContract.computeChildFeeHeader(
157
- grandparentCheckpoint.feeHeader,
158
- input.proposedCheckpointData.totalManaUsed,
159
- input.proposedCheckpointData.feeAssetPriceModifier,
160
- manaTarget,
161
- );
162
- }