@aztec/archiver 0.0.0-test.1 → 0.0.1-commit.0208eb9
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 -9
- package/dest/archiver.d.ts +136 -0
- package/dest/archiver.d.ts.map +1 -0
- package/dest/archiver.js +781 -0
- package/dest/config.d.ts +30 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/config.js +71 -0
- package/dest/errors.d.ts +41 -0
- package/dest/errors.d.ts.map +1 -0
- package/dest/errors.js +62 -0
- package/dest/factory.d.ts +13 -16
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +103 -55
- package/dest/index.d.ts +10 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +8 -3
- package/dest/interfaces.d.ts +9 -0
- package/dest/interfaces.d.ts.map +1 -0
- package/dest/interfaces.js +3 -0
- package/dest/l1/bin/retrieve-calldata.d.ts +3 -0
- package/dest/l1/bin/retrieve-calldata.d.ts.map +1 -0
- package/dest/l1/bin/retrieve-calldata.js +149 -0
- package/dest/l1/calldata_retriever.d.ts +112 -0
- package/dest/l1/calldata_retriever.d.ts.map +1 -0
- package/dest/l1/calldata_retriever.js +471 -0
- package/dest/l1/data_retrieval.d.ts +88 -0
- package/dest/l1/data_retrieval.d.ts.map +1 -0
- package/dest/l1/data_retrieval.js +312 -0
- package/dest/l1/debug_tx.d.ts +19 -0
- package/dest/l1/debug_tx.d.ts.map +1 -0
- package/dest/l1/debug_tx.js +73 -0
- package/dest/l1/spire_proposer.d.ts +70 -0
- package/dest/l1/spire_proposer.d.ts.map +1 -0
- package/dest/l1/spire_proposer.js +157 -0
- package/dest/l1/trace_tx.d.ts +97 -0
- package/dest/l1/trace_tx.d.ts.map +1 -0
- package/dest/l1/trace_tx.js +91 -0
- package/dest/l1/types.d.ts +12 -0
- package/dest/l1/types.d.ts.map +1 -0
- package/dest/l1/types.js +3 -0
- package/dest/l1/validate_trace.d.ts +32 -0
- package/dest/l1/validate_trace.d.ts.map +1 -0
- package/dest/l1/validate_trace.js +154 -0
- package/dest/modules/data_source_base.d.ts +84 -0
- package/dest/modules/data_source_base.d.ts.map +1 -0
- package/dest/modules/data_source_base.js +260 -0
- package/dest/modules/data_store_updater.d.ts +73 -0
- package/dest/modules/data_store_updater.d.ts.map +1 -0
- package/dest/modules/data_store_updater.js +302 -0
- package/dest/modules/instrumentation.d.ts +37 -0
- package/dest/modules/instrumentation.d.ts.map +1 -0
- package/dest/modules/instrumentation.js +110 -0
- package/dest/modules/l1_synchronizer.d.ts +75 -0
- package/dest/modules/l1_synchronizer.d.ts.map +1 -0
- package/dest/modules/l1_synchronizer.js +1112 -0
- package/dest/modules/validation.d.ts +17 -0
- package/dest/modules/validation.d.ts.map +1 -0
- package/dest/modules/validation.js +104 -0
- package/dest/store/block_store.d.ts +192 -0
- package/dest/store/block_store.d.ts.map +1 -0
- package/dest/store/block_store.js +721 -0
- package/dest/store/contract_class_store.d.ts +18 -0
- package/dest/store/contract_class_store.d.ts.map +1 -0
- package/dest/{archiver/kv_archiver_store → store}/contract_class_store.js +25 -27
- package/dest/store/contract_instance_store.d.ts +24 -0
- package/dest/store/contract_instance_store.d.ts.map +1 -0
- package/dest/store/contract_instance_store.js +77 -0
- package/dest/store/kv_archiver_store.d.ts +340 -0
- package/dest/store/kv_archiver_store.d.ts.map +1 -0
- package/dest/store/kv_archiver_store.js +446 -0
- package/dest/store/log_store.d.ts +54 -0
- package/dest/store/log_store.d.ts.map +1 -0
- package/dest/store/log_store.js +436 -0
- package/dest/store/message_store.d.ts +40 -0
- package/dest/store/message_store.d.ts.map +1 -0
- package/dest/store/message_store.js +188 -0
- package/dest/structs/data_retrieval.d.ts +27 -0
- 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/structs/inbox_message.js +39 -0
- package/dest/structs/published.d.ts +2 -0
- package/dest/structs/published.d.ts.map +1 -0
- package/dest/structs/published.js +1 -0
- package/dest/test/fake_l1_state.d.ts +190 -0
- package/dest/test/fake_l1_state.d.ts.map +1 -0
- package/dest/test/fake_l1_state.js +383 -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 +16 -8
- package/dest/test/mock_archiver.d.ts.map +1 -1
- package/dest/test/mock_archiver.js +18 -14
- package/dest/test/mock_l1_to_l2_message_source.d.ts +9 -6
- package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/test/mock_l1_to_l2_message_source.js +30 -7
- package/dest/test/mock_l2_block_source.d.ts +62 -16
- package/dest/test/mock_l2_block_source.d.ts.map +1 -1
- package/dest/test/mock_l2_block_source.js +263 -32
- package/dest/test/mock_structs.d.ts +85 -0
- package/dest/test/mock_structs.d.ts.map +1 -0
- package/dest/test/mock_structs.js +171 -0
- package/dest/test/noop_l1_archiver.d.ts +23 -0
- package/dest/test/noop_l1_archiver.d.ts.map +1 -0
- package/dest/test/noop_l1_archiver.js +68 -0
- package/package.json +31 -33
- package/src/archiver.ts +543 -0
- package/src/config.ts +95 -0
- package/src/errors.ts +102 -0
- package/src/factory.ts +144 -71
- package/src/index.ts +10 -3
- package/src/interfaces.ts +9 -0
- package/src/l1/README.md +98 -0
- package/src/l1/bin/retrieve-calldata.ts +187 -0
- package/src/l1/calldata_retriever.ts +641 -0
- package/src/l1/data_retrieval.ts +495 -0
- package/src/l1/debug_tx.ts +99 -0
- package/src/l1/spire_proposer.ts +160 -0
- package/src/l1/trace_tx.ts +128 -0
- package/src/l1/types.ts +13 -0
- package/src/l1/validate_trace.ts +229 -0
- package/src/modules/data_source_base.ts +367 -0
- package/src/modules/data_store_updater.ts +423 -0
- package/src/modules/instrumentation.ts +157 -0
- package/src/modules/l1_synchronizer.ts +930 -0
- package/src/modules/validation.ts +129 -0
- package/src/store/block_store.ts +966 -0
- package/src/{archiver/kv_archiver_store → store}/contract_class_store.ts +26 -32
- package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +37 -29
- package/src/store/kv_archiver_store.ts +639 -0
- package/src/store/log_store.ts +575 -0
- package/src/store/message_store.ts +261 -0
- package/src/structs/inbox_message.ts +41 -0
- package/src/structs/published.ts +1 -0
- package/src/test/fake_l1_state.ts +599 -0
- package/src/test/fixtures/debug_traceTransaction-multicall3.json +88 -0
- package/src/test/fixtures/debug_traceTransaction-multiplePropose.json +153 -0
- package/src/test/fixtures/debug_traceTransaction-proxied.json +122 -0
- package/src/test/fixtures/trace_transaction-multicall3.json +65 -0
- package/src/test/fixtures/trace_transaction-multiplePropose.json +319 -0
- package/src/test/fixtures/trace_transaction-proxied.json +128 -0
- package/src/test/fixtures/trace_transaction-randomRevert.json +216 -0
- package/src/test/index.ts +4 -0
- package/src/test/mock_archiver.ts +22 -16
- package/src/test/mock_l1_to_l2_message_source.ts +26 -8
- package/src/test/mock_l2_block_source.ts +313 -42
- package/src/test/mock_structs.ts +311 -0
- package/src/test/noop_l1_archiver.ts +109 -0
- package/dest/archiver/archiver.d.ts +0 -197
- package/dest/archiver/archiver.d.ts.map +0 -1
- package/dest/archiver/archiver.js +0 -900
- package/dest/archiver/archiver_store.d.ts +0 -220
- 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 -794
- package/dest/archiver/config.d.ts +0 -37
- package/dest/archiver/config.d.ts.map +0 -1
- package/dest/archiver/config.js +0 -46
- package/dest/archiver/data_retrieval.d.ts +0 -74
- package/dest/archiver/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/data_retrieval.js +0 -283
- package/dest/archiver/errors.d.ts +0 -4
- package/dest/archiver/errors.d.ts.map +0 -1
- package/dest/archiver/errors.js +0 -5
- package/dest/archiver/index.d.ts +0 -8
- package/dest/archiver/index.d.ts.map +0 -1
- package/dest/archiver/index.js +0 -5
- package/dest/archiver/instrumentation.d.ts +0 -29
- package/dest/archiver/instrumentation.d.ts.map +0 -1
- package/dest/archiver/instrumentation.js +0 -99
- package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -87
- package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/block_store.js +0 -217
- 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_instance_store.d.ts +0 -21
- package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/contract_instance_store.js +0 -63
- package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +0 -153
- 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 -254
- package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -49
- package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/log_store.js +0 -364
- package/dest/archiver/kv_archiver_store/message_store.d.ts +0 -33
- package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/message_store.js +0 -85
- package/dest/archiver/kv_archiver_store/nullifier_store.d.ts +0 -12
- package/dest/archiver/kv_archiver_store/nullifier_store.d.ts.map +0 -1
- package/dest/archiver/kv_archiver_store/nullifier_store.js +0 -73
- package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts +0 -23
- package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts.map +0 -1
- package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.js +0 -49
- package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts +0 -175
- package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts.map +0 -1
- package/dest/archiver/memory_archiver_store/memory_archiver_store.js +0 -636
- package/dest/archiver/structs/data_retrieval.d.ts +0 -27
- package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
- package/dest/archiver/structs/published.d.ts +0 -11
- package/dest/archiver/structs/published.d.ts.map +0 -1
- package/dest/archiver/structs/published.js +0 -1
- package/dest/rpc/index.d.ts +0 -10
- package/dest/rpc/index.d.ts.map +0 -1
- package/dest/rpc/index.js +0 -18
- package/src/archiver/archiver.ts +0 -1181
- package/src/archiver/archiver_store.ts +0 -263
- package/src/archiver/archiver_store_test_suite.ts +0 -810
- package/src/archiver/config.ts +0 -92
- package/src/archiver/data_retrieval.ts +0 -422
- package/src/archiver/errors.ts +0 -5
- package/src/archiver/index.ts +0 -7
- package/src/archiver/instrumentation.ts +0 -132
- package/src/archiver/kv_archiver_store/block_store.ts +0 -283
- package/src/archiver/kv_archiver_store/kv_archiver_store.ts +0 -358
- package/src/archiver/kv_archiver_store/log_store.ts +0 -444
- package/src/archiver/kv_archiver_store/message_store.ts +0 -102
- package/src/archiver/kv_archiver_store/nullifier_store.ts +0 -97
- package/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts +0 -61
- package/src/archiver/memory_archiver_store/memory_archiver_store.ts +0 -801
- package/src/archiver/structs/published.ts +0 -11
- package/src/rpc/index.ts +0 -20
- /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
- /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
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';
|
|
@@ -7,12 +7,12 @@ import type {
|
|
|
7
7
|
ContractClassPublic,
|
|
8
8
|
ContractClassPublicWithBlockNumber,
|
|
9
9
|
ExecutablePrivateFunctionWithMembershipProof,
|
|
10
|
-
|
|
10
|
+
UtilityFunctionWithMembershipProof,
|
|
11
11
|
} from '@aztec/stdlib/contract';
|
|
12
12
|
import { Vector } from '@aztec/stdlib/types';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* LMDB
|
|
15
|
+
* LMDB-based contract class storage for the archiver.
|
|
16
16
|
*/
|
|
17
17
|
export class ContractClassStore {
|
|
18
18
|
#contractClasses: AztecAsyncMap<string, Buffer>;
|
|
@@ -28,18 +28,22 @@ export class ContractClassStore {
|
|
|
28
28
|
bytecodeCommitment: Fr,
|
|
29
29
|
blockNumber: number,
|
|
30
30
|
): Promise<void> {
|
|
31
|
-
await this
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
await this.db.transactionAsync(async () => {
|
|
32
|
+
await this.#contractClasses.setIfNotExists(
|
|
33
|
+
contractClass.id.toString(),
|
|
34
|
+
serializeContractClassPublic({ ...contractClass, l2BlockNumber: blockNumber }),
|
|
35
|
+
);
|
|
36
|
+
await this.#bytecodeCommitments.setIfNotExists(contractClass.id.toString(), bytecodeCommitment.toBuffer());
|
|
37
|
+
});
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
async deleteContractClasses(contractClass: ContractClassPublic, blockNumber: number): Promise<void> {
|
|
39
41
|
const restoredContractClass = await this.#contractClasses.getAsync(contractClass.id.toString());
|
|
40
42
|
if (restoredContractClass && deserializeContractClassPublic(restoredContractClass).l2BlockNumber >= blockNumber) {
|
|
41
|
-
await this
|
|
42
|
-
|
|
43
|
+
await this.db.transactionAsync(async () => {
|
|
44
|
+
await this.#contractClasses.delete(contractClass.id.toString());
|
|
45
|
+
await this.#bytecodeCommitments.delete(contractClass.id.toString());
|
|
46
|
+
});
|
|
43
47
|
}
|
|
44
48
|
}
|
|
45
49
|
|
|
@@ -60,7 +64,7 @@ export class ContractClassStore {
|
|
|
60
64
|
async addFunctions(
|
|
61
65
|
contractClassId: Fr,
|
|
62
66
|
newPrivateFunctions: ExecutablePrivateFunctionWithMembershipProof[],
|
|
63
|
-
|
|
67
|
+
newUtilityFunctions: UtilityFunctionWithMembershipProof[],
|
|
64
68
|
): Promise<boolean> {
|
|
65
69
|
await this.db.transactionAsync(async () => {
|
|
66
70
|
const existingClassBuffer = await this.#contractClasses.getAsync(contractClassId.toString());
|
|
@@ -69,7 +73,7 @@ export class ContractClassStore {
|
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
const existingClass = deserializeContractClassPublic(existingClassBuffer);
|
|
72
|
-
const { privateFunctions: existingPrivateFns,
|
|
76
|
+
const { privateFunctions: existingPrivateFns, utilityFunctions: existingUtilityFns } = existingClass;
|
|
73
77
|
|
|
74
78
|
const updatedClass: Omit<ContractClassPublicWithBlockNumber, 'id'> = {
|
|
75
79
|
...existingClass,
|
|
@@ -77,11 +81,9 @@ export class ContractClassStore {
|
|
|
77
81
|
...existingPrivateFns,
|
|
78
82
|
...newPrivateFunctions.filter(newFn => !existingPrivateFns.some(f => f.selector.equals(newFn.selector))),
|
|
79
83
|
],
|
|
80
|
-
|
|
81
|
-
...
|
|
82
|
-
...
|
|
83
|
-
newFn => !existingUnconstrainedFns.some(f => f.selector.equals(newFn.selector)),
|
|
84
|
-
),
|
|
84
|
+
utilityFunctions: [
|
|
85
|
+
...existingUtilityFns,
|
|
86
|
+
...newUtilityFunctions.filter(newFn => !existingUtilityFns.some(f => f.selector.equals(newFn.selector))),
|
|
85
87
|
],
|
|
86
88
|
};
|
|
87
89
|
await this.#contractClasses.set(contractClassId.toString(), serializeContractClassPublic(updatedClass));
|
|
@@ -96,12 +98,10 @@ function serializeContractClassPublic(contractClass: Omit<ContractClassPublicWit
|
|
|
96
98
|
contractClass.l2BlockNumber,
|
|
97
99
|
numToUInt8(contractClass.version),
|
|
98
100
|
contractClass.artifactHash,
|
|
99
|
-
contractClass.publicFunctions.length,
|
|
100
|
-
contractClass.publicFunctions?.map(f => serializeToBuffer(f.selector, f.bytecode.length, f.bytecode)) ?? [],
|
|
101
101
|
contractClass.privateFunctions.length,
|
|
102
102
|
contractClass.privateFunctions.map(serializePrivateFunction),
|
|
103
|
-
contractClass.
|
|
104
|
-
contractClass.
|
|
103
|
+
contractClass.utilityFunctions.length,
|
|
104
|
+
contractClass.utilityFunctions.map(serializeUtilityFunction),
|
|
105
105
|
contractClass.packedBytecode.length,
|
|
106
106
|
contractClass.packedBytecode,
|
|
107
107
|
contractClass.privateFunctionsRoot,
|
|
@@ -116,7 +116,7 @@ function serializePrivateFunction(fn: ExecutablePrivateFunctionWithMembershipPro
|
|
|
116
116
|
fn.bytecode,
|
|
117
117
|
fn.functionMetadataHash,
|
|
118
118
|
fn.artifactMetadataHash,
|
|
119
|
-
fn.
|
|
119
|
+
fn.utilityFunctionsTreeRoot,
|
|
120
120
|
new Vector(fn.privateFunctionTreeSiblingPath),
|
|
121
121
|
fn.privateFunctionTreeLeafIndex,
|
|
122
122
|
new Vector(fn.artifactTreeSiblingPath),
|
|
@@ -124,7 +124,7 @@ function serializePrivateFunction(fn: ExecutablePrivateFunctionWithMembershipPro
|
|
|
124
124
|
);
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
function
|
|
127
|
+
function serializeUtilityFunction(fn: UtilityFunctionWithMembershipProof): Buffer {
|
|
128
128
|
return serializeToBuffer(
|
|
129
129
|
fn.selector,
|
|
130
130
|
fn.bytecode.length,
|
|
@@ -143,14 +143,8 @@ function deserializeContractClassPublic(buffer: Buffer): Omit<ContractClassPubli
|
|
|
143
143
|
l2BlockNumber: reader.readNumber(),
|
|
144
144
|
version: reader.readUInt8() as 1,
|
|
145
145
|
artifactHash: reader.readObject(Fr),
|
|
146
|
-
publicFunctions: reader.readVector({
|
|
147
|
-
fromBuffer: reader => ({
|
|
148
|
-
selector: reader.readObject(FunctionSelector),
|
|
149
|
-
bytecode: reader.readBuffer(),
|
|
150
|
-
}),
|
|
151
|
-
}),
|
|
152
146
|
privateFunctions: reader.readVector({ fromBuffer: deserializePrivateFunction }),
|
|
153
|
-
|
|
147
|
+
utilityFunctions: reader.readVector({ fromBuffer: deserializeUtilityFunction }),
|
|
154
148
|
packedBytecode: reader.readBuffer(),
|
|
155
149
|
privateFunctionsRoot: reader.readObject(Fr),
|
|
156
150
|
};
|
|
@@ -164,7 +158,7 @@ function deserializePrivateFunction(buffer: Buffer | BufferReader): ExecutablePr
|
|
|
164
158
|
bytecode: reader.readBuffer(),
|
|
165
159
|
functionMetadataHash: reader.readObject(Fr),
|
|
166
160
|
artifactMetadataHash: reader.readObject(Fr),
|
|
167
|
-
|
|
161
|
+
utilityFunctionsTreeRoot: reader.readObject(Fr),
|
|
168
162
|
privateFunctionTreeSiblingPath: reader.readVector(Fr),
|
|
169
163
|
privateFunctionTreeLeafIndex: reader.readNumber(),
|
|
170
164
|
artifactTreeSiblingPath: reader.readVector(Fr),
|
|
@@ -172,7 +166,7 @@ function deserializePrivateFunction(buffer: Buffer | BufferReader): ExecutablePr
|
|
|
172
166
|
};
|
|
173
167
|
}
|
|
174
168
|
|
|
175
|
-
function
|
|
169
|
+
function deserializeUtilityFunction(buffer: Buffer | BufferReader): UtilityFunctionWithMembershipProof {
|
|
176
170
|
const reader = BufferReader.asReader(buffer);
|
|
177
171
|
return {
|
|
178
172
|
selector: reader.readObject(FunctionSelector),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Fr } from '@aztec/foundation/
|
|
1
|
+
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
3
3
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
4
|
import {
|
|
@@ -7,71 +7,75 @@ import {
|
|
|
7
7
|
SerializableContractInstance,
|
|
8
8
|
SerializableContractInstanceUpdate,
|
|
9
9
|
} from '@aztec/stdlib/contract';
|
|
10
|
+
import type { UInt64 } from '@aztec/stdlib/types';
|
|
10
11
|
|
|
11
|
-
type ContractInstanceUpdateKey = [string,
|
|
12
|
+
type ContractInstanceUpdateKey = [string, string] | [string, string, number];
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
|
-
* LMDB
|
|
15
|
+
* LMDB-based contract instance storage for the archiver.
|
|
15
16
|
*/
|
|
16
17
|
export class ContractInstanceStore {
|
|
17
18
|
#contractInstances: AztecAsyncMap<string, Buffer>;
|
|
19
|
+
#contractInstancePublishedAt: AztecAsyncMap<string, number>;
|
|
18
20
|
#contractInstanceUpdates: AztecAsyncMap<ContractInstanceUpdateKey, Buffer>;
|
|
19
21
|
|
|
20
|
-
constructor(db: AztecAsyncKVStore) {
|
|
22
|
+
constructor(private db: AztecAsyncKVStore) {
|
|
21
23
|
this.#contractInstances = db.openMap('archiver_contract_instances');
|
|
24
|
+
this.#contractInstancePublishedAt = db.openMap('archiver_contract_instances_publication_block_number');
|
|
22
25
|
this.#contractInstanceUpdates = db.openMap('archiver_contract_instance_updates');
|
|
23
26
|
}
|
|
24
27
|
|
|
25
|
-
addContractInstance(contractInstance: ContractInstanceWithAddress): Promise<void> {
|
|
26
|
-
return this
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
addContractInstance(contractInstance: ContractInstanceWithAddress, blockNumber: number): Promise<void> {
|
|
29
|
+
return this.db.transactionAsync(async () => {
|
|
30
|
+
await this.#contractInstances.set(
|
|
31
|
+
contractInstance.address.toString(),
|
|
32
|
+
new SerializableContractInstance(contractInstance).toBuffer(),
|
|
33
|
+
);
|
|
34
|
+
await this.#contractInstancePublishedAt.set(contractInstance.address.toString(), blockNumber);
|
|
35
|
+
});
|
|
30
36
|
}
|
|
31
37
|
|
|
32
38
|
deleteContractInstance(contractInstance: ContractInstanceWithAddress): Promise<void> {
|
|
33
|
-
return this
|
|
39
|
+
return this.db.transactionAsync(async () => {
|
|
40
|
+
await this.#contractInstances.delete(contractInstance.address.toString());
|
|
41
|
+
await this.#contractInstancePublishedAt.delete(contractInstance.address.toString());
|
|
42
|
+
});
|
|
34
43
|
}
|
|
35
44
|
|
|
36
|
-
getUpdateKey(contractAddress: AztecAddress,
|
|
45
|
+
getUpdateKey(contractAddress: AztecAddress, timestamp: UInt64, logIndex?: number): ContractInstanceUpdateKey {
|
|
37
46
|
if (logIndex === undefined) {
|
|
38
|
-
return [contractAddress.toString(),
|
|
47
|
+
return [contractAddress.toString(), timestamp.toString()];
|
|
39
48
|
} else {
|
|
40
|
-
return [contractAddress.toString(),
|
|
49
|
+
return [contractAddress.toString(), timestamp.toString(), logIndex];
|
|
41
50
|
}
|
|
42
51
|
}
|
|
43
52
|
|
|
44
53
|
addContractInstanceUpdate(
|
|
45
54
|
contractInstanceUpdate: ContractInstanceUpdateWithAddress,
|
|
46
|
-
|
|
55
|
+
timestamp: UInt64,
|
|
47
56
|
logIndex: number,
|
|
48
57
|
): Promise<void> {
|
|
49
58
|
return this.#contractInstanceUpdates.set(
|
|
50
|
-
this.getUpdateKey(contractInstanceUpdate.address,
|
|
59
|
+
this.getUpdateKey(contractInstanceUpdate.address, timestamp, logIndex),
|
|
51
60
|
new SerializableContractInstanceUpdate(contractInstanceUpdate).toBuffer(),
|
|
52
61
|
);
|
|
53
62
|
}
|
|
54
63
|
|
|
55
64
|
deleteContractInstanceUpdate(
|
|
56
65
|
contractInstanceUpdate: ContractInstanceUpdateWithAddress,
|
|
57
|
-
|
|
66
|
+
timestamp: UInt64,
|
|
58
67
|
logIndex: number,
|
|
59
68
|
): Promise<void> {
|
|
60
|
-
return this.#contractInstanceUpdates.delete(
|
|
61
|
-
this.getUpdateKey(contractInstanceUpdate.address, blockNumber, logIndex),
|
|
62
|
-
);
|
|
69
|
+
return this.#contractInstanceUpdates.delete(this.getUpdateKey(contractInstanceUpdate.address, timestamp, logIndex));
|
|
63
70
|
}
|
|
64
71
|
|
|
65
|
-
async getCurrentContractInstanceClassId(
|
|
66
|
-
|
|
67
|
-
blockNumber: number,
|
|
68
|
-
originalClassId: Fr,
|
|
69
|
-
): Promise<Fr> {
|
|
70
|
-
// We need to find the last update before the given block number
|
|
72
|
+
async getCurrentContractInstanceClassId(address: AztecAddress, timestamp: UInt64, originalClassId: Fr): Promise<Fr> {
|
|
73
|
+
// We need to find the last update before the given timestamp
|
|
71
74
|
const queryResult = await this.#contractInstanceUpdates
|
|
72
75
|
.valuesAsync({
|
|
73
76
|
reverse: true,
|
|
74
|
-
|
|
77
|
+
start: this.getUpdateKey(address, 0n), // Make sure we only look at updates for this contract
|
|
78
|
+
end: this.getUpdateKey(address, timestamp + 1n), // No update can match this key since it doesn't have a log index. We want the highest key <= timestamp
|
|
75
79
|
limit: 1,
|
|
76
80
|
})
|
|
77
81
|
.next();
|
|
@@ -81,7 +85,7 @@ export class ContractInstanceStore {
|
|
|
81
85
|
|
|
82
86
|
const serializedUpdate = queryResult.value;
|
|
83
87
|
const update = SerializableContractInstanceUpdate.fromBuffer(serializedUpdate);
|
|
84
|
-
if (
|
|
88
|
+
if (timestamp < update.timestampOfChange) {
|
|
85
89
|
return update.prevContractClassId.isZero() ? originalClassId : update.prevContractClassId;
|
|
86
90
|
}
|
|
87
91
|
return update.newContractClassId;
|
|
@@ -89,7 +93,7 @@ export class ContractInstanceStore {
|
|
|
89
93
|
|
|
90
94
|
async getContractInstance(
|
|
91
95
|
address: AztecAddress,
|
|
92
|
-
|
|
96
|
+
timestamp: UInt64,
|
|
93
97
|
): Promise<ContractInstanceWithAddress | undefined> {
|
|
94
98
|
const contractInstance = await this.#contractInstances.getAsync(address.toString());
|
|
95
99
|
if (!contractInstance) {
|
|
@@ -99,9 +103,13 @@ export class ContractInstanceStore {
|
|
|
99
103
|
const instance = SerializableContractInstance.fromBuffer(contractInstance).withAddress(address);
|
|
100
104
|
instance.currentContractClassId = await this.getCurrentContractInstanceClassId(
|
|
101
105
|
address,
|
|
102
|
-
|
|
106
|
+
timestamp,
|
|
103
107
|
instance.originalContractClassId,
|
|
104
108
|
);
|
|
105
109
|
return instance;
|
|
106
110
|
}
|
|
111
|
+
|
|
112
|
+
getContractInstanceDeploymentBlockNumber(address: AztecAddress): Promise<number | undefined> {
|
|
113
|
+
return this.#contractInstancePublishedAt.getAsync(address.toString());
|
|
114
|
+
}
|
|
107
115
|
}
|