@aztec/sequencer-client 0.0.0-test.1 → 0.0.1-commit.0b941701

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 (135) hide show
  1. package/dest/client/index.d.ts +1 -1
  2. package/dest/client/sequencer-client.d.ts +31 -31
  3. package/dest/client/sequencer-client.d.ts.map +1 -1
  4. package/dest/client/sequencer-client.js +82 -60
  5. package/dest/config.d.ts +15 -16
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +118 -70
  8. package/dest/global_variable_builder/global_builder.d.ts +26 -15
  9. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  10. package/dest/global_variable_builder/global_builder.js +62 -44
  11. package/dest/global_variable_builder/index.d.ts +1 -1
  12. package/dest/index.d.ts +2 -4
  13. package/dest/index.d.ts.map +1 -1
  14. package/dest/index.js +1 -3
  15. package/dest/publisher/config.d.ts +15 -12
  16. package/dest/publisher/config.d.ts.map +1 -1
  17. package/dest/publisher/config.js +32 -19
  18. package/dest/publisher/index.d.ts +3 -1
  19. package/dest/publisher/index.d.ts.map +1 -1
  20. package/dest/publisher/index.js +3 -0
  21. package/dest/publisher/sequencer-publisher-factory.d.ts +44 -0
  22. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -0
  23. package/dest/publisher/sequencer-publisher-factory.js +51 -0
  24. package/dest/publisher/sequencer-publisher-metrics.d.ts +5 -4
  25. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  26. package/dest/publisher/sequencer-publisher-metrics.js +26 -62
  27. package/dest/publisher/sequencer-publisher.d.ts +134 -87
  28. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  29. package/dest/publisher/sequencer-publisher.js +1146 -249
  30. package/dest/sequencer/checkpoint_proposal_job.d.ts +79 -0
  31. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  32. package/dest/sequencer/checkpoint_proposal_job.js +1165 -0
  33. package/dest/sequencer/checkpoint_voter.d.ts +35 -0
  34. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  35. package/dest/sequencer/checkpoint_voter.js +109 -0
  36. package/dest/sequencer/config.d.ts +7 -1
  37. package/dest/sequencer/config.d.ts.map +1 -1
  38. package/dest/sequencer/errors.d.ts +11 -0
  39. package/dest/sequencer/errors.d.ts.map +1 -0
  40. package/dest/sequencer/errors.js +15 -0
  41. package/dest/sequencer/events.d.ts +46 -0
  42. package/dest/sequencer/events.d.ts.map +1 -0
  43. package/dest/sequencer/events.js +1 -0
  44. package/dest/sequencer/index.d.ts +4 -2
  45. package/dest/sequencer/index.d.ts.map +1 -1
  46. package/dest/sequencer/index.js +3 -1
  47. package/dest/sequencer/metrics.d.ts +48 -12
  48. package/dest/sequencer/metrics.d.ts.map +1 -1
  49. package/dest/sequencer/metrics.js +204 -69
  50. package/dest/sequencer/sequencer.d.ts +144 -137
  51. package/dest/sequencer/sequencer.d.ts.map +1 -1
  52. package/dest/sequencer/sequencer.js +967 -525
  53. package/dest/sequencer/timetable.d.ts +76 -24
  54. package/dest/sequencer/timetable.d.ts.map +1 -1
  55. package/dest/sequencer/timetable.js +177 -61
  56. package/dest/sequencer/types.d.ts +3 -0
  57. package/dest/sequencer/types.d.ts.map +1 -0
  58. package/dest/sequencer/types.js +1 -0
  59. package/dest/sequencer/utils.d.ts +20 -38
  60. package/dest/sequencer/utils.d.ts.map +1 -1
  61. package/dest/sequencer/utils.js +12 -47
  62. package/dest/test/index.d.ts +9 -1
  63. package/dest/test/index.d.ts.map +1 -1
  64. package/dest/test/index.js +0 -4
  65. package/dest/test/mock_checkpoint_builder.d.ts +95 -0
  66. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  67. package/dest/test/mock_checkpoint_builder.js +222 -0
  68. package/dest/test/utils.d.ts +53 -0
  69. package/dest/test/utils.d.ts.map +1 -0
  70. package/dest/test/utils.js +103 -0
  71. package/package.json +47 -45
  72. package/src/client/sequencer-client.ts +106 -107
  73. package/src/config.ts +131 -81
  74. package/src/global_variable_builder/global_builder.ts +84 -55
  75. package/src/index.ts +1 -3
  76. package/src/publisher/config.ts +45 -32
  77. package/src/publisher/index.ts +4 -0
  78. package/src/publisher/sequencer-publisher-factory.ts +92 -0
  79. package/src/publisher/sequencer-publisher-metrics.ts +30 -64
  80. package/src/publisher/sequencer-publisher.ts +967 -295
  81. package/src/sequencer/README.md +531 -0
  82. package/src/sequencer/checkpoint_proposal_job.ts +845 -0
  83. package/src/sequencer/checkpoint_voter.ts +130 -0
  84. package/src/sequencer/config.ts +8 -0
  85. package/src/sequencer/errors.ts +21 -0
  86. package/src/sequencer/events.ts +27 -0
  87. package/src/sequencer/index.ts +3 -1
  88. package/src/sequencer/metrics.ts +269 -72
  89. package/src/sequencer/sequencer.ts +708 -588
  90. package/src/sequencer/timetable.ts +221 -62
  91. package/src/sequencer/types.ts +6 -0
  92. package/src/sequencer/utils.ts +28 -60
  93. package/src/test/index.ts +12 -4
  94. package/src/test/mock_checkpoint_builder.ts +311 -0
  95. package/src/test/utils.ts +164 -0
  96. package/dest/sequencer/allowed.d.ts +0 -3
  97. package/dest/sequencer/allowed.d.ts.map +0 -1
  98. package/dest/sequencer/allowed.js +0 -27
  99. package/dest/slasher/factory.d.ts +0 -7
  100. package/dest/slasher/factory.d.ts.map +0 -1
  101. package/dest/slasher/factory.js +0 -8
  102. package/dest/slasher/index.d.ts +0 -3
  103. package/dest/slasher/index.d.ts.map +0 -1
  104. package/dest/slasher/index.js +0 -2
  105. package/dest/slasher/slasher_client.d.ts +0 -75
  106. package/dest/slasher/slasher_client.d.ts.map +0 -1
  107. package/dest/slasher/slasher_client.js +0 -132
  108. package/dest/tx_validator/archive_cache.d.ts +0 -14
  109. package/dest/tx_validator/archive_cache.d.ts.map +0 -1
  110. package/dest/tx_validator/archive_cache.js +0 -22
  111. package/dest/tx_validator/gas_validator.d.ts +0 -14
  112. package/dest/tx_validator/gas_validator.d.ts.map +0 -1
  113. package/dest/tx_validator/gas_validator.js +0 -78
  114. package/dest/tx_validator/nullifier_cache.d.ts +0 -16
  115. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  116. package/dest/tx_validator/nullifier_cache.js +0 -24
  117. package/dest/tx_validator/phases_validator.d.ts +0 -12
  118. package/dest/tx_validator/phases_validator.d.ts.map +0 -1
  119. package/dest/tx_validator/phases_validator.js +0 -80
  120. package/dest/tx_validator/test_utils.d.ts +0 -23
  121. package/dest/tx_validator/test_utils.d.ts.map +0 -1
  122. package/dest/tx_validator/test_utils.js +0 -26
  123. package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
  124. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  125. package/dest/tx_validator/tx_validator_factory.js +0 -50
  126. package/src/sequencer/allowed.ts +0 -36
  127. package/src/slasher/factory.ts +0 -15
  128. package/src/slasher/index.ts +0 -2
  129. package/src/slasher/slasher_client.ts +0 -193
  130. package/src/tx_validator/archive_cache.ts +0 -28
  131. package/src/tx_validator/gas_validator.ts +0 -101
  132. package/src/tx_validator/nullifier_cache.ts +0 -30
  133. package/src/tx_validator/phases_validator.ts +0 -98
  134. package/src/tx_validator/test_utils.ts +0 -48
  135. package/src/tx_validator/tx_validator_factory.ts +0 -120
