@aztec/archiver 3.0.3 → 3.9.9-nightly.20260312
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 +156 -22
- package/dest/archiver.d.ts +139 -0
- package/dest/archiver.d.ts.map +1 -0
- package/dest/archiver.js +734 -0
- package/dest/{archiver/config.d.ts → config.d.ts} +11 -3
- package/dest/config.d.ts.map +1 -0
- package/dest/{archiver/config.js → config.js} +13 -4
- package/dest/errors.d.ts +39 -0
- package/dest/errors.d.ts.map +1 -0
- package/dest/errors.js +57 -0
- package/dest/factory.d.ts +9 -7
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +93 -11
- package/dest/index.d.ts +11 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +9 -3
- package/dest/interfaces.d.ts +9 -0
- package/dest/interfaces.d.ts.map +1 -0
- package/dest/interfaces.js +3 -0
- package/dest/{archiver/l1 → l1}/bin/retrieve-calldata.d.ts +1 -1
- package/dest/l1/bin/retrieve-calldata.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/bin/retrieve-calldata.js +38 -33
- package/dest/l1/calldata_retriever.d.ts +135 -0
- package/dest/l1/calldata_retriever.d.ts.map +1 -0
- package/dest/l1/calldata_retriever.js +402 -0
- package/dest/l1/data_retrieval.d.ts +85 -0
- package/dest/l1/data_retrieval.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/data_retrieval.js +63 -73
- package/dest/{archiver/l1 → l1}/debug_tx.d.ts +1 -1
- package/dest/l1/debug_tx.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/spire_proposer.d.ts +5 -5
- package/dest/l1/spire_proposer.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/spire_proposer.js +9 -17
- package/dest/{archiver/l1 → l1}/trace_tx.d.ts +1 -1
- package/dest/l1/trace_tx.d.ts.map +1 -0
- package/dest/l1/types.d.ts +12 -0
- package/dest/l1/types.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/validate_trace.d.ts +6 -3
- package/dest/l1/validate_trace.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/validate_trace.js +14 -10
- package/dest/modules/data_source_base.d.ts +89 -0
- package/dest/modules/data_source_base.d.ts.map +1 -0
- package/dest/modules/data_source_base.js +216 -0
- package/dest/modules/data_store_updater.d.ts +83 -0
- package/dest/modules/data_store_updater.d.ts.map +1 -0
- package/dest/modules/data_store_updater.js +333 -0
- package/dest/modules/instrumentation.d.ts +39 -0
- package/dest/modules/instrumentation.d.ts.map +1 -0
- package/dest/{archiver → modules}/instrumentation.js +33 -67
- package/dest/modules/l1_synchronizer.d.ts +71 -0
- package/dest/modules/l1_synchronizer.d.ts.map +1 -0
- package/dest/modules/l1_synchronizer.js +1112 -0
- package/dest/modules/validation.d.ts +17 -0
- package/dest/modules/validation.d.ts.map +1 -0
- package/dest/{archiver → modules}/validation.js +7 -1
- package/dest/store/block_store.d.ts +196 -0
- package/dest/store/block_store.d.ts.map +1 -0
- package/dest/store/block_store.js +755 -0
- package/dest/store/contract_class_store.d.ts +18 -0
- package/dest/store/contract_class_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/contract_class_store.js +12 -8
- package/dest/store/contract_instance_store.d.ts +24 -0
- package/dest/store/contract_instance_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +1 -1
- package/dest/store/kv_archiver_store.d.ts +353 -0
- package/dest/store/kv_archiver_store.d.ts.map +1 -0
- package/dest/store/kv_archiver_store.js +464 -0
- package/dest/store/l2_tips_cache.d.ts +19 -0
- package/dest/store/l2_tips_cache.d.ts.map +1 -0
- package/dest/store/l2_tips_cache.js +89 -0
- package/dest/store/log_store.d.ts +54 -0
- package/dest/store/log_store.d.ts.map +1 -0
- package/dest/store/log_store.js +456 -0
- package/dest/{archiver/kv_archiver_store → store}/message_store.d.ts +1 -1
- package/dest/store/message_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/message_store.js +1 -1
- package/dest/{archiver/structs → structs}/data_retrieval.d.ts +1 -1
- package/dest/structs/data_retrieval.d.ts.map +1 -0
- package/dest/structs/inbox_message.d.ts +15 -0
- package/dest/structs/inbox_message.d.ts.map +1 -0
- package/dest/structs/published.d.ts +2 -0
- package/dest/structs/published.d.ts.map +1 -0
- package/dest/test/fake_l1_state.d.ts +195 -0
- package/dest/test/fake_l1_state.d.ts.map +1 -0
- package/dest/test/fake_l1_state.js +421 -0
- package/dest/test/index.d.ts +2 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +4 -1
- package/dest/test/mock_archiver.d.ts +2 -2
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +3 -3
- package/dest/test/mock_l1_to_l2_message_source.d.ts +2 -2
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +12 -3
- package/dest/test/mock_l2_block_source.d.ts +47 -17
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +244 -91
- package/dest/test/mock_structs.d.ts +81 -3
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +152 -7
- package/dest/test/noop_l1_archiver.d.ts +26 -0
- package/dest/test/noop_l1_archiver.d.ts.map +1 -0
- package/dest/test/noop_l1_archiver.js +72 -0
- package/package.json +16 -17
- package/src/archiver.ts +488 -0
- package/src/{archiver/config.ts → config.ts} +20 -5
- package/src/errors.ts +88 -0
- package/src/factory.ts +142 -11
- package/src/index.ts +11 -3
- package/src/interfaces.ts +9 -0
- package/src/l1/README.md +55 -0
- package/src/{archiver/l1 → l1}/bin/retrieve-calldata.ts +46 -34
- package/src/l1/calldata_retriever.ts +511 -0
- package/src/{archiver/l1 → l1}/data_retrieval.ts +93 -99
- package/src/{archiver/l1 → l1}/spire_proposer.ts +7 -15
- package/src/{archiver/l1 → l1}/validate_trace.ts +25 -7
- package/src/modules/data_source_base.ts +328 -0
- package/src/modules/data_store_updater.ts +453 -0
- package/src/{archiver → modules}/instrumentation.ts +33 -70
- package/src/modules/l1_synchronizer.ts +930 -0
- package/src/{archiver → modules}/validation.ts +11 -6
- package/src/store/block_store.ts +990 -0
- package/src/{archiver/kv_archiver_store → store}/contract_class_store.ts +12 -8
- package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +1 -1
- package/src/store/kv_archiver_store.ts +671 -0
- package/src/store/l2_tips_cache.ts +89 -0
- package/src/store/log_store.ts +637 -0
- package/src/{archiver/kv_archiver_store → store}/message_store.ts +1 -1
- package/src/{archiver/structs → structs}/published.ts +0 -1
- package/src/test/fake_l1_state.ts +657 -0
- package/src/test/index.ts +4 -0
- package/src/test/mock_archiver.ts +4 -3
- package/src/test/mock_l1_to_l2_message_source.ts +10 -4
- package/src/test/mock_l2_block_source.ts +294 -98
- package/src/test/mock_structs.ts +283 -8
- package/src/test/noop_l1_archiver.ts +115 -0
- package/dest/archiver/archiver.d.ts +0 -284
- package/dest/archiver/archiver.d.ts.map +0 -1
- package/dest/archiver/archiver.js +0 -1454
- package/dest/archiver/archiver_store.d.ts +0 -249
- package/dest/archiver/archiver_store.d.ts.map +0 -1
- package/dest/archiver/archiver_store.js +0 -4
- package/dest/archiver/archiver_store_test_suite.d.ts +0 -8
- package/dest/archiver/archiver_store_test_suite.d.ts.map +0 -1
- package/dest/archiver/archiver_store_test_suite.js +0 -1273
- package/dest/archiver/config.d.ts.map +0 -1
- package/dest/archiver/errors.d.ts +0 -12
- package/dest/archiver/errors.d.ts.map +0 -1
- package/dest/archiver/errors.js +0 -17
- package/dest/archiver/index.d.ts +0 -7
- package/dest/archiver/index.d.ts.map +0 -1
- package/dest/archiver/index.js +0 -4
- package/dest/archiver/instrumentation.d.ts +0 -37
- package/dest/archiver/instrumentation.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -125
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/block_store.js +0 -371
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +0 -18
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +0 -24
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +0 -162
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.js +0 -288
- package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -42
- package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/log_store.js +0 -314
- package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
- package/dest/archiver/l1/bin/retrieve-calldata.d.ts.map +0 -1
- package/dest/archiver/l1/calldata_retriever.d.ts +0 -98
- package/dest/archiver/l1/calldata_retriever.d.ts.map +0 -1
- package/dest/archiver/l1/calldata_retriever.js +0 -403
- package/dest/archiver/l1/data_retrieval.d.ts +0 -87
- package/dest/archiver/l1/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/l1/debug_tx.d.ts.map +0 -1
- package/dest/archiver/l1/spire_proposer.d.ts.map +0 -1
- package/dest/archiver/l1/trace_tx.d.ts.map +0 -1
- package/dest/archiver/l1/types.d.ts +0 -12
- package/dest/archiver/l1/types.d.ts.map +0 -1
- package/dest/archiver/l1/validate_trace.d.ts.map +0 -1
- package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/structs/inbox_message.d.ts +0 -15
- package/dest/archiver/structs/inbox_message.d.ts.map +0 -1
- package/dest/archiver/structs/published.d.ts +0 -3
- package/dest/archiver/structs/published.d.ts.map +0 -1
- package/dest/archiver/validation.d.ts +0 -17
- package/dest/archiver/validation.d.ts.map +0 -1
- package/dest/rpc/index.d.ts +0 -9
- package/dest/rpc/index.d.ts.map +0 -1
- package/dest/rpc/index.js +0 -15
- package/src/archiver/archiver.ts +0 -1906
- package/src/archiver/archiver_store.ts +0 -302
- package/src/archiver/archiver_store_test_suite.ts +0 -1286
- package/src/archiver/errors.ts +0 -26
- package/src/archiver/index.ts +0 -6
- package/src/archiver/kv_archiver_store/block_store.ts +0 -482
- package/src/archiver/kv_archiver_store/kv_archiver_store.ts +0 -413
- package/src/archiver/kv_archiver_store/log_store.ts +0 -380
- package/src/archiver/l1/README.md +0 -98
- package/src/archiver/l1/calldata_retriever.ts +0 -531
- package/src/rpc/index.ts +0 -16
- /package/dest/{archiver/l1 → l1}/debug_tx.js +0 -0
- /package/dest/{archiver/l1 → l1}/trace_tx.js +0 -0
- /package/dest/{archiver/l1 → l1}/types.js +0 -0
- /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
- /package/dest/{archiver/structs → structs}/inbox_message.js +0 -0
- /package/dest/{archiver/structs → structs}/published.js +0 -0
- /package/src/{archiver/l1 → l1}/debug_tx.ts +0 -0
- /package/src/{archiver/l1 → l1}/trace_tx.ts +0 -0
- /package/src/{archiver/l1 → l1}/types.ts +0 -0
- /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
- /package/src/{archiver/structs → structs}/inbox_message.ts +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BlockNumber,
|
|
1
|
+
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
-
import type { L2Tips } from '@aztec/stdlib/block';
|
|
3
|
+
import type { CheckpointId, L2BlockId, L2TipId, L2Tips } from '@aztec/stdlib/block';
|
|
4
4
|
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -33,9 +33,15 @@ export class MockL1ToL2MessageSource implements L1ToL2MessageSource {
|
|
|
33
33
|
|
|
34
34
|
getL2Tips(): Promise<L2Tips> {
|
|
35
35
|
const number = this.blockNumber;
|
|
36
|
-
const
|
|
36
|
+
const blockId: L2BlockId = { number: BlockNumber(number), hash: new Fr(number).toString() };
|
|
37
|
+
const checkpointId: CheckpointId = {
|
|
38
|
+
number: CheckpointNumber(number),
|
|
39
|
+
hash: new Fr(number + 1).toString(),
|
|
40
|
+
};
|
|
41
|
+
const tip: L2TipId = { block: blockId, checkpoint: checkpointId };
|
|
37
42
|
return Promise.resolve({
|
|
38
|
-
|
|
43
|
+
proposed: blockId,
|
|
44
|
+
checkpointed: tip,
|
|
39
45
|
proven: tip,
|
|
40
46
|
finalized: tip,
|
|
41
47
|
});
|
|
@@ -8,17 +8,20 @@ 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
|
+
type BlockData,
|
|
12
|
+
BlockHash,
|
|
13
|
+
CheckpointedL2Block,
|
|
11
14
|
L2Block,
|
|
12
|
-
L2BlockHash,
|
|
13
15
|
type L2BlockSource,
|
|
14
16
|
type L2Tips,
|
|
15
|
-
|
|
16
|
-
type ValidateBlockResult,
|
|
17
|
+
type ValidateCheckpointResult,
|
|
17
18
|
} from '@aztec/stdlib/block';
|
|
18
|
-
import
|
|
19
|
+
import { Checkpoint, type CheckpointData, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
19
20
|
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
20
21
|
import { EmptyL1RollupConstants, type L1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
21
|
-
import {
|
|
22
|
+
import { computeCheckpointOutHash } from '@aztec/stdlib/messaging';
|
|
23
|
+
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
24
|
+
import { type BlockHeader, TxExecutionResult, TxHash, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
22
25
|
import type { UInt64 } from '@aztec/stdlib/types';
|
|
23
26
|
|
|
24
27
|
/**
|
|
@@ -26,29 +29,63 @@ import type { UInt64 } from '@aztec/stdlib/types';
|
|
|
26
29
|
*/
|
|
27
30
|
export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
28
31
|
protected l2Blocks: L2Block[] = [];
|
|
32
|
+
protected checkpointList: Checkpoint[] = [];
|
|
29
33
|
|
|
30
34
|
private provenBlockNumber: number = 0;
|
|
31
35
|
private finalizedBlockNumber: number = 0;
|
|
36
|
+
private checkpointedBlockNumber: number = 0;
|
|
32
37
|
|
|
33
38
|
private log = createLogger('archiver:mock_l2_block_source');
|
|
34
39
|
|
|
40
|
+
/** Creates blocks grouped into single-block checkpoints. */
|
|
35
41
|
public async createBlocks(numBlocks: number) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
await this.createCheckpoints(numBlocks, 1);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public getCheckpointNumber(): Promise<CheckpointNumber> {
|
|
46
|
+
return Promise.resolve(
|
|
47
|
+
this.checkpointList.length === 0 ? CheckpointNumber.ZERO : CheckpointNumber(this.checkpointList.length),
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Creates checkpoints, each containing `blocksPerCheckpoint` blocks. */
|
|
52
|
+
public async createCheckpoints(numCheckpoints: number, blocksPerCheckpoint: number = 1) {
|
|
53
|
+
for (let c = 0; c < numCheckpoints; c++) {
|
|
54
|
+
const checkpointNum = CheckpointNumber(this.checkpointList.length + 1);
|
|
55
|
+
const startBlockNum = this.l2Blocks.length + 1;
|
|
56
|
+
const slotNumber = SlotNumber(Number(checkpointNum));
|
|
57
|
+
const checkpoint = await Checkpoint.random(checkpointNum, {
|
|
58
|
+
numBlocks: blocksPerCheckpoint,
|
|
59
|
+
startBlockNumber: startBlockNum,
|
|
60
|
+
slotNumber,
|
|
61
|
+
checkpointNumber: checkpointNum,
|
|
62
|
+
});
|
|
63
|
+
this.checkpointList.push(checkpoint);
|
|
64
|
+
this.l2Blocks.push(...checkpoint.blocks);
|
|
40
65
|
}
|
|
41
66
|
|
|
42
|
-
this.log.verbose(
|
|
67
|
+
this.log.verbose(
|
|
68
|
+
`Created ${numCheckpoints} checkpoints with ${blocksPerCheckpoint} blocks each in the mock L2 block source`,
|
|
69
|
+
);
|
|
43
70
|
}
|
|
44
71
|
|
|
45
|
-
public
|
|
72
|
+
public addProposedBlocks(blocks: L2Block[]) {
|
|
46
73
|
this.l2Blocks.push(...blocks);
|
|
47
|
-
this.log.verbose(`Added ${blocks.length} blocks to the mock L2 block source`);
|
|
74
|
+
this.log.verbose(`Added ${blocks.length} proposed blocks to the mock L2 block source`);
|
|
48
75
|
}
|
|
49
76
|
|
|
50
77
|
public removeBlocks(numBlocks: number) {
|
|
51
78
|
this.l2Blocks = this.l2Blocks.slice(0, -numBlocks);
|
|
79
|
+
const maxBlockNum = this.l2Blocks.length;
|
|
80
|
+
// Remove any checkpoint whose last block is beyond the remaining blocks.
|
|
81
|
+
this.checkpointList = this.checkpointList.filter(c => {
|
|
82
|
+
const lastBlockNum = c.blocks[0].number + c.blocks.length - 1;
|
|
83
|
+
return lastBlockNum <= maxBlockNum;
|
|
84
|
+
});
|
|
85
|
+
// Keep tip numbers consistent with remaining blocks.
|
|
86
|
+
this.checkpointedBlockNumber = Math.min(this.checkpointedBlockNumber, maxBlockNum);
|
|
87
|
+
this.provenBlockNumber = Math.min(this.provenBlockNumber, maxBlockNum);
|
|
88
|
+
this.finalizedBlockNumber = Math.min(this.finalizedBlockNumber, maxBlockNum);
|
|
52
89
|
this.log.verbose(`Removed ${numBlocks} blocks from the mock L2 block source`);
|
|
53
90
|
}
|
|
54
91
|
|
|
@@ -63,6 +100,36 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
63
100
|
this.finalizedBlockNumber = finalizedBlockNumber;
|
|
64
101
|
}
|
|
65
102
|
|
|
103
|
+
public setCheckpointedBlockNumber(checkpointedBlockNumber: number) {
|
|
104
|
+
const prevCheckpointed = this.checkpointedBlockNumber;
|
|
105
|
+
this.checkpointedBlockNumber = checkpointedBlockNumber;
|
|
106
|
+
// Auto-create single-block checkpoints for newly checkpointed blocks that don't have one yet.
|
|
107
|
+
// This handles blocks added via addProposedBlocks that are now being marked as checkpointed.
|
|
108
|
+
const newCheckpoints: Checkpoint[] = [];
|
|
109
|
+
for (let blockNum = prevCheckpointed + 1; blockNum <= checkpointedBlockNumber; blockNum++) {
|
|
110
|
+
const block = this.l2Blocks[blockNum - 1];
|
|
111
|
+
if (!block) {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (this.checkpointList.some(c => c.blocks.some(b => b.number === block.number))) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const checkpointNum = CheckpointNumber(this.checkpointList.length + newCheckpoints.length + 1);
|
|
118
|
+
const checkpoint = new Checkpoint(
|
|
119
|
+
block.archive,
|
|
120
|
+
CheckpointHeader.random({ slotNumber: block.header.globalVariables.slotNumber }),
|
|
121
|
+
[block],
|
|
122
|
+
checkpointNum,
|
|
123
|
+
);
|
|
124
|
+
newCheckpoints.push(checkpoint);
|
|
125
|
+
}
|
|
126
|
+
// Insert new checkpoints in order by number.
|
|
127
|
+
if (newCheckpoints.length > 0) {
|
|
128
|
+
this.checkpointList.push(...newCheckpoints);
|
|
129
|
+
this.checkpointList.sort((a, b) => a.number - b.number);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
66
133
|
/**
|
|
67
134
|
* Method to fetch the rollup contract address at the base-layer.
|
|
68
135
|
* @returns The rollup address.
|
|
@@ -91,13 +158,58 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
91
158
|
return Promise.resolve(BlockNumber(this.provenBlockNumber));
|
|
92
159
|
}
|
|
93
160
|
|
|
161
|
+
public getCheckpointedL2BlockNumber() {
|
|
162
|
+
return Promise.resolve(BlockNumber(this.checkpointedBlockNumber));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
public getFinalizedL2BlockNumber() {
|
|
166
|
+
return Promise.resolve(BlockNumber(this.finalizedBlockNumber));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
public getCheckpointedBlock(number: BlockNumber): Promise<CheckpointedL2Block | undefined> {
|
|
170
|
+
if (number > this.checkpointedBlockNumber) {
|
|
171
|
+
return Promise.resolve(undefined);
|
|
172
|
+
}
|
|
173
|
+
const block = this.l2Blocks[number - 1];
|
|
174
|
+
if (!block) {
|
|
175
|
+
return Promise.resolve(undefined);
|
|
176
|
+
}
|
|
177
|
+
return Promise.resolve(this.toCheckpointedBlock(block));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
public async getCheckpointedBlocks(from: BlockNumber, limit: number): Promise<CheckpointedL2Block[]> {
|
|
181
|
+
const result: CheckpointedL2Block[] = [];
|
|
182
|
+
for (let i = 0; i < limit; i++) {
|
|
183
|
+
const blockNum = from + i;
|
|
184
|
+
if (blockNum > this.checkpointedBlockNumber) {
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
const block = await this.getCheckpointedBlock(BlockNumber(blockNum));
|
|
188
|
+
if (block) {
|
|
189
|
+
result.push(block);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
194
|
+
|
|
94
195
|
/**
|
|
95
196
|
* Gets an l2 block.
|
|
96
197
|
* @param number - The block number to return (inclusive).
|
|
97
198
|
* @returns The requested L2 block.
|
|
98
199
|
*/
|
|
99
|
-
public getBlock(number: number) {
|
|
100
|
-
|
|
200
|
+
public getBlock(number: number): Promise<L2Block | undefined> {
|
|
201
|
+
const block = this.l2Blocks[number - 1];
|
|
202
|
+
return Promise.resolve(block);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Gets an L2 block (new format).
|
|
207
|
+
* @param number - The block number to return.
|
|
208
|
+
* @returns The requested L2 block.
|
|
209
|
+
*/
|
|
210
|
+
public getL2Block(number: BlockNumber): Promise<L2Block | undefined> {
|
|
211
|
+
const block = this.l2Blocks[number - 1];
|
|
212
|
+
return Promise.resolve(block);
|
|
101
213
|
}
|
|
102
214
|
|
|
103
215
|
/**
|
|
@@ -106,80 +218,60 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
106
218
|
* @param limit - The maximum number of blocks to return.
|
|
107
219
|
* @returns The requested mocked L2 blocks.
|
|
108
220
|
*/
|
|
109
|
-
public getBlocks(from: number, limit: number
|
|
221
|
+
public getBlocks(from: number, limit: number): Promise<L2Block[]> {
|
|
222
|
+
return Promise.resolve(this.l2Blocks.slice(from - 1, from - 1 + limit));
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
public getCheckpoints(from: CheckpointNumber, limit: number) {
|
|
226
|
+
const checkpoints = this.checkpointList.slice(from - 1, from - 1 + limit);
|
|
110
227
|
return Promise.resolve(
|
|
111
|
-
this.
|
|
112
|
-
.slice(from - 1, from - 1 + limit)
|
|
113
|
-
.filter(b => !proven || this.provenBlockNumber === undefined || b.number <= this.provenBlockNumber),
|
|
228
|
+
checkpoints.map(checkpoint => new PublishedCheckpoint(checkpoint, this.mockL1DataForCheckpoint(checkpoint), [])),
|
|
114
229
|
);
|
|
115
230
|
}
|
|
116
231
|
|
|
117
|
-
public
|
|
118
|
-
|
|
119
|
-
return
|
|
232
|
+
public getCheckpointByArchive(archive: Fr): Promise<Checkpoint | undefined> {
|
|
233
|
+
const checkpoint = this.checkpointList.find(c => c.archive.root.equals(archive));
|
|
234
|
+
return Promise.resolve(checkpoint);
|
|
120
235
|
}
|
|
121
236
|
|
|
122
|
-
public async
|
|
123
|
-
|
|
124
|
-
|
|
237
|
+
public async getCheckpointedBlockByHash(blockHash: BlockHash): Promise<CheckpointedL2Block | undefined> {
|
|
238
|
+
for (const block of this.l2Blocks) {
|
|
239
|
+
const hash = await block.hash();
|
|
240
|
+
if (hash.equals(blockHash)) {
|
|
241
|
+
return this.toCheckpointedBlock(block);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return undefined;
|
|
125
245
|
}
|
|
126
246
|
|
|
127
|
-
public
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
blockNumber: BigInt(block.number),
|
|
134
|
-
blockHash: Buffer32.random().toString(),
|
|
135
|
-
timestamp: BigInt(block.number),
|
|
136
|
-
},
|
|
137
|
-
attestations: [],
|
|
138
|
-
}),
|
|
139
|
-
);
|
|
247
|
+
public getCheckpointedBlockByArchive(archive: Fr): Promise<CheckpointedL2Block | undefined> {
|
|
248
|
+
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
249
|
+
if (!block) {
|
|
250
|
+
return Promise.resolve(undefined);
|
|
251
|
+
}
|
|
252
|
+
return Promise.resolve(this.toCheckpointedBlock(block));
|
|
140
253
|
}
|
|
141
254
|
|
|
142
|
-
public async
|
|
255
|
+
public async getL2BlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
143
256
|
for (const block of this.l2Blocks) {
|
|
144
257
|
const hash = await block.hash();
|
|
145
258
|
if (hash.equals(blockHash)) {
|
|
146
|
-
return
|
|
147
|
-
block,
|
|
148
|
-
l1: {
|
|
149
|
-
blockNumber: BigInt(block.number),
|
|
150
|
-
blockHash: Buffer32.random().toString(),
|
|
151
|
-
timestamp: BigInt(block.number),
|
|
152
|
-
},
|
|
153
|
-
attestations: [],
|
|
154
|
-
});
|
|
259
|
+
return block;
|
|
155
260
|
}
|
|
156
261
|
}
|
|
157
262
|
return undefined;
|
|
158
263
|
}
|
|
159
264
|
|
|
160
|
-
public
|
|
265
|
+
public getL2BlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
161
266
|
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
162
|
-
|
|
163
|
-
return Promise.resolve(undefined);
|
|
164
|
-
}
|
|
165
|
-
return Promise.resolve(
|
|
166
|
-
PublishedL2Block.fromFields({
|
|
167
|
-
block,
|
|
168
|
-
l1: {
|
|
169
|
-
blockNumber: BigInt(block.number),
|
|
170
|
-
blockHash: Buffer32.random().toString(),
|
|
171
|
-
timestamp: BigInt(block.number),
|
|
172
|
-
},
|
|
173
|
-
attestations: [],
|
|
174
|
-
}),
|
|
175
|
-
);
|
|
267
|
+
return Promise.resolve(block);
|
|
176
268
|
}
|
|
177
269
|
|
|
178
|
-
public async getBlockHeaderByHash(blockHash:
|
|
270
|
+
public async getBlockHeaderByHash(blockHash: BlockHash): Promise<BlockHeader | undefined> {
|
|
179
271
|
for (const block of this.l2Blocks) {
|
|
180
272
|
const hash = await block.hash();
|
|
181
273
|
if (hash.equals(blockHash)) {
|
|
182
|
-
return block.
|
|
274
|
+
return block.header;
|
|
183
275
|
}
|
|
184
276
|
}
|
|
185
277
|
return undefined;
|
|
@@ -187,31 +279,80 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
187
279
|
|
|
188
280
|
public getBlockHeaderByArchive(archive: Fr): Promise<BlockHeader | undefined> {
|
|
189
281
|
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
190
|
-
return Promise.resolve(block?.
|
|
282
|
+
return Promise.resolve(block?.header);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
public async getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
|
|
286
|
+
const block = this.l2Blocks[number - 1];
|
|
287
|
+
if (!block) {
|
|
288
|
+
return undefined;
|
|
289
|
+
}
|
|
290
|
+
return {
|
|
291
|
+
header: block.header,
|
|
292
|
+
archive: block.archive,
|
|
293
|
+
blockHash: await block.hash(),
|
|
294
|
+
checkpointNumber: block.checkpointNumber,
|
|
295
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
public async getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
|
|
300
|
+
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
301
|
+
if (!block) {
|
|
302
|
+
return undefined;
|
|
303
|
+
}
|
|
304
|
+
return {
|
|
305
|
+
header: block.header,
|
|
306
|
+
archive: block.archive,
|
|
307
|
+
blockHash: await block.hash(),
|
|
308
|
+
checkpointNumber: block.checkpointNumber,
|
|
309
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
310
|
+
};
|
|
191
311
|
}
|
|
192
312
|
|
|
193
313
|
getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
|
|
194
|
-
return Promise.resolve(this.l2Blocks.at(typeof number === 'number' ? number - 1 : -1)?.
|
|
314
|
+
return Promise.resolve(this.l2Blocks.at(typeof number === 'number' ? number - 1 : -1)?.header);
|
|
195
315
|
}
|
|
196
316
|
|
|
197
317
|
getCheckpointsForEpoch(epochNumber: EpochNumber): Promise<Checkpoint[]> {
|
|
198
|
-
|
|
199
|
-
return this.getBlocksForEpoch(epochNumber).then(blocks => blocks.map(b => b.toCheckpoint()));
|
|
318
|
+
return Promise.resolve(this.getCheckpointsInEpoch(epochNumber));
|
|
200
319
|
}
|
|
201
320
|
|
|
202
|
-
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
321
|
+
getCheckpointsDataForEpoch(epochNumber: EpochNumber): Promise<CheckpointData[]> {
|
|
322
|
+
const checkpoints = this.getCheckpointsInEpoch(epochNumber);
|
|
323
|
+
return Promise.resolve(
|
|
324
|
+
checkpoints.map(
|
|
325
|
+
(checkpoint): CheckpointData => ({
|
|
326
|
+
checkpointNumber: checkpoint.number,
|
|
327
|
+
header: checkpoint.header,
|
|
328
|
+
archive: checkpoint.archive,
|
|
329
|
+
checkpointOutHash: computeCheckpointOutHash(
|
|
330
|
+
checkpoint.blocks.map(b => b.body.txEffects.map(tx => tx.l2ToL1Msgs)),
|
|
331
|
+
),
|
|
332
|
+
startBlock: checkpoint.blocks[0].number,
|
|
333
|
+
blockCount: checkpoint.blocks.length,
|
|
334
|
+
attestations: [],
|
|
335
|
+
l1: this.mockL1DataForCheckpoint(checkpoint),
|
|
336
|
+
}),
|
|
337
|
+
),
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
getCheckpointedBlocksForEpoch(epochNumber: EpochNumber): Promise<CheckpointedL2Block[]> {
|
|
342
|
+
const checkpoints = this.getCheckpointsInEpoch(epochNumber);
|
|
343
|
+
return Promise.resolve(
|
|
344
|
+
checkpoints.flatMap(checkpoint => checkpoint.blocks.map(block => this.toCheckpointedBlock(block))),
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
getBlocksForSlot(slotNumber: SlotNumber): Promise<L2Block[]> {
|
|
349
|
+
const blocks = this.l2Blocks.filter(b => b.header.globalVariables.slotNumber === slotNumber);
|
|
209
350
|
return Promise.resolve(blocks);
|
|
210
351
|
}
|
|
211
352
|
|
|
212
|
-
async
|
|
213
|
-
const
|
|
214
|
-
return
|
|
353
|
+
async getCheckpointedBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]> {
|
|
354
|
+
const checkpointedBlocks = await this.getCheckpointedBlocksForEpoch(epochNumber);
|
|
355
|
+
return checkpointedBlocks.map(b => b.block.header);
|
|
215
356
|
}
|
|
216
357
|
|
|
217
358
|
/**
|
|
@@ -230,7 +371,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
230
371
|
return {
|
|
231
372
|
data: txEffect,
|
|
232
373
|
l2BlockNumber: block.number,
|
|
233
|
-
l2BlockHash:
|
|
374
|
+
l2BlockHash: await block.hash(),
|
|
234
375
|
txIndexInBlock: block.body.txEffects.indexOf(txEffect),
|
|
235
376
|
};
|
|
236
377
|
}
|
|
@@ -244,12 +385,14 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
244
385
|
for (const block of this.l2Blocks) {
|
|
245
386
|
for (const txEffect of block.body.txEffects) {
|
|
246
387
|
if (txEffect.txHash.equals(txHash)) {
|
|
388
|
+
// In mock, assume all txs are checkpointed with successful execution
|
|
247
389
|
return new TxReceipt(
|
|
248
390
|
txHash,
|
|
249
|
-
TxStatus.
|
|
250
|
-
|
|
391
|
+
TxStatus.CHECKPOINTED,
|
|
392
|
+
TxExecutionResult.SUCCESS,
|
|
393
|
+
undefined,
|
|
251
394
|
txEffect.transactionFee.toBigInt(),
|
|
252
|
-
|
|
395
|
+
await block.hash(),
|
|
253
396
|
block.number,
|
|
254
397
|
);
|
|
255
398
|
}
|
|
@@ -259,37 +402,56 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
259
402
|
}
|
|
260
403
|
|
|
261
404
|
async getL2Tips(): Promise<L2Tips> {
|
|
262
|
-
const [latest, proven, finalized] = [
|
|
405
|
+
const [latest, proven, finalized, checkpointed] = [
|
|
263
406
|
await this.getBlockNumber(),
|
|
264
407
|
await this.getProvenBlockNumber(),
|
|
265
408
|
this.finalizedBlockNumber,
|
|
409
|
+
this.checkpointedBlockNumber,
|
|
266
410
|
] as const;
|
|
267
411
|
|
|
268
412
|
const latestBlock = this.l2Blocks[latest - 1];
|
|
269
413
|
const provenBlock = this.l2Blocks[proven - 1];
|
|
270
414
|
const finalizedBlock = this.l2Blocks[finalized - 1];
|
|
415
|
+
const checkpointedBlock = this.l2Blocks[checkpointed - 1];
|
|
271
416
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
417
|
+
const latestBlockId = {
|
|
418
|
+
number: BlockNumber(latest),
|
|
419
|
+
hash: (await latestBlock?.hash())?.toString(),
|
|
420
|
+
};
|
|
421
|
+
const provenBlockId = {
|
|
422
|
+
number: BlockNumber(proven),
|
|
423
|
+
hash: (await provenBlock?.hash())?.toString(),
|
|
424
|
+
};
|
|
425
|
+
const finalizedBlockId = {
|
|
426
|
+
number: BlockNumber(finalized),
|
|
427
|
+
hash: (await finalizedBlock?.hash())?.toString(),
|
|
428
|
+
};
|
|
429
|
+
const checkpointedBlockId = {
|
|
430
|
+
number: BlockNumber(checkpointed),
|
|
431
|
+
hash: (await checkpointedBlock?.hash())?.toString(),
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
const makeTipId = (blockId: typeof latestBlockId) => ({
|
|
435
|
+
block: blockId,
|
|
436
|
+
checkpoint: {
|
|
437
|
+
number: this.findCheckpointNumberForBlock(blockId.number) ?? CheckpointNumber(0),
|
|
438
|
+
hash: blockId.hash,
|
|
284
439
|
},
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
return {
|
|
443
|
+
proposed: latestBlockId,
|
|
444
|
+
checkpointed: makeTipId(checkpointedBlockId),
|
|
445
|
+
proven: makeTipId(provenBlockId),
|
|
446
|
+
finalized: makeTipId(finalizedBlockId),
|
|
285
447
|
};
|
|
286
448
|
}
|
|
287
449
|
|
|
288
|
-
|
|
450
|
+
getSyncedL2EpochNumber(): Promise<EpochNumber> {
|
|
289
451
|
throw new Error('Method not implemented.');
|
|
290
452
|
}
|
|
291
453
|
|
|
292
|
-
|
|
454
|
+
getSyncedL2SlotNumber(): Promise<SlotNumber> {
|
|
293
455
|
throw new Error('Method not implemented.');
|
|
294
456
|
}
|
|
295
457
|
|
|
@@ -359,7 +521,41 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
359
521
|
return Promise.resolve(false);
|
|
360
522
|
}
|
|
361
523
|
|
|
362
|
-
getPendingChainValidationStatus(): Promise<
|
|
524
|
+
getPendingChainValidationStatus(): Promise<ValidateCheckpointResult> {
|
|
363
525
|
return Promise.resolve({ valid: true });
|
|
364
526
|
}
|
|
527
|
+
|
|
528
|
+
/** Returns checkpoints whose slot falls within the given epoch. */
|
|
529
|
+
private getCheckpointsInEpoch(epochNumber: EpochNumber): Checkpoint[] {
|
|
530
|
+
const epochDuration = DefaultL1ContractsConfig.aztecEpochDuration;
|
|
531
|
+
const [start, end] = getSlotRangeForEpoch(epochNumber, { epochDuration });
|
|
532
|
+
return this.checkpointList.filter(c => c.header.slotNumber >= start && c.header.slotNumber <= end);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/** Creates a mock L1PublishedData for a checkpoint. */
|
|
536
|
+
private mockL1DataForCheckpoint(checkpoint: Checkpoint): L1PublishedData {
|
|
537
|
+
return new L1PublishedData(BigInt(checkpoint.number), BigInt(checkpoint.number), Buffer32.random().toString());
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/** Creates a CheckpointedL2Block from a block using stored checkpoint info. */
|
|
541
|
+
private toCheckpointedBlock(block: L2Block): CheckpointedL2Block {
|
|
542
|
+
const checkpoint = this.checkpointList.find(c => c.blocks.some(b => b.number === block.number));
|
|
543
|
+
const checkpointNumber = checkpoint?.number ?? block.checkpointNumber;
|
|
544
|
+
return new CheckpointedL2Block(
|
|
545
|
+
checkpointNumber,
|
|
546
|
+
block,
|
|
547
|
+
new L1PublishedData(
|
|
548
|
+
BigInt(block.number),
|
|
549
|
+
BigInt(block.number),
|
|
550
|
+
`0x${block.number.toString(16).padStart(64, '0')}`,
|
|
551
|
+
),
|
|
552
|
+
[],
|
|
553
|
+
);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/** Finds the checkpoint number for a block, or undefined if the block is not in any checkpoint. */
|
|
557
|
+
private findCheckpointNumberForBlock(blockNumber: BlockNumber): CheckpointNumber | undefined {
|
|
558
|
+
const checkpoint = this.checkpointList.find(c => c.blocks.some(b => b.number === blockNumber));
|
|
559
|
+
return checkpoint?.number;
|
|
560
|
+
}
|
|
365
561
|
}
|