@aztec-labs/sequencer-client 6.0.0-nightly.20260829

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 (165) hide show
  1. package/README.md +307 -0
  2. package/dest/client/index.d.ts +2 -0
  3. package/dest/client/index.d.ts.map +1 -0
  4. package/dest/client/index.js +1 -0
  5. package/dest/client/sequencer-client.d.ts +94 -0
  6. package/dest/client/sequencer-client.d.ts.map +1 -0
  7. package/dest/client/sequencer-client.js +177 -0
  8. package/dest/config.d.ts +56 -0
  9. package/dest/config.d.ts.map +1 -0
  10. package/dest/config.js +251 -0
  11. package/dest/global_variable_builder/fee_predictor.d.ts +49 -0
  12. package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
  13. package/dest/global_variable_builder/fee_predictor.js +127 -0
  14. package/dest/global_variable_builder/fee_provider.d.ts +28 -0
  15. package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
  16. package/dest/global_variable_builder/fee_provider.js +87 -0
  17. package/dest/global_variable_builder/global_builder.d.ts +28 -0
  18. package/dest/global_variable_builder/global_builder.d.ts.map +1 -0
  19. package/dest/global_variable_builder/global_builder.js +40 -0
  20. package/dest/global_variable_builder/index.d.ts +4 -0
  21. package/dest/global_variable_builder/index.d.ts.map +1 -0
  22. package/dest/global_variable_builder/index.js +3 -0
  23. package/dest/index.d.ts +7 -0
  24. package/dest/index.d.ts.map +1 -0
  25. package/dest/index.js +8 -0
  26. package/dest/publisher/config.d.ts +68 -0
  27. package/dest/publisher/config.d.ts.map +1 -0
  28. package/dest/publisher/config.js +137 -0
  29. package/dest/publisher/index.d.ts +5 -0
  30. package/dest/publisher/index.d.ts.map +1 -0
  31. package/dest/publisher/index.js +4 -0
  32. package/dest/publisher/l1_to_l2_messaging.d.ts +21 -0
  33. package/dest/publisher/l1_to_l2_messaging.d.ts.map +1 -0
  34. package/dest/publisher/l1_to_l2_messaging.js +70 -0
  35. package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
  36. package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
  37. package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
  38. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +101 -0
  39. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
  40. package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +68 -0
  41. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
  42. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
  43. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +36 -0
  44. package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
  45. package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
  46. package/dest/publisher/l1_tx_failed_store/index.js +3 -0
  47. package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
  48. package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
  49. package/dest/publisher/sequencer-bundle-simulator.js +198 -0
  50. package/dest/publisher/sequencer-publisher-factory.d.ts +50 -0
  51. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -0
  52. package/dest/publisher/sequencer-publisher-factory.js +75 -0
  53. package/dest/publisher/sequencer-publisher-metrics.d.ts +26 -0
  54. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -0
  55. package/dest/publisher/sequencer-publisher-metrics.js +101 -0
  56. package/dest/publisher/sequencer-publisher.d.ts +254 -0
  57. package/dest/publisher/sequencer-publisher.d.ts.map +1 -0
  58. package/dest/publisher/sequencer-publisher.js +1784 -0
  59. package/dest/publisher/write_json.d.ts +11 -0
  60. package/dest/publisher/write_json.d.ts.map +1 -0
  61. package/dest/publisher/write_json.js +57 -0
  62. package/dest/sequencer/automine/automine_factory.d.ts +56 -0
  63. package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
  64. package/dest/sequencer/automine/automine_factory.js +85 -0
  65. package/dest/sequencer/automine/automine_sequencer.d.ts +189 -0
  66. package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
  67. package/dest/sequencer/automine/automine_sequencer.js +732 -0
  68. package/dest/sequencer/automine/index.d.ts +3 -0
  69. package/dest/sequencer/automine/index.d.ts.map +1 -0
  70. package/dest/sequencer/automine/index.js +2 -0
  71. package/dest/sequencer/checkpoint_proposal_job.d.ts +169 -0
  72. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  73. package/dest/sequencer/checkpoint_proposal_job.js +1961 -0
  74. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
  75. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
  76. package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
  77. package/dest/sequencer/checkpoint_voter.d.ts +34 -0
  78. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  79. package/dest/sequencer/checkpoint_voter.js +106 -0
  80. package/dest/sequencer/config.d.ts +8 -0
  81. package/dest/sequencer/config.d.ts.map +1 -0
  82. package/dest/sequencer/config.js +1 -0
  83. package/dest/sequencer/errors.d.ts +11 -0
  84. package/dest/sequencer/errors.d.ts.map +1 -0
  85. package/dest/sequencer/errors.js +15 -0
  86. package/dest/sequencer/events.d.ts +103 -0
  87. package/dest/sequencer/events.d.ts.map +1 -0
  88. package/dest/sequencer/events.js +1 -0
  89. package/dest/sequencer/inbox_bucket_selector.d.ts +88 -0
  90. package/dest/sequencer/inbox_bucket_selector.d.ts.map +1 -0
  91. package/dest/sequencer/inbox_bucket_selector.js +80 -0
  92. package/dest/sequencer/index.d.ts +6 -0
  93. package/dest/sequencer/index.d.ts.map +1 -0
  94. package/dest/sequencer/index.js +5 -0
  95. package/dest/sequencer/metrics.d.ts +75 -0
  96. package/dest/sequencer/metrics.d.ts.map +1 -0
  97. package/dest/sequencer/metrics.js +343 -0
  98. package/dest/sequencer/missing_committee.d.ts +72 -0
  99. package/dest/sequencer/missing_committee.d.ts.map +1 -0
  100. package/dest/sequencer/missing_committee.js +139 -0
  101. package/dest/sequencer/requests_tracker.d.ts +22 -0
  102. package/dest/sequencer/requests_tracker.d.ts.map +1 -0
  103. package/dest/sequencer/requests_tracker.js +33 -0
  104. package/dest/sequencer/sequencer.d.ts +326 -0
  105. package/dest/sequencer/sequencer.d.ts.map +1 -0
  106. package/dest/sequencer/sequencer.js +1495 -0
  107. package/dest/sequencer/types.d.ts +3 -0
  108. package/dest/sequencer/types.d.ts.map +1 -0
  109. package/dest/sequencer/types.js +1 -0
  110. package/dest/sequencer/utils.d.ts +30 -0
  111. package/dest/sequencer/utils.d.ts.map +1 -0
  112. package/dest/sequencer/utils.js +18 -0
  113. package/dest/test/index.d.ts +23 -0
  114. package/dest/test/index.d.ts.map +1 -0
  115. package/dest/test/index.js +6 -0
  116. package/dest/test/mock_checkpoint_builder.d.ts +95 -0
  117. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  118. package/dest/test/mock_checkpoint_builder.js +230 -0
  119. package/dest/test/utils.d.ts +67 -0
  120. package/dest/test/utils.d.ts.map +1 -0
  121. package/dest/test/utils.js +121 -0
  122. package/package.json +118 -0
  123. package/src/client/index.ts +1 -0
  124. package/src/client/sequencer-client.ts +281 -0
  125. package/src/config.ts +309 -0
  126. package/src/global_variable_builder/README.md +44 -0
  127. package/src/global_variable_builder/fee_predictor.ts +176 -0
  128. package/src/global_variable_builder/fee_provider.ts +104 -0
  129. package/src/global_variable_builder/global_builder.ts +68 -0
  130. package/src/global_variable_builder/index.ts +3 -0
  131. package/src/index.ts +15 -0
  132. package/src/publisher/config.ts +220 -0
  133. package/src/publisher/index.ts +8 -0
  134. package/src/publisher/l1_to_l2_messaging.ts +85 -0
  135. package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
  136. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +166 -0
  137. package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +47 -0
  138. package/src/publisher/l1_tx_failed_store/index.ts +3 -0
  139. package/src/publisher/sequencer-bundle-simulator.ts +253 -0
  140. package/src/publisher/sequencer-publisher-factory.ts +121 -0
  141. package/src/publisher/sequencer-publisher-metrics.ts +145 -0
  142. package/src/publisher/sequencer-publisher.ts +1719 -0
  143. package/src/publisher/write_json.ts +77 -0
  144. package/src/sequencer/README.md +243 -0
  145. package/src/sequencer/automine/README.md +60 -0
  146. package/src/sequencer/automine/automine_factory.ts +156 -0
  147. package/src/sequencer/automine/automine_sequencer.ts +841 -0
  148. package/src/sequencer/automine/index.ts +6 -0
  149. package/src/sequencer/checkpoint_proposal_job.ts +1889 -0
  150. package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
  151. package/src/sequencer/checkpoint_voter.ts +118 -0
  152. package/src/sequencer/config.ts +9 -0
  153. package/src/sequencer/errors.ts +21 -0
  154. package/src/sequencer/events.ts +93 -0
  155. package/src/sequencer/inbox_bucket_selector.ts +160 -0
  156. package/src/sequencer/index.ts +5 -0
  157. package/src/sequencer/metrics.ts +463 -0
  158. package/src/sequencer/missing_committee.ts +192 -0
  159. package/src/sequencer/requests_tracker.ts +43 -0
  160. package/src/sequencer/sequencer.ts +1401 -0
  161. package/src/sequencer/types.ts +6 -0
  162. package/src/sequencer/utils.ts +42 -0
  163. package/src/test/index.ts +26 -0
  164. package/src/test/mock_checkpoint_builder.ts +324 -0
  165. package/src/test/utils.ts +215 -0
