@aztec/archiver 0.0.1-commit.fce3e4f → 0.0.1-commit.fffb133c
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 +135 -0
- package/dest/archiver.d.ts.map +1 -0
- package/dest/archiver.js +768 -0
- package/dest/config.d.ts +30 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/{archiver/config.js → config.js} +21 -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 +7 -7
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +90 -10
- package/dest/index.d.ts +10 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +8 -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 +149 -0
- package/dest/l1/calldata_retriever.d.ts +112 -0
- package/dest/l1/calldata_retriever.d.ts.map +1 -0
- package/dest/l1/calldata_retriever.js +471 -0
- package/dest/l1/data_retrieval.d.ts +88 -0
- package/dest/l1/data_retrieval.d.ts.map +1 -0
- package/dest/{archiver → l1}/data_retrieval.js +76 -150
- 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 +29 -0
- package/dest/l1/validate_trace.d.ts.map +1 -0
- package/dest/l1/validate_trace.js +150 -0
- package/dest/modules/data_source_base.d.ts +84 -0
- package/dest/modules/data_source_base.d.ts.map +1 -0
- package/dest/modules/data_source_base.js +260 -0
- package/dest/modules/data_store_updater.d.ts +73 -0
- package/dest/modules/data_store_updater.d.ts.map +1 -0
- package/dest/modules/data_store_updater.js +302 -0
- package/dest/modules/instrumentation.d.ts +37 -0
- package/dest/modules/instrumentation.d.ts.map +1 -0
- package/dest/{archiver → modules}/instrumentation.js +22 -59
- package/dest/modules/l1_synchronizer.d.ts +75 -0
- package/dest/modules/l1_synchronizer.d.ts.map +1 -0
- package/dest/modules/l1_synchronizer.js +1113 -0
- package/dest/modules/validation.d.ts +17 -0
- package/dest/modules/validation.d.ts.map +1 -0
- package/dest/{archiver → modules}/validation.js +7 -1
- package/dest/store/block_store.d.ts +192 -0
- package/dest/store/block_store.d.ts.map +1 -0
- package/dest/store/block_store.js +721 -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 +2 -2
- 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 +340 -0
- package/dest/store/kv_archiver_store.d.ts.map +1 -0
- package/dest/store/kv_archiver_store.js +447 -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 +436 -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/{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}/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 +190 -0
- package/dest/test/fake_l1_state.d.ts.map +1 -0
- package/dest/test/fake_l1_state.js +383 -0
- package/dest/test/index.d.ts +2 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +1 -0
- 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 +18 -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 +34 -16
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +179 -59
- package/dest/test/mock_structs.d.ts +78 -3
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +141 -9
- package/package.json +19 -20
- package/src/archiver.ts +523 -0
- package/src/{archiver/config.ts → config.ts} +28 -12
- package/src/errors.ts +102 -0
- package/src/factory.ts +125 -10
- package/src/index.ts +10 -3
- package/src/interfaces.ts +9 -0
- package/src/l1/README.md +98 -0
- package/src/l1/bin/retrieve-calldata.ts +187 -0
- package/src/l1/calldata_retriever.ts +641 -0
- package/src/{archiver → l1}/data_retrieval.ts +142 -223
- 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 +211 -0
- package/src/modules/data_source_base.ts +367 -0
- package/src/modules/data_store_updater.ts +423 -0
- package/src/{archiver → modules}/instrumentation.ts +26 -61
- package/src/modules/l1_synchronizer.ts +931 -0
- package/src/{archiver → modules}/validation.ts +11 -6
- package/src/store/block_store.ts +966 -0
- package/src/{archiver/kv_archiver_store → store}/contract_class_store.ts +2 -2
- package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +2 -2
- package/src/store/kv_archiver_store.ts +639 -0
- package/src/store/log_store.ts +575 -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/{archiver/structs → structs}/published.ts +0 -1
- package/src/test/fake_l1_state.ts +599 -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 +1 -0
- package/src/test/mock_archiver.ts +22 -16
- package/src/test/mock_l1_to_l2_message_source.ts +18 -11
- package/src/test/mock_l2_block_source.ts +195 -69
- package/src/test/mock_structs.ts +256 -10
- package/dest/archiver/archiver.d.ts +0 -287
- package/dest/archiver/archiver.d.ts.map +0 -1
- package/dest/archiver/archiver.js +0 -1408
- 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 -1289
- 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 -79
- package/dest/archiver/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/errors.d.ts +0 -12
- package/dest/archiver/errors.d.ts.map +0 -1
- package/dest/archiver/errors.js +0 -17
- package/dest/archiver/index.d.ts +0 -7
- package/dest/archiver/index.d.ts.map +0 -1
- package/dest/archiver/index.js +0 -4
- package/dest/archiver/instrumentation.d.ts +0 -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.map +0 -1
- package/dest/archiver/structs/inbox_message.d.ts +0 -15
- package/dest/archiver/structs/inbox_message.d.ts.map +0 -1
- package/dest/archiver/structs/published.d.ts +0 -3
- package/dest/archiver/structs/published.d.ts.map +0 -1
- package/dest/archiver/validation.d.ts +0 -17
- package/dest/archiver/validation.d.ts.map +0 -1
- package/dest/rpc/index.d.ts +0 -9
- package/dest/rpc/index.d.ts.map +0 -1
- package/dest/rpc/index.js +0 -15
- package/src/archiver/archiver.ts +0 -1858
- package/src/archiver/archiver_store.ts +0 -305
- package/src/archiver/archiver_store_test_suite.ts +0 -1264
- 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/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,23 +1,24 @@
|
|
|
1
1
|
import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
|
|
2
|
-
import { DefaultL1ContractsConfig } from '@aztec/ethereum';
|
|
3
|
-
import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { DefaultL1ContractsConfig } from '@aztec/ethereum/config';
|
|
3
|
+
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
4
4
|
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
5
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
6
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
6
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
7
7
|
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
|
+
CheckpointedL2Block,
|
|
11
12
|
L2Block,
|
|
12
13
|
L2BlockHash,
|
|
13
14
|
type L2BlockSource,
|
|
14
15
|
type L2Tips,
|
|
15
|
-
|
|
16
|
-
type ValidateBlockResult,
|
|
16
|
+
type ValidateCheckpointResult,
|
|
17
17
|
} from '@aztec/stdlib/block';
|
|
18
|
+
import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
18
19
|
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
19
20
|
import { EmptyL1RollupConstants, type L1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
20
|
-
import { type BlockHeader, TxHash, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
21
|
+
import { type BlockHeader, TxExecutionResult, TxHash, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
21
22
|
import type { UInt64 } from '@aztec/stdlib/types';
|
|
22
23
|
|
|
23
24
|
/**
|
|
@@ -28,22 +29,23 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
28
29
|
|
|
29
30
|
private provenBlockNumber: number = 0;
|
|
30
31
|
private finalizedBlockNumber: number = 0;
|
|
32
|
+
private checkpointedBlockNumber: number = 0;
|
|
31
33
|
|
|
32
34
|
private log = createLogger('archiver:mock_l2_block_source');
|
|
33
35
|
|
|
34
36
|
public async createBlocks(numBlocks: number) {
|
|
35
37
|
for (let i = 0; i < numBlocks; i++) {
|
|
36
38
|
const blockNum = this.l2Blocks.length + 1;
|
|
37
|
-
const block = await L2Block.random(blockNum);
|
|
39
|
+
const block = await L2Block.random(BlockNumber(blockNum), { slotNumber: SlotNumber(blockNum) });
|
|
38
40
|
this.l2Blocks.push(block);
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
this.log.verbose(`Created ${numBlocks} blocks in the mock L2 block source`);
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
public
|
|
46
|
+
public addProposedBlocks(blocks: L2Block[]) {
|
|
45
47
|
this.l2Blocks.push(...blocks);
|
|
46
|
-
this.log.verbose(`Added ${blocks.length} blocks to the mock L2 block source`);
|
|
48
|
+
this.log.verbose(`Added ${blocks.length} proposed blocks to the mock L2 block source`);
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
public removeBlocks(numBlocks: number) {
|
|
@@ -62,6 +64,10 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
62
64
|
this.finalizedBlockNumber = finalizedBlockNumber;
|
|
63
65
|
}
|
|
64
66
|
|
|
67
|
+
public setCheckpointedBlockNumber(checkpointedBlockNumber: number) {
|
|
68
|
+
this.checkpointedBlockNumber = checkpointedBlockNumber;
|
|
69
|
+
}
|
|
70
|
+
|
|
65
71
|
/**
|
|
66
72
|
* Method to fetch the rollup contract address at the base-layer.
|
|
67
73
|
* @returns The rollup address.
|
|
@@ -83,11 +89,51 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
83
89
|
* @returns In this mock instance, returns the number of L2 blocks that we've mocked.
|
|
84
90
|
*/
|
|
85
91
|
public getBlockNumber() {
|
|
86
|
-
return Promise.resolve(this.l2Blocks.length);
|
|
92
|
+
return Promise.resolve(BlockNumber(this.l2Blocks.length));
|
|
87
93
|
}
|
|
88
94
|
|
|
89
|
-
public getProvenBlockNumber()
|
|
90
|
-
return Promise.resolve(this.provenBlockNumber);
|
|
95
|
+
public getProvenBlockNumber() {
|
|
96
|
+
return Promise.resolve(BlockNumber(this.provenBlockNumber));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public getCheckpointedL2BlockNumber() {
|
|
100
|
+
return Promise.resolve(BlockNumber(this.checkpointedBlockNumber));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public getFinalizedL2BlockNumber() {
|
|
104
|
+
return Promise.resolve(BlockNumber(this.finalizedBlockNumber));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public getCheckpointedBlock(number: BlockNumber): Promise<CheckpointedL2Block | undefined> {
|
|
108
|
+
if (number > this.checkpointedBlockNumber) {
|
|
109
|
+
return Promise.resolve(undefined);
|
|
110
|
+
}
|
|
111
|
+
const block = this.l2Blocks[number - 1];
|
|
112
|
+
if (!block) {
|
|
113
|
+
return Promise.resolve(undefined);
|
|
114
|
+
}
|
|
115
|
+
const checkpointedBlock = new CheckpointedL2Block(
|
|
116
|
+
CheckpointNumber.fromBlockNumber(number),
|
|
117
|
+
block,
|
|
118
|
+
new L1PublishedData(BigInt(number), BigInt(number), `0x${number.toString(16).padStart(64, '0')}`),
|
|
119
|
+
[],
|
|
120
|
+
);
|
|
121
|
+
return Promise.resolve(checkpointedBlock);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
public async getCheckpointedBlocks(from: BlockNumber, limit: number): Promise<CheckpointedL2Block[]> {
|
|
125
|
+
const result: CheckpointedL2Block[] = [];
|
|
126
|
+
for (let i = 0; i < limit; i++) {
|
|
127
|
+
const blockNum = from + i;
|
|
128
|
+
if (blockNum > this.checkpointedBlockNumber) {
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
const block = await this.getCheckpointedBlock(BlockNumber(blockNum));
|
|
132
|
+
if (block) {
|
|
133
|
+
result.push(block);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
91
137
|
}
|
|
92
138
|
|
|
93
139
|
/**
|
|
@@ -95,8 +141,19 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
95
141
|
* @param number - The block number to return (inclusive).
|
|
96
142
|
* @returns The requested L2 block.
|
|
97
143
|
*/
|
|
98
|
-
public getBlock(number: number) {
|
|
99
|
-
|
|
144
|
+
public getBlock(number: number): Promise<L2Block | undefined> {
|
|
145
|
+
const block = this.l2Blocks[number - 1];
|
|
146
|
+
return Promise.resolve(block);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Gets an L2 block (new format).
|
|
151
|
+
* @param number - The block number to return.
|
|
152
|
+
* @returns The requested L2 block.
|
|
153
|
+
*/
|
|
154
|
+
public getL2Block(number: BlockNumber): Promise<L2Block | undefined> {
|
|
155
|
+
const block = this.l2Blocks[number - 1];
|
|
156
|
+
return Promise.resolve(block);
|
|
100
157
|
}
|
|
101
158
|
|
|
102
159
|
/**
|
|
@@ -105,40 +162,47 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
105
162
|
* @param limit - The maximum number of blocks to return.
|
|
106
163
|
* @returns The requested mocked L2 blocks.
|
|
107
164
|
*/
|
|
108
|
-
public getBlocks(from: number, limit: number
|
|
109
|
-
return Promise.resolve(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
165
|
+
public getBlocks(from: number, limit: number): Promise<L2Block[]> {
|
|
166
|
+
return Promise.resolve(this.l2Blocks.slice(from - 1, from - 1 + limit));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
public getCheckpoints(from: CheckpointNumber, limit: number) {
|
|
170
|
+
// TODO(mbps): Implement this properly. This only works when we have one block per checkpoint.
|
|
171
|
+
const blocks = this.l2Blocks.slice(from - 1, from - 1 + limit);
|
|
172
|
+
return Promise.all(
|
|
173
|
+
blocks.map(async block => {
|
|
174
|
+
// Create a checkpoint from the block - manually construct since L2Block doesn't have toCheckpoint()
|
|
175
|
+
const checkpoint = await Checkpoint.random(block.checkpointNumber, { numBlocks: 1 });
|
|
176
|
+
checkpoint.blocks = [block];
|
|
177
|
+
return new PublishedCheckpoint(
|
|
178
|
+
checkpoint,
|
|
179
|
+
new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
|
|
180
|
+
[],
|
|
181
|
+
);
|
|
182
|
+
}),
|
|
113
183
|
);
|
|
114
184
|
}
|
|
115
185
|
|
|
116
|
-
public async
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
attestations: [],
|
|
127
|
-
}),
|
|
128
|
-
);
|
|
186
|
+
public async getCheckpointByArchive(archive: Fr): Promise<Checkpoint | undefined> {
|
|
187
|
+
// TODO(mbps): Implement this properly. This only works when we have one block per checkpoint.
|
|
188
|
+
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
189
|
+
if (!block) {
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
|
192
|
+
// Create a checkpoint from the block - manually construct since L2Block doesn't have toCheckpoint()
|
|
193
|
+
const checkpoint = await Checkpoint.random(block.checkpointNumber, { numBlocks: 1 });
|
|
194
|
+
checkpoint.blocks = [block];
|
|
195
|
+
return checkpoint;
|
|
129
196
|
}
|
|
130
197
|
|
|
131
|
-
public async
|
|
198
|
+
public async getCheckpointedBlockByHash(blockHash: Fr): Promise<CheckpointedL2Block | undefined> {
|
|
132
199
|
for (const block of this.l2Blocks) {
|
|
133
200
|
const hash = await block.hash();
|
|
134
201
|
if (hash.equals(blockHash)) {
|
|
135
|
-
return
|
|
202
|
+
return CheckpointedL2Block.fromFields({
|
|
203
|
+
checkpointNumber: CheckpointNumber.fromBlockNumber(block.number),
|
|
136
204
|
block,
|
|
137
|
-
l1:
|
|
138
|
-
blockNumber: BigInt(block.number),
|
|
139
|
-
blockHash: Buffer32.random().toString(),
|
|
140
|
-
timestamp: BigInt(block.number),
|
|
141
|
-
},
|
|
205
|
+
l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
|
|
142
206
|
attestations: [],
|
|
143
207
|
});
|
|
144
208
|
}
|
|
@@ -146,29 +210,41 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
146
210
|
return undefined;
|
|
147
211
|
}
|
|
148
212
|
|
|
149
|
-
public
|
|
213
|
+
public getCheckpointedBlockByArchive(archive: Fr): Promise<CheckpointedL2Block | undefined> {
|
|
150
214
|
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
151
215
|
if (!block) {
|
|
152
216
|
return Promise.resolve(undefined);
|
|
153
217
|
}
|
|
154
218
|
return Promise.resolve(
|
|
155
|
-
|
|
219
|
+
CheckpointedL2Block.fromFields({
|
|
220
|
+
checkpointNumber: CheckpointNumber.fromBlockNumber(block.number),
|
|
156
221
|
block,
|
|
157
|
-
l1:
|
|
158
|
-
blockNumber: BigInt(block.number),
|
|
159
|
-
blockHash: Buffer32.random().toString(),
|
|
160
|
-
timestamp: BigInt(block.number),
|
|
161
|
-
},
|
|
222
|
+
l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
|
|
162
223
|
attestations: [],
|
|
163
224
|
}),
|
|
164
225
|
);
|
|
165
226
|
}
|
|
166
227
|
|
|
228
|
+
public async getL2BlockByHash(blockHash: Fr): Promise<L2Block | undefined> {
|
|
229
|
+
for (const block of this.l2Blocks) {
|
|
230
|
+
const hash = await block.hash();
|
|
231
|
+
if (hash.equals(blockHash)) {
|
|
232
|
+
return block;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return undefined;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
public getL2BlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
239
|
+
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
240
|
+
return Promise.resolve(block);
|
|
241
|
+
}
|
|
242
|
+
|
|
167
243
|
public async getBlockHeaderByHash(blockHash: Fr): Promise<BlockHeader | undefined> {
|
|
168
244
|
for (const block of this.l2Blocks) {
|
|
169
245
|
const hash = await block.hash();
|
|
170
246
|
if (hash.equals(blockHash)) {
|
|
171
|
-
return block.
|
|
247
|
+
return block.header;
|
|
172
248
|
}
|
|
173
249
|
}
|
|
174
250
|
return undefined;
|
|
@@ -176,26 +252,58 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
176
252
|
|
|
177
253
|
public getBlockHeaderByArchive(archive: Fr): Promise<BlockHeader | undefined> {
|
|
178
254
|
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
179
|
-
return Promise.resolve(block?.
|
|
255
|
+
return Promise.resolve(block?.header);
|
|
180
256
|
}
|
|
181
257
|
|
|
182
258
|
getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
|
|
183
|
-
return Promise.resolve(this.l2Blocks.at(typeof number === 'number' ? number - 1 : -1)?.
|
|
259
|
+
return Promise.resolve(this.l2Blocks.at(typeof number === 'number' ? number - 1 : -1)?.header);
|
|
184
260
|
}
|
|
185
261
|
|
|
186
|
-
|
|
262
|
+
getCheckpointsForEpoch(epochNumber: EpochNumber): Promise<Checkpoint[]> {
|
|
263
|
+
// TODO(mbps): Implement this properly. This only works when we have one block per checkpoint.
|
|
187
264
|
const epochDuration = DefaultL1ContractsConfig.aztecEpochDuration;
|
|
188
265
|
const [start, end] = getSlotRangeForEpoch(epochNumber, { epochDuration });
|
|
189
266
|
const blocks = this.l2Blocks.filter(b => {
|
|
190
267
|
const slot = b.header.globalVariables.slotNumber;
|
|
191
268
|
return slot >= start && slot <= end;
|
|
192
269
|
});
|
|
270
|
+
// Create checkpoints from blocks - manually construct since L2Block doesn't have toCheckpoint()
|
|
271
|
+
return Promise.all(
|
|
272
|
+
blocks.map(async block => {
|
|
273
|
+
const checkpoint = await Checkpoint.random(block.checkpointNumber, { numBlocks: 1 });
|
|
274
|
+
checkpoint.blocks = [block];
|
|
275
|
+
return checkpoint;
|
|
276
|
+
}),
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
getCheckpointedBlocksForEpoch(epochNumber: EpochNumber): Promise<CheckpointedL2Block[]> {
|
|
281
|
+
const epochDuration = DefaultL1ContractsConfig.aztecEpochDuration;
|
|
282
|
+
const [start, end] = getSlotRangeForEpoch(epochNumber, { epochDuration });
|
|
283
|
+
const blocks = this.l2Blocks.filter(b => {
|
|
284
|
+
const slot = b.header.globalVariables.slotNumber;
|
|
285
|
+
return slot >= start && slot <= end;
|
|
286
|
+
});
|
|
287
|
+
return Promise.resolve(
|
|
288
|
+
blocks.map(block =>
|
|
289
|
+
CheckpointedL2Block.fromFields({
|
|
290
|
+
checkpointNumber: CheckpointNumber.fromBlockNumber(block.number),
|
|
291
|
+
block,
|
|
292
|
+
l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
|
|
293
|
+
attestations: [],
|
|
294
|
+
}),
|
|
295
|
+
),
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
getBlocksForSlot(slotNumber: SlotNumber): Promise<L2Block[]> {
|
|
300
|
+
const blocks = this.l2Blocks.filter(b => b.header.globalVariables.slotNumber === slotNumber);
|
|
193
301
|
return Promise.resolve(blocks);
|
|
194
302
|
}
|
|
195
303
|
|
|
196
|
-
async
|
|
197
|
-
const
|
|
198
|
-
return
|
|
304
|
+
async getCheckpointedBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]> {
|
|
305
|
+
const checkpointedBlocks = await this.getCheckpointedBlocksForEpoch(epochNumber);
|
|
306
|
+
return checkpointedBlocks.map(b => b.block.header);
|
|
199
307
|
}
|
|
200
308
|
|
|
201
309
|
/**
|
|
@@ -228,10 +336,12 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
228
336
|
for (const block of this.l2Blocks) {
|
|
229
337
|
for (const txEffect of block.body.txEffects) {
|
|
230
338
|
if (txEffect.txHash.equals(txHash)) {
|
|
339
|
+
// In mock, assume all txs are checkpointed with successful execution
|
|
231
340
|
return new TxReceipt(
|
|
232
341
|
txHash,
|
|
233
|
-
TxStatus.
|
|
234
|
-
|
|
342
|
+
TxStatus.CHECKPOINTED,
|
|
343
|
+
TxExecutionResult.SUCCESS,
|
|
344
|
+
undefined,
|
|
235
345
|
txEffect.transactionFee.toBigInt(),
|
|
236
346
|
L2BlockHash.fromField(await block.hash()),
|
|
237
347
|
block.number,
|
|
@@ -243,29 +353,45 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
243
353
|
}
|
|
244
354
|
|
|
245
355
|
async getL2Tips(): Promise<L2Tips> {
|
|
246
|
-
const [latest, proven, finalized] = [
|
|
356
|
+
const [latest, proven, finalized, checkpointed] = [
|
|
247
357
|
await this.getBlockNumber(),
|
|
248
358
|
await this.getProvenBlockNumber(),
|
|
249
359
|
this.finalizedBlockNumber,
|
|
360
|
+
this.checkpointedBlockNumber,
|
|
250
361
|
] as const;
|
|
251
362
|
|
|
252
363
|
const latestBlock = this.l2Blocks[latest - 1];
|
|
253
364
|
const provenBlock = this.l2Blocks[proven - 1];
|
|
254
365
|
const finalizedBlock = this.l2Blocks[finalized - 1];
|
|
366
|
+
const checkpointedBlock = this.l2Blocks[checkpointed - 1];
|
|
367
|
+
|
|
368
|
+
const latestBlockId = {
|
|
369
|
+
number: BlockNumber(latest),
|
|
370
|
+
hash: (await latestBlock?.hash())?.toString(),
|
|
371
|
+
};
|
|
372
|
+
const provenBlockId = {
|
|
373
|
+
number: BlockNumber(proven),
|
|
374
|
+
hash: (await provenBlock?.hash())?.toString(),
|
|
375
|
+
};
|
|
376
|
+
const finalizedBlockId = {
|
|
377
|
+
number: BlockNumber(finalized),
|
|
378
|
+
hash: (await finalizedBlock?.hash())?.toString(),
|
|
379
|
+
};
|
|
380
|
+
const checkpointedBlockId = {
|
|
381
|
+
number: BlockNumber(checkpointed),
|
|
382
|
+
hash: (await checkpointedBlock?.hash())?.toString(),
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
const makeTipId = (blockId: typeof latestBlockId) => ({
|
|
386
|
+
block: blockId,
|
|
387
|
+
checkpoint: { number: CheckpointNumber.fromBlockNumber(blockId.number), hash: blockId.hash },
|
|
388
|
+
});
|
|
255
389
|
|
|
256
390
|
return {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
proven: {
|
|
262
|
-
number: proven,
|
|
263
|
-
hash: (await provenBlock?.hash())?.toString(),
|
|
264
|
-
},
|
|
265
|
-
finalized: {
|
|
266
|
-
number: finalized,
|
|
267
|
-
hash: (await finalizedBlock?.hash())?.toString(),
|
|
268
|
-
},
|
|
391
|
+
proposed: latestBlockId,
|
|
392
|
+
checkpointed: makeTipId(checkpointedBlockId),
|
|
393
|
+
proven: makeTipId(provenBlockId),
|
|
394
|
+
finalized: makeTipId(finalizedBlockId),
|
|
269
395
|
};
|
|
270
396
|
}
|
|
271
397
|
|
|
@@ -343,7 +469,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
343
469
|
return Promise.resolve(false);
|
|
344
470
|
}
|
|
345
471
|
|
|
346
|
-
getPendingChainValidationStatus(): Promise<
|
|
472
|
+
getPendingChainValidationStatus(): Promise<ValidateCheckpointResult> {
|
|
347
473
|
return Promise.resolve({ valid: true });
|
|
348
474
|
}
|
|
349
475
|
}
|