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