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