@aztec/archiver 4.0.0-nightly.20260112 → 4.0.0-nightly.20260114
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 +139 -22
- package/dest/archiver/archive_source_base.d.ts +75 -0
- package/dest/archiver/archive_source_base.d.ts.map +1 -0
- package/dest/archiver/archive_source_base.js +202 -0
- package/dest/archiver/archiver.d.ts +32 -168
- package/dest/archiver/archiver.d.ts.map +1 -1
- package/dest/archiver/archiver.js +123 -613
- package/dest/archiver/archiver_store_updates.d.ts +38 -0
- package/dest/archiver/archiver_store_updates.d.ts.map +1 -0
- package/dest/archiver/archiver_store_updates.js +212 -0
- package/dest/archiver/config.js +2 -2
- package/dest/archiver/index.d.ts +3 -2
- package/dest/archiver/index.d.ts.map +1 -1
- package/dest/archiver/index.js +2 -0
- package/dest/archiver/kv_archiver_store/block_store.d.ts +12 -5
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/block_store.js +23 -4
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +1 -1
- package/dest/archiver/kv_archiver_store/contract_class_store.js +1 -1
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +1 -1
- package/dest/archiver/kv_archiver_store/contract_instance_store.js +1 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +173 -12
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +1 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.js +159 -48
- package/dest/archiver/l1/calldata_retriever.d.ts +2 -2
- package/dest/archiver/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/archiver/l1/calldata_retriever.js +2 -2
- package/dest/archiver/l1/data_retrieval.d.ts +9 -11
- package/dest/archiver/l1/data_retrieval.d.ts.map +1 -1
- package/dest/archiver/l1/data_retrieval.js +32 -51
- package/dest/archiver/l1/validate_trace.js +1 -1
- package/dest/archiver/test/fake_l1_state.d.ts +173 -0
- package/dest/archiver/test/fake_l1_state.d.ts.map +1 -0
- package/dest/archiver/test/fake_l1_state.js +364 -0
- package/dest/archiver/validation.d.ts +4 -4
- package/dest/archiver/validation.d.ts.map +1 -1
- package/dest/archiver/validation.js +1 -1
- package/dest/test/mock_l1_to_l2_message_source.d.ts +2 -2
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +12 -3
- package/dest/test/mock_l2_block_source.d.ts +8 -4
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +65 -19
- package/package.json +13 -13
- package/src/archiver/archive_source_base.ts +339 -0
- package/src/archiver/archiver.ts +166 -815
- package/src/archiver/archiver_store_updates.ts +321 -0
- package/src/archiver/config.ts +2 -2
- package/src/archiver/index.ts +2 -1
- package/src/archiver/kv_archiver_store/block_store.ts +36 -8
- package/src/archiver/kv_archiver_store/contract_class_store.ts +1 -1
- package/src/archiver/kv_archiver_store/contract_instance_store.ts +1 -1
- package/src/archiver/kv_archiver_store/kv_archiver_store.ts +177 -11
- package/src/archiver/l1/calldata_retriever.ts +2 -2
- package/src/archiver/l1/data_retrieval.ts +51 -68
- package/src/archiver/l1/validate_trace.ts +1 -1
- package/src/archiver/test/fake_l1_state.ts +561 -0
- package/src/archiver/validation.ts +6 -6
- package/src/test/mock_l1_to_l2_message_source.ts +10 -4
- package/src/test/mock_l2_block_source.ts +76 -18
- package/dest/archiver/archiver_store.d.ts +0 -308
- package/dest/archiver/archiver_store.d.ts.map +0 -1
- package/dest/archiver/archiver_store.js +0 -4
- package/dest/archiver/archiver_store_test_suite.d.ts +0 -8
- package/dest/archiver/archiver_store_test_suite.d.ts.map +0 -1
- package/dest/archiver/archiver_store_test_suite.js +0 -2770
- package/src/archiver/archiver_store.ts +0 -372
- package/src/archiver/archiver_store_test_suite.ts +0 -2843
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
|
|
2
2
|
import { DefaultL1ContractsConfig } from '@aztec/ethereum/config';
|
|
3
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
4
4
|
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
5
5
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
6
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
7
7
|
import { createLogger } from '@aztec/foundation/log';
|
|
8
|
-
import { L2Block, L2BlockHash, PublishedL2Block } from '@aztec/stdlib/block';
|
|
8
|
+
import { CheckpointedL2Block, L2Block, L2BlockHash, PublishedL2Block } from '@aztec/stdlib/block';
|
|
9
9
|
import { L1PublishedData } from '@aztec/stdlib/checkpoint';
|
|
10
10
|
import { EmptyL1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
11
11
|
import { TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
@@ -15,6 +15,7 @@ import { TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
|
15
15
|
l2Blocks = [];
|
|
16
16
|
provenBlockNumber = 0;
|
|
17
17
|
finalizedBlockNumber = 0;
|
|
18
|
+
checkpointedBlockNumber = 0;
|
|
18
19
|
log = createLogger('archiver:mock_l2_block_source');
|
|
19
20
|
async createBlocks(numBlocks) {
|
|
20
21
|
for(let i = 0; i < numBlocks; i++){
|
|
@@ -41,6 +42,9 @@ import { TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
|
41
42
|
}
|
|
42
43
|
this.finalizedBlockNumber = finalizedBlockNumber;
|
|
43
44
|
}
|
|
45
|
+
setCheckpointedBlockNumber(checkpointedBlockNumber) {
|
|
46
|
+
this.checkpointedBlockNumber = checkpointedBlockNumber;
|
|
47
|
+
}
|
|
44
48
|
/**
|
|
45
49
|
* Method to fetch the rollup contract address at the base-layer.
|
|
46
50
|
* @returns The rollup address.
|
|
@@ -62,9 +66,30 @@ import { TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
|
62
66
|
getProvenBlockNumber() {
|
|
63
67
|
return Promise.resolve(BlockNumber(this.provenBlockNumber));
|
|
64
68
|
}
|
|
65
|
-
getCheckpointedBlock(
|
|
66
|
-
|
|
67
|
-
|
|
69
|
+
getCheckpointedBlock(number) {
|
|
70
|
+
if (number > this.checkpointedBlockNumber) {
|
|
71
|
+
return Promise.resolve(undefined);
|
|
72
|
+
}
|
|
73
|
+
const block = this.l2Blocks[number - 1];
|
|
74
|
+
if (!block) {
|
|
75
|
+
return Promise.resolve(undefined);
|
|
76
|
+
}
|
|
77
|
+
const checkpointedBlock = new CheckpointedL2Block(CheckpointNumber(number), block.toL2Block(), new L1PublishedData(BigInt(number), BigInt(number), `0x${number.toString(16).padStart(64, '0')}`), []);
|
|
78
|
+
return Promise.resolve(checkpointedBlock);
|
|
79
|
+
}
|
|
80
|
+
async getCheckpointedBlocks(from, limit, _proven) {
|
|
81
|
+
const result = [];
|
|
82
|
+
for(let i = 0; i < limit; i++){
|
|
83
|
+
const blockNum = from + i;
|
|
84
|
+
if (blockNum > this.checkpointedBlockNumber) {
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
const block = await this.getCheckpointedBlock(BlockNumber(blockNum));
|
|
88
|
+
if (block) {
|
|
89
|
+
result.push(block);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
68
93
|
}
|
|
69
94
|
/**
|
|
70
95
|
* Gets an l2 block.
|
|
@@ -105,6 +130,10 @@ import { TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
|
105
130
|
attestations: []
|
|
106
131
|
}));
|
|
107
132
|
}
|
|
133
|
+
async getL2BlocksNew(from, limit, proven) {
|
|
134
|
+
const blocks = await this.getBlocks(from, limit, proven);
|
|
135
|
+
return blocks.map((x)=>x.toL2Block());
|
|
136
|
+
}
|
|
108
137
|
async getPublishedBlockByHash(blockHash) {
|
|
109
138
|
for (const block of this.l2Blocks){
|
|
110
139
|
const hash = await block.hash();
|
|
@@ -199,27 +228,44 @@ import { TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
|
199
228
|
return undefined;
|
|
200
229
|
}
|
|
201
230
|
async getL2Tips() {
|
|
202
|
-
const [latest, proven, finalized] = [
|
|
231
|
+
const [latest, proven, finalized, checkpointed] = [
|
|
203
232
|
await this.getBlockNumber(),
|
|
204
233
|
await this.getProvenBlockNumber(),
|
|
205
|
-
this.finalizedBlockNumber
|
|
234
|
+
this.finalizedBlockNumber,
|
|
235
|
+
this.checkpointedBlockNumber
|
|
206
236
|
];
|
|
207
237
|
const latestBlock = this.l2Blocks[latest - 1];
|
|
208
238
|
const provenBlock = this.l2Blocks[proven - 1];
|
|
209
239
|
const finalizedBlock = this.l2Blocks[finalized - 1];
|
|
240
|
+
const checkpointedBlock = this.l2Blocks[checkpointed - 1];
|
|
241
|
+
const latestBlockId = {
|
|
242
|
+
number: BlockNumber(latest),
|
|
243
|
+
hash: (await latestBlock?.hash())?.toString()
|
|
244
|
+
};
|
|
245
|
+
const provenBlockId = {
|
|
246
|
+
number: BlockNumber(proven),
|
|
247
|
+
hash: (await provenBlock?.hash())?.toString()
|
|
248
|
+
};
|
|
249
|
+
const finalizedBlockId = {
|
|
250
|
+
number: BlockNumber(finalized),
|
|
251
|
+
hash: (await finalizedBlock?.hash())?.toString()
|
|
252
|
+
};
|
|
253
|
+
const checkpointedBlockId = {
|
|
254
|
+
number: BlockNumber(checkpointed),
|
|
255
|
+
hash: (await checkpointedBlock?.hash())?.toString()
|
|
256
|
+
};
|
|
257
|
+
const makeTipId = (blockId)=>({
|
|
258
|
+
block: blockId,
|
|
259
|
+
checkpoint: {
|
|
260
|
+
number: CheckpointNumber(blockId.number),
|
|
261
|
+
hash: blockId.hash
|
|
262
|
+
}
|
|
263
|
+
});
|
|
210
264
|
return {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
proven: {
|
|
216
|
-
number: BlockNumber(proven),
|
|
217
|
-
hash: (await provenBlock?.hash())?.toString()
|
|
218
|
-
},
|
|
219
|
-
finalized: {
|
|
220
|
-
number: BlockNumber(finalized),
|
|
221
|
-
hash: (await finalizedBlock?.hash())?.toString()
|
|
222
|
-
}
|
|
265
|
+
proposed: latestBlockId,
|
|
266
|
+
checkpointed: makeTipId(checkpointedBlockId),
|
|
267
|
+
proven: makeTipId(provenBlockId),
|
|
268
|
+
finalized: makeTipId(finalizedBlockId)
|
|
223
269
|
};
|
|
224
270
|
}
|
|
225
271
|
getL2EpochNumber() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/archiver",
|
|
3
|
-
"version": "4.0.0-nightly.
|
|
3
|
+
"version": "4.0.0-nightly.20260114",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -66,18 +66,18 @@
|
|
|
66
66
|
]
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@aztec/blob-client": "4.0.0-nightly.
|
|
70
|
-
"@aztec/blob-lib": "4.0.0-nightly.
|
|
71
|
-
"@aztec/constants": "4.0.0-nightly.
|
|
72
|
-
"@aztec/epoch-cache": "4.0.0-nightly.
|
|
73
|
-
"@aztec/ethereum": "4.0.0-nightly.
|
|
74
|
-
"@aztec/foundation": "4.0.0-nightly.
|
|
75
|
-
"@aztec/kv-store": "4.0.0-nightly.
|
|
76
|
-
"@aztec/l1-artifacts": "4.0.0-nightly.
|
|
77
|
-
"@aztec/noir-protocol-circuits-types": "4.0.0-nightly.
|
|
78
|
-
"@aztec/protocol-contracts": "4.0.0-nightly.
|
|
79
|
-
"@aztec/stdlib": "4.0.0-nightly.
|
|
80
|
-
"@aztec/telemetry-client": "4.0.0-nightly.
|
|
69
|
+
"@aztec/blob-client": "4.0.0-nightly.20260114",
|
|
70
|
+
"@aztec/blob-lib": "4.0.0-nightly.20260114",
|
|
71
|
+
"@aztec/constants": "4.0.0-nightly.20260114",
|
|
72
|
+
"@aztec/epoch-cache": "4.0.0-nightly.20260114",
|
|
73
|
+
"@aztec/ethereum": "4.0.0-nightly.20260114",
|
|
74
|
+
"@aztec/foundation": "4.0.0-nightly.20260114",
|
|
75
|
+
"@aztec/kv-store": "4.0.0-nightly.20260114",
|
|
76
|
+
"@aztec/l1-artifacts": "4.0.0-nightly.20260114",
|
|
77
|
+
"@aztec/noir-protocol-circuits-types": "4.0.0-nightly.20260114",
|
|
78
|
+
"@aztec/protocol-contracts": "4.0.0-nightly.20260114",
|
|
79
|
+
"@aztec/stdlib": "4.0.0-nightly.20260114",
|
|
80
|
+
"@aztec/telemetry-client": "4.0.0-nightly.20260114",
|
|
81
81
|
"lodash.groupby": "^4.6.0",
|
|
82
82
|
"lodash.omit": "^4.5.0",
|
|
83
83
|
"tslib": "^2.5.0",
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { BlockNumber, CheckpointNumber, type EpochNumber, type SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
|
+
import { isDefined } from '@aztec/foundation/types';
|
|
5
|
+
import type { FunctionSelector } from '@aztec/stdlib/abi';
|
|
6
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
7
|
+
import {
|
|
8
|
+
type CheckpointedL2Block,
|
|
9
|
+
CommitteeAttestation,
|
|
10
|
+
L2Block,
|
|
11
|
+
type L2BlockNew,
|
|
12
|
+
type L2Tips,
|
|
13
|
+
PublishedL2Block,
|
|
14
|
+
} from '@aztec/stdlib/block';
|
|
15
|
+
import { Checkpoint, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
16
|
+
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
17
|
+
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
18
|
+
import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
|
|
19
|
+
import type { L2LogsSource } from '@aztec/stdlib/interfaces/server';
|
|
20
|
+
import type { LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
21
|
+
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
22
|
+
import type { BlockHeader, IndexedTxEffect, TxHash, TxReceipt } from '@aztec/stdlib/tx';
|
|
23
|
+
import type { UInt64 } from '@aztec/stdlib/types';
|
|
24
|
+
|
|
25
|
+
import type { ArchiveSource } from './archiver.js';
|
|
26
|
+
import type { KVArchiverDataStore } from './kv_archiver_store/kv_archiver_store.js';
|
|
27
|
+
import type { ValidateCheckpointResult } from './validation.js';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Abstract base class implementing ArchiveSource using a KVArchiverDataStore.
|
|
31
|
+
* Provides implementations for all store-delegating methods and declares abstract methods
|
|
32
|
+
* for L1-dependent functionality that subclasses must implement.
|
|
33
|
+
*/
|
|
34
|
+
export abstract class ArchiveSourceBase
|
|
35
|
+
implements ArchiveSource, L2LogsSource, ContractDataSource, L1ToL2MessageSource
|
|
36
|
+
{
|
|
37
|
+
protected readonly store: KVArchiverDataStore;
|
|
38
|
+
|
|
39
|
+
constructor(store: KVArchiverDataStore) {
|
|
40
|
+
this.store = store;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Abstract methods that require L1 dependencies
|
|
44
|
+
|
|
45
|
+
abstract getRollupAddress(): Promise<EthAddress>;
|
|
46
|
+
|
|
47
|
+
abstract getRegistryAddress(): Promise<EthAddress>;
|
|
48
|
+
|
|
49
|
+
abstract getL1Constants(): Promise<L1RollupConstants>;
|
|
50
|
+
|
|
51
|
+
abstract getGenesisValues(): Promise<{ genesisArchiveRoot: Fr }>;
|
|
52
|
+
|
|
53
|
+
abstract getL1Timestamp(): Promise<bigint | undefined>;
|
|
54
|
+
|
|
55
|
+
abstract getL2Tips(): Promise<L2Tips>;
|
|
56
|
+
|
|
57
|
+
abstract getL2SlotNumber(): Promise<SlotNumber | undefined>;
|
|
58
|
+
|
|
59
|
+
abstract getL2EpochNumber(): Promise<EpochNumber | undefined>;
|
|
60
|
+
|
|
61
|
+
abstract getCheckpointsForEpoch(epochNumber: EpochNumber): Promise<Checkpoint[]>;
|
|
62
|
+
|
|
63
|
+
abstract getBlocksForEpoch(epochNumber: EpochNumber): Promise<L2Block[]>;
|
|
64
|
+
|
|
65
|
+
abstract getBlockHeadersForEpoch(epochNumber: EpochNumber): Promise<BlockHeader[]>;
|
|
66
|
+
|
|
67
|
+
abstract isEpochComplete(epochNumber: EpochNumber): Promise<boolean>;
|
|
68
|
+
|
|
69
|
+
abstract syncImmediate(): Promise<void>;
|
|
70
|
+
|
|
71
|
+
// Store-delegating methods
|
|
72
|
+
|
|
73
|
+
public getBlockNumber(): Promise<BlockNumber> {
|
|
74
|
+
return this.store.getLatestBlockNumber();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public getProvenBlockNumber(): Promise<BlockNumber> {
|
|
78
|
+
return this.store.getProvenBlockNumber();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public async getBlockHeader(number: BlockNumber | 'latest'): Promise<BlockHeader | undefined> {
|
|
82
|
+
const blockNumber = number === 'latest' ? await this.store.getLatestBlockNumber() : number;
|
|
83
|
+
if (blockNumber === 0) {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
const headers = await this.store.getBlockHeaders(blockNumber, 1);
|
|
87
|
+
return headers.length === 0 ? undefined : headers[0];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public getCheckpointedBlock(number: BlockNumber): Promise<CheckpointedL2Block | undefined> {
|
|
91
|
+
return this.store.getCheckpointedBlock(number);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public async getCheckpointedBlocks(
|
|
95
|
+
from: BlockNumber,
|
|
96
|
+
limit: number,
|
|
97
|
+
proven?: boolean,
|
|
98
|
+
): Promise<CheckpointedL2Block[]> {
|
|
99
|
+
const blocks = await this.store.getCheckpointedBlocks(from, limit);
|
|
100
|
+
|
|
101
|
+
if (proven === true) {
|
|
102
|
+
const provenBlockNumber = await this.store.getProvenBlockNumber();
|
|
103
|
+
return blocks.filter(b => b.block.number <= provenBlockNumber);
|
|
104
|
+
}
|
|
105
|
+
return blocks;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public getBlockHeaderByHash(blockHash: Fr): Promise<BlockHeader | undefined> {
|
|
109
|
+
return this.store.getBlockHeaderByHash(blockHash);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
public getBlockHeaderByArchive(archive: Fr): Promise<BlockHeader | undefined> {
|
|
113
|
+
return this.store.getBlockHeaderByArchive(archive);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public async getL2BlockNew(number: BlockNumber): Promise<L2BlockNew | undefined> {
|
|
117
|
+
// If the number provided is -ve, then return the latest block.
|
|
118
|
+
if (number < 0) {
|
|
119
|
+
number = await this.store.getLatestBlockNumber();
|
|
120
|
+
}
|
|
121
|
+
if (number === 0) {
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
const publishedBlock = await this.store.getBlock(number);
|
|
125
|
+
return publishedBlock;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
129
|
+
return this.store.getTxEffect(txHash);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public getSettledTxReceipt(txHash: TxHash): Promise<TxReceipt | undefined> {
|
|
133
|
+
return this.store.getSettledTxReceipt(txHash);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
public isPendingChainInvalid(): Promise<boolean> {
|
|
137
|
+
return this.getPendingChainValidationStatus().then(status => !status.valid);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
public async getPendingChainValidationStatus(): Promise<ValidateCheckpointResult> {
|
|
141
|
+
return (await this.store.getPendingChainValidationStatus()) ?? { valid: true };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
public async getL2BlocksNew(from: BlockNumber, limit: number, proven?: boolean): Promise<L2BlockNew[]> {
|
|
145
|
+
const blocks = await this.store.getBlocks(from, limit);
|
|
146
|
+
|
|
147
|
+
if (proven === true) {
|
|
148
|
+
const provenBlockNumber = await this.store.getProvenBlockNumber();
|
|
149
|
+
return blocks.filter(b => b.number <= provenBlockNumber);
|
|
150
|
+
}
|
|
151
|
+
return blocks;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// L2LogsSource methods
|
|
155
|
+
|
|
156
|
+
public getPrivateLogsByTags(tags: SiloedTag[]): Promise<TxScopedL2Log[][]> {
|
|
157
|
+
return this.store.getPrivateLogsByTags(tags);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
public getPublicLogsByTagsFromContract(contractAddress: AztecAddress, tags: Tag[]): Promise<TxScopedL2Log[][]> {
|
|
161
|
+
return this.store.getPublicLogsByTagsFromContract(contractAddress, tags);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
public getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse> {
|
|
165
|
+
return this.store.getPublicLogs(filter);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
public getContractClassLogs(filter: LogFilter): Promise<GetContractClassLogsResponse> {
|
|
169
|
+
return this.store.getContractClassLogs(filter);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// ContractDataSource methods
|
|
173
|
+
|
|
174
|
+
public getContractClass(id: Fr): Promise<ContractClassPublic | undefined> {
|
|
175
|
+
return this.store.getContractClass(id);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
public getBytecodeCommitment(id: Fr): Promise<Fr | undefined> {
|
|
179
|
+
return this.store.getBytecodeCommitment(id);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
public async getContract(
|
|
183
|
+
address: AztecAddress,
|
|
184
|
+
maybeTimestamp?: UInt64,
|
|
185
|
+
): Promise<ContractInstanceWithAddress | undefined> {
|
|
186
|
+
let timestamp;
|
|
187
|
+
if (maybeTimestamp === undefined) {
|
|
188
|
+
const latestBlockHeader = await this.getBlockHeader('latest');
|
|
189
|
+
// If we get undefined block header, it means that the archiver has not yet synced any block so we default to 0.
|
|
190
|
+
timestamp = latestBlockHeader ? latestBlockHeader.globalVariables.timestamp : 0n;
|
|
191
|
+
} else {
|
|
192
|
+
timestamp = maybeTimestamp;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return this.store.getContractInstance(address, timestamp);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
public getContractClassIds(): Promise<Fr[]> {
|
|
199
|
+
return this.store.getContractClassIds();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
public getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
|
|
203
|
+
return this.store.getDebugFunctionName(address, selector);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
public registerContractFunctionSignatures(signatures: string[]): Promise<void> {
|
|
207
|
+
return this.store.registerContractFunctionSignatures(signatures);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// L1ToL2MessageSource methods
|
|
211
|
+
|
|
212
|
+
public getL1ToL2Messages(checkpointNumber: CheckpointNumber): Promise<Fr[]> {
|
|
213
|
+
return this.store.getL1ToL2Messages(checkpointNumber);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
public getL1ToL2MessageIndex(l1ToL2Message: Fr): Promise<bigint | undefined> {
|
|
217
|
+
return this.store.getL1ToL2MessageIndex(l1ToL2Message);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Published checkpoint methods
|
|
221
|
+
|
|
222
|
+
public async getPublishedCheckpoints(
|
|
223
|
+
checkpointNumber: CheckpointNumber,
|
|
224
|
+
limit: number,
|
|
225
|
+
): Promise<PublishedCheckpoint[]> {
|
|
226
|
+
const checkpoints = await this.store.getRangeOfCheckpoints(checkpointNumber, limit);
|
|
227
|
+
const blocks = (
|
|
228
|
+
await Promise.all(checkpoints.map(ch => this.store.getBlocksForCheckpoint(ch.checkpointNumber)))
|
|
229
|
+
).filter(isDefined);
|
|
230
|
+
|
|
231
|
+
const fullCheckpoints: PublishedCheckpoint[] = [];
|
|
232
|
+
for (let i = 0; i < checkpoints.length; i++) {
|
|
233
|
+
const blocksForCheckpoint = blocks[i];
|
|
234
|
+
const checkpoint = checkpoints[i];
|
|
235
|
+
const fullCheckpoint = new Checkpoint(
|
|
236
|
+
checkpoint.archive,
|
|
237
|
+
checkpoint.header,
|
|
238
|
+
blocksForCheckpoint,
|
|
239
|
+
checkpoint.checkpointNumber,
|
|
240
|
+
);
|
|
241
|
+
const publishedCheckpoint = new PublishedCheckpoint(
|
|
242
|
+
fullCheckpoint,
|
|
243
|
+
checkpoint.l1,
|
|
244
|
+
checkpoint.attestations.map(x => CommitteeAttestation.fromBuffer(x)),
|
|
245
|
+
);
|
|
246
|
+
fullCheckpoints.push(publishedCheckpoint);
|
|
247
|
+
}
|
|
248
|
+
return fullCheckpoints;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
public async getPublishedBlocks(from: BlockNumber, limit: number, proven?: boolean): Promise<PublishedL2Block[]> {
|
|
252
|
+
const checkpoints = await this.store.getRangeOfCheckpoints(CheckpointNumber(from), limit);
|
|
253
|
+
const provenCheckpointNumber = await this.store.getProvenCheckpointNumber();
|
|
254
|
+
const blocks = (
|
|
255
|
+
await Promise.all(checkpoints.map(ch => this.store.getBlocksForCheckpoint(ch.checkpointNumber)))
|
|
256
|
+
).filter(isDefined);
|
|
257
|
+
|
|
258
|
+
const olbBlocks: PublishedL2Block[] = [];
|
|
259
|
+
for (let i = 0; i < checkpoints.length; i++) {
|
|
260
|
+
const blockForCheckpoint = blocks[i][0];
|
|
261
|
+
const checkpoint = checkpoints[i];
|
|
262
|
+
if (checkpoint.checkpointNumber > provenCheckpointNumber && proven === true) {
|
|
263
|
+
// this checkpointisn't proven and we only want proven
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
const oldCheckpoint = new Checkpoint(
|
|
267
|
+
blockForCheckpoint.archive,
|
|
268
|
+
checkpoint.header,
|
|
269
|
+
[blockForCheckpoint],
|
|
270
|
+
checkpoint.checkpointNumber,
|
|
271
|
+
);
|
|
272
|
+
const oldBlock = L2Block.fromCheckpoint(oldCheckpoint);
|
|
273
|
+
const publishedBlock = new PublishedL2Block(
|
|
274
|
+
oldBlock,
|
|
275
|
+
checkpoint.l1,
|
|
276
|
+
checkpoint.attestations.map(x => CommitteeAttestation.fromBuffer(x)),
|
|
277
|
+
);
|
|
278
|
+
olbBlocks.push(publishedBlock);
|
|
279
|
+
}
|
|
280
|
+
return olbBlocks;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Legacy APIs
|
|
284
|
+
|
|
285
|
+
public async getBlock(number: BlockNumber): Promise<L2Block | undefined> {
|
|
286
|
+
// If the number provided is -ve, then return the latest block.
|
|
287
|
+
if (number < 0) {
|
|
288
|
+
number = await this.store.getLatestBlockNumber();
|
|
289
|
+
}
|
|
290
|
+
if (number === 0) {
|
|
291
|
+
return undefined;
|
|
292
|
+
}
|
|
293
|
+
const publishedBlocks = await this.getPublishedBlocks(number, 1);
|
|
294
|
+
if (publishedBlocks.length === 0) {
|
|
295
|
+
return undefined;
|
|
296
|
+
}
|
|
297
|
+
return publishedBlocks[0].block;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
public async getBlocks(from: BlockNumber, limit: number, proven?: boolean): Promise<L2Block[]> {
|
|
301
|
+
const publishedBlocks = await this.getPublishedBlocks(from, limit, proven);
|
|
302
|
+
return publishedBlocks.map(x => x.block);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
public async getPublishedBlockByHash(blockHash: Fr): Promise<PublishedL2Block | undefined> {
|
|
306
|
+
const checkpointedBlock = await this.store.getCheckpointedBlockByHash(blockHash);
|
|
307
|
+
return this.buildOldBlockFromCheckpointedBlock(checkpointedBlock);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
public async getPublishedBlockByArchive(archive: Fr): Promise<PublishedL2Block | undefined> {
|
|
311
|
+
const checkpointedBlock = await this.store.getCheckpointedBlockByArchive(archive);
|
|
312
|
+
return this.buildOldBlockFromCheckpointedBlock(checkpointedBlock);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
private async buildOldBlockFromCheckpointedBlock(
|
|
316
|
+
checkpointedBlock: CheckpointedL2Block | undefined,
|
|
317
|
+
): Promise<PublishedL2Block | undefined> {
|
|
318
|
+
if (!checkpointedBlock) {
|
|
319
|
+
return undefined;
|
|
320
|
+
}
|
|
321
|
+
const checkpoint = await this.store.getCheckpointData(checkpointedBlock.checkpointNumber);
|
|
322
|
+
if (!checkpoint) {
|
|
323
|
+
return checkpoint;
|
|
324
|
+
}
|
|
325
|
+
const fullCheckpoint = new Checkpoint(
|
|
326
|
+
checkpointedBlock?.block.archive,
|
|
327
|
+
checkpoint?.header,
|
|
328
|
+
[checkpointedBlock.block],
|
|
329
|
+
checkpoint.checkpointNumber,
|
|
330
|
+
);
|
|
331
|
+
const oldBlock = L2Block.fromCheckpoint(fullCheckpoint);
|
|
332
|
+
const published = new PublishedL2Block(
|
|
333
|
+
oldBlock,
|
|
334
|
+
checkpoint.l1,
|
|
335
|
+
checkpoint.attestations.map(x => CommitteeAttestation.fromBuffer(x)),
|
|
336
|
+
);
|
|
337
|
+
return published;
|
|
338
|
+
}
|
|
339
|
+
}
|