@aztec/archiver 0.0.1-commit.d1f2d6c → 0.0.1-commit.d20b825a7
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 +16 -10
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +110 -122
- 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 +55 -10
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +74 -15
- package/dest/factory.d.ts +5 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +34 -29
- package/dest/index.d.ts +4 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +3 -1
- package/dest/l1/bin/retrieve-calldata.js +36 -33
- 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 +26 -17
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +43 -48
- 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_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/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 +17 -10
- package/dest/modules/data_source_base.d.ts.map +1 -1
- package/dest/modules/data_source_base.js +39 -77
- package/dest/modules/data_store_updater.d.ts +50 -26
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +169 -130
- package/dest/modules/instrumentation.d.ts +21 -3
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +58 -18
- package/dest/modules/l1_synchronizer.d.ts +10 -9
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +285 -157
- 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 +85 -36
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +433 -162
- 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 +76 -32
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +92 -37
- 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 +6 -3
- 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 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +145 -28
- 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 +31 -10
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +163 -92
- 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 +20 -6
- 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 +74 -0
- package/package.json +14 -13
- package/src/archiver.ts +150 -146
- package/src/config.ts +22 -2
- package/src/errors.ts +116 -26
- package/src/factory.ts +49 -26
- package/src/index.ts +3 -1
- package/src/l1/README.md +25 -68
- package/src/l1/bin/retrieve-calldata.ts +46 -39
- package/src/l1/calldata_retriever.ts +250 -379
- package/src/l1/data_retrieval.ts +59 -70
- package/src/l1/spire_proposer.ts +7 -15
- package/src/l1/validate_historical_logs.ts +140 -0
- package/src/l1/validate_trace.ts +24 -6
- package/src/modules/data_source_base.ts +81 -101
- package/src/modules/data_store_updater.ts +202 -160
- package/src/modules/instrumentation.ts +71 -19
- package/src/modules/l1_synchronizer.ts +365 -197
- package/src/modules/validation.ts +2 -2
- package/src/store/block_store.ts +546 -206
- 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 +143 -53
- package/src/store/l2_tips_cache.ts +134 -0
- package/src/store/log_store.ts +225 -67
- package/src/store/message_store.ts +27 -10
- package/src/structs/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +193 -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 +217 -90
- package/src/test/mock_structs.ts +42 -12
- package/src/test/noop_l1_archiver.ts +117 -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,15 +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
|
+
type CommitteeAttestation,
|
|
14
|
+
L2Block,
|
|
15
|
+
type ValidateCheckpointResult,
|
|
16
|
+
} from '@aztec/stdlib/block';
|
|
17
|
+
import type {
|
|
18
|
+
CheckpointData,
|
|
19
|
+
CommonCheckpointData,
|
|
20
|
+
L1PublishedData,
|
|
21
|
+
ProposedCheckpointData,
|
|
22
|
+
ProposedCheckpointInput,
|
|
23
|
+
PublishedCheckpoint,
|
|
24
|
+
} from '@aztec/stdlib/checkpoint';
|
|
11
25
|
import type {
|
|
12
26
|
ContractClassPublic,
|
|
27
|
+
ContractClassPublicWithCommitment,
|
|
13
28
|
ContractDataSource,
|
|
14
29
|
ContractInstanceUpdateWithAddress,
|
|
15
30
|
ContractInstanceWithAddress,
|
|
16
|
-
ExecutablePrivateFunctionWithMembershipProof,
|
|
17
|
-
UtilityFunctionWithMembershipProof,
|
|
18
31
|
} from '@aztec/stdlib/contract';
|
|
19
32
|
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
20
33
|
import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
|
|
@@ -25,13 +38,13 @@ import type { UInt64 } from '@aztec/stdlib/types';
|
|
|
25
38
|
import { join } from 'path';
|
|
26
39
|
|
|
27
40
|
import type { InboxMessage } from '../structs/inbox_message.js';
|
|
28
|
-
import { BlockStore, type
|
|
41
|
+
import { BlockStore, type RemoveCheckpointsResult } from './block_store.js';
|
|
29
42
|
import { ContractClassStore } from './contract_class_store.js';
|
|
30
43
|
import { ContractInstanceStore } from './contract_instance_store.js';
|
|
31
44
|
import { LogStore } from './log_store.js';
|
|
32
45
|
import { MessageStore } from './message_store.js';
|
|
33
46
|
|
|
34
|
-
export const ARCHIVER_DB_VERSION =
|
|
47
|
+
export const ARCHIVER_DB_VERSION = 6;
|
|
35
48
|
export const MAX_FUNCTION_SIGNATURES = 1000;
|
|
36
49
|
export const MAX_FUNCTION_NAME_LEN = 256;
|
|
37
50
|
|
|
@@ -65,15 +78,19 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
65
78
|
constructor(
|
|
66
79
|
private db: AztecAsyncKVStore,
|
|
67
80
|
logsMaxPageSize: number = 1000,
|
|
68
|
-
l1Constants: Pick<L1RollupConstants, 'epochDuration'>,
|
|
69
81
|
) {
|
|
70
|
-
this.#blockStore = new BlockStore(db
|
|
82
|
+
this.#blockStore = new BlockStore(db);
|
|
71
83
|
this.#logStore = new LogStore(db, this.#blockStore, logsMaxPageSize);
|
|
72
84
|
this.#messageStore = new MessageStore(db);
|
|
73
85
|
this.#contractClassStore = new ContractClassStore(db);
|
|
74
86
|
this.#contractInstanceStore = new ContractInstanceStore(db);
|
|
75
87
|
}
|
|
76
88
|
|
|
89
|
+
/** Returns the underlying block store. Used by L2TipsCache. */
|
|
90
|
+
get blockStore(): BlockStore {
|
|
91
|
+
return this.#blockStore;
|
|
92
|
+
}
|
|
93
|
+
|
|
77
94
|
/** Opens a new transaction to the underlying store and runs all operations within it. */
|
|
78
95
|
public transactionAsync<T>(callback: () => Promise<T>): Promise<T> {
|
|
79
96
|
return this.db.transactionAsync(callback);
|
|
@@ -157,19 +174,14 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
157
174
|
|
|
158
175
|
/**
|
|
159
176
|
* Add new contract classes from an L2 block to the store's list.
|
|
160
|
-
* @param data - List of contract classes to be added.
|
|
161
|
-
* @param bytecodeCommitments - Bytecode commitments for the contract classes.
|
|
177
|
+
* @param data - List of contract classes (with bytecode commitments) to be added.
|
|
162
178
|
* @param blockNumber - Number of the L2 block the contracts were registered in.
|
|
163
179
|
* @returns True if the operation is successful.
|
|
164
180
|
*/
|
|
165
|
-
async addContractClasses(
|
|
166
|
-
data: ContractClassPublic[],
|
|
167
|
-
bytecodeCommitments: Fr[],
|
|
168
|
-
blockNumber: BlockNumber,
|
|
169
|
-
): Promise<boolean> {
|
|
181
|
+
async addContractClasses(data: ContractClassPublicWithCommitment[], blockNumber: BlockNumber): Promise<boolean> {
|
|
170
182
|
return (
|
|
171
183
|
await Promise.all(
|
|
172
|
-
data.map(
|
|
184
|
+
data.map(c => this.#contractClassStore.addContractClass(c, c.publicBytecodeCommitment, blockNumber)),
|
|
173
185
|
)
|
|
174
186
|
).every(Boolean);
|
|
175
187
|
}
|
|
@@ -184,15 +196,6 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
184
196
|
return this.#contractClassStore.getBytecodeCommitment(contractClassId);
|
|
185
197
|
}
|
|
186
198
|
|
|
187
|
-
/** Adds private functions to a contract class. */
|
|
188
|
-
addFunctions(
|
|
189
|
-
contractClassId: Fr,
|
|
190
|
-
privateFunctions: ExecutablePrivateFunctionWithMembershipProof[],
|
|
191
|
-
utilityFunctions: UtilityFunctionWithMembershipProof[],
|
|
192
|
-
): Promise<boolean> {
|
|
193
|
-
return this.#contractClassStore.addFunctions(contractClassId, privateFunctions, utilityFunctions);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
199
|
/**
|
|
197
200
|
* Add new contract instances from an L2 block to the store's list.
|
|
198
201
|
* @param data - List of contract instances to be added.
|
|
@@ -235,12 +238,14 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
235
238
|
}
|
|
236
239
|
|
|
237
240
|
/**
|
|
238
|
-
* Append new
|
|
239
|
-
*
|
|
241
|
+
* Append a new proposed block to the store.
|
|
242
|
+
* This is an uncheckpointed block that has been proposed by the sequencer but not yet included in a checkpoint on L1.
|
|
243
|
+
* For checkpointed blocks (already published to L1), use addCheckpoints() instead.
|
|
244
|
+
* @param block - The proposed L2 block to be added to the store.
|
|
240
245
|
* @returns True if the operation is successful.
|
|
241
246
|
*/
|
|
242
|
-
|
|
243
|
-
return this.#blockStore.
|
|
247
|
+
addProposedBlock(block: L2Block, opts: { force?: boolean } = {}): Promise<boolean> {
|
|
248
|
+
return this.#blockStore.addProposedBlock(block, opts);
|
|
244
249
|
}
|
|
245
250
|
|
|
246
251
|
/**
|
|
@@ -257,18 +262,16 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
257
262
|
* @returns The number of the latest block
|
|
258
263
|
*/
|
|
259
264
|
getLatestBlockNumber(): Promise<BlockNumber> {
|
|
260
|
-
return this.#blockStore.
|
|
265
|
+
return this.#blockStore.getLatestL2BlockNumber();
|
|
261
266
|
}
|
|
262
267
|
|
|
263
268
|
/**
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
* @param checkpointsToUnwind - The number of checkpoints we are to unwind
|
|
268
|
-
* @returns True if the operation is successful
|
|
269
|
+
* Removes all checkpoints with checkpoint number > checkpointNumber.
|
|
270
|
+
* Also removes ALL blocks (both checkpointed and uncheckpointed) after the last block of the given checkpoint.
|
|
271
|
+
* @param checkpointNumber - Remove all checkpoints strictly after this one.
|
|
269
272
|
*/
|
|
270
|
-
|
|
271
|
-
return this.#blockStore.
|
|
273
|
+
removeCheckpointsAfter(checkpointNumber: CheckpointNumber): Promise<RemoveCheckpointsResult> {
|
|
274
|
+
return this.#blockStore.removeCheckpointsAfter(checkpointNumber);
|
|
272
275
|
}
|
|
273
276
|
|
|
274
277
|
/**
|
|
@@ -291,7 +294,7 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
291
294
|
* Returns the block for the given hash, or undefined if not exists.
|
|
292
295
|
* @param blockHash - The block hash to return.
|
|
293
296
|
*/
|
|
294
|
-
getCheckpointedBlockByHash(blockHash:
|
|
297
|
+
getCheckpointedBlockByHash(blockHash: BlockHash): Promise<CheckpointedL2Block | undefined> {
|
|
295
298
|
return this.#blockStore.getCheckpointedBlockByHash(blockHash);
|
|
296
299
|
}
|
|
297
300
|
/**
|
|
@@ -312,8 +315,8 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
312
315
|
* Returns the block for the given hash, or undefined if not exists.
|
|
313
316
|
* @param blockHash - The block hash to return.
|
|
314
317
|
*/
|
|
315
|
-
getBlockByHash(blockHash:
|
|
316
|
-
return this.#blockStore.getBlockByHash(
|
|
318
|
+
getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
319
|
+
return this.#blockStore.getBlockByHash(blockHash);
|
|
317
320
|
}
|
|
318
321
|
/**
|
|
319
322
|
* Returns the block for the given archive root, or undefined if not exists.
|
|
@@ -357,8 +360,8 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
357
360
|
* Returns the block header for the given hash, or undefined if not exists.
|
|
358
361
|
* @param blockHash - The block hash to return.
|
|
359
362
|
*/
|
|
360
|
-
getBlockHeaderByHash(blockHash:
|
|
361
|
-
return this.#blockStore.getBlockHeaderByHash(
|
|
363
|
+
getBlockHeaderByHash(blockHash: BlockHash): Promise<BlockHeader | undefined> {
|
|
364
|
+
return this.#blockStore.getBlockHeaderByHash(blockHash);
|
|
362
365
|
}
|
|
363
366
|
|
|
364
367
|
/**
|
|
@@ -369,6 +372,22 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
369
372
|
return this.#blockStore.getBlockHeaderByArchive(archive);
|
|
370
373
|
}
|
|
371
374
|
|
|
375
|
+
/**
|
|
376
|
+
* Gets block metadata (without tx data) by block number.
|
|
377
|
+
* @param blockNumber - The block number to return.
|
|
378
|
+
*/
|
|
379
|
+
getBlockData(blockNumber: BlockNumber): Promise<BlockData | undefined> {
|
|
380
|
+
return this.#blockStore.getBlockData(blockNumber);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Gets block metadata (without tx data) by archive root.
|
|
385
|
+
* @param archive - The archive root to return.
|
|
386
|
+
*/
|
|
387
|
+
getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
|
|
388
|
+
return this.#blockStore.getBlockDataByArchive(archive);
|
|
389
|
+
}
|
|
390
|
+
|
|
372
391
|
/**
|
|
373
392
|
* Gets a tx effect.
|
|
374
393
|
* @param txHash - The hash of the tx corresponding to the tx effect.
|
|
@@ -383,8 +402,11 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
383
402
|
* @param txHash - The hash of a tx we try to get the receipt for.
|
|
384
403
|
* @returns The requested tx receipt (or undefined if not found).
|
|
385
404
|
*/
|
|
386
|
-
getSettledTxReceipt(
|
|
387
|
-
|
|
405
|
+
getSettledTxReceipt(
|
|
406
|
+
txHash: TxHash,
|
|
407
|
+
l1Constants?: Pick<L1RollupConstants, 'epochDuration'>,
|
|
408
|
+
): Promise<TxReceipt | undefined> {
|
|
409
|
+
return this.#blockStore.getSettledTxReceipt(txHash, l1Constants);
|
|
388
410
|
}
|
|
389
411
|
|
|
390
412
|
/**
|
|
@@ -445,10 +467,11 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
445
467
|
* array implies no logs match that tag.
|
|
446
468
|
* @param tags - The tags to search for.
|
|
447
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.
|
|
448
471
|
*/
|
|
449
|
-
getPrivateLogsByTags(tags: SiloedTag[], page?: number): Promise<TxScopedL2Log[][]> {
|
|
472
|
+
getPrivateLogsByTags(tags: SiloedTag[], page?: number, upToBlockNumber?: BlockNumber): Promise<TxScopedL2Log[][]> {
|
|
450
473
|
try {
|
|
451
|
-
return this.#logStore.getPrivateLogsByTags(tags, page);
|
|
474
|
+
return this.#logStore.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
452
475
|
} catch (err) {
|
|
453
476
|
return Promise.reject(err);
|
|
454
477
|
}
|
|
@@ -460,14 +483,16 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
460
483
|
* @param contractAddress - The contract address to search logs for.
|
|
461
484
|
* @param tags - The tags to search for.
|
|
462
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.
|
|
463
487
|
*/
|
|
464
488
|
getPublicLogsByTagsFromContract(
|
|
465
489
|
contractAddress: AztecAddress,
|
|
466
490
|
tags: Tag[],
|
|
467
491
|
page?: number,
|
|
492
|
+
upToBlockNumber?: BlockNumber,
|
|
468
493
|
): Promise<TxScopedL2Log[][]> {
|
|
469
494
|
try {
|
|
470
|
-
return this.#logStore.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
495
|
+
return this.#logStore.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
471
496
|
} catch (err) {
|
|
472
497
|
return Promise.reject(err);
|
|
473
498
|
}
|
|
@@ -515,15 +540,24 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
515
540
|
await this.#blockStore.setProvenCheckpointNumber(checkpointNumber);
|
|
516
541
|
}
|
|
517
542
|
|
|
518
|
-
|
|
519
|
-
|
|
543
|
+
/**
|
|
544
|
+
* Gets the number of the latest finalized checkpoint processed.
|
|
545
|
+
* @returns The number of the latest finalized checkpoint processed.
|
|
546
|
+
*/
|
|
547
|
+
getFinalizedCheckpointNumber(): Promise<CheckpointNumber> {
|
|
548
|
+
return this.#blockStore.getFinalizedCheckpointNumber();
|
|
520
549
|
}
|
|
521
550
|
|
|
522
551
|
/**
|
|
523
|
-
* Stores the
|
|
552
|
+
* Stores the number of the latest finalized checkpoint processed.
|
|
553
|
+
* @param checkpointNumber - The number of the latest finalized checkpoint processed.
|
|
524
554
|
*/
|
|
525
|
-
async
|
|
526
|
-
await this.#
|
|
555
|
+
async setFinalizedCheckpointNumber(checkpointNumber: CheckpointNumber) {
|
|
556
|
+
await this.#blockStore.setFinalizedCheckpointNumber(checkpointNumber);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
async setBlockSynchedL1BlockNumber(l1BlockNumber: bigint) {
|
|
560
|
+
await this.#blockStore.setSynchedL1BlockNumber(l1BlockNumber);
|
|
527
561
|
}
|
|
528
562
|
|
|
529
563
|
/**
|
|
@@ -558,6 +592,11 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
558
592
|
return this.#messageStore.rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber);
|
|
559
593
|
}
|
|
560
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
|
+
|
|
561
600
|
/** Returns an async iterator to all L1 to L2 messages on the range. */
|
|
562
601
|
public iterateL1ToL2Messages(range: CustomRange<bigint> = {}): AsyncIterableIterator<InboxMessage> {
|
|
563
602
|
return this.#messageStore.iterateL1ToL2Messages(range);
|
|
@@ -578,6 +617,51 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
578
617
|
return this.#blockStore.setPendingChainValidationStatus(status);
|
|
579
618
|
}
|
|
580
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
|
+
|
|
581
665
|
/**
|
|
582
666
|
* Gets the number of the latest L2 block processed.
|
|
583
667
|
* @returns The number of the latest L2 block processed.
|
|
@@ -618,6 +702,11 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
618
702
|
return this.#blockStore.getCheckpointData(checkpointNumber);
|
|
619
703
|
}
|
|
620
704
|
|
|
705
|
+
/** Returns checkpoint data for all checkpoints whose slot falls within the given range (inclusive). */
|
|
706
|
+
getCheckpointDataForSlotRange(startSlot: SlotNumber, endSlot: SlotNumber): Promise<CheckpointData[]> {
|
|
707
|
+
return this.#blockStore.getCheckpointDataForSlotRange(startSlot, endSlot);
|
|
708
|
+
}
|
|
709
|
+
|
|
621
710
|
/**
|
|
622
711
|
* Gets all blocks that have the given slot number.
|
|
623
712
|
* @param slotNumber - The slot number to search for.
|
|
@@ -629,10 +718,11 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
629
718
|
|
|
630
719
|
/**
|
|
631
720
|
* Removes all blocks with block number > blockNumber.
|
|
721
|
+
* Does not remove any associated checkpoints.
|
|
632
722
|
* @param blockNumber - The block number to remove after.
|
|
633
723
|
* @returns The removed blocks (for event emission).
|
|
634
724
|
*/
|
|
635
725
|
removeBlocksAfter(blockNumber: BlockNumber): Promise<L2Block[]> {
|
|
636
|
-
return this.#blockStore.
|
|
726
|
+
return this.#blockStore.removeBlocksAfter(blockNumber);
|
|
637
727
|
}
|
|
638
728
|
}
|