@aztec/archiver 0.0.1-commit.7d4e6cd → 0.0.1-commit.7ffbba4
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 +141 -0
- package/dest/archiver.d.ts.map +1 -0
- package/dest/archiver.js +710 -0
- package/dest/{archiver/config.d.ts → config.d.ts} +9 -1
- package/dest/config.d.ts.map +1 -0
- package/dest/{archiver/config.js → config.js} +9 -0
- package/dest/errors.d.ts +41 -0
- package/dest/errors.d.ts.map +1 -0
- package/dest/{archiver/errors.js → errors.js} +8 -0
- package/dest/factory.d.ts +10 -8
- 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 +35 -32
- 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/{archiver/l1 → l1}/data_retrieval.js +54 -71
- 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 +13 -9
- 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 +331 -0
- package/dest/modules/instrumentation.d.ts +50 -0
- package/dest/modules/instrumentation.d.ts.map +1 -0
- package/dest/{archiver → modules}/instrumentation.js +36 -12
- 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 +1119 -0
- package/dest/{archiver → modules}/validation.d.ts +1 -1
- package/dest/modules/validation.d.ts.map +1 -0
- package/dest/{archiver → modules}/validation.js +6 -0
- package/dest/store/block_store.d.ts +196 -0
- package/dest/store/block_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/block_store.js +207 -60
- 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 +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/{archiver/kv_archiver_store → store}/log_store.js +146 -91
- 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/{archiver/structs → structs}/published.d.ts +1 -1
- 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_l2_block_source.d.ts +36 -17
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +180 -74
- 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 +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 +16 -17
- package/src/archiver.ts +466 -0
- package/src/{archiver/config.ts → config.ts} +11 -0
- package/src/{archiver/errors.ts → errors.ts} +12 -0
- package/src/factory.ts +143 -12
- 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 +45 -33
- package/src/l1/calldata_retriever.ts +511 -0
- package/src/{archiver/l1 → l1}/data_retrieval.ts +75 -94
- package/src/{archiver/l1 → l1}/spire_proposer.ts +7 -15
- package/src/{archiver/l1 → l1}/validate_trace.ts +24 -6
- package/src/modules/data_source_base.ts +328 -0
- package/src/modules/data_store_updater.ts +453 -0
- package/src/{archiver → modules}/instrumentation.ts +46 -14
- package/src/modules/l1_synchronizer.ts +939 -0
- package/src/{archiver → modules}/validation.ts +5 -0
- package/src/{archiver/kv_archiver_store → store}/block_store.ts +258 -93
- 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/{archiver/kv_archiver_store → store}/kv_archiver_store.ts +267 -38
- package/src/store/l2_tips_cache.ts +89 -0
- package/src/{archiver/kv_archiver_store → store}/log_store.ts +242 -121
- package/src/{archiver/kv_archiver_store → store}/message_store.ts +1 -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_l2_block_source.ts +224 -90
- package/src/test/mock_structs.ts +283 -8
- package/src/test/noop_l1_archiver.ts +109 -0
- package/dest/archiver/archiver.d.ts +0 -307
- package/dest/archiver/archiver.d.ts.map +0 -1
- package/dest/archiver/archiver.js +0 -2102
- package/dest/archiver/archiver_store.d.ts +0 -315
- 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 -2770
- package/dest/archiver/config.d.ts.map +0 -1
- package/dest/archiver/errors.d.ts +0 -36
- package/dest/archiver/errors.d.ts.map +0 -1
- 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 -164
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
- 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 -159
- 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 -316
- package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -45
- package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
- 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 -112
- package/dest/archiver/l1/calldata_retriever.d.ts.map +0 -1
- package/dest/archiver/l1/calldata_retriever.js +0 -471
- package/dest/archiver/l1/data_retrieval.d.ts +0 -90
- 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.map +0 -1
- 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 -2265
- package/src/archiver/archiver_store.ts +0 -380
- package/src/archiver/archiver_store_test_suite.ts +0 -2842
- package/src/archiver/index.ts +0 -6
- package/src/archiver/l1/README.md +0 -98
- package/src/archiver/l1/calldata_retriever.ts +0 -641
- 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
- /package/src/{archiver/structs → structs}/published.ts +0 -0
|
@@ -8,19 +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,
|
|
11
13
|
CheckpointedL2Block,
|
|
12
14
|
L2Block,
|
|
13
|
-
L2BlockHash,
|
|
14
|
-
L2BlockNew,
|
|
15
15
|
type L2BlockSource,
|
|
16
16
|
type L2Tips,
|
|
17
|
-
PublishedL2Block,
|
|
18
17
|
type ValidateCheckpointResult,
|
|
19
18
|
} from '@aztec/stdlib/block';
|
|
20
|
-
import { type
|
|
19
|
+
import { Checkpoint, type CheckpointData, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
21
20
|
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
22
21
|
import { EmptyL1RollupConstants, type L1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
23
|
-
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';
|
|
24
25
|
import type { UInt64 } from '@aztec/stdlib/types';
|
|
25
26
|
|
|
26
27
|
/**
|
|
@@ -28,6 +29,7 @@ import type { UInt64 } from '@aztec/stdlib/types';
|
|
|
28
29
|
*/
|
|
29
30
|
export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
30
31
|
protected l2Blocks: L2Block[] = [];
|
|
32
|
+
protected checkpointList: Checkpoint[] = [];
|
|
31
33
|
|
|
32
34
|
private provenBlockNumber: number = 0;
|
|
33
35
|
private finalizedBlockNumber: number = 0;
|
|
@@ -35,23 +37,55 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
35
37
|
|
|
36
38
|
private log = createLogger('archiver:mock_l2_block_source');
|
|
37
39
|
|
|
40
|
+
/** Creates blocks grouped into single-block checkpoints. */
|
|
38
41
|
public async createBlocks(numBlocks: number) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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);
|
|
43
65
|
}
|
|
44
66
|
|
|
45
|
-
this.log.verbose(
|
|
67
|
+
this.log.verbose(
|
|
68
|
+
`Created ${numCheckpoints} checkpoints with ${blocksPerCheckpoint} blocks each in the mock L2 block source`,
|
|
69
|
+
);
|
|
46
70
|
}
|
|
47
71
|
|
|
48
|
-
public
|
|
72
|
+
public addProposedBlocks(blocks: L2Block[]) {
|
|
49
73
|
this.l2Blocks.push(...blocks);
|
|
50
|
-
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`);
|
|
51
75
|
}
|
|
52
76
|
|
|
53
77
|
public removeBlocks(numBlocks: number) {
|
|
54
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);
|
|
55
89
|
this.log.verbose(`Removed ${numBlocks} blocks from the mock L2 block source`);
|
|
56
90
|
}
|
|
57
91
|
|
|
@@ -67,7 +101,33 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
67
101
|
}
|
|
68
102
|
|
|
69
103
|
public setCheckpointedBlockNumber(checkpointedBlockNumber: number) {
|
|
104
|
+
const prevCheckpointed = this.checkpointedBlockNumber;
|
|
70
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
|
+
}
|
|
71
131
|
}
|
|
72
132
|
|
|
73
133
|
/**
|
|
@@ -98,6 +158,14 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
98
158
|
return Promise.resolve(BlockNumber(this.provenBlockNumber));
|
|
99
159
|
}
|
|
100
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
|
+
|
|
101
169
|
public getCheckpointedBlock(number: BlockNumber): Promise<CheckpointedL2Block | undefined> {
|
|
102
170
|
if (number > this.checkpointedBlockNumber) {
|
|
103
171
|
return Promise.resolve(undefined);
|
|
@@ -106,20 +174,10 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
106
174
|
if (!block) {
|
|
107
175
|
return Promise.resolve(undefined);
|
|
108
176
|
}
|
|
109
|
-
|
|
110
|
-
CheckpointNumber(number),
|
|
111
|
-
block.toL2Block(),
|
|
112
|
-
new L1PublishedData(BigInt(number), BigInt(number), `0x${number.toString(16).padStart(64, '0')}`),
|
|
113
|
-
[],
|
|
114
|
-
);
|
|
115
|
-
return Promise.resolve(checkpointedBlock);
|
|
177
|
+
return Promise.resolve(this.toCheckpointedBlock(block));
|
|
116
178
|
}
|
|
117
179
|
|
|
118
|
-
public async getCheckpointedBlocks(
|
|
119
|
-
from: BlockNumber,
|
|
120
|
-
limit: number,
|
|
121
|
-
_proven?: boolean,
|
|
122
|
-
): Promise<CheckpointedL2Block[]> {
|
|
180
|
+
public async getCheckpointedBlocks(from: BlockNumber, limit: number): Promise<CheckpointedL2Block[]> {
|
|
123
181
|
const result: CheckpointedL2Block[] = [];
|
|
124
182
|
for (let i = 0; i < limit; i++) {
|
|
125
183
|
const blockNum = from + i;
|
|
@@ -139,8 +197,9 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
139
197
|
* @param number - The block number to return (inclusive).
|
|
140
198
|
* @returns The requested L2 block.
|
|
141
199
|
*/
|
|
142
|
-
public getBlock(number: number) {
|
|
143
|
-
|
|
200
|
+
public getBlock(number: number): Promise<L2Block | undefined> {
|
|
201
|
+
const block = this.l2Blocks[number - 1];
|
|
202
|
+
return Promise.resolve(block);
|
|
144
203
|
}
|
|
145
204
|
|
|
146
205
|
/**
|
|
@@ -148,9 +207,9 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
148
207
|
* @param number - The block number to return.
|
|
149
208
|
* @returns The requested L2 block.
|
|
150
209
|
*/
|
|
151
|
-
public
|
|
210
|
+
public getL2Block(number: BlockNumber): Promise<L2Block | undefined> {
|
|
152
211
|
const block = this.l2Blocks[number - 1];
|
|
153
|
-
return Promise.resolve(block
|
|
212
|
+
return Promise.resolve(block);
|
|
154
213
|
}
|
|
155
214
|
|
|
156
215
|
/**
|
|
@@ -159,73 +218,60 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
159
218
|
* @param limit - The maximum number of blocks to return.
|
|
160
219
|
* @returns The requested mocked L2 blocks.
|
|
161
220
|
*/
|
|
162
|
-
public getBlocks(from: number, limit: number
|
|
163
|
-
return Promise.resolve(
|
|
164
|
-
this.l2Blocks
|
|
165
|
-
.slice(from - 1, from - 1 + limit)
|
|
166
|
-
.filter(b => !proven || this.provenBlockNumber === undefined || b.number <= this.provenBlockNumber),
|
|
167
|
-
);
|
|
221
|
+
public getBlocks(from: number, limit: number): Promise<L2Block[]> {
|
|
222
|
+
return Promise.resolve(this.l2Blocks.slice(from - 1, from - 1 + limit));
|
|
168
223
|
}
|
|
169
224
|
|
|
170
|
-
public
|
|
171
|
-
|
|
172
|
-
return
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
public async getCheckpointByArchive(archive: Fr): Promise<Checkpoint | undefined> {
|
|
176
|
-
// TODO: Implement this properly. This only works when we have one block per checkpoint.
|
|
177
|
-
return (await this.getPublishedBlockByArchive(archive))?.block.toCheckpoint();
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
public async getPublishedBlocks(from: number, limit: number, proven?: boolean) {
|
|
181
|
-
const blocks = await this.getBlocks(from, limit, proven);
|
|
182
|
-
return blocks.map(block =>
|
|
183
|
-
PublishedL2Block.fromFields({
|
|
184
|
-
block,
|
|
185
|
-
l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
|
|
186
|
-
attestations: [],
|
|
187
|
-
}),
|
|
225
|
+
public getCheckpoints(from: CheckpointNumber, limit: number) {
|
|
226
|
+
const checkpoints = this.checkpointList.slice(from - 1, from - 1 + limit);
|
|
227
|
+
return Promise.resolve(
|
|
228
|
+
checkpoints.map(checkpoint => new PublishedCheckpoint(checkpoint, this.mockL1DataForCheckpoint(checkpoint), [])),
|
|
188
229
|
);
|
|
189
230
|
}
|
|
190
231
|
|
|
191
|
-
|
|
192
|
-
const
|
|
193
|
-
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);
|
|
194
235
|
}
|
|
195
236
|
|
|
196
|
-
public async
|
|
237
|
+
public async getCheckpointedBlockByHash(blockHash: BlockHash): Promise<CheckpointedL2Block | undefined> {
|
|
197
238
|
for (const block of this.l2Blocks) {
|
|
198
239
|
const hash = await block.hash();
|
|
199
240
|
if (hash.equals(blockHash)) {
|
|
200
|
-
return
|
|
201
|
-
block,
|
|
202
|
-
l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
|
|
203
|
-
attestations: [],
|
|
204
|
-
});
|
|
241
|
+
return this.toCheckpointedBlock(block);
|
|
205
242
|
}
|
|
206
243
|
}
|
|
207
244
|
return undefined;
|
|
208
245
|
}
|
|
209
246
|
|
|
210
|
-
public
|
|
247
|
+
public getCheckpointedBlockByArchive(archive: Fr): Promise<CheckpointedL2Block | undefined> {
|
|
211
248
|
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
212
249
|
if (!block) {
|
|
213
250
|
return Promise.resolve(undefined);
|
|
214
251
|
}
|
|
215
|
-
return Promise.resolve(
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
252
|
+
return Promise.resolve(this.toCheckpointedBlock(block));
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
public async getL2BlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
256
|
+
for (const block of this.l2Blocks) {
|
|
257
|
+
const hash = await block.hash();
|
|
258
|
+
if (hash.equals(blockHash)) {
|
|
259
|
+
return block;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return undefined;
|
|
222
263
|
}
|
|
223
264
|
|
|
224
|
-
public
|
|
265
|
+
public getL2BlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
266
|
+
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
267
|
+
return Promise.resolve(block);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
public async getBlockHeaderByHash(blockHash: BlockHash): Promise<BlockHeader | undefined> {
|
|
225
271
|
for (const block of this.l2Blocks) {
|
|
226
272
|
const hash = await block.hash();
|
|
227
273
|
if (hash.equals(blockHash)) {
|
|
228
|
-
return block.
|
|
274
|
+
return block.header;
|
|
229
275
|
}
|
|
230
276
|
}
|
|
231
277
|
return undefined;
|
|
@@ -233,31 +279,80 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
233
279
|
|
|
234
280
|
public getBlockHeaderByArchive(archive: Fr): Promise<BlockHeader | undefined> {
|
|
235
281
|
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
236
|
-
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
|
+
};
|
|
237
311
|
}
|
|
238
312
|
|
|
239
313
|
getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
|
|
240
|
-
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);
|
|
241
315
|
}
|
|
242
316
|
|
|
243
317
|
getCheckpointsForEpoch(epochNumber: EpochNumber): Promise<Checkpoint[]> {
|
|
244
|
-
|
|
245
|
-
return this.getBlocksForEpoch(epochNumber).then(blocks => blocks.map(b => b.toCheckpoint()));
|
|
318
|
+
return Promise.resolve(this.getCheckpointsInEpoch(epochNumber));
|
|
246
319
|
}
|
|
247
320
|
|
|
248
|
-
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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);
|
|
255
350
|
return Promise.resolve(blocks);
|
|
256
351
|
}
|
|
257
352
|
|
|
258
|
-
async
|
|
259
|
-
const
|
|
260
|
-
return
|
|
353
|
+
async getCheckpointedBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]> {
|
|
354
|
+
const checkpointedBlocks = await this.getCheckpointedBlocksForEpoch(epochNumber);
|
|
355
|
+
return checkpointedBlocks.map(b => b.block.header);
|
|
261
356
|
}
|
|
262
357
|
|
|
263
358
|
/**
|
|
@@ -276,7 +371,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
276
371
|
return {
|
|
277
372
|
data: txEffect,
|
|
278
373
|
l2BlockNumber: block.number,
|
|
279
|
-
l2BlockHash:
|
|
374
|
+
l2BlockHash: await block.hash(),
|
|
280
375
|
txIndexInBlock: block.body.txEffects.indexOf(txEffect),
|
|
281
376
|
};
|
|
282
377
|
}
|
|
@@ -290,12 +385,14 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
290
385
|
for (const block of this.l2Blocks) {
|
|
291
386
|
for (const txEffect of block.body.txEffects) {
|
|
292
387
|
if (txEffect.txHash.equals(txHash)) {
|
|
388
|
+
// In mock, assume all txs are checkpointed with successful execution
|
|
293
389
|
return new TxReceipt(
|
|
294
390
|
txHash,
|
|
295
|
-
TxStatus.
|
|
296
|
-
|
|
391
|
+
TxStatus.CHECKPOINTED,
|
|
392
|
+
TxExecutionResult.SUCCESS,
|
|
393
|
+
undefined,
|
|
297
394
|
txEffect.transactionFee.toBigInt(),
|
|
298
|
-
|
|
395
|
+
await block.hash(),
|
|
299
396
|
block.number,
|
|
300
397
|
);
|
|
301
398
|
}
|
|
@@ -336,7 +433,10 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
336
433
|
|
|
337
434
|
const makeTipId = (blockId: typeof latestBlockId) => ({
|
|
338
435
|
block: blockId,
|
|
339
|
-
checkpoint: {
|
|
436
|
+
checkpoint: {
|
|
437
|
+
number: this.findCheckpointNumberForBlock(blockId.number) ?? CheckpointNumber(0),
|
|
438
|
+
hash: blockId.hash,
|
|
439
|
+
},
|
|
340
440
|
});
|
|
341
441
|
|
|
342
442
|
return {
|
|
@@ -424,4 +524,38 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
424
524
|
getPendingChainValidationStatus(): Promise<ValidateCheckpointResult> {
|
|
425
525
|
return Promise.resolve({ valid: true });
|
|
426
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
|
+
}
|
|
427
561
|
}
|