@aztec/archiver 0.0.1-commit.f2ce05ee → 0.0.1-commit.f5d02921e
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/dest/archiver.d.ts +9 -6
- package/dest/archiver.d.ts.map +1 -1
- package/dest/archiver.js +76 -111
- package/dest/config.d.ts +3 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +2 -1
- package/dest/errors.d.ts +34 -10
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +45 -16
- package/dest/factory.d.ts +4 -5
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +29 -26
- 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 +32 -28
- 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 +9 -9
- package/dest/l1/data_retrieval.d.ts.map +1 -1
- package/dest/l1/data_retrieval.js +21 -19
- 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/modules/data_source_base.d.ts +14 -7
- 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 +25 -12
- package/dest/modules/data_store_updater.d.ts.map +1 -1
- package/dest/modules/data_store_updater.js +125 -94
- package/dest/modules/instrumentation.d.ts +15 -2
- package/dest/modules/instrumentation.d.ts.map +1 -1
- package/dest/modules/instrumentation.js +19 -2
- package/dest/modules/l1_synchronizer.d.ts +5 -8
- package/dest/modules/l1_synchronizer.d.ts.map +1 -1
- package/dest/modules/l1_synchronizer.js +73 -33
- 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 +65 -28
- package/dest/store/block_store.d.ts.map +1 -1
- package/dest/store/block_store.js +311 -134
- 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 +62 -21
- package/dest/store/kv_archiver_store.d.ts.map +1 -1
- package/dest/store/kv_archiver_store.js +75 -22
- 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 +93 -16
- package/dest/store/message_store.d.ts +5 -1
- package/dest/store/message_store.d.ts.map +1 -1
- package/dest/store/message_store.js +14 -1
- package/dest/test/fake_l1_state.d.ts +13 -1
- package/dest/test/fake_l1_state.d.ts.map +1 -1
- package/dest/test/fake_l1_state.js +95 -23
- 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 +26 -5
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +160 -89
- package/dest/test/mock_structs.d.ts +4 -1
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +13 -1
- package/dest/test/noop_l1_archiver.d.ts +4 -1
- package/dest/test/noop_l1_archiver.d.ts.map +1 -1
- package/dest/test/noop_l1_archiver.js +5 -1
- package/package.json +13 -13
- package/src/archiver.ts +93 -132
- package/src/config.ts +8 -1
- package/src/errors.ts +70 -26
- package/src/factory.ts +30 -16
- package/src/index.ts +1 -0
- package/src/l1/README.md +25 -68
- package/src/l1/bin/retrieve-calldata.ts +40 -27
- package/src/l1/calldata_retriever.ts +250 -379
- package/src/l1/data_retrieval.ts +23 -25
- package/src/l1/spire_proposer.ts +7 -15
- package/src/modules/data_source_base.ts +78 -98
- package/src/modules/data_store_updater.ts +138 -124
- package/src/modules/instrumentation.ts +29 -2
- package/src/modules/l1_synchronizer.ts +86 -43
- package/src/modules/validation.ts +2 -2
- package/src/store/block_store.ts +393 -170
- 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 +117 -36
- package/src/store/l2_tips_cache.ts +128 -0
- package/src/store/log_store.ts +126 -27
- package/src/store/message_store.ts +20 -1
- package/src/test/fake_l1_state.ts +125 -26
- 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 +209 -82
- package/src/test/mock_structs.ts +20 -6
- package/src/test/noop_l1_archiver.ts +7 -1
|
@@ -2,14 +2,7 @@ import { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
2
2
|
import { toArray } from '@aztec/foundation/iterable';
|
|
3
3
|
import { BufferReader, numToUInt8, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
4
4
|
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
5
|
-
import {
|
|
6
|
-
import type {
|
|
7
|
-
ContractClassPublic,
|
|
8
|
-
ContractClassPublicWithBlockNumber,
|
|
9
|
-
ExecutablePrivateFunctionWithMembershipProof,
|
|
10
|
-
UtilityFunctionWithMembershipProof,
|
|
11
|
-
} from '@aztec/stdlib/contract';
|
|
12
|
-
import { Vector } from '@aztec/stdlib/types';
|
|
5
|
+
import type { ContractClassPublic, ContractClassPublicWithBlockNumber } from '@aztec/stdlib/contract';
|
|
13
6
|
|
|
14
7
|
/**
|
|
15
8
|
* LMDB-based contract class storage for the archiver.
|
|
@@ -29,11 +22,15 @@ export class ContractClassStore {
|
|
|
29
22
|
blockNumber: number,
|
|
30
23
|
): Promise<void> {
|
|
31
24
|
await this.db.transactionAsync(async () => {
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
const key = contractClass.id.toString();
|
|
26
|
+
if (await this.#contractClasses.hasAsync(key)) {
|
|
27
|
+
throw new Error(`Contract class ${key} already exists, cannot add again at block ${blockNumber}`);
|
|
28
|
+
}
|
|
29
|
+
await this.#contractClasses.set(
|
|
30
|
+
key,
|
|
34
31
|
serializeContractClassPublic({ ...contractClass, l2BlockNumber: blockNumber }),
|
|
35
32
|
);
|
|
36
|
-
await this.#bytecodeCommitments.
|
|
33
|
+
await this.#bytecodeCommitments.set(key, bytecodeCommitment.toBuffer());
|
|
37
34
|
});
|
|
38
35
|
}
|
|
39
36
|
|
|
@@ -60,37 +57,6 @@ export class ContractClassStore {
|
|
|
60
57
|
async getContractClassIds(): Promise<Fr[]> {
|
|
61
58
|
return (await toArray(this.#contractClasses.keysAsync())).map(key => Fr.fromHexString(key));
|
|
62
59
|
}
|
|
63
|
-
|
|
64
|
-
async addFunctions(
|
|
65
|
-
contractClassId: Fr,
|
|
66
|
-
newPrivateFunctions: ExecutablePrivateFunctionWithMembershipProof[],
|
|
67
|
-
newUtilityFunctions: UtilityFunctionWithMembershipProof[],
|
|
68
|
-
): Promise<boolean> {
|
|
69
|
-
await this.db.transactionAsync(async () => {
|
|
70
|
-
const existingClassBuffer = await this.#contractClasses.getAsync(contractClassId.toString());
|
|
71
|
-
if (!existingClassBuffer) {
|
|
72
|
-
throw new Error(`Unknown contract class ${contractClassId} when adding private functions to store`);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const existingClass = deserializeContractClassPublic(existingClassBuffer);
|
|
76
|
-
const { privateFunctions: existingPrivateFns, utilityFunctions: existingUtilityFns } = existingClass;
|
|
77
|
-
|
|
78
|
-
const updatedClass: Omit<ContractClassPublicWithBlockNumber, 'id'> = {
|
|
79
|
-
...existingClass,
|
|
80
|
-
privateFunctions: [
|
|
81
|
-
...existingPrivateFns,
|
|
82
|
-
...newPrivateFunctions.filter(newFn => !existingPrivateFns.some(f => f.selector.equals(newFn.selector))),
|
|
83
|
-
],
|
|
84
|
-
utilityFunctions: [
|
|
85
|
-
...existingUtilityFns,
|
|
86
|
-
...newUtilityFunctions.filter(newFn => !existingUtilityFns.some(f => f.selector.equals(newFn.selector))),
|
|
87
|
-
],
|
|
88
|
-
};
|
|
89
|
-
await this.#contractClasses.set(contractClassId.toString(), serializeContractClassPublic(updatedClass));
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
60
|
}
|
|
95
61
|
|
|
96
62
|
function serializeContractClassPublic(contractClass: Omit<ContractClassPublicWithBlockNumber, 'id'>): Buffer {
|
|
@@ -98,83 +64,19 @@ function serializeContractClassPublic(contractClass: Omit<ContractClassPublicWit
|
|
|
98
64
|
contractClass.l2BlockNumber,
|
|
99
65
|
numToUInt8(contractClass.version),
|
|
100
66
|
contractClass.artifactHash,
|
|
101
|
-
contractClass.privateFunctions.length,
|
|
102
|
-
contractClass.privateFunctions.map(serializePrivateFunction),
|
|
103
|
-
contractClass.utilityFunctions.length,
|
|
104
|
-
contractClass.utilityFunctions.map(serializeUtilityFunction),
|
|
105
67
|
contractClass.packedBytecode.length,
|
|
106
68
|
contractClass.packedBytecode,
|
|
107
69
|
contractClass.privateFunctionsRoot,
|
|
108
70
|
);
|
|
109
71
|
}
|
|
110
72
|
|
|
111
|
-
function serializePrivateFunction(fn: ExecutablePrivateFunctionWithMembershipProof): Buffer {
|
|
112
|
-
return serializeToBuffer(
|
|
113
|
-
fn.selector,
|
|
114
|
-
fn.vkHash,
|
|
115
|
-
fn.bytecode.length,
|
|
116
|
-
fn.bytecode,
|
|
117
|
-
fn.functionMetadataHash,
|
|
118
|
-
fn.artifactMetadataHash,
|
|
119
|
-
fn.utilityFunctionsTreeRoot,
|
|
120
|
-
new Vector(fn.privateFunctionTreeSiblingPath),
|
|
121
|
-
fn.privateFunctionTreeLeafIndex,
|
|
122
|
-
new Vector(fn.artifactTreeSiblingPath),
|
|
123
|
-
fn.artifactTreeLeafIndex,
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function serializeUtilityFunction(fn: UtilityFunctionWithMembershipProof): Buffer {
|
|
128
|
-
return serializeToBuffer(
|
|
129
|
-
fn.selector,
|
|
130
|
-
fn.bytecode.length,
|
|
131
|
-
fn.bytecode,
|
|
132
|
-
fn.functionMetadataHash,
|
|
133
|
-
fn.artifactMetadataHash,
|
|
134
|
-
fn.privateFunctionsArtifactTreeRoot,
|
|
135
|
-
new Vector(fn.artifactTreeSiblingPath),
|
|
136
|
-
fn.artifactTreeLeafIndex,
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
73
|
function deserializeContractClassPublic(buffer: Buffer): Omit<ContractClassPublicWithBlockNumber, 'id'> {
|
|
141
74
|
const reader = BufferReader.asReader(buffer);
|
|
142
75
|
return {
|
|
143
76
|
l2BlockNumber: reader.readNumber(),
|
|
144
77
|
version: reader.readUInt8() as 1,
|
|
145
78
|
artifactHash: reader.readObject(Fr),
|
|
146
|
-
privateFunctions: reader.readVector({ fromBuffer: deserializePrivateFunction }),
|
|
147
|
-
utilityFunctions: reader.readVector({ fromBuffer: deserializeUtilityFunction }),
|
|
148
79
|
packedBytecode: reader.readBuffer(),
|
|
149
80
|
privateFunctionsRoot: reader.readObject(Fr),
|
|
150
81
|
};
|
|
151
82
|
}
|
|
152
|
-
|
|
153
|
-
function deserializePrivateFunction(buffer: Buffer | BufferReader): ExecutablePrivateFunctionWithMembershipProof {
|
|
154
|
-
const reader = BufferReader.asReader(buffer);
|
|
155
|
-
return {
|
|
156
|
-
selector: reader.readObject(FunctionSelector),
|
|
157
|
-
vkHash: reader.readObject(Fr),
|
|
158
|
-
bytecode: reader.readBuffer(),
|
|
159
|
-
functionMetadataHash: reader.readObject(Fr),
|
|
160
|
-
artifactMetadataHash: reader.readObject(Fr),
|
|
161
|
-
utilityFunctionsTreeRoot: reader.readObject(Fr),
|
|
162
|
-
privateFunctionTreeSiblingPath: reader.readVector(Fr),
|
|
163
|
-
privateFunctionTreeLeafIndex: reader.readNumber(),
|
|
164
|
-
artifactTreeSiblingPath: reader.readVector(Fr),
|
|
165
|
-
artifactTreeLeafIndex: reader.readNumber(),
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function deserializeUtilityFunction(buffer: Buffer | BufferReader): UtilityFunctionWithMembershipProof {
|
|
170
|
-
const reader = BufferReader.asReader(buffer);
|
|
171
|
-
return {
|
|
172
|
-
selector: reader.readObject(FunctionSelector),
|
|
173
|
-
bytecode: reader.readBuffer(),
|
|
174
|
-
functionMetadataHash: reader.readObject(Fr),
|
|
175
|
-
artifactMetadataHash: reader.readObject(Fr),
|
|
176
|
-
privateFunctionsArtifactTreeRoot: reader.readObject(Fr),
|
|
177
|
-
artifactTreeSiblingPath: reader.readVector(Fr),
|
|
178
|
-
artifactTreeLeafIndex: reader.readNumber(),
|
|
179
|
-
};
|
|
180
|
-
}
|
|
@@ -27,11 +27,14 @@ export class ContractInstanceStore {
|
|
|
27
27
|
|
|
28
28
|
addContractInstance(contractInstance: ContractInstanceWithAddress, blockNumber: number): Promise<void> {
|
|
29
29
|
return this.db.transactionAsync(async () => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
new
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
const key = contractInstance.address.toString();
|
|
31
|
+
if (await this.#contractInstances.hasAsync(key)) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`Contract instance at ${key} already exists (deployed at block ${await this.#contractInstancePublishedAt.getAsync(key)}), cannot add again at block ${blockNumber}`,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
await this.#contractInstances.set(key, new SerializableContractInstance(contractInstance).toBuffer());
|
|
37
|
+
await this.#contractInstancePublishedAt.set(key, blockNumber);
|
|
35
38
|
});
|
|
36
39
|
}
|
|
37
40
|
|
|
@@ -6,15 +6,26 @@ 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';
|
|
19
30
|
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
20
31
|
import type { GetContractClassLogsResponse, GetPublicLogsResponse } from '@aztec/stdlib/interfaces/client';
|
|
@@ -25,13 +36,13 @@ import type { UInt64 } from '@aztec/stdlib/types';
|
|
|
25
36
|
import { join } from 'path';
|
|
26
37
|
|
|
27
38
|
import type { InboxMessage } from '../structs/inbox_message.js';
|
|
28
|
-
import { BlockStore, type
|
|
39
|
+
import { BlockStore, type RemoveCheckpointsResult } from './block_store.js';
|
|
29
40
|
import { ContractClassStore } from './contract_class_store.js';
|
|
30
41
|
import { ContractInstanceStore } from './contract_instance_store.js';
|
|
31
42
|
import { LogStore } from './log_store.js';
|
|
32
43
|
import { MessageStore } from './message_store.js';
|
|
33
44
|
|
|
34
|
-
export const ARCHIVER_DB_VERSION =
|
|
45
|
+
export const ARCHIVER_DB_VERSION = 6;
|
|
35
46
|
export const MAX_FUNCTION_SIGNATURES = 1000;
|
|
36
47
|
export const MAX_FUNCTION_NAME_LEN = 256;
|
|
37
48
|
|
|
@@ -65,15 +76,19 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
65
76
|
constructor(
|
|
66
77
|
private db: AztecAsyncKVStore,
|
|
67
78
|
logsMaxPageSize: number = 1000,
|
|
68
|
-
l1Constants: Pick<L1RollupConstants, 'epochDuration'>,
|
|
69
79
|
) {
|
|
70
|
-
this.#blockStore = new BlockStore(db
|
|
80
|
+
this.#blockStore = new BlockStore(db);
|
|
71
81
|
this.#logStore = new LogStore(db, this.#blockStore, logsMaxPageSize);
|
|
72
82
|
this.#messageStore = new MessageStore(db);
|
|
73
83
|
this.#contractClassStore = new ContractClassStore(db);
|
|
74
84
|
this.#contractInstanceStore = new ContractInstanceStore(db);
|
|
75
85
|
}
|
|
76
86
|
|
|
87
|
+
/** Returns the underlying block store. Used by L2TipsCache. */
|
|
88
|
+
get blockStore(): BlockStore {
|
|
89
|
+
return this.#blockStore;
|
|
90
|
+
}
|
|
91
|
+
|
|
77
92
|
/** Opens a new transaction to the underlying store and runs all operations within it. */
|
|
78
93
|
public transactionAsync<T>(callback: () => Promise<T>): Promise<T> {
|
|
79
94
|
return this.db.transactionAsync(callback);
|
|
@@ -157,19 +172,14 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
157
172
|
|
|
158
173
|
/**
|
|
159
174
|
* 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.
|
|
175
|
+
* @param data - List of contract classes (with bytecode commitments) to be added.
|
|
162
176
|
* @param blockNumber - Number of the L2 block the contracts were registered in.
|
|
163
177
|
* @returns True if the operation is successful.
|
|
164
178
|
*/
|
|
165
|
-
async addContractClasses(
|
|
166
|
-
data: ContractClassPublic[],
|
|
167
|
-
bytecodeCommitments: Fr[],
|
|
168
|
-
blockNumber: BlockNumber,
|
|
169
|
-
): Promise<boolean> {
|
|
179
|
+
async addContractClasses(data: ContractClassPublicWithCommitment[], blockNumber: BlockNumber): Promise<boolean> {
|
|
170
180
|
return (
|
|
171
181
|
await Promise.all(
|
|
172
|
-
data.map(
|
|
182
|
+
data.map(c => this.#contractClassStore.addContractClass(c, c.publicBytecodeCommitment, blockNumber)),
|
|
173
183
|
)
|
|
174
184
|
).every(Boolean);
|
|
175
185
|
}
|
|
@@ -184,15 +194,6 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
184
194
|
return this.#contractClassStore.getBytecodeCommitment(contractClassId);
|
|
185
195
|
}
|
|
186
196
|
|
|
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
197
|
/**
|
|
197
198
|
* Add new contract instances from an L2 block to the store's list.
|
|
198
199
|
* @param data - List of contract instances to be added.
|
|
@@ -235,14 +236,14 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
235
236
|
}
|
|
236
237
|
|
|
237
238
|
/**
|
|
238
|
-
* Append new proposed
|
|
239
|
-
*
|
|
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.
|
|
240
241
|
* For checkpointed blocks (already published to L1), use addCheckpoints() instead.
|
|
241
|
-
* @param
|
|
242
|
+
* @param block - The proposed L2 block to be added to the store.
|
|
242
243
|
* @returns True if the operation is successful.
|
|
243
244
|
*/
|
|
244
|
-
|
|
245
|
-
return this.#blockStore.
|
|
245
|
+
addProposedBlock(block: L2Block, opts: { force?: boolean } = {}): Promise<boolean> {
|
|
246
|
+
return this.#blockStore.addProposedBlock(block, opts);
|
|
246
247
|
}
|
|
247
248
|
|
|
248
249
|
/**
|
|
@@ -259,7 +260,7 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
259
260
|
* @returns The number of the latest block
|
|
260
261
|
*/
|
|
261
262
|
getLatestBlockNumber(): Promise<BlockNumber> {
|
|
262
|
-
return this.#blockStore.
|
|
263
|
+
return this.#blockStore.getLatestL2BlockNumber();
|
|
263
264
|
}
|
|
264
265
|
|
|
265
266
|
/**
|
|
@@ -369,6 +370,22 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
369
370
|
return this.#blockStore.getBlockHeaderByArchive(archive);
|
|
370
371
|
}
|
|
371
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
|
+
|
|
372
389
|
/**
|
|
373
390
|
* Gets a tx effect.
|
|
374
391
|
* @param txHash - The hash of the tx corresponding to the tx effect.
|
|
@@ -383,8 +400,11 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
383
400
|
* @param txHash - The hash of a tx we try to get the receipt for.
|
|
384
401
|
* @returns The requested tx receipt (or undefined if not found).
|
|
385
402
|
*/
|
|
386
|
-
getSettledTxReceipt(
|
|
387
|
-
|
|
403
|
+
getSettledTxReceipt(
|
|
404
|
+
txHash: TxHash,
|
|
405
|
+
l1Constants?: Pick<L1RollupConstants, 'epochDuration'>,
|
|
406
|
+
): Promise<TxReceipt | undefined> {
|
|
407
|
+
return this.#blockStore.getSettledTxReceipt(txHash, l1Constants);
|
|
388
408
|
}
|
|
389
409
|
|
|
390
410
|
/**
|
|
@@ -445,10 +465,11 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
445
465
|
* array implies no logs match that tag.
|
|
446
466
|
* @param tags - The tags to search for.
|
|
447
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.
|
|
448
469
|
*/
|
|
449
|
-
getPrivateLogsByTags(tags: SiloedTag[], page?: number): Promise<TxScopedL2Log[][]> {
|
|
470
|
+
getPrivateLogsByTags(tags: SiloedTag[], page?: number, upToBlockNumber?: BlockNumber): Promise<TxScopedL2Log[][]> {
|
|
450
471
|
try {
|
|
451
|
-
return this.#logStore.getPrivateLogsByTags(tags, page);
|
|
472
|
+
return this.#logStore.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
452
473
|
} catch (err) {
|
|
453
474
|
return Promise.reject(err);
|
|
454
475
|
}
|
|
@@ -460,14 +481,16 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
460
481
|
* @param contractAddress - The contract address to search logs for.
|
|
461
482
|
* @param tags - The tags to search for.
|
|
462
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.
|
|
463
485
|
*/
|
|
464
486
|
getPublicLogsByTagsFromContract(
|
|
465
487
|
contractAddress: AztecAddress,
|
|
466
488
|
tags: Tag[],
|
|
467
489
|
page?: number,
|
|
490
|
+
upToBlockNumber?: BlockNumber,
|
|
468
491
|
): Promise<TxScopedL2Log[][]> {
|
|
469
492
|
try {
|
|
470
|
-
return this.#logStore.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
493
|
+
return this.#logStore.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
471
494
|
} catch (err) {
|
|
472
495
|
return Promise.reject(err);
|
|
473
496
|
}
|
|
@@ -515,6 +538,22 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
515
538
|
await this.#blockStore.setProvenCheckpointNumber(checkpointNumber);
|
|
516
539
|
}
|
|
517
540
|
|
|
541
|
+
/**
|
|
542
|
+
* Gets the number of the latest finalized checkpoint processed.
|
|
543
|
+
* @returns The number of the latest finalized checkpoint processed.
|
|
544
|
+
*/
|
|
545
|
+
getFinalizedCheckpointNumber(): Promise<CheckpointNumber> {
|
|
546
|
+
return this.#blockStore.getFinalizedCheckpointNumber();
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Stores the number of the latest finalized checkpoint processed.
|
|
551
|
+
* @param checkpointNumber - The number of the latest finalized checkpoint processed.
|
|
552
|
+
*/
|
|
553
|
+
async setFinalizedCheckpointNumber(checkpointNumber: CheckpointNumber) {
|
|
554
|
+
await this.#blockStore.setFinalizedCheckpointNumber(checkpointNumber);
|
|
555
|
+
}
|
|
556
|
+
|
|
518
557
|
async setBlockSynchedL1BlockNumber(l1BlockNumber: bigint) {
|
|
519
558
|
await this.#blockStore.setSynchedL1BlockNumber(l1BlockNumber);
|
|
520
559
|
}
|
|
@@ -558,6 +597,11 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
558
597
|
return this.#messageStore.rollbackL1ToL2MessagesToCheckpoint(targetCheckpointNumber);
|
|
559
598
|
}
|
|
560
599
|
|
|
600
|
+
/** Persists the inbox tree-in-progress checkpoint number from L1 state. */
|
|
601
|
+
public setInboxTreeInProgress(value: bigint): Promise<void> {
|
|
602
|
+
return this.#messageStore.setInboxTreeInProgress(value);
|
|
603
|
+
}
|
|
604
|
+
|
|
561
605
|
/** Returns an async iterator to all L1 to L2 messages on the range. */
|
|
562
606
|
public iterateL1ToL2Messages(range: CustomRange<bigint> = {}): AsyncIterableIterator<InboxMessage> {
|
|
563
607
|
return this.#messageStore.iterateL1ToL2Messages(range);
|
|
@@ -578,6 +622,38 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
578
622
|
return this.#blockStore.setPendingChainValidationStatus(status);
|
|
579
623
|
}
|
|
580
624
|
|
|
625
|
+
/**
|
|
626
|
+
* Gets the L2 block number of the proposed checkpoint.
|
|
627
|
+
* @returns The block number of the proposed checkpoint, or the checkpointed block number if none.
|
|
628
|
+
*/
|
|
629
|
+
public getProposedCheckpointL2BlockNumber(): Promise<BlockNumber> {
|
|
630
|
+
return this.#blockStore.getProposedCheckpointL2BlockNumber();
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/** Returns the checkpoint data at the proposed tip */
|
|
634
|
+
public getProposedCheckpoint(): Promise<CommonCheckpointData | undefined> {
|
|
635
|
+
return this.#blockStore.getProposedCheckpoint();
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/** Returns the proposed checkpoint data, or undefined if no proposed checkpoint exists. No fallback to confirmed. */
|
|
639
|
+
public getProposedCheckpointOnly(): Promise<ProposedCheckpointData | undefined> {
|
|
640
|
+
return this.#blockStore.getProposedCheckpointOnly();
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* Set proposed checkpoint
|
|
645
|
+
* @param proposedCheckpoint
|
|
646
|
+
* @returns
|
|
647
|
+
*/
|
|
648
|
+
public setProposedCheckpoint(proposedCheckpoint: ProposedCheckpointInput): Promise<void> {
|
|
649
|
+
return this.#blockStore.setProposedCheckpoint(proposedCheckpoint);
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
/** Deletes the proposed checkpoint from storage. */
|
|
653
|
+
public deleteProposedCheckpoint(): Promise<void> {
|
|
654
|
+
return this.#blockStore.deleteProposedCheckpoint();
|
|
655
|
+
}
|
|
656
|
+
|
|
581
657
|
/**
|
|
582
658
|
* Gets the number of the latest L2 block processed.
|
|
583
659
|
* @returns The number of the latest L2 block processed.
|
|
@@ -618,6 +694,11 @@ export class KVArchiverDataStore implements ContractDataSource {
|
|
|
618
694
|
return this.#blockStore.getCheckpointData(checkpointNumber);
|
|
619
695
|
}
|
|
620
696
|
|
|
697
|
+
/** Returns checkpoint data for all checkpoints whose slot falls within the given range (inclusive). */
|
|
698
|
+
getCheckpointDataForSlotRange(startSlot: SlotNumber, endSlot: SlotNumber): Promise<CheckpointData[]> {
|
|
699
|
+
return this.#blockStore.getCheckpointDataForSlotRange(startSlot, endSlot);
|
|
700
|
+
}
|
|
701
|
+
|
|
621
702
|
/**
|
|
622
703
|
* Gets all blocks that have the given slot number.
|
|
623
704
|
* @param slotNumber - The slot number to search for.
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { GENESIS_BLOCK_HEADER_HASH, INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
2
|
+
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { type BlockData, type CheckpointId, GENESIS_CHECKPOINT_HEADER_HASH, type L2Tips } from '@aztec/stdlib/block';
|
|
4
|
+
|
|
5
|
+
import type { BlockStore } from './block_store.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* In-memory cache for L2 chain tips (proposed, checkpointed, proven, finalized).
|
|
9
|
+
* Populated from the BlockStore on first access, then kept up-to-date by the ArchiverDataStoreUpdater.
|
|
10
|
+
* Refresh calls should happen within the store transaction that mutates block data to ensure consistency.
|
|
11
|
+
*/
|
|
12
|
+
export class L2TipsCache {
|
|
13
|
+
#tipsPromise: Promise<L2Tips> | undefined;
|
|
14
|
+
|
|
15
|
+
constructor(private blockStore: BlockStore) {}
|
|
16
|
+
|
|
17
|
+
/** Returns the cached L2 tips. Loads from the block store on first call. */
|
|
18
|
+
public getL2Tips(): Promise<L2Tips> {
|
|
19
|
+
return (this.#tipsPromise ??= this.loadFromStore());
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Reloads the L2 tips from the block store. Should be called within the store transaction that mutates data. */
|
|
23
|
+
public async refresh(): Promise<void> {
|
|
24
|
+
this.#tipsPromise = this.loadFromStore();
|
|
25
|
+
await this.#tipsPromise;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private async loadFromStore(): Promise<L2Tips> {
|
|
29
|
+
const [
|
|
30
|
+
latestBlockNumber,
|
|
31
|
+
provenBlockNumber,
|
|
32
|
+
proposedCheckpointBlockNumber,
|
|
33
|
+
checkpointedBlockNumber,
|
|
34
|
+
finalizedBlockNumber,
|
|
35
|
+
] = await Promise.all([
|
|
36
|
+
this.blockStore.getLatestL2BlockNumber(),
|
|
37
|
+
this.blockStore.getProvenBlockNumber(),
|
|
38
|
+
this.blockStore.getProposedCheckpointL2BlockNumber(),
|
|
39
|
+
this.blockStore.getCheckpointedL2BlockNumber(),
|
|
40
|
+
this.blockStore.getFinalizedL2BlockNumber(),
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
const genesisBlockHeader = {
|
|
44
|
+
blockHash: GENESIS_BLOCK_HEADER_HASH,
|
|
45
|
+
checkpointNumber: CheckpointNumber.ZERO,
|
|
46
|
+
} as const;
|
|
47
|
+
const beforeInitialBlockNumber = BlockNumber(INITIAL_L2_BLOCK_NUM - 1);
|
|
48
|
+
|
|
49
|
+
const getBlockData = (blockNumber: BlockNumber) =>
|
|
50
|
+
blockNumber > beforeInitialBlockNumber ? this.blockStore.getBlockData(blockNumber) : genesisBlockHeader;
|
|
51
|
+
|
|
52
|
+
const [latestBlockData, provenBlockData, proposedCheckpointBlockData, checkpointedBlockData, finalizedBlockData] =
|
|
53
|
+
await Promise.all(
|
|
54
|
+
[
|
|
55
|
+
latestBlockNumber,
|
|
56
|
+
provenBlockNumber,
|
|
57
|
+
proposedCheckpointBlockNumber,
|
|
58
|
+
checkpointedBlockNumber,
|
|
59
|
+
finalizedBlockNumber,
|
|
60
|
+
].map(getBlockData),
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
if (
|
|
64
|
+
!latestBlockData ||
|
|
65
|
+
!provenBlockData ||
|
|
66
|
+
!finalizedBlockData ||
|
|
67
|
+
!checkpointedBlockData ||
|
|
68
|
+
!proposedCheckpointBlockData
|
|
69
|
+
) {
|
|
70
|
+
throw new Error('Failed to load block data for L2 tips');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const [provenCheckpointId, finalizedCheckpointId, proposedCheckpointId, checkpointedCheckpointId] =
|
|
74
|
+
await Promise.all([
|
|
75
|
+
this.getCheckpointIdForBlock(provenBlockData),
|
|
76
|
+
this.getCheckpointIdForBlock(finalizedBlockData),
|
|
77
|
+
this.getCheckpointIdForProposedCheckpoint(checkpointedBlockData),
|
|
78
|
+
this.getCheckpointIdForBlock(checkpointedBlockData),
|
|
79
|
+
]);
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
proposed: { number: latestBlockNumber, hash: latestBlockData.blockHash.toString() },
|
|
83
|
+
proven: {
|
|
84
|
+
block: { number: provenBlockNumber, hash: provenBlockData.blockHash.toString() },
|
|
85
|
+
checkpoint: provenCheckpointId,
|
|
86
|
+
},
|
|
87
|
+
proposedCheckpoint: {
|
|
88
|
+
block: { number: proposedCheckpointBlockNumber, hash: proposedCheckpointBlockData.blockHash.toString() },
|
|
89
|
+
checkpoint: proposedCheckpointId,
|
|
90
|
+
},
|
|
91
|
+
finalized: {
|
|
92
|
+
block: { number: finalizedBlockNumber, hash: finalizedBlockData.blockHash.toString() },
|
|
93
|
+
checkpoint: finalizedCheckpointId,
|
|
94
|
+
},
|
|
95
|
+
checkpointed: {
|
|
96
|
+
block: { number: checkpointedBlockNumber, hash: checkpointedBlockData.blockHash.toString() },
|
|
97
|
+
checkpoint: checkpointedCheckpointId,
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private async getCheckpointIdForProposedCheckpoint(
|
|
103
|
+
checkpointedBlockData: Pick<BlockData, 'checkpointNumber'>,
|
|
104
|
+
): Promise<CheckpointId> {
|
|
105
|
+
const checkpointData = await this.blockStore.getProposedCheckpointOnly();
|
|
106
|
+
if (!checkpointData) {
|
|
107
|
+
return this.getCheckpointIdForBlock(checkpointedBlockData);
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
number: checkpointData.checkpointNumber,
|
|
111
|
+
hash: checkpointData.header.hash().toString(),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
private async getCheckpointIdForBlock(blockData: Pick<BlockData, 'checkpointNumber'>): Promise<CheckpointId> {
|
|
116
|
+
const checkpointData = await this.blockStore.getCheckpointData(blockData.checkpointNumber);
|
|
117
|
+
if (!checkpointData) {
|
|
118
|
+
return {
|
|
119
|
+
number: CheckpointNumber.ZERO,
|
|
120
|
+
hash: GENESIS_CHECKPOINT_HEADER_HASH.toString(),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
number: checkpointData.checkpointNumber,
|
|
125
|
+
hash: checkpointData.header.hash().toString(),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|