@aztec/archiver 0.0.1-commit.f295ac2 → 0.0.1-commit.fc805bf
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 +6 -5
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +34 -22
- 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 +7 -6
- package/dest/l1/bin/retrieve-calldata.js +2 -2
- package/dest/l1/data_retrieval.d.ts +1 -1
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +3 -3
- 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 +19 -20
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +25 -56
- package/dest/modules/data_store_updater.d.ts +23 -19
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +47 -49
- package/dest/modules/instrumentation.d.ts +3 -3
- 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 +9 -10
- package/dest/store/block_store.d.ts +35 -21
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +81 -40
- 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 +37 -28
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +31 -23
- 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 +22 -8
- package/dest/test/fake_l1_state.d.ts +4 -4
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/index.js +3 -1
- package/dest/test/mock_archiver.js +1 -1
- package/dest/test/mock_l2_block_source.d.ts +20 -20
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +40 -41
- 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 +46 -28
- package/src/errors.ts +12 -0
- package/src/factory.ts +7 -5
- package/src/l1/bin/retrieve-calldata.ts +7 -2
- package/src/l1/data_retrieval.ts +4 -4
- package/src/l1/validate_trace.ts +24 -6
- package/src/modules/data_source_base.ts +34 -81
- package/src/modules/data_store_updater.ts +59 -55
- package/src/modules/instrumentation.ts +17 -12
- package/src/modules/l1_synchronizer.ts +11 -12
- package/src/store/block_store.ts +107 -60
- package/src/store/contract_class_store.ts +11 -7
- package/src/store/kv_archiver_store.ts +52 -35
- package/src/store/log_store.ts +41 -18
- package/src/test/fake_l1_state.ts +2 -2
- package/src/test/index.ts +3 -0
- package/src/test/mock_archiver.ts +1 -1
- package/src/test/mock_l2_block_source.ts +54 -64
- package/src/test/mock_structs.ts +26 -10
- package/src/test/noop_l1_archiver.ts +109 -0
package/src/archiver.ts
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
type ArchiverEmitter,
|
|
18
18
|
type CheckpointId,
|
|
19
19
|
GENESIS_CHECKPOINT_HEADER_HASH,
|
|
20
|
-
|
|
20
|
+
L2Block,
|
|
21
21
|
type L2BlockSink,
|
|
22
22
|
type L2Tips,
|
|
23
23
|
type ValidateCheckpointResult,
|
|
@@ -26,6 +26,7 @@ import { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
|
26
26
|
import {
|
|
27
27
|
type L1RollupConstants,
|
|
28
28
|
getEpochNumberAtTimestamp,
|
|
29
|
+
getSlotAtNextL1Block,
|
|
29
30
|
getSlotAtTimestamp,
|
|
30
31
|
getSlotRangeForEpoch,
|
|
31
32
|
getTimestampRangeForEpoch,
|
|
@@ -46,7 +47,7 @@ export type { ArchiverEmitter };
|
|
|
46
47
|
|
|
47
48
|
/** Request to add a block to the archiver, queued for processing by the sync loop. */
|
|
48
49
|
type AddBlockRequest = {
|
|
49
|
-
block:
|
|
50
|
+
block: L2Block;
|
|
50
51
|
resolve: () => void;
|
|
51
52
|
reject: (err: Error) => void;
|
|
52
53
|
};
|
|
@@ -68,7 +69,7 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
68
69
|
public readonly events: ArchiverEmitter;
|
|
69
70
|
|
|
70
71
|
/** A loop in which we will be continually fetching new checkpoints. */
|
|
71
|
-
|
|
72
|
+
protected runningPromise: RunningPromise;
|
|
72
73
|
|
|
73
74
|
/** L1 synchronizer that handles fetching checkpoints and messages from L1. */
|
|
74
75
|
private readonly synchronizer: ArchiverL1Synchronizer;
|
|
@@ -158,7 +159,11 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
158
159
|
|
|
159
160
|
await this.blobClient.testSources();
|
|
160
161
|
await this.synchronizer.testEthereumNodeSynced();
|
|
161
|
-
await validateAndLogTraceAvailability(
|
|
162
|
+
await validateAndLogTraceAvailability(
|
|
163
|
+
this.debugClient,
|
|
164
|
+
this.config.ethereumAllowNoDebugHosts ?? false,
|
|
165
|
+
this.log.getBindings(),
|
|
166
|
+
);
|
|
162
167
|
|
|
163
168
|
// Log initial state for the archiver
|
|
164
169
|
const { l1StartBlock } = this.l1Constants;
|
|
@@ -187,7 +192,7 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
187
192
|
* @param block - The L2 block to add.
|
|
188
193
|
* @returns A promise that resolves when the block has been added to the store, or rejects on error.
|
|
189
194
|
*/
|
|
190
|
-
public addBlock(block:
|
|
195
|
+
public addBlock(block: L2Block): Promise<void> {
|
|
191
196
|
return new Promise<void>((resolve, reject) => {
|
|
192
197
|
this.blockQueue.push({ block, resolve, reject });
|
|
193
198
|
this.log.debug(`Queued block ${block.number} for processing`);
|
|
@@ -212,10 +217,25 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
212
217
|
const queuedItems = this.blockQueue.splice(0, this.blockQueue.length);
|
|
213
218
|
this.log.debug(`Processing ${queuedItems.length} queued block(s)`);
|
|
214
219
|
|
|
220
|
+
// Calculate slot threshold for validation
|
|
221
|
+
const l1Timestamp = this.synchronizer.getL1Timestamp();
|
|
222
|
+
const slotAtNextL1Block =
|
|
223
|
+
l1Timestamp === undefined ? undefined : getSlotAtNextL1Block(l1Timestamp, this.l1Constants);
|
|
224
|
+
|
|
215
225
|
// Process each block individually to properly resolve/reject each promise
|
|
216
226
|
for (const { block, resolve, reject } of queuedItems) {
|
|
227
|
+
const blockSlot = block.header.globalVariables.slotNumber;
|
|
228
|
+
if (slotAtNextL1Block !== undefined && blockSlot < slotAtNextL1Block) {
|
|
229
|
+
this.log.warn(
|
|
230
|
+
`Rejecting proposed block ${block.number} for past slot ${blockSlot} (current is ${slotAtNextL1Block})`,
|
|
231
|
+
{ block: block.toBlockInfo(), l1Timestamp, slotAtNextL1Block },
|
|
232
|
+
);
|
|
233
|
+
reject(new Error(`Block ${block.number} is for past slot ${blockSlot} (current is ${slotAtNextL1Block})`));
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
|
|
217
237
|
try {
|
|
218
|
-
await this.updater.
|
|
238
|
+
await this.updater.addProposedBlocks([block]);
|
|
219
239
|
this.log.debug(`Added block ${block.number} to store`);
|
|
220
240
|
resolve();
|
|
221
241
|
} catch (err: any) {
|
|
@@ -323,8 +343,11 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
323
343
|
}
|
|
324
344
|
|
|
325
345
|
public async isEpochComplete(epochNumber: EpochNumber): Promise<boolean> {
|
|
326
|
-
// The epoch is complete if the current L2 block is the last one in the epoch (or later)
|
|
327
|
-
|
|
346
|
+
// The epoch is complete if the current checkpointed L2 block is the last one in the epoch (or later).
|
|
347
|
+
// We use the checkpointed block number (synced from L1) instead of 'latest' to avoid returning true
|
|
348
|
+
// prematurely when proposed blocks have been pushed to the archiver but not yet checkpointed on L1.
|
|
349
|
+
const checkpointedBlockNumber = await this.getCheckpointedL2BlockNumber();
|
|
350
|
+
const header = checkpointedBlockNumber > 0 ? await this.getBlockHeader(checkpointedBlockNumber) : undefined;
|
|
328
351
|
const slot = header ? header.globalVariables.slotNumber : undefined;
|
|
329
352
|
const [_startSlot, endSlot] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
|
|
330
353
|
if (slot && slot >= endSlot) {
|
|
@@ -355,8 +378,8 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
355
378
|
return this.initialSyncComplete;
|
|
356
379
|
}
|
|
357
380
|
|
|
358
|
-
public
|
|
359
|
-
return this.updater.
|
|
381
|
+
public removeCheckpointsAfter(checkpointNumber: CheckpointNumber): Promise<boolean> {
|
|
382
|
+
return this.updater.removeCheckpointsAfter(checkpointNumber);
|
|
360
383
|
}
|
|
361
384
|
|
|
362
385
|
/** Used by TXE to add checkpoints directly without syncing from L1. */
|
|
@@ -364,22 +387,18 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
364
387
|
checkpoints: PublishedCheckpoint[],
|
|
365
388
|
pendingChainValidationStatus?: ValidateCheckpointResult,
|
|
366
389
|
): Promise<boolean> {
|
|
367
|
-
await this.updater.
|
|
390
|
+
await this.updater.addCheckpoints(checkpoints, pendingChainValidationStatus);
|
|
368
391
|
return true;
|
|
369
392
|
}
|
|
370
393
|
|
|
371
394
|
public async getL2Tips(): Promise<L2Tips> {
|
|
372
|
-
const [latestBlockNumber, provenBlockNumber, checkpointedBlockNumber] = await Promise.all([
|
|
395
|
+
const [latestBlockNumber, provenBlockNumber, checkpointedBlockNumber, finalizedBlockNumber] = await Promise.all([
|
|
373
396
|
this.getBlockNumber(),
|
|
374
397
|
this.getProvenBlockNumber(),
|
|
375
|
-
this.
|
|
398
|
+
this.getCheckpointedL2BlockNumber(),
|
|
399
|
+
this.getFinalizedL2BlockNumber(),
|
|
376
400
|
] as const);
|
|
377
401
|
|
|
378
|
-
// TODO(#13569): Compute proper finalized block number based on L1 finalized block.
|
|
379
|
-
// We just force it 2 epochs worth of proven data for now.
|
|
380
|
-
// NOTE: update end-to-end/src/e2e_epochs/epochs_empty_blocks.test.ts as that uses finalized blocks in computations
|
|
381
|
-
const finalizedBlockNumber = BlockNumber(Math.max(provenBlockNumber - this.l1Constants.epochDuration * 2, 0));
|
|
382
|
-
|
|
383
402
|
const beforeInitialblockNumber = BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
|
|
384
403
|
|
|
385
404
|
// Get the latest block header and checkpointed blocks for proven, finalised and checkpointed blocks
|
|
@@ -425,14 +444,12 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
425
444
|
// Now attempt to retrieve checkpoints for proven, finalised and checkpointed blocks
|
|
426
445
|
const [[provenBlockCheckpoint], [finalizedBlockCheckpoint], [checkpointedBlockCheckpoint]] = await Promise.all([
|
|
427
446
|
provenCheckpointedBlock !== undefined
|
|
428
|
-
? await this.
|
|
447
|
+
? await this.getCheckpoints(provenCheckpointedBlock?.checkpointNumber, 1)
|
|
429
448
|
: [undefined],
|
|
430
449
|
finalizedCheckpointedBlock !== undefined
|
|
431
|
-
? await this.
|
|
432
|
-
: [undefined],
|
|
433
|
-
checkpointedBlock !== undefined
|
|
434
|
-
? await this.getPublishedCheckpoints(checkpointedBlock?.checkpointNumber, 1)
|
|
450
|
+
? await this.getCheckpoints(finalizedCheckpointedBlock?.checkpointNumber, 1)
|
|
435
451
|
: [undefined],
|
|
452
|
+
checkpointedBlock !== undefined ? await this.getCheckpoints(checkpointedBlock?.checkpointNumber, 1) : [undefined],
|
|
436
453
|
]);
|
|
437
454
|
|
|
438
455
|
const initialcheckpointId: CheckpointId = {
|
|
@@ -490,13 +507,12 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
490
507
|
if (targetL2BlockNumber >= currentL2Block) {
|
|
491
508
|
throw new Error(`Target L2 block ${targetL2BlockNumber} must be less than current L2 block ${currentL2Block}`);
|
|
492
509
|
}
|
|
493
|
-
const blocksToUnwind = currentL2Block - targetL2BlockNumber;
|
|
494
510
|
const targetL2Block = await this.store.getCheckpointedBlock(targetL2BlockNumber);
|
|
495
511
|
if (!targetL2Block) {
|
|
496
512
|
throw new Error(`Target L2 block ${targetL2BlockNumber} not found`);
|
|
497
513
|
}
|
|
498
514
|
const targetL1BlockNumber = targetL2Block.l1.blockNumber;
|
|
499
|
-
const targetCheckpointNumber =
|
|
515
|
+
const targetCheckpointNumber = targetL2Block.checkpointNumber;
|
|
500
516
|
const targetL1Block = await this.publicClient.getBlock({
|
|
501
517
|
blockNumber: targetL1BlockNumber,
|
|
502
518
|
includeTransactions: false,
|
|
@@ -505,9 +521,11 @@ export class Archiver extends ArchiverDataSourceBase implements L2BlockSink, Tra
|
|
|
505
521
|
throw new Error(`Missing L1 block ${targetL1BlockNumber}`);
|
|
506
522
|
}
|
|
507
523
|
const targetL1BlockHash = Buffer32.fromString(targetL1Block.hash);
|
|
508
|
-
this.log.info(
|
|
509
|
-
|
|
510
|
-
|
|
524
|
+
this.log.info(
|
|
525
|
+
`Removing checkpoints after checkpoint ${targetCheckpointNumber} (target block ${targetL2BlockNumber})`,
|
|
526
|
+
);
|
|
527
|
+
await this.updater.removeCheckpointsAfter(targetCheckpointNumber);
|
|
528
|
+
this.log.info(`Rolling back L1 to L2 messages to checkpoint ${targetCheckpointNumber}`);
|
|
511
529
|
await this.store.rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber);
|
|
512
530
|
this.log.info(`Setting L1 syncpoints to ${targetL1BlockNumber}`);
|
|
513
531
|
await this.store.setCheckpointSynchedL1BlockNumber(targetL1BlockNumber);
|
package/src/errors.ts
CHANGED
|
@@ -88,3 +88,15 @@ export class BlockNotFoundError extends Error {
|
|
|
88
88
|
super(`Failed to find expected block number ${blockNumber}`);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
+
|
|
92
|
+
export class CannotOverwriteCheckpointedBlockError extends Error {
|
|
93
|
+
constructor(
|
|
94
|
+
public readonly blockNumber: number,
|
|
95
|
+
public readonly lastCheckpointedBlock: number,
|
|
96
|
+
) {
|
|
97
|
+
super(
|
|
98
|
+
`Cannot add block ${blockNumber}: would overwrite checkpointed data (checkpointed up to block ${lastCheckpointedBlock})`,
|
|
99
|
+
);
|
|
100
|
+
this.name = 'CannotOverwriteCheckpointedBlockError';
|
|
101
|
+
}
|
|
102
|
+
}
|
package/src/factory.ts
CHANGED
|
@@ -6,7 +6,6 @@ import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
|
6
6
|
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
7
7
|
import { merge } from '@aztec/foundation/collection';
|
|
8
8
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
9
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
10
9
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
11
10
|
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
12
11
|
import { createStore } from '@aztec/kv-store/lmdb-v2';
|
|
@@ -15,6 +14,7 @@ import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/prov
|
|
|
15
14
|
import { FunctionType, decodeFunctionSignature } from '@aztec/stdlib/abi';
|
|
16
15
|
import type { ArchiverEmitter } from '@aztec/stdlib/block';
|
|
17
16
|
import { type ContractClassPublic, computePublicBytecodeCommitment } from '@aztec/stdlib/contract';
|
|
17
|
+
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
18
18
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
19
19
|
|
|
20
20
|
import { EventEmitter } from 'events';
|
|
@@ -31,13 +31,14 @@ export const ARCHIVER_STORE_NAME = 'archiver';
|
|
|
31
31
|
/** Creates an archiver store. */
|
|
32
32
|
export async function createArchiverStore(
|
|
33
33
|
userConfig: Pick<ArchiverConfig, 'archiverStoreMapSizeKb' | 'maxLogs'> & DataStoreConfig,
|
|
34
|
+
l1Constants: Pick<L1RollupConstants, 'epochDuration'>,
|
|
34
35
|
) {
|
|
35
36
|
const config = {
|
|
36
37
|
...userConfig,
|
|
37
38
|
dataStoreMapSizeKb: userConfig.archiverStoreMapSizeKb ?? userConfig.dataStoreMapSizeKb,
|
|
38
39
|
};
|
|
39
|
-
const store = await createStore(ARCHIVER_STORE_NAME, ARCHIVER_DB_VERSION, config
|
|
40
|
-
return new KVArchiverDataStore(store, config.maxLogs);
|
|
40
|
+
const store = await createStore(ARCHIVER_STORE_NAME, ARCHIVER_DB_VERSION, config);
|
|
41
|
+
return new KVArchiverDataStore(store, config.maxLogs, l1Constants);
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
/**
|
|
@@ -52,7 +53,7 @@ export async function createArchiver(
|
|
|
52
53
|
deps: ArchiverDeps,
|
|
53
54
|
opts: { blockUntilSync: boolean } = { blockUntilSync: true },
|
|
54
55
|
): Promise<Archiver> {
|
|
55
|
-
const archiverStore = await createArchiverStore(config);
|
|
56
|
+
const archiverStore = await createArchiverStore(config, { epochDuration: config.aztecEpochDuration });
|
|
56
57
|
await registerProtocolContracts(archiverStore);
|
|
57
58
|
|
|
58
59
|
// Create Ethereum clients
|
|
@@ -155,7 +156,8 @@ export async function createArchiver(
|
|
|
155
156
|
return archiver;
|
|
156
157
|
}
|
|
157
158
|
|
|
158
|
-
|
|
159
|
+
/** Registers protocol contracts in the archiver store. */
|
|
160
|
+
export async function registerProtocolContracts(store: KVArchiverDataStore) {
|
|
159
161
|
const blockNumber = 0;
|
|
160
162
|
for (const name of protocolContractNames) {
|
|
161
163
|
const provider = new BundledProtocolContractsProvider();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import type { ViemPublicClient, ViemPublicDebugClient } from '@aztec/ethereum/types';
|
|
3
|
-
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
4
4
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
6
|
|
|
@@ -142,7 +142,12 @@ async function main() {
|
|
|
142
142
|
logger.info('');
|
|
143
143
|
|
|
144
144
|
// For this script, we don't have blob hashes or expected hashes, so pass empty arrays/objects
|
|
145
|
-
const result = await retriever.getCheckpointFromRollupTx(
|
|
145
|
+
const result = await retriever.getCheckpointFromRollupTx(
|
|
146
|
+
txHash,
|
|
147
|
+
[],
|
|
148
|
+
CheckpointNumber.fromBlockNumber(BlockNumber(l2BlockNumber)),
|
|
149
|
+
{},
|
|
150
|
+
);
|
|
146
151
|
|
|
147
152
|
logger.info(' Successfully retrieved block header!');
|
|
148
153
|
logger.info('');
|
package/src/l1/data_retrieval.ts
CHANGED
|
@@ -20,7 +20,7 @@ import { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
20
20
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
21
21
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
22
22
|
import { RollupAbi } from '@aztec/l1-artifacts';
|
|
23
|
-
import { Body, CommitteeAttestation,
|
|
23
|
+
import { Body, CommitteeAttestation, L2Block } from '@aztec/stdlib/block';
|
|
24
24
|
import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
25
25
|
import { Proof } from '@aztec/stdlib/proofs';
|
|
26
26
|
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
@@ -69,7 +69,7 @@ export async function retrievedToPublishedCheckpoint({
|
|
|
69
69
|
const l1toL2MessageTreeRoot = blocksBlobData[0].l1ToL2MessageRoot!;
|
|
70
70
|
|
|
71
71
|
const spongeBlob = SpongeBlob.init();
|
|
72
|
-
const l2Blocks:
|
|
72
|
+
const l2Blocks: L2Block[] = [];
|
|
73
73
|
for (let i = 0; i < blocksBlobData.length; i++) {
|
|
74
74
|
const blockBlobData = blocksBlobData[i];
|
|
75
75
|
const { blockEndMarker, blockEndStateField, lastArchiveRoot, noteHashRoot, nullifierRoot, publicDataRoot } =
|
|
@@ -100,7 +100,7 @@ export async function retrievedToPublishedCheckpoint({
|
|
|
100
100
|
}),
|
|
101
101
|
});
|
|
102
102
|
|
|
103
|
-
const body = Body.fromTxBlobData(
|
|
103
|
+
const body = Body.fromTxBlobData(blockBlobData.txs);
|
|
104
104
|
|
|
105
105
|
const blobFields = encodeBlockBlobData(blockBlobData);
|
|
106
106
|
await spongeBlob.absorb(blobFields);
|
|
@@ -119,7 +119,7 @@ export async function retrievedToPublishedCheckpoint({
|
|
|
119
119
|
|
|
120
120
|
const newArchive = new AppendOnlyTreeSnapshot(newArchiveRoots[i], l2BlockNumber + 1);
|
|
121
121
|
|
|
122
|
-
l2Blocks.push(new
|
|
122
|
+
l2Blocks.push(new L2Block(newArchive, header, body, checkpointNumber, IndexWithinCheckpoint(i)));
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
const lastBlock = l2Blocks.at(-1)!;
|
package/src/l1/validate_trace.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ViemPublicDebugClient } from '@aztec/ethereum/types';
|
|
2
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
3
3
|
|
|
4
4
|
import type { Hex } from 'viem';
|
|
5
5
|
import type { ZodSchema } from 'zod';
|
|
@@ -7,8 +7,6 @@ import type { ZodSchema } from 'zod';
|
|
|
7
7
|
import { callTraceSchema } from './debug_tx.js';
|
|
8
8
|
import { traceTransactionResponseSchema } from './trace_tx.js';
|
|
9
9
|
|
|
10
|
-
const logger = createLogger('aztec:archiver:validate_trace');
|
|
11
|
-
|
|
12
10
|
/**
|
|
13
11
|
* Helper function to test a trace method with validation
|
|
14
12
|
*
|
|
@@ -17,6 +15,7 @@ const logger = createLogger('aztec:archiver:validate_trace');
|
|
|
17
15
|
* @param schema - Zod schema to validate the response
|
|
18
16
|
* @param method - Name of the RPC method ('debug_traceTransaction' or 'trace_transaction')
|
|
19
17
|
* @param blockType - Type of block being tested ('recent' or 'old')
|
|
18
|
+
* @param logger - Logger instance
|
|
20
19
|
* @returns true if the method works and validation passes, false otherwise
|
|
21
20
|
*/
|
|
22
21
|
async function testTraceMethod(
|
|
@@ -25,6 +24,7 @@ async function testTraceMethod(
|
|
|
25
24
|
schema: ZodSchema,
|
|
26
25
|
method: 'debug_traceTransaction' | 'trace_transaction',
|
|
27
26
|
blockType: string,
|
|
27
|
+
logger: Logger,
|
|
28
28
|
): Promise<boolean> {
|
|
29
29
|
try {
|
|
30
30
|
// Make request with appropriate params based on method name
|
|
@@ -59,9 +59,14 @@ export interface TraceAvailability {
|
|
|
59
59
|
* Validates the availability of debug/trace methods on the Ethereum client.
|
|
60
60
|
*
|
|
61
61
|
* @param client - The Viem public debug client
|
|
62
|
+
* @param bindings - Optional logger bindings for context
|
|
62
63
|
* @returns Object indicating which trace methods are available for recent and old blocks
|
|
63
64
|
*/
|
|
64
|
-
export async function validateTraceAvailability(
|
|
65
|
+
export async function validateTraceAvailability(
|
|
66
|
+
client: ViemPublicDebugClient,
|
|
67
|
+
bindings?: LoggerBindings,
|
|
68
|
+
): Promise<TraceAvailability> {
|
|
69
|
+
const logger = createLogger('archiver:validate_trace', bindings);
|
|
65
70
|
const result: TraceAvailability = {
|
|
66
71
|
debugTraceRecent: false,
|
|
67
72
|
traceTransactionRecent: false,
|
|
@@ -95,6 +100,7 @@ export async function validateTraceAvailability(client: ViemPublicDebugClient):
|
|
|
95
100
|
callTraceSchema,
|
|
96
101
|
'debug_traceTransaction',
|
|
97
102
|
'recent',
|
|
103
|
+
logger,
|
|
98
104
|
);
|
|
99
105
|
|
|
100
106
|
// Test trace_transaction with recent block
|
|
@@ -104,6 +110,7 @@ export async function validateTraceAvailability(client: ViemPublicDebugClient):
|
|
|
104
110
|
traceTransactionResponseSchema,
|
|
105
111
|
'trace_transaction',
|
|
106
112
|
'recent',
|
|
113
|
+
logger,
|
|
107
114
|
);
|
|
108
115
|
|
|
109
116
|
// Get a block from 512 blocks ago
|
|
@@ -132,7 +139,14 @@ export async function validateTraceAvailability(client: ViemPublicDebugClient):
|
|
|
132
139
|
const oldTxHash = oldBlock.transactions[0] as Hex;
|
|
133
140
|
|
|
134
141
|
// Test debug_traceTransaction with old block
|
|
135
|
-
result.debugTraceOld = await testTraceMethod(
|
|
142
|
+
result.debugTraceOld = await testTraceMethod(
|
|
143
|
+
client,
|
|
144
|
+
oldTxHash,
|
|
145
|
+
callTraceSchema,
|
|
146
|
+
'debug_traceTransaction',
|
|
147
|
+
'old',
|
|
148
|
+
logger,
|
|
149
|
+
);
|
|
136
150
|
|
|
137
151
|
// Test trace_transaction with old block
|
|
138
152
|
result.traceTransactionOld = await testTraceMethod(
|
|
@@ -141,6 +155,7 @@ export async function validateTraceAvailability(client: ViemPublicDebugClient):
|
|
|
141
155
|
traceTransactionResponseSchema,
|
|
142
156
|
'trace_transaction',
|
|
143
157
|
'old',
|
|
158
|
+
logger,
|
|
144
159
|
);
|
|
145
160
|
} catch (error) {
|
|
146
161
|
logger.warn(`Error validating debug_traceTransaction and trace_transaction availability: ${error}`);
|
|
@@ -159,15 +174,18 @@ function hasTxs(block: { transactions?: Hex[] }): boolean {
|
|
|
159
174
|
*
|
|
160
175
|
* @param client - The Viem public debug client
|
|
161
176
|
* @param ethereumAllowNoDebugHosts - If false, throws an error when no trace methods are available
|
|
177
|
+
* @param bindings - Optional logger bindings for context
|
|
162
178
|
* @throws Error if ethereumAllowNoDebugHosts is false and no trace methods are available
|
|
163
179
|
*/
|
|
164
180
|
export async function validateAndLogTraceAvailability(
|
|
165
181
|
client: ViemPublicDebugClient,
|
|
166
182
|
ethereumAllowNoDebugHosts: boolean,
|
|
183
|
+
bindings?: LoggerBindings,
|
|
167
184
|
): Promise<void> {
|
|
185
|
+
const logger = createLogger('archiver:validate_trace', bindings);
|
|
168
186
|
logger.debug('Validating trace/debug method availability...');
|
|
169
187
|
|
|
170
|
-
const availability = await validateTraceAvailability(client);
|
|
188
|
+
const availability = await validateTraceAvailability(client, bindings);
|
|
171
189
|
|
|
172
190
|
// Check if we have support for old blocks (either debug or trace)
|
|
173
191
|
const hasOldBlockSupport = availability.debugTraceOld || availability.traceTransactionOld;
|
|
@@ -4,7 +4,7 @@ import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
|
4
4
|
import { isDefined } from '@aztec/foundation/types';
|
|
5
5
|
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
6
6
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
7
|
-
import { CheckpointedL2Block, CommitteeAttestation,
|
|
7
|
+
import { type BlockHash, CheckpointedL2Block, CommitteeAttestation, L2Block, type L2Tips } from '@aztec/stdlib/block';
|
|
8
8
|
import { Checkpoint, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
9
9
|
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
10
10
|
import { type L1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
@@ -87,10 +87,14 @@ export abstract class ArchiverDataSourceBase
|
|
|
87
87
|
return this.store.getCheckpointedBlock(number);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
public
|
|
90
|
+
public getCheckpointedL2BlockNumber(): Promise<BlockNumber> {
|
|
91
91
|
return this.store.getCheckpointedL2BlockNumber();
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
public getFinalizedL2BlockNumber(): Promise<BlockNumber> {
|
|
95
|
+
return this.store.getFinalizedL2BlockNumber();
|
|
96
|
+
}
|
|
97
|
+
|
|
94
98
|
public async getCheckpointHeader(number: CheckpointNumber | 'latest'): Promise<CheckpointHeader | undefined> {
|
|
95
99
|
if (number === 'latest') {
|
|
96
100
|
number = await this.store.getSynchedCheckpointNumber();
|
|
@@ -113,21 +117,11 @@ export abstract class ArchiverDataSourceBase
|
|
|
113
117
|
return BlockNumber(checkpointData.startBlock + checkpointData.numBlocks - 1);
|
|
114
118
|
}
|
|
115
119
|
|
|
116
|
-
public
|
|
117
|
-
from
|
|
118
|
-
limit: number,
|
|
119
|
-
proven?: boolean,
|
|
120
|
-
): Promise<CheckpointedL2Block[]> {
|
|
121
|
-
const blocks = await this.store.getCheckpointedBlocks(from, limit);
|
|
122
|
-
|
|
123
|
-
if (proven === true) {
|
|
124
|
-
const provenBlockNumber = await this.store.getProvenBlockNumber();
|
|
125
|
-
return blocks.filter(b => b.block.number <= provenBlockNumber);
|
|
126
|
-
}
|
|
127
|
-
return blocks;
|
|
120
|
+
public getCheckpointedBlocks(from: BlockNumber, limit: number): Promise<CheckpointedL2Block[]> {
|
|
121
|
+
return this.store.getCheckpointedBlocks(from, limit);
|
|
128
122
|
}
|
|
129
123
|
|
|
130
|
-
public getBlockHeaderByHash(blockHash:
|
|
124
|
+
public getBlockHeaderByHash(blockHash: BlockHash): Promise<BlockHeader | undefined> {
|
|
131
125
|
return this.store.getBlockHeaderByHash(blockHash);
|
|
132
126
|
}
|
|
133
127
|
|
|
@@ -135,7 +129,7 @@ export abstract class ArchiverDataSourceBase
|
|
|
135
129
|
return this.store.getBlockHeaderByArchive(archive);
|
|
136
130
|
}
|
|
137
131
|
|
|
138
|
-
public async
|
|
132
|
+
public async getL2Block(number: BlockNumber): Promise<L2Block | undefined> {
|
|
139
133
|
// If the number provided is -ve, then return the latest block.
|
|
140
134
|
if (number < 0) {
|
|
141
135
|
number = await this.store.getLatestBlockNumber();
|
|
@@ -163,22 +157,16 @@ export abstract class ArchiverDataSourceBase
|
|
|
163
157
|
return (await this.store.getPendingChainValidationStatus()) ?? { valid: true };
|
|
164
158
|
}
|
|
165
159
|
|
|
166
|
-
public
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
if (proven === true) {
|
|
170
|
-
const provenBlockNumber = await this.store.getProvenBlockNumber();
|
|
171
|
-
return blocks.filter(b => b.number <= provenBlockNumber);
|
|
172
|
-
}
|
|
173
|
-
return blocks;
|
|
160
|
+
public getPrivateLogsByTags(tags: SiloedTag[], page?: number): Promise<TxScopedL2Log[][]> {
|
|
161
|
+
return this.store.getPrivateLogsByTags(tags, page);
|
|
174
162
|
}
|
|
175
163
|
|
|
176
|
-
public
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
return this.store.getPublicLogsByTagsFromContract(contractAddress, tags);
|
|
164
|
+
public getPublicLogsByTagsFromContract(
|
|
165
|
+
contractAddress: AztecAddress,
|
|
166
|
+
tags: Tag[],
|
|
167
|
+
page?: number,
|
|
168
|
+
): Promise<TxScopedL2Log[][]> {
|
|
169
|
+
return this.store.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
182
170
|
}
|
|
183
171
|
|
|
184
172
|
public getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse> {
|
|
@@ -233,10 +221,7 @@ export abstract class ArchiverDataSourceBase
|
|
|
233
221
|
return this.store.getL1ToL2MessageIndex(l1ToL2Message);
|
|
234
222
|
}
|
|
235
223
|
|
|
236
|
-
public async
|
|
237
|
-
checkpointNumber: CheckpointNumber,
|
|
238
|
-
limit: number,
|
|
239
|
-
): Promise<PublishedCheckpoint[]> {
|
|
224
|
+
public async getCheckpoints(checkpointNumber: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
240
225
|
const checkpoints = await this.store.getRangeOfCheckpoints(checkpointNumber, limit);
|
|
241
226
|
const blocks = (
|
|
242
227
|
await Promise.all(checkpoints.map(ch => this.store.getBlocksForCheckpoint(ch.checkpointNumber)))
|
|
@@ -262,17 +247,17 @@ export abstract class ArchiverDataSourceBase
|
|
|
262
247
|
return fullCheckpoints;
|
|
263
248
|
}
|
|
264
249
|
|
|
265
|
-
public getBlocksForSlot(slotNumber: SlotNumber): Promise<
|
|
250
|
+
public getBlocksForSlot(slotNumber: SlotNumber): Promise<L2Block[]> {
|
|
266
251
|
return this.store.getBlocksForSlot(slotNumber);
|
|
267
252
|
}
|
|
268
253
|
|
|
269
|
-
public async
|
|
254
|
+
public async getCheckpointedBlocksForEpoch(epochNumber: EpochNumber): Promise<CheckpointedL2Block[]> {
|
|
270
255
|
if (!this.l1Constants) {
|
|
271
256
|
throw new Error('L1 constants not set');
|
|
272
257
|
}
|
|
273
258
|
|
|
274
259
|
const [start, end] = getSlotRangeForEpoch(epochNumber, this.l1Constants);
|
|
275
|
-
const blocks:
|
|
260
|
+
const blocks: CheckpointedL2Block[] = [];
|
|
276
261
|
|
|
277
262
|
// Walk the list of checkpoints backwards and filter by slots matching the requested epoch.
|
|
278
263
|
// We'll typically ask for checkpoints for a very recent epoch, so we shouldn't need an index here.
|
|
@@ -283,9 +268,9 @@ export abstract class ArchiverDataSourceBase
|
|
|
283
268
|
// push the blocks on backwards
|
|
284
269
|
const endBlock = checkpoint.startBlock + checkpoint.numBlocks - 1;
|
|
285
270
|
for (let i = endBlock; i >= checkpoint.startBlock; i--) {
|
|
286
|
-
const
|
|
287
|
-
if (
|
|
288
|
-
blocks.push(
|
|
271
|
+
const checkpointedBlock = await this.getCheckpointedBlock(BlockNumber(i));
|
|
272
|
+
if (checkpointedBlock) {
|
|
273
|
+
blocks.push(checkpointedBlock);
|
|
289
274
|
}
|
|
290
275
|
}
|
|
291
276
|
}
|
|
@@ -295,7 +280,7 @@ export abstract class ArchiverDataSourceBase
|
|
|
295
280
|
return blocks.reverse();
|
|
296
281
|
}
|
|
297
282
|
|
|
298
|
-
public async
|
|
283
|
+
public async getCheckpointedBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]> {
|
|
299
284
|
if (!this.l1Constants) {
|
|
300
285
|
throw new Error('L1 constants not set');
|
|
301
286
|
}
|
|
@@ -338,7 +323,7 @@ export abstract class ArchiverDataSourceBase
|
|
|
338
323
|
while (checkpointData && slot(checkpointData) >= start) {
|
|
339
324
|
if (slot(checkpointData) <= end) {
|
|
340
325
|
// push the checkpoints on backwards
|
|
341
|
-
const [checkpoint] = await this.
|
|
326
|
+
const [checkpoint] = await this.getCheckpoints(checkpointData.checkpointNumber, 1);
|
|
342
327
|
checkpoints.push(checkpoint.checkpoint);
|
|
343
328
|
}
|
|
344
329
|
checkpointData = await this.store.getCheckpointData(CheckpointNumber(checkpointData.checkpointNumber - 1));
|
|
@@ -347,33 +332,7 @@ export abstract class ArchiverDataSourceBase
|
|
|
347
332
|
return checkpoints.reverse();
|
|
348
333
|
}
|
|
349
334
|
|
|
350
|
-
public async
|
|
351
|
-
const checkpoints = await this.store.getRangeOfCheckpoints(CheckpointNumber(from), limit);
|
|
352
|
-
const provenCheckpointNumber = await this.store.getProvenCheckpointNumber();
|
|
353
|
-
const blocks = (
|
|
354
|
-
await Promise.all(checkpoints.map(ch => this.store.getBlocksForCheckpoint(ch.checkpointNumber)))
|
|
355
|
-
).filter(isDefined);
|
|
356
|
-
|
|
357
|
-
const publishedBlocks: CheckpointedL2Block[] = [];
|
|
358
|
-
for (let i = 0; i < checkpoints.length; i++) {
|
|
359
|
-
const blockForCheckpoint = blocks[i][0];
|
|
360
|
-
const checkpoint = checkpoints[i];
|
|
361
|
-
if (checkpoint.checkpointNumber > provenCheckpointNumber && proven === true) {
|
|
362
|
-
// this checkpoint isn't proven and we only want proven
|
|
363
|
-
continue;
|
|
364
|
-
}
|
|
365
|
-
const publishedBlock = new CheckpointedL2Block(
|
|
366
|
-
checkpoint.checkpointNumber,
|
|
367
|
-
blockForCheckpoint,
|
|
368
|
-
checkpoint.l1,
|
|
369
|
-
checkpoint.attestations.map(x => CommitteeAttestation.fromBuffer(x)),
|
|
370
|
-
);
|
|
371
|
-
publishedBlocks.push(publishedBlock);
|
|
372
|
-
}
|
|
373
|
-
return publishedBlocks;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
public async getBlock(number: BlockNumber): Promise<L2BlockNew | undefined> {
|
|
335
|
+
public async getBlock(number: BlockNumber): Promise<L2Block | undefined> {
|
|
377
336
|
// If the number provided is -ve, then return the latest block.
|
|
378
337
|
if (number < 0) {
|
|
379
338
|
number = await this.store.getLatestBlockNumber();
|
|
@@ -384,30 +343,24 @@ export abstract class ArchiverDataSourceBase
|
|
|
384
343
|
return this.store.getBlock(number);
|
|
385
344
|
}
|
|
386
345
|
|
|
387
|
-
public
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
if (proven === true) {
|
|
391
|
-
const provenBlockNumber = await this.store.getProvenBlockNumber();
|
|
392
|
-
return blocks.filter(b => b.number <= provenBlockNumber);
|
|
393
|
-
}
|
|
394
|
-
return blocks;
|
|
346
|
+
public getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
|
|
347
|
+
return this.store.getBlocks(from, limit);
|
|
395
348
|
}
|
|
396
349
|
|
|
397
|
-
public
|
|
350
|
+
public getCheckpointedBlockByHash(blockHash: BlockHash): Promise<CheckpointedL2Block | undefined> {
|
|
398
351
|
return this.store.getCheckpointedBlockByHash(blockHash);
|
|
399
352
|
}
|
|
400
353
|
|
|
401
|
-
public
|
|
354
|
+
public getCheckpointedBlockByArchive(archive: Fr): Promise<CheckpointedL2Block | undefined> {
|
|
402
355
|
return this.store.getCheckpointedBlockByArchive(archive);
|
|
403
356
|
}
|
|
404
357
|
|
|
405
|
-
public async
|
|
358
|
+
public async getL2BlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
406
359
|
const checkpointedBlock = await this.store.getCheckpointedBlockByHash(blockHash);
|
|
407
360
|
return checkpointedBlock?.block;
|
|
408
361
|
}
|
|
409
362
|
|
|
410
|
-
public async
|
|
363
|
+
public async getL2BlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
411
364
|
const checkpointedBlock = await this.store.getCheckpointedBlockByArchive(archive);
|
|
412
365
|
return checkpointedBlock?.block;
|
|
413
366
|
}
|