@aztec/sequencer-client 0.0.1-commit.b655e406 → 0.0.1-commit.b8a057fa

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 +281 -21
  2. package/dest/client/index.d.ts +1 -1
  3. package/dest/client/sequencer-client.d.ts +41 -18
  4. package/dest/client/sequencer-client.d.ts.map +1 -1
  5. package/dest/client/sequencer-client.js +88 -42
  6. package/dest/config.d.ts +41 -8
  7. package/dest/config.d.ts.map +1 -1
  8. package/dest/config.js +153 -53
  9. package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
  10. package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
  11. package/dest/global_variable_builder/fee_predictor.js +138 -0
  12. package/dest/global_variable_builder/fee_provider.d.ts +21 -0
  13. package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
  14. package/dest/global_variable_builder/fee_provider.js +80 -0
  15. package/dest/global_variable_builder/global_builder.d.ts +20 -29
  16. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  17. package/dest/global_variable_builder/global_builder.js +28 -72
  18. package/dest/global_variable_builder/index.d.ts +4 -2
  19. package/dest/global_variable_builder/index.d.ts.map +1 -1
  20. package/dest/global_variable_builder/index.js +2 -0
  21. package/dest/index.d.ts +2 -3
  22. package/dest/index.d.ts.map +1 -1
  23. package/dest/index.js +1 -2
  24. package/dest/publisher/config.d.ts +59 -20
  25. package/dest/publisher/config.d.ts.map +1 -1
  26. package/dest/publisher/config.js +134 -34
  27. package/dest/publisher/index.d.ts +2 -1
  28. package/dest/publisher/index.d.ts.map +1 -1
  29. package/dest/publisher/l1_to_l2_messaging.d.ts +21 -0
  30. package/dest/publisher/l1_to_l2_messaging.d.ts.map +1 -0
  31. package/dest/publisher/l1_to_l2_messaging.js +70 -0
  32. package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
  33. package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
  34. package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
  35. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +98 -0
  36. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
  37. package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +68 -0
  38. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
  39. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
  40. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +36 -0
  41. package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
  42. package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
  43. package/dest/publisher/l1_tx_failed_store/index.js +3 -0
  44. package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
  45. package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
  46. package/dest/publisher/sequencer-bundle-simulator.js +198 -0
  47. package/dest/publisher/sequencer-publisher-factory.d.ts +15 -8
  48. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  49. package/dest/publisher/sequencer-publisher-factory.js +28 -4
  50. package/dest/publisher/sequencer-publisher-metrics.d.ts +3 -3
  51. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  52. package/dest/publisher/sequencer-publisher-metrics.js +23 -86
  53. package/dest/publisher/sequencer-publisher.d.ts +164 -96
  54. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  55. package/dest/publisher/sequencer-publisher.js +1305 -416
  56. package/dest/publisher/write_json.d.ts +11 -0
  57. package/dest/publisher/write_json.d.ts.map +1 -0
  58. package/dest/publisher/write_json.js +57 -0
  59. package/dest/sequencer/automine/automine_factory.d.ts +56 -0
  60. package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
  61. package/dest/sequencer/automine/automine_factory.js +85 -0
  62. package/dest/sequencer/automine/automine_sequencer.d.ts +189 -0
  63. package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
  64. package/dest/sequencer/automine/automine_sequencer.js +690 -0
  65. package/dest/sequencer/automine/index.d.ts +3 -0
  66. package/dest/sequencer/automine/index.d.ts.map +1 -0
  67. package/dest/sequencer/automine/index.js +2 -0
  68. package/dest/sequencer/checkpoint_proposal_job.d.ts +158 -0
  69. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  70. package/dest/sequencer/checkpoint_proposal_job.js +1801 -0
  71. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
  72. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
  73. package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
  74. package/dest/sequencer/checkpoint_voter.d.ts +34 -0
  75. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  76. package/dest/sequencer/checkpoint_voter.js +106 -0
  77. package/dest/sequencer/config.d.ts +3 -2
  78. package/dest/sequencer/config.d.ts.map +1 -1
  79. package/dest/sequencer/errors.d.ts +1 -1
  80. package/dest/sequencer/errors.d.ts.map +1 -1
  81. package/dest/sequencer/events.d.ts +103 -0
  82. package/dest/sequencer/events.d.ts.map +1 -0
  83. package/dest/sequencer/events.js +1 -0
  84. package/dest/sequencer/index.d.ts +4 -2
  85. package/dest/sequencer/index.d.ts.map +1 -1
  86. package/dest/sequencer/index.js +3 -1
  87. package/dest/sequencer/metrics.d.ts +48 -4
  88. package/dest/sequencer/metrics.d.ts.map +1 -1
  89. package/dest/sequencer/metrics.js +257 -50
  90. package/dest/sequencer/requests_tracker.d.ts +22 -0
  91. package/dest/sequencer/requests_tracker.d.ts.map +1 -0
  92. package/dest/sequencer/requests_tracker.js +33 -0
  93. package/dest/sequencer/sequencer.d.ts +253 -148
  94. package/dest/sequencer/sequencer.d.ts.map +1 -1
  95. package/dest/sequencer/sequencer.js +1208 -598
  96. package/dest/sequencer/types.d.ts +3 -0
  97. package/dest/sequencer/types.d.ts.map +1 -0
  98. package/dest/sequencer/types.js +1 -0
  99. package/dest/sequencer/utils.d.ts +14 -8
  100. package/dest/sequencer/utils.d.ts.map +1 -1
  101. package/dest/sequencer/utils.js +7 -4
  102. package/dest/test/index.d.ts +8 -9
  103. package/dest/test/index.d.ts.map +1 -1
  104. package/dest/test/mock_checkpoint_builder.d.ts +95 -0
  105. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  106. package/dest/test/mock_checkpoint_builder.js +231 -0
  107. package/dest/test/utils.d.ts +67 -0
  108. package/dest/test/utils.d.ts.map +1 -0
  109. package/dest/test/utils.js +122 -0
  110. package/package.json +34 -30
  111. package/src/client/sequencer-client.ts +118 -66
  112. package/src/config.ts +181 -62
  113. package/src/global_variable_builder/README.md +44 -0
  114. package/src/global_variable_builder/fee_predictor.ts +182 -0
  115. package/src/global_variable_builder/fee_provider.ts +97 -0
  116. package/src/global_variable_builder/global_builder.ts +45 -106
  117. package/src/global_variable_builder/index.ts +3 -1
  118. package/src/index.ts +1 -7
  119. package/src/publisher/config.ts +190 -46
  120. package/src/publisher/index.ts +3 -0
  121. package/src/publisher/l1_to_l2_messaging.ts +85 -0
  122. package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
  123. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +164 -0
  124. package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +47 -0
  125. package/src/publisher/l1_tx_failed_store/index.ts +3 -0
  126. package/src/publisher/sequencer-bundle-simulator.ts +254 -0
  127. package/src/publisher/sequencer-publisher-factory.ts +45 -14
  128. package/src/publisher/sequencer-publisher-metrics.ts +19 -71
  129. package/src/publisher/sequencer-publisher.ts +1109 -538
  130. package/src/publisher/write_json.ts +78 -0
  131. package/src/sequencer/README.md +243 -0
  132. package/src/sequencer/automine/README.md +60 -0
  133. package/src/sequencer/automine/automine_factory.ts +152 -0
  134. package/src/sequencer/automine/automine_sequencer.ts +796 -0
  135. package/src/sequencer/automine/index.ts +6 -0
  136. package/src/sequencer/checkpoint_proposal_job.ts +1652 -0
  137. package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
  138. package/src/sequencer/checkpoint_voter.ts +119 -0
  139. package/src/sequencer/config.ts +2 -1
  140. package/src/sequencer/events.ts +88 -0
  141. package/src/sequencer/index.ts +3 -1
  142. package/src/sequencer/metrics.ts +330 -62
  143. package/src/sequencer/requests_tracker.ts +43 -0
  144. package/src/sequencer/sequencer.ts +1033 -777
  145. package/src/sequencer/types.ts +6 -0
  146. package/src/sequencer/utils.ts +18 -9
  147. package/src/test/index.ts +7 -8
  148. package/src/test/mock_checkpoint_builder.ts +323 -0
  149. package/src/test/utils.ts +218 -0
  150. package/dest/sequencer/block_builder.d.ts +0 -27
  151. package/dest/sequencer/block_builder.d.ts.map +0 -1
  152. package/dest/sequencer/block_builder.js +0 -130
  153. package/dest/sequencer/timetable.d.ts +0 -50
  154. package/dest/sequencer/timetable.d.ts.map +0 -1
  155. package/dest/sequencer/timetable.js +0 -137
  156. package/dest/tx_validator/nullifier_cache.d.ts +0 -14
  157. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  158. package/dest/tx_validator/nullifier_cache.js +0 -24
  159. package/dest/tx_validator/tx_validator_factory.d.ts +0 -17
  160. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  161. package/dest/tx_validator/tx_validator_factory.js +0 -53
  162. package/src/sequencer/block_builder.ts +0 -218
  163. package/src/sequencer/timetable.ts +0 -188
  164. package/src/tx_validator/nullifier_cache.ts +0 -30
  165. package/src/tx_validator/tx_validator_factory.ts +0 -132
