@aztec/archiver 0.0.1-commit.d431d1c → 0.0.1-commit.d939eb5aa
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 +21 -6
- package/dest/archiver.d.ts +17 -12
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +108 -127
- package/dest/config.d.ts +3 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +3 -2
- package/dest/errors.d.ts +39 -10
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +52 -15
- package/dest/factory.d.ts +4 -2
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +29 -23
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/l1/bin/retrieve-calldata.js +35 -32
- package/dest/l1/calldata_retriever.d.ts +73 -50
- package/dest/l1/calldata_retriever.d.ts.map +1 -1
- package/dest/l1/calldata_retriever.js +191 -259
- package/dest/l1/data_retrieval.d.ts +11 -11
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +38 -37
- package/dest/l1/spire_proposer.d.ts +5 -5
- package/dest/l1/spire_proposer.d.ts.map +1 -1
- package/dest/l1/spire_proposer.js +9 -17
- package/dest/l1/validate_trace.d.ts +6 -3
- package/dest/l1/validate_trace.d.ts.map +1 -1
- package/dest/l1/validate_trace.js +13 -9
- package/dest/modules/data_source_base.d.ts +29 -23
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +55 -124
- package/dest/modules/data_store_updater.d.ts +43 -26
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +158 -129
- package/dest/modules/instrumentation.d.ts +19 -4
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +53 -18
- package/dest/modules/l1_synchronizer.d.ts +7 -9
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +186 -145
- 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 +86 -34
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +414 -152
- 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 +16 -72
- 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 +80 -39
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +86 -35
- package/dest/store/l2_tips_cache.d.ts +20 -0
- package/dest/store/l2_tips_cache.d.ts.map +1 -0
- package/dest/store/l2_tips_cache.js +109 -0
- package/dest/store/log_store.d.ts +9 -6
- package/dest/store/log_store.d.ts.map +1 -1
- package/dest/store/log_store.js +151 -56
- 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 +21 -9
- package/dest/test/fake_l1_state.d.ts +24 -4
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +133 -26
- package/dest/test/index.js +3 -1
- package/dest/test/mock_archiver.d.ts +1 -1
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +3 -2
- 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 +44 -23
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +185 -115
- package/dest/test/mock_structs.d.ts +6 -2
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +24 -10
- package/dest/test/noop_l1_archiver.d.ts +26 -0
- package/dest/test/noop_l1_archiver.d.ts.map +1 -0
- package/dest/test/noop_l1_archiver.js +71 -0
- package/package.json +14 -13
- package/src/archiver.ts +144 -159
- package/src/config.ts +9 -2
- package/src/errors.ts +82 -26
- package/src/factory.ts +46 -22
- package/src/index.ts +1 -0
- package/src/l1/README.md +25 -68
- package/src/l1/bin/retrieve-calldata.ts +45 -33
- package/src/l1/calldata_retriever.ts +250 -379
- package/src/l1/data_retrieval.ts +35 -41
- package/src/l1/spire_proposer.ts +7 -15
- package/src/l1/validate_trace.ts +24 -6
- package/src/modules/data_source_base.ts +98 -169
- package/src/modules/data_store_updater.ts +178 -160
- package/src/modules/instrumentation.ts +64 -20
- package/src/modules/l1_synchronizer.ts +212 -182
- package/src/modules/validation.ts +2 -2
- package/src/store/block_store.ts +533 -207
- package/src/store/contract_class_store.ts +16 -110
- package/src/store/contract_instance_store.ts +8 -5
- package/src/store/kv_archiver_store.ts +141 -59
- package/src/store/l2_tips_cache.ts +134 -0
- package/src/store/log_store.ts +232 -74
- package/src/store/message_store.ts +27 -10
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +180 -32
- package/src/test/index.ts +3 -0
- package/src/test/mock_archiver.ts +3 -2
- package/src/test/mock_l1_to_l2_message_source.ts +1 -0
- package/src/test/mock_l2_block_source.ts +247 -130
- package/src/test/mock_structs.ts +45 -15
- package/src/test/noop_l1_archiver.ts +114 -0
|
@@ -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.
|
|
@@ -28,18 +21,26 @@ export class ContractClassStore {
|
|
|
28
21
|
bytecodeCommitment: Fr,
|
|
29
22
|
blockNumber: number,
|
|
30
23
|
): Promise<void> {
|
|
31
|
-
await this
|
|
32
|
-
contractClass.id.toString()
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
await this.db.transactionAsync(async () => {
|
|
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,
|
|
31
|
+
serializeContractClassPublic({ ...contractClass, l2BlockNumber: blockNumber }),
|
|
32
|
+
);
|
|
33
|
+
await this.#bytecodeCommitments.set(key, bytecodeCommitment.toBuffer());
|
|
34
|
+
});
|
|
36
35
|
}
|
|
37
36
|
|
|
38
37
|
async deleteContractClasses(contractClass: ContractClassPublic, blockNumber: number): Promise<void> {
|
|
39
38
|
const restoredContractClass = await this.#contractClasses.getAsync(contractClass.id.toString());
|
|
40
39
|
if (restoredContractClass && deserializeContractClassPublic(restoredContractClass).l2BlockNumber >= blockNumber) {
|
|
41
|
-
await this
|
|
42
|
-
|
|
40
|
+
await this.db.transactionAsync(async () => {
|
|
41
|
+
await this.#contractClasses.delete(contractClass.id.toString());
|
|
42
|
+
await this.#bytecodeCommitments.delete(contractClass.id.toString());
|
|
43
|
+
});
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
|
|
@@ -56,37 +57,6 @@ export class ContractClassStore {
|
|
|
56
57
|
async getContractClassIds(): Promise<Fr[]> {
|
|
57
58
|
return (await toArray(this.#contractClasses.keysAsync())).map(key => Fr.fromHexString(key));
|
|
58
59
|
}
|
|
59
|
-
|
|
60
|
-
async addFunctions(
|
|
61
|
-
contractClassId: Fr,
|
|
62
|
-
newPrivateFunctions: ExecutablePrivateFunctionWithMembershipProof[],
|
|
63
|
-
newUtilityFunctions: UtilityFunctionWithMembershipProof[],
|
|
64
|
-
): Promise<boolean> {
|
|
65
|
-
await this.db.transactionAsync(async () => {
|
|
66
|
-
const existingClassBuffer = await this.#contractClasses.getAsync(contractClassId.toString());
|
|
67
|
-
if (!existingClassBuffer) {
|
|
68
|
-
throw new Error(`Unknown contract class ${contractClassId} when adding private functions to store`);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const existingClass = deserializeContractClassPublic(existingClassBuffer);
|
|
72
|
-
const { privateFunctions: existingPrivateFns, utilityFunctions: existingUtilityFns } = existingClass;
|
|
73
|
-
|
|
74
|
-
const updatedClass: Omit<ContractClassPublicWithBlockNumber, 'id'> = {
|
|
75
|
-
...existingClass,
|
|
76
|
-
privateFunctions: [
|
|
77
|
-
...existingPrivateFns,
|
|
78
|
-
...newPrivateFunctions.filter(newFn => !existingPrivateFns.some(f => f.selector.equals(newFn.selector))),
|
|
79
|
-
],
|
|
80
|
-
utilityFunctions: [
|
|
81
|
-
...existingUtilityFns,
|
|
82
|
-
...newUtilityFunctions.filter(newFn => !existingUtilityFns.some(f => f.selector.equals(newFn.selector))),
|
|
83
|
-
],
|
|
84
|
-
};
|
|
85
|
-
await this.#contractClasses.set(contractClassId.toString(), serializeContractClassPublic(updatedClass));
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
60
|
}
|
|
91
61
|
|
|
92
62
|
function serializeContractClassPublic(contractClass: Omit<ContractClassPublicWithBlockNumber, 'id'>): Buffer {
|
|
@@ -94,83 +64,19 @@ function serializeContractClassPublic(contractClass: Omit<ContractClassPublicWit
|
|
|
94
64
|
contractClass.l2BlockNumber,
|
|
95
65
|
numToUInt8(contractClass.version),
|
|
96
66
|
contractClass.artifactHash,
|
|
97
|
-
contractClass.privateFunctions.length,
|
|
98
|
-
contractClass.privateFunctions.map(serializePrivateFunction),
|
|
99
|
-
contractClass.utilityFunctions.length,
|
|
100
|
-
contractClass.utilityFunctions.map(serializeUtilityFunction),
|
|
101
67
|
contractClass.packedBytecode.length,
|
|
102
68
|
contractClass.packedBytecode,
|
|
103
69
|
contractClass.privateFunctionsRoot,
|
|
104
70
|
);
|
|
105
71
|
}
|
|
106
72
|
|
|
107
|
-
function serializePrivateFunction(fn: ExecutablePrivateFunctionWithMembershipProof): Buffer {
|
|
108
|
-
return serializeToBuffer(
|
|
109
|
-
fn.selector,
|
|
110
|
-
fn.vkHash,
|
|
111
|
-
fn.bytecode.length,
|
|
112
|
-
fn.bytecode,
|
|
113
|
-
fn.functionMetadataHash,
|
|
114
|
-
fn.artifactMetadataHash,
|
|
115
|
-
fn.utilityFunctionsTreeRoot,
|
|
116
|
-
new Vector(fn.privateFunctionTreeSiblingPath),
|
|
117
|
-
fn.privateFunctionTreeLeafIndex,
|
|
118
|
-
new Vector(fn.artifactTreeSiblingPath),
|
|
119
|
-
fn.artifactTreeLeafIndex,
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function serializeUtilityFunction(fn: UtilityFunctionWithMembershipProof): Buffer {
|
|
124
|
-
return serializeToBuffer(
|
|
125
|
-
fn.selector,
|
|
126
|
-
fn.bytecode.length,
|
|
127
|
-
fn.bytecode,
|
|
128
|
-
fn.functionMetadataHash,
|
|
129
|
-
fn.artifactMetadataHash,
|
|
130
|
-
fn.privateFunctionsArtifactTreeRoot,
|
|
131
|
-
new Vector(fn.artifactTreeSiblingPath),
|
|
132
|
-
fn.artifactTreeLeafIndex,
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
73
|
function deserializeContractClassPublic(buffer: Buffer): Omit<ContractClassPublicWithBlockNumber, 'id'> {
|
|
137
74
|
const reader = BufferReader.asReader(buffer);
|
|
138
75
|
return {
|
|
139
76
|
l2BlockNumber: reader.readNumber(),
|
|
140
77
|
version: reader.readUInt8() as 1,
|
|
141
78
|
artifactHash: reader.readObject(Fr),
|
|
142
|
-
privateFunctions: reader.readVector({ fromBuffer: deserializePrivateFunction }),
|
|
143
|
-
utilityFunctions: reader.readVector({ fromBuffer: deserializeUtilityFunction }),
|
|
144
79
|
packedBytecode: reader.readBuffer(),
|
|
145
80
|
privateFunctionsRoot: reader.readObject(Fr),
|
|
146
81
|
};
|
|
147
82
|
}
|
|
148
|
-
|
|
149
|
-
function deserializePrivateFunction(buffer: Buffer | BufferReader): ExecutablePrivateFunctionWithMembershipProof {
|
|
150
|
-
const reader = BufferReader.asReader(buffer);
|
|
151
|
-
return {
|
|
152
|
-
selector: reader.readObject(FunctionSelector),
|
|
153
|
-
vkHash: reader.readObject(Fr),
|
|
154
|
-
bytecode: reader.readBuffer(),
|
|
155
|
-
functionMetadataHash: reader.readObject(Fr),
|
|
156
|
-
artifactMetadataHash: reader.readObject(Fr),
|
|
157
|
-
utilityFunctionsTreeRoot: reader.readObject(Fr),
|
|
158
|
-
privateFunctionTreeSiblingPath: reader.readVector(Fr),
|
|
159
|
-
privateFunctionTreeLeafIndex: reader.readNumber(),
|
|
160
|
-
artifactTreeSiblingPath: reader.readVector(Fr),
|
|
161
|
-
artifactTreeLeafIndex: reader.readNumber(),
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function deserializeUtilityFunction(buffer: Buffer | BufferReader): UtilityFunctionWithMembershipProof {
|
|
166
|
-
const reader = BufferReader.asReader(buffer);
|
|
167
|
-
return {
|
|
168
|
-
selector: reader.readObject(FunctionSelector),
|
|
169
|
-
bytecode: reader.readBuffer(),
|
|
170
|
-
functionMetadataHash: reader.readObject(Fr),
|
|
171
|
-
artifactMetadataHash: reader.readObject(Fr),
|
|
172
|
-
privateFunctionsArtifactTreeRoot: reader.readObject(Fr),
|
|
173
|
-
artifactTreeSiblingPath: reader.readVector(Fr),
|
|
174
|
-
artifactTreeLeafIndex: reader.readNumber(),
|
|
175
|
-
};
|
|
176
|
-
}
|
|
@@ -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
|
|
|
@@ -6,16 +6,28 @@ import { createLogger } from '@aztec/foundation/log';
|
|
|
6
6
|
import type { AztecAsyncKVStore, CustomRange, StoreSize } from '@aztec/kv-store';
|
|
7
7
|
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
8
8
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
9
|
-
import {
|
|
10
|
-
|
|
9
|
+
import {
|
|
10
|
+
type BlockData,
|
|
11
|
+
BlockHash,
|
|
12
|
+
CheckpointedL2Block,
|
|
13
|
+
L2Block,
|
|
14
|
+
type ValidateCheckpointResult,
|
|
15
|
+
} from '@aztec/stdlib/block';
|
|
16
|
+
import type {
|
|
17
|
+
CheckpointData,
|
|
18
|
+
CommonCheckpointData,
|
|
19
|
+
ProposedCheckpointData,
|
|
20
|
+
ProposedCheckpointInput,
|
|
21
|
+
PublishedCheckpoint,
|
|
22
|
+
} from '@aztec/stdlib/checkpoint';
|
|
11
23
|
import type {
|
|
12
24
|
ContractClassPublic,
|
|
25
|
+
ContractClassPublicWithCommitment,
|
|
13
26
|
ContractDataSource,
|
|
14
27
|
ContractInstanceUpdateWithAddress,
|
|
15
28
|
ContractInstanceWithAddress,
|
|
16
|
-
ExecutablePrivateFunctionWithMembershipProof,
|
|
17
|
-
UtilityFunctionWithMembershipProof,
|
|
18
29
|
} from '@aztec/stdlib/contract';
|
|
30
|
+
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
19
31
|
import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
|
|
20
32
|
import type { LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
21
33
|
import type { BlockHeader, TxHash, TxReceipt } from '@aztec/stdlib/tx';
|
|
@@ -24,13 +36,13 @@ import type { UInt64 } from '@aztec/stdlib/types';
|
|
|
24
36
|
import { join } from 'path';
|
|
25
37
|
|
|
26
38
|
import type { InboxMessage } from '../structs/inbox_message.js';
|
|
27
|
-
import { BlockStore, type
|
|
39
|
+
import { BlockStore, type RemoveCheckpointsResult } from './block_store.js';
|
|
28
40
|
import { ContractClassStore } from './contract_class_store.js';
|
|
29
41
|
import { ContractInstanceStore } from './contract_instance_store.js';
|
|
30
42
|
import { LogStore } from './log_store.js';
|
|
31
43
|
import { MessageStore } from './message_store.js';
|
|
32
44
|
|
|
33
|
-
export const ARCHIVER_DB_VERSION =
|
|
45
|
+
export const ARCHIVER_DB_VERSION = 6;
|
|
34
46
|
export const MAX_FUNCTION_SIGNATURES = 1000;
|
|
35
47
|
export const MAX_FUNCTION_NAME_LEN = 256;
|
|
36
48
|
|
|
@@ -72,6 +84,11 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
72
84
|
this.#contractInstanceStore = new ContractInstanceStore(db);
|
|
73
85
|
}
|
|
74
86
|
|
|
87
|
+
/** Returns the underlying block store. Used by L2TipsCache. */
|
|
88
|
+
get blockStore(): BlockStore {
|
|
89
|
+
return this.#blockStore;
|
|
90
|
+
}
|
|
91
|
+
|
|
75
92
|
/** Opens a new transaction to the underlying store and runs all operations within it. */
|
|
76
93
|
public transactionAsync<T>(callback: () => Promise<T>): Promise<T> {
|
|
77
94
|
return this.db.transactionAsync(callback);
|
|
@@ -101,6 +118,11 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
101
118
|
return this.db.close();
|
|
102
119
|
}
|
|
103
120
|
|
|
121
|
+
/** Computes the finalized block number based on the proven block number. */
|
|
122
|
+
getFinalizedL2BlockNumber(): Promise<BlockNumber> {
|
|
123
|
+
return this.#blockStore.getFinalizedL2BlockNumber();
|
|
124
|
+
}
|
|
125
|
+
|
|
104
126
|
/** Looks up a public function name given a selector. */
|
|
105
127
|
getDebugFunctionName(_address: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
|
|
106
128
|
return Promise.resolve(this.functionNames.get(selector.toString()));
|
|
@@ -150,19 +172,14 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
150
172
|
|
|
151
173
|
/**
|
|
152
174
|
* Add new contract classes from an L2 block to the store's list.
|
|
153
|
-
* @param data - List of contract classes to be added.
|
|
154
|
-
* @param bytecodeCommitments - Bytecode commitments for the contract classes.
|
|
175
|
+
* @param data - List of contract classes (with bytecode commitments) to be added.
|
|
155
176
|
* @param blockNumber - Number of the L2 block the contracts were registered in.
|
|
156
177
|
* @returns True if the operation is successful.
|
|
157
178
|
*/
|
|
158
|
-
async addContractClasses(
|
|
159
|
-
data: ContractClassPublic[],
|
|
160
|
-
bytecodeCommitments: Fr[],
|
|
161
|
-
blockNumber: BlockNumber,
|
|
162
|
-
): Promise<boolean> {
|
|
179
|
+
async addContractClasses(data: ContractClassPublicWithCommitment[], blockNumber: BlockNumber): Promise<boolean> {
|
|
163
180
|
return (
|
|
164
181
|
await Promise.all(
|
|
165
|
-
data.map(
|
|
182
|
+
data.map(c => this.#contractClassStore.addContractClass(c, c.publicBytecodeCommitment, blockNumber)),
|
|
166
183
|
)
|
|
167
184
|
).every(Boolean);
|
|
168
185
|
}
|
|
@@ -177,15 +194,6 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
177
194
|
return this.#contractClassStore.getBytecodeCommitment(contractClassId);
|
|
178
195
|
}
|
|
179
196
|
|
|
180
|
-
/** Adds private functions to a contract class. */
|
|
181
|
-
addFunctions(
|
|
182
|
-
contractClassId: Fr,
|
|
183
|
-
privateFunctions: ExecutablePrivateFunctionWithMembershipProof[],
|
|
184
|
-
utilityFunctions: UtilityFunctionWithMembershipProof[],
|
|
185
|
-
): Promise<boolean> {
|
|
186
|
-
return this.#contractClassStore.addFunctions(contractClassId, privateFunctions, utilityFunctions);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
197
|
/**
|
|
190
198
|
* Add new contract instances from an L2 block to the store's list.
|
|
191
199
|
* @param data - List of contract instances to be added.
|
|
@@ -228,12 +236,14 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
228
236
|
}
|
|
229
237
|
|
|
230
238
|
/**
|
|
231
|
-
* Append new
|
|
232
|
-
*
|
|
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.
|
|
241
|
+
* For checkpointed blocks (already published to L1), use addCheckpoints() instead.
|
|
242
|
+
* @param block - The proposed L2 block to be added to the store.
|
|
233
243
|
* @returns True if the operation is successful.
|
|
234
244
|
*/
|
|
235
|
-
|
|
236
|
-
return this.#blockStore.
|
|
245
|
+
addProposedBlock(block: L2Block, opts: { force?: boolean } = {}): Promise<boolean> {
|
|
246
|
+
return this.#blockStore.addProposedBlock(block, opts);
|
|
237
247
|
}
|
|
238
248
|
|
|
239
249
|
/**
|
|
@@ -250,18 +260,16 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
250
260
|
* @returns The number of the latest block
|
|
251
261
|
*/
|
|
252
262
|
getLatestBlockNumber(): Promise<BlockNumber> {
|
|
253
|
-
return this.#blockStore.
|
|
263
|
+
return this.#blockStore.getLatestL2BlockNumber();
|
|
254
264
|
}
|
|
255
265
|
|
|
256
266
|
/**
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
* @param checkpointsToUnwind - The number of checkpoints we are to unwind
|
|
261
|
-
* @returns True if the operation is successful
|
|
267
|
+
* Removes all checkpoints with checkpoint number > checkpointNumber.
|
|
268
|
+
* Also removes ALL blocks (both checkpointed and uncheckpointed) after the last block of the given checkpoint.
|
|
269
|
+
* @param checkpointNumber - Remove all checkpoints strictly after this one.
|
|
262
270
|
*/
|
|
263
|
-
|
|
264
|
-
return this.#blockStore.
|
|
271
|
+
removeCheckpointsAfter(checkpointNumber: CheckpointNumber): Promise<RemoveCheckpointsResult> {
|
|
272
|
+
return this.#blockStore.removeCheckpointsAfter(checkpointNumber);
|
|
265
273
|
}
|
|
266
274
|
|
|
267
275
|
/**
|
|
@@ -284,7 +292,7 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
284
292
|
* Returns the block for the given hash, or undefined if not exists.
|
|
285
293
|
* @param blockHash - The block hash to return.
|
|
286
294
|
*/
|
|
287
|
-
getCheckpointedBlockByHash(blockHash:
|
|
295
|
+
getCheckpointedBlockByHash(blockHash: BlockHash): Promise<CheckpointedL2Block | undefined> {
|
|
288
296
|
return this.#blockStore.getCheckpointedBlockByHash(blockHash);
|
|
289
297
|
}
|
|
290
298
|
/**
|
|
@@ -298,21 +306,21 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
298
306
|
* Returns the block for the given number, or undefined if not exists.
|
|
299
307
|
* @param number - The block number to return.
|
|
300
308
|
*/
|
|
301
|
-
getBlock(number: BlockNumber): Promise<
|
|
309
|
+
getBlock(number: BlockNumber): Promise<L2Block | undefined> {
|
|
302
310
|
return this.#blockStore.getBlock(number);
|
|
303
311
|
}
|
|
304
312
|
/**
|
|
305
313
|
* Returns the block for the given hash, or undefined if not exists.
|
|
306
314
|
* @param blockHash - The block hash to return.
|
|
307
315
|
*/
|
|
308
|
-
getBlockByHash(blockHash:
|
|
309
|
-
return this.#blockStore.getBlockByHash(
|
|
316
|
+
getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
317
|
+
return this.#blockStore.getBlockByHash(blockHash);
|
|
310
318
|
}
|
|
311
319
|
/**
|
|
312
320
|
* Returns the block for the given archive root, or undefined if not exists.
|
|
313
321
|
* @param archive - The archive root to return.
|
|
314
322
|
*/
|
|
315
|
-
getBlockByArchive(archive: Fr): Promise<
|
|
323
|
+
getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
316
324
|
return this.#blockStore.getBlockByArchive(archive);
|
|
317
325
|
}
|
|
318
326
|
|
|
@@ -322,7 +330,7 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
322
330
|
* @param limit - The number of blocks to return.
|
|
323
331
|
* @returns The requested L2 blocks.
|
|
324
332
|
*/
|
|
325
|
-
getBlocks(from: BlockNumber, limit: number): Promise<
|
|
333
|
+
getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
|
|
326
334
|
return toArray(this.#blockStore.getBlocks(from, limit));
|
|
327
335
|
}
|
|
328
336
|
|
|
@@ -350,8 +358,8 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
350
358
|
* Returns the block header for the given hash, or undefined if not exists.
|
|
351
359
|
* @param blockHash - The block hash to return.
|
|
352
360
|
*/
|
|
353
|
-
getBlockHeaderByHash(blockHash:
|
|
354
|
-
return this.#blockStore.getBlockHeaderByHash(
|
|
361
|
+
getBlockHeaderByHash(blockHash: BlockHash): Promise<BlockHeader | undefined> {
|
|
362
|
+
return this.#blockStore.getBlockHeaderByHash(blockHash);
|
|
355
363
|
}
|
|
356
364
|
|
|
357
365
|
/**
|
|
@@ -362,6 +370,22 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
362
370
|
return this.#blockStore.getBlockHeaderByArchive(archive);
|
|
363
371
|
}
|
|
364
372
|
|
|
373
|
+
/**
|
|
374
|
+
* Gets block metadata (without tx data) by block number.
|
|
375
|
+
* @param blockNumber - The block number to return.
|
|
376
|
+
*/
|
|
377
|
+
getBlockData(blockNumber: BlockNumber): Promise<BlockData | undefined> {
|
|
378
|
+
return this.#blockStore.getBlockData(blockNumber);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Gets block metadata (without tx data) by archive root.
|
|
383
|
+
* @param archive - The archive root to return.
|
|
384
|
+
*/
|
|
385
|
+
getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
|
|
386
|
+
return this.#blockStore.getBlockDataByArchive(archive);
|
|
387
|
+
}
|
|
388
|
+
|
|
365
389
|
/**
|
|
366
390
|
* Gets a tx effect.
|
|
367
391
|
* @param txHash - The hash of the tx corresponding to the tx effect.
|
|
@@ -376,8 +400,11 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
376
400
|
* @param txHash - The hash of a tx we try to get the receipt for.
|
|
377
401
|
* @returns The requested tx receipt (or undefined if not found).
|
|
378
402
|
*/
|
|
379
|
-
getSettledTxReceipt(
|
|
380
|
-
|
|
403
|
+
getSettledTxReceipt(
|
|
404
|
+
txHash: TxHash,
|
|
405
|
+
l1Constants?: Pick<L1RollupConstants, 'epochDuration'>,
|
|
406
|
+
): Promise<TxReceipt | undefined> {
|
|
407
|
+
return this.#blockStore.getSettledTxReceipt(txHash, l1Constants);
|
|
381
408
|
}
|
|
382
409
|
|
|
383
410
|
/**
|
|
@@ -385,11 +412,11 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
385
412
|
* @param blocks - The blocks for which to add the logs.
|
|
386
413
|
* @returns True if the operation is successful.
|
|
387
414
|
*/
|
|
388
|
-
addLogs(blocks:
|
|
415
|
+
addLogs(blocks: L2Block[]): Promise<boolean> {
|
|
389
416
|
return this.#logStore.addLogs(blocks);
|
|
390
417
|
}
|
|
391
418
|
|
|
392
|
-
deleteLogs(blocks:
|
|
419
|
+
deleteLogs(blocks: L2Block[]): Promise<boolean> {
|
|
393
420
|
return this.#logStore.deleteLogs(blocks);
|
|
394
421
|
}
|
|
395
422
|
|
|
@@ -438,10 +465,11 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
438
465
|
* array implies no logs match that tag.
|
|
439
466
|
* @param tags - The tags to search for.
|
|
440
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.
|
|
441
469
|
*/
|
|
442
|
-
getPrivateLogsByTags(tags: SiloedTag[], page?: number): Promise<TxScopedL2Log[][]> {
|
|
470
|
+
getPrivateLogsByTags(tags: SiloedTag[], page?: number, upToBlockNumber?: BlockNumber): Promise<TxScopedL2Log[][]> {
|
|
443
471
|
try {
|
|
444
|
-
return this.#logStore.getPrivateLogsByTags(tags, page);
|
|
472
|
+
return this.#logStore.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
445
473
|
} catch (err) {
|
|
446
474
|
return Promise.reject(err);
|
|
447
475
|
}
|
|
@@ -453,14 +481,16 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
453
481
|
* @param contractAddress - The contract address to search logs for.
|
|
454
482
|
* @param tags - The tags to search for.
|
|
455
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.
|
|
456
485
|
*/
|
|
457
486
|
getPublicLogsByTagsFromContract(
|
|
458
487
|
contractAddress: AztecAddress,
|
|
459
488
|
tags: Tag[],
|
|
460
489
|
page?: number,
|
|
490
|
+
upToBlockNumber?: BlockNumber,
|
|
461
491
|
): Promise<TxScopedL2Log[][]> {
|
|
462
492
|
try {
|
|
463
|
-
return this.#logStore.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
493
|
+
return this.#logStore.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
464
494
|
} catch (err) {
|
|
465
495
|
return Promise.reject(err);
|
|
466
496
|
}
|
|
@@ -508,15 +538,24 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
508
538
|
await this.#blockStore.setProvenCheckpointNumber(checkpointNumber);
|
|
509
539
|
}
|
|
510
540
|
|
|
511
|
-
|
|
512
|
-
|
|
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();
|
|
513
547
|
}
|
|
514
548
|
|
|
515
549
|
/**
|
|
516
|
-
* Stores the
|
|
550
|
+
* Stores the number of the latest finalized checkpoint processed.
|
|
551
|
+
* @param checkpointNumber - The number of the latest finalized checkpoint processed.
|
|
517
552
|
*/
|
|
518
|
-
async
|
|
519
|
-
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);
|
|
520
559
|
}
|
|
521
560
|
|
|
522
561
|
/**
|
|
@@ -551,6 +590,11 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
551
590
|
return this.#messageStore.rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber);
|
|
552
591
|
}
|
|
553
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
|
+
|
|
554
598
|
/** Returns an async iterator to all L1 to L2 messages on the range. */
|
|
555
599
|
public iterateL1ToL2Messages(range: CustomRange<bigint> = {}): AsyncIterableIterator<InboxMessage> {
|
|
556
600
|
return this.#messageStore.iterateL1ToL2Messages(range);
|
|
@@ -571,6 +615,38 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
571
615
|
return this.#blockStore.setPendingChainValidationStatus(status);
|
|
572
616
|
}
|
|
573
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
|
+
|
|
574
650
|
/**
|
|
575
651
|
* Gets the number of the latest L2 block processed.
|
|
576
652
|
* @returns The number of the latest L2 block processed.
|
|
@@ -598,7 +674,7 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
598
674
|
* @param checkpointNumber Retrieves all blocks for the given checkpoint
|
|
599
675
|
* @returns The collection of blocks for the requested checkpoint if available (undefined otherwise)
|
|
600
676
|
*/
|
|
601
|
-
getBlocksForCheckpoint(checkpointNumber: CheckpointNumber): Promise<
|
|
677
|
+
getBlocksForCheckpoint(checkpointNumber: CheckpointNumber): Promise<L2Block[] | undefined> {
|
|
602
678
|
return this.#blockStore.getBlocksForCheckpoint(checkpointNumber);
|
|
603
679
|
}
|
|
604
680
|
|
|
@@ -611,21 +687,27 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
611
687
|
return this.#blockStore.getCheckpointData(checkpointNumber);
|
|
612
688
|
}
|
|
613
689
|
|
|
690
|
+
/** Returns checkpoint data for all checkpoints whose slot falls within the given range (inclusive). */
|
|
691
|
+
getCheckpointDataForSlotRange(startSlot: SlotNumber, endSlot: SlotNumber): Promise<CheckpointData[]> {
|
|
692
|
+
return this.#blockStore.getCheckpointDataForSlotRange(startSlot, endSlot);
|
|
693
|
+
}
|
|
694
|
+
|
|
614
695
|
/**
|
|
615
696
|
* Gets all blocks that have the given slot number.
|
|
616
697
|
* @param slotNumber - The slot number to search for.
|
|
617
698
|
* @returns All blocks with the given slot number.
|
|
618
699
|
*/
|
|
619
|
-
getBlocksForSlot(slotNumber: SlotNumber): Promise<
|
|
700
|
+
getBlocksForSlot(slotNumber: SlotNumber): Promise<L2Block[]> {
|
|
620
701
|
return this.#blockStore.getBlocksForSlot(slotNumber);
|
|
621
702
|
}
|
|
622
703
|
|
|
623
704
|
/**
|
|
624
705
|
* Removes all blocks with block number > blockNumber.
|
|
706
|
+
* Does not remove any associated checkpoints.
|
|
625
707
|
* @param blockNumber - The block number to remove after.
|
|
626
708
|
* @returns The removed blocks (for event emission).
|
|
627
709
|
*/
|
|
628
|
-
removeBlocksAfter(blockNumber: BlockNumber): Promise<
|
|
629
|
-
return this.#blockStore.
|
|
710
|
+
removeBlocksAfter(blockNumber: BlockNumber): Promise<L2Block[]> {
|
|
711
|
+
return this.#blockStore.removeBlocksAfter(blockNumber);
|
|
630
712
|
}
|
|
631
713
|
}
|