@aztec/sequencer-client 0.0.0-test.1 → 0.0.1-commit.1142ef1

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 (139) 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 +120 -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/block_builder.d.ts +26 -0
  31. package/dest/sequencer/block_builder.d.ts.map +1 -0
  32. package/dest/sequencer/block_builder.js +129 -0
  33. package/dest/sequencer/checkpoint_proposal_job.d.ts +77 -0
  34. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  35. package/dest/sequencer/checkpoint_proposal_job.js +1089 -0
  36. package/dest/sequencer/checkpoint_voter.d.ts +34 -0
  37. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  38. package/dest/sequencer/checkpoint_voter.js +85 -0
  39. package/dest/sequencer/config.d.ts +7 -1
  40. package/dest/sequencer/config.d.ts.map +1 -1
  41. package/dest/sequencer/errors.d.ts +11 -0
  42. package/dest/sequencer/errors.d.ts.map +1 -0
  43. package/dest/sequencer/errors.js +15 -0
  44. package/dest/sequencer/events.d.ts +46 -0
  45. package/dest/sequencer/events.d.ts.map +1 -0
  46. package/dest/sequencer/events.js +1 -0
  47. package/dest/sequencer/index.d.ts +5 -2
  48. package/dest/sequencer/index.d.ts.map +1 -1
  49. package/dest/sequencer/index.js +4 -1
  50. package/dest/sequencer/metrics.d.ts +48 -12
  51. package/dest/sequencer/metrics.d.ts.map +1 -1
  52. package/dest/sequencer/metrics.js +204 -69
  53. package/dest/sequencer/sequencer.d.ts +136 -137
  54. package/dest/sequencer/sequencer.d.ts.map +1 -1
  55. package/dest/sequencer/sequencer.js +913 -527
  56. package/dest/sequencer/timetable.d.ts +76 -24
  57. package/dest/sequencer/timetable.d.ts.map +1 -1
  58. package/dest/sequencer/timetable.js +177 -61
  59. package/dest/sequencer/types.d.ts +3 -0
  60. package/dest/sequencer/types.d.ts.map +1 -0
  61. package/dest/sequencer/types.js +1 -0
  62. package/dest/sequencer/utils.d.ts +20 -38
  63. package/dest/sequencer/utils.d.ts.map +1 -1
  64. package/dest/sequencer/utils.js +12 -47
  65. package/dest/test/index.d.ts +9 -1
  66. package/dest/test/index.d.ts.map +1 -1
  67. package/dest/test/index.js +0 -4
  68. package/dest/test/mock_checkpoint_builder.d.ts +91 -0
  69. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  70. package/dest/test/mock_checkpoint_builder.js +202 -0
  71. package/dest/test/utils.d.ts +53 -0
  72. package/dest/test/utils.d.ts.map +1 -0
  73. package/dest/test/utils.js +103 -0
  74. package/package.json +45 -45
  75. package/src/client/sequencer-client.ts +106 -107
  76. package/src/config.ts +133 -81
  77. package/src/global_variable_builder/global_builder.ts +84 -55
  78. package/src/index.ts +6 -3
  79. package/src/publisher/config.ts +45 -32
  80. package/src/publisher/index.ts +4 -0
  81. package/src/publisher/sequencer-publisher-factory.ts +92 -0
  82. package/src/publisher/sequencer-publisher-metrics.ts +30 -64
  83. package/src/publisher/sequencer-publisher.ts +967 -295
  84. package/src/sequencer/README.md +531 -0
  85. package/src/sequencer/block_builder.ts +216 -0
  86. package/src/sequencer/checkpoint_proposal_job.ts +742 -0
  87. package/src/sequencer/checkpoint_voter.ts +105 -0
  88. package/src/sequencer/config.ts +8 -0
  89. package/src/sequencer/errors.ts +21 -0
  90. package/src/sequencer/events.ts +27 -0
  91. package/src/sequencer/index.ts +4 -1
  92. package/src/sequencer/metrics.ts +269 -72
  93. package/src/sequencer/sequencer.ts +640 -592
  94. package/src/sequencer/timetable.ts +221 -62
  95. package/src/sequencer/types.ts +6 -0
  96. package/src/sequencer/utils.ts +28 -60
  97. package/src/test/index.ts +12 -4
  98. package/src/test/mock_checkpoint_builder.ts +279 -0
  99. package/src/test/utils.ts +157 -0
  100. package/dest/sequencer/allowed.d.ts +0 -3
  101. package/dest/sequencer/allowed.d.ts.map +0 -1
  102. package/dest/sequencer/allowed.js +0 -27
  103. package/dest/slasher/factory.d.ts +0 -7
  104. package/dest/slasher/factory.d.ts.map +0 -1
  105. package/dest/slasher/factory.js +0 -8
  106. package/dest/slasher/index.d.ts +0 -3
  107. package/dest/slasher/index.d.ts.map +0 -1
  108. package/dest/slasher/index.js +0 -2
  109. package/dest/slasher/slasher_client.d.ts +0 -75
  110. package/dest/slasher/slasher_client.d.ts.map +0 -1
  111. package/dest/slasher/slasher_client.js +0 -132
  112. package/dest/tx_validator/archive_cache.d.ts +0 -14
  113. package/dest/tx_validator/archive_cache.d.ts.map +0 -1
  114. package/dest/tx_validator/archive_cache.js +0 -22
  115. package/dest/tx_validator/gas_validator.d.ts +0 -14
  116. package/dest/tx_validator/gas_validator.d.ts.map +0 -1
  117. package/dest/tx_validator/gas_validator.js +0 -78
  118. package/dest/tx_validator/nullifier_cache.d.ts +0 -16
  119. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  120. package/dest/tx_validator/nullifier_cache.js +0 -24
  121. package/dest/tx_validator/phases_validator.d.ts +0 -12
  122. package/dest/tx_validator/phases_validator.d.ts.map +0 -1
  123. package/dest/tx_validator/phases_validator.js +0 -80
  124. package/dest/tx_validator/test_utils.d.ts +0 -23
  125. package/dest/tx_validator/test_utils.d.ts.map +0 -1
  126. package/dest/tx_validator/test_utils.js +0 -26
  127. package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
  128. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  129. package/dest/tx_validator/tx_validator_factory.js +0 -50
  130. package/src/sequencer/allowed.ts +0 -36
  131. package/src/slasher/factory.ts +0 -15
  132. package/src/slasher/index.ts +0 -2
  133. package/src/slasher/slasher_client.ts +0 -193
  134. package/src/tx_validator/archive_cache.ts +0 -28
  135. package/src/tx_validator/gas_validator.ts +0 -101
  136. package/src/tx_validator/nullifier_cache.ts +0 -30
  137. package/src/tx_validator/phases_validator.ts +0 -98
  138. package/src/tx_validator/test_utils.ts +0 -48
  139. package/src/tx_validator/tx_validator_factory.ts +0 -120
