@aztec/archiver 0.65.2 → 0.67.0
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/archiver.d.ts +20 -24
- package/dest/archiver/archiver.d.ts.map +1 -1
- package/dest/archiver/archiver.js +148 -102
- package/dest/archiver/archiver_store.d.ts +8 -9
- package/dest/archiver/archiver_store.d.ts.map +1 -1
- package/dest/archiver/archiver_store_test_suite.d.ts.map +1 -1
- package/dest/archiver/archiver_store_test_suite.js +126 -150
- package/dest/archiver/config.d.ts +6 -12
- package/dest/archiver/config.d.ts.map +1 -1
- package/dest/archiver/config.js +6 -1
- package/dest/archiver/data_retrieval.d.ts +4 -5
- package/dest/archiver/data_retrieval.d.ts.map +1 -1
- package/dest/archiver/data_retrieval.js +21 -22
- package/dest/archiver/instrumentation.d.ts +4 -7
- package/dest/archiver/instrumentation.d.ts.map +1 -1
- package/dest/archiver/instrumentation.js +17 -22
- package/dest/archiver/kv_archiver_store/block_store.d.ts +2 -2
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/block_store.js +6 -6
- package/dest/archiver/kv_archiver_store/contract_class_store.js +2 -2
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +8 -9
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.js +9 -10
- package/dest/archiver/kv_archiver_store/log_store.d.ts +7 -8
- package/dest/archiver/kv_archiver_store/log_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/log_store.js +57 -97
- package/dest/archiver/kv_archiver_store/message_store.js +3 -3
- package/dest/archiver/kv_archiver_store/nullifier_store.js +3 -3
- package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts +9 -11
- package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts.map +1 -1
- package/dest/archiver/memory_archiver_store/memory_archiver_store.js +53 -60
- package/dest/factory.js +4 -4
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +3 -42
- package/dest/test/mock_l2_block_source.d.ts +2 -2
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +4 -4
- package/package.json +15 -13
- package/src/archiver/archiver.ts +208 -198
- package/src/archiver/archiver_store.ts +8 -15
- package/src/archiver/archiver_store_test_suite.ts +160 -186
- package/src/archiver/config.ts +12 -12
- package/src/archiver/data_retrieval.ts +21 -26
- package/src/archiver/instrumentation.ts +21 -23
- package/src/archiver/kv_archiver_store/block_store.ts +6 -6
- package/src/archiver/kv_archiver_store/contract_class_store.ts +1 -1
- package/src/archiver/kv_archiver_store/kv_archiver_store.ts +11 -18
- package/src/archiver/kv_archiver_store/log_store.ts +70 -120
- package/src/archiver/kv_archiver_store/message_store.ts +2 -2
- package/src/archiver/kv_archiver_store/nullifier_store.ts +2 -2
- package/src/archiver/memory_archiver_store/memory_archiver_store.ts +56 -70
- package/src/factory.ts +3 -3
- package/src/index.ts +2 -59
- package/src/test/mock_l2_block_source.ts +5 -6
- package/dest/archiver/epoch_helpers.d.ts +0 -20
- package/dest/archiver/epoch_helpers.d.ts.map +0 -1
- package/dest/archiver/epoch_helpers.js +0 -34
- package/src/archiver/epoch_helpers.ts +0 -54
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { InboxLeaf } from '@aztec/circuit-types';
|
|
2
2
|
import { Fr, L1_TO_L2_MSG_SUBTREE_HEIGHT } from '@aztec/circuits.js';
|
|
3
|
-
import {
|
|
3
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { type AztecKVStore, type AztecMap, type AztecSingleton } from '@aztec/kv-store';
|
|
5
5
|
|
|
6
6
|
import { type DataRetrieval } from '../structs/data_retrieval.js';
|
|
@@ -14,7 +14,7 @@ export class MessageStore {
|
|
|
14
14
|
#lastSynchedL1Block: AztecSingleton<bigint>;
|
|
15
15
|
#totalMessageCount: AztecSingleton<bigint>;
|
|
16
16
|
|
|
17
|
-
#log =
|
|
17
|
+
#log = createLogger('archiver:message_store');
|
|
18
18
|
|
|
19
19
|
#l1ToL2MessagesSubtreeSize = 2 ** L1_TO_L2_MSG_SUBTREE_HEIGHT;
|
|
20
20
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { type InBlock, type L2Block } from '@aztec/circuit-types';
|
|
2
2
|
import { type Fr, MAX_NULLIFIERS_PER_TX } from '@aztec/circuits.js';
|
|
3
|
-
import {
|
|
3
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { type AztecKVStore, type AztecMap } from '@aztec/kv-store';
|
|
5
5
|
|
|
6
6
|
export class NullifierStore {
|
|
7
7
|
#nullifiersToBlockNumber: AztecMap<string, number>;
|
|
8
8
|
#nullifiersToBlockHash: AztecMap<string, string>;
|
|
9
9
|
#nullifiersToIndex: AztecMap<string, number>;
|
|
10
|
-
#log =
|
|
10
|
+
#log = createLogger('archiver:log_store');
|
|
11
11
|
|
|
12
12
|
constructor(private db: AztecKVStore) {
|
|
13
13
|
this.#nullifiersToBlockNumber = db.openMap('archiver_nullifiers_to_block_number');
|
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
-
type Body,
|
|
3
2
|
type ContractClass2BlockL2Logs,
|
|
4
|
-
type EncryptedL2BlockL2Logs,
|
|
5
|
-
type EncryptedNoteL2BlockL2Logs,
|
|
6
3
|
ExtendedUnencryptedL2Log,
|
|
7
|
-
type FromLogType,
|
|
8
4
|
type GetUnencryptedLogsResponse,
|
|
9
5
|
type InBlock,
|
|
10
6
|
type InboxLeaf,
|
|
11
7
|
type L2Block,
|
|
12
8
|
L2BlockHash,
|
|
13
|
-
type L2BlockL2Logs,
|
|
14
9
|
type LogFilter,
|
|
15
10
|
LogId,
|
|
16
|
-
LogType,
|
|
17
11
|
type TxEffect,
|
|
18
12
|
type TxHash,
|
|
19
13
|
TxReceipt,
|
|
@@ -22,20 +16,21 @@ import {
|
|
|
22
16
|
wrapInBlock,
|
|
23
17
|
} from '@aztec/circuit-types';
|
|
24
18
|
import {
|
|
19
|
+
type BlockHeader,
|
|
25
20
|
type ContractClassPublic,
|
|
26
21
|
type ContractClassPublicWithBlockNumber,
|
|
27
22
|
type ContractInstanceWithAddress,
|
|
28
23
|
type ExecutablePrivateFunctionWithMembershipProof,
|
|
29
24
|
Fr,
|
|
30
|
-
type Header,
|
|
31
25
|
INITIAL_L2_BLOCK_NUM,
|
|
32
26
|
MAX_NOTE_HASHES_PER_TX,
|
|
33
27
|
MAX_NULLIFIERS_PER_TX,
|
|
28
|
+
type PrivateLog,
|
|
34
29
|
type UnconstrainedFunctionWithMembershipProof,
|
|
35
30
|
} from '@aztec/circuits.js';
|
|
36
31
|
import { type ContractArtifact, FunctionSelector } from '@aztec/foundation/abi';
|
|
37
32
|
import { type AztecAddress } from '@aztec/foundation/aztec-address';
|
|
38
|
-
import {
|
|
33
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
39
34
|
|
|
40
35
|
import { type ArchiverDataStore, type ArchiverL1SynchPoint } from '../archiver_store.js';
|
|
41
36
|
import { type DataRetrieval } from '../structs/data_retrieval.js';
|
|
@@ -56,13 +51,11 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
56
51
|
*/
|
|
57
52
|
private txEffects: InBlock<TxEffect>[] = [];
|
|
58
53
|
|
|
59
|
-
private noteEncryptedLogsPerBlock: Map<number, EncryptedNoteL2BlockL2Logs> = new Map();
|
|
60
|
-
|
|
61
54
|
private taggedLogs: Map<string, TxScopedL2Log[]> = new Map();
|
|
62
55
|
|
|
63
56
|
private logTagsPerBlock: Map<number, Fr[]> = new Map();
|
|
64
57
|
|
|
65
|
-
private
|
|
58
|
+
private privateLogsPerBlock: Map<number, PrivateLog[]> = new Map();
|
|
66
59
|
|
|
67
60
|
private unencryptedLogsPerBlock: Map<number, UnencryptedL2BlockL2Logs> = new Map();
|
|
68
61
|
|
|
@@ -93,7 +86,7 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
93
86
|
private lastProvenL2BlockNumber: number = 0;
|
|
94
87
|
private lastProvenL2EpochNumber: number = 0;
|
|
95
88
|
|
|
96
|
-
#log =
|
|
89
|
+
#log = createLogger('archiver:data-store');
|
|
97
90
|
|
|
98
91
|
constructor(
|
|
99
92
|
/** The max number of logs that can be obtained in 1 "getUnencryptedLogs" call. */
|
|
@@ -112,7 +105,7 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
112
105
|
}
|
|
113
106
|
|
|
114
107
|
public getContractClassIds(): Promise<Fr[]> {
|
|
115
|
-
return Promise.resolve(Array.from(this.contractClasses.keys()).map(key => Fr.
|
|
108
|
+
return Promise.resolve(Array.from(this.contractClasses.keys()).map(key => Fr.fromHexString(key)));
|
|
116
109
|
}
|
|
117
110
|
|
|
118
111
|
public getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
@@ -232,46 +225,61 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
232
225
|
return Promise.resolve(true);
|
|
233
226
|
}
|
|
234
227
|
|
|
235
|
-
#
|
|
228
|
+
#storeTaggedLogsFromPrivate(block: L2Block): void {
|
|
229
|
+
const dataStartIndexForBlock =
|
|
230
|
+
block.header.state.partial.noteHashTree.nextAvailableLeafIndex -
|
|
231
|
+
block.body.numberOfTxsIncludingPadded * MAX_NOTE_HASHES_PER_TX;
|
|
232
|
+
block.body.txEffects.forEach((txEffect, txIndex) => {
|
|
233
|
+
const txHash = txEffect.txHash;
|
|
234
|
+
const dataStartIndexForTx = dataStartIndexForBlock + txIndex * MAX_NOTE_HASHES_PER_TX;
|
|
235
|
+
txEffect.privateLogs.forEach(log => {
|
|
236
|
+
const tag = log.fields[0];
|
|
237
|
+
const currentLogs = this.taggedLogs.get(tag.toString()) || [];
|
|
238
|
+
this.taggedLogs.set(tag.toString(), [
|
|
239
|
+
...currentLogs,
|
|
240
|
+
new TxScopedL2Log(txHash, dataStartIndexForTx, block.number, /* isFromPublic */ false, log.toBuffer()),
|
|
241
|
+
]);
|
|
242
|
+
const currentTagsInBlock = this.logTagsPerBlock.get(block.number) || [];
|
|
243
|
+
this.logTagsPerBlock.set(block.number, [...currentTagsInBlock, tag]);
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
#storeTaggedLogsFromPublic(block: L2Block): void {
|
|
236
249
|
const dataStartIndexForBlock =
|
|
237
250
|
block.header.state.partial.noteHashTree.nextAvailableLeafIndex -
|
|
238
251
|
block.body.numberOfTxsIncludingPadded * MAX_NOTE_HASHES_PER_TX;
|
|
239
|
-
block.body
|
|
252
|
+
block.body.unencryptedLogs.txLogs.forEach((txLogs, txIndex) => {
|
|
240
253
|
const txHash = block.body.txEffects[txIndex].txHash;
|
|
241
254
|
const dataStartIndexForTx = dataStartIndexForBlock + txIndex * MAX_NOTE_HASHES_PER_TX;
|
|
242
255
|
const logs = txLogs.unrollLogs();
|
|
243
256
|
logs.forEach(log => {
|
|
244
257
|
if (
|
|
245
|
-
(logType == 'noteEncryptedLogs' && log.data.length < 32) ||
|
|
246
258
|
// TODO remove when #9835 and #9836 are fixed
|
|
247
|
-
|
|
259
|
+
log.data.length <
|
|
260
|
+
32 * 33
|
|
248
261
|
) {
|
|
249
|
-
this.#log.warn(`Skipping log
|
|
262
|
+
this.#log.warn(`Skipping unencrypted log with invalid data length: ${log.data.length}`);
|
|
250
263
|
return;
|
|
251
264
|
}
|
|
252
265
|
try {
|
|
253
|
-
let tag = Fr.ZERO;
|
|
254
266
|
// TODO remove when #9835 and #9836 are fixed. The partial note logs are emitted as bytes, but encoded as Fields.
|
|
255
267
|
// This means that for every 32 bytes of payload, we only have 1 byte of data.
|
|
256
268
|
// Also, the tag is not stored in the first 32 bytes of the log, (that's the length of public fields now) but in the next 32.
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
correctedBuffer.writeUInt8(byte, i);
|
|
265
|
-
}
|
|
266
|
-
tag = new Fr(correctedBuffer);
|
|
267
|
-
} else {
|
|
268
|
-
tag = new Fr(log.data.subarray(0, 32));
|
|
269
|
+
const correctedBuffer = Buffer.alloc(32);
|
|
270
|
+
const initialOffset = 32;
|
|
271
|
+
for (let i = 0; i < 32; i++) {
|
|
272
|
+
const byte = Fr.fromBuffer(
|
|
273
|
+
log.data.subarray(i * 32 + initialOffset, i * 32 + 32 + initialOffset),
|
|
274
|
+
).toNumber();
|
|
275
|
+
correctedBuffer.writeUInt8(byte, i);
|
|
269
276
|
}
|
|
270
|
-
|
|
277
|
+
const tag = new Fr(correctedBuffer);
|
|
278
|
+
this.#log.verbose(`Storing unencrypted tagged log with tag ${tag.toString()} in block ${block.number}`);
|
|
271
279
|
const currentLogs = this.taggedLogs.get(tag.toString()) || [];
|
|
272
280
|
this.taggedLogs.set(tag.toString(), [
|
|
273
281
|
...currentLogs,
|
|
274
|
-
new TxScopedL2Log(txHash, dataStartIndexForTx, block.number,
|
|
282
|
+
new TxScopedL2Log(txHash, dataStartIndexForTx, block.number, /* isFromPublic */ true, log.data),
|
|
275
283
|
]);
|
|
276
284
|
const currentTagsInBlock = this.logTagsPerBlock.get(block.number) || [];
|
|
277
285
|
this.logTagsPerBlock.set(block.number, [...currentTagsInBlock, tag]);
|
|
@@ -289,10 +297,9 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
289
297
|
*/
|
|
290
298
|
addLogs(blocks: L2Block[]): Promise<boolean> {
|
|
291
299
|
blocks.forEach(block => {
|
|
292
|
-
void this.#
|
|
293
|
-
void this.#
|
|
294
|
-
this.
|
|
295
|
-
this.encryptedLogsPerBlock.set(block.number, block.body.encryptedLogs);
|
|
300
|
+
void this.#storeTaggedLogsFromPrivate(block);
|
|
301
|
+
void this.#storeTaggedLogsFromPublic(block);
|
|
302
|
+
this.privateLogsPerBlock.set(block.number, block.body.txEffects.map(txEffect => txEffect.privateLogs).flat());
|
|
296
303
|
this.unencryptedLogsPerBlock.set(block.number, block.body.unencryptedLogs);
|
|
297
304
|
this.contractClassLogsPerBlock.set(block.number, block.body.contractClassLogs);
|
|
298
305
|
});
|
|
@@ -308,8 +315,7 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
308
315
|
});
|
|
309
316
|
|
|
310
317
|
blocks.forEach(block => {
|
|
311
|
-
this.
|
|
312
|
-
this.noteEncryptedLogsPerBlock.delete(block.number);
|
|
318
|
+
this.privateLogsPerBlock.delete(block.number);
|
|
313
319
|
this.unencryptedLogsPerBlock.delete(block.number);
|
|
314
320
|
this.logTagsPerBlock.delete(block.number);
|
|
315
321
|
this.contractClassLogsPerBlock.delete(block.number);
|
|
@@ -421,7 +427,7 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
421
427
|
return Promise.resolve(this.l2Blocks.slice(fromIndex, toIndex));
|
|
422
428
|
}
|
|
423
429
|
|
|
424
|
-
public async getBlockHeaders(from: number, limit: number): Promise<
|
|
430
|
+
public async getBlockHeaders(from: number, limit: number): Promise<BlockHeader[]> {
|
|
425
431
|
const blocks = await this.getBlocks(from, limit);
|
|
426
432
|
return blocks.map(block => block.data.header);
|
|
427
433
|
}
|
|
@@ -471,17 +477,12 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
471
477
|
}
|
|
472
478
|
|
|
473
479
|
/**
|
|
474
|
-
*
|
|
475
|
-
* @param from -
|
|
476
|
-
* @param limit - The number of
|
|
477
|
-
* @
|
|
478
|
-
* @returns The requested logs.
|
|
480
|
+
* Retrieves all private logs from up to `limit` blocks, starting from the block number `from`.
|
|
481
|
+
* @param from - The block number from which to begin retrieving logs.
|
|
482
|
+
* @param limit - The maximum number of blocks to retrieve logs from.
|
|
483
|
+
* @returns An array of private logs from the specified range of blocks.
|
|
479
484
|
*/
|
|
480
|
-
|
|
481
|
-
from: number,
|
|
482
|
-
limit: number,
|
|
483
|
-
logType: TLogType,
|
|
484
|
-
): Promise<L2BlockL2Logs<FromLogType<TLogType>>[]> {
|
|
485
|
+
getPrivateLogs(from: number, limit: number): Promise<PrivateLog[]> {
|
|
485
486
|
if (from < INITIAL_L2_BLOCK_NUM || limit < 1) {
|
|
486
487
|
return Promise.resolve([]);
|
|
487
488
|
}
|
|
@@ -490,34 +491,19 @@ export class MemoryArchiverStore implements ArchiverDataStore {
|
|
|
490
491
|
return Promise.resolve([]);
|
|
491
492
|
}
|
|
492
493
|
|
|
493
|
-
const logMap = (() => {
|
|
494
|
-
switch (logType) {
|
|
495
|
-
case LogType.ENCRYPTED:
|
|
496
|
-
return this.encryptedLogsPerBlock;
|
|
497
|
-
case LogType.NOTEENCRYPTED:
|
|
498
|
-
return this.noteEncryptedLogsPerBlock;
|
|
499
|
-
case LogType.UNENCRYPTED:
|
|
500
|
-
default:
|
|
501
|
-
return this.unencryptedLogsPerBlock;
|
|
502
|
-
}
|
|
503
|
-
})() as Map<number, L2BlockL2Logs<FromLogType<TLogType>>>;
|
|
504
|
-
|
|
505
494
|
const startIndex = from;
|
|
506
495
|
const endIndex = startIndex + limit;
|
|
507
496
|
const upper = Math.min(endIndex, this.l2Blocks.length + INITIAL_L2_BLOCK_NUM);
|
|
508
497
|
|
|
509
|
-
const
|
|
498
|
+
const logsInBlocks = [];
|
|
510
499
|
for (let i = startIndex; i < upper; i++) {
|
|
511
|
-
const
|
|
512
|
-
if (
|
|
513
|
-
|
|
514
|
-
} else {
|
|
515
|
-
// I hate typescript sometimes
|
|
516
|
-
l.push(undefined as unknown as L2BlockL2Logs<FromLogType<TLogType>>);
|
|
500
|
+
const logs = this.privateLogsPerBlock.get(i);
|
|
501
|
+
if (logs) {
|
|
502
|
+
logsInBlocks.push(logs);
|
|
517
503
|
}
|
|
518
504
|
}
|
|
519
505
|
|
|
520
|
-
return Promise.resolve(
|
|
506
|
+
return Promise.resolve(logsInBlocks.flat());
|
|
521
507
|
}
|
|
522
508
|
|
|
523
509
|
/**
|
package/src/factory.ts
CHANGED
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
computePublicBytecodeCommitment,
|
|
5
5
|
getContractClassFromArtifact,
|
|
6
6
|
} from '@aztec/circuits.js';
|
|
7
|
-
import {
|
|
7
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
8
8
|
import { type Maybe } from '@aztec/foundation/types';
|
|
9
9
|
import { type DataStoreConfig } from '@aztec/kv-store/config';
|
|
10
|
-
import { createStore } from '@aztec/kv-store/
|
|
10
|
+
import { createStore } from '@aztec/kv-store/lmdb';
|
|
11
11
|
import { TokenBridgeContractArtifact, TokenContractArtifact } from '@aztec/noir-contracts.js';
|
|
12
12
|
import { getCanonicalProtocolContract, protocolContractNames } from '@aztec/protocol-contracts';
|
|
13
13
|
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
@@ -24,7 +24,7 @@ export async function createArchiver(
|
|
|
24
24
|
opts: { blockUntilSync: boolean } = { blockUntilSync: true },
|
|
25
25
|
): Promise<ArchiverApi & Maybe<Service>> {
|
|
26
26
|
if (!config.archiverUrl) {
|
|
27
|
-
const store = await createStore('archiver', config,
|
|
27
|
+
const store = await createStore('archiver', config, createLogger('archiver:lmdb'));
|
|
28
28
|
const archiverStore = new KVArchiverDataStore(store, config.maxLogs);
|
|
29
29
|
await registerProtocolContracts(archiverStore);
|
|
30
30
|
await registerCommonContracts(archiverStore);
|
package/src/index.ts
CHANGED
|
@@ -1,62 +1,5 @@
|
|
|
1
|
-
import { jsonStringify } from '@aztec/foundation/json-rpc';
|
|
2
|
-
import { createDebugLogger } from '@aztec/foundation/log';
|
|
3
|
-
import { fileURLToPath } from '@aztec/foundation/url';
|
|
4
|
-
import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';
|
|
5
|
-
|
|
6
|
-
import { createPublicClient, http } from 'viem';
|
|
7
|
-
import { localhost } from 'viem/chains';
|
|
8
|
-
|
|
9
|
-
import { Archiver, getArchiverConfigFromEnv } from './archiver/index.js';
|
|
10
|
-
import { ArchiverInstrumentation } from './archiver/instrumentation.js';
|
|
11
|
-
import { MemoryArchiverStore } from './archiver/memory_archiver_store/memory_archiver_store.js';
|
|
12
|
-
|
|
13
1
|
export * from './archiver/index.js';
|
|
14
|
-
export * from './rpc/index.js';
|
|
15
2
|
export * from './factory.js';
|
|
3
|
+
export * from './rpc/index.js';
|
|
16
4
|
|
|
17
|
-
export {
|
|
18
|
-
|
|
19
|
-
const log = createDebugLogger('aztec:archiver');
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* A function which instantiates and starts Archiver.
|
|
23
|
-
*/
|
|
24
|
-
// eslint-disable-next-line require-await
|
|
25
|
-
async function main() {
|
|
26
|
-
const config = getArchiverConfigFromEnv();
|
|
27
|
-
const { l1RpcUrl: rpcUrl, l1Contracts } = config;
|
|
28
|
-
|
|
29
|
-
log.info(`Starting archiver in main(): ${jsonStringify(config)}`);
|
|
30
|
-
const publicClient = createPublicClient({
|
|
31
|
-
chain: localhost,
|
|
32
|
-
transport: http(rpcUrl),
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const archiverStore = new MemoryArchiverStore(1000);
|
|
36
|
-
|
|
37
|
-
const archiver = new Archiver(
|
|
38
|
-
publicClient,
|
|
39
|
-
l1Contracts.rollupAddress,
|
|
40
|
-
l1Contracts.inboxAddress,
|
|
41
|
-
l1Contracts.registryAddress,
|
|
42
|
-
archiverStore,
|
|
43
|
-
1000,
|
|
44
|
-
new ArchiverInstrumentation(new NoopTelemetryClient()),
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
const shutdown = async () => {
|
|
48
|
-
await archiver.stop();
|
|
49
|
-
process.exit(0);
|
|
50
|
-
};
|
|
51
|
-
process.once('SIGINT', shutdown);
|
|
52
|
-
process.once('SIGTERM', shutdown);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// See https://twitter.com/Rich_Harris/status/1355289863130673153
|
|
56
|
-
if (process.argv[1] === fileURLToPath(import.meta.url).replace(/\/index\.js$/, '')) {
|
|
57
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
58
|
-
main().catch(err => {
|
|
59
|
-
log.error(err);
|
|
60
|
-
process.exit(1);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
5
|
+
export { retrieveBlocksFromRollup, retrieveL2ProofVerifiedEvents } from './archiver/data_retrieval.js';
|
|
@@ -7,11 +7,10 @@ import {
|
|
|
7
7
|
TxReceipt,
|
|
8
8
|
TxStatus,
|
|
9
9
|
} from '@aztec/circuit-types';
|
|
10
|
-
import {
|
|
10
|
+
import { getSlotRangeForEpoch } from '@aztec/circuit-types';
|
|
11
|
+
import { type BlockHeader, EthAddress } from '@aztec/circuits.js';
|
|
11
12
|
import { DefaultL1ContractsConfig } from '@aztec/ethereum';
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
import { getSlotRangeForEpoch } from '../archiver/epoch_helpers.js';
|
|
13
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
16
|
* A mocked implementation of L2BlockSource to be used in tests.
|
|
@@ -22,7 +21,7 @@ export class MockL2BlockSource implements L2BlockSource {
|
|
|
22
21
|
private provenEpochNumber: number = 0;
|
|
23
22
|
private provenBlockNumber: number = 0;
|
|
24
23
|
|
|
25
|
-
private log =
|
|
24
|
+
private log = createLogger('archiver:mock_l2_block_source');
|
|
26
25
|
|
|
27
26
|
public createBlocks(numBlocks: number) {
|
|
28
27
|
for (let i = 0; i < numBlocks; i++) {
|
|
@@ -107,7 +106,7 @@ export class MockL2BlockSource implements L2BlockSource {
|
|
|
107
106
|
);
|
|
108
107
|
}
|
|
109
108
|
|
|
110
|
-
getBlockHeader(number: number | 'latest'): Promise<
|
|
109
|
+
getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
|
|
111
110
|
return Promise.resolve(this.l2Blocks.at(typeof number === 'number' ? number - 1 : -1)?.header);
|
|
112
111
|
}
|
|
113
112
|
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export type EpochConstants = {
|
|
2
|
-
l1GenesisBlock: bigint;
|
|
3
|
-
l1GenesisTime: bigint;
|
|
4
|
-
epochDuration: number;
|
|
5
|
-
slotDuration: number;
|
|
6
|
-
};
|
|
7
|
-
/** Returns the slot number for a given timestamp. */
|
|
8
|
-
export declare function getSlotAtTimestamp(ts: bigint, constants: Pick<EpochConstants, 'l1GenesisTime' | 'slotDuration'>): bigint;
|
|
9
|
-
/** Returns the epoch number for a given timestamp. */
|
|
10
|
-
export declare function getEpochNumberAtTimestamp(ts: bigint, constants: Pick<EpochConstants, 'epochDuration' | 'slotDuration' | 'l1GenesisTime'>): bigint;
|
|
11
|
-
/** Returns the range of L2 slots (inclusive) for a given epoch number. */
|
|
12
|
-
export declare function getSlotRangeForEpoch(epochNumber: bigint, constants: Pick<EpochConstants, 'epochDuration'>): bigint[];
|
|
13
|
-
/** Returns the range of L1 timestamps (inclusive) for a given epoch number. */
|
|
14
|
-
export declare function getTimestampRangeForEpoch(epochNumber: bigint, constants: Pick<EpochConstants, 'l1GenesisTime' | 'slotDuration' | 'epochDuration'>): bigint[];
|
|
15
|
-
/**
|
|
16
|
-
* Returns the range of L1 blocks (inclusive) for a given epoch number.
|
|
17
|
-
* @remarks This assumes no time warp has happened.
|
|
18
|
-
*/
|
|
19
|
-
export declare function getL1BlockRangeForEpoch(epochNumber: bigint, constants: Pick<EpochConstants, 'l1GenesisBlock' | 'epochDuration' | 'slotDuration'>): bigint[];
|
|
20
|
-
//# sourceMappingURL=epoch_helpers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"epoch_helpers.d.ts","sourceRoot":"","sources":["../../src/archiver/epoch_helpers.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,cAAc,GAAG;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,qDAAqD;AACrD,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,cAAc,EAAE,eAAe,GAAG,cAAc,CAAC,UAE/G;AAED,sDAAsD;AACtD,wBAAgB,yBAAyB,CACvC,EAAE,EAAE,MAAM,EACV,SAAS,EAAE,IAAI,CAAC,cAAc,EAAE,eAAe,GAAG,cAAc,GAAG,eAAe,CAAC,UAGpF;AAED,0EAA0E;AAC1E,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,cAAc,EAAE,eAAe,CAAC,YAGzG;AAED,+EAA+E;AAC/E,wBAAgB,yBAAyB,CACvC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,IAAI,CAAC,cAAc,EAAE,eAAe,GAAG,cAAc,GAAG,eAAe,CAAC,YAOpF;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,IAAI,CAAC,cAAc,EAAE,gBAAgB,GAAG,eAAe,GAAG,cAAc,CAAC,YAOrF"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// REFACTOR: This file should go in a package lower in the dependency graph.
|
|
2
|
-
/** Returns the slot number for a given timestamp. */
|
|
3
|
-
export function getSlotAtTimestamp(ts, constants) {
|
|
4
|
-
return ts < constants.l1GenesisTime ? 0n : (ts - constants.l1GenesisTime) / BigInt(constants.slotDuration);
|
|
5
|
-
}
|
|
6
|
-
/** Returns the epoch number for a given timestamp. */
|
|
7
|
-
export function getEpochNumberAtTimestamp(ts, constants) {
|
|
8
|
-
return getSlotAtTimestamp(ts, constants) / BigInt(constants.epochDuration);
|
|
9
|
-
}
|
|
10
|
-
/** Returns the range of L2 slots (inclusive) for a given epoch number. */
|
|
11
|
-
export function getSlotRangeForEpoch(epochNumber, constants) {
|
|
12
|
-
const startSlot = epochNumber * BigInt(constants.epochDuration);
|
|
13
|
-
return [startSlot, startSlot + BigInt(constants.epochDuration) - 1n];
|
|
14
|
-
}
|
|
15
|
-
/** Returns the range of L1 timestamps (inclusive) for a given epoch number. */
|
|
16
|
-
export function getTimestampRangeForEpoch(epochNumber, constants) {
|
|
17
|
-
const [startSlot, endSlot] = getSlotRangeForEpoch(epochNumber, constants);
|
|
18
|
-
return [
|
|
19
|
-
constants.l1GenesisTime + startSlot * BigInt(constants.slotDuration),
|
|
20
|
-
constants.l1GenesisTime + endSlot * BigInt(constants.slotDuration),
|
|
21
|
-
];
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Returns the range of L1 blocks (inclusive) for a given epoch number.
|
|
25
|
-
* @remarks This assumes no time warp has happened.
|
|
26
|
-
*/
|
|
27
|
-
export function getL1BlockRangeForEpoch(epochNumber, constants) {
|
|
28
|
-
const epochDurationInL1Blocks = BigInt(constants.epochDuration) * BigInt(constants.slotDuration);
|
|
29
|
-
return [
|
|
30
|
-
epochNumber * epochDurationInL1Blocks + constants.l1GenesisBlock,
|
|
31
|
-
(epochNumber + 1n) * epochDurationInL1Blocks + constants.l1GenesisBlock - 1n,
|
|
32
|
-
];
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXBvY2hfaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9hcmNoaXZlci9lcG9jaF9oZWxwZXJzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLDRFQUE0RTtBQVM1RSxxREFBcUQ7QUFDckQsTUFBTSxVQUFVLGtCQUFrQixDQUFDLEVBQVUsRUFBRSxTQUFpRTtJQUM5RyxPQUFPLEVBQUUsR0FBRyxTQUFTLENBQUMsYUFBYSxDQUFDLENBQUMsQ0FBQyxFQUFFLENBQUMsQ0FBQyxDQUFDLENBQUMsRUFBRSxHQUFHLFNBQVMsQ0FBQyxhQUFhLENBQUMsR0FBRyxNQUFNLENBQUMsU0FBUyxDQUFDLFlBQVksQ0FBQyxDQUFDO0FBQzdHLENBQUM7QUFFRCxzREFBc0Q7QUFDdEQsTUFBTSxVQUFVLHlCQUF5QixDQUN2QyxFQUFVLEVBQ1YsU0FBbUY7SUFFbkYsT0FBTyxrQkFBa0IsQ0FBQyxFQUFFLEVBQUUsU0FBUyxDQUFDLEdBQUcsTUFBTSxDQUFDLFNBQVMsQ0FBQyxhQUFhLENBQUMsQ0FBQztBQUM3RSxDQUFDO0FBRUQsMEVBQTBFO0FBQzFFLE1BQU0sVUFBVSxvQkFBb0IsQ0FBQyxXQUFtQixFQUFFLFNBQWdEO0lBQ3hHLE1BQU0sU0FBUyxHQUFHLFdBQVcsR0FBRyxNQUFNLENBQUMsU0FBUyxDQUFDLGFBQWEsQ0FBQyxDQUFDO0lBQ2hFLE9BQU8sQ0FBQyxTQUFTLEVBQUUsU0FBUyxHQUFHLE1BQU0sQ0FBQyxTQUFTLENBQUMsYUFBYSxDQUFDLEdBQUcsRUFBRSxDQUFDLENBQUM7QUFDdkUsQ0FBQztBQUVELCtFQUErRTtBQUMvRSxNQUFNLFVBQVUseUJBQXlCLENBQ3ZDLFdBQW1CLEVBQ25CLFNBQW1GO0lBRW5GLE1BQU0sQ0FBQyxTQUFTLEVBQUUsT0FBTyxDQUFDLEdBQUcsb0JBQW9CLENBQUMsV0FBVyxFQUFFLFNBQVMsQ0FBQyxDQUFDO0lBQzFFLE9BQU87UUFDTCxTQUFTLENBQUMsYUFBYSxHQUFHLFNBQVMsR0FBRyxNQUFNLENBQUMsU0FBUyxDQUFDLFlBQVksQ0FBQztRQUNwRSxTQUFTLENBQUMsYUFBYSxHQUFHLE9BQU8sR0FBRyxNQUFNLENBQUMsU0FBUyxDQUFDLFlBQVksQ0FBQztLQUNuRSxDQUFDO0FBQ0osQ0FBQztBQUVEOzs7R0FHRztBQUNILE1BQU0sVUFBVSx1QkFBdUIsQ0FDckMsV0FBbUIsRUFDbkIsU0FBb0Y7SUFFcEYsTUFBTSx1QkFBdUIsR0FBRyxNQUFNLENBQUMsU0FBUyxDQUFDLGFBQWEsQ0FBQyxHQUFHLE1BQU0sQ0FBQyxTQUFTLENBQUMsWUFBWSxDQUFDLENBQUM7SUFDakcsT0FBTztRQUNMLFdBQVcsR0FBRyx1QkFBdUIsR0FBRyxTQUFTLENBQUMsY0FBYztRQUNoRSxDQUFDLFdBQVcsR0FBRyxFQUFFLENBQUMsR0FBRyx1QkFBdUIsR0FBRyxTQUFTLENBQUMsY0FBYyxHQUFHLEVBQUU7S0FDN0UsQ0FBQztBQUNKLENBQUMifQ==
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// REFACTOR: This file should go in a package lower in the dependency graph.
|
|
2
|
-
|
|
3
|
-
export type EpochConstants = {
|
|
4
|
-
l1GenesisBlock: bigint;
|
|
5
|
-
l1GenesisTime: bigint;
|
|
6
|
-
epochDuration: number;
|
|
7
|
-
slotDuration: number;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
/** Returns the slot number for a given timestamp. */
|
|
11
|
-
export function getSlotAtTimestamp(ts: bigint, constants: Pick<EpochConstants, 'l1GenesisTime' | 'slotDuration'>) {
|
|
12
|
-
return ts < constants.l1GenesisTime ? 0n : (ts - constants.l1GenesisTime) / BigInt(constants.slotDuration);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/** Returns the epoch number for a given timestamp. */
|
|
16
|
-
export function getEpochNumberAtTimestamp(
|
|
17
|
-
ts: bigint,
|
|
18
|
-
constants: Pick<EpochConstants, 'epochDuration' | 'slotDuration' | 'l1GenesisTime'>,
|
|
19
|
-
) {
|
|
20
|
-
return getSlotAtTimestamp(ts, constants) / BigInt(constants.epochDuration);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** Returns the range of L2 slots (inclusive) for a given epoch number. */
|
|
24
|
-
export function getSlotRangeForEpoch(epochNumber: bigint, constants: Pick<EpochConstants, 'epochDuration'>) {
|
|
25
|
-
const startSlot = epochNumber * BigInt(constants.epochDuration);
|
|
26
|
-
return [startSlot, startSlot + BigInt(constants.epochDuration) - 1n];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** Returns the range of L1 timestamps (inclusive) for a given epoch number. */
|
|
30
|
-
export function getTimestampRangeForEpoch(
|
|
31
|
-
epochNumber: bigint,
|
|
32
|
-
constants: Pick<EpochConstants, 'l1GenesisTime' | 'slotDuration' | 'epochDuration'>,
|
|
33
|
-
) {
|
|
34
|
-
const [startSlot, endSlot] = getSlotRangeForEpoch(epochNumber, constants);
|
|
35
|
-
return [
|
|
36
|
-
constants.l1GenesisTime + startSlot * BigInt(constants.slotDuration),
|
|
37
|
-
constants.l1GenesisTime + endSlot * BigInt(constants.slotDuration),
|
|
38
|
-
];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Returns the range of L1 blocks (inclusive) for a given epoch number.
|
|
43
|
-
* @remarks This assumes no time warp has happened.
|
|
44
|
-
*/
|
|
45
|
-
export function getL1BlockRangeForEpoch(
|
|
46
|
-
epochNumber: bigint,
|
|
47
|
-
constants: Pick<EpochConstants, 'l1GenesisBlock' | 'epochDuration' | 'slotDuration'>,
|
|
48
|
-
) {
|
|
49
|
-
const epochDurationInL1Blocks = BigInt(constants.epochDuration) * BigInt(constants.slotDuration);
|
|
50
|
-
return [
|
|
51
|
-
epochNumber * epochDurationInL1Blocks + constants.l1GenesisBlock,
|
|
52
|
-
(epochNumber + 1n) * epochDurationInL1Blocks + constants.l1GenesisBlock - 1n,
|
|
53
|
-
];
|
|
54
|
-
}
|