@@ -0,0 +1,6 @@
1
+ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
2
+
3
+ export type SequencerRollupConstants = Pick<
4
+ L1RollupConstants,
5
+ 'ethereumSlotDuration' | 'l1GenesisTime' | 'slotDuration' | 'rollupManaLimit' | 'epochDuration'
6
+ >;
@@ -9,22 +9,31 @@ export enum SequencerState {
9
9
  SYNCHRONIZING = 'SYNCHRONIZING',
10
10
  /** Checking if we are the proposer for the current slot. */
11
11
  PROPOSER_CHECK = 'PROPOSER_CHECK',
12
- /** Initializing the block proposal. Will move to CREATING_BLOCK if there are valid txs to include, or back to SYNCHRONIZING otherwise. */
13
- INITIALIZING_PROPOSAL = 'INITIALIZING_PROPOSAL',
14
- /** Creating a new L2 block. Includes processing public function calls and running rollup circuits. Will move to PUBLISHING_CONTRACT_DATA. */
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. */
15
17
  CREATING_BLOCK = 'CREATING_BLOCK',
16
- /** Collecting attestations from its peers. Will move to PUBLISHING_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. */
17
23
  COLLECTING_ATTESTATIONS = 'COLLECTING_ATTESTATIONS',
18
- /** Sending the tx to L1 with the L2 block data and awaiting it to be mined. Will move to SYNCHRONIZING. */
19
- PUBLISHING_BLOCK = 'PUBLISHING_BLOCK',
24
+ /** Sending the tx to L1 with the L2 checkpoint data and awaiting it to be mined.. */
25
+ PUBLISHING_CHECKPOINT = 'PUBLISHING_CHECKPOINT',
20
26
  }
