@aztec/txe 0.0.1-commit.f504929 → 0.0.1-commit.f5a9928
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/AuthRegistry-56AMRLSQ.js +3 -0
- package/dest/AuthRegistry-56AMRLSQ.js.map +7 -0
- package/dest/ContractClassRegistry-CRN27URB.js +3 -0
- package/dest/ContractClassRegistry-CRN27URB.js.map +7 -0
- package/dest/ContractInstanceRegistry-GRGL26IC.js +3 -0
- package/dest/ContractInstanceRegistry-GRGL26IC.js.map +7 -0
- package/dest/FeeJuice-J23RVHLW.js +3 -0
- package/dest/FeeJuice-J23RVHLW.js.map +7 -0
- package/dest/HandshakeRegistry-5.0.1-PEFCLEGP.js +3 -0
- package/dest/HandshakeRegistry-5.0.1-PEFCLEGP.js.map +7 -0
- package/dest/HandshakeRegistry-GNFACTEE.js +3 -0
- package/dest/HandshakeRegistry-GNFACTEE.js.map +7 -0
- package/dest/MultiCallEntrypoint-MIDICLQB.js +3 -0
- package/dest/MultiCallEntrypoint-MIDICLQB.js.map +7 -0
- package/dest/SchnorrAccount-ZRENHSMV.js +3 -0
- package/dest/SchnorrAccount-ZRENHSMV.js.map +7 -0
- package/dest/SchnorrInitializerlessAccount-L56LOFSV.js +3 -0
- package/dest/SchnorrInitializerlessAccount-L56LOFSV.js.map +7 -0
- package/dest/bin/check_txe_oracle_version.d.ts +2 -0
- package/dest/bin/check_txe_oracle_version.d.ts.map +1 -0
- package/dest/bin/check_txe_oracle_version.js +53 -0
- package/dest/bin/index.js +3 -30
- package/dest/bin/index.js.map +7 -0
- package/dest/bin/oracle_test_server.d.ts +3 -0
- package/dest/bin/oracle_test_server.d.ts.map +1 -0
- package/dest/bin/oracle_test_server.js +41 -0
- package/dest/chunk-BJVAAXNA.js +3 -0
- package/dest/chunk-BJVAAXNA.js.map +7 -0
- package/dest/chunk-C2WBKKGS.js +266 -0
- package/dest/chunk-C2WBKKGS.js.map +7 -0
- package/dest/chunk-OFS2CI6U.js +304 -0
- package/dest/chunk-OFS2CI6U.js.map +7 -0
- package/dest/constants.d.ts +5 -1
- package/dest/constants.d.ts.map +1 -1
- package/dest/constants.js +9 -1
- package/dest/dispatcher_pool.d.ts +67 -0
- package/dest/dispatcher_pool.d.ts.map +1 -0
- package/dest/dispatcher_pool.js +286 -0
- package/dest/index.d.ts +51 -7
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +72 -190
- package/dest/metafile.json +40416 -0
- package/dest/msgpackr_fr_extension.d.ts +2 -0
- package/dest/msgpackr_fr_extension.d.ts.map +1 -0
- package/dest/msgpackr_fr_extension.js +21 -0
- package/dest/oracle/interfaces.d.ts +47 -9
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/tagging_secret_strategy.d.ts +12 -0
- package/dest/oracle/tagging_secret_strategy.d.ts.map +1 -0
- package/dest/oracle/tagging_secret_strategy.js +12 -0
- package/dest/oracle/test-resolver/default_fixtures.d.ts +16 -0
- package/dest/oracle/test-resolver/default_fixtures.d.ts.map +1 -0
- package/dest/oracle/test-resolver/default_fixtures.js +200 -0
- package/dest/oracle/test-resolver/index.d.ts +9 -0
- package/dest/oracle/test-resolver/index.d.ts.map +1 -0
- package/dest/oracle/test-resolver/index.js +32 -0
- package/dest/oracle/test-resolver/resolver.d.ts +48 -0
- package/dest/oracle/test-resolver/resolver.d.ts.map +1 -0
- package/dest/oracle/test-resolver/resolver.js +181 -0
- package/dest/oracle/txe_oracle_public_context.d.ts +26 -2
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +49 -1
- package/dest/oracle/txe_oracle_registry.d.ts +172 -0
- package/dest/oracle/txe_oracle_registry.d.ts.map +1 -0
- package/dest/oracle/txe_oracle_registry.js +767 -0
- package/dest/oracle/txe_oracle_top_level_context.d.ts +58 -17
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +259 -88
- package/dest/oracle/txe_oracle_version.d.ts +17 -0
- package/dest/oracle/txe_oracle_version.d.ts.map +1 -0
- package/dest/oracle/txe_oracle_version.js +14 -0
- package/dest/oracle/txe_private_execution_oracle.d.ts +17 -0
- package/dest/oracle/txe_private_execution_oracle.d.ts.map +1 -0
- package/dest/oracle/txe_private_execution_oracle.js +15 -0
- package/dest/rpc_server.d.ts +14 -0
- package/dest/rpc_server.d.ts.map +1 -0
- package/dest/rpc_server.js +78 -0
- package/dest/rpc_translator.d.ts +115 -228
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +791 -607
- package/dest/server.bundle.js +3 -0
- package/dest/server.bundle.js.map +7 -0
- package/dest/state_machine/archiver.d.ts +6 -5
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +28 -20
- package/dest/state_machine/dummy_p2p_client.d.ts +18 -8
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +31 -4
- package/dest/state_machine/global_variable_builder.d.ts +10 -6
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +8 -5
- package/dest/state_machine/index.d.ts +11 -5
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +50 -10
- package/dest/state_machine/mock_epoch_cache.d.ts +16 -3
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +29 -2
- package/dest/state_machine/synchronizer.d.ts +9 -6
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +10 -6
- package/dest/txe_session.d.ts +90 -19
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +315 -61
- package/dest/utils/block_creation.d.ts +2 -2
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +2 -2
- package/dest/utils/encoding.d.ts +192 -0
- package/dest/utils/encoding.d.ts.map +1 -0
- package/dest/{util → utils}/encoding.js +7 -2
- package/dest/{util → utils}/expected_failure_error.d.ts +1 -1
- package/dest/utils/expected_failure_error.d.ts.map +1 -0
- package/dest/utils/tx_effect_creation.d.ts +1 -1
- package/dest/utils/tx_effect_creation.d.ts.map +1 -1
- package/dest/utils/tx_effect_creation.js +0 -1
- package/dest/{util → utils}/txe_account_store.d.ts +1 -1
- package/dest/utils/txe_account_store.d.ts.map +1 -0
- package/dest/utils/txe_artifact_resolver.d.ts +37 -0
- package/dest/utils/txe_artifact_resolver.d.ts.map +1 -0
- package/dest/utils/txe_artifact_resolver.js +161 -0
- package/dest/utils/txe_public_contract_data_source.d.ts +20 -0
- package/dest/utils/txe_public_contract_data_source.d.ts.map +1 -0
- package/dest/{util → utils}/txe_public_contract_data_source.js +8 -7
- package/dest/worker.bundle.js +3 -0
- package/dest/worker.bundle.js.map +7 -0
- package/dest/worker.d.ts +2 -0
- package/dest/worker.d.ts.map +1 -0
- package/dest/worker.js +92 -0
- package/package.json +38 -21
- package/src/bin/check_txe_oracle_version.ts +67 -0
- package/src/bin/index.ts +11 -2
- package/src/bin/oracle_test_server.ts +51 -0
- package/src/constants.ts +11 -1
- package/src/dispatcher_pool.ts +317 -0
- package/src/index.ts +99 -227
- package/src/msgpackr_fr_extension.ts +23 -0
- package/src/oracle/interfaces.ts +47 -8
- package/src/oracle/tagging_secret_strategy.ts +25 -0
- package/src/oracle/test-resolver/default_fixtures.ts +271 -0
- package/src/oracle/test-resolver/index.ts +44 -0
- package/src/oracle/test-resolver/resolver.ts +245 -0
- package/src/oracle/txe_oracle_public_context.ts +62 -0
- package/src/oracle/txe_oracle_registry.ts +556 -0
- package/src/oracle/txe_oracle_top_level_context.ts +342 -97
- package/src/oracle/txe_oracle_version.ts +17 -0
- package/src/oracle/txe_private_execution_oracle.ts +30 -0
- package/src/rpc_server.ts +87 -0
- package/src/rpc_translator.ts +882 -870
- package/src/state_machine/archiver.ts +41 -20
- package/src/state_machine/dummy_p2p_client.ts +49 -12
- package/src/state_machine/global_variable_builder.ts +12 -11
- package/src/state_machine/index.ts +63 -28
- package/src/state_machine/mock_epoch_cache.ts +38 -3
- package/src/state_machine/synchronizer.ts +13 -7
- package/src/txe_session.ts +552 -75
- package/src/utils/block_creation.ts +2 -1
- package/src/{util → utils}/encoding.ts +8 -2
- package/src/utils/tx_effect_creation.ts +0 -2
- package/src/utils/txe_artifact_resolver.ts +217 -0
- package/src/{util → utils}/txe_public_contract_data_source.ts +6 -6
- package/src/worker.ts +98 -0
- package/dest/util/encoding.d.ts +0 -720
- package/dest/util/encoding.d.ts.map +0 -1
- package/dest/util/expected_failure_error.d.ts.map +0 -1
- package/dest/util/txe_account_store.d.ts.map +0 -1
- package/dest/util/txe_public_contract_data_source.d.ts +0 -20
- package/dest/util/txe_public_contract_data_source.d.ts.map +0 -1
- /package/dest/{util → utils}/expected_failure_error.js +0 -0
- /package/dest/{util → utils}/txe_account_store.js +0 -0
- /package/src/{util → utils}/expected_failure_error.ts +0 -0
- /package/src/{util → utils}/txe_account_store.ts +0 -0
package/dest/index.js
CHANGED
|
@@ -1,35 +1,27 @@
|
|
|
1
|
-
import { SchnorrAccountContractArtifact } from '@aztec/accounts/schnorr';
|
|
2
|
-
import { loadContractArtifact } from '@aztec/aztec.js/abi';
|
|
3
|
-
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
4
|
-
import { getContractInstanceFromInstantiationParams } from '@aztec/aztec.js/contracts';
|
|
5
1
|
import { Fr } from '@aztec/aztec.js/fields';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
9
|
-
import { protocolContractNames } from '@aztec/protocol-contracts';
|
|
10
|
-
import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
|
|
11
|
-
import { ContractStore } from '@aztec/pxe/server';
|
|
12
|
-
import { computeArtifactHash } from '@aztec/stdlib/contract';
|
|
2
|
+
import { cloneEphemeralStoreFrom } from '@aztec/kv-store/lmdb-v2';
|
|
3
|
+
import { ContractStore } from '@aztec/pxe/client/lazy';
|
|
13
4
|
import { zodFor } from '@aztec/stdlib/schemas';
|
|
14
|
-
import {
|
|
15
|
-
import { createReadStream } from 'fs';
|
|
16
|
-
import { readFile, readdir } from 'fs/promises';
|
|
17
|
-
import { join, parse } from 'path';
|
|
5
|
+
import { join } from 'path';
|
|
18
6
|
import { z } from 'zod';
|
|
7
|
+
// Side-effect import: registers the msgpackr Fr extension for the bundled `Fr` class. Must
|
|
8
|
+
// be loaded before any `sendMessage` call. See msgpackr_fr_extension.ts for the why.
|
|
9
|
+
import './msgpackr_fr_extension.js';
|
|
19
10
|
import { TXESession } from './txe_session.js';
|
|
20
|
-
import { ForeignCallArgsSchema, ForeignCallResultSchema
|
|
11
|
+
import { ForeignCallArgsSchema, ForeignCallResultSchema } from './utils/encoding.js';
|
|
12
|
+
import { TXEArtifactResolver } from './utils/txe_artifact_resolver.js';
|
|
13
|
+
export const TXE_REQUIRED_PROTOCOL_CONTRACTS = [
|
|
14
|
+
'ContractClassRegistry',
|
|
15
|
+
'ContractInstanceRegistry',
|
|
16
|
+
'FeeJuice'
|
|
17
|
+
];
|
|
21
18
|
const sessions = new Map();
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
* The in-flight map coalesces concurrent requests for the same cache key so that
|
|
27
|
-
* computeArtifactHash (very expensive) is only run once even under parallelism.
|
|
28
|
-
*/ const TXEArtifactsCache = new Map();
|
|
29
|
-
const TXEArtifactsCacheInFlight = new Map();
|
|
30
|
-
const TXEForeignCallInputSchema = zodFor()(z.object({
|
|
19
|
+
export const TXEForeignCallInputSchema = zodFor()(z.object({
|
|
20
|
+
// Nargo generates session_id as a u64, which may exceed Number.MAX_SAFE_INTEGER.
|
|
21
|
+
// Zod 4's `.int()` enforces the safe-integer bound, so we drop it here and only require
|
|
22
|
+
// the value to be a non-negative number (it is used solely as a Map key).
|
|
31
23
|
// eslint-disable-next-line camelcase
|
|
32
|
-
session_id: z.number().
|
|
24
|
+
session_id: z.number().nonnegative(),
|
|
33
25
|
function: z.string(),
|
|
34
26
|
// eslint-disable-next-line camelcase
|
|
35
27
|
root_path: z.string(),
|
|
@@ -37,184 +29,74 @@ const TXEForeignCallInputSchema = zodFor()(z.object({
|
|
|
37
29
|
package_name: z.string(),
|
|
38
30
|
inputs: ForeignCallArgsSchema
|
|
39
31
|
}));
|
|
40
|
-
class TXEDispatcher {
|
|
32
|
+
export class TXEDispatcher {
|
|
41
33
|
logger;
|
|
42
34
|
contractStore;
|
|
43
|
-
|
|
35
|
+
artifactResolver;
|
|
36
|
+
contractStoreSourceDir;
|
|
37
|
+
schnorrClassId;
|
|
38
|
+
constructor(logger, opts){
|
|
44
39
|
this.logger = logger;
|
|
40
|
+
this.contractStoreSourceDir = opts.contractStoreSourceDir;
|
|
41
|
+
this.schnorrClassId = Fr.fromString(opts.schnorrClassId);
|
|
45
42
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
resolve(hash.read());
|
|
54
|
-
});
|
|
55
|
-
fd.pipe(hash);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
async #processDeployInputs({ inputs, root_path: rootPath, package_name: packageName }) {
|
|
59
|
-
const [contractPath, initializer] = inputs.slice(0, 2).map((input)=>fromArray(input).map((char)=>String.fromCharCode(char.toNumber())).join(''));
|
|
60
|
-
const decodedArgs = fromArray(inputs[3]);
|
|
61
|
-
const secret = fromSingle(inputs[4]);
|
|
62
|
-
const salt = fromSingle(inputs[5]);
|
|
63
|
-
const deployer = addressFromSingle(inputs[6]);
|
|
64
|
-
const publicKeys = secret.equals(Fr.ZERO) ? PublicKeys.default() : (await deriveKeys(secret)).publicKeys;
|
|
65
|
-
const publicKeysHash = await publicKeys.hash();
|
|
66
|
-
let artifactPath = '';
|
|
67
|
-
const { dir: contractDirectory, base: contractFilename } = parse(contractPath);
|
|
68
|
-
if (contractDirectory) {
|
|
69
|
-
if (contractDirectory.includes('@')) {
|
|
70
|
-
// We're deploying a contract that belongs in a workspace
|
|
71
|
-
// env.deploy("../path/to/workspace/root@packageName/contractName")
|
|
72
|
-
const [workspace, pkg] = contractDirectory.split('@');
|
|
73
|
-
const targetPath = join(rootPath, workspace, '/target');
|
|
74
|
-
this.logger.debug(`Looking for compiled artifact in workspace ${targetPath}`);
|
|
75
|
-
artifactPath = join(targetPath, `${pkg}-${contractFilename}.json`);
|
|
76
|
-
} else {
|
|
77
|
-
// We're deploying a standalone external contract
|
|
78
|
-
// env.deploy("../path/to/contract/root/contractName")
|
|
79
|
-
const targetPath = join(rootPath, contractDirectory, '/target');
|
|
80
|
-
this.logger.debug(`Looking for compiled artifact in ${targetPath}`);
|
|
81
|
-
[artifactPath] = (await readdir(targetPath)).filter((file)=>file.endsWith(`-${contractFilename}.json`));
|
|
82
|
-
}
|
|
83
|
-
} else {
|
|
84
|
-
// We're deploying a local contract
|
|
85
|
-
// env.deploy("contractName")
|
|
86
|
-
artifactPath = join(rootPath, './target', `${packageName}-${contractFilename}.json`);
|
|
87
|
-
}
|
|
88
|
-
const fileHash = await this.fastHashFile(artifactPath);
|
|
89
|
-
const cacheKey = `${contractDirectory ?? ''}-${contractFilename}-${initializer}-${decodedArgs.map((arg)=>arg.toString()).join('-')}-${publicKeysHash}-${salt}-${deployer}-${fileHash}`;
|
|
90
|
-
let instance;
|
|
91
|
-
let artifact;
|
|
92
|
-
if (TXEArtifactsCache.has(cacheKey)) {
|
|
93
|
-
this.logger.debug(`Using cached artifact for ${cacheKey}`);
|
|
94
|
-
({ artifact, instance } = TXEArtifactsCache.get(cacheKey));
|
|
95
|
-
} else {
|
|
96
|
-
if (!TXEArtifactsCacheInFlight.has(cacheKey)) {
|
|
97
|
-
this.logger.debug(`Loading compiled artifact ${artifactPath}`);
|
|
98
|
-
const compute = async ()=>{
|
|
99
|
-
const artifactJSON = JSON.parse(await readFile(artifactPath, 'utf-8'));
|
|
100
|
-
const artifactWithoutHash = loadContractArtifact(artifactJSON);
|
|
101
|
-
const computedArtifact = {
|
|
102
|
-
...artifactWithoutHash,
|
|
103
|
-
// Artifact hash is *very* expensive to compute, so we do it here once
|
|
104
|
-
// and the TXE contract data provider can cache it
|
|
105
|
-
artifactHash: await computeArtifactHash(artifactWithoutHash)
|
|
106
|
-
};
|
|
107
|
-
this.logger.debug(`Deploy ${computedArtifact.name} with initializer ${initializer}(${decodedArgs}) and public keys hash ${publicKeysHash.toString()}`);
|
|
108
|
-
const computedInstance = await getContractInstanceFromInstantiationParams(computedArtifact, {
|
|
109
|
-
constructorArgs: decodedArgs,
|
|
110
|
-
skipArgsDecoding: true,
|
|
111
|
-
salt,
|
|
112
|
-
publicKeys,
|
|
113
|
-
constructorArtifact: initializer ? initializer : undefined,
|
|
114
|
-
deployer
|
|
115
|
-
});
|
|
116
|
-
const result = {
|
|
117
|
-
artifact: computedArtifact,
|
|
118
|
-
instance: computedInstance
|
|
119
|
-
};
|
|
120
|
-
TXEArtifactsCache.set(cacheKey, result);
|
|
121
|
-
TXEArtifactsCacheInFlight.delete(cacheKey);
|
|
122
|
-
return result;
|
|
123
|
-
};
|
|
124
|
-
TXEArtifactsCacheInFlight.set(cacheKey, compute());
|
|
125
|
-
}
|
|
126
|
-
({ artifact, instance } = await TXEArtifactsCacheInFlight.get(cacheKey));
|
|
43
|
+
/**
|
|
44
|
+
* Clones the pre-populated LMDB at `contractStoreSourceDir` into a fresh per-instance tmpdir
|
|
45
|
+
* on first use, so this dispatcher has a writable store already containing the required
|
|
46
|
+
* protocol contracts + SchnorrAccount. Idempotent — subsequent calls are no-ops.
|
|
47
|
+
*/ async warmUp() {
|
|
48
|
+
if (this.contractStore) {
|
|
49
|
+
return;
|
|
127
50
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (TXEArtifactsCache.has(cacheKey)) {
|
|
136
|
-
this.logger.debug(`Using cached artifact for ${cacheKey}`);
|
|
137
|
-
({ artifact, instance } = TXEArtifactsCache.get(cacheKey));
|
|
138
|
-
} else {
|
|
139
|
-
if (!TXEArtifactsCacheInFlight.has(cacheKey)) {
|
|
140
|
-
const compute = async ()=>{
|
|
141
|
-
const keys = await deriveKeys(secret);
|
|
142
|
-
const args = [
|
|
143
|
-
keys.publicKeys.masterIncomingViewingPublicKey.x,
|
|
144
|
-
keys.publicKeys.masterIncomingViewingPublicKey.y
|
|
145
|
-
];
|
|
146
|
-
const computedArtifact = {
|
|
147
|
-
...SchnorrAccountContractArtifact,
|
|
148
|
-
// Artifact hash is *very* expensive to compute, so we do it here once
|
|
149
|
-
// and the TXE contract data provider can cache it
|
|
150
|
-
artifactHash: await computeArtifactHash(SchnorrAccountContractArtifact)
|
|
151
|
-
};
|
|
152
|
-
const computedInstance = await getContractInstanceFromInstantiationParams(computedArtifact, {
|
|
153
|
-
constructorArgs: args,
|
|
154
|
-
skipArgsDecoding: true,
|
|
155
|
-
salt: Fr.ONE,
|
|
156
|
-
publicKeys: keys.publicKeys,
|
|
157
|
-
constructorArtifact: 'constructor',
|
|
158
|
-
deployer: AztecAddress.ZERO
|
|
159
|
-
});
|
|
160
|
-
const result = {
|
|
161
|
-
artifact: computedArtifact,
|
|
162
|
-
instance: computedInstance
|
|
163
|
-
};
|
|
164
|
-
TXEArtifactsCache.set(cacheKey, result);
|
|
165
|
-
TXEArtifactsCacheInFlight.delete(cacheKey);
|
|
166
|
-
return result;
|
|
167
|
-
};
|
|
168
|
-
TXEArtifactsCacheInFlight.set(cacheKey, compute());
|
|
169
|
-
}
|
|
170
|
-
({ artifact, instance } = await TXEArtifactsCacheInFlight.get(cacheKey));
|
|
171
|
-
}
|
|
172
|
-
inputs.splice(0, 0, artifact, instance);
|
|
51
|
+
const t0 = Date.now();
|
|
52
|
+
const kvStore = await cloneEphemeralStoreFrom(join(this.contractStoreSourceDir, 'data.mdb'), 'txe-contracts', undefined, 2);
|
|
53
|
+
this.contractStore = new ContractStore(kvStore);
|
|
54
|
+
this.artifactResolver = new TXEArtifactResolver(this.contractStore, this.schnorrClassId);
|
|
55
|
+
this.logger.debug('Cloned shared protocol-contracts store', {
|
|
56
|
+
totalMs: Date.now() - t0
|
|
57
|
+
});
|
|
173
58
|
}
|
|
174
59
|
// eslint-disable-next-line camelcase
|
|
175
60
|
async resolve_foreign_call(callData) {
|
|
176
|
-
const { session_id: sessionId, function: functionName, inputs } = callData;
|
|
61
|
+
const { session_id: sessionId, function: functionName, inputs, root_path: rootPath, package_name: packageName } = callData;
|
|
177
62
|
this.logger.debug(`Calling ${functionName} on session ${sessionId}`);
|
|
178
63
|
if (!sessions.has(sessionId)) {
|
|
179
64
|
this.logger.debug(`Creating new session ${sessionId}`);
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
this.contractStore = new ContractStore(kvStore);
|
|
183
|
-
const provider = new BundledProtocolContractsProvider();
|
|
184
|
-
for (const name of protocolContractNames){
|
|
185
|
-
const { instance, artifact } = await provider.getProtocolContractArtifact(name);
|
|
186
|
-
await this.contractStore.addContractArtifact(artifact);
|
|
187
|
-
await this.contractStore.addContractInstance(instance);
|
|
188
|
-
}
|
|
189
|
-
this.logger.debug('Registered protocol contracts in shared contract store');
|
|
190
|
-
}
|
|
191
|
-
sessions.set(sessionId, await TXESession.init(this.contractStore));
|
|
192
|
-
}
|
|
193
|
-
switch(functionName){
|
|
194
|
-
case 'aztec_txe_deploy':
|
|
195
|
-
{
|
|
196
|
-
await this.#processDeployInputs(callData);
|
|
197
|
-
break;
|
|
198
|
-
}
|
|
199
|
-
case 'aztec_txe_addAccount':
|
|
200
|
-
{
|
|
201
|
-
await this.#processAddAccountInputs(callData);
|
|
202
|
-
break;
|
|
203
|
-
}
|
|
65
|
+
await this.warmUp();
|
|
66
|
+
sessions.set(sessionId, await TXESession.init(this.contractStore, this.artifactResolver, rootPath, packageName));
|
|
204
67
|
}
|
|
205
68
|
return await sessions.get(sessionId).processFunction(functionName, inputs);
|
|
206
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Releases a session and its resources (per-session LMDB + `NativeWorldStateService`).
|
|
72
|
+
* Called by the dispatcher pool when nargo closes its TCP connection for a test (see
|
|
73
|
+
* `rpc_server.ts`'s socket tracker). No-op if the session was never created — that happens
|
|
74
|
+
* when nargo opens a connection but errors before sending a request.
|
|
75
|
+
*/ async disposeSession(sessionId) {
|
|
76
|
+
const session = sessions.get(sessionId);
|
|
77
|
+
if (!session) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
sessions.delete(sessionId);
|
|
81
|
+
await session.dispose();
|
|
82
|
+
}
|
|
207
83
|
}
|
|
208
|
-
|
|
84
|
+
/** Diagnostic-only: number of sessions currently held by this worker. */ export function activeSessionCount() {
|
|
85
|
+
return sessions.size;
|
|
86
|
+
}
|
|
87
|
+
export const TXEDispatcherApiSchema = {
|
|
209
88
|
// eslint-disable-next-line camelcase
|
|
210
|
-
resolve_foreign_call: z.function(
|
|
89
|
+
resolve_foreign_call: z.function({
|
|
90
|
+
input: z.tuple([
|
|
91
|
+
TXEForeignCallInputSchema
|
|
92
|
+
]),
|
|
93
|
+
output: ForeignCallResultSchema
|
|
94
|
+
}),
|
|
95
|
+
// disposeSession is invoked over IPC from the worker, not via RPC; required by ApiSchemaFor.
|
|
96
|
+
disposeSession: z.function({
|
|
97
|
+
input: z.tuple([
|
|
98
|
+
z.number().nonnegative()
|
|
99
|
+
]),
|
|
100
|
+
output: z.void()
|
|
101
|
+
})
|
|
211
102
|
};
|
|
212
|
-
/**
|
|
213
|
-
* Creates an RPC server that forwards calls to the TXE.
|
|
214
|
-
* @param logger - Logger to output to
|
|
215
|
-
* @returns A TXE RPC server.
|
|
216
|
-
*/ export function createTXERpcServer(logger) {
|
|
217
|
-
return createSafeJsonRpcServer(new TXEDispatcher(logger), TXEDispatcherApiSchema, {
|
|
218
|
-
http200OnError: true
|
|
219
|
-
});
|
|
220
|
-
}
|