@@ -0,0 +1,311 @@
1
+ import { type BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
+ import { Timer } from '@aztec/foundation/timer';
4
+ import { L2Block } from '@aztec/stdlib/block';
5
+ import { Checkpoint } from '@aztec/stdlib/checkpoint';
6
+ import { Gas } from '@aztec/stdlib/gas';
7
+ import type {
8
+ FullNodeBlockBuilderConfig,
9
+ ICheckpointBlockBuilder,
10
+ ICheckpointsBuilder,
11
+ MerkleTreeWriteOperations,
12
+ PublicProcessorLimits,
13
+ } from '@aztec/stdlib/interfaces/server';
14
+ import { CheckpointHeader } from '@aztec/stdlib/rollup';
15
+ import { makeAppendOnlyTreeSnapshot } from '@aztec/stdlib/testing';
16
+ import type { CheckpointGlobalVariables, Tx } from '@aztec/stdlib/tx';
17
+ import type { BuildBlockInCheckpointResultWithTimer } from '@aztec/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: PublicProcessorLimits;
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: PublicProcessorLimits,
79
+ ): Promise<BuildBlockInCheckpointResultWithTimer> {
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
91
+ block = this.blockProvider();
92
+ usedTxs = [];
93
+ this.builtBlocks.push(block);
94
+ } else {
95
+ // Seeded mode: get block from pre-seeded list
96
+ block = this.blocks[this.blockIndex];
97
+ usedTxs = this.usedTxsPerBlock[this.blockIndex] ?? [];
98
+ this.blockIndex++;
99
+ this.builtBlocks.push(block);
100
+ }
101
+
102
+ // Check that no pending tx has already been consumed
103
+ for await (const tx of pendingTxs) {
104
+ const hash = tx.getTxHash().toString();
105
+ if (this.consumedTxHashes.has(hash)) {
106
+ throw new Error(`Transaction ${hash} was already consumed in a previous block`);
107
+ }
108
+ }
109
+
110
+ // Add used txs to consumed set
111
+ for (const tx of usedTxs) {
112
+ this.consumedTxHashes.add(tx.getTxHash().toString());
113
+ }
114
+
115
+ return {
116
+ block,
117
+ publicGas: Gas.empty(),
118
+ publicProcessorDuration: 0,
119
+ numTxs: block?.body?.txEffects?.length ?? usedTxs.length,
120
+ blockBuildingTimer: new Timer(),
121
+ usedTxs,
122
+ failedTxs: [],
123
+ usedTxBlobFields: block?.body?.txEffects?.reduce((sum, tx) => sum + tx.getNumBlobFields(), 0) ?? 0,
124
+ };
125
+ }
126
+
127
+ completeCheckpoint(): Promise<Checkpoint> {
128
+ this.completeCheckpointCalled = true;
129
+ const allBlocks = this.blockProvider ? this.builtBlocks : this.blocks;
130
+ const lastBlock = allBlocks[allBlocks.length - 1];
131
+ // Create a CheckpointHeader from the last block's header for testing
132
+ const checkpointHeader = this.createCheckpointHeader(lastBlock);
133
+ return Promise.resolve(
134
+ new Checkpoint(
135
+ makeAppendOnlyTreeSnapshot(lastBlock.header.globalVariables.blockNumber + 1),
136
+ checkpointHeader,
137
+ allBlocks,
138
+ this.checkpointNumber,
139
+ ),
140
+ );
141
+ }
142
+
143
+ getCheckpoint(): Promise<Checkpoint> {
144
+ this.getCheckpointCalled = true;
145
+ const builtBlocks = this.blockProvider ? this.builtBlocks : this.blocks.slice(0, this.blockIndex);
146
+ const lastBlock = builtBlocks[builtBlocks.length - 1];
147
+ if (!lastBlock) {
148
+ throw new Error('No blocks built yet');
149
+ }
150
+ // Create a CheckpointHeader from the last block's header for testing
151
+ const checkpointHeader = this.createCheckpointHeader(lastBlock);
152
+ return Promise.resolve(
153
+ new Checkpoint(
154
+ makeAppendOnlyTreeSnapshot(lastBlock.header.globalVariables.blockNumber + 1),
155
+ checkpointHeader,
156
+ builtBlocks,
157
+ this.checkpointNumber,
158
+ ),
159
+ );
160
+ }
161
+
162
+ /**
163
+ * Creates a CheckpointHeader from a block's header for testing.
164
+ * This is a simplified version that creates a minimal CheckpointHeader.
165
+ */
166
+ private createCheckpointHeader(block: L2Block): CheckpointHeader {
167
+ const header = block.header;
168
+ const gv = header.globalVariables;
169
+ return CheckpointHeader.empty({
170
+ lastArchiveRoot: header.lastArchive.root,
171
+ blockHeadersHash: Fr.random(), // Use random for testing
172
+ slotNumber: gv.slotNumber,
173
+ timestamp: gv.timestamp,
174
+ coinbase: gv.coinbase,
175
+ feeRecipient: gv.feeRecipient,
176
+ gasFees: gv.gasFees,
177
+ totalManaUsed: header.totalManaUsed,
178
+ });
179
+ }
180
+
181
+ /** Reset for reuse in another test */
182
+ reset(): void {
183
+ this.blocks = [];
184
+ this.builtBlocks = [];
185
+ this.usedTxsPerBlock = [];
186
+ this.blockIndex = 0;
187
+ this.buildBlockCalls = [];
188
+ this.consumedTxHashes.clear();
189
+ this.completeCheckpointCalled = false;
190
+ this.getCheckpointCalled = false;
191
+ this.errorOnBuild = undefined;
192
+ this.blockProvider = undefined;
193
+ }
194
+ }
195
+
196
+ /**
197
+ * A fake CheckpointsBuilder (factory) for testing that implements the same interface
198
+ * as FullNodeCheckpointsBuilder. Returns MockCheckpointBuilder instances.
199
+ * Does NOT use jest mocks - this is a proper test double.
200
+ */
201
+ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
202
+ private checkpointBuilder: MockCheckpointBuilder | undefined;
203
+
204
+ /** Track calls for assertions */
205
+ public startCheckpointCalls: Array<{
206
+ checkpointNumber: CheckpointNumber;
207
+ constants: CheckpointGlobalVariables;
208
+ l1ToL2Messages: Fr[];
209
+ previousCheckpointOutHashes: Fr[];
210
+ }> = [];
211
+ public openCheckpointCalls: Array<{
212
+ checkpointNumber: CheckpointNumber;
213
+ constants: CheckpointGlobalVariables;
214
+ l1ToL2Messages: Fr[];
215
+ previousCheckpointOutHashes: Fr[];
216
+ existingBlocks: L2Block[];
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
+ };
253
+ }
254
+
255
+ updateConfig(config: Partial<FullNodeBlockBuilderConfig>): void {
256
+ this.updateConfigCalls.push(config);
257
+ }
258
+
259
+ startCheckpoint(
260
+ checkpointNumber: CheckpointNumber,
261
+ constants: CheckpointGlobalVariables,
262
+ l1ToL2Messages: Fr[],
263
+ previousCheckpointOutHashes: Fr[],
264
+ _fork: MerkleTreeWriteOperations,
265
+ ): Promise<ICheckpointBlockBuilder> {
266
+ this.startCheckpointCalls.push({ checkpointNumber, constants, l1ToL2Messages, previousCheckpointOutHashes });
267
+
268
+ if (!this.checkpointBuilder) {
269
+ // Auto-create a builder if none was set
270
+ this.checkpointBuilder = new MockCheckpointBuilder(constants, checkpointNumber);
271
+ }
272
+
273
+ return Promise.resolve(this.checkpointBuilder);
274
+ }
275
+
276
+ openCheckpoint(
277
+ checkpointNumber: CheckpointNumber,
278
+ constants: CheckpointGlobalVariables,
279
+ l1ToL2Messages: Fr[],
280
+ previousCheckpointOutHashes: Fr[],
281
+ _fork: MerkleTreeWriteOperations,
282
+ existingBlocks: L2Block[] = [],
283
+ ): Promise<ICheckpointBlockBuilder> {
284
+ this.openCheckpointCalls.push({
285
+ checkpointNumber,
286
+ constants,
287
+ l1ToL2Messages,
288
+ previousCheckpointOutHashes,
289
+ existingBlocks,
290
+ });
291
+
292
+ if (!this.checkpointBuilder) {
293
+ // Auto-create a builder if none was set
294
+ this.checkpointBuilder = new MockCheckpointBuilder(constants, checkpointNumber);
295
+ }
296
+
297
+ return Promise.resolve(this.checkpointBuilder);
298
+ }
299
+
300
+ getFork(_blockNumber: BlockNumber): Promise<MerkleTreeWriteOperations> {
301
+ throw new Error('MockCheckpointsBuilder.getFork not implemented');
302
+ }
303
+
304
+ /** Reset for reuse in another test */
305
+ reset(): void {
306
+ this.checkpointBuilder = undefined;
307
+ this.startCheckpointCalls = [];
308
+ this.openCheckpointCalls = [];
309
+ this.updateConfigCalls = [];
310
+ }
311
+ }
@@ -0,0 +1,164 @@
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 { BlockProposal, CheckpointAttestation, CheckpointProposal, ConsensusPayload } from '@aztec/stdlib/p2p';
12
+ import { CheckpointHeader } from '@aztec/stdlib/rollup';
13
+ import { makeAppendOnlyTreeSnapshot, mockTxForRollup } from '@aztec/stdlib/testing';
14
+ import { BlockHeader, GlobalVariables, type Tx, makeProcessedTxFromPrivateOnlyTx } from '@aztec/stdlib/tx';
15
+
16
+ import type { MockProxy } from 'jest-mock-extended';
17
+
18
+ // Re-export mock classes from their dedicated file
19
+ export { MockCheckpointBuilder, MockCheckpointsBuilder } from './mock_checkpoint_builder.js';
20
+
21
+ /**
22
+ * Creates a mock transaction with a specific seed for deterministic testing
23
+ */
24
+ export async function makeTx(seed?: number, chainId?: Fr): Promise<Tx> {
25
+ const tx = await mockTxForRollup(seed);
26
+ if (chainId) {
27
+ tx.data.constants.txContext.chainId = chainId;
28
+ }
29
+ return tx;
30
+ }
31
+
32
+ /**
33
+ * Creates an L2Block from transactions and global variables
34
+ */
35
+ export async function makeBlock(txs: Tx[], globalVariables: GlobalVariables): Promise<L2Block> {
36
+ const processedTxs = await Promise.all(
37
+ txs.map(tx =>
38
+ makeProcessedTxFromPrivateOnlyTx(tx, Fr.ZERO, new PublicDataWrite(Fr.random(), Fr.random()), globalVariables),
39
+ ),
40
+ );
41
+ const body = new Body(processedTxs.map(tx => tx.txEffect));
42
+ const header = BlockHeader.empty({ globalVariables });
43
+ const archive = makeAppendOnlyTreeSnapshot(globalVariables.blockNumber + 1);
44
+ return new L2Block(
45
+ archive,
46
+ header,
47
+ body,
48
+ CheckpointNumber.fromBlockNumber(globalVariables.blockNumber),
49
+ IndexWithinCheckpoint(0),
50
+ );
51
+ }
52
+
53
+ /**
54
+ * Mocks the P2P client to return specific pending transactions
55
+ */
56
+ export function mockPendingTxs(p2p: MockProxy<P2P>, txs: Tx[]): void {
57
+ p2p.getPendingTxCount.mockResolvedValue(txs.length);
58
+ p2p.iteratePendingTxs.mockImplementation(() => mockTxIterator(Promise.resolve(txs)));
59
+ }
60
+
61
+ /**
62
+ * Creates an async iterator for transactions
63
+ */
64
+ export async function* mockTxIterator(txs: Promise<Tx[]>): AsyncIterableIterator<Tx> {
65
+ for (const tx of await txs) {
66
+ yield tx;
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Creates mock committee attestations from a signer
72
+ */
73
+ export function createMockSignatures(signer: Secp256k1Signer): CommitteeAttestation[] {
74
+ const mockedSig = Signature.random();
75
+ return [new CommitteeAttestation(signer.address, mockedSig)];
76
+ }
77
+
78
+ /**
79
+ * Creates a CheckpointHeader from an L2Block for testing purposes.
80
+ * Uses mock values for blockHeadersHash, blobsHash and inHash since L2Block doesn't have these fields.
81
+ */
82
+ function createCheckpointHeaderFromBlock(block: L2Block): CheckpointHeader {
83
+ const gv = block.header.globalVariables;
84
+ return new CheckpointHeader(
85
+ block.header.lastArchive.root,
86
+ Fr.random(), // blockHeadersHash - mock value for testing
87
+ Fr.random(), // blobsHash - mock value for testing
88
+ Fr.random(), // inHash - mock value for testing
89
+ Fr.random(), // outHash - mock value for testing
90
+ gv.slotNumber,
91
+ gv.timestamp,
92
+ gv.coinbase,
93
+ gv.feeRecipient,
94
+ gv.gasFees,
95
+ block.header.totalManaUsed,
96
+ );
97
+ }
98
+
99
+ /**
100
+ * Creates a block proposal from a block and signature
101
+ */
102
+ export function createBlockProposal(block: L2Block, signature: Signature): BlockProposal {
103
+ const txHashes = block.body.txEffects.map(tx => tx.txHash);
104
+ return new BlockProposal(
105
+ block.header,
106
+ block.indexWithinCheckpoint,
107
+ Fr.ZERO, // inHash - using zero for testing
108
+ block.archive.root,
109
+ txHashes,
110
+ signature,
111
+ );
112
+ }
113
+
114
+ /**
115
+ * Creates a checkpoint proposal from a block and signature
116
+ */
117
+ export function createCheckpointProposal(
118
+ block: L2Block,
119
+ checkpointSignature: Signature,
120
+ blockSignature?: Signature,
121
+ ): CheckpointProposal {
122
+ const txHashes = block.body.txEffects.map(tx => tx.txHash);
123
+ const checkpointHeader = createCheckpointHeaderFromBlock(block);
124
+ return new CheckpointProposal(checkpointHeader, block.archive.root, checkpointSignature, {
125
+ blockHeader: block.header,
126
+ indexWithinCheckpoint: block.indexWithinCheckpoint,
127
+ txHashes,
128
+ signature: blockSignature ?? checkpointSignature, // Use checkpoint signature as block signature if not provided
129
+ });
130
+ }
131
+
132
+ /**
133
+ * Creates a checkpoint attestation from a block and signature.
134
+ * Note: We manually set the sender since we use random signatures in tests.
135
+ * In production, the sender is recovered from the signature.
136
+ */
137
+ export function createCheckpointAttestation(
138
+ block: L2Block,
139
+ signature: Signature,
140
+ sender: EthAddress,
141
+ ): CheckpointAttestation {
142
+ const checkpointHeader = createCheckpointHeaderFromBlock(block);
143
+ const payload = new ConsensusPayload(checkpointHeader, block.archive.root);
144
+ const attestation = new CheckpointAttestation(payload, signature, signature);
145
+ // Set sender directly for testing (bypasses signature recovery)
146
+ (attestation as any).sender = sender;
147
+ return attestation;
148
+ }
149
+
150
+ /**
151
+ * Creates transactions and a block, and mocks P2P to return them.
152
+ * Helper for tests that need to set up a block with transactions.
153
+ */
154
+ export async function setupTxsAndBlock(
155
+ p2p: MockProxy<P2P>,
156
+ globalVariables: GlobalVariables,
157
+ txCount: number,
158
+ chainId: Fr,
159
+ ): Promise<{ txs: Tx[]; block: L2Block }> {
160
+ const txs = await Promise.all(times(txCount, i => makeTx(i + 1, chainId)));
161
+ const block = await makeBlock(txs, globalVariables);
162
+ mockPendingTxs(p2p, txs);
163
+ return { txs, block };
164
+ }
@@ -1,3 +0,0 @@
1
- import type { AllowedElement } from '@aztec/stdlib/interfaces/server';
2
- export declare function getDefaultAllowedSetupFunctions(): Promise<AllowedElement[]>;
3
- //# sourceMappingURL=allowed.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"allowed.d.ts","sourceRoot":"","sources":["../../src/sequencer/allowed.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAItE,wBAAsB,+BAA+B,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC,CA2BjF"}
@@ -1,27 +0,0 @@
1
- import { FPCContract } from '@aztec/noir-contracts.js/FPC';
2
- import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token';
3
- import { ProtocolContractAddress } from '@aztec/protocol-contracts';
4
- import { getContractClassFromArtifact } from '@aztec/stdlib/contract';
5
- let defaultAllowedSetupFunctions = undefined;
6
- export async function getDefaultAllowedSetupFunctions() {
7
- if (defaultAllowedSetupFunctions === undefined) {
8
- defaultAllowedSetupFunctions = [
9
- // needed for authwit support
10
- {
11
- address: ProtocolContractAddress.AuthRegistry
12
- },
13
- // needed for claiming on the same tx as a spend
14
- {
15
- address: ProtocolContractAddress.FeeJuice
16
- },
17
- // needed for private transfers via FPC
18
- {
19
- classId: (await getContractClassFromArtifact(TokenContractArtifact)).id
20
- },
21
- {
22
- classId: (await getContractClassFromArtifact(FPCContract.artifact)).id
23
- }
24
- ];
25
- }
26
- return defaultAllowedSetupFunctions;
27
- }
@@ -1,7 +0,0 @@
1
- import type { L1ContractsConfig, L1ReaderConfig } from '@aztec/ethereum';
2
- import type { L2BlockSourceEventEmitter } from '@aztec/stdlib/block';
3
- import { type TelemetryClient } from '@aztec/telemetry-client';
4
- import { SlasherClient } from './slasher_client.js';
5
- import type { SlasherConfig } from './slasher_client.js';
6
- export declare const createSlasherClient: (_config: SlasherConfig & L1ContractsConfig & L1ReaderConfig, l2BlockSource: L2BlockSourceEventEmitter, telemetry?: TelemetryClient) => SlasherClient;
7
- //# sourceMappingURL=factory.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/slasher/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,yBAAyB,CAAC;AAEnF,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,eAAO,MAAM,mBAAmB,YACrB,aAAa,GAAG,iBAAiB,GAAG,cAAc,iBAC5C,yBAAyB,cAC7B,eAAe,kBAI3B,CAAC"}
@@ -1,8 +0,0 @@
1
- import { getTelemetryClient } from '@aztec/telemetry-client';
2
- import { SlasherClient } from './slasher_client.js';
3
- export const createSlasherClient = (_config, l2BlockSource, telemetry = getTelemetryClient())=>{
4
- const config = {
5
- ..._config
6
- };
7
- return new SlasherClient(config, l2BlockSource, telemetry);
8
- };
@@ -1,3 +0,0 @@
1
- export * from './slasher_client.js';
2
- export { createSlasherClient } from './factory.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/slasher/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from './slasher_client.js';
2
- export { createSlasherClient } from './factory.js';
@@ -1,75 +0,0 @@
1
- import { type L1ContractsConfig, type L1ReaderConfig, type ViemPublicClient } from '@aztec/ethereum';
2
- import { EthAddress } from '@aztec/foundation/eth-address';
3
- import { SlashFactoryAbi } from '@aztec/l1-artifacts';
4
- import { type L2BlockId, type L2BlockSourceEvent, type L2BlockSourceEventEmitter } from '@aztec/stdlib/block';
5
- import { type TelemetryClient, WithTracer } from '@aztec/telemetry-client';
6
- import { type GetContractReturnType } from 'viem';
7
- /**
8
- * Enum defining the possible states of the Slasher client.
9
- */
10
- export declare enum SlasherClientState {
11
- IDLE = 0,
12
- RUNNING = 1,
13
- STOPPED = 2
14
- }
15
- /**
16
- * The synchronization status of the Slasher client.
17
- */
18
- export interface SlasherSyncState {
19
- /**
20
- * The current state of the slasher client.
21
- */
22
- state: SlasherClientState;
23
- /**
24
- * The block number that the slasher client is synced to.
25
- */
26
- syncedToL2Block: L2BlockId;
27
- }
28
- export interface SlasherConfig {
29
- blockCheckIntervalMS: number;
30
- blockRequestBatchSize: number;
31
- }
32
- /**
33
- * @notice A Hypomeiones slasher client implementation
34
- *
35
- * Hypomeiones: a class of individuals in ancient Sparta who were considered inferior or lesser citizens compared
36
- * to the full Spartan citizens.
37
- *
38
- * The implementation here is less than ideal. It exists, not to be the end all be all, but to show that
39
- * slashing can be done with this mechanism.
40
- *
41
- * The implementation is VERY brute in the sense that it only looks for pruned blocks and then tries to slash
42
- * the full committee of that.
43
- * If it sees a prune, it will mark the full epoch as "to be slashed".
44
- *
45
- * Also, it is not particularly smart around what it should if there were to be multiple slashing events.
46
- *
47
- * A few improvements:
48
- * - Only vote on the proposal if it is possible to reach, e.g., if 6 votes are needed and only 4 slots are left don't vote.
49
- * - Stop voting on a payload once it is processed.
50
- * - Only vote on the proposal if it have not already been executed
51
- * - Caveat, we need to fully decide if it is acceptable to have the same payload address multiple times. In the current
52
- * slash factory that could mean slashing the same committee for the same error multiple times.
53
- * - Decide how to deal with multiple slashing events in the same round.
54
- * - This could be that multiple epochs are pruned in the same round, but with the current naive implementation we could end up
55
- * slashing only the first, because the "lifetime" of the second would have passed after that vote
56
- */
57
- export declare class SlasherClient extends WithTracer {
58
- private config;
59
- private l2BlockSource;
60
- private log;
61
- private slashEvents;
62
- protected slashFactoryContract?: GetContractReturnType<typeof SlashFactoryAbi, ViemPublicClient>;
63
- private slashingAmount;
64
- constructor(config: SlasherConfig & L1ContractsConfig & L1ReaderConfig, l2BlockSource: L2BlockSourceEventEmitter, telemetry?: TelemetryClient, log?: import("@aztec/foundation/log").Logger);
65
- start(): void;
66
- getSlashPayload(slotNumber: bigint): Promise<EthAddress | undefined>;
67
- handleBlockStreamEvent(event: L2BlockSourceEvent): Promise<void>;
68
- /**
69
- * Allows consumers to stop the instance of the slasher client.
70
- * 'ready' will now return 'false' and the running promise that keeps the client synced is interrupted.
71
- */
72
- stop(): void;
73
- private handlePruneL2Blocks;
74
- }
75
- //# sourceMappingURL=slasher_client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"slasher_client.d.ts","sourceRoot":"","sources":["../../src/slasher/slasher_client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EAEtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EACL,KAAK,SAAS,EACd,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,EAE/B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,KAAK,eAAe,EAAE,UAAU,EAAsB,MAAM,yBAAyB,CAAC;AAE/F,OAAO,EAAE,KAAK,qBAAqB,EAA+D,MAAM,MAAM,CAAC;AAE/G;;GAEG;AACH,oBAAY,kBAAkB;IAC5B,IAAI,IAAA;IACJ,OAAO,IAAA;IACP,OAAO,IAAA;CACR;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,KAAK,EAAE,kBAAkB,CAAC;IAC1B;;OAEG;IACH,eAAe,EAAE,SAAS,CAAC;CAC5B;AAED,MAAM,WAAW,aAAa;IAC5B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,qBAAqB,EAAE,MAAM,CAAC;CAC/B;AAQD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,aAAc,SAAQ,UAAU;IAWzC,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,aAAa;IAErB,OAAO,CAAC,GAAG;IAbb,OAAO,CAAC,WAAW,CAAoB;IAEvC,SAAS,CAAC,oBAAoB,CAAC,EAAE,qBAAqB,CAAC,OAAO,eAAe,EAAE,gBAAgB,CAAC,CAAa;IAK7G,OAAO,CAAC,cAAc,CAAc;gBAG1B,MAAM,EAAE,aAAa,GAAG,iBAAiB,GAAG,cAAc,EAC1D,aAAa,EAAE,yBAAyB,EAChD,SAAS,GAAE,eAAsC,EACzC,GAAG,yCAA0B;IAwBhC,KAAK;IAMC,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IA8B1E,sBAAsB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAavE;;;OAGG;IACI,IAAI;IAOX,OAAO,CAAC,mBAAmB;CAgB5B"}