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