@aztec/archiver 0.0.1-commit.d117d021b → 0.0.1-commit.d1da697d6
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 +12 -6
- package/dest/archiver.d.ts +5 -7
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +56 -20
- package/dest/config.d.ts +3 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +2 -1
- package/dest/errors.d.ts +34 -10
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +45 -16
- package/dest/factory.d.ts +3 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +19 -18
- package/dest/l1/calldata_retriever.d.ts +1 -1
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +2 -1
- package/dest/l1/data_retrieval.d.ts +2 -2
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +13 -14
- package/dest/modules/data_source_base.d.ts +8 -6
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +11 -5
- package/dest/modules/data_store_updater.d.ts +14 -11
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +78 -76
- package/dest/modules/l1_synchronizer.d.ts +4 -3
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +160 -127
- package/dest/modules/validation.d.ts +1 -1
- package/dest/modules/validation.d.ts.map +1 -1
- package/dest/modules/validation.js +2 -2
- package/dest/store/block_store.d.ts +50 -16
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +288 -119
- package/dest/store/contract_class_store.d.ts +2 -3
- package/dest/store/contract_class_store.d.ts.map +1 -1
- package/dest/store/contract_class_store.js +7 -67
- package/dest/store/contract_instance_store.d.ts +1 -1
- package/dest/store/contract_instance_store.d.ts.map +1 -1
- package/dest/store/contract_instance_store.js +6 -2
- package/dest/store/kv_archiver_store.d.ts +45 -22
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +57 -27
- package/dest/store/l2_tips_cache.d.ts +2 -1
- package/dest/store/l2_tips_cache.d.ts.map +1 -1
- package/dest/store/l2_tips_cache.js +25 -5
- package/dest/store/log_store.d.ts +6 -3
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +93 -16
- package/dest/store/message_store.d.ts +5 -1
- package/dest/store/message_store.d.ts.map +1 -1
- package/dest/store/message_store.js +20 -8
- package/dest/test/fake_l1_state.d.ts +16 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +77 -8
- package/dest/test/mock_l1_to_l2_message_source.d.ts +1 -1
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +2 -1
- package/dest/test/mock_l2_block_source.d.ts +9 -4
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +32 -7
- package/dest/test/noop_l1_archiver.d.ts +4 -1
- package/dest/test/noop_l1_archiver.d.ts.map +1 -1
- package/dest/test/noop_l1_archiver.js +5 -1
- package/package.json +13 -13
- package/src/archiver.ts +62 -21
- package/src/config.ts +8 -1
- package/src/errors.ts +70 -26
- package/src/factory.ts +19 -14
- package/src/l1/calldata_retriever.ts +2 -1
- package/src/l1/data_retrieval.ts +7 -11
- package/src/modules/data_source_base.ts +26 -7
- package/src/modules/data_store_updater.ts +91 -107
- package/src/modules/l1_synchronizer.ts +174 -156
- package/src/modules/validation.ts +2 -2
- package/src/store/block_store.ts +370 -140
- package/src/store/contract_class_store.ts +8 -106
- package/src/store/contract_instance_store.ts +8 -5
- package/src/store/kv_archiver_store.ts +81 -39
- package/src/store/l2_tips_cache.ts +50 -11
- package/src/store/log_store.ts +126 -27
- package/src/store/message_store.ts +26 -9
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +103 -13
- package/src/test/mock_l1_to_l2_message_source.ts +1 -0
- package/src/test/mock_l2_block_source.ts +46 -5
- package/src/test/noop_l1_archiver.ts +7 -1
|
@@ -2,14 +2,7 @@ import { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
2
2
|
import { toArray } from '@aztec/foundation/iterable';
|
|
3
3
|
import { BufferReader, numToUInt8, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
4
4
|
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
5
|
-
import {
|
|
6
|
-
import type {
|
|
7
|
-
ContractClassPublic,
|
|
8
|
-
ContractClassPublicWithBlockNumber,
|
|
9
|
-
ExecutablePrivateFunctionWithMembershipProof,
|
|
10
|
-
UtilityFunctionWithMembershipProof,
|
|
11
|
-
} from '@aztec/stdlib/contract';
|
|
12
|
-
import { Vector } from '@aztec/stdlib/types';
|
|
5
|
+
import type { ContractClassPublic, ContractClassPublicWithBlockNumber } from '@aztec/stdlib/contract';
|
|
13
6
|
|
|
14
7
|
/**
|
|
15
8
|
* LMDB-based contract class storage for the archiver.
|
|
@@ -29,11 +22,15 @@ export class ContractClassStore {
|
|
|
29
22
|
blockNumber: number,
|
|
30
23
|
): Promise<void> {
|
|
31
24
|
await this.db.transactionAsync(async () => {
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
const key = contractClass.id.toString();
|
|
26
|
+
if (await this.#contractClasses.hasAsync(key)) {
|
|
27
|
+
throw new Error(`Contract class ${key} already exists, cannot add again at block ${blockNumber}`);
|
|
28
|
+
}
|
|
29
|
+
await this.#contractClasses.set(
|
|
30
|
+
key,
|
|
34
31
|
serializeContractClassPublic({ ...contractClass, l2BlockNumber: blockNumber }),
|
|
35
32
|
);
|
|
36
|
-
await this.#bytecodeCommitments.
|
|
33
|
+
await this.#bytecodeCommitments.set(key, bytecodeCommitment.toBuffer());
|
|
37
34
|
});
|
|
38
35
|
}
|
|
39
36
|
|
|
@@ -60,37 +57,6 @@ export class ContractClassStore {
|
|
|
60
57
|
async getContractClassIds(): Promise<Fr[]> {
|
|
61
58
|
return (await toArray(this.#contractClasses.keysAsync())).map(key => Fr.fromHexString(key));
|
|
62
59
|
}
|
|
63
|
-
|
|
64
|
-
async addFunctions(
|
|
65
|
-
contractClassId: Fr,
|
|
66
|
-
newPrivateFunctions: ExecutablePrivateFunctionWithMembershipProof[],
|
|
67
|
-
newUtilityFunctions: UtilityFunctionWithMembershipProof[],
|
|
68
|
-
): Promise<boolean> {
|
|
69
|
-
await this.db.transactionAsync(async () => {
|
|
70
|
-
const existingClassBuffer = await this.#contractClasses.getAsync(contractClassId.toString());
|
|
71
|
-
if (!existingClassBuffer) {
|
|
72
|
-
throw new Error(`Unknown contract class ${contractClassId} when adding private functions to store`);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const existingClass = deserializeContractClassPublic(existingClassBuffer);
|
|
76
|
-
const { privateFunctions: existingPrivateFns, utilityFunctions: existingUtilityFns } = existingClass;
|
|
77
|
-
|
|
78
|
-
const updatedClass: Omit<ContractClassPublicWithBlockNumber, 'id'> = {
|
|
79
|
-
...existingClass,
|
|
80
|
-
privateFunctions: [
|
|
81
|
-
...existingPrivateFns,
|
|
82
|
-
...newPrivateFunctions.filter(newFn => !existingPrivateFns.some(f => f.selector.equals(newFn.selector))),
|
|
83
|
-
],
|
|
84
|
-
utilityFunctions: [
|
|
85
|
-
...existingUtilityFns,
|
|
86
|
-
...newUtilityFunctions.filter(newFn => !existingUtilityFns.some(f => f.selector.equals(newFn.selector))),
|
|
87
|
-
],
|
|
88
|
-
};
|
|
89
|
-
await this.#contractClasses.set(contractClassId.toString(), serializeContractClassPublic(updatedClass));
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
60
|
}
|
|
95
61
|
|
|
96
62
|
function serializeContractClassPublic(contractClass: Omit<ContractClassPublicWithBlockNumber, 'id'>): Buffer {
|
|
@@ -98,83 +64,19 @@ function serializeContractClassPublic(contractClass: Omit<ContractClassPublicWit
|
|
|
98
64
|
contractClass.l2BlockNumber,
|
|
99
65
|
numToUInt8(contractClass.version),
|
|
100
66
|
contractClass.artifactHash,
|
|
101
|
-
contractClass.privateFunctions.length,
|
|
102
|
-
contractClass.privateFunctions.map(serializePrivateFunction),
|
|
103
|
-
contractClass.utilityFunctions.length,
|
|
104
|
-
contractClass.utilityFunctions.map(serializeUtilityFunction),
|
|
105
67
|
contractClass.packedBytecode.length,
|
|
106
68
|
contractClass.packedBytecode,
|
|
107
69
|
contractClass.privateFunctionsRoot,
|
|
108
70
|
);
|
|
109
71
|
}
|
|
110
72
|
|
|
111
|
-
function serializePrivateFunction(fn: ExecutablePrivateFunctionWithMembershipProof): Buffer {
|
|
112
|
-
return serializeToBuffer(
|
|
113
|
-
fn.selector,
|
|
114
|
-
fn.vkHash,
|
|
115
|
-
fn.bytecode.length,
|
|
116
|
-
fn.bytecode,
|
|
117
|
-
fn.functionMetadataHash,
|
|
118
|
-
fn.artifactMetadataHash,
|
|
119
|
-
fn.utilityFunctionsTreeRoot,
|
|
120
|
-
new Vector(fn.privateFunctionTreeSiblingPath),
|
|
121
|
-
fn.privateFunctionTreeLeafIndex,
|
|
122
|
-
new Vector(fn.artifactTreeSiblingPath),
|
|
123
|
-
fn.artifactTreeLeafIndex,
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function serializeUtilityFunction(fn: UtilityFunctionWithMembershipProof): Buffer {
|
|
128
|
-
return serializeToBuffer(
|
|
129
|
-
fn.selector,
|
|
130
|
-
fn.bytecode.length,
|
|
131
|
-
fn.bytecode,
|
|
132
|
-
fn.functionMetadataHash,
|
|
133
|
-
fn.artifactMetadataHash,
|
|
134
|
-
fn.privateFunctionsArtifactTreeRoot,
|
|
135
|
-
new Vector(fn.artifactTreeSiblingPath),
|
|
136
|
-
fn.artifactTreeLeafIndex,
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
73
|
function deserializeContractClassPublic(buffer: Buffer): Omit<ContractClassPublicWithBlockNumber, 'id'> {
|
|
141
74
|
const reader = BufferReader.asReader(buffer);
|
|
142
75
|
return {
|
|
143
76
|
l2BlockNumber: reader.readNumber(),
|
|
144
77
|
version: reader.readUInt8() as 1,
|
|
145
78
|
artifactHash: reader.readObject(Fr),
|
|
146
|
-
privateFunctions: reader.readVector({ fromBuffer: deserializePrivateFunction }),
|
|
147
|
-
utilityFunctions: reader.readVector({ fromBuffer: deserializeUtilityFunction }),
|
|
148
79
|
packedBytecode: reader.readBuffer(),
|
|
149
80
|
privateFunctionsRoot: reader.readObject(Fr),
|
|
150
81
|
};
|
|
151
82
|
}
|
|
152
|
-
|
|
153
|
-
function deserializePrivateFunction(buffer: Buffer | BufferReader): ExecutablePrivateFunctionWithMembershipProof {
|
|
154
|
-
const reader = BufferReader.asReader(buffer);
|
|
155
|
-
return {
|
|
156
|
-
selector: reader.readObject(FunctionSelector),
|
|
157
|
-
vkHash: reader.readObject(Fr),
|
|
158
|
-
bytecode: reader.readBuffer(),
|
|
159
|
-
functionMetadataHash: reader.readObject(Fr),
|
|
160
|
-
artifactMetadataHash: reader.readObject(Fr),
|
|
161
|
-
utilityFunctionsTreeRoot: reader.readObject(Fr),
|
|
162
|
-
privateFunctionTreeSiblingPath: reader.readVector(Fr),
|
|
163
|
-
privateFunctionTreeLeafIndex: reader.readNumber(),
|
|
164
|
-
artifactTreeSiblingPath: reader.readVector(Fr),
|
|
165
|
-
artifactTreeLeafIndex: reader.readNumber(),
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function deserializeUtilityFunction(buffer: Buffer | BufferReader): UtilityFunctionWithMembershipProof {
|
|
170
|
-
const reader = BufferReader.asReader(buffer);
|
|
171
|
-
return {
|
|
172
|
-
selector: reader.readObject(FunctionSelector),
|
|
173
|
-
bytecode: reader.readBuffer(),
|
|
174
|
-
functionMetadataHash: reader.readObject(Fr),
|
|
175
|
-
artifactMetadataHash: reader.readObject(Fr),
|
|
176
|
-
privateFunctionsArtifactTreeRoot: reader.readObject(Fr),
|
|
177
|
-
artifactTreeSiblingPath: reader.readVector(Fr),
|
|
178
|
-
artifactTreeLeafIndex: reader.readNumber(),
|
|
179
|
-
};
|
|
180
|
-
}
|
|
@@ -27,11 +27,14 @@ export class ContractInstanceStore {
|
|
|
27
27
|
|
|
28
28
|
addContractInstance(contractInstance: ContractInstanceWithAddress, blockNumber: number): Promise<void> {
|
|
29
29
|
return this.db.transactionAsync(async () => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
new
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
const key = contractInstance.address.toString();
|
|
31
|
+
if (await this.#contractInstances.hasAsync(key)) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`Contract instance at ${key} already exists (deployed at block ${await this.#contractInstancePublishedAt.getAsync(key)}), cannot add again at block ${blockNumber}`,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
await this.#contractInstances.set(key, new SerializableContractInstance(contractInstance).toBuffer());
|
|
37
|
+
await this.#contractInstancePublishedAt.set(key, blockNumber);
|
|
35
38
|
});
|
|
36
39
|
}
|
|
37
40
|
|
|
@@ -13,14 +13,19 @@ import {
|
|
|
13
13
|
L2Block,
|
|
14
14
|
type ValidateCheckpointResult,
|
|
15
15
|
} from '@aztec/stdlib/block';
|
|
16
|
-
import type {
|
|
16
|
+
import type {
|
|
17
|
+
CheckpointData,
|
|
18
|
+
CommonCheckpointData,
|
|
19
|
+
ProposedCheckpointData,
|
|
20
|
+
ProposedCheckpointInput,
|
|
21
|
+
PublishedCheckpoint,
|
|
22
|
+
} from '@aztec/stdlib/checkpoint';
|
|
17
23
|
import type {
|
|
18
24
|
ContractClassPublic,
|
|
25
|
+
ContractClassPublicWithCommitment,
|
|
19
26
|
ContractDataSource,
|
|
20
27
|
ContractInstanceUpdateWithAddress,
|
|
21
28
|
ContractInstanceWithAddress,
|
|
22
|
-
ExecutablePrivateFunctionWithMembershipProof,
|
|
23
|
-
UtilityFunctionWithMembershipProof,
|
|
24
29
|
} from '@aztec/stdlib/contract';
|
|
25
30
|
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
26
31
|
import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
|
|
@@ -37,7 +42,7 @@ import { ContractInstanceStore } from './contract_instance_store.js';
|
|
|
37
42
|
import { LogStore } from './log_store.js';
|
|
38
43
|
import { MessageStore } from './message_store.js';
|
|
39
44
|
|
|
40
|
-
export const ARCHIVER_DB_VERSION =
|
|
45
|
+
export const ARCHIVER_DB_VERSION = 6;
|
|
41
46
|
export const MAX_FUNCTION_SIGNATURES = 1000;
|
|
42
47
|
export const MAX_FUNCTION_NAME_LEN = 256;
|
|
43
48
|
|
|
@@ -71,9 +76,8 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
71
76
|
constructor(
|
|
72
77
|
private db: AztecAsyncKVStore,
|
|
73
78
|
logsMaxPageSize: number = 1000,
|
|
74
|
-
l1Constants: Pick<L1RollupConstants, 'epochDuration'>,
|
|
75
79
|
) {
|
|
76
|
-
this.#blockStore = new BlockStore(db
|
|
80
|
+
this.#blockStore = new BlockStore(db);
|
|
77
81
|
this.#logStore = new LogStore(db, this.#blockStore, logsMaxPageSize);
|
|
78
82
|
this.#messageStore = new MessageStore(db);
|
|
79
83
|
this.#contractClassStore = new ContractClassStore(db);
|
|
@@ -168,19 +172,14 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
168
172
|
|
|
169
173
|
/**
|
|
170
174
|
* Add new contract classes from an L2 block to the store's list.
|
|
171
|
-
* @param data - List of contract classes to be added.
|
|
172
|
-
* @param bytecodeCommitments - Bytecode commitments for the contract classes.
|
|
175
|
+
* @param data - List of contract classes (with bytecode commitments) to be added.
|
|
173
176
|
* @param blockNumber - Number of the L2 block the contracts were registered in.
|
|
174
177
|
* @returns True if the operation is successful.
|
|
175
178
|
*/
|
|
176
|
-
async addContractClasses(
|
|
177
|
-
data: ContractClassPublic[],
|
|
178
|
-
bytecodeCommitments: Fr[],
|
|
179
|
-
blockNumber: BlockNumber,
|
|
180
|
-
): Promise<boolean> {
|
|
179
|
+
async addContractClasses(data: ContractClassPublicWithCommitment[], blockNumber: BlockNumber): Promise<boolean> {
|
|
181
180
|
return (
|
|
182
181
|
await Promise.all(
|
|
183
|
-
data.map(
|
|
182
|
+
data.map(c => this.#contractClassStore.addContractClass(c, c.publicBytecodeCommitment, blockNumber)),
|
|
184
183
|
)
|
|
185
184
|
).every(Boolean);
|
|
186
185
|
}
|
|
@@ -195,15 +194,6 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
195
194
|
return this.#contractClassStore.getBytecodeCommitment(contractClassId);
|
|
196
195
|
}
|
|
197
196
|
|
|
198
|
-
/** Adds private functions to a contract class. */
|
|
199
|
-
addFunctions(
|
|
200
|
-
contractClassId: Fr,
|
|
201
|
-
privateFunctions: ExecutablePrivateFunctionWithMembershipProof[],
|
|
202
|
-
utilityFunctions: UtilityFunctionWithMembershipProof[],
|
|
203
|
-
): Promise<boolean> {
|
|
204
|
-
return this.#contractClassStore.addFunctions(contractClassId, privateFunctions, utilityFunctions);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
197
|
/**
|
|
208
198
|
* Add new contract instances from an L2 block to the store's list.
|
|
209
199
|
* @param data - List of contract instances to be added.
|
|
@@ -246,14 +236,14 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
246
236
|
}
|
|
247
237
|
|
|
248
238
|
/**
|
|
249
|
-
* Append new proposed
|
|
250
|
-
*
|
|
239
|
+
* Append a new proposed block to the store.
|
|
240
|
+
* This is an uncheckpointed block that has been proposed by the sequencer but not yet included in a checkpoint on L1.
|
|
251
241
|
* For checkpointed blocks (already published to L1), use addCheckpoints() instead.
|
|
252
|
-
* @param
|
|
242
|
+
* @param block - The proposed L2 block to be added to the store.
|
|
253
243
|
* @returns True if the operation is successful.
|
|
254
244
|
*/
|
|
255
|
-
|
|
256
|
-
return this.#blockStore.
|
|
245
|
+
addProposedBlock(block: L2Block, opts: { force?: boolean } = {}): Promise<boolean> {
|
|
246
|
+
return this.#blockStore.addProposedBlock(block, opts);
|
|
257
247
|
}
|
|
258
248
|
|
|
259
249
|
/**
|
|
@@ -270,7 +260,7 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
270
260
|
* @returns The number of the latest block
|
|
271
261
|
*/
|
|
272
262
|
getLatestBlockNumber(): Promise<BlockNumber> {
|
|
273
|
-
return this.#blockStore.
|
|
263
|
+
return this.#blockStore.getLatestL2BlockNumber();
|
|
274
264
|
}
|
|
275
265
|
|
|
276
266
|
/**
|
|
@@ -410,8 +400,11 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
410
400
|
* @param txHash - The hash of a tx we try to get the receipt for.
|
|
411
401
|
* @returns The requested tx receipt (or undefined if not found).
|
|
412
402
|
*/
|
|
413
|
-
getSettledTxReceipt(
|
|
414
|
-
|
|
403
|
+
getSettledTxReceipt(
|
|
404
|
+
txHash: TxHash,
|
|
405
|
+
l1Constants?: Pick<L1RollupConstants, 'epochDuration'>,
|
|
406
|
+
): Promise<TxReceipt | undefined> {
|
|
407
|
+
return this.#blockStore.getSettledTxReceipt(txHash, l1Constants);
|
|
415
408
|
}
|
|
416
409
|
|
|
417
410
|
/**
|
|
@@ -472,10 +465,11 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
472
465
|
* array implies no logs match that tag.
|
|
473
466
|
* @param tags - The tags to search for.
|
|
474
467
|
* @param page - The page number (0-indexed) for pagination. Returns at most 10 logs per tag per page.
|
|
468
|
+
* @param upToBlockNumber - If set, only return logs from blocks up to and including this block number.
|
|
475
469
|
*/
|
|
476
|
-
getPrivateLogsByTags(tags: SiloedTag[], page?: number): Promise<TxScopedL2Log[][]> {
|
|
470
|
+
getPrivateLogsByTags(tags: SiloedTag[], page?: number, upToBlockNumber?: BlockNumber): Promise<TxScopedL2Log[][]> {
|
|
477
471
|
try {
|
|
478
|
-
return this.#logStore.getPrivateLogsByTags(tags, page);
|
|
472
|
+
return this.#logStore.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
479
473
|
} catch (err) {
|
|
480
474
|
return Promise.reject(err);
|
|
481
475
|
}
|
|
@@ -487,14 +481,16 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
487
481
|
* @param contractAddress - The contract address to search logs for.
|
|
488
482
|
* @param tags - The tags to search for.
|
|
489
483
|
* @param page - The page number (0-indexed) for pagination. Returns at most 10 logs per tag per page.
|
|
484
|
+
* @param upToBlockNumber - If set, only return logs from blocks up to and including this block number.
|
|
490
485
|
*/
|
|
491
486
|
getPublicLogsByTagsFromContract(
|
|
492
487
|
contractAddress: AztecAddress,
|
|
493
488
|
tags: Tag[],
|
|
494
489
|
page?: number,
|
|
490
|
+
upToBlockNumber?: BlockNumber,
|
|
495
491
|
): Promise<TxScopedL2Log[][]> {
|
|
496
492
|
try {
|
|
497
|
-
return this.#logStore.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
493
|
+
return this.#logStore.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
498
494
|
} catch (err) {
|
|
499
495
|
return Promise.reject(err);
|
|
500
496
|
}
|
|
@@ -542,15 +538,24 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
542
538
|
await this.#blockStore.setProvenCheckpointNumber(checkpointNumber);
|
|
543
539
|
}
|
|
544
540
|
|
|
545
|
-
|
|
546
|
-
|
|
541
|
+
/**
|
|
542
|
+
* Gets the number of the latest finalized checkpoint processed.
|
|
543
|
+
* @returns The number of the latest finalized checkpoint processed.
|
|
544
|
+
*/
|
|
545
|
+
getFinalizedCheckpointNumber(): Promise<CheckpointNumber> {
|
|
546
|
+
return this.#blockStore.getFinalizedCheckpointNumber();
|
|
547
547
|
}
|
|
548
548
|
|
|
549
549
|
/**
|
|
550
|
-
* Stores the
|
|
550
|
+
* Stores the number of the latest finalized checkpoint processed.
|
|
551
|
+
* @param checkpointNumber - The number of the latest finalized checkpoint processed.
|
|
551
552
|
*/
|
|
552
|
-
async
|
|
553
|
-
await this.#
|
|
553
|
+
async setFinalizedCheckpointNumber(checkpointNumber: CheckpointNumber) {
|
|
554
|
+
await this.#blockStore.setFinalizedCheckpointNumber(checkpointNumber);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
async setBlockSynchedL1BlockNumber(l1BlockNumber: bigint) {
|
|
558
|
+
await this.#blockStore.setSynchedL1BlockNumber(l1BlockNumber);
|
|
554
559
|
}
|
|
555
560
|
|
|
556
561
|
/**
|
|
@@ -585,6 +590,11 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
585
590
|
return this.#messageStore.rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber);
|
|
586
591
|
}
|
|
587
592
|
|
|
593
|
+
/** Atomically updates the message sync state: the L1 sync point and the inbox tree-in-progress marker. */
|
|
594
|
+
public setMessageSyncState(l1Block: L1BlockId, treeInProgress: bigint | undefined): Promise<void> {
|
|
595
|
+
return this.#messageStore.setMessageSyncState(l1Block, treeInProgress);
|
|
596
|
+
}
|
|
597
|
+
|
|
588
598
|
/** Returns an async iterator to all L1 to L2 messages on the range. */
|
|
589
599
|
public iterateL1ToL2Messages(range: CustomRange<bigint> = {}): AsyncIterableIterator<InboxMessage> {
|
|
590
600
|
return this.#messageStore.iterateL1ToL2Messages(range);
|
|
@@ -605,6 +615,38 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
605
615
|
return this.#blockStore.setPendingChainValidationStatus(status);
|
|
606
616
|
}
|
|
607
617
|
|
|
618
|
+
/**
|
|
619
|
+
* Gets the L2 block number of the proposed checkpoint.
|
|
620
|
+
* @returns The block number of the proposed checkpoint, or the checkpointed block number if none.
|
|
621
|
+
*/
|
|
622
|
+
public getProposedCheckpointL2BlockNumber(): Promise<BlockNumber> {
|
|
623
|
+
return this.#blockStore.getProposedCheckpointL2BlockNumber();
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
/** Returns the checkpoint data at the proposed tip */
|
|
627
|
+
public getProposedCheckpoint(): Promise<CommonCheckpointData | undefined> {
|
|
628
|
+
return this.#blockStore.getProposedCheckpoint();
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/** Returns the proposed checkpoint data, or undefined if no proposed checkpoint exists. No fallback to confirmed. */
|
|
632
|
+
public getProposedCheckpointOnly(): Promise<ProposedCheckpointData | undefined> {
|
|
633
|
+
return this.#blockStore.getProposedCheckpointOnly();
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* Set proposed checkpoint
|
|
638
|
+
* @param proposedCheckpoint
|
|
639
|
+
* @returns
|
|
640
|
+
*/
|
|
641
|
+
public setProposedCheckpoint(proposedCheckpoint: ProposedCheckpointInput): Promise<void> {
|
|
642
|
+
return this.#blockStore.setProposedCheckpoint(proposedCheckpoint);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
/** Deletes the proposed checkpoint from storage. */
|
|
646
|
+
public deleteProposedCheckpoint(): Promise<void> {
|
|
647
|
+
return this.#blockStore.deleteProposedCheckpoint();
|
|
648
|
+
}
|
|
649
|
+
|
|
608
650
|
/**
|
|
609
651
|
* Gets the number of the latest L2 block processed.
|
|
610
652
|
* @returns The number of the latest L2 block processed.
|
|
@@ -26,9 +26,16 @@ export class L2TipsCache {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
private async loadFromStore(): Promise<L2Tips> {
|
|
29
|
-
const [
|
|
30
|
-
|
|
29
|
+
const [
|
|
30
|
+
latestBlockNumber,
|
|
31
|
+
provenBlockNumber,
|
|
32
|
+
proposedCheckpointBlockNumber,
|
|
33
|
+
checkpointedBlockNumber,
|
|
34
|
+
finalizedBlockNumber,
|
|
35
|
+
] = await Promise.all([
|
|
36
|
+
this.blockStore.getLatestL2BlockNumber(),
|
|
31
37
|
this.blockStore.getProvenBlockNumber(),
|
|
38
|
+
this.blockStore.getProposedCheckpointL2BlockNumber(),
|
|
32
39
|
this.blockStore.getCheckpointedL2BlockNumber(),
|
|
33
40
|
this.blockStore.getFinalizedL2BlockNumber(),
|
|
34
41
|
]);
|
|
@@ -42,19 +49,34 @@ export class L2TipsCache {
|
|
|
42
49
|
const getBlockData = (blockNumber: BlockNumber) =>
|
|
43
50
|
blockNumber > beforeInitialBlockNumber ? this.blockStore.getBlockData(blockNumber) : genesisBlockHeader;
|
|
44
51
|
|
|
45
|
-
const [latestBlockData, provenBlockData, checkpointedBlockData, finalizedBlockData] =
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
const [latestBlockData, provenBlockData, proposedCheckpointBlockData, checkpointedBlockData, finalizedBlockData] =
|
|
53
|
+
await Promise.all(
|
|
54
|
+
[
|
|
55
|
+
latestBlockNumber,
|
|
56
|
+
provenBlockNumber,
|
|
57
|
+
proposedCheckpointBlockNumber,
|
|
58
|
+
checkpointedBlockNumber,
|
|
59
|
+
finalizedBlockNumber,
|
|
60
|
+
].map(getBlockData),
|
|
61
|
+
);
|
|
48
62
|
|
|
49
|
-
if (
|
|
63
|
+
if (
|
|
64
|
+
!latestBlockData ||
|
|
65
|
+
!provenBlockData ||
|
|
66
|
+
!finalizedBlockData ||
|
|
67
|
+
!checkpointedBlockData ||
|
|
68
|
+
!proposedCheckpointBlockData
|
|
69
|
+
) {
|
|
50
70
|
throw new Error('Failed to load block data for L2 tips');
|
|
51
71
|
}
|
|
52
72
|
|
|
53
|
-
const [provenCheckpointId, finalizedCheckpointId, checkpointedCheckpointId] =
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
73
|
+
const [provenCheckpointId, finalizedCheckpointId, proposedCheckpointId, checkpointedCheckpointId] =
|
|
74
|
+
await Promise.all([
|
|
75
|
+
this.getCheckpointIdForBlock(provenBlockData),
|
|
76
|
+
this.getCheckpointIdForBlock(finalizedBlockData),
|
|
77
|
+
this.getCheckpointIdForProposedCheckpoint(checkpointedBlockData),
|
|
78
|
+
this.getCheckpointIdForBlock(checkpointedBlockData),
|
|
79
|
+
]);
|
|
58
80
|
|
|
59
81
|
return {
|
|
60
82
|
proposed: { number: latestBlockNumber, hash: latestBlockData.blockHash.toString() },
|
|
@@ -62,6 +84,10 @@ export class L2TipsCache {
|
|
|
62
84
|
block: { number: provenBlockNumber, hash: provenBlockData.blockHash.toString() },
|
|
63
85
|
checkpoint: provenCheckpointId,
|
|
64
86
|
},
|
|
87
|
+
proposedCheckpoint: {
|
|
88
|
+
block: { number: proposedCheckpointBlockNumber, hash: proposedCheckpointBlockData.blockHash.toString() },
|
|
89
|
+
checkpoint: proposedCheckpointId,
|
|
90
|
+
},
|
|
65
91
|
finalized: {
|
|
66
92
|
block: { number: finalizedBlockNumber, hash: finalizedBlockData.blockHash.toString() },
|
|
67
93
|
checkpoint: finalizedCheckpointId,
|
|
@@ -73,6 +99,19 @@ export class L2TipsCache {
|
|
|
73
99
|
};
|
|
74
100
|
}
|
|
75
101
|
|
|
102
|
+
private async getCheckpointIdForProposedCheckpoint(
|
|
103
|
+
checkpointedBlockData: Pick<BlockData, 'checkpointNumber'>,
|
|
104
|
+
): Promise<CheckpointId> {
|
|
105
|
+
const checkpointData = await this.blockStore.getProposedCheckpointOnly();
|
|
106
|
+
if (!checkpointData) {
|
|
107
|
+
return this.getCheckpointIdForBlock(checkpointedBlockData);
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
number: checkpointData.checkpointNumber,
|
|
111
|
+
hash: checkpointData.header.hash().toString(),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
76
115
|
private async getCheckpointIdForBlock(blockData: Pick<BlockData, 'checkpointNumber'>): Promise<CheckpointId> {
|
|
77
116
|
const checkpointData = await this.blockStore.getCheckpointData(blockData.checkpointNumber);
|
|
78
117
|
if (!checkpointData) {
|