@aztec/archiver 0.0.1-commit.b1c78909e → 0.0.1-commit.b2a5d0dd1
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 +7 -5
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +39 -15
- package/dest/config.d.ts +5 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +15 -3
- package/dest/errors.d.ts +44 -2
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +58 -2
- package/dest/factory.d.ts +2 -2
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +18 -14
- package/dest/index.d.ts +3 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -1
- 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 +19 -10
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +25 -32
- package/dest/l1/validate_historical_logs.d.ts +23 -0
- package/dest/l1/validate_historical_logs.d.ts.map +1 -0
- package/dest/l1/validate_historical_logs.js +108 -0
- package/dest/modules/data_source_base.d.ts +6 -4
- 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 +15 -10
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +69 -68
- package/dest/modules/instrumentation.d.ts +7 -2
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +22 -6
- package/dest/modules/l1_synchronizer.d.ts +6 -2
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +244 -146
- 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 +49 -6
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +277 -67
- 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 +39 -18
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +45 -20
- 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 +27 -7
- 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 +95 -20
- 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 +14 -3
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +63 -10
- 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 +7 -2
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +30 -5
- package/dest/test/noop_l1_archiver.d.ts +1 -1
- package/dest/test/noop_l1_archiver.d.ts.map +1 -1
- package/dest/test/noop_l1_archiver.js +4 -2
- package/package.json +13 -13
- package/src/archiver.ts +57 -18
- package/src/config.ts +22 -2
- package/src/errors.ts +94 -2
- package/src/factory.ts +18 -10
- package/src/index.ts +2 -1
- package/src/l1/calldata_retriever.ts +2 -1
- package/src/l1/data_retrieval.ts +36 -45
- package/src/l1/validate_historical_logs.ts +140 -0
- package/src/modules/data_source_base.ts +24 -5
- package/src/modules/data_store_updater.ts +94 -97
- package/src/modules/instrumentation.ts +27 -7
- package/src/modules/l1_synchronizer.ts +314 -177
- package/src/modules/validation.ts +2 -2
- package/src/store/block_store.ts +364 -76
- 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 +77 -34
- package/src/store/l2_tips_cache.ts +58 -13
- package/src/store/log_store.ts +128 -32
- package/src/store/message_store.ts +26 -9
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +87 -15
- package/src/test/mock_l1_to_l2_message_source.ts +1 -0
- package/src/test/mock_l2_block_source.ts +44 -3
- package/src/test/noop_l1_archiver.ts +3 -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
|
|
|
@@ -10,18 +10,26 @@ import {
|
|
|
10
10
|
type BlockData,
|
|
11
11
|
BlockHash,
|
|
12
12
|
CheckpointedL2Block,
|
|
13
|
+
type CommitteeAttestation,
|
|
13
14
|
L2Block,
|
|
14
15
|
type ValidateCheckpointResult,
|
|
15
16
|
} from '@aztec/stdlib/block';
|
|
16
|
-
import type {
|
|
17
|
+
import type {
|
|
18
|
+
CheckpointData,
|
|
19
|
+
CommonCheckpointData,
|
|
20
|
+
L1PublishedData,
|
|
21
|
+
ProposedCheckpointData,
|
|
22
|
+
ProposedCheckpointInput,
|
|
23
|
+
PublishedCheckpoint,
|
|
24
|
+
} from '@aztec/stdlib/checkpoint';
|
|
17
25
|
import type {
|
|
18
26
|
ContractClassPublic,
|
|
27
|
+
ContractClassPublicWithCommitment,
|
|
19
28
|
ContractDataSource,
|
|
20
29
|
ContractInstanceUpdateWithAddress,
|
|
21
30
|
ContractInstanceWithAddress,
|
|
22
|
-
ExecutablePrivateFunctionWithMembershipProof,
|
|
23
|
-
UtilityFunctionWithMembershipProof,
|
|
24
31
|
} from '@aztec/stdlib/contract';
|
|
32
|
+
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
25
33
|
import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
|
|
26
34
|
import type { LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
27
35
|
import type { BlockHeader, TxHash, TxReceipt } from '@aztec/stdlib/tx';
|
|
@@ -36,7 +44,7 @@ import { ContractInstanceStore } from './contract_instance_store.js';
|
|
|
36
44
|
import { LogStore } from './log_store.js';
|
|
37
45
|
import { MessageStore } from './message_store.js';
|
|
38
46
|
|
|
39
|
-
export const ARCHIVER_DB_VERSION =
|
|
47
|
+
export const ARCHIVER_DB_VERSION = 6;
|
|
40
48
|
export const MAX_FUNCTION_SIGNATURES = 1000;
|
|
41
49
|
export const MAX_FUNCTION_NAME_LEN = 256;
|
|
42
50
|
|
|
@@ -166,19 +174,14 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
166
174
|
|
|
167
175
|
/**
|
|
168
176
|
* Add new contract classes from an L2 block to the store's list.
|
|
169
|
-
* @param data - List of contract classes to be added.
|
|
170
|
-
* @param bytecodeCommitments - Bytecode commitments for the contract classes.
|
|
177
|
+
* @param data - List of contract classes (with bytecode commitments) to be added.
|
|
171
178
|
* @param blockNumber - Number of the L2 block the contracts were registered in.
|
|
172
179
|
* @returns True if the operation is successful.
|
|
173
180
|
*/
|
|
174
|
-
async addContractClasses(
|
|
175
|
-
data: ContractClassPublic[],
|
|
176
|
-
bytecodeCommitments: Fr[],
|
|
177
|
-
blockNumber: BlockNumber,
|
|
178
|
-
): Promise<boolean> {
|
|
181
|
+
async addContractClasses(data: ContractClassPublicWithCommitment[], blockNumber: BlockNumber): Promise<boolean> {
|
|
179
182
|
return (
|
|
180
183
|
await Promise.all(
|
|
181
|
-
data.map(
|
|
184
|
+
data.map(c => this.#contractClassStore.addContractClass(c, c.publicBytecodeCommitment, blockNumber)),
|
|
182
185
|
)
|
|
183
186
|
).every(Boolean);
|
|
184
187
|
}
|
|
@@ -193,15 +196,6 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
193
196
|
return this.#contractClassStore.getBytecodeCommitment(contractClassId);
|
|
194
197
|
}
|
|
195
198
|
|
|
196
|
-
/** Adds private functions to a contract class. */
|
|
197
|
-
addFunctions(
|
|
198
|
-
contractClassId: Fr,
|
|
199
|
-
privateFunctions: ExecutablePrivateFunctionWithMembershipProof[],
|
|
200
|
-
utilityFunctions: UtilityFunctionWithMembershipProof[],
|
|
201
|
-
): Promise<boolean> {
|
|
202
|
-
return this.#contractClassStore.addFunctions(contractClassId, privateFunctions, utilityFunctions);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
199
|
/**
|
|
206
200
|
* Add new contract instances from an L2 block to the store's list.
|
|
207
201
|
* @param data - List of contract instances to be added.
|
|
@@ -268,7 +262,7 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
268
262
|
* @returns The number of the latest block
|
|
269
263
|
*/
|
|
270
264
|
getLatestBlockNumber(): Promise<BlockNumber> {
|
|
271
|
-
return this.#blockStore.
|
|
265
|
+
return this.#blockStore.getLatestL2BlockNumber();
|
|
272
266
|
}
|
|
273
267
|
|
|
274
268
|
/**
|
|
@@ -408,8 +402,11 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
408
402
|
* @param txHash - The hash of a tx we try to get the receipt for.
|
|
409
403
|
* @returns The requested tx receipt (or undefined if not found).
|
|
410
404
|
*/
|
|
411
|
-
getSettledTxReceipt(
|
|
412
|
-
|
|
405
|
+
getSettledTxReceipt(
|
|
406
|
+
txHash: TxHash,
|
|
407
|
+
l1Constants?: Pick<L1RollupConstants, 'epochDuration'>,
|
|
408
|
+
): Promise<TxReceipt | undefined> {
|
|
409
|
+
return this.#blockStore.getSettledTxReceipt(txHash, l1Constants);
|
|
413
410
|
}
|
|
414
411
|
|
|
415
412
|
/**
|
|
@@ -470,10 +467,11 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
470
467
|
* array implies no logs match that tag.
|
|
471
468
|
* @param tags - The tags to search for.
|
|
472
469
|
* @param page - The page number (0-indexed) for pagination. Returns at most 10 logs per tag per page.
|
|
470
|
+
* @param upToBlockNumber - If set, only return logs from blocks up to and including this block number.
|
|
473
471
|
*/
|
|
474
|
-
getPrivateLogsByTags(tags: SiloedTag[], page?: number): Promise<TxScopedL2Log[][]> {
|
|
472
|
+
getPrivateLogsByTags(tags: SiloedTag[], page?: number, upToBlockNumber?: BlockNumber): Promise<TxScopedL2Log[][]> {
|
|
475
473
|
try {
|
|
476
|
-
return this.#logStore.getPrivateLogsByTags(tags, page);
|
|
474
|
+
return this.#logStore.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
477
475
|
} catch (err) {
|
|
478
476
|
return Promise.reject(err);
|
|
479
477
|
}
|
|
@@ -485,14 +483,16 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
485
483
|
* @param contractAddress - The contract address to search logs for.
|
|
486
484
|
* @param tags - The tags to search for.
|
|
487
485
|
* @param page - The page number (0-indexed) for pagination. Returns at most 10 logs per tag per page.
|
|
486
|
+
* @param upToBlockNumber - If set, only return logs from blocks up to and including this block number.
|
|
488
487
|
*/
|
|
489
488
|
getPublicLogsByTagsFromContract(
|
|
490
489
|
contractAddress: AztecAddress,
|
|
491
490
|
tags: Tag[],
|
|
492
491
|
page?: number,
|
|
492
|
+
upToBlockNumber?: BlockNumber,
|
|
493
493
|
): Promise<TxScopedL2Log[][]> {
|
|
494
494
|
try {
|
|
495
|
-
return this.#logStore.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
495
|
+
return this.#logStore.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
496
496
|
} catch (err) {
|
|
497
497
|
return Promise.reject(err);
|
|
498
498
|
}
|
|
@@ -560,13 +560,6 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
560
560
|
await this.#blockStore.setSynchedL1BlockNumber(l1BlockNumber);
|
|
561
561
|
}
|
|
562
562
|
|
|
563
|
-
/**
|
|
564
|
-
* Stores the l1 block that messages have been synched until
|
|
565
|
-
*/
|
|
566
|
-
async setMessageSynchedL1Block(l1Block: L1BlockId) {
|
|
567
|
-
await this.#messageStore.setSynchedL1Block(l1Block);
|
|
568
|
-
}
|
|
569
|
-
|
|
570
563
|
/**
|
|
571
564
|
* Returns the number of the most recent proven block
|
|
572
565
|
* @returns The number of the most recent proven block
|
|
@@ -599,6 +592,11 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
599
592
|
return this.#messageStore.rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber);
|
|
600
593
|
}
|
|
601
594
|
|
|
595
|
+
/** Atomically updates the message sync state: the L1 sync point and the inbox tree-in-progress marker. */
|
|
596
|
+
public setMessageSyncState(l1Block: L1BlockId, treeInProgress: bigint | undefined): Promise<void> {
|
|
597
|
+
return this.#messageStore.setMessageSyncState(l1Block, treeInProgress);
|
|
598
|
+
}
|
|
599
|
+
|
|
602
600
|
/** Returns an async iterator to all L1 to L2 messages on the range. */
|
|
603
601
|
public iterateL1ToL2Messages(range: CustomRange<bigint> = {}): AsyncIterableIterator<InboxMessage> {
|
|
604
602
|
return this.#messageStore.iterateL1ToL2Messages(range);
|
|
@@ -619,6 +617,51 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
619
617
|
return this.#blockStore.setPendingChainValidationStatus(status);
|
|
620
618
|
}
|
|
621
619
|
|
|
620
|
+
/**
|
|
621
|
+
* Gets the L2 block number of the proposed checkpoint.
|
|
622
|
+
* @returns The block number of the proposed checkpoint, or the checkpointed block number if none.
|
|
623
|
+
*/
|
|
624
|
+
public getProposedCheckpointL2BlockNumber(): Promise<BlockNumber> {
|
|
625
|
+
return this.#blockStore.getProposedCheckpointL2BlockNumber();
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
/** Returns the checkpoint data at the proposed tip */
|
|
629
|
+
public getProposedCheckpoint(): Promise<CommonCheckpointData | undefined> {
|
|
630
|
+
return this.#blockStore.getProposedCheckpoint();
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/** Returns the proposed checkpoint data, or undefined if no proposed checkpoint exists. No fallback to confirmed. */
|
|
634
|
+
public getProposedCheckpointOnly(): Promise<ProposedCheckpointData | undefined> {
|
|
635
|
+
return this.#blockStore.getProposedCheckpointOnly();
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* Set proposed checkpoint
|
|
640
|
+
* @param proposedCheckpoint
|
|
641
|
+
* @returns
|
|
642
|
+
*/
|
|
643
|
+
public setProposedCheckpoint(proposedCheckpoint: ProposedCheckpointInput): Promise<void> {
|
|
644
|
+
return this.#blockStore.setProposedCheckpoint(proposedCheckpoint);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/** Deletes the proposed checkpoint from storage. */
|
|
648
|
+
public deleteProposedCheckpoint(): Promise<void> {
|
|
649
|
+
return this.#blockStore.deleteProposedCheckpoint();
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* Promotes the proposed checkpoint to a confirmed checkpoint entry.
|
|
654
|
+
* Should only be called after the checkpoint has been validated.
|
|
655
|
+
* @param expectedArchiveRoot - The archive root to match against the proposed checkpoint, to guard against races.
|
|
656
|
+
*/
|
|
657
|
+
public promoteProposedToCheckpointed(
|
|
658
|
+
l1: L1PublishedData,
|
|
659
|
+
attestations: CommitteeAttestation[],
|
|
660
|
+
expectedArchiveRoot: Fr,
|
|
661
|
+
): Promise<void> {
|
|
662
|
+
return this.#blockStore.promoteProposedToCheckpointed(l1, attestations, expectedArchiveRoot);
|
|
663
|
+
}
|
|
664
|
+
|
|
622
665
|
/**
|
|
623
666
|
* Gets the number of the latest L2 block processed.
|
|
624
667
|
* @returns The number of the latest L2 block processed.
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
2
2
|
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
type BlockData,
|
|
5
|
+
type CheckpointId,
|
|
6
|
+
GENESIS_BLOCK_HEADER_HASH,
|
|
7
|
+
GENESIS_CHECKPOINT_HEADER_HASH,
|
|
8
|
+
type L2Tips,
|
|
9
|
+
} from '@aztec/stdlib/block';
|
|
4
10
|
|
|
5
11
|
import type { BlockStore } from './block_store.js';
|
|
6
12
|
|
|
@@ -26,9 +32,16 @@ export class L2TipsCache {
|
|
|
26
32
|
}
|
|
27
33
|
|
|
28
34
|
private async loadFromStore(): Promise<L2Tips> {
|
|
29
|
-
const [
|
|
30
|
-
|
|
35
|
+
const [
|
|
36
|
+
latestBlockNumber,
|
|
37
|
+
provenBlockNumber,
|
|
38
|
+
proposedCheckpointBlockNumber,
|
|
39
|
+
checkpointedBlockNumber,
|
|
40
|
+
finalizedBlockNumber,
|
|
41
|
+
] = await Promise.all([
|
|
42
|
+
this.blockStore.getLatestL2BlockNumber(),
|
|
31
43
|
this.blockStore.getProvenBlockNumber(),
|
|
44
|
+
this.blockStore.getProposedCheckpointL2BlockNumber(),
|
|
32
45
|
this.blockStore.getCheckpointedL2BlockNumber(),
|
|
33
46
|
this.blockStore.getFinalizedL2BlockNumber(),
|
|
34
47
|
]);
|
|
@@ -42,19 +55,34 @@ export class L2TipsCache {
|
|
|
42
55
|
const getBlockData = (blockNumber: BlockNumber) =>
|
|
43
56
|
blockNumber > beforeInitialBlockNumber ? this.blockStore.getBlockData(blockNumber) : genesisBlockHeader;
|
|
44
57
|
|
|
45
|
-
const [latestBlockData, provenBlockData, checkpointedBlockData, finalizedBlockData] =
|
|
46
|
-
|
|
47
|
-
|
|
58
|
+
const [latestBlockData, provenBlockData, proposedCheckpointBlockData, checkpointedBlockData, finalizedBlockData] =
|
|
59
|
+
await Promise.all(
|
|
60
|
+
[
|
|
61
|
+
latestBlockNumber,
|
|
62
|
+
provenBlockNumber,
|
|
63
|
+
proposedCheckpointBlockNumber,
|
|
64
|
+
checkpointedBlockNumber,
|
|
65
|
+
finalizedBlockNumber,
|
|
66
|
+
].map(getBlockData),
|
|
67
|
+
);
|
|
48
68
|
|
|
49
|
-
if (
|
|
69
|
+
if (
|
|
70
|
+
!latestBlockData ||
|
|
71
|
+
!provenBlockData ||
|
|
72
|
+
!finalizedBlockData ||
|
|
73
|
+
!checkpointedBlockData ||
|
|
74
|
+
!proposedCheckpointBlockData
|
|
75
|
+
) {
|
|
50
76
|
throw new Error('Failed to load block data for L2 tips');
|
|
51
77
|
}
|
|
52
78
|
|
|
53
|
-
const [provenCheckpointId, finalizedCheckpointId, checkpointedCheckpointId] =
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
79
|
+
const [provenCheckpointId, finalizedCheckpointId, proposedCheckpointId, checkpointedCheckpointId] =
|
|
80
|
+
await Promise.all([
|
|
81
|
+
this.getCheckpointIdForBlock(provenBlockData),
|
|
82
|
+
this.getCheckpointIdForBlock(finalizedBlockData),
|
|
83
|
+
this.getCheckpointIdForProposedCheckpoint(checkpointedBlockData),
|
|
84
|
+
this.getCheckpointIdForBlock(checkpointedBlockData),
|
|
85
|
+
]);
|
|
58
86
|
|
|
59
87
|
return {
|
|
60
88
|
proposed: { number: latestBlockNumber, hash: latestBlockData.blockHash.toString() },
|
|
@@ -62,6 +90,10 @@ export class L2TipsCache {
|
|
|
62
90
|
block: { number: provenBlockNumber, hash: provenBlockData.blockHash.toString() },
|
|
63
91
|
checkpoint: provenCheckpointId,
|
|
64
92
|
},
|
|
93
|
+
proposedCheckpoint: {
|
|
94
|
+
block: { number: proposedCheckpointBlockNumber, hash: proposedCheckpointBlockData.blockHash.toString() },
|
|
95
|
+
checkpoint: proposedCheckpointId,
|
|
96
|
+
},
|
|
65
97
|
finalized: {
|
|
66
98
|
block: { number: finalizedBlockNumber, hash: finalizedBlockData.blockHash.toString() },
|
|
67
99
|
checkpoint: finalizedCheckpointId,
|
|
@@ -73,6 +105,19 @@ export class L2TipsCache {
|
|
|
73
105
|
};
|
|
74
106
|
}
|
|
75
107
|
|
|
108
|
+
private async getCheckpointIdForProposedCheckpoint(
|
|
109
|
+
checkpointedBlockData: Pick<BlockData, 'checkpointNumber'>,
|
|
110
|
+
): Promise<CheckpointId> {
|
|
111
|
+
const checkpointData = await this.blockStore.getProposedCheckpointOnly();
|
|
112
|
+
if (!checkpointData) {
|
|
113
|
+
return this.getCheckpointIdForBlock(checkpointedBlockData);
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
number: checkpointData.checkpointNumber,
|
|
117
|
+
hash: checkpointData.header.hash().toString(),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
76
121
|
private async getCheckpointIdForBlock(blockData: Pick<BlockData, 'checkpointNumber'>): Promise<CheckpointId> {
|
|
77
122
|
const checkpointData = await this.blockStore.getCheckpointData(blockData.checkpointNumber);
|
|
78
123
|
if (!checkpointData) {
|