@@ -0,0 +1,77 @@
1
+ import { BatchedBlob, Blob, getEthBlobEvaluationInputs, getPrefixedEthBlobCommitments } from '@aztec-labs/blob-lib';
2
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
3
+ import { EthAddress } from '@aztec-labs/foundation/eth-address';
4
+ import { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
5
+ import { L2Block } from '@aztec-labs/stdlib/block';
6
+ import { CheckpointHeader } from '@aztec-labs/stdlib/rollup';
7
+ import { writeFile } from 'fs/promises';
8
+
9
+ const AZTEC_GENERATE_TEST_DATA = !!process.env.AZTEC_GENERATE_TEST_DATA;
10
+
11
+ /**
12
+ * Creates a json object that can be used to test the solidity contract.
13
+ * The json object must be put into
14
+ */
15
+ export async function writeJson(
16
+ fileName: string,
17
+ checkpointHeader: CheckpointHeader,
18
+ block: L2Block,
19
+ l1ToL2Content: Fr[],
20
+ blobs: Blob[],
21
+ batchedBlob: BatchedBlob,
22
+ recipientAddress: AztecAddress,
23
+ deployerAddress: `0x${string}`,
24
+ ): Promise<void> {
25
+ if (!AZTEC_GENERATE_TEST_DATA) {
26
+ return;
27
+ }
28
+ // Path relative to the package.json in the end-to-end folder
29
+ const path = `../../l1-contracts/test/fixtures/${fileName}.json`;
30
+
31
+ const asHex = (value: Fr | Buffer | EthAddress | AztecAddress, size = 64) => {
32
+ const buffer = Buffer.isBuffer(value) ? value : value.toBuffer();
33
+ return `0x${buffer.toString('hex').padStart(size, '0')}`;
34
+ };
35
+
36
+ const jsonObject = {
37
+ populate: {
38
+ l1ToL2Content: l1ToL2Content.map(value => asHex(value)),
39
+ recipient: asHex(recipientAddress.toField()),
40
+ sender: deployerAddress,
41
+ },
42
+ messages: {
43
+ l2ToL1Messages: block.body.txEffects.flatMap(txEffect => txEffect.l2ToL1Msgs).map(value => asHex(value)),
44
+ },
45
+ checkpoint: {
46
+ // The json formatting in forge is a bit brittle, so we convert Fr to a number in the few values below.
47
+ // This should not be a problem for testing as long as the values are not larger than u32.
48
+ archive: asHex(block.archive.root),
49
+ blobCommitments: getPrefixedEthBlobCommitments(blobs),
50
+ batchedBlobInputs: getEthBlobEvaluationInputs(batchedBlob),
51
+ checkpointNumber: block.number,
52
+ body: `0x${block.body.toBuffer().toString('hex')}`,
53
+ header: {
54
+ lastArchiveRoot: asHex(checkpointHeader.lastArchiveRoot),
55
+ blockHeadersHash: asHex(checkpointHeader.blockHeadersHash),
56
+ blobsHash: asHex(checkpointHeader.blobsHash),
57
+ inboxRollingHash: asHex(checkpointHeader.inboxRollingHash),
58
+ outHash: asHex(checkpointHeader.epochOutHash),
59
+ slotNumber: Number(checkpointHeader.slotNumber),
60
+ timestamp: Number(checkpointHeader.timestamp),
61
+ coinbase: asHex(checkpointHeader.coinbase, 40),
62
+ feeRecipient: asHex(checkpointHeader.feeRecipient),
63
+ gasFees: {
64
+ feePerDaGas: Number(checkpointHeader.gasFees.feePerDaGas),
65
+ feePerL2Gas: Number(checkpointHeader.gasFees.feePerL2Gas),
66
+ },
67
+ totalManaUsed: checkpointHeader.totalManaUsed.toNumber(),
68
+ accumulatedFees: checkpointHeader.accumulatedFees.toNumber(),
69
+ },
70
+ headerHash: asHex(checkpointHeader.hash()),
71
+ numTxs: block.body.txEffects.length,
72
+ },
73
+ };
74
+
75
+ const output = JSON.stringify(jsonObject, null, 2);
76
+ await writeFile(path, output, 'utf8');
77
+ }
@@ -0,0 +1,243 @@
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-labs/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.
@@ -0,0 +1,60 @@
1
+ # AutomineSequencer
2
+
3
+ A minimal, deterministic, queue-driven sequencer for e2e tests that do not exercise block-building or consensus mechanics (e.g. `e2e_token`, `e2e_amm`, `e2e_authwit`).
4
+
5
+ ## When to use it
6
+
7
+ Use `AutomineSequencer` (via `AUTOMINE_E2E_OPTS`) for single-sequencer tests that care about contract logic, not about proposer selection, attestations, pipelining, or multi-validator coordination. It bypasses all of that machinery.
8
+
9
+ Use the production `Sequencer` (via `PIPELINING_SETUP_OPTS` or the default) for tests that explicitly exercise consensus, validator rotation, P2P gossip, slashing, or multi-node behavior.
10
+
11
+ **Requirement**: the deployed rollup must have `aztecTargetCommitteeSize == 0`. This causes `Rollup.verifyProposer` / `verifyAttestations` on L1 to short-circuit and accept an empty `CommitteeAttestationsAndSigners`, which is what `AutomineSequencer` always sends.
12
+
13
+ ## What it omits
14
+
15
+ Compared to the production `Sequencer`:
16
+
17
+ - No proposer-turn check (single sequencer, always proposes).
18
+ - No sync check, no pipelining, no timetable enforcement.
19
+ - No validator orchestration, attestation collection, or P2P proposal gossip.
20
+ - No slashing, no governance votes, no `SequencerEvents`.
21
+
22
+ Consumers (archiver, world-state) observe L1 and the archiver tip directly rather than listening for sequencer events.
23
+
24
+ ## Serial-queue invariant
25
+
26
+ Every operation — mempool-driven block builds, explicit empty-block builds, time warps, reorgs, and synthetic epoch proving — is serialized through a single `SerialQueue`. They never interleave.
27
+
28
+ Public entry points:
29
+
30
+ | Method | Description |
31
+ | --- | --- |
32
+ | `buildIfPending()` | Enqueues a mempool-driven build. Coalesces bursts into one job. |
33
+ | `buildEmptyBlock()` | Enqueues a forced empty-block build. |
34
+ | `warpTo(ts)` / `warpBy(delta)` | Advances L1 time to a slot boundary. |
35
+ | `prove(upToCheckpoint?)` | Synthetically proves epochs up to a checkpoint (default: the latest checkpointed): writes the epoch out hashes into the L1 Outbox so L2-to-L1 messages become consumable, then advances the proven tip. No real proof. Clamps to the checkpointed tip and no-ops when already proven. |
36
+ | `revertToCheckpoint(n)` | Rolls L1 back to the block that published checkpoint `n`, then resets archiver, world-state, and P2P pool. |
37
+ | `syncPoint()` | Awaits the queue reaching idle. |
38
+
39
+ ## Time control
40
+
41
+ The AutomineSequencer owns L1 time in the local network (replacing the deleted `AnvilTestWatcher`). It builds and publishes each checkpoint at the next aztec-slot boundary, and `warpTo` / `warpBy` advance the clock by publishing an empty checkpoint at the target slot. Before every build, warp, and prove it reconciles the injected `TestDateProvider` to the latest *mined* L1 timestamp, so node-side consumers of `dateProvider.now()` stay aligned with L1 even when an unrelated L1 tx mines a block between our builds. It never advances the clock to the pending, un-mined timestamp.
42
+
43
+ ## Publish-failure recovery
44
+
45
+ A failed propose mines no checkpoint on L1 (it reverts inside the multicall or is never sent), so recovery is purely local — there is **no L1 reorg**. The optimistic archiver insert (the proposed block plus its proposed checkpoint) is rolled back via `archiver.removeUncheckpointedBlocksAfter`, which removes the uncheckpointed block and evicts the proposed checkpoint that referenced it. `p2pClient.sync()` then observes the lowered proposed tip and returns the block's txs to the pending pool, `worldState.syncImmediate()` drops any applied effects, and the L1 nonce is reset. The build is not retried inline; the mempool poller re-enqueues one once the txs are back in the pool.
46
+
47
+ ## Entry points
48
+
49
+ **Factory** — `createAutomineSequencer` in `automine_factory.ts` wires up all dependencies (publisher manager, keystore, cheat codes, etc.), starts the `PublisherManager`, and returns an unstarted `AutomineSequencer`. The caller (`AztecNodeService.createAndSync` in `aztec-node/src/aztec-node/server.ts`) invokes `AutomineSequencer.start()` separately. It is called by the full node when `aztecTargetCommitteeSize == 0`.
50
+
51
+ **Test fixture** — `AUTOMINE_E2E_OPTS` in `end-to-end/src/fixtures/fixtures.ts` is the test-side entry point. Pass it to `setup()` to get a node + `AutomineSequencer` instead of the production sequencer stack.
52
+
53
+ ## Epoch proving
54
+
55
+ There is no real prover in the automine setup, so epochs are settled synthetically: the epoch out hash is written into the L1 Outbox via cheat codes and the rollup's proven tip is advanced — the local-network equivalent of an epoch proof landing on L1. The grouping/out-hash logic lives in the shared `settleEpochOutbox` helper in `@aztec-labs/prover-client/test`, used by both proving drivers below.
56
+
57
+ Who drives proving depends on the `automineEnableProveEpoch` config flag:
58
+
59
+ - **Local network / sandbox** (`automineEnableProveEpoch: true`): the AutomineSequencer runs an auto-prove loop that calls `prove()` as checkpoints land, through the same serial queue as its builds. This replaces the standalone `EpochTestSettler`, which used to race the build loop. The loop also reconciles the clock on each tick.
60
+ - **e2e tests** (`AUTOMINE_E2E_OPTS`, flag off): proving is manual so tests stay deterministic. Cross-epoch tests advance the proven anchor explicitly via `node.prove(...)`, `cheatCodes.rollup.markAsProven(...)`, or a hand-driven `EpochTestSettler`. See `e2e_pruned_blocks.test.ts` and `e2e_epochs/epochs_partial_proof_multi_root.test.ts` for real examples.
@@ -0,0 +1,156 @@
1
+ import type { Archiver } from '@aztec-labs/archiver';
2
+ import type { BlobClientInterface } from '@aztec-labs/blob-client/client';
3
+ import type { EpochCache } from '@aztec-labs/epoch-cache';
4
+ import { GovernanceProposerContract, type RollupContract } from '@aztec-labs/ethereum/contracts';
5
+ import type { L1TxUtils } from '@aztec-labs/ethereum/l1-tx-utils';
6
+ import { PublisherManager } from '@aztec-labs/ethereum/publisher-manager';
7
+ import { EthCheatCodes } from '@aztec-labs/ethereum/test';
8
+ import type { ViemPublicClient } from '@aztec-labs/ethereum/types';
9
+ import type { Logger } from '@aztec-labs/foundation/log';
10
+ import type { DateProvider } from '@aztec-labs/foundation/timer';
11
+ import type { KeystoreManager } from '@aztec-labs/node-keystore';
12
+ import type { P2PClient as ConcreteP2PClient, P2P } from '@aztec-labs/p2p';
13
+ import type { L2BlockSource } from '@aztec-labs/stdlib/block';
14
+ import type { ChainConfig } from '@aztec-labs/stdlib/config';
15
+ import type { WorldStateSynchronizer } from '@aztec-labs/stdlib/interfaces/server';
16
+ import type { L1ToL2MessageSource } from '@aztec-labs/stdlib/messaging';
17
+ import type { TelemetryClient } from '@aztec-labs/telemetry-client';
18
+ import {
19
+ type FullNodeCheckpointsBuilder,
20
+ NodeKeystoreAdapter,
21
+ type ValidatorClient,
22
+ } from '@aztec-labs/validator-client';
23
+
24
+ import { type SequencerClientConfig, getPublisherConfigFromSequencerConfig } from '../../config.js';
25
+ import type { GlobalVariableBuilder } from '../../global_variable_builder/global_builder.js';
26
+ import { SequencerPublisherFactory } from '../../publisher/sequencer-publisher-factory.js';
27
+ import { AutomineSequencer } from './automine_sequencer.js';
28
+
29
+ /** Arguments for {@link createAutomineSequencer}. */
30
+ export type CreateAutomineSequencerArgs = {
31
+ config: SequencerClientConfig & Pick<ChainConfig, 'l1ChainId' | 'rollupAddress'>;
32
+ l1TxUtils: L1TxUtils[];
33
+ funderL1TxUtils: L1TxUtils | undefined;
34
+ publicClient: ViemPublicClient;
35
+ rollupContract: RollupContract;
36
+ epochCache: EpochCache;
37
+ blobClient: BlobClientInterface | undefined;
38
+ telemetry: TelemetryClient;
39
+ dateProvider: DateProvider;
40
+ keyStoreManager: KeystoreManager;
41
+ validatorClient: ValidatorClient;
42
+ checkpointsBuilder: FullNodeCheckpointsBuilder;
43
+ globalVariableBuilder: GlobalVariableBuilder;
44
+ worldStateSynchronizer: WorldStateSynchronizer;
45
+ archiver: L2BlockSource &
46
+ L1ToL2MessageSource &
47
+ Pick<
48
+ Archiver,
49
+ 'rollbackTo' | 'addBlock' | 'addProposedCheckpoint' | 'syncImmediate' | 'removeUncheckpointedBlocksAfter'
50
+ >;
51
+ p2pClient: P2P & Pick<ConcreteP2PClient, 'sync'>;
52
+ l1Constants: { l1GenesisTime: bigint; slotDuration: number; ethereumSlotDuration: number; rollupManaLimit: number };
53
+ /** When true, run the auto-settle / clock-reconcile loop (local-network only). */
54
+ autoSettle?: boolean;
55
+ log: Logger;
56
+ };
57
+
58
+ /**
59
+ * Builds an {@link AutomineSequencer} for use in single-sequencer e2e tests.
60
+ *
61
+ * Constructs the PublisherManager, GovernanceProposerContract, SequencerPublisherFactory,
62
+ * looks up the attestor/coinbase/feeRecipient from the keystore, wires EthCheatCodes,
63
+ * and starts the publisher manager before returning.
64
+ */
65
+ export async function createAutomineSequencer({
66
+ config,
67
+ l1TxUtils,
68
+ funderL1TxUtils,
69
+ publicClient,
70
+ rollupContract,
71
+ epochCache,
72
+ blobClient,
73
+ telemetry,
74
+ dateProvider,
75
+ keyStoreManager,
76
+ validatorClient,
77
+ checkpointsBuilder,
78
+ globalVariableBuilder,
79
+ worldStateSynchronizer,
80
+ archiver,
81
+ p2pClient,
82
+ l1Constants,
83
+ autoSettle,
84
+ log,
85
+ }: CreateAutomineSequencerArgs): Promise<AutomineSequencer> {
86
+ const publisherManager = new PublisherManager(l1TxUtils, getPublisherConfigFromSequencerConfig(config), {
87
+ bindings: log.getBindings(),
88
+ funder: funderL1TxUtils,
89
+ });
90
+ const governanceProposerContract = new GovernanceProposerContract(
91
+ publicClient,
92
+ config.governanceProposerAddress.toString(),
93
+ );
94
+ const publisherFactory = new SequencerPublisherFactory(config, {
95
+ telemetry,
96
+ blobClient: blobClient!,
97
+ epochCache,
98
+ governanceProposerContract,
99
+ rollupContract,
100
+ dateProvider,
101
+ publisherManager,
102
+ nodeKeyStore: NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager),
103
+ logger: log,
104
+ });
105
+ const attestorAddresses = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAttesterAddresses();
106
+ const attestor = attestorAddresses[0];
107
+ if (!attestor) {
108
+ throw new Error('AutomineSequencer requires at least one attestor address in the keystore');
109
+ }
110
+ const coinbase = validatorClient.getCoinbaseForAttestor(attestor);
111
+ const feeRecipient = validatorClient.getFeeRecipientForAttestor(attestor);
112
+ const ethCheatCodes = new EthCheatCodes(config.l1RpcUrls, dateProvider, log.createChild('eth-cheat-codes'));
113
+
114
+ // Include the funder's L1TxUtils in the reorg reset list so funding-tx nonces don't
115
+ // go stale after L1 rollbacks. Dedupe by sender address in case the funder reuses a
116
+ // publisher's signer.
117
+ const reorgResetL1TxUtils = (() => {
118
+ if (!funderL1TxUtils) {
119
+ return l1TxUtils;
120
+ }
121
+ const funderAddress = funderL1TxUtils.getSenderAddress().toString();
122
+ const alreadyIncluded = l1TxUtils.some(utils => utils.getSenderAddress().toString() === funderAddress);
123
+ return alreadyIncluded ? l1TxUtils : [...l1TxUtils, funderL1TxUtils];
124
+ })();
125
+
126
+ const automineSequencer = new AutomineSequencer({
127
+ publisherFactory,
128
+ checkpointsBuilder,
129
+ globalsBuilder: globalVariableBuilder,
130
+ worldState: worldStateSynchronizer,
131
+ l2BlockSource: archiver,
132
+ l1ToL2MessageSource: archiver,
133
+ p2pClient,
134
+ ethCheatCodes,
135
+ dateProvider: dateProvider as any, // TestDateProvider; verified at construction in fixture
136
+ l1Constants: {
137
+ l1GenesisTime: l1Constants.l1GenesisTime,
138
+ slotDuration: l1Constants.slotDuration,
139
+ ethereumSlotDuration: l1Constants.ethereumSlotDuration,
140
+ rollupManaLimit: l1Constants.rollupManaLimit,
141
+ epochDuration: config.aztecEpochDuration,
142
+ },
143
+ coinbase,
144
+ feeRecipient,
145
+ signatureContext: { chainId: config.l1ChainId, rollupAddress: config.rollupAddress },
146
+ config,
147
+ archiver,
148
+ l1TxUtils: reorgResetL1TxUtils,
149
+ autoSettle,
150
+ stopExtras: () => publisherManager.stop(),
151
+ log: log.createChild('automine-sequencer'),
152
+ });
153
+
154
+ await publisherManager.start();
155
+ return automineSequencer;
156
+ }