@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,6 @@
1
+ import type { L1RollupConstants } from '@aztec-labs/stdlib/epoch-helpers';
2
+
3
+ export type SequencerRollupConstants = Pick<
4
+ L1RollupConstants,
5
+ 'ethereumSlotDuration' | 'l1GenesisTime' | 'slotDuration' | 'rollupManaLimit' | 'epochDuration'
6
+ >;
@@ -0,0 +1,42 @@
1
+ export enum SequencerState {
2
+ /** Sequencer is stopped and not processing any txs from the pool. */
3
+ STOPPED = 'STOPPED',
4
+ /** Sequencer is being stopped. Will move to STOPPED shortly. */
5
+ STOPPING = 'STOPPING',
6
+ /** Sequencer is awaiting the next call to work(). */
7
+ IDLE = 'IDLE',
8
+ /** Synchronizing with the L2 chain. */
9
+ SYNCHRONIZING = 'SYNCHRONIZING',
10
+ /** Checking if we are the proposer for the current slot. */
11
+ PROPOSER_CHECK = 'PROPOSER_CHECK',
12
+ /** Initializing the checkpoint proposal. */
13
+ INITIALIZING_CHECKPOINT = 'INITIALIZING_CHECKPOINT',
14
+ /** Waiting for transactions to arrive in the pool. */
15
+ WAITING_FOR_TXS = 'WAITING_FOR_TXS',
16
+ /** Creating a new L2 block. Includes processing public function calls. */
17
+ CREATING_BLOCK = 'CREATING_BLOCK',
18
+ /** Waiting until the next block can be created. */
19
+ WAITING_UNTIL_NEXT_BLOCK = 'WAITING_UNTIL_NEXT_BLOCK',
20
+ /** Assembling and broadcasting the checkpoint. */
21
+ ASSEMBLING_CHECKPOINT = 'ASSEMBLING_CHECKPOINT',
22
+ /** Collecting attestations from its peers. */
23
+ COLLECTING_ATTESTATIONS = 'COLLECTING_ATTESTATIONS',
24
+ /** Sending the tx to L1 with the L2 checkpoint data and awaiting it to be mined.. */
25
+ PUBLISHING_CHECKPOINT = 'PUBLISHING_CHECKPOINT',
26
+ }
27
+
28
+ export type SequencerStateWithSlot =
29
+ | SequencerState.INITIALIZING_CHECKPOINT
30
+ | SequencerState.WAITING_FOR_TXS
31
+ | SequencerState.CREATING_BLOCK
32
+ | SequencerState.WAITING_UNTIL_NEXT_BLOCK
33
+ | SequencerState.COLLECTING_ATTESTATIONS
34
+ | SequencerState.PUBLISHING_CHECKPOINT
35
+ | SequencerState.PROPOSER_CHECK
36
+ | SequencerState.ASSEMBLING_CHECKPOINT;
37
+
38
+ export type SequencerStateCallback = () => SequencerState;
39
+
40
+ export function sequencerStateToNumber(state: SequencerState): number {
41
+ return Object.values(SequencerState).indexOf(state);
42
+ }
@@ -0,0 +1,26 @@
1
+ import type { L1TxUtils } from '@aztec-labs/ethereum/l1-tx-utils';
2
+ import type { PublisherManager } from '@aztec-labs/ethereum/publisher-manager';
3
+ import type { PublicProcessorFactory } from '@aztec-labs/simulator/server';
4
+ import type { ProposerTimetable } from '@aztec-labs/stdlib/timetable';
5
+ import type { FullNodeCheckpointsBuilder, ValidatorClient } from '@aztec-labs/validator-client';
6
+
7
+ import { SequencerClient } from '../client/sequencer-client.js';
8
+ import type { SequencerPublisherFactory } from '../publisher/sequencer-publisher-factory.js';
9
+ import { Sequencer } from '../sequencer/sequencer.js';
10
+
11
+ class TestSequencer_ extends Sequencer {
12
+ declare public publicProcessorFactory: PublicProcessorFactory;
13
+ declare public timetable: ProposerTimetable;
14
+ declare public publisherFactory: SequencerPublisherFactory;
15
+ declare public validatorClient: ValidatorClient;
16
+ declare public checkpointsBuilder: FullNodeCheckpointsBuilder;
17
+ }
18
+
19
+ export type TestSequencer = TestSequencer_;
20
+
21
+ class TestSequencerClient_ extends SequencerClient {
22
+ declare public sequencer: TestSequencer;
23
+ declare public publisherManager: PublisherManager<L1TxUtils>;
24
+ }
25
+
26
+ export type TestSequencerClient = TestSequencerClient_;
@@ -0,0 +1,324 @@
1
+ import { type BlockNumber, CheckpointNumber, IndexWithinCheckpoint } from '@aztec-labs/foundation/branded-types';
2
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
3
+ import type { LoggerBindings } from '@aztec-labs/foundation/log';
4
+ import { unfreeze } from '@aztec-labs/foundation/types';
5
+ import { L2Block } from '@aztec-labs/stdlib/block';
6
+ import { Checkpoint } from '@aztec-labs/stdlib/checkpoint';
7
+ import type {
8
+ BlockBuilderOptions,
9
+ FullNodeBlockBuilderConfig,
10
+ ICheckpointBlockBuilder,
11
+ ICheckpointsBuilder,
12
+ MerkleTreeWriteOperations,
13
+ } from '@aztec-labs/stdlib/interfaces/server';
14
+ import { CheckpointHeader } from '@aztec-labs/stdlib/rollup';
15
+ import { makeAppendOnlyTreeSnapshot } from '@aztec-labs/stdlib/testing';
16
+ import type { CheckpointGlobalVariables, Tx } from '@aztec-labs/stdlib/tx';
17
+ import type { BuildBlockInCheckpointResult } from '@aztec-labs/validator-client';
18
+
19
+ /**
20
+ * A fake CheckpointBuilder for testing that implements the same interface as the real one.
21
+ * Can be seeded with blocks to return sequentially on each `buildBlock` call.
22
+ */
23
+ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
24
+ private blocks: L2Block[] = [];
25
+ private builtBlocks: L2Block[] = [];
26
+ private usedTxsPerBlock: Tx[][] = [];
27
+ private blockIndex = 0;
28
+
29
+ /** Optional function to dynamically provide the block (alternative to seedBlocks) */
30
+ private blockProvider: (() => L2Block) | undefined = undefined;
31
+
32
+ /** Track calls for assertions */
33
+ public buildBlockCalls: Array<{
34
+ blockNumber: BlockNumber;
35
+ timestamp: bigint;
36
+ opts: BlockBuilderOptions;
37
+ }> = [];
38
+ /** Track all consumed transaction hashes across buildBlock calls */
39
+ public consumedTxHashes: Set<string> = new Set();
40
+ public completeCheckpointCalled = false;
41
+ public getCheckpointCalled = false;
42
+
43
+ /** Set to an error to make buildBlock throw on next call */
44
+ public errorOnBuild: Error | undefined = undefined;
45
+
46
+ constructor(
47
+ private readonly constants: CheckpointGlobalVariables,
48
+ private readonly checkpointNumber: CheckpointNumber,
49
+ ) {}
50
+
51
+ /** Seed the builder with blocks to return on successive buildBlock calls */
52
+ seedBlocks(blocks: L2Block[], usedTxsPerBlock?: Tx[][]): this {
53
+ this.blocks = blocks;
54
+ this.usedTxsPerBlock = usedTxsPerBlock ?? blocks.map(() => []);
55
+ this.blockIndex = 0;
56
+ this.blockProvider = undefined;
57
+ return this;
58
+ }
59
+
60
+ /**
61
+ * Set a function that provides blocks dynamically.
62
+ * Useful for tests where the block is determined at call time (e.g., sequencer tests).
63
+ */
64
+ setBlockProvider(provider: () => L2Block): this {
65
+ this.blockProvider = provider;
66
+ this.blocks = [];
67
+ return this;
68
+ }
69
+
70
+ getConstantData(): CheckpointGlobalVariables {
71
+ return this.constants;
72
+ }
73
+
74
+ async buildBlock(
75
+ pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
76
+ blockNumber: BlockNumber,
77
+ timestamp: bigint,
78
+ opts: BlockBuilderOptions,
79
+ ): Promise<BuildBlockInCheckpointResult> {
80
+ this.buildBlockCalls.push({ blockNumber, timestamp, opts });
81
+
82
+ if (this.errorOnBuild) {
83
+ throw this.errorOnBuild;
84
+ }
85
+
86
+ let block: L2Block;
87
+ let usedTxs: Tx[];
88
+
89
+ if (this.blockProvider) {
90
+ // Dynamic mode: get block from provider, cloning to avoid shared references across multiple buildBlock calls
91
+ block = L2Block.fromBuffer(this.blockProvider().toBuffer());
92
+ block.header.globalVariables.blockNumber = blockNumber;
93
+ await block.header.recomputeHash();
94
+ usedTxs = [];
95
+ this.builtBlocks.push(block);
96
+ } else {
97
+ // Seeded mode: get block from pre-seeded list
98
+ block = this.blocks[this.blockIndex];
99
+ usedTxs = this.usedTxsPerBlock[this.blockIndex] ?? [];
100
+ this.blockIndex++;
101
+ this.builtBlocks.push(block);
102
+ }
103
+
104
+ // Check that no pending tx has already been consumed
105
+ for await (const tx of pendingTxs) {
106
+ const hash = tx.getTxHash().toString();
107
+ if (this.consumedTxHashes.has(hash)) {
108
+ throw new Error(`Transaction ${hash} was already consumed in a previous block`);
109
+ }
110
+ }
111
+
112
+ // Add used txs to consumed set
113
+ for (const tx of usedTxs) {
114
+ this.consumedTxHashes.add(tx.getTxHash().toString());
115
+ }
116
+
117
+ return {
118
+ block,
119
+ publicProcessorDuration: 0,
120
+ numTxs: block?.body?.txEffects?.length ?? usedTxs.length,
121
+ usedTxs,
122
+ failedTxs: [],
123
+ };
124
+ }
125
+
126
+ completeCheckpoint(): Promise<Checkpoint> {
127
+ this.completeCheckpointCalled = true;
128
+ const allBlocks = this.blockProvider ? this.builtBlocks : this.blocks;
129
+ return this.buildCheckpoint(allBlocks);
130
+ }
131
+
132
+ getCheckpoint(): Promise<Checkpoint> {
133
+ this.getCheckpointCalled = true;
134
+ const builtBlocks = this.blockProvider ? this.builtBlocks : this.blocks.slice(0, this.blockIndex);
135
+ if (builtBlocks.length === 0) {
136
+ throw new Error('No blocks built yet');
137
+ }
138
+ return this.buildCheckpoint(builtBlocks);
139
+ }
140
+
141
+ /** Builds a structurally valid Checkpoint from a list of blocks, fixing up indexes and archive chaining. */
142
+ private async buildCheckpoint(blocks: L2Block[]): Promise<Checkpoint> {
143
+ // Fix up indexWithinCheckpoint and archive chaining so the checkpoint passes structural validation.
144
+ for (let i = 0; i < blocks.length; i++) {
145
+ blocks[i].indexWithinCheckpoint = IndexWithinCheckpoint(i);
146
+ if (i > 0) {
147
+ unfreeze(blocks[i].header).lastArchive = blocks[i - 1].archive;
148
+ await blocks[i].header.recomputeHash();
149
+ }
150
+ }
151
+
152
+ const firstBlock = blocks[0];
153
+ const lastBlock = blocks[blocks.length - 1];
154
+ const gv = firstBlock.header.globalVariables;
155
+
156
+ const checkpointHeader = CheckpointHeader.empty({
157
+ lastArchiveRoot: firstBlock.header.lastArchive.root,
158
+ blockHeadersHash: Fr.random(),
159
+ slotNumber: gv.slotNumber,
160
+ timestamp: gv.timestamp,
161
+ coinbase: gv.coinbase,
162
+ feeRecipient: gv.feeRecipient,
163
+ gasFees: gv.gasFees,
164
+ totalManaUsed: lastBlock.header.totalManaUsed,
165
+ });
166
+
167
+ return new Checkpoint(
168
+ makeAppendOnlyTreeSnapshot(lastBlock.header.globalVariables.blockNumber + 1),
169
+ checkpointHeader,
170
+ blocks,
171
+ this.checkpointNumber,
172
+ );
173
+ }
174
+
175
+ /** Resets per-checkpoint state (built blocks, consumed txs) while preserving config (blockProvider, seeded blocks). */
176
+ resetCheckpointState(): void {
177
+ this.builtBlocks = [];
178
+ this.blockIndex = 0;
179
+ this.consumedTxHashes.clear();
180
+ this.completeCheckpointCalled = false;
181
+ this.getCheckpointCalled = false;
182
+ }
183
+
184
+ /** Reset for reuse in another test */
185
+ reset(): void {
186
+ this.blocks = [];
187
+ this.usedTxsPerBlock = [];
188
+ this.buildBlockCalls = [];
189
+ this.errorOnBuild = undefined;
190
+ this.blockProvider = undefined;
191
+ this.resetCheckpointState();
192
+ }
193
+ }
194
+
195
+ /**
196
+ * A fake CheckpointsBuilder (factory) for testing that implements the same interface
197
+ * as FullNodeCheckpointsBuilder. Returns MockCheckpointBuilder instances.
198
+ * Does NOT use jest mocks - this is a proper test double.
199
+ */
200
+ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
201
+ private checkpointBuilder: MockCheckpointBuilder | undefined;
202
+
203
+ /** Track calls for assertions */
204
+ public startCheckpointCalls: Array<{
205
+ checkpointNumber: CheckpointNumber;
206
+ constants: CheckpointGlobalVariables;
207
+ previousCheckpointOutHashes: Fr[];
208
+ feeAssetPriceModifier: bigint;
209
+ }> = [];
210
+ public openCheckpointCalls: Array<{
211
+ checkpointNumber: CheckpointNumber;
212
+ constants: CheckpointGlobalVariables;
213
+ l1ToL2Messages: Fr[];
214
+ previousCheckpointOutHashes: Fr[];
215
+ existingBlocks: L2Block[];
216
+ feeAssetPriceModifier: bigint;
217
+ }> = [];
218
+ public updateConfigCalls: Array<Partial<FullNodeBlockBuilderConfig>> = [];
219
+
220
+ /**
221
+ * Set the MockCheckpointBuilder to return from startCheckpoint.
222
+ * Must be called before startCheckpoint is invoked.
223
+ */
224
+ setCheckpointBuilder(builder: MockCheckpointBuilder): this {
225
+ this.checkpointBuilder = builder;
226
+ return this;
227
+ }
228
+
229
+ /**
230
+ * Creates a new MockCheckpointBuilder with the given constants.
231
+ * Convenience method that creates and sets the builder in one call.
232
+ */
233
+ createCheckpointBuilder(
234
+ constants: CheckpointGlobalVariables,
235
+ checkpointNumber: CheckpointNumber,
236
+ ): MockCheckpointBuilder {
237
+ this.checkpointBuilder = new MockCheckpointBuilder(constants, checkpointNumber);
238
+ return this.checkpointBuilder;
239
+ }
240
+
241
+ /** Get the current checkpoint builder (for assertions) */
242
+ getCheckpointBuilder(): MockCheckpointBuilder | undefined {
243
+ return this.checkpointBuilder;
244
+ }
245
+
246
+ getConfig(): FullNodeBlockBuilderConfig {
247
+ return {
248
+ l1GenesisTime: 0n,
249
+ slotDuration: 24,
250
+ l1ChainId: 1,
251
+ rollupVersion: 1,
252
+ rollupManaLimit: 200_000_000,
253
+ };
254
+ }
255
+
256
+ updateConfig(config: Partial<FullNodeBlockBuilderConfig>): void {
257
+ this.updateConfigCalls.push(config);
258
+ }
259
+
260
+ startCheckpoint(
261
+ checkpointNumber: CheckpointNumber,
262
+ constants: CheckpointGlobalVariables,
263
+ feeAssetPriceModifier: bigint,
264
+ previousCheckpointOutHashes: Fr[],
265
+ _previousInboxRollingHash: Fr,
266
+ _fork: MerkleTreeWriteOperations,
267
+ _bindings?: LoggerBindings,
268
+ ): Promise<ICheckpointBlockBuilder> {
269
+ this.startCheckpointCalls.push({
270
+ checkpointNumber,
271
+ constants,
272
+ previousCheckpointOutHashes,
273
+ feeAssetPriceModifier,
274
+ });
275
+
276
+ if (!this.checkpointBuilder) {
277
+ // Auto-create a builder if none was set
278
+ this.checkpointBuilder = new MockCheckpointBuilder(constants, checkpointNumber);
279
+ } else {
280
+ this.checkpointBuilder.resetCheckpointState();
281
+ }
282
+
283
+ return Promise.resolve(this.checkpointBuilder);
284
+ }
285
+
286
+ openCheckpoint(
287
+ checkpointNumber: CheckpointNumber,
288
+ constants: CheckpointGlobalVariables,
289
+ feeAssetPriceModifier: bigint,
290
+ l1ToL2Messages: Fr[],
291
+ previousCheckpointOutHashes: Fr[],
292
+ _previousInboxRollingHash: Fr,
293
+ _fork: MerkleTreeWriteOperations,
294
+ existingBlocks: L2Block[] = [],
295
+ ): Promise<ICheckpointBlockBuilder> {
296
+ this.openCheckpointCalls.push({
297
+ checkpointNumber,
298
+ constants,
299
+ l1ToL2Messages,
300
+ previousCheckpointOutHashes,
301
+ existingBlocks,
302
+ feeAssetPriceModifier,
303
+ });
304
+
305
+ if (!this.checkpointBuilder) {
306
+ // Auto-create a builder if none was set
307
+ this.checkpointBuilder = new MockCheckpointBuilder(constants, checkpointNumber);
308
+ }
309
+
310
+ return Promise.resolve(this.checkpointBuilder);
311
+ }
312
+
313
+ getFork(_blockNumber: BlockNumber): Promise<MerkleTreeWriteOperations> {
314
+ throw new Error('MockCheckpointsBuilder.getFork not implemented');
315
+ }
316
+
317
+ /** Reset for reuse in another test */
318
+ reset(): void {
319
+ this.checkpointBuilder = undefined;
320
+ this.startCheckpointCalls = [];
321
+ this.openCheckpointCalls = [];
322
+ this.updateConfigCalls = [];
323
+ }
324
+ }
@@ -0,0 +1,215 @@
1
+ import { CheckpointNumber, IndexWithinCheckpoint } from '@aztec-labs/foundation/branded-types';
2
+ import { times } from '@aztec-labs/foundation/collection';
3
+ import { Secp256k1Signer } from '@aztec-labs/foundation/crypto/secp256k1-signer';
4
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
5
+ import type { EthAddress } from '@aztec-labs/foundation/eth-address';
6
+ import { Signature } from '@aztec-labs/foundation/eth-signature';
7
+ import type { P2P } from '@aztec-labs/p2p';
8
+ import { PublicDataWrite } from '@aztec-labs/stdlib/avm';
9
+ import { Body, CommitteeAttestation, L2Block } from '@aztec-labs/stdlib/block';
10
+ import { DEFAULT_BLOCK_DURATION_MS } from '@aztec-labs/stdlib/config';
11
+ import type { L1RollupConstants } from '@aztec-labs/stdlib/epoch-helpers';
12
+ import { BlockProposal, CheckpointAttestation, CheckpointProposal, ConsensusPayload } from '@aztec-labs/stdlib/p2p';
13
+ import { CheckpointHeader } from '@aztec-labs/stdlib/rollup';
14
+ import {
15
+ TEST_COORDINATION_SIGNATURE_CONTEXT,
16
+ makeAppendOnlyTreeSnapshot,
17
+ mockTxForRollup,
18
+ } from '@aztec-labs/stdlib/testing';
19
+ import {
20
+ DEFAULT_CHECKPOINT_PROPOSAL_INIT_TIME,
21
+ DEFAULT_CHECKPOINT_PROPOSAL_PREPARE_TIME,
22
+ DEFAULT_MIN_BLOCK_DURATION,
23
+ DEFAULT_P2P_PROPAGATION_TIME,
24
+ ProposerTimetable,
25
+ } from '@aztec-labs/stdlib/timetable';
26
+ import { BlockHeader, GlobalVariables, type Tx, makeProcessedTxFromPrivateOnlyTx } from '@aztec-labs/stdlib/tx';
27
+ import type { MockProxy } from 'jest-mock-extended';
28
+
29
+ // Re-export mock classes from their dedicated file
30
+ export { MockCheckpointBuilder, MockCheckpointsBuilder } from './mock_checkpoint_builder.js';
31
+
32
+ /**
33
+ * Builds a {@link ProposerTimetable} for tests from a millisecond block duration and optional budgets,
34
+ * filling unset budgets with the shared `DEFAULT_*` values the sequencer config layer applies. Mirrors how
35
+ * the sequencer constructs its timetable so tests exercise the same budget resolution.
36
+ */
37
+ export function makeProposerTimetable(opts: {
38
+ l1Constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration' | 'ethereumSlotDuration'>;
39
+ blockDurationMs?: number;
40
+ minBlockDuration?: number;
41
+ p2pPropagationTime?: number;
42
+ checkpointProposalPrepareTime?: number;
43
+ }): ProposerTimetable {
44
+ return new ProposerTimetable({
45
+ l1Constants: opts.l1Constants,
46
+ blockDuration: (opts.blockDurationMs ?? DEFAULT_BLOCK_DURATION_MS) / 1000,
47
+ minBlockDuration: opts.minBlockDuration ?? DEFAULT_MIN_BLOCK_DURATION,
48
+ p2pPropagationTime: opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME,
49
+ checkpointProposalPrepareTime: opts.checkpointProposalPrepareTime ?? DEFAULT_CHECKPOINT_PROPOSAL_PREPARE_TIME,
50
+ checkpointProposalInitTime: DEFAULT_CHECKPOINT_PROPOSAL_INIT_TIME,
51
+ });
52
+ }
53
+
54
+ /**
55
+ * Creates a mock transaction with a specific seed for deterministic testing
56
+ */
57
+ export async function makeTx(seed?: number, chainId?: Fr): Promise<Tx> {
58
+ const tx = await mockTxForRollup(seed);
59
+ if (chainId) {
60
+ tx.data.constants.txContext.chainId = chainId;
61
+ }
62
+ return tx;
63
+ }
64
+
65
+ /**
66
+ * Creates an L2Block from transactions and global variables
67
+ */
68
+ export async function makeBlock(txs: Tx[], globalVariables: GlobalVariables): Promise<L2Block> {
69
+ const processedTxs = await Promise.all(
70
+ txs.map(tx =>
71
+ makeProcessedTxFromPrivateOnlyTx(tx, Fr.ZERO, new PublicDataWrite(Fr.random(), Fr.random()), globalVariables),
72
+ ),
73
+ );
74
+ const body = new Body(processedTxs.map(tx => tx.txEffect));
75
+ const header = BlockHeader.empty({ globalVariables });
76
+ const archive = makeAppendOnlyTreeSnapshot(globalVariables.blockNumber + 1);
77
+ return new L2Block(
78
+ archive,
79
+ header,
80
+ body,
81
+ CheckpointNumber.fromBlockNumber(globalVariables.blockNumber),
82
+ IndexWithinCheckpoint(0),
83
+ );
84
+ }
85
+
86
+ /**
87
+ * Mocks the P2P client to return specific pending transactions
88
+ */
89
+ export function mockPendingTxs(p2p: MockProxy<P2P>, txs: Tx[]): void {
90
+ p2p.getPendingTxCount.mockResolvedValue(txs.length);
91
+ p2p.hasEligiblePendingTxs.mockImplementation(minCount => Promise.resolve(txs.length >= minCount));
92
+ p2p.iteratePendingTxs.mockImplementation(() => mockTxIterator(Promise.resolve(txs)));
93
+ p2p.iterateEligiblePendingTxs.mockImplementation(() => mockTxIterator(Promise.resolve(txs)));
94
+ }
95
+
96
+ /**
97
+ * Creates an async iterator for transactions
98
+ */
99
+ export async function* mockTxIterator(txs: Promise<Tx[]>): AsyncIterableIterator<Tx> {
100
+ for (const tx of await txs) {
101
+ yield tx;
102
+ }
103
+ }
104
+
105
+ /**
106
+ * Creates mock committee attestations from a signer
107
+ */
108
+ export function createMockSignatures(signer: Secp256k1Signer): CommitteeAttestation[] {
109
+ const mockedSig = Signature.random();
110
+ return [new CommitteeAttestation(signer.address, mockedSig)];
111
+ }
112
+
113
+ /**
114
+ * Creates a CheckpointHeader from an L2Block for testing purposes.
115
+ * Uses mock values for blockHeadersHash and blobsHash since L2Block doesn't have these fields.
116
+ */
117
+ function createCheckpointHeaderFromBlock(block: L2Block): CheckpointHeader {
118
+ const gv = block.header.globalVariables;
119
+ return new CheckpointHeader(
120
+ block.header.lastArchive.root,
121
+ Fr.random(), // blockHeadersHash - mock value for testing
122
+ Fr.random(), // blobsHash - mock value for testing
123
+ Fr.random(), // inboxRollingHash - mock value for testing
124
+ Fr.random(), // outHash - mock value for testing
125
+ gv.slotNumber,
126
+ gv.timestamp,
127
+ gv.coinbase,
128
+ gv.feeRecipient,
129
+ gv.gasFees,
130
+ block.header.totalManaUsed,
131
+ block.header.totalFees,
132
+ );
133
+ }
134
+
135
+ /**
136
+ * Creates a block proposal from a block and signature
137
+ */
138
+ export function createBlockProposal(block: L2Block, signature: Signature): BlockProposal {
139
+ const txHashes = block.body.txEffects.map(tx => tx.txHash);
140
+ return new BlockProposal(
141
+ block.header,
142
+ block.indexWithinCheckpoint,
143
+ block.archive.root,
144
+ txHashes,
145
+ signature,
146
+ TEST_COORDINATION_SIGNATURE_CONTEXT,
147
+ );
148
+ }
149
+
150
+ /**
151
+ * Creates a checkpoint proposal from a block and signature
152
+ */
153
+ export function createCheckpointProposal(
154
+ block: L2Block,
155
+ checkpointSignature: Signature,
156
+ blockSignature?: Signature,
157
+ feeAssetPriceModifier: bigint = 0n,
158
+ ): CheckpointProposal {
159
+ const txHashes = block.body.txEffects.map(tx => tx.txHash);
160
+ const checkpointHeader = createCheckpointHeaderFromBlock(block);
161
+ return new CheckpointProposal(
162
+ checkpointHeader,
163
+ block.archive.root,
164
+ feeAssetPriceModifier,
165
+ checkpointSignature,
166
+ TEST_COORDINATION_SIGNATURE_CONTEXT,
167
+ {
168
+ blockHeader: block.header,
169
+ indexWithinCheckpoint: block.indexWithinCheckpoint,
170
+ txHashes,
171
+ signature: blockSignature ?? checkpointSignature, // Use checkpoint signature as block signature if not provided
172
+ },
173
+ );
174
+ }
175
+
176
+ /**
177
+ * Creates a checkpoint attestation from a block and signature.
178
+ * Note: We manually set the sender since we use random signatures in tests.
179
+ * In production, the sender is recovered from the signature.
180
+ */
181
+ export function createCheckpointAttestation(
182
+ block: L2Block,
183
+ signature: Signature,
184
+ sender: EthAddress,
185
+ feeAssetPriceModifier: bigint = 0n,
186
+ ): CheckpointAttestation {
187
+ const checkpointHeader = createCheckpointHeaderFromBlock(block);
188
+ const payload = new ConsensusPayload(
189
+ checkpointHeader,
190
+ block.archive.root,
191
+ feeAssetPriceModifier,
192
+ TEST_COORDINATION_SIGNATURE_CONTEXT,
193
+ );
194
+ const attestation = new CheckpointAttestation(payload, signature, signature);
195
+ // Bypass signature recovery for testing since we use random signatures
196
+ (attestation as any).getSender = () => sender;
197
+ (attestation as any).getProposer = () => sender;
198
+ return attestation;
199
+ }
200
+
201
+ /**
202
+ * Creates transactions and a block, and mocks P2P to return them.
203
+ * Helper for tests that need to set up a block with transactions.
204
+ */
205
+ export async function setupTxsAndBlock(
206
+ p2p: MockProxy<P2P>,
207
+ globalVariables: GlobalVariables,
208
+ txCount: number,
209
+ chainId: Fr,
210
+ ): Promise<{ txs: Tx[]; block: L2Block }> {
211
+ const txs = await Promise.all(times(txCount, i => makeTx(i + 1, chainId)));
212
+ const block = await makeBlock(txs, globalVariables);
213
+ mockPendingTxs(p2p, txs);
214
+ return { txs, block };
215
+ }