@aztec/archiver 0.0.1-commit.d3ec352c → 0.0.1-commit.e3c1de76
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 +136 -0
- package/dest/archiver.d.ts.map +1 -0
- package/dest/archiver.js +781 -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 +9 -7
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +89 -11
- 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 +75 -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 +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 +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 +30 -60
- 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 +1112 -0
- package/dest/modules/validation.d.ts +17 -0
- package/dest/modules/validation.d.ts.map +1 -0
- package/dest/{archiver → modules}/validation.js +7 -1
- package/dest/store/block_store.d.ts +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 +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 +340 -0
- package/dest/store/kv_archiver_store.d.ts.map +1 -0
- package/dest/store/kv_archiver_store.js +446 -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 -6
- 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 +4 -1
- package/dest/test/mock_archiver.d.ts +5 -6
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +6 -11
- package/dest/test/mock_l1_to_l2_message_source.d.ts +6 -7
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +19 -14
- package/dest/test/mock_l2_block_source.d.ts +30 -16
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +175 -68
- 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 -12
- 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 +18 -18
- package/src/archiver.ts +543 -0
- package/src/{archiver/config.ts → config.ts} +28 -12
- package/src/errors.ts +102 -0
- package/src/factory.ts +125 -11
- 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 +138 -220
- 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 +367 -0
- package/src/modules/data_store_updater.ts +423 -0
- package/src/{archiver → modules}/instrumentation.ts +34 -64
- package/src/modules/l1_synchronizer.ts +930 -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 +13 -9
- 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 +7 -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 +4 -0
- package/src/test/mock_archiver.ts +8 -13
- package/src/test/mock_l1_to_l2_message_source.ts +16 -15
- package/src/test/mock_l2_block_source.ts +191 -81
- package/src/test/mock_structs.ts +275 -14
- package/src/test/noop_l1_archiver.ts +109 -0
- package/dest/archiver/archiver.d.ts +0 -290
- package/dest/archiver/archiver.d.ts.map +0 -1
- package/dest/archiver/archiver.js +0 -1434
- package/dest/archiver/archiver_store.d.ts +0 -256
- 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 -80
- 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 -125
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/block_store.js +0 -371
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +0 -18
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +0 -24
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +0 -169
- 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 -337
- 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 -1880
- package/src/archiver/archiver_store.ts +0 -310
- package/src/archiver/archiver_store_test_suite.ts +0 -1295
- package/src/archiver/errors.ts +0 -26
- package/src/archiver/index.ts +0 -6
- package/src/archiver/kv_archiver_store/block_store.ts +0 -482
- package/src/archiver/kv_archiver_store/kv_archiver_store.ts +0 -423
- package/src/archiver/kv_archiver_store/log_store.ts +0 -407
- 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,24 +1,24 @@
|
|
|
1
1
|
import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
|
|
2
|
-
import { DefaultL1ContractsConfig } from '@aztec/ethereum';
|
|
2
|
+
import { DefaultL1ContractsConfig } from '@aztec/ethereum/config';
|
|
3
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
|
+
BlockHash,
|
|
12
|
+
CheckpointedL2Block,
|
|
11
13
|
L2Block,
|
|
12
|
-
L2BlockHash,
|
|
13
14
|
type L2BlockSource,
|
|
14
15
|
type L2Tips,
|
|
15
|
-
|
|
16
|
-
type ValidateBlockResult,
|
|
16
|
+
type ValidateCheckpointResult,
|
|
17
17
|
} from '@aztec/stdlib/block';
|
|
18
|
-
import
|
|
18
|
+
import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
19
19
|
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
20
20
|
import { EmptyL1RollupConstants, type L1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
21
|
-
import { type BlockHeader, TxHash, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
21
|
+
import { type BlockHeader, TxExecutionResult, TxHash, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
22
22
|
import type { UInt64 } from '@aztec/stdlib/types';
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -29,22 +29,23 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
29
29
|
|
|
30
30
|
private provenBlockNumber: number = 0;
|
|
31
31
|
private finalizedBlockNumber: number = 0;
|
|
32
|
+
private checkpointedBlockNumber: number = 0;
|
|
32
33
|
|
|
33
34
|
private log = createLogger('archiver:mock_l2_block_source');
|
|
34
35
|
|
|
35
36
|
public async createBlocks(numBlocks: number) {
|
|
36
37
|
for (let i = 0; i < numBlocks; i++) {
|
|
37
38
|
const blockNum = this.l2Blocks.length + 1;
|
|
38
|
-
const block = await L2Block.random(BlockNumber(blockNum));
|
|
39
|
+
const block = await L2Block.random(BlockNumber(blockNum), { slotNumber: SlotNumber(blockNum) });
|
|
39
40
|
this.l2Blocks.push(block);
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
this.log.verbose(`Created ${numBlocks} blocks in the mock L2 block source`);
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
public
|
|
46
|
+
public addProposedBlocks(blocks: L2Block[]) {
|
|
46
47
|
this.l2Blocks.push(...blocks);
|
|
47
|
-
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`);
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
public removeBlocks(numBlocks: number) {
|
|
@@ -63,6 +64,10 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
63
64
|
this.finalizedBlockNumber = finalizedBlockNumber;
|
|
64
65
|
}
|
|
65
66
|
|
|
67
|
+
public setCheckpointedBlockNumber(checkpointedBlockNumber: number) {
|
|
68
|
+
this.checkpointedBlockNumber = checkpointedBlockNumber;
|
|
69
|
+
}
|
|
70
|
+
|
|
66
71
|
/**
|
|
67
72
|
* Method to fetch the rollup contract address at the base-layer.
|
|
68
73
|
* @returns The rollup address.
|
|
@@ -91,13 +96,64 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
91
96
|
return Promise.resolve(BlockNumber(this.provenBlockNumber));
|
|
92
97
|
}
|
|
93
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;
|
|
137
|
+
}
|
|
138
|
+
|
|
94
139
|
/**
|
|
95
140
|
* Gets an l2 block.
|
|
96
141
|
* @param number - The block number to return (inclusive).
|
|
97
142
|
* @returns The requested L2 block.
|
|
98
143
|
*/
|
|
99
|
-
public getBlock(number: number) {
|
|
100
|
-
|
|
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);
|
|
101
157
|
}
|
|
102
158
|
|
|
103
159
|
/**
|
|
@@ -106,50 +162,47 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
106
162
|
* @param limit - The maximum number of blocks to return.
|
|
107
163
|
* @returns The requested mocked L2 blocks.
|
|
108
164
|
*/
|
|
109
|
-
public getBlocks(from: number, limit: number
|
|
110
|
-
return Promise.resolve(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
+
}),
|
|
114
183
|
);
|
|
115
184
|
}
|
|
116
185
|
|
|
117
|
-
public async getPublishedCheckpoints(from: CheckpointNumber, limit: number) {
|
|
118
|
-
// TODO: Implement this properly. This only works when we have one block per checkpoint.
|
|
119
|
-
return (await this.getPublishedBlocks(from, limit)).map(block => block.toPublishedCheckpoint());
|
|
120
|
-
}
|
|
121
|
-
|
|
122
186
|
public async getCheckpointByArchive(archive: Fr): Promise<Checkpoint | undefined> {
|
|
123
|
-
// TODO: Implement this properly. This only works when we have one block per checkpoint.
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
l1: {
|
|
133
|
-
blockNumber: BigInt(block.number),
|
|
134
|
-
blockHash: Buffer32.random().toString(),
|
|
135
|
-
timestamp: BigInt(block.number),
|
|
136
|
-
},
|
|
137
|
-
attestations: [],
|
|
138
|
-
}),
|
|
139
|
-
);
|
|
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;
|
|
140
196
|
}
|
|
141
197
|
|
|
142
|
-
public async
|
|
198
|
+
public async getCheckpointedBlockByHash(blockHash: BlockHash): Promise<CheckpointedL2Block | undefined> {
|
|
143
199
|
for (const block of this.l2Blocks) {
|
|
144
200
|
const hash = await block.hash();
|
|
145
201
|
if (hash.equals(blockHash)) {
|
|
146
|
-
return
|
|
202
|
+
return CheckpointedL2Block.fromFields({
|
|
203
|
+
checkpointNumber: CheckpointNumber.fromBlockNumber(block.number),
|
|
147
204
|
block,
|
|
148
|
-
l1:
|
|
149
|
-
blockNumber: BigInt(block.number),
|
|
150
|
-
blockHash: Buffer32.random().toString(),
|
|
151
|
-
timestamp: BigInt(block.number),
|
|
152
|
-
},
|
|
205
|
+
l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
|
|
153
206
|
attestations: [],
|
|
154
207
|
});
|
|
155
208
|
}
|
|
@@ -157,29 +210,41 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
157
210
|
return undefined;
|
|
158
211
|
}
|
|
159
212
|
|
|
160
|
-
public
|
|
213
|
+
public getCheckpointedBlockByArchive(archive: Fr): Promise<CheckpointedL2Block | undefined> {
|
|
161
214
|
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
162
215
|
if (!block) {
|
|
163
216
|
return Promise.resolve(undefined);
|
|
164
217
|
}
|
|
165
218
|
return Promise.resolve(
|
|
166
|
-
|
|
219
|
+
CheckpointedL2Block.fromFields({
|
|
220
|
+
checkpointNumber: CheckpointNumber.fromBlockNumber(block.number),
|
|
167
221
|
block,
|
|
168
|
-
l1:
|
|
169
|
-
blockNumber: BigInt(block.number),
|
|
170
|
-
blockHash: Buffer32.random().toString(),
|
|
171
|
-
timestamp: BigInt(block.number),
|
|
172
|
-
},
|
|
222
|
+
l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
|
|
173
223
|
attestations: [],
|
|
174
224
|
}),
|
|
175
225
|
);
|
|
176
226
|
}
|
|
177
227
|
|
|
178
|
-
public async
|
|
228
|
+
public async getL2BlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
179
229
|
for (const block of this.l2Blocks) {
|
|
180
230
|
const hash = await block.hash();
|
|
181
231
|
if (hash.equals(blockHash)) {
|
|
182
|
-
return block
|
|
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
|
+
|
|
243
|
+
public async getBlockHeaderByHash(blockHash: BlockHash): Promise<BlockHeader | undefined> {
|
|
244
|
+
for (const block of this.l2Blocks) {
|
|
245
|
+
const hash = await block.hash();
|
|
246
|
+
if (hash.equals(blockHash)) {
|
|
247
|
+
return block.header;
|
|
183
248
|
}
|
|
184
249
|
}
|
|
185
250
|
return undefined;
|
|
@@ -187,31 +252,58 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
187
252
|
|
|
188
253
|
public getBlockHeaderByArchive(archive: Fr): Promise<BlockHeader | undefined> {
|
|
189
254
|
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
190
|
-
return Promise.resolve(block?.
|
|
255
|
+
return Promise.resolve(block?.header);
|
|
191
256
|
}
|
|
192
257
|
|
|
193
258
|
getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
|
|
194
|
-
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);
|
|
195
260
|
}
|
|
196
261
|
|
|
197
262
|
getCheckpointsForEpoch(epochNumber: EpochNumber): Promise<Checkpoint[]> {
|
|
198
|
-
// TODO: Implement this properly. This only works when we have one block per checkpoint.
|
|
199
|
-
|
|
263
|
+
// TODO(mbps): Implement this properly. This only works when we have one block per checkpoint.
|
|
264
|
+
const epochDuration = DefaultL1ContractsConfig.aztecEpochDuration;
|
|
265
|
+
const [start, end] = getSlotRangeForEpoch(epochNumber, { epochDuration });
|
|
266
|
+
const blocks = this.l2Blocks.filter(b => {
|
|
267
|
+
const slot = b.header.globalVariables.slotNumber;
|
|
268
|
+
return slot >= start && slot <= end;
|
|
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
|
+
);
|
|
200
278
|
}
|
|
201
279
|
|
|
202
|
-
|
|
280
|
+
getCheckpointedBlocksForEpoch(epochNumber: EpochNumber): Promise<CheckpointedL2Block[]> {
|
|
203
281
|
const epochDuration = DefaultL1ContractsConfig.aztecEpochDuration;
|
|
204
282
|
const [start, end] = getSlotRangeForEpoch(epochNumber, { epochDuration });
|
|
205
283
|
const blocks = this.l2Blocks.filter(b => {
|
|
206
284
|
const slot = b.header.globalVariables.slotNumber;
|
|
207
285
|
return slot >= start && slot <= end;
|
|
208
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);
|
|
209
301
|
return Promise.resolve(blocks);
|
|
210
302
|
}
|
|
211
303
|
|
|
212
|
-
async
|
|
213
|
-
const
|
|
214
|
-
return
|
|
304
|
+
async getCheckpointedBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]> {
|
|
305
|
+
const checkpointedBlocks = await this.getCheckpointedBlocksForEpoch(epochNumber);
|
|
306
|
+
return checkpointedBlocks.map(b => b.block.header);
|
|
215
307
|
}
|
|
216
308
|
|
|
217
309
|
/**
|
|
@@ -230,7 +322,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
230
322
|
return {
|
|
231
323
|
data: txEffect,
|
|
232
324
|
l2BlockNumber: block.number,
|
|
233
|
-
l2BlockHash:
|
|
325
|
+
l2BlockHash: await block.hash(),
|
|
234
326
|
txIndexInBlock: block.body.txEffects.indexOf(txEffect),
|
|
235
327
|
};
|
|
236
328
|
}
|
|
@@ -244,12 +336,14 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
244
336
|
for (const block of this.l2Blocks) {
|
|
245
337
|
for (const txEffect of block.body.txEffects) {
|
|
246
338
|
if (txEffect.txHash.equals(txHash)) {
|
|
339
|
+
// In mock, assume all txs are checkpointed with successful execution
|
|
247
340
|
return new TxReceipt(
|
|
248
341
|
txHash,
|
|
249
|
-
TxStatus.
|
|
250
|
-
|
|
342
|
+
TxStatus.CHECKPOINTED,
|
|
343
|
+
TxExecutionResult.SUCCESS,
|
|
344
|
+
undefined,
|
|
251
345
|
txEffect.transactionFee.toBigInt(),
|
|
252
|
-
|
|
346
|
+
await block.hash(),
|
|
253
347
|
block.number,
|
|
254
348
|
);
|
|
255
349
|
}
|
|
@@ -259,29 +353,45 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
259
353
|
}
|
|
260
354
|
|
|
261
355
|
async getL2Tips(): Promise<L2Tips> {
|
|
262
|
-
const [latest, proven, finalized] = [
|
|
356
|
+
const [latest, proven, finalized, checkpointed] = [
|
|
263
357
|
await this.getBlockNumber(),
|
|
264
358
|
await this.getProvenBlockNumber(),
|
|
265
359
|
this.finalizedBlockNumber,
|
|
360
|
+
this.checkpointedBlockNumber,
|
|
266
361
|
] as const;
|
|
267
362
|
|
|
268
363
|
const latestBlock = this.l2Blocks[latest - 1];
|
|
269
364
|
const provenBlock = this.l2Blocks[proven - 1];
|
|
270
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
|
+
});
|
|
271
389
|
|
|
272
390
|
return {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
proven: {
|
|
278
|
-
number: BlockNumber(proven),
|
|
279
|
-
hash: (await provenBlock?.hash())?.toString(),
|
|
280
|
-
},
|
|
281
|
-
finalized: {
|
|
282
|
-
number: BlockNumber(finalized),
|
|
283
|
-
hash: (await finalizedBlock?.hash())?.toString(),
|
|
284
|
-
},
|
|
391
|
+
proposed: latestBlockId,
|
|
392
|
+
checkpointed: makeTipId(checkpointedBlockId),
|
|
393
|
+
proven: makeTipId(provenBlockId),
|
|
394
|
+
finalized: makeTipId(finalizedBlockId),
|
|
285
395
|
};
|
|
286
396
|
}
|
|
287
397
|
|
|
@@ -359,7 +469,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
359
469
|
return Promise.resolve(false);
|
|
360
470
|
}
|
|
361
471
|
|
|
362
|
-
getPendingChainValidationStatus(): Promise<
|
|
472
|
+
getPendingChainValidationStatus(): Promise<ValidateCheckpointResult> {
|
|
363
473
|
return Promise.resolve({ valid: true });
|
|
364
474
|
}
|
|
365
475
|
}
|