@@ -0,0 +1,279 @@
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 type { FunctionsOf } from '@aztec/foundation/types';
5
+ import { L2BlockNew } from '@aztec/stdlib/block';
6
+ import { Checkpoint } from '@aztec/stdlib/checkpoint';
7
+ import { Gas } from '@aztec/stdlib/gas';
8
+ import type { FullNodeBlockBuilderConfig, PublicProcessorLimits } from '@aztec/stdlib/interfaces/server';
9
+ import { CheckpointHeader } from '@aztec/stdlib/rollup';
10
+ import { makeAppendOnlyTreeSnapshot } from '@aztec/stdlib/testing';
11
+ import type { CheckpointGlobalVariables, Tx } from '@aztec/stdlib/tx';
12
+ import type {
13
+ BuildBlockInCheckpointResult,
14
+ CheckpointBuilder,
15
+ FullNodeCheckpointsBuilder,
16
+ } 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 FunctionsOf<CheckpointBuilder> {
23
+ private blocks: L2BlockNew[] = [];
24
+ private builtBlocks: L2BlockNew[] = [];
25
+ private usedTxsPerBlock: Tx[][] = [];
26
+ private blockIndex = 0;
27
+
28
+ /** Optional function to dynamically provide the block (alternative to seedBlocks) */
29
+ private blockProvider: (() => L2BlockNew) | undefined = undefined;
30
+
31
+ /** Track calls for assertions */
32
+ public buildBlockCalls: Array<{
33
+ blockNumber: BlockNumber;
34
+ timestamp: bigint;
35
+ opts: PublicProcessorLimits;
36
+ }> = [];
37
+ public completeCheckpointCalled = false;
38
+ public getCheckpointCalled = false;
39
+
40
+ /** Set to an error to make buildBlock throw on next call */
41
+ public errorOnBuild: Error | undefined = undefined;
42
+
43
+ constructor(
44
+ private readonly constants: CheckpointGlobalVariables,
45
+ private readonly checkpointNumber: CheckpointNumber,
46
+ ) {}
47
+
48
+ /** Seed the builder with blocks to return on successive buildBlock calls */
49
+ seedBlocks(blocks: L2BlockNew[], usedTxsPerBlock?: Tx[][]): this {
50
+ this.blocks = blocks;
51
+ this.usedTxsPerBlock = usedTxsPerBlock ?? blocks.map(() => []);
52
+ this.blockIndex = 0;
53
+ this.blockProvider = undefined;
54
+ return this;
55
+ }
56
+
57
+ /**
58
+ * Set a function that provides blocks dynamically.
59
+ * Useful for tests where the block is determined at call time (e.g., sequencer tests).
60
+ */
61
+ setBlockProvider(provider: () => L2BlockNew): this {
62
+ this.blockProvider = provider;
63
+ this.blocks = [];
64
+ return this;
65
+ }
66
+
67
+ getConstantData(): CheckpointGlobalVariables {
68
+ return this.constants;
69
+ }
70
+
71
+ buildBlock(
72
+ _pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
73
+ blockNumber: BlockNumber,
74
+ timestamp: bigint,
75
+ opts: PublicProcessorLimits,
76
+ ): Promise<BuildBlockInCheckpointResult> {
77
+ this.buildBlockCalls.push({ blockNumber, timestamp, opts });
78
+
79
+ if (this.errorOnBuild) {
80
+ return Promise.reject(this.errorOnBuild);
81
+ }
82
+
83
+ let block: L2BlockNew;
84
+ let usedTxs: Tx[];
85
+
86
+ if (this.blockProvider) {
87
+ // Dynamic mode: get block from provider
88
+ block = this.blockProvider();
89
+ usedTxs = [];
90
+ this.builtBlocks.push(block);
91
+ } else {
92
+ // Seeded mode: get block from pre-seeded list
93
+ block = this.blocks[this.blockIndex];
94
+ usedTxs = this.usedTxsPerBlock[this.blockIndex] ?? [];
95
+ this.blockIndex++;
96
+ this.builtBlocks.push(block);
97
+ }
98
+
99
+ return Promise.resolve({
100
+ block,
101
+ publicGas: Gas.empty(),
102
+ publicProcessorDuration: 0,
103
+ numTxs: block?.body?.txEffects?.length ?? usedTxs.length,
104
+ blockBuildingTimer: new Timer(),
105
+ usedTxs,
106
+ failedTxs: [],
107
+ });
108
+ }
109
+
110
+ completeCheckpoint(): Promise<Checkpoint> {
111
+ this.completeCheckpointCalled = true;
112
+ const allBlocks = this.blockProvider ? this.builtBlocks : this.blocks;
113
+ const lastBlock = allBlocks[allBlocks.length - 1];
114
+ // Create a CheckpointHeader from the last block's header for testing
115
+ const checkpointHeader = this.createCheckpointHeader(lastBlock);
116
+ return Promise.resolve(
117
+ new Checkpoint(
118
+ makeAppendOnlyTreeSnapshot(lastBlock.header.globalVariables.blockNumber + 1),
119
+ checkpointHeader,
120
+ allBlocks,
121
+ this.checkpointNumber,
122
+ ),
123
+ );
124
+ }
125
+
126
+ getCheckpoint(): Promise<Checkpoint> {
127
+ this.getCheckpointCalled = true;
128
+ const builtBlocks = this.blockProvider ? this.builtBlocks : this.blocks.slice(0, this.blockIndex);
129
+ const lastBlock = builtBlocks[builtBlocks.length - 1];
130
+ if (!lastBlock) {
131
+ throw new Error('No blocks built yet');
132
+ }
133
+ // Create a CheckpointHeader from the last block's header for testing
134
+ const checkpointHeader = this.createCheckpointHeader(lastBlock);
135
+ return Promise.resolve(
136
+ new Checkpoint(
137
+ makeAppendOnlyTreeSnapshot(lastBlock.header.globalVariables.blockNumber + 1),
138
+ checkpointHeader,
139
+ builtBlocks,
140
+ this.checkpointNumber,
141
+ ),
142
+ );
143
+ }
144
+
145
+ /**
146
+ * Creates a CheckpointHeader from a block's header for testing.
147
+ * This is a simplified version that creates a minimal CheckpointHeader.
148
+ */
149
+ private createCheckpointHeader(block: L2BlockNew): CheckpointHeader {
150
+ const header = block.header;
151
+ const gv = header.globalVariables;
152
+ return CheckpointHeader.empty({
153
+ lastArchiveRoot: header.lastArchive.root,
154
+ blockHeadersHash: Fr.random(), // Use random for testing
155
+ slotNumber: gv.slotNumber,
156
+ timestamp: gv.timestamp,
157
+ coinbase: gv.coinbase,
158
+ feeRecipient: gv.feeRecipient,
159
+ gasFees: gv.gasFees,
160
+ totalManaUsed: header.totalManaUsed,
161
+ });
162
+ }
163
+
164
+ /** Reset for reuse in another test */
165
+ reset(): void {
166
+ this.blocks = [];
167
+ this.builtBlocks = [];
168
+ this.usedTxsPerBlock = [];
169
+ this.blockIndex = 0;
170
+ this.buildBlockCalls = [];
171
+ this.completeCheckpointCalled = false;
172
+ this.getCheckpointCalled = false;
173
+ this.errorOnBuild = undefined;
174
+ this.blockProvider = undefined;
175
+ }
176
+ }
177
+
178
+ /**
179
+ * A fake CheckpointsBuilder (factory) for testing that implements the same interface
180
+ * as FullNodeCheckpointsBuilder. Returns MockCheckpointBuilder instances.
181
+ * Does NOT use jest mocks - this is a proper test double.
182
+ */
183
+ export class MockCheckpointsBuilder implements FunctionsOf<FullNodeCheckpointsBuilder> {
184
+ private checkpointBuilder: MockCheckpointBuilder | undefined;
185
+
186
+ /** Track calls for assertions */
187
+ public startCheckpointCalls: Array<{
188
+ checkpointNumber: CheckpointNumber;
189
+ constants: CheckpointGlobalVariables;
190
+ l1ToL2Messages: Fr[];
191
+ }> = [];
192
+ public openCheckpointCalls: Array<{
193
+ checkpointNumber: CheckpointNumber;
194
+ constants: CheckpointGlobalVariables;
195
+ l1ToL2Messages: Fr[];
196
+ existingBlocks: L2BlockNew[];
197
+ }> = [];
198
+ public updateConfigCalls: Array<Partial<FullNodeBlockBuilderConfig>> = [];
199
+
200
+ /**
201
+ * Set the MockCheckpointBuilder to return from startCheckpoint.
202
+ * Must be called before startCheckpoint is invoked.
203
+ */
204
+ setCheckpointBuilder(builder: MockCheckpointBuilder): this {
205
+ this.checkpointBuilder = builder;
206
+ return this;
207
+ }
208
+
209
+ /**
210
+ * Creates a new MockCheckpointBuilder with the given constants.
211
+ * Convenience method that creates and sets the builder in one call.
212
+ */
213
+ createCheckpointBuilder(
214
+ constants: CheckpointGlobalVariables,
215
+ checkpointNumber: CheckpointNumber,
216
+ ): MockCheckpointBuilder {
217
+ this.checkpointBuilder = new MockCheckpointBuilder(constants, checkpointNumber);
218
+ return this.checkpointBuilder;
219
+ }
220
+
221
+ /** Get the current checkpoint builder (for assertions) */
222
+ getCheckpointBuilder(): MockCheckpointBuilder | undefined {
223
+ return this.checkpointBuilder;
224
+ }
225
+
226
+ getConfig(): FullNodeBlockBuilderConfig {
227
+ return {
228
+ l1GenesisTime: 0n,
229
+ slotDuration: 24,
230
+ l1ChainId: 1,
231
+ rollupVersion: 1,
232
+ };
233
+ }
234
+
235
+ updateConfig(config: Partial<FullNodeBlockBuilderConfig>): void {
236
+ this.updateConfigCalls.push(config);
237
+ }
238
+
239
+ startCheckpoint(
240
+ checkpointNumber: CheckpointNumber,
241
+ constants: CheckpointGlobalVariables,
242
+ l1ToL2Messages: Fr[],
243
+ _fork: unknown,
244
+ ): Promise<CheckpointBuilder> {
245
+ this.startCheckpointCalls.push({ checkpointNumber, constants, l1ToL2Messages });
246
+
247
+ if (!this.checkpointBuilder) {
248
+ // Auto-create a builder if none was set
249
+ this.checkpointBuilder = new MockCheckpointBuilder(constants, checkpointNumber);
250
+ }
251
+
252
+ return Promise.resolve(this.checkpointBuilder as unknown as CheckpointBuilder);
253
+ }
254
+
255
+ openCheckpoint(
256
+ checkpointNumber: CheckpointNumber,
257
+ constants: CheckpointGlobalVariables,
258
+ l1ToL2Messages: Fr[],
259
+ _fork: unknown,
260
+ existingBlocks: L2BlockNew[] = [],
261
+ ): Promise<CheckpointBuilder> {
262
+ this.openCheckpointCalls.push({ checkpointNumber, constants, l1ToL2Messages, existingBlocks });
263
+
264
+ if (!this.checkpointBuilder) {
265
+ // Auto-create a builder if none was set
266
+ this.checkpointBuilder = new MockCheckpointBuilder(constants, checkpointNumber);
267
+ }
268
+
269
+ return Promise.resolve(this.checkpointBuilder as unknown as CheckpointBuilder);
270
+ }
271
+
272
+ /** Reset for reuse in another test */
273
+ reset(): void {
274
+ this.checkpointBuilder = undefined;
275
+ this.startCheckpointCalls = [];
276
+ this.openCheckpointCalls = [];
277
+ this.updateConfigCalls = [];
278
+ }
279
+ }
@@ -0,0 +1,157 @@
1
+ import { Body } from '@aztec/aztec.js/block';
2
+ import { CheckpointNumber } 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, L2BlockNew } 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 L2BlockNew from transactions and global variables
34
+ */
35
+ export async function makeBlock(txs: Tx[], globalVariables: GlobalVariables): Promise<L2BlockNew> {
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 L2BlockNew(archive, header, body, CheckpointNumber(globalVariables.blockNumber), 0);
45
+ }
46
+
47
+ /**
48
+ * Mocks the P2P client to return specific pending transactions
49
+ */
50
+ export function mockPendingTxs(p2p: MockProxy<P2P>, txs: Tx[]): void {
51
+ p2p.getPendingTxCount.mockResolvedValue(txs.length);
52
+ p2p.iteratePendingTxs.mockImplementation(() => mockTxIterator(Promise.resolve(txs)));
53
+ }
54
+
55
+ /**
56
+ * Creates an async iterator for transactions
57
+ */
58
+ export async function* mockTxIterator(txs: Promise<Tx[]>): AsyncIterableIterator<Tx> {
59
+ for (const tx of await txs) {
60
+ yield tx;
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Creates mock committee attestations from a signer
66
+ */
67
+ export function createMockSignatures(signer: Secp256k1Signer): CommitteeAttestation[] {
68
+ const mockedSig = Signature.random();
69
+ return [new CommitteeAttestation(signer.address, mockedSig)];
70
+ }
71
+
72
+ /**
73
+ * Creates a CheckpointHeader from an L2BlockNew for testing purposes.
74
+ * Uses mock values for blockHeadersHash, blobsHash and inHash since L2BlockNew doesn't have these fields.
75
+ */
76
+ function createCheckpointHeaderFromBlock(block: L2BlockNew): CheckpointHeader {
77
+ const gv = block.header.globalVariables;
78
+ return new CheckpointHeader(
79
+ block.header.lastArchive.root,
80
+ Fr.random(), // blockHeadersHash - mock value for testing
81
+ Fr.random(), // blobsHash - mock value for testing
82
+ Fr.random(), // inHash - mock value for testing
83
+ gv.slotNumber,
84
+ gv.timestamp,
85
+ gv.coinbase,
86
+ gv.feeRecipient,
87
+ gv.gasFees,
88
+ block.header.totalManaUsed,
89
+ );
90
+ }
91
+
92
+ /**
93
+ * Creates a block proposal from a block and signature
94
+ */
95
+ export function createBlockProposal(block: L2BlockNew, signature: Signature): BlockProposal {
96
+ const txHashes = block.body.txEffects.map(tx => tx.txHash);
97
+ return new BlockProposal(
98
+ block.header,
99
+ block.indexWithinCheckpoint,
100
+ Fr.ZERO, // inHash - using zero for testing
101
+ block.archive.root,
102
+ txHashes,
103
+ signature,
104
+ );
105
+ }
106
+
107
+ /**
108
+ * Creates a checkpoint proposal from a block and signature
109
+ */
110
+ export function createCheckpointProposal(
111
+ block: L2BlockNew,
112
+ checkpointSignature: Signature,
113
+ blockSignature?: Signature,
114
+ ): CheckpointProposal {
115
+ const txHashes = block.body.txEffects.map(tx => tx.txHash);
116
+ const checkpointHeader = createCheckpointHeaderFromBlock(block);
117
+ return new CheckpointProposal(checkpointHeader, block.archive.root, checkpointSignature, {
118
+ blockHeader: block.header,
119
+ indexWithinCheckpoint: block.indexWithinCheckpoint,
120
+ txHashes,
121
+ signature: blockSignature ?? checkpointSignature, // Use checkpoint signature as block signature if not provided
122
+ });
123
+ }
124
+
125
+ /**
126
+ * Creates a checkpoint attestation from a block and signature.
127
+ * Note: We manually set the sender since we use random signatures in tests.
128
+ * In production, the sender is recovered from the signature.
129
+ */
130
+ export function createCheckpointAttestation(
131
+ block: L2BlockNew,
132
+ signature: Signature,
133
+ sender: EthAddress,
134
+ ): CheckpointAttestation {
135
+ const checkpointHeader = createCheckpointHeaderFromBlock(block);
136
+ const payload = new ConsensusPayload(checkpointHeader, block.archive.root);
137
+ const attestation = new CheckpointAttestation(payload, signature, signature);
138
+ // Set sender directly for testing (bypasses signature recovery)
139
+ (attestation as any).sender = sender;
140
+ return attestation;
141
+ }
142
+
143
+ /**
144
+ * Creates transactions and a block, and mocks P2P to return them.
145
+ * Helper for tests that need to set up a block with transactions.
146
+ */
147
+ export async function setupTxsAndBlock(
148
+ p2p: MockProxy<P2P>,
149
+ globalVariables: GlobalVariables,
150
+ txCount: number,
151
+ chainId: Fr,
152
+ ): Promise<{ txs: Tx[]; block: L2BlockNew }> {
153
+ const txs = await Promise.all(times(txCount, i => makeTx(i + 1, chainId)));
154
+ const block = await makeBlock(txs, globalVariables);
155
+ mockPendingTxs(p2p, txs);
156
+ return { txs, block };
157
+ }
@@ -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"}