21
27
 
22
28
  export type SequencerStateWithSlot =
23
- | SequencerState.INITIALIZING_PROPOSAL
29
+ | SequencerState.INITIALIZING_CHECKPOINT
30
+ | SequencerState.WAITING_FOR_TXS
24
31
  | SequencerState.CREATING_BLOCK
32
+ | SequencerState.WAITING_UNTIL_NEXT_BLOCK
25
33
  | SequencerState.COLLECTING_ATTESTATIONS
26
- | SequencerState.PUBLISHING_BLOCK
27
- | SequencerState.PROPOSER_CHECK;
34
+ | SequencerState.PUBLISHING_CHECKPOINT
35
+ | SequencerState.PROPOSER_CHECK
36
+ | SequencerState.ASSEMBLING_CHECKPOINT;
28
37
 
29
38
  export type SequencerStateCallback = () => SequencerState;
30
39
 
package/src/test/index.ts CHANGED
@@ -1,27 +1,26 @@
1
- import type { PublisherManager } from '@aztec/ethereum';
2
- import type { L1TxUtilsWithBlobs } from '@aztec/ethereum/l1-tx-utils-with-blobs';
1
+ import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
2
+ import type { PublisherManager } from '@aztec/ethereum/publisher-manager';
3
3
  import type { PublicProcessorFactory } from '@aztec/simulator/server';
4
- import type { ValidatorClient } from '@aztec/validator-client';
4
+ import type { ProposerTimetable } from '@aztec/stdlib/timetable';
5
+ import type { FullNodeCheckpointsBuilder, ValidatorClient } from '@aztec/validator-client';
5
6
 
6
7
  import { SequencerClient } from '../client/sequencer-client.js';
7
8
  import type { SequencerPublisherFactory } from '../publisher/sequencer-publisher-factory.js';
8
- import type { SequencerPublisher } from '../publisher/sequencer-publisher.js';
9
9
  import { Sequencer } from '../sequencer/sequencer.js';
10
- import type { SequencerTimetable } from '../sequencer/timetable.js';
11
10
 
12
11
  class TestSequencer_ extends Sequencer {
13
12
  declare public publicProcessorFactory: PublicProcessorFactory;
14
- declare public timetable: SequencerTimetable;
15
- declare public publisher: SequencerPublisher;
13
+ declare public timetable: ProposerTimetable;
16
14
  declare public publisherFactory: SequencerPublisherFactory;
17
15
  declare public validatorClient: ValidatorClient;
16
+ declare public checkpointsBuilder: FullNodeCheckpointsBuilder;
18
17
  }
19
18
 
20
19
  export type TestSequencer = TestSequencer_;
21
20
 
22
21
  class TestSequencerClient_ extends SequencerClient {
23
22
  declare public sequencer: TestSequencer;
24
- declare public publisherManager: PublisherManager<L1TxUtilsWithBlobs>;
23
+ declare public publisherManager: PublisherManager<L1TxUtils>;
25
24
  }
26
25
 
27
26
  export type TestSequencerClient = TestSequencerClient_;
