@aztec/archiver 0.0.1-commit.96bb3f7 → 0.0.1-commit.993d240
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 +164 -22
- package/dest/archiver.d.ts +158 -0
- package/dest/archiver.d.ts.map +1 -0
- package/dest/archiver.js +881 -0
- package/dest/config.d.ts +33 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/{archiver/config.js → config.js} +31 -14
- package/dest/errors.d.ts +87 -0
- package/dest/errors.d.ts.map +1 -0
- package/dest/errors.js +129 -0
- package/dest/factory.d.ts +16 -10
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +112 -20
- package/dest/index.d.ts +19 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +17 -3
- package/dest/interfaces.d.ts +9 -0
- package/dest/interfaces.d.ts.map +1 -0
- package/dest/interfaces.js +3 -0
- package/dest/{archiver/l1 → l1}/bin/retrieve-calldata.d.ts +1 -1
- package/dest/l1/bin/retrieve-calldata.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/bin/retrieve-calldata.js +35 -32
- package/dest/l1/calldata_retriever.d.ts +136 -0
- package/dest/l1/calldata_retriever.d.ts.map +1 -0
- package/dest/l1/calldata_retriever.js +412 -0
- package/dest/l1/data_retrieval.d.ts +97 -0
- package/dest/l1/data_retrieval.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/data_retrieval.js +65 -89
- package/dest/{archiver/l1 → l1}/debug_tx.d.ts +1 -1
- package/dest/l1/debug_tx.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/spire_proposer.d.ts +5 -5
- package/dest/l1/spire_proposer.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/spire_proposer.js +9 -17
- package/dest/l1/trace_tx.d.ts +43 -0
- package/dest/l1/trace_tx.d.ts.map +1 -0
- package/dest/l1/types.d.ts +12 -0
- package/dest/l1/types.d.ts.map +1 -0
- 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/{archiver/l1 → l1}/validate_trace.d.ts +6 -3
- package/dest/l1/validate_trace.d.ts.map +1 -0
- package/dest/{archiver/l1 → l1}/validate_trace.js +13 -9
- package/dest/modules/contract_data_source_adapter.d.ts +25 -0
- package/dest/modules/contract_data_source_adapter.d.ts.map +1 -0
- package/dest/modules/contract_data_source_adapter.js +40 -0
- package/dest/modules/data_source_base.d.ts +113 -0
- package/dest/modules/data_source_base.d.ts.map +1 -0
- package/dest/modules/data_source_base.js +351 -0
- package/dest/modules/data_store_updater.d.ts +105 -0
- package/dest/modules/data_store_updater.d.ts.map +1 -0
- package/dest/modules/data_store_updater.js +392 -0
- package/dest/modules/instrumentation.d.ts +55 -0
- package/dest/modules/instrumentation.d.ts.map +1 -0
- package/dest/{archiver → modules}/instrumentation.js +61 -19
- package/dest/modules/l1_synchronizer.d.ts +77 -0
- package/dest/modules/l1_synchronizer.d.ts.map +1 -0
- package/dest/modules/l1_synchronizer.js +1344 -0
- package/dest/modules/validation.d.ts +18 -0
- package/dest/modules/validation.d.ts.map +1 -0
- package/dest/{archiver → modules}/validation.js +12 -6
- package/dest/store/block_store.d.ts +300 -0
- package/dest/store/block_store.d.ts.map +1 -0
- package/dest/store/block_store.js +1219 -0
- package/dest/store/contract_class_store.d.ts +31 -0
- package/dest/store/contract_class_store.d.ts.map +1 -0
- package/dest/store/contract_class_store.js +80 -0
- package/dest/store/contract_instance_store.d.ts +51 -0
- package/dest/store/contract_instance_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/contract_instance_store.js +38 -3
- package/dest/store/data_stores.d.ts +68 -0
- package/dest/store/data_stores.d.ts.map +1 -0
- package/dest/store/data_stores.js +54 -0
- package/dest/store/function_names_cache.d.ts +17 -0
- package/dest/store/function_names_cache.d.ts.map +1 -0
- package/dest/store/function_names_cache.js +30 -0
- package/dest/store/l2_tips_cache.d.ts +25 -0
- package/dest/store/l2_tips_cache.d.ts.map +1 -0
- package/dest/store/l2_tips_cache.js +26 -0
- package/dest/store/log_store.d.ts +59 -0
- package/dest/store/log_store.d.ts.map +1 -0
- package/dest/store/log_store.js +310 -0
- package/dest/store/log_store_codec.d.ts +70 -0
- package/dest/store/log_store_codec.d.ts.map +1 -0
- package/dest/store/log_store_codec.js +101 -0
- package/dest/store/message_store.d.ts +50 -0
- package/dest/store/message_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/message_store.js +51 -9
- package/dest/{archiver/structs → structs}/data_retrieval.d.ts +1 -1
- package/dest/structs/data_retrieval.d.ts.map +1 -0
- package/dest/structs/inbox_message.d.ts +15 -0
- package/dest/structs/inbox_message.d.ts.map +1 -0
- package/dest/{archiver/structs → structs}/published.d.ts +1 -1
- package/dest/structs/published.d.ts.map +1 -0
- package/dest/test/fake_l1_state.d.ts +214 -0
- package/dest/test/fake_l1_state.d.ts.map +1 -0
- package/dest/test/fake_l1_state.js +517 -0
- package/dest/test/index.d.ts +2 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +4 -1
- package/dest/test/mock_archiver.d.ts +2 -2
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +3 -3
- 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 +65 -41
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +330 -151
- package/dest/test/mock_structs.d.ts +81 -3
- package/dest/test/mock_structs.d.ts.map +1 -1
- package/dest/test/mock_structs.js +152 -7
- package/dest/test/noop_l1_archiver.d.ts +29 -0
- package/dest/test/noop_l1_archiver.d.ts.map +1 -0
- package/dest/test/noop_l1_archiver.js +85 -0
- package/package.json +17 -18
- package/src/archiver.ts +681 -0
- package/src/{archiver/config.ts → config.ts} +43 -12
- package/src/errors.ts +203 -0
- package/src/factory.ts +175 -22
- package/src/index.ts +27 -3
- package/src/interfaces.ts +9 -0
- package/src/l1/README.md +55 -0
- package/src/{archiver/l1 → l1}/bin/retrieve-calldata.ts +45 -33
- package/src/l1/calldata_retriever.ts +522 -0
- package/src/{archiver/l1 → l1}/data_retrieval.ts +106 -134
- package/src/{archiver/l1 → l1}/spire_proposer.ts +7 -15
- package/src/l1/validate_historical_logs.ts +140 -0
- package/src/{archiver/l1 → l1}/validate_trace.ts +24 -6
- package/src/modules/contract_data_source_adapter.ts +55 -0
- package/src/modules/data_source_base.ts +493 -0
- package/src/modules/data_store_updater.ts +518 -0
- package/src/{archiver → modules}/instrumentation.ts +72 -20
- package/src/modules/l1_synchronizer.ts +1257 -0
- package/src/{archiver → modules}/validation.ts +15 -9
- package/src/store/block_store.ts +1590 -0
- package/src/store/contract_class_store.ts +108 -0
- package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +52 -6
- package/src/store/data_stores.ts +104 -0
- package/src/store/function_names_cache.ts +37 -0
- package/src/store/l2_tips_cache.ts +35 -0
- package/src/store/log_store.ts +379 -0
- package/src/store/log_store_codec.ts +132 -0
- package/src/{archiver/kv_archiver_store → store}/message_store.ts +60 -10
- package/src/{archiver/structs → structs}/inbox_message.ts +1 -1
- package/src/test/fake_l1_state.ts +770 -0
- package/src/test/index.ts +4 -0
- package/src/test/mock_archiver.ts +4 -3
- package/src/test/mock_l1_to_l2_message_source.ts +1 -0
- package/src/test/mock_l2_block_source.ts +403 -171
- package/src/test/mock_structs.ts +283 -8
- package/src/test/noop_l1_archiver.ts +139 -0
- package/dest/archiver/archiver.d.ts +0 -307
- package/dest/archiver/archiver.d.ts.map +0 -1
- package/dest/archiver/archiver.js +0 -2102
- package/dest/archiver/archiver_store.d.ts +0 -315
- package/dest/archiver/archiver_store.d.ts.map +0 -1
- package/dest/archiver/archiver_store.js +0 -4
- package/dest/archiver/archiver_store_test_suite.d.ts +0 -8
- package/dest/archiver/archiver_store_test_suite.d.ts.map +0 -1
- package/dest/archiver/archiver_store_test_suite.js +0 -2770
- package/dest/archiver/config.d.ts +0 -22
- package/dest/archiver/config.d.ts.map +0 -1
- package/dest/archiver/errors.d.ts +0 -36
- package/dest/archiver/errors.d.ts.map +0 -1
- package/dest/archiver/errors.js +0 -54
- package/dest/archiver/index.d.ts +0 -7
- package/dest/archiver/index.d.ts.map +0 -1
- package/dest/archiver/index.js +0 -4
- package/dest/archiver/instrumentation.d.ts +0 -37
- package/dest/archiver/instrumentation.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -164
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/block_store.js +0 -626
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +0 -18
- package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/contract_class_store.js +0 -120
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +0 -24
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +0 -159
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/kv_archiver_store.js +0 -316
- package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -45
- package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/log_store.js +0 -401
- package/dest/archiver/kv_archiver_store/message_store.d.ts +0 -40
- package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
- package/dest/archiver/l1/bin/retrieve-calldata.d.ts.map +0 -1
- package/dest/archiver/l1/calldata_retriever.d.ts +0 -112
- package/dest/archiver/l1/calldata_retriever.d.ts.map +0 -1
- package/dest/archiver/l1/calldata_retriever.js +0 -471
- package/dest/archiver/l1/data_retrieval.d.ts +0 -90
- package/dest/archiver/l1/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/l1/debug_tx.d.ts.map +0 -1
- package/dest/archiver/l1/spire_proposer.d.ts.map +0 -1
- package/dest/archiver/l1/trace_tx.d.ts +0 -97
- package/dest/archiver/l1/trace_tx.d.ts.map +0 -1
- package/dest/archiver/l1/types.d.ts +0 -12
- package/dest/archiver/l1/types.d.ts.map +0 -1
- package/dest/archiver/l1/validate_trace.d.ts.map +0 -1
- package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/structs/inbox_message.d.ts +0 -15
- package/dest/archiver/structs/inbox_message.d.ts.map +0 -1
- package/dest/archiver/structs/published.d.ts.map +0 -1
- package/dest/archiver/validation.d.ts +0 -17
- package/dest/archiver/validation.d.ts.map +0 -1
- package/dest/rpc/index.d.ts +0 -9
- package/dest/rpc/index.d.ts.map +0 -1
- package/dest/rpc/index.js +0 -15
- package/src/archiver/archiver.ts +0 -2265
- package/src/archiver/archiver_store.ts +0 -380
- package/src/archiver/archiver_store_test_suite.ts +0 -2842
- package/src/archiver/errors.ts +0 -90
- package/src/archiver/index.ts +0 -6
- package/src/archiver/kv_archiver_store/block_store.ts +0 -850
- package/src/archiver/kv_archiver_store/contract_class_store.ts +0 -176
- package/src/archiver/kv_archiver_store/kv_archiver_store.ts +0 -442
- package/src/archiver/kv_archiver_store/log_store.ts +0 -516
- package/src/archiver/l1/README.md +0 -98
- package/src/archiver/l1/calldata_retriever.ts +0 -641
- package/src/rpc/index.ts +0 -16
- /package/dest/{archiver/l1 → l1}/debug_tx.js +0 -0
- /package/dest/{archiver/l1 → l1}/trace_tx.js +0 -0
- /package/dest/{archiver/l1 → l1}/types.js +0 -0
- /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
- /package/dest/{archiver/structs → structs}/inbox_message.js +0 -0
- /package/dest/{archiver/structs → structs}/published.js +0 -0
- /package/src/{archiver/l1 → l1}/debug_tx.ts +0 -0
- /package/src/{archiver/l1 → l1}/trace_tx.ts +0 -0
- /package/src/{archiver/l1 → l1}/types.ts +0 -0
- /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
- /package/src/{archiver/structs → structs}/published.ts +0 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import { toArray } from '@aztec/foundation/iterable';
|
|
3
|
+
import { BufferReader, numToUInt8, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
4
|
+
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
5
|
+
import type {
|
|
6
|
+
ContractClassPublic,
|
|
7
|
+
ContractClassPublicWithBlockNumber,
|
|
8
|
+
ContractClassPublicWithCommitment,
|
|
9
|
+
} from '@aztec/stdlib/contract';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* LMDB-based contract class storage for the archiver.
|
|
13
|
+
*/
|
|
14
|
+
export class ContractClassStore {
|
|
15
|
+
#contractClasses: AztecAsyncMap<string, Buffer>;
|
|
16
|
+
#bytecodeCommitments: AztecAsyncMap<string, Buffer>;
|
|
17
|
+
|
|
18
|
+
constructor(private db: AztecAsyncKVStore) {
|
|
19
|
+
this.#contractClasses = db.openMap('archiver_contract_classes');
|
|
20
|
+
this.#bytecodeCommitments = db.openMap('archiver_bytecode_commitments');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Adds multiple contract classes to the store.
|
|
25
|
+
* @param data - Contract classes (with bytecode commitments) to add.
|
|
26
|
+
* @param blockNumber - L2 block number where the classes were registered.
|
|
27
|
+
* @returns True if every insert succeeded.
|
|
28
|
+
*/
|
|
29
|
+
async addContractClasses(data: ContractClassPublicWithCommitment[], blockNumber: number): Promise<boolean> {
|
|
30
|
+
return (await Promise.all(data.map(c => this.addContractClass(c, c.publicBytecodeCommitment, blockNumber)))).every(
|
|
31
|
+
Boolean,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Removes multiple contract classes from the store, but only if they were registered at or after the given block.
|
|
37
|
+
* @param data - Contract classes to delete.
|
|
38
|
+
* @param blockNumber - Lower bound on the block number at which the classes were registered.
|
|
39
|
+
* @returns True if every delete succeeded.
|
|
40
|
+
*/
|
|
41
|
+
async deleteContractClasses(data: ContractClassPublic[], blockNumber: number): Promise<boolean> {
|
|
42
|
+
return (await Promise.all(data.map(c => this.deleteContractClass(c, blockNumber)))).every(Boolean);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async addContractClass(
|
|
46
|
+
contractClass: ContractClassPublic,
|
|
47
|
+
bytecodeCommitment: Fr,
|
|
48
|
+
blockNumber: number,
|
|
49
|
+
): Promise<void> {
|
|
50
|
+
await this.db.transactionAsync(async () => {
|
|
51
|
+
const key = contractClass.id.toString();
|
|
52
|
+
if (await this.#contractClasses.hasAsync(key)) {
|
|
53
|
+
throw new Error(`Contract class ${key} already exists, cannot add again at block ${blockNumber}`);
|
|
54
|
+
}
|
|
55
|
+
await this.#contractClasses.set(
|
|
56
|
+
key,
|
|
57
|
+
serializeContractClassPublic({ ...contractClass, l2BlockNumber: blockNumber }),
|
|
58
|
+
);
|
|
59
|
+
await this.#bytecodeCommitments.set(key, bytecodeCommitment.toBuffer());
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async deleteContractClass(contractClass: ContractClassPublic, blockNumber: number): Promise<void> {
|
|
64
|
+
const restoredContractClass = await this.#contractClasses.getAsync(contractClass.id.toString());
|
|
65
|
+
if (restoredContractClass && deserializeContractClassPublic(restoredContractClass).l2BlockNumber >= blockNumber) {
|
|
66
|
+
await this.db.transactionAsync(async () => {
|
|
67
|
+
await this.#contractClasses.delete(contractClass.id.toString());
|
|
68
|
+
await this.#bytecodeCommitments.delete(contractClass.id.toString());
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async getContractClass(id: Fr): Promise<ContractClassPublic | undefined> {
|
|
74
|
+
const contractClass = await this.#contractClasses.getAsync(id.toString());
|
|
75
|
+
return contractClass && { ...deserializeContractClassPublic(contractClass), id };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async getBytecodeCommitment(id: Fr): Promise<Fr | undefined> {
|
|
79
|
+
const value = await this.#bytecodeCommitments.getAsync(id.toString());
|
|
80
|
+
return value === undefined ? undefined : Fr.fromBuffer(value);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async getContractClassIds(): Promise<Fr[]> {
|
|
84
|
+
return (await toArray(this.#contractClasses.keysAsync())).map(key => Fr.fromHexString(key));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function serializeContractClassPublic(contractClass: Omit<ContractClassPublicWithBlockNumber, 'id'>): Buffer {
|
|
89
|
+
return serializeToBuffer(
|
|
90
|
+
contractClass.l2BlockNumber,
|
|
91
|
+
numToUInt8(contractClass.version),
|
|
92
|
+
contractClass.artifactHash,
|
|
93
|
+
contractClass.packedBytecode.length,
|
|
94
|
+
contractClass.packedBytecode,
|
|
95
|
+
contractClass.privateFunctionsRoot,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function deserializeContractClassPublic(buffer: Buffer): Omit<ContractClassPublicWithBlockNumber, 'id'> {
|
|
100
|
+
const reader = BufferReader.asReader(buffer);
|
|
101
|
+
return {
|
|
102
|
+
l2BlockNumber: reader.readNumber(),
|
|
103
|
+
version: reader.readUInt8() as 1,
|
|
104
|
+
artifactHash: reader.readObject(Fr),
|
|
105
|
+
packedBytecode: reader.readBuffer(),
|
|
106
|
+
privateFunctionsRoot: reader.readObject(Fr),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
@@ -12,7 +12,7 @@ import type { UInt64 } from '@aztec/stdlib/types';
|
|
|
12
12
|
type ContractInstanceUpdateKey = [string, string] | [string, string, number];
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* LMDB
|
|
15
|
+
* LMDB-based contract instance storage for the archiver.
|
|
16
16
|
*/
|
|
17
17
|
export class ContractInstanceStore {
|
|
18
18
|
#contractInstances: AztecAsyncMap<string, Buffer>;
|
|
@@ -25,13 +25,59 @@ export class ContractInstanceStore {
|
|
|
25
25
|
this.#contractInstanceUpdates = db.openMap('archiver_contract_instance_updates');
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Adds multiple contract instances to the store.
|
|
30
|
+
* @param data - Contract instances to add.
|
|
31
|
+
* @param blockNumber - L2 block number where the instances were deployed.
|
|
32
|
+
* @returns True if every insert succeeded.
|
|
33
|
+
*/
|
|
34
|
+
async addContractInstances(data: ContractInstanceWithAddress[], blockNumber: number): Promise<boolean> {
|
|
35
|
+
return (await Promise.all(data.map(c => this.addContractInstance(c, blockNumber)))).every(Boolean);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Removes multiple contract instances from the store.
|
|
40
|
+
* @param data - Contract instances to delete.
|
|
41
|
+
* @returns True if every delete succeeded.
|
|
42
|
+
*/
|
|
43
|
+
async deleteContractInstances(data: ContractInstanceWithAddress[]): Promise<boolean> {
|
|
44
|
+
return (await Promise.all(data.map(c => this.deleteContractInstance(c)))).every(Boolean);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Adds multiple contract instance updates to the store.
|
|
49
|
+
* @param data - Contract instance updates to add.
|
|
50
|
+
* @param timestamp - Timestamp at which the updates were scheduled.
|
|
51
|
+
* @returns True if every insert succeeded.
|
|
52
|
+
*/
|
|
53
|
+
async addContractInstanceUpdates(data: ContractInstanceUpdateWithAddress[], timestamp: UInt64): Promise<boolean> {
|
|
54
|
+
return (
|
|
55
|
+
await Promise.all(data.map((update, logIndex) => this.addContractInstanceUpdate(update, timestamp, logIndex)))
|
|
56
|
+
).every(Boolean);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Removes multiple contract instance updates from the store.
|
|
61
|
+
* @param data - Contract instance updates to delete.
|
|
62
|
+
* @param timestamp - Timestamp at which the updates were scheduled.
|
|
63
|
+
* @returns True if every delete succeeded.
|
|
64
|
+
*/
|
|
65
|
+
async deleteContractInstanceUpdates(data: ContractInstanceUpdateWithAddress[], timestamp: UInt64): Promise<boolean> {
|
|
66
|
+
return (
|
|
67
|
+
await Promise.all(data.map((update, logIndex) => this.deleteContractInstanceUpdate(update, timestamp, logIndex)))
|
|
68
|
+
).every(Boolean);
|
|
69
|
+
}
|
|
70
|
+
|
|
28
71
|
addContractInstance(contractInstance: ContractInstanceWithAddress, blockNumber: number): Promise<void> {
|
|
29
72
|
return this.db.transactionAsync(async () => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
new
|
|
33
|
-
|
|
34
|
-
|
|
73
|
+
const key = contractInstance.address.toString();
|
|
74
|
+
if (await this.#contractInstances.hasAsync(key)) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
`Contract instance at ${key} already exists (deployed at block ${await this.#contractInstancePublishedAt.getAsync(key)}), cannot add again at block ${blockNumber}`,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
await this.#contractInstances.set(key, new SerializableContractInstance(contractInstance).toBuffer());
|
|
80
|
+
await this.#contractInstancePublishedAt.set(key, blockNumber);
|
|
35
81
|
});
|
|
36
82
|
}
|
|
37
83
|
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { L1BlockId } from '@aztec/ethereum/l1-types';
|
|
2
|
+
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
3
|
+
import type { BlockHash } from '@aztec/stdlib/block';
|
|
4
|
+
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
5
|
+
|
|
6
|
+
import { join } from 'path';
|
|
7
|
+
|
|
8
|
+
import { ArchiverContractDataSourceAdapter } from '../modules/contract_data_source_adapter.js';
|
|
9
|
+
import { BlockStore } from './block_store.js';
|
|
10
|
+
import { ContractClassStore } from './contract_class_store.js';
|
|
11
|
+
import { ContractInstanceStore } from './contract_instance_store.js';
|
|
12
|
+
import { FunctionNamesCache } from './function_names_cache.js';
|
|
13
|
+
import { LogStore } from './log_store.js';
|
|
14
|
+
import { MessageStore } from './message_store.js';
|
|
15
|
+
|
|
16
|
+
export const ARCHIVER_DB_VERSION = 7;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Represents the latest L1 block processed by the archiver for various objects in L2.
|
|
20
|
+
*/
|
|
21
|
+
export type ArchiverL1SynchPoint = {
|
|
22
|
+
/** Number of the last L1 block that added a new L2 checkpoint metadata. */
|
|
23
|
+
blocksSynchedTo?: bigint;
|
|
24
|
+
/** Last L1 block checked for L1 to L2 messages. */
|
|
25
|
+
messagesSynchedTo?: L1BlockId;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Bundle of archiver-owned LMDB substores plus the in-memory caches that span them.
|
|
30
|
+
*
|
|
31
|
+
* Replaces the former `KVArchiverDataStore` pass-through wrapper. Callers reach into
|
|
32
|
+
* the relevant substore directly (e.g. `stores.blocks.getBlock`) and use
|
|
33
|
+
* {@link createArchiverDataStores} to wire them up against a shared KV store.
|
|
34
|
+
*/
|
|
35
|
+
export type ArchiverDataStores = {
|
|
36
|
+
/** The underlying key-value store. Use {@link AztecAsyncKVStore.transactionAsync} to compose updates atomically. */
|
|
37
|
+
db: AztecAsyncKVStore;
|
|
38
|
+
/** Blocks, checkpoints, tx effects, proven/finalized state. */
|
|
39
|
+
blocks: BlockStore;
|
|
40
|
+
/** Public, private and contract class logs. */
|
|
41
|
+
logs: LogStore;
|
|
42
|
+
/** L1 to L2 messages and message sync state. */
|
|
43
|
+
messages: MessageStore;
|
|
44
|
+
/** Contract classes (with bytecode commitments). */
|
|
45
|
+
contractClasses: ContractClassStore;
|
|
46
|
+
/** Contract instances and contract instance updates. */
|
|
47
|
+
contractInstances: ContractInstanceStore;
|
|
48
|
+
/** In-memory cache of public function selectors -> names. */
|
|
49
|
+
functionNames: FunctionNamesCache;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Wires up the archiver substores against a shared KV store and returns the
|
|
54
|
+
* {@link ArchiverDataStores} bundle.
|
|
55
|
+
*
|
|
56
|
+
* @param genesisBlockHash - Hash of the synthetic genesis block, forwarded to the {@link LogStore} so it
|
|
57
|
+
* can resolve a genesis `referenceBlock` (used by the PXE during early sync) instead of treating it as a
|
|
58
|
+
* reorg.
|
|
59
|
+
*/
|
|
60
|
+
export function createArchiverDataStores(db: AztecAsyncKVStore, genesisBlockHash: BlockHash): ArchiverDataStores {
|
|
61
|
+
const blocks = new BlockStore(db);
|
|
62
|
+
return {
|
|
63
|
+
db,
|
|
64
|
+
blocks,
|
|
65
|
+
logs: new LogStore(db, blocks, genesisBlockHash),
|
|
66
|
+
messages: new MessageStore(db),
|
|
67
|
+
contractClasses: new ContractClassStore(db),
|
|
68
|
+
contractInstances: new ContractInstanceStore(db),
|
|
69
|
+
functionNames: new FunctionNamesCache(),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Returns the L1 sync point of the archiver, combining the block sync point from {@link BlockStore}
|
|
75
|
+
* and the message sync point from {@link MessageStore}.
|
|
76
|
+
*/
|
|
77
|
+
export async function getArchiverSynchPoint(stores: ArchiverDataStores): Promise<ArchiverL1SynchPoint> {
|
|
78
|
+
const [blocksSynchedTo, messagesSynchedTo] = await Promise.all([
|
|
79
|
+
stores.blocks.getSynchedL1BlockNumber(),
|
|
80
|
+
stores.messages.getSynchedL1Block(),
|
|
81
|
+
]);
|
|
82
|
+
return { blocksSynchedTo, messagesSynchedTo };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Backs up the underlying KV store to the given folder. Returns the path to the resulting db file.
|
|
87
|
+
*/
|
|
88
|
+
export async function backupArchiverDataStores(
|
|
89
|
+
stores: ArchiverDataStores,
|
|
90
|
+
path: string,
|
|
91
|
+
compress = true,
|
|
92
|
+
): Promise<string> {
|
|
93
|
+
await stores.db.backupTo(path, compress);
|
|
94
|
+
return join(path, 'data.mdb');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Returns a {@link ContractDataSource} adapter over {@link ArchiverDataStores}.
|
|
99
|
+
* Used by contexts (e.g. offline epoch re-prover tools) that need a ContractDataSource
|
|
100
|
+
* but do not need a full archiver instance.
|
|
101
|
+
*/
|
|
102
|
+
export function createContractDataSource(stores: ArchiverDataStores): ContractDataSource {
|
|
103
|
+
return new ArchiverContractDataSourceAdapter(stores);
|
|
104
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
3
|
+
|
|
4
|
+
const MAX_FUNCTION_SIGNATURES = 1000;
|
|
5
|
+
const MAX_FUNCTION_NAME_LEN = 256;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* In-memory cache mapping public function selectors to function names.
|
|
9
|
+
*
|
|
10
|
+
* Populated opportunistically (e.g. by PXE registering signatures from artifacts) so the
|
|
11
|
+
* archiver can attach human-readable names to logs and traces. Bounded by
|
|
12
|
+
* {@link MAX_FUNCTION_SIGNATURES} to avoid unbounded growth from untrusted callers.
|
|
13
|
+
*/
|
|
14
|
+
export class FunctionNamesCache {
|
|
15
|
+
private readonly log = createLogger('archiver:data-stores');
|
|
16
|
+
private readonly names: Map<string, string> = new Map();
|
|
17
|
+
|
|
18
|
+
/** Adds the given public function signatures to the cache. */
|
|
19
|
+
public async register(signatures: string[]): Promise<void> {
|
|
20
|
+
for (const sig of signatures) {
|
|
21
|
+
if (this.names.size > MAX_FUNCTION_SIGNATURES) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const selector = await FunctionSelector.fromSignature(sig);
|
|
26
|
+
this.names.set(selector.toString(), sig.slice(0, sig.indexOf('(')).slice(0, MAX_FUNCTION_NAME_LEN));
|
|
27
|
+
} catch {
|
|
28
|
+
this.log.warn(`Failed to parse signature: ${sig}. Ignoring`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Looks up a function name for the given selector, or returns undefined if not registered. */
|
|
34
|
+
public get(selector: FunctionSelector): string | undefined {
|
|
35
|
+
return this.names.get(selector.toString());
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { BlockHash, L2Tips } from '@aztec/stdlib/block';
|
|
2
|
+
|
|
3
|
+
import type { BlockStore } from './block_store.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* In-memory cache for L2 chain tips (proposed, checkpointed, proven, finalized).
|
|
7
|
+
* Populated from the BlockStore on first access, then kept up-to-date by the ArchiverDataStoreUpdater.
|
|
8
|
+
* Refresh calls should happen *after* the store transaction that mutates block data has committed,
|
|
9
|
+
* so the cache loads from committed state and is never replaced if the writer aborts.
|
|
10
|
+
*/
|
|
11
|
+
export class L2TipsCache {
|
|
12
|
+
#tipsPromise: Promise<L2Tips> | undefined;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The genesis block hash is dynamic — derived from the injected initial header, which depends on
|
|
16
|
+
* `genesisTimestamp` and any prefilled state — so it is supplied here rather than read from store.
|
|
17
|
+
* The genesis checkpoint hash, by contrast, is the static protocol constant and is resolved
|
|
18
|
+
* inside the block store.
|
|
19
|
+
*/
|
|
20
|
+
constructor(
|
|
21
|
+
private blockStore: BlockStore,
|
|
22
|
+
private readonly initialBlockHash: BlockHash,
|
|
23
|
+
) {}
|
|
24
|
+
|
|
25
|
+
/** Returns the cached L2 tips. Loads from the block store on first call. */
|
|
26
|
+
public getL2Tips(): Promise<L2Tips> {
|
|
27
|
+
return (this.#tipsPromise ??= this.blockStore.getL2TipsData(this.initialBlockHash));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Reloads the L2 tips from the block store. Should be called after the writer transaction has committed. */
|
|
31
|
+
public async refresh(): Promise<void> {
|
|
32
|
+
this.#tipsPromise = this.blockStore.getL2TipsData(this.initialBlockHash);
|
|
33
|
+
await this.#tipsPromise;
|
|
34
|
+
}
|
|
35
|
+
}
|