@aztec/archiver 0.0.1-commit.f295ac2 → 0.0.1-commit.f504929
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.
- package/README.md +9 -0
- package/dest/archiver.d.ts +10 -6
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +50 -111
- package/dest/errors.d.ts +6 -1
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +8 -0
- package/dest/factory.d.ts +5 -2
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +16 -13
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/l1/bin/retrieve-calldata.js +35 -32
- package/dest/l1/calldata_retriever.d.ts +73 -50
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +190 -259
- package/dest/l1/data_retrieval.d.ts +9 -9
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +24 -22
- package/dest/l1/spire_proposer.d.ts +5 -5
- package/dest/l1/spire_proposer.d.ts.map +1 -1
- package/dest/l1/spire_proposer.js +9 -17
- package/dest/l1/validate_trace.d.ts +6 -3
- package/dest/l1/validate_trace.d.ts.map +1 -1
- package/dest/l1/validate_trace.js +13 -9
- package/dest/modules/data_source_base.d.ts +25 -21
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +48 -123
- package/dest/modules/data_store_updater.d.ts +31 -20
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +79 -60
- package/dest/modules/instrumentation.d.ts +17 -4
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +36 -12
- package/dest/modules/l1_synchronizer.d.ts +4 -8
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +23 -19
- package/dest/store/block_store.d.ts +50 -32
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +147 -54
- package/dest/store/contract_class_store.d.ts +1 -1
- package/dest/store/contract_class_store.d.ts.map +1 -1
- package/dest/store/contract_class_store.js +11 -7
- package/dest/store/kv_archiver_store.d.ts +52 -29
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +49 -23
- package/dest/store/l2_tips_cache.d.ts +19 -0
- package/dest/store/l2_tips_cache.d.ts.map +1 -0
- package/dest/store/l2_tips_cache.js +89 -0
- package/dest/store/log_store.d.ts +17 -8
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +77 -43
- package/dest/test/fake_l1_state.d.ts +9 -4
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +56 -18
- package/dest/test/index.js +3 -1
- package/dest/test/mock_archiver.d.ts +1 -1
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +3 -2
- package/dest/test/mock_l2_block_source.d.ts +36 -21
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +151 -109
- package/dest/test/mock_structs.d.ts +3 -2
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +11 -9
- package/dest/test/noop_l1_archiver.d.ts +23 -0
- package/dest/test/noop_l1_archiver.d.ts.map +1 -0
- package/dest/test/noop_l1_archiver.js +68 -0
- package/package.json +14 -13
- package/src/archiver.ts +71 -136
- package/src/errors.ts +12 -0
- package/src/factory.ts +30 -14
- package/src/index.ts +1 -0
- package/src/l1/README.md +25 -68
- package/src/l1/bin/retrieve-calldata.ts +45 -33
- package/src/l1/calldata_retriever.ts +249 -379
- package/src/l1/data_retrieval.ts +27 -29
- package/src/l1/spire_proposer.ts +7 -15
- package/src/l1/validate_trace.ts +24 -6
- package/src/modules/data_source_base.ts +81 -167
- package/src/modules/data_store_updater.ts +92 -63
- package/src/modules/instrumentation.ts +46 -14
- package/src/modules/l1_synchronizer.ts +26 -24
- package/src/store/block_store.ts +188 -92
- package/src/store/contract_class_store.ts +11 -7
- package/src/store/kv_archiver_store.ts +85 -36
- package/src/store/l2_tips_cache.ts +89 -0
- package/src/store/log_store.ts +134 -49
- package/src/test/fake_l1_state.ts +77 -19
- package/src/test/index.ts +3 -0
- package/src/test/mock_archiver.ts +3 -2
- package/src/test/mock_l2_block_source.ts +196 -126
- package/src/test/mock_structs.ts +26 -10
- package/src/test/noop_l1_archiver.ts +109 -0
package/src/store/log_store.ts
CHANGED
|
@@ -6,7 +6,8 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
6
6
|
import { BufferReader, numToUInt32BE } from '@aztec/foundation/serialize';
|
|
7
7
|
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
8
8
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
9
|
-
import {
|
|
9
|
+
import { BlockHash, L2Block } from '@aztec/stdlib/block';
|
|
10
|
+
import { MAX_LOGS_PER_TAG } from '@aztec/stdlib/interfaces/api-limit';
|
|
10
11
|
import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
|
|
11
12
|
import {
|
|
12
13
|
ContractClassLog,
|
|
@@ -19,6 +20,7 @@ import {
|
|
|
19
20
|
Tag,
|
|
20
21
|
TxScopedL2Log,
|
|
21
22
|
} from '@aztec/stdlib/logs';
|
|
23
|
+
import { TxHash } from '@aztec/stdlib/tx';
|
|
22
24
|
|
|
23
25
|
import type { BlockStore } from './block_store.js';
|
|
24
26
|
|
|
@@ -58,7 +60,7 @@ export class LogStore {
|
|
|
58
60
|
* @param block - The L2 block to extract logs from.
|
|
59
61
|
* @returns An object containing the private and public tagged logs for the block.
|
|
60
62
|
*/
|
|
61
|
-
#extractTaggedLogsFromBlock(block:
|
|
63
|
+
#extractTaggedLogsFromBlock(block: L2Block) {
|
|
62
64
|
// SiloedTag (as string) -> array of log buffers.
|
|
63
65
|
const privateTaggedLogs = new Map<string, Buffer[]>();
|
|
64
66
|
// "{contractAddress}_{tag}" (as string) -> array of log buffers.
|
|
@@ -119,7 +121,7 @@ export class LogStore {
|
|
|
119
121
|
* @returns A map from tag (as string) to an array of serialized private logs belonging to that tag, and a map from
|
|
120
122
|
* "{contractAddress}_{tag}" (as string) to an array of serialized public logs belonging to that key.
|
|
121
123
|
*/
|
|
122
|
-
#extractTaggedLogs(blocks:
|
|
124
|
+
#extractTaggedLogs(blocks: L2Block[]): {
|
|
123
125
|
privateTaggedLogs: Map<string, Buffer[]>;
|
|
124
126
|
publicTaggedLogs: Map<string, Buffer[]>;
|
|
125
127
|
} {
|
|
@@ -145,7 +147,7 @@ export class LogStore {
|
|
|
145
147
|
return { privateTaggedLogs, publicTaggedLogs };
|
|
146
148
|
}
|
|
147
149
|
|
|
148
|
-
async #addPrivateLogs(blocks:
|
|
150
|
+
async #addPrivateLogs(blocks: L2Block[]): Promise<void> {
|
|
149
151
|
const newBlocks = await filterAsync(
|
|
150
152
|
blocks,
|
|
151
153
|
async block => !(await this.#privateLogKeysByBlock.hasAsync(block.number)),
|
|
@@ -180,7 +182,7 @@ export class LogStore {
|
|
|
180
182
|
}
|
|
181
183
|
}
|
|
182
184
|
|
|
183
|
-
async #addPublicLogs(blocks:
|
|
185
|
+
async #addPublicLogs(blocks: L2Block[]): Promise<void> {
|
|
184
186
|
const newBlocks = await filterAsync(
|
|
185
187
|
blocks,
|
|
186
188
|
async block => !(await this.#publicLogKeysByBlock.hasAsync(block.number)),
|
|
@@ -218,6 +220,7 @@ export class LogStore {
|
|
|
218
220
|
.map((txEffect, txIndex) =>
|
|
219
221
|
[
|
|
220
222
|
numToUInt32BE(txIndex),
|
|
223
|
+
txEffect.txHash.toBuffer(),
|
|
221
224
|
numToUInt32BE(txEffect.publicLogs.length),
|
|
222
225
|
txEffect.publicLogs.map(log => log.toBuffer()),
|
|
223
226
|
].flat(),
|
|
@@ -228,7 +231,7 @@ export class LogStore {
|
|
|
228
231
|
}
|
|
229
232
|
}
|
|
230
233
|
|
|
231
|
-
async #addContractClassLogs(blocks:
|
|
234
|
+
async #addContractClassLogs(blocks: L2Block[]): Promise<void> {
|
|
232
235
|
const newBlocks = await filterAsync(
|
|
233
236
|
blocks,
|
|
234
237
|
async block => !(await this.#contractClassLogsByBlock.hasAsync(block.number)),
|
|
@@ -241,6 +244,7 @@ export class LogStore {
|
|
|
241
244
|
.map((txEffect, txIndex) =>
|
|
242
245
|
[
|
|
243
246
|
numToUInt32BE(txIndex),
|
|
247
|
+
txEffect.txHash.toBuffer(),
|
|
244
248
|
numToUInt32BE(txEffect.contractClassLogs.length),
|
|
245
249
|
txEffect.contractClassLogs.map(log => log.toBuffer()),
|
|
246
250
|
].flat(),
|
|
@@ -259,7 +263,7 @@ export class LogStore {
|
|
|
259
263
|
* @param blocks - The blocks for which to add the logs.
|
|
260
264
|
* @returns True if the operation is successful.
|
|
261
265
|
*/
|
|
262
|
-
addLogs(blocks:
|
|
266
|
+
addLogs(blocks: L2Block[]): Promise<boolean> {
|
|
263
267
|
return this.db.transactionAsync(async () => {
|
|
264
268
|
await Promise.all([
|
|
265
269
|
this.#addPrivateLogs(blocks),
|
|
@@ -270,21 +274,21 @@ export class LogStore {
|
|
|
270
274
|
});
|
|
271
275
|
}
|
|
272
276
|
|
|
273
|
-
#packWithBlockHash(blockHash:
|
|
277
|
+
#packWithBlockHash(blockHash: BlockHash, data: Buffer<ArrayBufferLike>[]): Buffer<ArrayBufferLike> {
|
|
274
278
|
return Buffer.concat([blockHash.toBuffer(), ...data]);
|
|
275
279
|
}
|
|
276
280
|
|
|
277
|
-
#unpackBlockHash(reader: BufferReader):
|
|
281
|
+
#unpackBlockHash(reader: BufferReader): BlockHash {
|
|
278
282
|
const blockHash = reader.remainingBytes() > 0 ? reader.readObject(Fr) : undefined;
|
|
279
283
|
|
|
280
284
|
if (!blockHash) {
|
|
281
285
|
throw new Error('Failed to read block hash from log entry buffer');
|
|
282
286
|
}
|
|
283
287
|
|
|
284
|
-
return
|
|
288
|
+
return new BlockHash(blockHash);
|
|
285
289
|
}
|
|
286
290
|
|
|
287
|
-
deleteLogs(blocks:
|
|
291
|
+
deleteLogs(blocks: L2Block[]): Promise<boolean> {
|
|
288
292
|
return this.db.transactionAsync(async () => {
|
|
289
293
|
await Promise.all(
|
|
290
294
|
blocks.map(async block => {
|
|
@@ -314,27 +318,49 @@ export class LogStore {
|
|
|
314
318
|
}
|
|
315
319
|
|
|
316
320
|
/**
|
|
317
|
-
* Gets
|
|
321
|
+
* Gets private logs that match any of the `tags`. For each tag, an array of matching logs is returned. An empty
|
|
318
322
|
* array implies no logs match that tag.
|
|
323
|
+
* @param tags - The tags to search for.
|
|
324
|
+
* @param page - The page number (0-indexed) for pagination.
|
|
325
|
+
* @returns An array of log arrays, one per tag. Returns at most MAX_LOGS_PER_TAG logs per tag per page. If
|
|
326
|
+
* MAX_LOGS_PER_TAG logs are returned for a tag, the caller should fetch the next page to check for more logs.
|
|
319
327
|
*/
|
|
320
|
-
async getPrivateLogsByTags(tags: SiloedTag[]): Promise<TxScopedL2Log[][]> {
|
|
328
|
+
async getPrivateLogsByTags(tags: SiloedTag[], page: number = 0): Promise<TxScopedL2Log[][]> {
|
|
321
329
|
const logs = await Promise.all(tags.map(tag => this.#privateLogsByTag.getAsync(tag.toString())));
|
|
330
|
+
const start = page * MAX_LOGS_PER_TAG;
|
|
331
|
+
const end = start + MAX_LOGS_PER_TAG;
|
|
322
332
|
|
|
323
|
-
return logs.map(
|
|
333
|
+
return logs.map(
|
|
334
|
+
logBuffers => logBuffers?.slice(start, end).map(logBuffer => TxScopedL2Log.fromBuffer(logBuffer)) ?? [],
|
|
335
|
+
);
|
|
324
336
|
}
|
|
325
337
|
|
|
326
338
|
/**
|
|
327
|
-
* Gets
|
|
339
|
+
* Gets public logs that match any of the `tags` from the specified contract. For each tag, an array of matching
|
|
328
340
|
* logs is returned. An empty array implies no logs match that tag.
|
|
341
|
+
* @param contractAddress - The contract address to search logs for.
|
|
342
|
+
* @param tags - The tags to search for.
|
|
343
|
+
* @param page - The page number (0-indexed) for pagination.
|
|
344
|
+
* @returns An array of log arrays, one per tag. Returns at most MAX_LOGS_PER_TAG logs per tag per page. If
|
|
345
|
+
* MAX_LOGS_PER_TAG logs are returned for a tag, the caller should fetch the next page to check for more logs.
|
|
329
346
|
*/
|
|
330
|
-
async getPublicLogsByTagsFromContract(
|
|
347
|
+
async getPublicLogsByTagsFromContract(
|
|
348
|
+
contractAddress: AztecAddress,
|
|
349
|
+
tags: Tag[],
|
|
350
|
+
page: number = 0,
|
|
351
|
+
): Promise<TxScopedL2Log[][]> {
|
|
331
352
|
const logs = await Promise.all(
|
|
332
353
|
tags.map(tag => {
|
|
333
354
|
const key = `${contractAddress.toString()}_${tag.value.toString()}`;
|
|
334
355
|
return this.#publicLogsByContractAndTag.getAsync(key);
|
|
335
356
|
}),
|
|
336
357
|
);
|
|
337
|
-
|
|
358
|
+
const start = page * MAX_LOGS_PER_TAG;
|
|
359
|
+
const end = start + MAX_LOGS_PER_TAG;
|
|
360
|
+
|
|
361
|
+
return logs.map(
|
|
362
|
+
logBuffers => logBuffers?.slice(start, end).map(logBuffer => TxScopedL2Log.fromBuffer(logBuffer)) ?? [],
|
|
363
|
+
);
|
|
338
364
|
}
|
|
339
365
|
|
|
340
366
|
/**
|
|
@@ -363,24 +389,33 @@ export class LogStore {
|
|
|
363
389
|
}
|
|
364
390
|
|
|
365
391
|
const buffer = (await this.#publicLogsByBlock.getAsync(blockNumber)) ?? Buffer.alloc(0);
|
|
366
|
-
const publicLogsInBlock:
|
|
392
|
+
const publicLogsInBlock: { txHash: TxHash; logs: PublicLog[] }[] = [];
|
|
367
393
|
const reader = new BufferReader(buffer);
|
|
368
394
|
|
|
369
395
|
const blockHash = this.#unpackBlockHash(reader);
|
|
370
396
|
|
|
371
397
|
while (reader.remainingBytes() > 0) {
|
|
372
398
|
const indexOfTx = reader.readNumber();
|
|
399
|
+
const txHash = reader.readObject(TxHash);
|
|
373
400
|
const numLogsInTx = reader.readNumber();
|
|
374
|
-
publicLogsInBlock[indexOfTx] = [];
|
|
401
|
+
publicLogsInBlock[indexOfTx] = { txHash, logs: [] };
|
|
375
402
|
for (let i = 0; i < numLogsInTx; i++) {
|
|
376
|
-
publicLogsInBlock[indexOfTx].push(reader.readObject(PublicLog));
|
|
403
|
+
publicLogsInBlock[indexOfTx].logs.push(reader.readObject(PublicLog));
|
|
377
404
|
}
|
|
378
405
|
}
|
|
379
406
|
|
|
380
|
-
const
|
|
407
|
+
const txData = publicLogsInBlock[txIndex];
|
|
381
408
|
|
|
382
409
|
const logs: ExtendedPublicLog[] = [];
|
|
383
|
-
const maxLogsHit = this.#
|
|
410
|
+
const maxLogsHit = this.#accumulatePublicLogs(
|
|
411
|
+
logs,
|
|
412
|
+
blockNumber,
|
|
413
|
+
blockHash,
|
|
414
|
+
txIndex,
|
|
415
|
+
txData.txHash,
|
|
416
|
+
txData.logs,
|
|
417
|
+
filter,
|
|
418
|
+
);
|
|
384
419
|
|
|
385
420
|
return { logs, maxLogsHit };
|
|
386
421
|
}
|
|
@@ -401,22 +436,31 @@ export class LogStore {
|
|
|
401
436
|
|
|
402
437
|
let maxLogsHit = false;
|
|
403
438
|
loopOverBlocks: for await (const [blockNumber, logBuffer] of this.#publicLogsByBlock.entriesAsync({ start, end })) {
|
|
404
|
-
const publicLogsInBlock:
|
|
439
|
+
const publicLogsInBlock: { txHash: TxHash; logs: PublicLog[] }[] = [];
|
|
405
440
|
const reader = new BufferReader(logBuffer);
|
|
406
441
|
|
|
407
442
|
const blockHash = this.#unpackBlockHash(reader);
|
|
408
443
|
|
|
409
444
|
while (reader.remainingBytes() > 0) {
|
|
410
445
|
const indexOfTx = reader.readNumber();
|
|
446
|
+
const txHash = reader.readObject(TxHash);
|
|
411
447
|
const numLogsInTx = reader.readNumber();
|
|
412
|
-
publicLogsInBlock[indexOfTx] = [];
|
|
448
|
+
publicLogsInBlock[indexOfTx] = { txHash, logs: [] };
|
|
413
449
|
for (let i = 0; i < numLogsInTx; i++) {
|
|
414
|
-
publicLogsInBlock[indexOfTx].push(reader.readObject(PublicLog));
|
|
450
|
+
publicLogsInBlock[indexOfTx].logs.push(reader.readObject(PublicLog));
|
|
415
451
|
}
|
|
416
452
|
}
|
|
417
453
|
for (let txIndex = filter.afterLog?.txIndex ?? 0; txIndex < publicLogsInBlock.length; txIndex++) {
|
|
418
|
-
const
|
|
419
|
-
maxLogsHit = this.#
|
|
454
|
+
const txData = publicLogsInBlock[txIndex];
|
|
455
|
+
maxLogsHit = this.#accumulatePublicLogs(
|
|
456
|
+
logs,
|
|
457
|
+
blockNumber,
|
|
458
|
+
blockHash,
|
|
459
|
+
txIndex,
|
|
460
|
+
txData.txHash,
|
|
461
|
+
txData.logs,
|
|
462
|
+
filter,
|
|
463
|
+
);
|
|
420
464
|
if (maxLogsHit) {
|
|
421
465
|
this.#log.debug(`Max logs hit at block ${blockNumber}`);
|
|
422
466
|
break loopOverBlocks;
|
|
@@ -452,24 +496,33 @@ export class LogStore {
|
|
|
452
496
|
return { logs: [], maxLogsHit: false };
|
|
453
497
|
}
|
|
454
498
|
const contractClassLogsBuffer = (await this.#contractClassLogsByBlock.getAsync(blockNumber)) ?? Buffer.alloc(0);
|
|
455
|
-
const contractClassLogsInBlock:
|
|
499
|
+
const contractClassLogsInBlock: { txHash: TxHash; logs: ContractClassLog[] }[] = [];
|
|
456
500
|
|
|
457
501
|
const reader = new BufferReader(contractClassLogsBuffer);
|
|
458
502
|
const blockHash = this.#unpackBlockHash(reader);
|
|
459
503
|
|
|
460
504
|
while (reader.remainingBytes() > 0) {
|
|
461
505
|
const indexOfTx = reader.readNumber();
|
|
506
|
+
const txHash = reader.readObject(TxHash);
|
|
462
507
|
const numLogsInTx = reader.readNumber();
|
|
463
|
-
contractClassLogsInBlock[indexOfTx] = [];
|
|
508
|
+
contractClassLogsInBlock[indexOfTx] = { txHash, logs: [] };
|
|
464
509
|
for (let i = 0; i < numLogsInTx; i++) {
|
|
465
|
-
contractClassLogsInBlock[indexOfTx].push(reader.readObject(ContractClassLog));
|
|
510
|
+
contractClassLogsInBlock[indexOfTx].logs.push(reader.readObject(ContractClassLog));
|
|
466
511
|
}
|
|
467
512
|
}
|
|
468
513
|
|
|
469
|
-
const
|
|
514
|
+
const txData = contractClassLogsInBlock[txIndex];
|
|
470
515
|
|
|
471
516
|
const logs: ExtendedContractClassLog[] = [];
|
|
472
|
-
const maxLogsHit = this.#
|
|
517
|
+
const maxLogsHit = this.#accumulateContractClassLogs(
|
|
518
|
+
logs,
|
|
519
|
+
blockNumber,
|
|
520
|
+
blockHash,
|
|
521
|
+
txIndex,
|
|
522
|
+
txData.txHash,
|
|
523
|
+
txData.logs,
|
|
524
|
+
filter,
|
|
525
|
+
);
|
|
473
526
|
|
|
474
527
|
return { logs, maxLogsHit };
|
|
475
528
|
}
|
|
@@ -493,20 +546,29 @@ export class LogStore {
|
|
|
493
546
|
start,
|
|
494
547
|
end,
|
|
495
548
|
})) {
|
|
496
|
-
const contractClassLogsInBlock:
|
|
549
|
+
const contractClassLogsInBlock: { txHash: TxHash; logs: ContractClassLog[] }[] = [];
|
|
497
550
|
const reader = new BufferReader(logBuffer);
|
|
498
551
|
const blockHash = this.#unpackBlockHash(reader);
|
|
499
552
|
while (reader.remainingBytes() > 0) {
|
|
500
553
|
const indexOfTx = reader.readNumber();
|
|
554
|
+
const txHash = reader.readObject(TxHash);
|
|
501
555
|
const numLogsInTx = reader.readNumber();
|
|
502
|
-
contractClassLogsInBlock[indexOfTx] = [];
|
|
556
|
+
contractClassLogsInBlock[indexOfTx] = { txHash, logs: [] };
|
|
503
557
|
for (let i = 0; i < numLogsInTx; i++) {
|
|
504
|
-
contractClassLogsInBlock[indexOfTx].push(reader.readObject(ContractClassLog));
|
|
558
|
+
contractClassLogsInBlock[indexOfTx].logs.push(reader.readObject(ContractClassLog));
|
|
505
559
|
}
|
|
506
560
|
}
|
|
507
561
|
for (let txIndex = filter.afterLog?.txIndex ?? 0; txIndex < contractClassLogsInBlock.length; txIndex++) {
|
|
508
|
-
const
|
|
509
|
-
maxLogsHit = this.#
|
|
562
|
+
const txData = contractClassLogsInBlock[txIndex];
|
|
563
|
+
maxLogsHit = this.#accumulateContractClassLogs(
|
|
564
|
+
logs,
|
|
565
|
+
blockNumber,
|
|
566
|
+
blockHash,
|
|
567
|
+
txIndex,
|
|
568
|
+
txData.txHash,
|
|
569
|
+
txData.logs,
|
|
570
|
+
filter,
|
|
571
|
+
);
|
|
510
572
|
if (maxLogsHit) {
|
|
511
573
|
this.#log.debug(`Max logs hit at block ${blockNumber}`);
|
|
512
574
|
break loopOverBlocks;
|
|
@@ -517,12 +579,13 @@ export class LogStore {
|
|
|
517
579
|
return { logs, maxLogsHit };
|
|
518
580
|
}
|
|
519
581
|
|
|
520
|
-
#
|
|
521
|
-
results:
|
|
582
|
+
#accumulatePublicLogs(
|
|
583
|
+
results: ExtendedPublicLog[],
|
|
522
584
|
blockNumber: number,
|
|
523
|
-
blockHash:
|
|
585
|
+
blockHash: BlockHash,
|
|
524
586
|
txIndex: number,
|
|
525
|
-
|
|
587
|
+
txHash: TxHash,
|
|
588
|
+
txLogs: PublicLog[],
|
|
526
589
|
filter: LogFilter = {},
|
|
527
590
|
): boolean {
|
|
528
591
|
let maxLogsHit = false;
|
|
@@ -530,15 +593,37 @@ export class LogStore {
|
|
|
530
593
|
for (; logIndex < txLogs.length; logIndex++) {
|
|
531
594
|
const log = txLogs[logIndex];
|
|
532
595
|
if (!filter.contractAddress || log.contractAddress.equals(filter.contractAddress)) {
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
throw new Error('Unknown log type');
|
|
596
|
+
results.push(
|
|
597
|
+
new ExtendedPublicLog(new LogId(BlockNumber(blockNumber), blockHash, txHash, txIndex, logIndex), log),
|
|
598
|
+
);
|
|
599
|
+
|
|
600
|
+
if (results.length >= this.#logsMaxPageSize) {
|
|
601
|
+
maxLogsHit = true;
|
|
602
|
+
break;
|
|
541
603
|
}
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
return maxLogsHit;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
#accumulateContractClassLogs(
|
|
611
|
+
results: ExtendedContractClassLog[],
|
|
612
|
+
blockNumber: number,
|
|
613
|
+
blockHash: BlockHash,
|
|
614
|
+
txIndex: number,
|
|
615
|
+
txHash: TxHash,
|
|
616
|
+
txLogs: ContractClassLog[],
|
|
617
|
+
filter: LogFilter = {},
|
|
618
|
+
): boolean {
|
|
619
|
+
let maxLogsHit = false;
|
|
620
|
+
let logIndex = typeof filter.afterLog?.logIndex === 'number' ? filter.afterLog.logIndex + 1 : 0;
|
|
621
|
+
for (; logIndex < txLogs.length; logIndex++) {
|
|
622
|
+
const log = txLogs[logIndex];
|
|
623
|
+
if (!filter.contractAddress || log.contractAddress.equals(filter.contractAddress)) {
|
|
624
|
+
results.push(
|
|
625
|
+
new ExtendedContractClassLog(new LogId(BlockNumber(blockNumber), blockHash, txHash, txIndex, logIndex), log),
|
|
626
|
+
);
|
|
542
627
|
|
|
543
628
|
if (results.length >= this.#logsMaxPageSize) {
|
|
544
629
|
maxLogsHit = true;
|
|
@@ -10,10 +10,11 @@ import { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
10
10
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
11
11
|
import { createLogger } from '@aztec/foundation/log';
|
|
12
12
|
import { RollupAbi } from '@aztec/l1-artifacts';
|
|
13
|
-
import { CommitteeAttestation, CommitteeAttestationsAndSigners,
|
|
13
|
+
import { CommitteeAttestation, CommitteeAttestationsAndSigners, L2Block } from '@aztec/stdlib/block';
|
|
14
14
|
import { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
15
15
|
import { getSlotAtTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
16
16
|
import { InboxLeaf } from '@aztec/stdlib/messaging';
|
|
17
|
+
import { ConsensusPayload, SignatureDomainSeparator } from '@aztec/stdlib/p2p';
|
|
17
18
|
import {
|
|
18
19
|
makeAndSignCommitteeAttestationsAndSigners,
|
|
19
20
|
makeCheckpointAttestationFromCheckpoint,
|
|
@@ -22,7 +23,16 @@ import {
|
|
|
22
23
|
import { AppendOnlyTreeSnapshot } from '@aztec/stdlib/trees';
|
|
23
24
|
|
|
24
25
|
import { type MockProxy, mock } from 'jest-mock-extended';
|
|
25
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
type AbiParameter,
|
|
28
|
+
type FormattedBlock,
|
|
29
|
+
type Transaction,
|
|
30
|
+
encodeAbiParameters,
|
|
31
|
+
encodeFunctionData,
|
|
32
|
+
keccak256,
|
|
33
|
+
multicall3Abi,
|
|
34
|
+
toHex,
|
|
35
|
+
} from 'viem';
|
|
26
36
|
|
|
27
37
|
import { updateRollingHash } from '../structs/inbox_message.js';
|
|
28
38
|
|
|
@@ -51,7 +61,7 @@ type AddCheckpointOptions = {
|
|
|
51
61
|
/** Number of L2 blocks in the checkpoint. Default: 1 */
|
|
52
62
|
numBlocks?: number;
|
|
53
63
|
/** Or the actual blocks for the checkpoint */
|
|
54
|
-
blocks?:
|
|
64
|
+
blocks?: L2Block[];
|
|
55
65
|
/** Number of transactions per block. Default: 4 */
|
|
56
66
|
txsPerBlock?: number;
|
|
57
67
|
/** Max number of effects per tx (for generating large blobs). Default: undefined */
|
|
@@ -87,6 +97,10 @@ type CheckpointData = {
|
|
|
87
97
|
blobHashes: `0x${string}`[];
|
|
88
98
|
blobs: Blob[];
|
|
89
99
|
signers: Secp256k1Signer[];
|
|
100
|
+
/** Hash of the packed attestations, matching what the L1 event emits. */
|
|
101
|
+
attestationsHash: Buffer32;
|
|
102
|
+
/** Payload digest, matching what the L1 event emits. */
|
|
103
|
+
payloadDigest: Buffer32;
|
|
90
104
|
/** If true, archiveAt will ignore it */
|
|
91
105
|
pruned?: boolean;
|
|
92
106
|
};
|
|
@@ -131,6 +145,7 @@ export class FakeL1State {
|
|
|
131
145
|
private provenCheckpointNumber: CheckpointNumber = CheckpointNumber(0);
|
|
132
146
|
private targetCommitteeSize: number = 0;
|
|
133
147
|
private version: bigint = 1n;
|
|
148
|
+
private canPruneResult: boolean = false;
|
|
134
149
|
|
|
135
150
|
// Computed from checkpoints based on L1 block visibility
|
|
136
151
|
private pendingCheckpointNumber: CheckpointNumber = CheckpointNumber(0);
|
|
@@ -193,10 +208,10 @@ export class FakeL1State {
|
|
|
193
208
|
// Store the messages internally so they match the checkpoint's inHash
|
|
194
209
|
this.addMessages(checkpointNumber, messagesL1BlockNumber, messages);
|
|
195
210
|
|
|
196
|
-
// Create the transaction and
|
|
197
|
-
const tx = this.makeRollupTx(checkpoint, signers);
|
|
198
|
-
const blobHashes = this.makeVersionedBlobHashes(checkpoint);
|
|
199
|
-
const blobs = this.makeBlobsFromCheckpoint(checkpoint);
|
|
211
|
+
// Create the transaction, blobs, and event hashes
|
|
212
|
+
const { tx, attestationsHash, payloadDigest } = await this.makeRollupTx(checkpoint, signers);
|
|
213
|
+
const blobHashes = await this.makeVersionedBlobHashes(checkpoint);
|
|
214
|
+
const blobs = await this.makeBlobsFromCheckpoint(checkpoint);
|
|
200
215
|
|
|
201
216
|
// Store the checkpoint data
|
|
202
217
|
this.checkpoints.push({
|
|
@@ -207,6 +222,8 @@ export class FakeL1State {
|
|
|
207
222
|
blobHashes,
|
|
208
223
|
blobs,
|
|
209
224
|
signers,
|
|
225
|
+
attestationsHash,
|
|
226
|
+
payloadDigest,
|
|
210
227
|
});
|
|
211
228
|
|
|
212
229
|
// Update last archive for auto-chaining
|
|
@@ -276,6 +293,11 @@ export class FakeL1State {
|
|
|
276
293
|
this.targetCommitteeSize = size;
|
|
277
294
|
}
|
|
278
295
|
|
|
296
|
+
/** Sets whether the rollup contract would allow pruning at the next block. */
|
|
297
|
+
setCanPrune(value: boolean): void {
|
|
298
|
+
this.canPruneResult = value;
|
|
299
|
+
}
|
|
300
|
+
|
|
279
301
|
/**
|
|
280
302
|
* Removes all entries for a checkpoint number (simulates L1 reorg or prune).
|
|
281
303
|
* Note: Does NOT remove messages for this checkpoint (use numL1ToL2Messages: 0 when re-adding).
|
|
@@ -384,6 +406,8 @@ export class FakeL1State {
|
|
|
384
406
|
});
|
|
385
407
|
});
|
|
386
408
|
|
|
409
|
+
mockRollup.canPruneAtTime.mockImplementation(() => Promise.resolve(this.canPruneResult));
|
|
410
|
+
|
|
387
411
|
// Mock the wrapper method for fetching checkpoint events
|
|
388
412
|
mockRollup.getCheckpointProposedEvents.mockImplementation((fromBlock: bigint, toBlock: bigint) =>
|
|
389
413
|
Promise.resolve(this.getCheckpointProposedLogs(fromBlock, toBlock)),
|
|
@@ -502,10 +526,8 @@ export class FakeL1State {
|
|
|
502
526
|
checkpointNumber: cpData.checkpointNumber,
|
|
503
527
|
archive: cpData.checkpoint.archive.root,
|
|
504
528
|
versionedBlobHashes: cpData.blobHashes.map(h => Buffer.from(h.slice(2), 'hex')),
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
payloadDigest: undefined,
|
|
508
|
-
attestationsHash: undefined,
|
|
529
|
+
attestationsHash: cpData.attestationsHash,
|
|
530
|
+
payloadDigest: cpData.payloadDigest,
|
|
509
531
|
},
|
|
510
532
|
}));
|
|
511
533
|
}
|
|
@@ -531,14 +553,17 @@ export class FakeL1State {
|
|
|
531
553
|
}));
|
|
532
554
|
}
|
|
533
555
|
|
|
534
|
-
private makeRollupTx(
|
|
556
|
+
private async makeRollupTx(
|
|
557
|
+
checkpoint: Checkpoint,
|
|
558
|
+
signers: Secp256k1Signer[],
|
|
559
|
+
): Promise<{ tx: Transaction; attestationsHash: Buffer32; payloadDigest: Buffer32 }> {
|
|
535
560
|
const attestations = signers
|
|
536
561
|
.map(signer => makeCheckpointAttestationFromCheckpoint(checkpoint, signer))
|
|
537
562
|
.map(attestation => CommitteeAttestation.fromSignature(attestation.signature))
|
|
538
563
|
.map(committeeAttestation => committeeAttestation.toViem());
|
|
539
564
|
|
|
540
565
|
const header = checkpoint.header.toViem();
|
|
541
|
-
const blobInput = getPrefixedEthBlobCommitments(getBlobsPerL1Block(checkpoint.toBlobFields()));
|
|
566
|
+
const blobInput = getPrefixedEthBlobCommitments(await getBlobsPerL1Block(checkpoint.toBlobFields()));
|
|
542
567
|
const archive = toHex(checkpoint.archive.root.toBuffer());
|
|
543
568
|
const attestationsAndSigners = new CommitteeAttestationsAndSigners(
|
|
544
569
|
attestations.map(attestation => CommitteeAttestation.fromViem(attestation)),
|
|
@@ -549,6 +574,8 @@ export class FakeL1State {
|
|
|
549
574
|
signers[0],
|
|
550
575
|
);
|
|
551
576
|
|
|
577
|
+
const packedAttestations = attestationsAndSigners.getPackedAttestations();
|
|
578
|
+
|
|
552
579
|
const rollupInput = encodeFunctionData({
|
|
553
580
|
abi: RollupAbi,
|
|
554
581
|
functionName: 'propose',
|
|
@@ -558,7 +585,7 @@ export class FakeL1State {
|
|
|
558
585
|
archive,
|
|
559
586
|
oracleInput: { feeAssetPriceModifier: 0n },
|
|
560
587
|
},
|
|
561
|
-
|
|
588
|
+
packedAttestations,
|
|
562
589
|
attestationsAndSigners.getSigners().map(signer => signer.toString()),
|
|
563
590
|
attestationsAndSignersSignature.toViemSignature(),
|
|
564
591
|
blobInput,
|
|
@@ -579,21 +606,52 @@ export class FakeL1State {
|
|
|
579
606
|
],
|
|
580
607
|
});
|
|
581
608
|
|
|
582
|
-
|
|
609
|
+
// Compute attestationsHash (same logic as CalldataRetriever)
|
|
610
|
+
const attestationsHash = Buffer32.fromString(
|
|
611
|
+
keccak256(encodeAbiParameters([this.getCommitteeAttestationsStructDef()], [packedAttestations])),
|
|
612
|
+
);
|
|
613
|
+
|
|
614
|
+
// Compute payloadDigest (same logic as CalldataRetriever)
|
|
615
|
+
const consensusPayload = ConsensusPayload.fromCheckpoint(checkpoint);
|
|
616
|
+
const payloadToSign = consensusPayload.getPayloadToSign(SignatureDomainSeparator.checkpointAttestation);
|
|
617
|
+
const payloadDigest = Buffer32.fromString(keccak256(payloadToSign));
|
|
618
|
+
|
|
619
|
+
const tx = {
|
|
583
620
|
input: multiCallInput,
|
|
584
621
|
hash: archive,
|
|
585
622
|
blockHash: archive,
|
|
586
623
|
to: MULTI_CALL_3_ADDRESS as `0x${string}`,
|
|
587
624
|
} as Transaction<bigint, number>;
|
|
625
|
+
|
|
626
|
+
return { tx, attestationsHash, payloadDigest };
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
/** Extracts the CommitteeAttestations struct definition from RollupAbi for hash computation. */
|
|
630
|
+
private getCommitteeAttestationsStructDef(): AbiParameter {
|
|
631
|
+
const proposeFunction = RollupAbi.find(item => item.type === 'function' && item.name === 'propose') as
|
|
632
|
+
| { type: 'function'; name: string; inputs: readonly AbiParameter[] }
|
|
633
|
+
| undefined;
|
|
634
|
+
|
|
635
|
+
if (!proposeFunction) {
|
|
636
|
+
throw new Error('propose function not found in RollupAbi');
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
const attestationsParam = proposeFunction.inputs.find(param => param.name === '_attestations');
|
|
640
|
+
if (!attestationsParam) {
|
|
641
|
+
throw new Error('_attestations parameter not found in propose function');
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
const tupleParam = attestationsParam as unknown as { type: 'tuple'; components?: readonly AbiParameter[] };
|
|
645
|
+
return { type: 'tuple', components: tupleParam.components || [] } as AbiParameter;
|
|
588
646
|
}
|
|
589
647
|
|
|
590
|
-
private makeVersionedBlobHashes(checkpoint: Checkpoint):
|
|
591
|
-
return getBlobsPerL1Block(checkpoint.toBlobFields()).map(
|
|
648
|
+
private async makeVersionedBlobHashes(checkpoint: Checkpoint): Promise<`0x${string}`[]> {
|
|
649
|
+
return (await getBlobsPerL1Block(checkpoint.toBlobFields())).map(
|
|
592
650
|
b => `0x${b.getEthVersionedBlobHash().toString('hex')}` as `0x${string}`,
|
|
593
651
|
);
|
|
594
652
|
}
|
|
595
653
|
|
|
596
|
-
private makeBlobsFromCheckpoint(checkpoint: Checkpoint): Blob[] {
|
|
597
|
-
return getBlobsPerL1Block(checkpoint.toBlobFields());
|
|
654
|
+
private async makeBlobsFromCheckpoint(checkpoint: Checkpoint): Promise<Blob[]> {
|
|
655
|
+
return await getBlobsPerL1Block(checkpoint.toBlobFields());
|
|
598
656
|
}
|
|
599
657
|
}
|
package/src/test/index.ts
CHANGED
|
@@ -2,3 +2,6 @@ export * from './mock_structs.js';
|
|
|
2
2
|
export * from './mock_l2_block_source.js';
|
|
3
3
|
export * from './mock_l1_to_l2_message_source.js';
|
|
4
4
|
export * from './mock_archiver.js';
|
|
5
|
+
// NOTE: noop_l1_archiver.js is intentionally NOT exported here because it imports
|
|
6
|
+
// jest-mock-extended, which depends on @jest/globals and can only run inside Jest.
|
|
7
|
+
// Import it directly: import { NoopL1Archiver } from '@aztec/archiver/test/noop-l1';
|
|
@@ -56,8 +56,9 @@ export class MockPrefilledArchiver extends MockArchiver {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
const fromBlock = this.l2Blocks.length;
|
|
59
|
-
|
|
60
|
-
this.
|
|
59
|
+
const checkpointsToAdd = this.prefilled.slice(fromBlock, fromBlock + numBlocks);
|
|
60
|
+
this.addProposedBlocks(checkpointsToAdd.flatMap(c => c.blocks));
|
|
61
|
+
this.checkpointList.push(...checkpointsToAdd);
|
|
61
62
|
return Promise.resolve();
|
|
62
63
|
}
|
|
63
64
|
}
|