@aztec/archiver 0.0.1-commit.2ed92850 → 0.0.1-commit.3d8f95d
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/dest/archiver.d.ts +3 -2
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +15 -2
- package/dest/factory.d.ts +3 -1
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +6 -5
- package/dest/l1/bin/retrieve-calldata.js +18 -19
- package/dest/l1/data_retrieval.js +1 -1
- 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 +5 -5
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/instrumentation.d.ts +1 -1
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +17 -10
- package/dest/modules/l1_synchronizer.d.ts +1 -1
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +2 -3
- package/dest/store/block_store.d.ts +5 -5
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +2 -2
- 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 +5 -5
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +2 -3
- package/dest/store/log_store.d.ts +1 -1
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +57 -37
- package/dest/test/index.js +3 -1
- package/dest/test/mock_l2_block_source.d.ts +6 -6
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +3 -3
- 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 +7 -5
- 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 +22 -2
- package/src/factory.ts +19 -11
- package/src/l1/bin/retrieve-calldata.ts +17 -23
- package/src/l1/data_retrieval.ts +1 -1
- package/src/l1/validate_trace.ts +24 -6
- package/src/modules/data_source_base.ts +4 -4
- package/src/modules/instrumentation.ts +15 -10
- package/src/modules/l1_synchronizer.ts +2 -3
- package/src/store/block_store.ts +5 -5
- package/src/store/contract_class_store.ts +11 -7
- package/src/store/kv_archiver_store.ts +6 -6
- package/src/store/log_store.ts +98 -36
- package/src/test/index.ts +3 -0
- package/src/test/mock_l2_block_source.ts +6 -6
- package/src/test/mock_structs.ts +22 -6
- package/src/test/noop_l1_archiver.ts +109 -0
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
type TelemetryClient,
|
|
11
11
|
type Tracer,
|
|
12
12
|
type UpDownCounter,
|
|
13
|
+
createUpDownCounterWithDefault,
|
|
13
14
|
} from '@aztec/telemetry-client';
|
|
14
15
|
|
|
15
16
|
export class ArchiverInstrumentation {
|
|
@@ -48,15 +49,17 @@ export class ArchiverInstrumentation {
|
|
|
48
49
|
|
|
49
50
|
this.l1BlockHeight = meter.createGauge(Metrics.ARCHIVER_L1_BLOCK_HEIGHT);
|
|
50
51
|
|
|
51
|
-
this.txCount = meter
|
|
52
|
+
this.txCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_TOTAL_TXS);
|
|
52
53
|
|
|
53
|
-
this.proofsSubmittedCount = meter
|
|
54
|
+
this.proofsSubmittedCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_ROLLUP_PROOF_COUNT, {
|
|
55
|
+
[Attributes.PROOF_TIMED_OUT]: [true, false],
|
|
56
|
+
});
|
|
54
57
|
|
|
55
58
|
this.proofsSubmittedDelay = meter.createHistogram(Metrics.ARCHIVER_ROLLUP_PROOF_DELAY);
|
|
56
59
|
|
|
57
60
|
this.syncDurationPerBlock = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_BLOCK);
|
|
58
61
|
|
|
59
|
-
this.syncBlockCount = meter
|
|
62
|
+
this.syncBlockCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_SYNC_BLOCK_COUNT);
|
|
60
63
|
|
|
61
64
|
this.manaPerBlock = meter.createHistogram(Metrics.ARCHIVER_MANA_PER_BLOCK);
|
|
62
65
|
|
|
@@ -64,13 +67,19 @@ export class ArchiverInstrumentation {
|
|
|
64
67
|
|
|
65
68
|
this.syncDurationPerMessage = meter.createHistogram(Metrics.ARCHIVER_SYNC_PER_MESSAGE);
|
|
66
69
|
|
|
67
|
-
this.syncMessageCount = meter
|
|
70
|
+
this.syncMessageCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_SYNC_MESSAGE_COUNT);
|
|
68
71
|
|
|
69
72
|
this.pruneDuration = meter.createHistogram(Metrics.ARCHIVER_PRUNE_DURATION);
|
|
70
73
|
|
|
71
|
-
this.pruneCount = meter
|
|
74
|
+
this.pruneCount = createUpDownCounterWithDefault(meter, Metrics.ARCHIVER_PRUNE_COUNT);
|
|
72
75
|
|
|
73
|
-
this.blockProposalTxTargetCount =
|
|
76
|
+
this.blockProposalTxTargetCount = createUpDownCounterWithDefault(
|
|
77
|
+
meter,
|
|
78
|
+
Metrics.ARCHIVER_BLOCK_PROPOSAL_TX_TARGET_COUNT,
|
|
79
|
+
{
|
|
80
|
+
[Attributes.L1_BLOCK_PROPOSAL_USED_TRACE]: [true, false],
|
|
81
|
+
},
|
|
82
|
+
);
|
|
74
83
|
|
|
75
84
|
this.dbMetrics = new LmdbMetrics(
|
|
76
85
|
meter,
|
|
@@ -84,10 +93,6 @@ export class ArchiverInstrumentation {
|
|
|
84
93
|
public static async new(telemetry: TelemetryClient, lmdbStats?: LmdbStatsCallback) {
|
|
85
94
|
const instance = new ArchiverInstrumentation(telemetry, lmdbStats);
|
|
86
95
|
|
|
87
|
-
instance.syncBlockCount.add(0);
|
|
88
|
-
instance.syncMessageCount.add(0);
|
|
89
|
-
instance.pruneCount.add(0);
|
|
90
|
-
|
|
91
96
|
await instance.telemetry.flush();
|
|
92
97
|
|
|
93
98
|
return instance;
|
|
@@ -16,7 +16,7 @@ import { DateProvider, Timer, elapsed } from '@aztec/foundation/timer';
|
|
|
16
16
|
import { isDefined } from '@aztec/foundation/types';
|
|
17
17
|
import { type ArchiverEmitter, L2BlockSourceEvents, type ValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
18
18
|
import { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
19
|
-
import { type L1RollupConstants, getEpochAtSlot,
|
|
19
|
+
import { type L1RollupConstants, getEpochAtSlot, getSlotAtNextL1Block } from '@aztec/stdlib/epoch-helpers';
|
|
20
20
|
import { computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
21
21
|
import { type Traceable, type Tracer, execInSpan, trackSpan } from '@aztec/telemetry-client';
|
|
22
22
|
|
|
@@ -249,8 +249,7 @@ export class ArchiverL1Synchronizer implements Traceable {
|
|
|
249
249
|
const firstUncheckpointedBlockSlot = firstUncheckpointedBlockHeader?.getSlot();
|
|
250
250
|
|
|
251
251
|
// What's the slot at the next L1 block? All blocks for slots strictly before this one should've been checkpointed by now.
|
|
252
|
-
const
|
|
253
|
-
const slotAtNextL1Block = getSlotAtTimestamp(nextL1BlockTimestamp, this.l1Constants);
|
|
252
|
+
const slotAtNextL1Block = getSlotAtNextL1Block(currentL1Timestamp, this.l1Constants);
|
|
254
253
|
|
|
255
254
|
// Prune provisional blocks from slots that have ended without being checkpointed
|
|
256
255
|
if (firstUncheckpointedBlockSlot !== undefined && firstUncheckpointedBlockSlot < slotAtNextL1Block) {
|
package/src/store/block_store.ts
CHANGED
|
@@ -9,11 +9,11 @@ import { isDefined } from '@aztec/foundation/types';
|
|
|
9
9
|
import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncSingleton, Range } from '@aztec/kv-store';
|
|
10
10
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
11
11
|
import {
|
|
12
|
+
BlockHash,
|
|
12
13
|
Body,
|
|
13
14
|
CheckpointedL2Block,
|
|
14
15
|
CommitteeAttestation,
|
|
15
16
|
L2Block,
|
|
16
|
-
L2BlockHash,
|
|
17
17
|
type ValidateCheckpointResult,
|
|
18
18
|
deserializeValidateCheckpointResult,
|
|
19
19
|
serializeValidateCheckpointResult,
|
|
@@ -351,7 +351,7 @@ export class BlockStore {
|
|
|
351
351
|
}
|
|
352
352
|
|
|
353
353
|
private async addBlockToDatabase(block: L2Block, checkpointNumber: number, indexWithinCheckpoint: number) {
|
|
354
|
-
const blockHash =
|
|
354
|
+
const blockHash = await block.hash();
|
|
355
355
|
|
|
356
356
|
await this.#blocks.set(block.number, {
|
|
357
357
|
header: block.header.toBuffer(),
|
|
@@ -624,7 +624,7 @@ export class BlockStore {
|
|
|
624
624
|
}
|
|
625
625
|
}
|
|
626
626
|
|
|
627
|
-
async getCheckpointedBlockByHash(blockHash:
|
|
627
|
+
async getCheckpointedBlockByHash(blockHash: BlockHash): Promise<CheckpointedL2Block | undefined> {
|
|
628
628
|
const blockNumber = await this.#blockHashIndex.getAsync(blockHash.toString());
|
|
629
629
|
if (blockNumber === undefined) {
|
|
630
630
|
return undefined;
|
|
@@ -673,7 +673,7 @@ export class BlockStore {
|
|
|
673
673
|
* @param blockHash - The hash of the block to return.
|
|
674
674
|
* @returns The requested L2 block.
|
|
675
675
|
*/
|
|
676
|
-
async getBlockByHash(blockHash:
|
|
676
|
+
async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
677
677
|
const blockNumber = await this.#blockHashIndex.getAsync(blockHash.toString());
|
|
678
678
|
if (blockNumber === undefined) {
|
|
679
679
|
return undefined;
|
|
@@ -699,7 +699,7 @@ export class BlockStore {
|
|
|
699
699
|
* @param blockHash - The hash of the block to return.
|
|
700
700
|
* @returns The requested block header.
|
|
701
701
|
*/
|
|
702
|
-
async getBlockHeaderByHash(blockHash:
|
|
702
|
+
async getBlockHeaderByHash(blockHash: BlockHash): Promise<BlockHeader | undefined> {
|
|
703
703
|
const blockNumber = await this.#blockHashIndex.getAsync(blockHash.toString());
|
|
704
704
|
if (blockNumber === undefined) {
|
|
705
705
|
return undefined;
|
|
@@ -28,18 +28,22 @@ export class ContractClassStore {
|
|
|
28
28
|
bytecodeCommitment: Fr,
|
|
29
29
|
blockNumber: number,
|
|
30
30
|
): Promise<void> {
|
|
31
|
-
await this
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
await this.db.transactionAsync(async () => {
|
|
32
|
+
await this.#contractClasses.setIfNotExists(
|
|
33
|
+
contractClass.id.toString(),
|
|
34
|
+
serializeContractClassPublic({ ...contractClass, l2BlockNumber: blockNumber }),
|
|
35
|
+
);
|
|
36
|
+
await this.#bytecodeCommitments.setIfNotExists(contractClass.id.toString(), bytecodeCommitment.toBuffer());
|
|
37
|
+
});
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
async deleteContractClasses(contractClass: ContractClassPublic, blockNumber: number): Promise<void> {
|
|
39
41
|
const restoredContractClass = await this.#contractClasses.getAsync(contractClass.id.toString());
|
|
40
42
|
if (restoredContractClass && deserializeContractClassPublic(restoredContractClass).l2BlockNumber >= blockNumber) {
|
|
41
|
-
await this
|
|
42
|
-
|
|
43
|
+
await this.db.transactionAsync(async () => {
|
|
44
|
+
await this.#contractClasses.delete(contractClass.id.toString());
|
|
45
|
+
await this.#bytecodeCommitments.delete(contractClass.id.toString());
|
|
46
|
+
});
|
|
43
47
|
}
|
|
44
48
|
}
|
|
45
49
|
|
|
@@ -6,7 +6,7 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
6
6
|
import type { AztecAsyncKVStore, CustomRange, StoreSize } from '@aztec/kv-store';
|
|
7
7
|
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
8
8
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
9
|
-
import { CheckpointedL2Block, L2Block,
|
|
9
|
+
import { BlockHash, CheckpointedL2Block, L2Block, type ValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
10
10
|
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
11
11
|
import type {
|
|
12
12
|
ContractClassPublic,
|
|
@@ -291,7 +291,7 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
291
291
|
* Returns the block for the given hash, or undefined if not exists.
|
|
292
292
|
* @param blockHash - The block hash to return.
|
|
293
293
|
*/
|
|
294
|
-
getCheckpointedBlockByHash(blockHash:
|
|
294
|
+
getCheckpointedBlockByHash(blockHash: BlockHash): Promise<CheckpointedL2Block | undefined> {
|
|
295
295
|
return this.#blockStore.getCheckpointedBlockByHash(blockHash);
|
|
296
296
|
}
|
|
297
297
|
/**
|
|
@@ -312,8 +312,8 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
312
312
|
* Returns the block for the given hash, or undefined if not exists.
|
|
313
313
|
* @param blockHash - The block hash to return.
|
|
314
314
|
*/
|
|
315
|
-
getBlockByHash(blockHash:
|
|
316
|
-
return this.#blockStore.getBlockByHash(
|
|
315
|
+
getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
316
|
+
return this.#blockStore.getBlockByHash(blockHash);
|
|
317
317
|
}
|
|
318
318
|
/**
|
|
319
319
|
* Returns the block for the given archive root, or undefined if not exists.
|
|
@@ -357,8 +357,8 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
357
357
|
* Returns the block header for the given hash, or undefined if not exists.
|
|
358
358
|
* @param blockHash - The block hash to return.
|
|
359
359
|
*/
|
|
360
|
-
getBlockHeaderByHash(blockHash:
|
|
361
|
-
return this.#blockStore.getBlockHeaderByHash(
|
|
360
|
+
getBlockHeaderByHash(blockHash: BlockHash): Promise<BlockHeader | undefined> {
|
|
361
|
+
return this.#blockStore.getBlockHeaderByHash(blockHash);
|
|
362
362
|
}
|
|
363
363
|
|
|
364
364
|
/**
|
package/src/store/log_store.ts
CHANGED
|
@@ -6,7 +6,7 @@ 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
10
|
import { MAX_LOGS_PER_TAG } from '@aztec/stdlib/interfaces/api-limit';
|
|
11
11
|
import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
|
|
12
12
|
import {
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
Tag,
|
|
21
21
|
TxScopedL2Log,
|
|
22
22
|
} from '@aztec/stdlib/logs';
|
|
23
|
+
import { TxHash } from '@aztec/stdlib/tx';
|
|
23
24
|
|
|
24
25
|
import type { BlockStore } from './block_store.js';
|
|
25
26
|
|
|
@@ -219,6 +220,7 @@ export class LogStore {
|
|
|
219
220
|
.map((txEffect, txIndex) =>
|
|
220
221
|
[
|
|
221
222
|
numToUInt32BE(txIndex),
|
|
223
|
+
txEffect.txHash.toBuffer(),
|
|
222
224
|
numToUInt32BE(txEffect.publicLogs.length),
|
|
223
225
|
txEffect.publicLogs.map(log => log.toBuffer()),
|
|
224
226
|
].flat(),
|
|
@@ -242,6 +244,7 @@ export class LogStore {
|
|
|
242
244
|
.map((txEffect, txIndex) =>
|
|
243
245
|
[
|
|
244
246
|
numToUInt32BE(txIndex),
|
|
247
|
+
txEffect.txHash.toBuffer(),
|
|
245
248
|
numToUInt32BE(txEffect.contractClassLogs.length),
|
|
246
249
|
txEffect.contractClassLogs.map(log => log.toBuffer()),
|
|
247
250
|
].flat(),
|
|
@@ -271,18 +274,18 @@ export class LogStore {
|
|
|
271
274
|
});
|
|
272
275
|
}
|
|
273
276
|
|
|
274
|
-
#packWithBlockHash(blockHash:
|
|
277
|
+
#packWithBlockHash(blockHash: BlockHash, data: Buffer<ArrayBufferLike>[]): Buffer<ArrayBufferLike> {
|
|
275
278
|
return Buffer.concat([blockHash.toBuffer(), ...data]);
|
|
276
279
|
}
|
|
277
280
|
|
|
278
|
-
#unpackBlockHash(reader: BufferReader):
|
|
281
|
+
#unpackBlockHash(reader: BufferReader): BlockHash {
|
|
279
282
|
const blockHash = reader.remainingBytes() > 0 ? reader.readObject(Fr) : undefined;
|
|
280
283
|
|
|
281
284
|
if (!blockHash) {
|
|
282
285
|
throw new Error('Failed to read block hash from log entry buffer');
|
|
283
286
|
}
|
|
284
287
|
|
|
285
|
-
return
|
|
288
|
+
return new BlockHash(blockHash);
|
|
286
289
|
}
|
|
287
290
|
|
|
288
291
|
deleteLogs(blocks: L2Block[]): Promise<boolean> {
|
|
@@ -386,24 +389,33 @@ export class LogStore {
|
|
|
386
389
|
}
|
|
387
390
|
|
|
388
391
|
const buffer = (await this.#publicLogsByBlock.getAsync(blockNumber)) ?? Buffer.alloc(0);
|
|
389
|
-
const publicLogsInBlock:
|
|
392
|
+
const publicLogsInBlock: { txHash: TxHash; logs: PublicLog[] }[] = [];
|
|
390
393
|
const reader = new BufferReader(buffer);
|
|
391
394
|
|
|
392
395
|
const blockHash = this.#unpackBlockHash(reader);
|
|
393
396
|
|
|
394
397
|
while (reader.remainingBytes() > 0) {
|
|
395
398
|
const indexOfTx = reader.readNumber();
|
|
399
|
+
const txHash = reader.readObject(TxHash);
|
|
396
400
|
const numLogsInTx = reader.readNumber();
|
|
397
|
-
publicLogsInBlock[indexOfTx] = [];
|
|
401
|
+
publicLogsInBlock[indexOfTx] = { txHash, logs: [] };
|
|
398
402
|
for (let i = 0; i < numLogsInTx; i++) {
|
|
399
|
-
publicLogsInBlock[indexOfTx].push(reader.readObject(PublicLog));
|
|
403
|
+
publicLogsInBlock[indexOfTx].logs.push(reader.readObject(PublicLog));
|
|
400
404
|
}
|
|
401
405
|
}
|
|
402
406
|
|
|
403
|
-
const
|
|
407
|
+
const txData = publicLogsInBlock[txIndex];
|
|
404
408
|
|
|
405
409
|
const logs: ExtendedPublicLog[] = [];
|
|
406
|
-
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
|
+
);
|
|
407
419
|
|
|
408
420
|
return { logs, maxLogsHit };
|
|
409
421
|
}
|
|
@@ -424,22 +436,31 @@ export class LogStore {
|
|
|
424
436
|
|
|
425
437
|
let maxLogsHit = false;
|
|
426
438
|
loopOverBlocks: for await (const [blockNumber, logBuffer] of this.#publicLogsByBlock.entriesAsync({ start, end })) {
|
|
427
|
-
const publicLogsInBlock:
|
|
439
|
+
const publicLogsInBlock: { txHash: TxHash; logs: PublicLog[] }[] = [];
|
|
428
440
|
const reader = new BufferReader(logBuffer);
|
|
429
441
|
|
|
430
442
|
const blockHash = this.#unpackBlockHash(reader);
|
|
431
443
|
|
|
432
444
|
while (reader.remainingBytes() > 0) {
|
|
433
445
|
const indexOfTx = reader.readNumber();
|
|
446
|
+
const txHash = reader.readObject(TxHash);
|
|
434
447
|
const numLogsInTx = reader.readNumber();
|
|
435
|
-
publicLogsInBlock[indexOfTx] = [];
|
|
448
|
+
publicLogsInBlock[indexOfTx] = { txHash, logs: [] };
|
|
436
449
|
for (let i = 0; i < numLogsInTx; i++) {
|
|
437
|
-
publicLogsInBlock[indexOfTx].push(reader.readObject(PublicLog));
|
|
450
|
+
publicLogsInBlock[indexOfTx].logs.push(reader.readObject(PublicLog));
|
|
438
451
|
}
|
|
439
452
|
}
|
|
440
453
|
for (let txIndex = filter.afterLog?.txIndex ?? 0; txIndex < publicLogsInBlock.length; txIndex++) {
|
|
441
|
-
const
|
|
442
|
-
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
|
+
);
|
|
443
464
|
if (maxLogsHit) {
|
|
444
465
|
this.#log.debug(`Max logs hit at block ${blockNumber}`);
|
|
445
466
|
break loopOverBlocks;
|
|
@@ -475,24 +496,33 @@ export class LogStore {
|
|
|
475
496
|
return { logs: [], maxLogsHit: false };
|
|
476
497
|
}
|
|
477
498
|
const contractClassLogsBuffer = (await this.#contractClassLogsByBlock.getAsync(blockNumber)) ?? Buffer.alloc(0);
|
|
478
|
-
const contractClassLogsInBlock:
|
|
499
|
+
const contractClassLogsInBlock: { txHash: TxHash; logs: ContractClassLog[] }[] = [];
|
|
479
500
|
|
|
480
501
|
const reader = new BufferReader(contractClassLogsBuffer);
|
|
481
502
|
const blockHash = this.#unpackBlockHash(reader);
|
|
482
503
|
|
|
483
504
|
while (reader.remainingBytes() > 0) {
|
|
484
505
|
const indexOfTx = reader.readNumber();
|
|
506
|
+
const txHash = reader.readObject(TxHash);
|
|
485
507
|
const numLogsInTx = reader.readNumber();
|
|
486
|
-
contractClassLogsInBlock[indexOfTx] = [];
|
|
508
|
+
contractClassLogsInBlock[indexOfTx] = { txHash, logs: [] };
|
|
487
509
|
for (let i = 0; i < numLogsInTx; i++) {
|
|
488
|
-
contractClassLogsInBlock[indexOfTx].push(reader.readObject(ContractClassLog));
|
|
510
|
+
contractClassLogsInBlock[indexOfTx].logs.push(reader.readObject(ContractClassLog));
|
|
489
511
|
}
|
|
490
512
|
}
|
|
491
513
|
|
|
492
|
-
const
|
|
514
|
+
const txData = contractClassLogsInBlock[txIndex];
|
|
493
515
|
|
|
494
516
|
const logs: ExtendedContractClassLog[] = [];
|
|
495
|
-
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
|
+
);
|
|
496
526
|
|
|
497
527
|
return { logs, maxLogsHit };
|
|
498
528
|
}
|
|
@@ -516,20 +546,29 @@ export class LogStore {
|
|
|
516
546
|
start,
|
|
517
547
|
end,
|
|
518
548
|
})) {
|
|
519
|
-
const contractClassLogsInBlock:
|
|
549
|
+
const contractClassLogsInBlock: { txHash: TxHash; logs: ContractClassLog[] }[] = [];
|
|
520
550
|
const reader = new BufferReader(logBuffer);
|
|
521
551
|
const blockHash = this.#unpackBlockHash(reader);
|
|
522
552
|
while (reader.remainingBytes() > 0) {
|
|
523
553
|
const indexOfTx = reader.readNumber();
|
|
554
|
+
const txHash = reader.readObject(TxHash);
|
|
524
555
|
const numLogsInTx = reader.readNumber();
|
|
525
|
-
contractClassLogsInBlock[indexOfTx] = [];
|
|
556
|
+
contractClassLogsInBlock[indexOfTx] = { txHash, logs: [] };
|
|
526
557
|
for (let i = 0; i < numLogsInTx; i++) {
|
|
527
|
-
contractClassLogsInBlock[indexOfTx].push(reader.readObject(ContractClassLog));
|
|
558
|
+
contractClassLogsInBlock[indexOfTx].logs.push(reader.readObject(ContractClassLog));
|
|
528
559
|
}
|
|
529
560
|
}
|
|
530
561
|
for (let txIndex = filter.afterLog?.txIndex ?? 0; txIndex < contractClassLogsInBlock.length; txIndex++) {
|
|
531
|
-
const
|
|
532
|
-
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
|
+
);
|
|
533
572
|
if (maxLogsHit) {
|
|
534
573
|
this.#log.debug(`Max logs hit at block ${blockNumber}`);
|
|
535
574
|
break loopOverBlocks;
|
|
@@ -540,12 +579,13 @@ export class LogStore {
|
|
|
540
579
|
return { logs, maxLogsHit };
|
|
541
580
|
}
|
|
542
581
|
|
|
543
|
-
#
|
|
544
|
-
results:
|
|
582
|
+
#accumulatePublicLogs(
|
|
583
|
+
results: ExtendedPublicLog[],
|
|
545
584
|
blockNumber: number,
|
|
546
|
-
blockHash:
|
|
585
|
+
blockHash: BlockHash,
|
|
547
586
|
txIndex: number,
|
|
548
|
-
|
|
587
|
+
txHash: TxHash,
|
|
588
|
+
txLogs: PublicLog[],
|
|
549
589
|
filter: LogFilter = {},
|
|
550
590
|
): boolean {
|
|
551
591
|
let maxLogsHit = false;
|
|
@@ -553,15 +593,37 @@ export class LogStore {
|
|
|
553
593
|
for (; logIndex < txLogs.length; logIndex++) {
|
|
554
594
|
const log = txLogs[logIndex];
|
|
555
595
|
if (!filter.contractAddress || log.contractAddress.equals(filter.contractAddress)) {
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
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;
|
|
564
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
|
+
);
|
|
565
627
|
|
|
566
628
|
if (results.length >= this.#logsMaxPageSize) {
|
|
567
629
|
maxLogsHit = true;
|
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';
|
|
@@ -8,9 +8,9 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
8
8
|
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
9
9
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
10
10
|
import {
|
|
11
|
+
BlockHash,
|
|
11
12
|
CheckpointedL2Block,
|
|
12
13
|
L2Block,
|
|
13
|
-
L2BlockHash,
|
|
14
14
|
type L2BlockSource,
|
|
15
15
|
type L2Tips,
|
|
16
16
|
type ValidateCheckpointResult,
|
|
@@ -195,7 +195,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
195
195
|
return checkpoint;
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
public async getCheckpointedBlockByHash(blockHash:
|
|
198
|
+
public async getCheckpointedBlockByHash(blockHash: BlockHash): Promise<CheckpointedL2Block | undefined> {
|
|
199
199
|
for (const block of this.l2Blocks) {
|
|
200
200
|
const hash = await block.hash();
|
|
201
201
|
if (hash.equals(blockHash)) {
|
|
@@ -225,7 +225,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
225
225
|
);
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
-
public async getL2BlockByHash(blockHash:
|
|
228
|
+
public async getL2BlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
229
229
|
for (const block of this.l2Blocks) {
|
|
230
230
|
const hash = await block.hash();
|
|
231
231
|
if (hash.equals(blockHash)) {
|
|
@@ -240,7 +240,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
240
240
|
return Promise.resolve(block);
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
-
public async getBlockHeaderByHash(blockHash:
|
|
243
|
+
public async getBlockHeaderByHash(blockHash: BlockHash): Promise<BlockHeader | undefined> {
|
|
244
244
|
for (const block of this.l2Blocks) {
|
|
245
245
|
const hash = await block.hash();
|
|
246
246
|
if (hash.equals(blockHash)) {
|
|
@@ -322,7 +322,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
322
322
|
return {
|
|
323
323
|
data: txEffect,
|
|
324
324
|
l2BlockNumber: block.number,
|
|
325
|
-
l2BlockHash:
|
|
325
|
+
l2BlockHash: await block.hash(),
|
|
326
326
|
txIndexInBlock: block.body.txEffects.indexOf(txEffect),
|
|
327
327
|
};
|
|
328
328
|
}
|
|
@@ -343,7 +343,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
343
343
|
TxExecutionResult.SUCCESS,
|
|
344
344
|
undefined,
|
|
345
345
|
txEffect.transactionFee.toBigInt(),
|
|
346
|
-
|
|
346
|
+
await block.hash(),
|
|
347
347
|
block.number,
|
|
348
348
|
);
|
|
349
349
|
}
|
package/src/test/mock_structs.ts
CHANGED
|
@@ -46,24 +46,40 @@ export function makeInboxMessage(
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export function makeInboxMessages(
|
|
49
|
-
|
|
49
|
+
totalCount: number,
|
|
50
50
|
opts: {
|
|
51
51
|
initialHash?: Buffer16;
|
|
52
52
|
initialCheckpointNumber?: CheckpointNumber;
|
|
53
|
+
messagesPerCheckpoint?: number;
|
|
53
54
|
overrideFn?: (msg: InboxMessage, index: number) => InboxMessage;
|
|
54
55
|
} = {},
|
|
55
56
|
): InboxMessage[] {
|
|
56
|
-
const {
|
|
57
|
+
const {
|
|
58
|
+
initialHash = Buffer16.ZERO,
|
|
59
|
+
overrideFn = msg => msg,
|
|
60
|
+
initialCheckpointNumber = CheckpointNumber(1),
|
|
61
|
+
messagesPerCheckpoint = 1,
|
|
62
|
+
} = opts;
|
|
63
|
+
|
|
57
64
|
const messages: InboxMessage[] = [];
|
|
58
65
|
let rollingHash = initialHash;
|
|
59
|
-
for (let i = 0; i <
|
|
66
|
+
for (let i = 0; i < totalCount; i++) {
|
|
67
|
+
const msgIndex = i % messagesPerCheckpoint;
|
|
68
|
+
const checkpointNumber = CheckpointNumber.fromBigInt(
|
|
69
|
+
BigInt(initialCheckpointNumber) + BigInt(i) / BigInt(messagesPerCheckpoint),
|
|
70
|
+
);
|
|
60
71
|
const leaf = Fr.random();
|
|
61
|
-
const
|
|
62
|
-
|
|
72
|
+
const message = overrideFn(
|
|
73
|
+
makeInboxMessage(rollingHash, {
|
|
74
|
+
leaf,
|
|
75
|
+
checkpointNumber,
|
|
76
|
+
index: InboxLeaf.smallestIndexForCheckpoint(checkpointNumber) + BigInt(msgIndex),
|
|
77
|
+
}),
|
|
78
|
+
i,
|
|
79
|
+
);
|
|
63
80
|
rollingHash = message.rollingHash;
|
|
64
81
|
messages.push(message);
|
|
65
82
|
}
|
|
66
|
-
|
|
67
83
|
return messages;
|
|
68
84
|
}
|
|
69
85
|
|