@aztec/archiver 0.0.1-commit.d3ec352c → 0.0.1-commit.f295ac2
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 +147 -22
- package/dest/archiver.d.ts +135 -0
- package/dest/archiver.d.ts.map +1 -0
- package/dest/archiver.js +769 -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 +36 -0
- package/dest/errors.d.ts.map +1 -0
- package/dest/errors.js +54 -0
- package/dest/factory.d.ts +5 -6
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +82 -5
- 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 +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 +85 -0
- package/dest/modules/data_source_base.d.ts.map +1 -0
- package/dest/modules/data_source_base.js +291 -0
- package/dest/modules/data_store_updater.d.ts +69 -0
- package/dest/modules/data_store_updater.d.ts.map +1 -0
- package/dest/modules/data_store_updater.js +304 -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 +178 -0
- package/dest/store/block_store.d.ts.map +1 -0
- package/dest/store/block_store.js +680 -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 +331 -0
- package/dest/store/kv_archiver_store.d.ts.map +1 -0
- package/dest/store/kv_archiver_store.js +438 -0
- package/dest/store/log_store.d.ts +45 -0
- package/dest/store/log_store.d.ts.map +1 -0
- package/dest/store/log_store.js +422 -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 +1 -0
- 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 +28 -14
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +160 -52
- 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 -10
- package/package.json +17 -18
- package/src/archiver.ts +525 -0
- package/src/{archiver/config.ts → config.ts} +28 -12
- package/src/errors.ts +90 -0
- package/src/factory.ts +118 -6
- 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 +182 -0
- package/src/l1/calldata_retriever.ts +641 -0
- package/src/{archiver → l1}/data_retrieval.ts +136 -218
- 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 +414 -0
- package/src/modules/data_store_updater.ts +419 -0
- package/src/{archiver → modules}/instrumentation.ts +24 -59
- package/src/modules/l1_synchronizer.ts +931 -0
- package/src/{archiver → modules}/validation.ts +11 -6
- package/src/store/block_store.ts +919 -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 +622 -0
- package/src/store/log_store.ts +552 -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 +1 -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 +184 -64
- package/src/test/mock_structs.ts +256 -11
- 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,21 +1,21 @@
|
|
|
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
|
-
|
|
11
|
+
CheckpointedL2Block,
|
|
12
12
|
L2BlockHash,
|
|
13
|
+
L2BlockNew,
|
|
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
21
|
import { type BlockHeader, TxHash, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
@@ -25,24 +25,25 @@ import type { UInt64 } from '@aztec/stdlib/types';
|
|
|
25
25
|
* A mocked implementation of L2BlockSource to be used in tests.
|
|
26
26
|
*/
|
|
27
27
|
export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
28
|
-
protected l2Blocks:
|
|
28
|
+
protected l2Blocks: L2BlockNew[] = [];
|
|
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
|
|
39
|
+
const block = await L2BlockNew.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 addBlocks(blocks:
|
|
46
|
+
public addBlocks(blocks: L2BlockNew[]) {
|
|
46
47
|
this.l2Blocks.push(...blocks);
|
|
47
48
|
this.log.verbose(`Added ${blocks.length} blocks to the mock L2 block source`);
|
|
48
49
|
}
|
|
@@ -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,60 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
91
96
|
return Promise.resolve(BlockNumber(this.provenBlockNumber));
|
|
92
97
|
}
|
|
93
98
|
|
|
99
|
+
public getCheckpointedBlock(number: BlockNumber): Promise<CheckpointedL2Block | undefined> {
|
|
100
|
+
if (number > this.checkpointedBlockNumber) {
|
|
101
|
+
return Promise.resolve(undefined);
|
|
102
|
+
}
|
|
103
|
+
const block = this.l2Blocks[number - 1];
|
|
104
|
+
if (!block) {
|
|
105
|
+
return Promise.resolve(undefined);
|
|
106
|
+
}
|
|
107
|
+
const checkpointedBlock = new CheckpointedL2Block(
|
|
108
|
+
CheckpointNumber(number),
|
|
109
|
+
block,
|
|
110
|
+
new L1PublishedData(BigInt(number), BigInt(number), `0x${number.toString(16).padStart(64, '0')}`),
|
|
111
|
+
[],
|
|
112
|
+
);
|
|
113
|
+
return Promise.resolve(checkpointedBlock);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public async getCheckpointedBlocks(
|
|
117
|
+
from: BlockNumber,
|
|
118
|
+
limit: number,
|
|
119
|
+
_proven?: boolean,
|
|
120
|
+
): Promise<CheckpointedL2Block[]> {
|
|
121
|
+
const result: CheckpointedL2Block[] = [];
|
|
122
|
+
for (let i = 0; i < limit; i++) {
|
|
123
|
+
const blockNum = from + i;
|
|
124
|
+
if (blockNum > this.checkpointedBlockNumber) {
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
const block = await this.getCheckpointedBlock(BlockNumber(blockNum));
|
|
128
|
+
if (block) {
|
|
129
|
+
result.push(block);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return result;
|
|
133
|
+
}
|
|
134
|
+
|
|
94
135
|
/**
|
|
95
136
|
* Gets an l2 block.
|
|
96
137
|
* @param number - The block number to return (inclusive).
|
|
97
138
|
* @returns The requested L2 block.
|
|
98
139
|
*/
|
|
99
|
-
public getBlock(number: number) {
|
|
100
|
-
|
|
140
|
+
public getBlock(number: number): Promise<L2BlockNew | undefined> {
|
|
141
|
+
const block = this.l2Blocks[number - 1];
|
|
142
|
+
return Promise.resolve(block);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Gets an L2 block (new format).
|
|
147
|
+
* @param number - The block number to return.
|
|
148
|
+
* @returns The requested L2 block.
|
|
149
|
+
*/
|
|
150
|
+
public getL2BlockNew(number: BlockNumber): Promise<L2BlockNew | undefined> {
|
|
151
|
+
const block = this.l2Blocks[number - 1];
|
|
152
|
+
return Promise.resolve(block);
|
|
101
153
|
}
|
|
102
154
|
|
|
103
155
|
/**
|
|
@@ -106,7 +158,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
106
158
|
* @param limit - The maximum number of blocks to return.
|
|
107
159
|
* @returns The requested mocked L2 blocks.
|
|
108
160
|
*/
|
|
109
|
-
public getBlocks(from: number, limit: number, proven?: boolean) {
|
|
161
|
+
public getBlocks(from: number, limit: number, proven?: boolean): Promise<L2BlockNew[]> {
|
|
110
162
|
return Promise.resolve(
|
|
111
163
|
this.l2Blocks
|
|
112
164
|
.slice(from - 1, from - 1 + limit)
|
|
@@ -114,42 +166,64 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
114
166
|
);
|
|
115
167
|
}
|
|
116
168
|
|
|
117
|
-
public
|
|
118
|
-
// TODO: Implement this properly. This only works when we have one block per checkpoint.
|
|
119
|
-
|
|
169
|
+
public getPublishedCheckpoints(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 L2BlockNew 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
|
+
}),
|
|
183
|
+
);
|
|
120
184
|
}
|
|
121
185
|
|
|
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
|
-
|
|
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 L2BlockNew doesn't have toCheckpoint()
|
|
193
|
+
const checkpoint = await Checkpoint.random(block.checkpointNumber, { numBlocks: 1 });
|
|
194
|
+
checkpoint.blocks = [block];
|
|
195
|
+
return checkpoint;
|
|
125
196
|
}
|
|
126
197
|
|
|
127
|
-
public
|
|
128
|
-
const blocks =
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
198
|
+
public getPublishedBlocks(from: number, limit: number, proven?: boolean): Promise<CheckpointedL2Block[]> {
|
|
199
|
+
const blocks = this.l2Blocks
|
|
200
|
+
.slice(from - 1, from - 1 + limit)
|
|
201
|
+
.filter(b => !proven || this.provenBlockNumber === undefined || b.number <= this.provenBlockNumber);
|
|
202
|
+
return Promise.resolve(
|
|
203
|
+
blocks.map(block =>
|
|
204
|
+
CheckpointedL2Block.fromFields({
|
|
205
|
+
checkpointNumber: CheckpointNumber(block.number),
|
|
206
|
+
block,
|
|
207
|
+
l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
|
|
208
|
+
attestations: [],
|
|
209
|
+
}),
|
|
210
|
+
),
|
|
139
211
|
);
|
|
140
212
|
}
|
|
141
213
|
|
|
142
|
-
|
|
214
|
+
getL2BlocksNew(from: BlockNumber, limit: number, proven?: boolean): Promise<L2BlockNew[]> {
|
|
215
|
+
// getBlocks already returns L2BlockNew[], so just return directly
|
|
216
|
+
return this.getBlocks(from, limit, proven);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
public async getPublishedBlockByHash(blockHash: Fr): Promise<CheckpointedL2Block | undefined> {
|
|
143
220
|
for (const block of this.l2Blocks) {
|
|
144
221
|
const hash = await block.hash();
|
|
145
222
|
if (hash.equals(blockHash)) {
|
|
146
|
-
return
|
|
223
|
+
return CheckpointedL2Block.fromFields({
|
|
224
|
+
checkpointNumber: CheckpointNumber(block.number),
|
|
147
225
|
block,
|
|
148
|
-
l1:
|
|
149
|
-
blockNumber: BigInt(block.number),
|
|
150
|
-
blockHash: Buffer32.random().toString(),
|
|
151
|
-
timestamp: BigInt(block.number),
|
|
152
|
-
},
|
|
226
|
+
l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
|
|
153
227
|
attestations: [],
|
|
154
228
|
});
|
|
155
229
|
}
|
|
@@ -157,29 +231,41 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
157
231
|
return undefined;
|
|
158
232
|
}
|
|
159
233
|
|
|
160
|
-
public getPublishedBlockByArchive(archive: Fr): Promise<
|
|
234
|
+
public getPublishedBlockByArchive(archive: Fr): Promise<CheckpointedL2Block | undefined> {
|
|
161
235
|
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
162
236
|
if (!block) {
|
|
163
237
|
return Promise.resolve(undefined);
|
|
164
238
|
}
|
|
165
239
|
return Promise.resolve(
|
|
166
|
-
|
|
240
|
+
CheckpointedL2Block.fromFields({
|
|
241
|
+
checkpointNumber: CheckpointNumber(block.number),
|
|
167
242
|
block,
|
|
168
|
-
l1:
|
|
169
|
-
blockNumber: BigInt(block.number),
|
|
170
|
-
blockHash: Buffer32.random().toString(),
|
|
171
|
-
timestamp: BigInt(block.number),
|
|
172
|
-
},
|
|
243
|
+
l1: new L1PublishedData(BigInt(block.number), BigInt(block.number), Buffer32.random().toString()),
|
|
173
244
|
attestations: [],
|
|
174
245
|
}),
|
|
175
246
|
);
|
|
176
247
|
}
|
|
177
248
|
|
|
249
|
+
public async getL2BlockNewByHash(blockHash: Fr): Promise<L2BlockNew | 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 getL2BlockNewByArchive(archive: Fr): Promise<L2BlockNew | undefined> {
|
|
260
|
+
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
261
|
+
return Promise.resolve(block);
|
|
262
|
+
}
|
|
263
|
+
|
|
178
264
|
public async getBlockHeaderByHash(blockHash: Fr): Promise<BlockHeader | undefined> {
|
|
179
265
|
for (const block of this.l2Blocks) {
|
|
180
266
|
const hash = await block.hash();
|
|
181
267
|
if (hash.equals(blockHash)) {
|
|
182
|
-
return block.
|
|
268
|
+
return block.header;
|
|
183
269
|
}
|
|
184
270
|
}
|
|
185
271
|
return undefined;
|
|
@@ -187,19 +273,32 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
187
273
|
|
|
188
274
|
public getBlockHeaderByArchive(archive: Fr): Promise<BlockHeader | undefined> {
|
|
189
275
|
const block = this.l2Blocks.find(b => b.archive.root.equals(archive));
|
|
190
|
-
return Promise.resolve(block?.
|
|
276
|
+
return Promise.resolve(block?.header);
|
|
191
277
|
}
|
|
192
278
|
|
|
193
279
|
getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
|
|
194
|
-
return Promise.resolve(this.l2Blocks.at(typeof number === 'number' ? number - 1 : -1)?.
|
|
280
|
+
return Promise.resolve(this.l2Blocks.at(typeof number === 'number' ? number - 1 : -1)?.header);
|
|
195
281
|
}
|
|
196
282
|
|
|
197
283
|
getCheckpointsForEpoch(epochNumber: EpochNumber): Promise<Checkpoint[]> {
|
|
198
|
-
// TODO: Implement this properly. This only works when we have one block per checkpoint.
|
|
199
|
-
|
|
284
|
+
// TODO(mbps): Implement this properly. This only works when we have one block per checkpoint.
|
|
285
|
+
const epochDuration = DefaultL1ContractsConfig.aztecEpochDuration;
|
|
286
|
+
const [start, end] = getSlotRangeForEpoch(epochNumber, { epochDuration });
|
|
287
|
+
const blocks = this.l2Blocks.filter(b => {
|
|
288
|
+
const slot = b.header.globalVariables.slotNumber;
|
|
289
|
+
return slot >= start && slot <= end;
|
|
290
|
+
});
|
|
291
|
+
// Create checkpoints from blocks - manually construct since L2BlockNew doesn't have toCheckpoint()
|
|
292
|
+
return Promise.all(
|
|
293
|
+
blocks.map(async block => {
|
|
294
|
+
const checkpoint = await Checkpoint.random(block.checkpointNumber, { numBlocks: 1 });
|
|
295
|
+
checkpoint.blocks = [block];
|
|
296
|
+
return checkpoint;
|
|
297
|
+
}),
|
|
298
|
+
);
|
|
200
299
|
}
|
|
201
300
|
|
|
202
|
-
getBlocksForEpoch(epochNumber: EpochNumber): Promise<
|
|
301
|
+
getBlocksForEpoch(epochNumber: EpochNumber): Promise<L2BlockNew[]> {
|
|
203
302
|
const epochDuration = DefaultL1ContractsConfig.aztecEpochDuration;
|
|
204
303
|
const [start, end] = getSlotRangeForEpoch(epochNumber, { epochDuration });
|
|
205
304
|
const blocks = this.l2Blocks.filter(b => {
|
|
@@ -209,9 +308,14 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
209
308
|
return Promise.resolve(blocks);
|
|
210
309
|
}
|
|
211
310
|
|
|
311
|
+
getBlocksForSlot(slotNumber: SlotNumber): Promise<L2BlockNew[]> {
|
|
312
|
+
const blocks = this.l2Blocks.filter(b => b.header.globalVariables.slotNumber === slotNumber);
|
|
313
|
+
return Promise.resolve(blocks);
|
|
314
|
+
}
|
|
315
|
+
|
|
212
316
|
async getBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]> {
|
|
213
317
|
const blocks = await this.getBlocksForEpoch(epochNumber);
|
|
214
|
-
return blocks.map(b => b.
|
|
318
|
+
return blocks.map(b => b.header);
|
|
215
319
|
}
|
|
216
320
|
|
|
217
321
|
/**
|
|
@@ -259,29 +363,45 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
259
363
|
}
|
|
260
364
|
|
|
261
365
|
async getL2Tips(): Promise<L2Tips> {
|
|
262
|
-
const [latest, proven, finalized] = [
|
|
366
|
+
const [latest, proven, finalized, checkpointed] = [
|
|
263
367
|
await this.getBlockNumber(),
|
|
264
368
|
await this.getProvenBlockNumber(),
|
|
265
369
|
this.finalizedBlockNumber,
|
|
370
|
+
this.checkpointedBlockNumber,
|
|
266
371
|
] as const;
|
|
267
372
|
|
|
268
373
|
const latestBlock = this.l2Blocks[latest - 1];
|
|
269
374
|
const provenBlock = this.l2Blocks[proven - 1];
|
|
270
375
|
const finalizedBlock = this.l2Blocks[finalized - 1];
|
|
376
|
+
const checkpointedBlock = this.l2Blocks[checkpointed - 1];
|
|
377
|
+
|
|
378
|
+
const latestBlockId = {
|
|
379
|
+
number: BlockNumber(latest),
|
|
380
|
+
hash: (await latestBlock?.hash())?.toString(),
|
|
381
|
+
};
|
|
382
|
+
const provenBlockId = {
|
|
383
|
+
number: BlockNumber(proven),
|
|
384
|
+
hash: (await provenBlock?.hash())?.toString(),
|
|
385
|
+
};
|
|
386
|
+
const finalizedBlockId = {
|
|
387
|
+
number: BlockNumber(finalized),
|
|
388
|
+
hash: (await finalizedBlock?.hash())?.toString(),
|
|
389
|
+
};
|
|
390
|
+
const checkpointedBlockId = {
|
|
391
|
+
number: BlockNumber(checkpointed),
|
|
392
|
+
hash: (await checkpointedBlock?.hash())?.toString(),
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
const makeTipId = (blockId: typeof latestBlockId) => ({
|
|
396
|
+
block: blockId,
|
|
397
|
+
checkpoint: { number: CheckpointNumber(blockId.number), hash: blockId.hash },
|
|
398
|
+
});
|
|
271
399
|
|
|
272
400
|
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
|
-
},
|
|
401
|
+
proposed: latestBlockId,
|
|
402
|
+
checkpointed: makeTipId(checkpointedBlockId),
|
|
403
|
+
proven: makeTipId(provenBlockId),
|
|
404
|
+
finalized: makeTipId(finalizedBlockId),
|
|
285
405
|
};
|
|
286
406
|
}
|
|
287
407
|
|
|
@@ -359,7 +479,7 @@ export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
|
|
|
359
479
|
return Promise.resolve(false);
|
|
360
480
|
}
|
|
361
481
|
|
|
362
|
-
getPendingChainValidationStatus(): Promise<
|
|
482
|
+
getPendingChainValidationStatus(): Promise<ValidateCheckpointResult> {
|
|
363
483
|
return Promise.resolve({ valid: true });
|
|
364
484
|
}
|
|
365
485
|
}
|