@@ -0,0 +1,323 @@
1
+ import { type BlockNumber, CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
+ import { unfreeze } from '@aztec/foundation/types';
4
+ import { L2Block } from '@aztec/stdlib/block';
5
+ import { Checkpoint } from '@aztec/stdlib/checkpoint';
6
+ import type {
7
+ BlockBuilderOptions,
8
+ FullNodeBlockBuilderConfig,
9
+ ICheckpointBlockBuilder,
10
+ ICheckpointsBuilder,
11
+ MerkleTreeWriteOperations,
12
+ } from '@aztec/stdlib/interfaces/server';
13
+ import { CheckpointHeader } from '@aztec/stdlib/rollup';
14
+ import { makeAppendOnlyTreeSnapshot } from '@aztec/stdlib/testing';
15
+ import type { CheckpointGlobalVariables, Tx } from '@aztec/stdlib/tx';
16
+ import type { BuildBlockInCheckpointResult } from '@aztec/validator-client';
17
+
18
+ /**
19
+ * A fake CheckpointBuilder for testing that implements the same interface as the real one.
20
+ * Can be seeded with blocks to return sequentially on each `buildBlock` call.
21
+ */
22
+ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
23
+ private blocks: L2Block[] = [];
24
+ private builtBlocks: L2Block[] = [];
25
+ private usedTxsPerBlock: Tx[][] = [];
26
+ private blockIndex = 0;
27
+
28
+ /** Optional function to dynamically provide the block (alternative to seedBlocks) */
29
+ private blockProvider: (() => L2Block) | undefined = undefined;
30
+
31
+ /** Track calls for assertions */
32
+ public buildBlockCalls: Array<{
33
+ blockNumber: BlockNumber;
34
+ timestamp: bigint;
35
+ opts: BlockBuilderOptions;
36
+ }> = [];
37
+ /** Track all consumed transaction hashes across buildBlock calls */
38
+ public consumedTxHashes: Set<string> = new Set();
39
+ public completeCheckpointCalled = false;
40
+ public getCheckpointCalled = false;
41
+
42
+ /** Set to an error to make buildBlock throw on next call */
43
+ public errorOnBuild: Error | undefined = undefined;
44
+
45
+ constructor(
46
+ private readonly constants: CheckpointGlobalVariables,
47
+ private readonly checkpointNumber: CheckpointNumber,
48
+ ) {}
49
+
50
+ /** Seed the builder with blocks to return on successive buildBlock calls */
51
+ seedBlocks(blocks: L2Block[], usedTxsPerBlock?: Tx[][]): this {
52
+ this.blocks = blocks;
53
+ this.usedTxsPerBlock = usedTxsPerBlock ?? blocks.map(() => []);
54
+ this.blockIndex = 0;
55
+ this.blockProvider = undefined;
56
+ return this;
57
+ }
58
+
59
+ /**
60
+ * Set a function that provides blocks dynamically.
61
+ * Useful for tests where the block is determined at call time (e.g., sequencer tests).
62
+ */
63
+ setBlockProvider(provider: () => L2Block): this {
64
+ this.blockProvider = provider;
65
+ this.blocks = [];
66
+ return this;
67
+ }
68
+
69
+ getConstantData(): CheckpointGlobalVariables {
70
+ return this.constants;
71
+ }
72
+
73
+ async buildBlock(
74
+ pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
75
+ blockNumber: BlockNumber,
76
+ timestamp: bigint,
77
+ opts: BlockBuilderOptions,
78
+ ): Promise<BuildBlockInCheckpointResult> {
79
+ this.buildBlockCalls.push({ blockNumber, timestamp, opts });
80
+
81
+ if (this.errorOnBuild) {
82
+ throw this.errorOnBuild;
83
+ }
84
+
85
+ let block: L2Block;
86
+ let usedTxs: Tx[];
87
+
88
+ if (this.blockProvider) {
89
+ // Dynamic mode: get block from provider, cloning to avoid shared references across multiple buildBlock calls
90
+ block = L2Block.fromBuffer(this.blockProvider().toBuffer());
91
+ block.header.globalVariables.blockNumber = blockNumber;
92
+ await block.header.recomputeHash();
93
+ usedTxs = [];
94
+ this.builtBlocks.push(block);
95
+ } else {
96
+ // Seeded mode: get block from pre-seeded list
97
+ block = this.blocks[this.blockIndex];
98
+ usedTxs = this.usedTxsPerBlock[this.blockIndex] ?? [];
99
+ this.blockIndex++;
100
+ this.builtBlocks.push(block);
101
+ }
102
+
103
+ // Check that no pending tx has already been consumed
104
+ for await (const tx of pendingTxs) {
105
+ const hash = tx.getTxHash().toString();
106
+ if (this.consumedTxHashes.has(hash)) {
107
+ throw new Error(`Transaction ${hash} was already consumed in a previous block`);
108
+ }
109
+ }
110
+
111
+ // Add used txs to consumed set
112
+ for (const tx of usedTxs) {
113
+ this.consumedTxHashes.add(tx.getTxHash().toString());
114
+ }
115
+
116
+ return {
117
+ block,
118
+ publicProcessorDuration: 0,
119
+ numTxs: block?.body?.txEffects?.length ?? usedTxs.length,
120
+ usedTxs,
121
+ failedTxs: [],
122
+ };
123
+ }
124
+
125
+ completeCheckpoint(): Promise<Checkpoint> {
126
+ this.completeCheckpointCalled = true;
127
+ const allBlocks = this.blockProvider ? this.builtBlocks : this.blocks;
128
+ return this.buildCheckpoint(allBlocks);
129
+ }
130
+
131
+ getCheckpoint(): Promise<Checkpoint> {
132
+ this.getCheckpointCalled = true;
133
+ const builtBlocks = this.blockProvider ? this.builtBlocks : this.blocks.slice(0, this.blockIndex);
134
+ if (builtBlocks.length === 0) {
135
+ throw new Error('No blocks built yet');
136
+ }
137
+ return this.buildCheckpoint(builtBlocks);
138
+ }
139
+
140
+ /** Builds a structurally valid Checkpoint from a list of blocks, fixing up indexes and archive chaining. */
141
+ private async buildCheckpoint(blocks: L2Block[]): Promise<Checkpoint> {
142
+ // Fix up indexWithinCheckpoint and archive chaining so the checkpoint passes structural validation.
143
+ for (let i = 0; i < blocks.length; i++) {
144
+ blocks[i].indexWithinCheckpoint = IndexWithinCheckpoint(i);
145
+ if (i > 0) {
146
+ unfreeze(blocks[i].header).lastArchive = blocks[i - 1].archive;
147
+ await blocks[i].header.recomputeHash();
148
+ }
149
+ }
150
+
151
+ const firstBlock = blocks[0];
152
+ const lastBlock = blocks[blocks.length - 1];
153
+ const gv = firstBlock.header.globalVariables;
154
+
155
+ const checkpointHeader = CheckpointHeader.empty({
156
+ lastArchiveRoot: firstBlock.header.lastArchive.root,
157
+ blockHeadersHash: Fr.random(),
158
+ slotNumber: gv.slotNumber,
159
+ timestamp: gv.timestamp,
160
+ coinbase: gv.coinbase,
161
+ feeRecipient: gv.feeRecipient,
162
+ gasFees: gv.gasFees,
163
+ totalManaUsed: lastBlock.header.totalManaUsed,
164
+ });
165
+
166
+ return new Checkpoint(
167
+ makeAppendOnlyTreeSnapshot(lastBlock.header.globalVariables.blockNumber + 1),
168
+ checkpointHeader,
169
+ blocks,
170
+ this.checkpointNumber,
171
+ );
172
+ }
173
+
174
+ /** Resets per-checkpoint state (built blocks, consumed txs) while preserving config (blockProvider, seeded blocks). */
175
+ resetCheckpointState(): void {
176
+ this.builtBlocks = [];
177
+ this.blockIndex = 0;
178
+ this.consumedTxHashes.clear();
179
+ this.completeCheckpointCalled = false;
180
+ this.getCheckpointCalled = false;
181
+ }
182
+
183
+ /** Reset for reuse in another test */
184
+ reset(): void {
185
+ this.blocks = [];
186
+ this.usedTxsPerBlock = [];
187
+ this.buildBlockCalls = [];
188
+ this.errorOnBuild = undefined;
189
+ this.blockProvider = undefined;
190
+ this.resetCheckpointState();
191
+ }
192
+ }
193
+
194
+ /**
195
+ * A fake CheckpointsBuilder (factory) for testing that implements the same interface
196
+ * as FullNodeCheckpointsBuilder. Returns MockCheckpointBuilder instances.
197
+ * Does NOT use jest mocks - this is a proper test double.
198
+ */
199
+ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
200
+ private checkpointBuilder: MockCheckpointBuilder | undefined;
201
+
202
+ /** Track calls for assertions */
203
+ public startCheckpointCalls: Array<{
204
+ checkpointNumber: CheckpointNumber;
205
+ constants: CheckpointGlobalVariables;
206
+ l1ToL2Messages: Fr[];
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
+ l1ToL2Messages: Fr[],
265
+ previousCheckpointOutHashes: Fr[],
266
+ _fork: MerkleTreeWriteOperations,
267
+ ): Promise<ICheckpointBlockBuilder> {
268
+ this.startCheckpointCalls.push({
269
+ checkpointNumber,
270
+ constants,
271
+ l1ToL2Messages,
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
+ _fork: MerkleTreeWriteOperations,
293
+ existingBlocks: L2Block[] = [],
294
+ ): Promise<ICheckpointBlockBuilder> {
295
+ this.openCheckpointCalls.push({
296
+ checkpointNumber,
297
+ constants,
298
+ l1ToL2Messages,
299
+ previousCheckpointOutHashes,
300
+ existingBlocks,
301
+ feeAssetPriceModifier,
302
+ });
303
+
304
+ if (!this.checkpointBuilder) {
305
+ // Auto-create a builder if none was set
306
+ this.checkpointBuilder = new MockCheckpointBuilder(constants, checkpointNumber);
307
+ }
308
+
309
+ return Promise.resolve(this.checkpointBuilder);
310
+ }
311
+
312
+ getFork(_blockNumber: BlockNumber): Promise<MerkleTreeWriteOperations> {
313
+ throw new Error('MockCheckpointsBuilder.getFork not implemented');
314
+ }
315
+
316
+ /** Reset for reuse in another test */
317
+ reset(): void {
318
+ this.checkpointBuilder = undefined;
319
+ this.startCheckpointCalls = [];
320
+ this.openCheckpointCalls = [];
321
+ this.updateConfigCalls = [];
322
+ }
323
+ }
@@ -0,0 +1,218 @@
1
+ import { Body } from '@aztec/aztec.js/block';
2
+ import { CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
3
+ import { times } from '@aztec/foundation/collection';
4
+ import { Secp256k1Signer } from '@aztec/foundation/crypto/secp256k1-signer';
5
+ import { Fr } from '@aztec/foundation/curves/bn254';
6
+ import type { EthAddress } from '@aztec/foundation/eth-address';
7
+ import { Signature } from '@aztec/foundation/eth-signature';
8
+ import type { P2P } from '@aztec/p2p';
9
+ import { PublicDataWrite } from '@aztec/stdlib/avm';
10
+ import { CommitteeAttestation, L2Block } from '@aztec/stdlib/block';
11
+ import { DEFAULT_BLOCK_DURATION_MS } from '@aztec/stdlib/config';
12
+ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
13
+ import { BlockProposal, CheckpointAttestation, CheckpointProposal, ConsensusPayload } from '@aztec/stdlib/p2p';
14
+ import { CheckpointHeader } from '@aztec/stdlib/rollup';
15
+ import {
16
+ TEST_COORDINATION_SIGNATURE_CONTEXT,
17
+ makeAppendOnlyTreeSnapshot,
18
+ mockTxForRollup,
19
+ } from '@aztec/stdlib/testing';
20
+ import {
21
+ DEFAULT_CHECKPOINT_PROPOSAL_INIT_TIME,
22
+ DEFAULT_CHECKPOINT_PROPOSAL_PREPARE_TIME,
23
+ DEFAULT_MIN_BLOCK_DURATION,
24
+ DEFAULT_P2P_PROPAGATION_TIME,
25
+ ProposerTimetable,
26
+ } from '@aztec/stdlib/timetable';
27
+ import { BlockHeader, GlobalVariables, type Tx, makeProcessedTxFromPrivateOnlyTx } from '@aztec/stdlib/tx';
28
+
29
+ import type { MockProxy } from 'jest-mock-extended';
30
+
31
+ // Re-export mock classes from their dedicated file
32
+ export { MockCheckpointBuilder, MockCheckpointsBuilder } from './mock_checkpoint_builder.js';
33
+
34
+ /**
35
+ * Builds a {@link ProposerTimetable} for tests from a millisecond block duration and optional budgets,
36
+ * filling unset budgets with the shared `DEFAULT_*` values the sequencer config layer applies. Mirrors how
37
+ * the sequencer constructs its timetable so tests exercise the same budget resolution.
38
+ */
39
+ export function makeProposerTimetable(opts: {
40
+ l1Constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration' | 'ethereumSlotDuration'>;
41
+ blockDurationMs?: number;
42
+ minBlockDuration?: number;
43
+ p2pPropagationTime?: number;
44
+ checkpointProposalPrepareTime?: number;
45
+ }): ProposerTimetable {
46
+ return new ProposerTimetable({
47
+ l1Constants: opts.l1Constants,
48
+ blockDuration: (opts.blockDurationMs ?? DEFAULT_BLOCK_DURATION_MS) / 1000,
49
+ minBlockDuration: opts.minBlockDuration ?? DEFAULT_MIN_BLOCK_DURATION,
50
+ p2pPropagationTime: opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME,
51
+ checkpointProposalPrepareTime: opts.checkpointProposalPrepareTime ?? DEFAULT_CHECKPOINT_PROPOSAL_PREPARE_TIME,
52
+ checkpointProposalInitTime: DEFAULT_CHECKPOINT_PROPOSAL_INIT_TIME,
53
+ });
54
+ }
55
+
56
+ /**
57
+ * Creates a mock transaction with a specific seed for deterministic testing
58
+ */
59
+ export async function makeTx(seed?: number, chainId?: Fr): Promise<Tx> {
60
+ const tx = await mockTxForRollup(seed);
61
+ if (chainId) {
62
+ tx.data.constants.txContext.chainId = chainId;
63
+ }
64
+ return tx;
65
+ }
66
+
67
+ /**
68
+ * Creates an L2Block from transactions and global variables
69
+ */
70
+ export async function makeBlock(txs: Tx[], globalVariables: GlobalVariables): Promise<L2Block> {
71
+ const processedTxs = await Promise.all(
72
+ txs.map(tx =>
73
+ makeProcessedTxFromPrivateOnlyTx(tx, Fr.ZERO, new PublicDataWrite(Fr.random(), Fr.random()), globalVariables),
74
+ ),
75
+ );
76
+ const body = new Body(processedTxs.map(tx => tx.txEffect));
77
+ const header = BlockHeader.empty({ globalVariables });
78
+ const archive = makeAppendOnlyTreeSnapshot(globalVariables.blockNumber + 1);
79
+ return new L2Block(
80
+ archive,
81
+ header,
82
+ body,
83
+ CheckpointNumber.fromBlockNumber(globalVariables.blockNumber),
84
+ IndexWithinCheckpoint(0),
85
+ );
86
+ }
87
+
88
+ /**
89
+ * Mocks the P2P client to return specific pending transactions
90
+ */
91
+ export function mockPendingTxs(p2p: MockProxy<P2P>, txs: Tx[]): void {
92
+ p2p.getPendingTxCount.mockResolvedValue(txs.length);
93
+ p2p.hasEligiblePendingTxs.mockImplementation(minCount => Promise.resolve(txs.length >= minCount));
94
+ p2p.iteratePendingTxs.mockImplementation(() => mockTxIterator(Promise.resolve(txs)));
95
+ p2p.iterateEligiblePendingTxs.mockImplementation(() => mockTxIterator(Promise.resolve(txs)));
96
+ }
97
+
98
+ /**
99
+ * Creates an async iterator for transactions
100
+ */
101
+ export async function* mockTxIterator(txs: Promise<Tx[]>): AsyncIterableIterator<Tx> {
102
+ for (const tx of await txs) {
103
+ yield tx;
104
+ }
105
+ }
106
+
107
+ /**
108
+ * Creates mock committee attestations from a signer
109
+ */
110
+ export function createMockSignatures(signer: Secp256k1Signer): CommitteeAttestation[] {
111
+ const mockedSig = Signature.random();
112
+ return [new CommitteeAttestation(signer.address, mockedSig)];
113
+ }
114
+
115
+ /**
116
+ * Creates a CheckpointHeader from an L2Block for testing purposes.
117
+ * Uses mock values for blockHeadersHash, blobsHash and inHash since L2Block doesn't have these fields.
118
+ */
119
+ function createCheckpointHeaderFromBlock(block: L2Block): CheckpointHeader {
120
+ const gv = block.header.globalVariables;
121
+ return new CheckpointHeader(
122
+ block.header.lastArchive.root,
123
+ Fr.random(), // blockHeadersHash - mock value for testing
124
+ Fr.random(), // blobsHash - mock value for testing
125
+ Fr.random(), // inHash - mock value for testing
126
+ Fr.random(), // outHash - mock value for testing
127
+ gv.slotNumber,
128
+ gv.timestamp,
129
+ gv.coinbase,
130
+ gv.feeRecipient,
131
+ gv.gasFees,
132
+ block.header.totalManaUsed,
133
+ block.header.totalFees,
134
+ );
135
+ }
136
+
137
+ /**
138
+ * Creates a block proposal from a block and signature
139
+ */
140
+ export function createBlockProposal(block: L2Block, signature: Signature): BlockProposal {
141
+ const txHashes = block.body.txEffects.map(tx => tx.txHash);
142
+ return new BlockProposal(
143
+ block.header,
144
+ block.indexWithinCheckpoint,
145
+ Fr.ZERO, // inHash - using zero for testing
146
+ block.archive.root,
147
+ txHashes,
148
+ signature,
149
+ TEST_COORDINATION_SIGNATURE_CONTEXT,
150
+ );
151
+ }
152
+
153
+ /**
154
+ * Creates a checkpoint proposal from a block and signature
155
+ */
156
+ export function createCheckpointProposal(
157
+ block: L2Block,
158
+ checkpointSignature: Signature,
159
+ blockSignature?: Signature,
160
+ feeAssetPriceModifier: bigint = 0n,
161
+ ): CheckpointProposal {
162
+ const txHashes = block.body.txEffects.map(tx => tx.txHash);
163
+ const checkpointHeader = createCheckpointHeaderFromBlock(block);
164
+ return new CheckpointProposal(
165
+ checkpointHeader,
166
+ block.archive.root,
167
+ feeAssetPriceModifier,
168
+ checkpointSignature,
169
+ TEST_COORDINATION_SIGNATURE_CONTEXT,
170
+ {
171
+ blockHeader: block.header,
172
+ indexWithinCheckpoint: block.indexWithinCheckpoint,
173
+ txHashes,
174
+ signature: blockSignature ?? checkpointSignature, // Use checkpoint signature as block signature if not provided
175
+ },
176
+ );
177
+ }
178
+
179
+ /**
180
+ * Creates a checkpoint attestation from a block and signature.
181
+ * Note: We manually set the sender since we use random signatures in tests.
182
+ * In production, the sender is recovered from the signature.
183
+ */
184
+ export function createCheckpointAttestation(
185
+ block: L2Block,
186
+ signature: Signature,
187
+ sender: EthAddress,
188
+ feeAssetPriceModifier: bigint = 0n,
189
+ ): CheckpointAttestation {
190
+ const checkpointHeader = createCheckpointHeaderFromBlock(block);
191
+ const payload = new ConsensusPayload(
192
+ checkpointHeader,
193
+ block.archive.root,
194
+ feeAssetPriceModifier,
195
+ TEST_COORDINATION_SIGNATURE_CONTEXT,
196
+ );
197
+ const attestation = new CheckpointAttestation(payload, signature, signature);
198
+ // Bypass signature recovery for testing since we use random signatures
199
+ (attestation as any).getSender = () => sender;
200
+ (attestation as any).getProposer = () => sender;
201
+ return attestation;
202
+ }
203
+
204
+ /**
205
+ * Creates transactions and a block, and mocks P2P to return them.
206
+ * Helper for tests that need to set up a block with transactions.
207
+ */
208
+ export async function setupTxsAndBlock(
209
+ p2p: MockProxy<P2P>,
210
+ globalVariables: GlobalVariables,
211
+ txCount: number,
212
+ chainId: Fr,
213
+ ): Promise<{ txs: Tx[]; block: L2Block }> {
214
+ const txs = await Promise.all(times(txCount, i => makeTx(i + 1, chainId)));
215
+ const block = await makeBlock(txs, globalVariables);
216
+ mockPendingTxs(p2p, txs);
217
+ return { txs, block };
218
+ }
@@ -1,27 +0,0 @@
1
- import type { Fr } from '@aztec/foundation/fields';
2
- import { DateProvider } from '@aztec/foundation/timer';
3
- import { PublicProcessor } from '@aztec/simulator/server';
4
- import type { ContractDataSource } from '@aztec/stdlib/contract';
5
- import { type L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
6
- import type { BuildBlockResult, FullNodeBlockBuilderConfig, IFullNodeBlockBuilder, MerkleTreeWriteOperations, PublicProcessorLimits, PublicProcessorValidator, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
7
- import { GlobalVariables, Tx } from '@aztec/stdlib/tx';
8
- import { type TelemetryClient } from '@aztec/telemetry-client';
9
- export declare function buildBlock(pendingTxs: Iterable<Tx> | AsyncIterable<Tx>, l1ToL2Messages: Fr[], newGlobalVariables: GlobalVariables, opts: PublicProcessorLimits | undefined, worldStateFork: MerkleTreeWriteOperations, processor: PublicProcessor, validator: PublicProcessorValidator, l1Constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration'>, dateProvider: DateProvider, telemetryClient?: TelemetryClient): Promise<BuildBlockResult>;
10
- export declare class FullNodeBlockBuilder implements IFullNodeBlockBuilder {
11
- private config;
12
- private worldState;
13
- private contractDataSource;
14
- private dateProvider;
15
- private telemetryClient;
16
- constructor(config: FullNodeBlockBuilderConfig, worldState: WorldStateSynchronizer, contractDataSource: ContractDataSource, dateProvider: DateProvider, telemetryClient?: TelemetryClient);
17
- getConfig(): FullNodeBlockBuilderConfig;
18
- updateConfig(config: Partial<FullNodeBlockBuilderConfig>): void;
19
- makeBlockBuilderDeps(globalVariables: GlobalVariables, fork: MerkleTreeWriteOperations): Promise<{
20
- processor: PublicProcessor;
21
- validator: PublicProcessorValidator;
22
- }>;
23
- private syncToPreviousBlock;
24
- buildBlock(pendingTxs: Iterable<Tx> | AsyncIterable<Tx>, l1ToL2Messages: Fr[], globalVariables: GlobalVariables, opts: PublicProcessorLimits, suppliedFork?: MerkleTreeWriteOperations): Promise<BuildBlockResult>;
25
- getFork(blockNumber: number): Promise<MerkleTreeWriteOperations>;
26
- }
27
- //# sourceMappingURL=block_builder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"block_builder.d.ts","sourceRoot":"","sources":["../../src/sequencer/block_builder.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAInD,OAAO,EAAE,YAAY,EAAkB,MAAM,yBAAyB,CAAC;AAGvE,OAAO,EAGL,eAAe,EAEhB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,KAAK,iBAAiB,EAAuB,MAAM,6BAA6B,CAAC;AAE1F,OAAO,KAAK,EACV,gBAAgB,EAChB,0BAA0B,EAC1B,qBAAqB,EACrB,yBAAyB,EACzB,qBAAqB,EACrB,wBAAwB,EACxB,sBAAsB,EACvB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,yBAAyB,CAAC;AAMnF,wBAAsB,UAAU,CAC9B,UAAU,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,EAAE,CAAC,EAC5C,cAAc,EAAE,EAAE,EAAE,EACpB,kBAAkB,EAAE,eAAe,EACnC,IAAI,EAAE,qBAAqB,YAAK,EAChC,cAAc,EAAE,yBAAyB,EACzC,SAAS,EAAE,eAAe,EAC1B,SAAS,EAAE,wBAAwB,EACnC,WAAW,EAAE,IAAI,CAAC,iBAAiB,EAAE,eAAe,GAAG,cAAc,CAAC,EACtE,YAAY,EAAE,YAAY,EAC1B,eAAe,GAAE,eAAsC,GACtD,OAAO,CAAC,gBAAgB,CAAC,CA4C3B;AAWD,qBAAa,oBAAqB,YAAW,qBAAqB;IAE9D,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,kBAAkB;IAC1B,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,eAAe;gBAJf,MAAM,EAAE,0BAA0B,EAClC,UAAU,EAAE,sBAAsB,EAClC,kBAAkB,EAAE,kBAAkB,EACtC,YAAY,EAAE,YAAY,EAC1B,eAAe,GAAE,eAAsC;IAG1D,SAAS,IAAI,0BAA0B;IAIvC,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,0BAA0B,CAAC;IAIlD,oBAAoB,CAAC,eAAe,EAAE,eAAe,EAAE,IAAI,EAAE,yBAAyB;;;;YAyCrF,mBAAmB;IAU3B,UAAU,CACd,UAAU,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,EAAE,CAAC,EAC5C,cAAc,EAAE,EAAE,EAAE,EACpB,eAAe,EAAE,eAAe,EAChC,IAAI,EAAE,qBAAqB,EAC3B,YAAY,CAAC,EAAE,yBAAyB,GACvC,OAAO,CAAC,gBAAgB,CAAC;IAwC5B,OAAO,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,yBAAyB,CAAC;CAGjE"}