@aztec/foundation 0.0.1-commit.2f68f620 → 0.0.1-commit.321f6a9
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/config/env_var.d.ts +2 -2
- package/dest/config/env_var.d.ts.map +1 -1
- package/dest/config/index.d.ts +21 -8
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +46 -30
- package/dest/crypto/keys/index.d.ts +3 -2
- package/dest/crypto/keys/index.d.ts.map +1 -1
- package/dest/crypto/keys/index.js +30 -6
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts +1 -1
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -1
- package/dest/json-rpc/client/safe_json_rpc_client.js +3 -2
- package/dest/promise/running-promise.d.ts +5 -4
- package/dest/promise/running-promise.d.ts.map +1 -1
- package/dest/promise/running-promise.js +7 -3
- package/dest/retry/index.d.ts +20 -3
- package/dest/retry/index.d.ts.map +1 -1
- package/dest/retry/index.js +23 -2
- package/dest/testing/files/index.d.ts +2 -3
- package/dest/testing/files/index.d.ts.map +1 -1
- package/dest/testing/files/index.js +1 -2
- package/dest/trees/membership_witness.d.ts +1 -5
- package/dest/trees/membership_witness.d.ts.map +1 -1
- package/dest/trees/membership_witness.js +0 -9
- package/package.json +2 -2
- package/src/config/env_var.ts +23 -4
- package/src/config/index.ts +46 -30
- package/src/crypto/keys/index.ts +20 -4
- package/src/json-rpc/client/safe_json_rpc_client.ts +3 -2
- package/src/promise/running-promise.ts +8 -5
- package/src/retry/index.ts +36 -4
- package/src/testing/files/index.ts +1 -2
- package/src/trees/membership_witness.ts +0 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/retry/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ret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AS,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,EAClD,IAAI,SAAK,EACT,OAAO,SAAK,EACZ,QAAQ,SAAM,oCAGf"}
|
package/dest/retry/index.js
CHANGED
|
@@ -68,6 +68,23 @@ import { Timer } from '../timer/index.js';
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Resolves a {@link RetryUntilTimeout} to a numeric timeout in seconds for the legacy timer-based loop.
|
|
73
|
+
* A numeric/`{ timeout }` value passes through unchanged (0 means never time out, negative times out on the
|
|
74
|
+
* first interval). A `{ deadline }` is the remaining seconds until the deadline; when the deadline is already
|
|
75
|
+
* at or past `now` it resolves to a negative value so the loop times out immediately instead of being read as
|
|
76
|
+
* the never-timeout sentinel 0.
|
|
77
|
+
*/ function resolveRetryUntilTimeoutSeconds(timeout) {
|
|
78
|
+
if (typeof timeout === 'number') {
|
|
79
|
+
return timeout;
|
|
80
|
+
}
|
|
81
|
+
if ('deadline' in timeout) {
|
|
82
|
+
const now = timeout.dateProvider?.now() ?? Date.now();
|
|
83
|
+
const remainingSeconds = (timeout.deadline.getTime() - now) / 1000;
|
|
84
|
+
return remainingSeconds > 0 ? remainingSeconds : -1;
|
|
85
|
+
}
|
|
86
|
+
return timeout.timeout;
|
|
87
|
+
}
|
|
71
88
|
/**
|
|
72
89
|
* Retry an asynchronous function until it returns a truthy value or the specified timeout is exceeded.
|
|
73
90
|
* The function is retried periodically with a fixed interval between attempts. The operation can be named for better error messages.
|
|
@@ -75,10 +92,14 @@ import { Timer } from '../timer/index.js';
|
|
|
75
92
|
*
|
|
76
93
|
* @param fn - The asynchronous function to be retried, which should return a truthy value upon success or undefined otherwise.
|
|
77
94
|
* @param name - The optional name of the operation, used for generating timeout error message.
|
|
78
|
-
* @param timeout - The
|
|
95
|
+
* @param timeout - The maximum time to keep retrying before throwing a timeout error. Accepts a number of
|
|
96
|
+
* seconds (0 = never time out), an explicit `{ timeout }` in seconds, or an absolute `{ deadline }` with an
|
|
97
|
+
* optional `dateProvider`. A deadline already in the past times out on the first interval, the same as a
|
|
98
|
+
* zero/negative numeric timeout. Defaults to 0 (never timeout).
|
|
79
99
|
* @param interval - The optional interval, in seconds, between retry attempts. Defaults to 1 second.
|
|
80
100
|
* @returns A Promise that resolves with the successful (truthy) result of the provided function, or rejects if timeout is exceeded.
|
|
81
101
|
*/ export async function retryUntil(fn, name = '', timeout = 0, interval = 1) {
|
|
102
|
+
const timeoutSeconds = resolveRetryUntilTimeoutSeconds(timeout);
|
|
82
103
|
const timer = new Timer();
|
|
83
104
|
while(true){
|
|
84
105
|
const result = await fn();
|
|
@@ -86,7 +107,7 @@ import { Timer } from '../timer/index.js';
|
|
|
86
107
|
return result;
|
|
87
108
|
}
|
|
88
109
|
await sleep(interval * 1000);
|
|
89
|
-
if (
|
|
110
|
+
if (timeoutSeconds && timer.s() > timeoutSeconds) {
|
|
90
111
|
throw new TimeoutError(name ? `Timeout awaiting ${name}` : 'Timeout');
|
|
91
112
|
}
|
|
92
113
|
}
|
|
@@ -11,9 +11,8 @@ export declare function updateInlineTestData(targetFileFromRepoRoot: string, ite
|
|
|
11
11
|
/**
|
|
12
12
|
* Updates the sample Prover.toml files in noir-projects/noir-protocol-circuits/crates/.
|
|
13
13
|
* @remarks Requires AZTEC_GENERATE_TEST_DATA=1 to be set
|
|
14
|
-
* To re-gen, run 'AZTEC_GENERATE_TEST_DATA=1 FAKE_PROOFS=1 yarn test:e2e full.test'
|
|
15
|
-
* To re-gen public base only, run 'AZTEC_GENERATE_TEST_DATA=1 yarn workspace @aztec/prover-client test orchestrator_public_functions'
|
|
14
|
+
* To re-gen, run 'AZTEC_GENERATE_TEST_DATA=1 FAKE_PROOFS=1 yarn test:e2e e2e_prover/full.test'
|
|
16
15
|
*/
|
|
17
16
|
export declare function updateProtocolCircuitSampleInputs(circuitName: string, value: string): void;
|
|
18
17
|
export declare function getPathToFile(targetFileFromRepoRoot: string): string;
|
|
19
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
18
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy90ZXN0aW5nL2ZpbGVzL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQU9BLDJGQUEyRjtBQUMzRix3QkFBZ0IsYUFBYSxDQUFDLHNCQUFzQixFQUFFLE1BQU0sRUFBRSxRQUFRLEVBQUUsTUFBTSxHQUFHLE1BQU0sRUFBRSxHQUFHLEdBQUUsT0FBZSxRQVM1RztBQUVELHdCQUFnQixZQUFZLENBQUMsUUFBUSxFQUFFLE1BQU0sR0FBRyxNQUFNLENBR3JEO0FBRUQ7Ozs7O0dBS0c7QUFDSCx3QkFBZ0Isb0JBQW9CLENBQUMsc0JBQXNCLEVBQUUsTUFBTSxFQUFFLFFBQVEsRUFBRSxNQUFNLEVBQUUsS0FBSyxFQUFFLE1BQU0sUUFtQm5HO0FBRUQ7Ozs7R0FJRztBQUNILHdCQUFnQixpQ0FBaUMsQ0FBQyxXQUFXLEVBQUUsTUFBTSxFQUFFLEtBQUssRUFBRSxNQUFNLFFBTW5GO0FBRUQsd0JBQWdCLGFBQWEsQ0FBQyxzQkFBc0IsRUFBRSxNQUFNLFVBTzNEIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/testing/files/index.ts"],"names":[],"mappings":"AAOA,2FAA2F;AAC3F,wBAAgB,aAAa,CAAC,sBAAsB,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,GAAE,OAAe,QAS5G;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGrD;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,sBAAsB,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAmBnG;AAED
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/testing/files/index.ts"],"names":[],"mappings":"AAOA,2FAA2F;AAC3F,wBAAgB,aAAa,CAAC,sBAAsB,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,GAAE,OAAe,QAS5G;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGrD;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,sBAAsB,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAmBnG;AAED;;;;GAIG;AACH,wBAAgB,iCAAiC,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAMnF;AAED,wBAAgB,aAAa,CAAC,sBAAsB,EAAE,MAAM,UAO3D"}
|
|
@@ -40,8 +40,7 @@ export function readTestData(repoPath) {
|
|
|
40
40
|
/**
|
|
41
41
|
* Updates the sample Prover.toml files in noir-projects/noir-protocol-circuits/crates/.
|
|
42
42
|
* @remarks Requires AZTEC_GENERATE_TEST_DATA=1 to be set
|
|
43
|
-
* To re-gen, run 'AZTEC_GENERATE_TEST_DATA=1 FAKE_PROOFS=1 yarn test:e2e full.test'
|
|
44
|
-
* To re-gen public base only, run 'AZTEC_GENERATE_TEST_DATA=1 yarn workspace @aztec/prover-client test orchestrator_public_functions'
|
|
43
|
+
* To re-gen, run 'AZTEC_GENERATE_TEST_DATA=1 FAKE_PROOFS=1 yarn test:e2e e2e_prover/full.test'
|
|
45
44
|
*/ export function updateProtocolCircuitSampleInputs(circuitName, value) {
|
|
46
45
|
const logger = createConsoleLogger('aztec:testing:test_data');
|
|
47
46
|
const targetFileFromRepoRoot = `noir-projects/noir-protocol-circuits/crates/${circuitName}/Prover.toml`;
|
|
@@ -29,10 +29,6 @@ export declare class MembershipWitness<N extends number> {
|
|
|
29
29
|
toBuffer(): Buffer<ArrayBufferLike>;
|
|
30
30
|
toJSON(): Buffer<ArrayBufferLike>;
|
|
31
31
|
toFields(): Fr[];
|
|
32
|
-
/**
|
|
33
|
-
* Returns a representation of the membership witness as expected by intrinsic Noir deserialization.
|
|
34
|
-
*/
|
|
35
|
-
toNoirRepresentation(): (string | string[])[];
|
|
36
32
|
static schemaFor<N extends number>(size: N): import("zod").ZodPipe<import("../schemas/types.js").ZodFor<Buffer<ArrayBufferLike>>, import("zod").ZodTransform<MembershipWitness<N>, Buffer<ArrayBufferLike>>>;
|
|
37
33
|
/**
|
|
38
34
|
* Creates a random membership witness. Used for testing purposes.
|
|
@@ -64,4 +60,4 @@ export declare class MembershipWitness<N extends number> {
|
|
|
64
60
|
};
|
|
65
61
|
static fromSiblingPath<N extends number>(leafIndex: bigint, siblingPath: SiblingPath<N>): MembershipWitness<N>;
|
|
66
62
|
}
|
|
67
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
63
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVtYmVyc2hpcF93aXRuZXNzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdHJlZXMvbWVtYmVyc2hpcF93aXRuZXNzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSwwQkFBMEIsQ0FBQztBQUU5QyxPQUFPLEVBQUUsWUFBWSxFQUFFLEtBQUssS0FBSyxFQUFxQixNQUFNLHVCQUF1QixDQUFDO0FBQ3BGLE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBRXJEOztHQUVHO0FBQ0gscUJBQWEsaUJBQWlCLENBQUMsQ0FBQyxTQUFTLE1BQU07SUFNM0M7O09BRUc7SUFDSSxTQUFTLEVBQUUs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sQ0FBQyxDQUtoRztJQUVEOzs7O09BSUc7SUFDSCxNQUFNLENBQUMsWUFBWSxDQUFDLENBQUMsU0FBUyxNQUFNLEVBQUUsSUFBSSxFQUFFLENBQUMsR0FBRztRQUFFLFVBQVUsQ0FBQyxNQUFNLEVBQUUsTUFBTSxHQUFHLFlBQVksR0FBRyxpQkFBaUIsQ0FBQyxDQUFDLENBQUMsQ0FBQTtLQUFFLENBU2xIO0lBRUQsTUFBTSxDQUFDLGVBQWUsQ0FBQyxDQUFDLFNBQVMsTUFBTSxFQUFFLFNBQVMsRUFBRSxNQUFNLEVBQUUsV0FBVyxFQUFFLFdBQVcsQ0FBQyxDQUFDLENBQUMsR0FBRyxpQkFBaUIsQ0FBQyxDQUFDLENBQUMsQ0FFN0c7Q0FDRiJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"membership_witness.d.ts","sourceRoot":"","sources":["../../src/trees/membership_witness.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE9C,OAAO,EAAE,YAAY,EAAE,KAAK,KAAK,EAAqB,MAAM,uBAAuB,CAAC;AACpF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;GAEG;AACH,qBAAa,iBAAiB,CAAC,CAAC,SAAS,MAAM;IAM3C;;OAEG;IACI,SAAS,EAAE,MAAM;IACxB;;OAEG;IACI,WAAW,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;IAZlC;IACE;;OAEG;IACH,QAAQ,EAAE,CAAC;IACX;;OAEG;IACI,SAAS,EAAE,MAAM;IACxB;;OAEG;IACI,WAAW,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,EAGjC;IAED,QAAQ,4BAEP;IAED,MAAM,4BAEL;IAED,QAAQ,IAAI,EAAE,EAAE,CAEf;IAED
|
|
1
|
+
{"version":3,"file":"membership_witness.d.ts","sourceRoot":"","sources":["../../src/trees/memb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AIG;IACH,MAAM,CAAC,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG;QAAE,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAA;KAAE,CASlH;IAED,MAAM,CAAC,eAAe,CAAC,CAAC,SAAS,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAE7G;CACF"}
|
|
@@ -31,15 +31,6 @@ import { BufferReader, serializeToBuffer } from '../serialize/index.js';
|
|
|
31
31
|
...this.siblingPath
|
|
32
32
|
];
|
|
33
33
|
}
|
|
34
|
-
/**
|
|
35
|
-
* Returns a representation of the membership witness as expected by intrinsic Noir deserialization.
|
|
36
|
-
*/ toNoirRepresentation() {
|
|
37
|
-
// TODO(#12874): remove the stupid as string conversion by modifying ForeignCallOutput type in acvm.js
|
|
38
|
-
return [
|
|
39
|
-
new Fr(this.leafIndex).toString(),
|
|
40
|
-
this.siblingPath.map((fr)=>fr.toString())
|
|
41
|
-
];
|
|
42
|
-
}
|
|
43
34
|
static schemaFor(size) {
|
|
44
35
|
return schemas.Buffer.transform((b)=>MembershipWitness.fromBuffer(b, size));
|
|
45
36
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/foundation",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.321f6a9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dest/index.js",
|
|
6
6
|
"types": "./dest/index.d.ts",
|
|
@@ -146,7 +146,7 @@
|
|
|
146
146
|
"testEnvironment": "../../foundation/src/jest/env.mjs"
|
|
147
147
|
},
|
|
148
148
|
"dependencies": {
|
|
149
|
-
"@aztec/bb.js": "0.0.1-commit.
|
|
149
|
+
"@aztec/bb.js": "0.0.1-commit.321f6a9",
|
|
150
150
|
"@koa/cors": "^5.0.0",
|
|
151
151
|
"@noble/curves": "=1.7.0",
|
|
152
152
|
"@noble/hashes": "^1.6.1",
|
package/src/config/env_var.ts
CHANGED
|
@@ -10,7 +10,8 @@ export type EnvVar =
|
|
|
10
10
|
| 'ARCHIVER_URL'
|
|
11
11
|
| 'ARCHIVER_VIEM_POLLING_INTERVAL_MS'
|
|
12
12
|
| 'ARCHIVER_BATCH_SIZE'
|
|
13
|
-
| '
|
|
13
|
+
| 'ARCHIVER_ORPHAN_PRUNE_NO_PROPOSAL_TOLERANCE'
|
|
14
|
+
| 'ARCHIVER_SKIP_ORPHAN_PROPOSED_BLOCK_PRUNING'
|
|
14
15
|
| 'AZTEC_ADMIN_PORT'
|
|
15
16
|
| 'AZTEC_NODE_DEBUG'
|
|
16
17
|
| 'AZTEC_ADMIN_API_KEY_HASH'
|
|
@@ -77,6 +78,7 @@ export type EnvVar =
|
|
|
77
78
|
| 'DEBUG_P2P_DISABLE_COLOCATION_PENALTY'
|
|
78
79
|
| 'ENABLE_PROVER_NODE'
|
|
79
80
|
| 'USE_AUTOMINE_SEQUENCER'
|
|
81
|
+
| 'AUTOMINE_ENABLE_PROVE_EPOCH'
|
|
80
82
|
| 'ETHEREUM_HOSTS'
|
|
81
83
|
| 'ETHEREUM_DEBUG_HOSTS'
|
|
82
84
|
| 'ETHEREUM_ALLOW_NO_DEBUG_HOSTS'
|
|
@@ -97,6 +99,7 @@ export type EnvVar =
|
|
|
97
99
|
| 'MNEMONIC'
|
|
98
100
|
| 'NETWORK'
|
|
99
101
|
| 'NETWORK_CONFIG_LOCATION'
|
|
102
|
+
| 'ALLOW_OVERRIDING_NETWORK_CONFIG'
|
|
100
103
|
| 'USE_GCLOUD_LOGGING'
|
|
101
104
|
| 'OTEL_EXPORTER_OTLP_METRICS_ENDPOINT'
|
|
102
105
|
| 'OTEL_EXPORTER_OTLP_TRACES_ENDPOINT'
|
|
@@ -116,7 +119,6 @@ export type EnvVar =
|
|
|
116
119
|
| 'P2P_BATCH_TX_REQUESTER_TX_BATCH_SIZE'
|
|
117
120
|
| 'P2P_BATCH_TX_REQUESTER_BAD_PEER_THRESHOLD'
|
|
118
121
|
| 'P2P_BLOCK_CHECK_INTERVAL_MS'
|
|
119
|
-
| 'P2P_SLOT_CHECK_INTERVAL_MS'
|
|
120
122
|
| 'P2P_BLOCK_REQUEST_BATCH_SIZE'
|
|
121
123
|
| 'P2P_BOOTSTRAP_NODE_ENR_VERSION_CHECK'
|
|
122
124
|
| 'P2P_BOOTSTRAP_NODES_AS_FULL_PEERS'
|
|
@@ -135,7 +137,9 @@ export type EnvVar =
|
|
|
135
137
|
| 'P2P_GOSSIPSUB_TX_INVALID_MESSAGE_DELIVERIES_WEIGHT'
|
|
136
138
|
| 'P2P_GOSSIPSUB_TX_TOPIC_WEIGHT'
|
|
137
139
|
| 'P2P_L2_QUEUE_SIZE'
|
|
140
|
+
| 'P2P_MAX_GOSSIP_CLOCK_DISPARITY_MS'
|
|
138
141
|
| 'P2P_MAX_PEERS'
|
|
142
|
+
| 'P2P_PEER_BAN_DURATION_SECONDS'
|
|
139
143
|
| 'P2P_PEER_CHECK_INTERVAL_MS'
|
|
140
144
|
| 'P2P_PEER_FAILED_BAN_TIME_MS'
|
|
141
145
|
| 'P2P_PEER_PENALTY_VALUES'
|
|
@@ -164,6 +168,7 @@ export type EnvVar =
|
|
|
164
168
|
| 'P2P_MIN_TX_POOL_AGE_MS'
|
|
165
169
|
| 'P2P_MISSING_TX_COLLECTION_DEADLINE_SLOTS'
|
|
166
170
|
| 'P2P_RPC_PRICE_BUMP_PERCENTAGE'
|
|
171
|
+
| 'P2P_KEEP_FINALIZED_TXS_FOR_SLOTS'
|
|
167
172
|
| 'P2P_TX_VALIDATION_CACHE_SIZE'
|
|
168
173
|
| 'DEBUG_P2P_INSTRUMENT_MESSAGES'
|
|
169
174
|
| 'PEER_ID_PRIVATE_KEY'
|
|
@@ -213,6 +218,7 @@ export type EnvVar =
|
|
|
213
218
|
| 'RPC_MAX_BODY_SIZE'
|
|
214
219
|
| 'RPC_SIMULATE_PUBLIC_MAX_GAS_LIMIT'
|
|
215
220
|
| 'RPC_SIMULATE_PUBLIC_MAX_DEBUG_LOG_MEMORY_READS'
|
|
221
|
+
| 'OFFENSE_COLLECTION_ENABLED'
|
|
216
222
|
| 'SENTINEL_ENABLED'
|
|
217
223
|
| 'SENTINEL_HISTORY_LENGTH_IN_EPOCHS'
|
|
218
224
|
| 'SENTINEL_HISTORIC_EPOCH_PERFORMANCE_LENGTH_IN_EPOCHS'
|
|
@@ -224,18 +230,23 @@ export type EnvVar =
|
|
|
224
230
|
| 'SEQ_MAX_DA_BLOCK_GAS'
|
|
225
231
|
| 'SEQ_MAX_L2_BLOCK_GAS'
|
|
226
232
|
| 'SEQ_PER_BLOCK_ALLOCATION_MULTIPLIER'
|
|
233
|
+
| 'SEQ_PER_BLOCK_DA_ALLOCATION_MULTIPLIER'
|
|
227
234
|
| 'SEQ_REDISTRIBUTE_CHECKPOINT_BUDGET'
|
|
228
235
|
| 'SEQ_PUBLISHER_PRIVATE_KEY'
|
|
229
236
|
| 'SEQ_PUBLISHER_PRIVATE_KEYS'
|
|
230
237
|
| 'SEQ_PUBLISHER_ADDRESSES'
|
|
231
238
|
| 'SEQ_PUBLISHER_ALLOW_INVALID_STATES'
|
|
232
239
|
| 'SEQ_PUBLISHER_FORWARDER_ADDRESS'
|
|
240
|
+
| 'SEQ_PUBLISHER_PREVIOUS_L1_BLOCK_WAIT_TIMEOUT_MS'
|
|
241
|
+
| 'SEQ_PUBLISHER_PREVIOUS_L1_BLOCK_WAIT_POLL_INTERVAL_MS'
|
|
233
242
|
| 'PUBLISHER_FUNDING_THRESHOLD'
|
|
234
243
|
| 'PUBLISHER_FUNDING_AMOUNT'
|
|
235
244
|
| 'SEQ_POLLING_INTERVAL_MS'
|
|
236
|
-
| 'SEQ_ENFORCE_TIME_TABLE'
|
|
237
245
|
| 'SEQ_L1_PUBLISHING_TIME_ALLOWANCE_IN_SLOT'
|
|
238
246
|
| 'SEQ_ATTESTATION_PROPAGATION_TIME'
|
|
247
|
+
| 'SEQ_CHECKPOINT_PROPOSAL_PREPARE_TIME'
|
|
248
|
+
| 'CHECKPOINT_PROPOSAL_SYNC_GRACE_SECONDS'
|
|
249
|
+
| 'SEQ_MIN_BLOCK_DURATION'
|
|
239
250
|
| 'SEQ_BLOCK_DURATION_MS'
|
|
240
251
|
| 'SEQ_LAST_BLOCK_DURATION_MS'
|
|
241
252
|
| 'SEQ_EXPECTED_BLOCK_PROPOSALS_PER_SLOT'
|
|
@@ -268,6 +279,7 @@ export type EnvVar =
|
|
|
268
279
|
| 'SYNC_SNAPSHOTS_URL'
|
|
269
280
|
| 'TELEMETRY'
|
|
270
281
|
| 'TEST_ACCOUNTS'
|
|
282
|
+
| 'TEST_PRELOAD_STANDARD_CONTRACTS'
|
|
271
283
|
| 'SPONSORED_FPC'
|
|
272
284
|
| 'PREFUND_ADDRESSES'
|
|
273
285
|
| 'TX_COLLECTION_FAST_NODES_TIMEOUT_BEFORE_REQ_RESP_MS'
|
|
@@ -333,6 +345,11 @@ export type EnvVar =
|
|
|
333
345
|
| 'AZTEC_GOVERNANCE_PROPOSER_ROUND_SIZE'
|
|
334
346
|
| 'AZTEC_GOVERNANCE_VOTING_DURATION'
|
|
335
347
|
| 'AZTEC_EXIT_DELAY_SECONDS'
|
|
348
|
+
| 'AZTEC_ENTRY_QUEUE_BOOTSTRAP_VALIDATOR_SET_SIZE'
|
|
349
|
+
| 'AZTEC_ENTRY_QUEUE_BOOTSTRAP_FLUSH_SIZE'
|
|
350
|
+
| 'AZTEC_ENTRY_QUEUE_FLUSH_SIZE_MIN'
|
|
351
|
+
| 'AZTEC_ENTRY_QUEUE_FLUSH_SIZE_QUOTIENT'
|
|
352
|
+
| 'AZTEC_ENTRY_QUEUE_MAX_FLUSH_SIZE'
|
|
336
353
|
| 'L1_GAS_LIMIT_BUFFER_PERCENTAGE'
|
|
337
354
|
| 'L1_GAS_PRICE_MAX'
|
|
338
355
|
| 'L1_FEE_PER_GAS_GWEI_MAX'
|
|
@@ -357,7 +374,7 @@ export type EnvVar =
|
|
|
357
374
|
| 'K8S_POD_NAME'
|
|
358
375
|
| 'K8S_POD_UID'
|
|
359
376
|
| 'K8S_NAMESPACE_NAME'
|
|
360
|
-
| '
|
|
377
|
+
| 'ENABLE_AUTO_SHUTDOWN'
|
|
361
378
|
| 'WEB3_SIGNER_URL'
|
|
362
379
|
| 'SKIP_ARCHIVER_INITIAL_SYNC'
|
|
363
380
|
| 'BLOB_ALLOW_EMPTY_SOURCES'
|
|
@@ -368,10 +385,12 @@ export type EnvVar =
|
|
|
368
385
|
| 'MAX_BLOCKS_PER_CHECKPOINT'
|
|
369
386
|
| 'LEGACY_BLS_CLI'
|
|
370
387
|
| 'DEBUG_FORCE_TX_PROOF_VERIFICATION'
|
|
388
|
+
| 'VALIDATOR_ALLOW_EPHEMERAL_SIGNING_PROTECTION'
|
|
371
389
|
| 'VALIDATOR_HA_SIGNING_ENABLED'
|
|
372
390
|
| 'VALIDATOR_HA_NODE_ID'
|
|
373
391
|
| 'VALIDATOR_HA_POLLING_INTERVAL_MS'
|
|
374
392
|
| 'VALIDATOR_HA_SIGNING_TIMEOUT_MS'
|
|
393
|
+
| 'VALIDATOR_SIGNER_CALL_TIMEOUT_MS'
|
|
375
394
|
| 'VALIDATOR_HA_MAX_STUCK_DUTIES_AGE_MS'
|
|
376
395
|
| 'VALIDATOR_HA_OLD_DUTIES_MAX_AGE_H'
|
|
377
396
|
| 'VALIDATOR_HA_DATABASE_URL'
|
package/src/config/index.ts
CHANGED
|
@@ -119,21 +119,29 @@ export function omitConfigMappings<T, K extends keyof T>(
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
/**
|
|
122
|
-
* Generates parseEnv and default values for
|
|
123
|
-
*
|
|
124
|
-
*
|
|
122
|
+
* Generates parseEnv and default values for an integer config value.
|
|
123
|
+
*
|
|
124
|
+
* The default is used only when the environment variable is unset or empty. A set-but-invalid
|
|
125
|
+
* value (non-numeric, fractional, or outside the safe-integer range) throws rather than silently
|
|
126
|
+
* falling back to the default.
|
|
127
|
+
* @param defaultVal - The default value to use when the environment variable is unset
|
|
128
|
+
* @returns Object with parseEnv and default values for an integer config value
|
|
125
129
|
*/
|
|
126
130
|
export function numberConfigHelper(defaultVal: number): Pick<ConfigMapping<number>, 'parseEnv' | 'defaultValue'> {
|
|
127
131
|
return {
|
|
128
|
-
parseEnv: (val: string) =>
|
|
132
|
+
parseEnv: (val: string) => parseSafeInteger(val),
|
|
129
133
|
defaultValue: defaultVal,
|
|
130
134
|
};
|
|
131
135
|
}
|
|
132
136
|
|
|
133
137
|
/**
|
|
134
|
-
* Generates parseEnv and default values for a
|
|
135
|
-
*
|
|
136
|
-
*
|
|
138
|
+
* Generates parseEnv and default values for a floating-point config value.
|
|
139
|
+
*
|
|
140
|
+
* The default is used only when the environment variable is unset or empty. A set-but-invalid
|
|
141
|
+
* value (not a finite number) throws rather than silently falling back to the default.
|
|
142
|
+
* @param defaultVal - The default value to use when the environment variable is unset
|
|
143
|
+
* @param validationFn - Optional extra validation applied to the parsed value; should throw on invalid input
|
|
144
|
+
* @returns Object with parseEnv and default values for a floating-point config value
|
|
137
145
|
*/
|
|
138
146
|
export function floatConfigHelper(
|
|
139
147
|
defaultVal: number,
|
|
@@ -141,7 +149,7 @@ export function floatConfigHelper(
|
|
|
141
149
|
): Pick<ConfigMapping<number>, 'parseEnv' | 'defaultValue'> {
|
|
142
150
|
return {
|
|
143
151
|
parseEnv: (val: string): number => {
|
|
144
|
-
const parsed =
|
|
152
|
+
const parsed = parseFiniteNumber(val);
|
|
145
153
|
validationFn?.(parsed);
|
|
146
154
|
return parsed;
|
|
147
155
|
},
|
|
@@ -150,12 +158,17 @@ export function floatConfigHelper(
|
|
|
150
158
|
}
|
|
151
159
|
|
|
152
160
|
/**
|
|
153
|
-
*
|
|
161
|
+
* Generates parseEnv and default values for a 0-1 percentage config value.
|
|
162
|
+
*
|
|
163
|
+
* The default is used only when the environment variable is unset or empty. A set-but-invalid
|
|
164
|
+
* value (not a finite number, or outside the 0-1 range) throws rather than silently falling back
|
|
165
|
+
* to the default.
|
|
166
|
+
* @param defaultVal - The default value to use when the environment variable is unset
|
|
154
167
|
*/
|
|
155
168
|
export function percentageConfigHelper(defaultVal: number): Pick<ConfigMapping<number>, 'parseEnv' | 'defaultValue'> {
|
|
156
169
|
return {
|
|
157
170
|
parseEnv: (val: string): number => {
|
|
158
|
-
const parsed =
|
|
171
|
+
const parsed = parseFiniteNumber(val);
|
|
159
172
|
if (parsed < 0 || parsed > 1) {
|
|
160
173
|
throw new TypeError(`Invalid percentage value: ${parsed} should be between 0 and 1`);
|
|
161
174
|
}
|
|
@@ -205,13 +218,7 @@ export function bigintConfigHelper(
|
|
|
205
218
|
*/
|
|
206
219
|
export function optionalNumberConfigHelper(): Pick<ConfigMapping<number>, 'parseEnv'> {
|
|
207
220
|
return {
|
|
208
|
-
parseEnv: (val: string) =>
|
|
209
|
-
const parsedValue = parseInt(val);
|
|
210
|
-
if (!Number.isSafeInteger(parsedValue)) {
|
|
211
|
-
throw new Error(`Invalid number: ${val}`);
|
|
212
|
-
}
|
|
213
|
-
return parsedValue;
|
|
214
|
-
},
|
|
221
|
+
parseEnv: (val: string) => parseSafeInteger(val),
|
|
215
222
|
};
|
|
216
223
|
}
|
|
217
224
|
|
|
@@ -344,27 +351,36 @@ export function secretFqConfigHelper(defaultValue?: Fq): {
|
|
|
344
351
|
}
|
|
345
352
|
|
|
346
353
|
/**
|
|
347
|
-
*
|
|
348
|
-
*
|
|
354
|
+
* Parses a string into a safe integer, throwing if the value is numeric but not an integer.
|
|
355
|
+
*
|
|
356
|
+
* Unlike `parseInt`, this does not silently truncate decimals: `'0.8'` throws rather than
|
|
357
|
+
* becoming `0`. A fractional value indicates the caller intended a non-integer where only
|
|
358
|
+
* integers are supported (use `floatConfigHelper`/`percentageConfigHelper` for those).
|
|
349
359
|
* @param value - The string value to parse
|
|
350
|
-
* @
|
|
351
|
-
* @returns Either parsed value or default value
|
|
360
|
+
* @returns The parsed integer value
|
|
352
361
|
*/
|
|
353
|
-
function
|
|
354
|
-
const parsedValue =
|
|
355
|
-
|
|
362
|
+
function parseSafeInteger(value: string): number {
|
|
363
|
+
const parsedValue = parseFloat(value);
|
|
364
|
+
if (!Number.isSafeInteger(parsedValue)) {
|
|
365
|
+
throw new Error(`Invalid integer config value '${value}'; expected a whole number`);
|
|
366
|
+
}
|
|
367
|
+
return parsedValue;
|
|
356
368
|
}
|
|
357
369
|
|
|
358
370
|
/**
|
|
359
|
-
*
|
|
360
|
-
*
|
|
371
|
+
* Parses a string into a finite floating-point number, throwing if the value is not a finite number.
|
|
372
|
+
*
|
|
373
|
+
* Invalid input (e.g. `'abc'`, or an overflow to `Infinity`) throws rather than being silently
|
|
374
|
+
* swallowed, so a misconfigured value fails loudly instead of falling back to the config default.
|
|
361
375
|
* @param value - The string value to parse
|
|
362
|
-
* @
|
|
363
|
-
* @returns Either parsed value or default value
|
|
376
|
+
* @returns The parsed number
|
|
364
377
|
*/
|
|
365
|
-
function
|
|
378
|
+
function parseFiniteNumber(value: string): number {
|
|
366
379
|
const parsedValue = parseFloat(value);
|
|
367
|
-
|
|
380
|
+
if (!Number.isFinite(parsedValue)) {
|
|
381
|
+
throw new Error(`Invalid number config value '${value}'`);
|
|
382
|
+
}
|
|
383
|
+
return parsedValue;
|
|
368
384
|
}
|
|
369
385
|
|
|
370
386
|
/**
|
package/src/crypto/keys/index.ts
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
|
-
import { BarretenbergSync } from '@aztec/bb.js';
|
|
1
|
+
import { BarretenbergSync, CircuitKind } from '@aztec/bb.js';
|
|
2
2
|
|
|
3
3
|
import { Fr } from '../../curves/bn254/field.js';
|
|
4
4
|
|
|
5
|
-
export async function
|
|
5
|
+
export async function vkAsFields(input: Buffer, kind: CircuitKind): Promise<Fr[]> {
|
|
6
6
|
await BarretenbergSync.initSingleton();
|
|
7
7
|
const api = BarretenbergSync.getSingleton();
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
switch (kind) {
|
|
9
|
+
case CircuitKind.App: {
|
|
10
|
+
const response = api.megaAppVkAsFields({ verificationKey: input });
|
|
11
|
+
return response.fields.map(field => Fr.fromBuffer(Buffer.from(field)));
|
|
12
|
+
}
|
|
13
|
+
case CircuitKind.Kernel: {
|
|
14
|
+
const response = api.megaKernelVkAsFields({ verificationKey: input });
|
|
15
|
+
return response.fields.map(field => Fr.fromBuffer(Buffer.from(field)));
|
|
16
|
+
}
|
|
17
|
+
case CircuitKind.HidingKernel: {
|
|
18
|
+
const response = api.megaZKVkAsFields({ verificationKey: input });
|
|
19
|
+
return response.fields.map(field => Fr.fromBuffer(Buffer.from(field)));
|
|
20
|
+
}
|
|
21
|
+
default: {
|
|
22
|
+
const _exhaustive: never = kind;
|
|
23
|
+
throw new Error(`vkAsFields: unhandled CircuitKind ${_exhaustive}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
10
26
|
}
|
|
@@ -14,8 +14,9 @@ const DEFAULT_BATCH_WINDOW_MS = 0;
|
|
|
14
14
|
// the maximum size of a batched request
|
|
15
15
|
const DEFAULT_MAX_BATCH_SIZE = 100;
|
|
16
16
|
|
|
17
|
-
//
|
|
18
|
-
|
|
17
|
+
// 1 mb, matching the JSON-RPC server's default maxBodySizeBytes so the client never assembles a batch the
|
|
18
|
+
// server rejects for exceeding the body limit
|
|
19
|
+
const DEFAULT_MAX_REQUESTY_BODY_SIZE = 1 * 1024 * 1024;
|
|
19
20
|
|
|
20
21
|
export type SafeJsonRpcClientOptions = {
|
|
21
22
|
namespaceMethods?: string | false;
|
|
@@ -22,16 +22,17 @@ export function makeLoggingErrorHandler(
|
|
|
22
22
|
* at a specified polling interval. It allows starting, stopping, and checking the status of the
|
|
23
23
|
* internally managed promise. The class also supports interrupting the polling process when stopped.
|
|
24
24
|
*/
|
|
25
|
-
export class RunningPromise {
|
|
25
|
+
export class RunningPromise<T = void> {
|
|
26
26
|
private running = false;
|
|
27
27
|
private runningPromise = Promise.resolve();
|
|
28
28
|
private interruptibleSleep = new InterruptibleSleep();
|
|
29
29
|
private requested: PromiseWithResolvers<void> | undefined = undefined;
|
|
30
|
+
private requestedArg: T | undefined = undefined;
|
|
30
31
|
|
|
31
32
|
public static readonly EXIT: typeof EXIT = EXIT;
|
|
32
33
|
|
|
33
34
|
constructor(
|
|
34
|
-
private fn: () => void | Promise<void>,
|
|
35
|
+
private fn: (arg?: T) => void | Promise<void>,
|
|
35
36
|
private logger = createLogger('running-promise'),
|
|
36
37
|
private pollingIntervalMS = 10000,
|
|
37
38
|
private handleError: ErrorHandler = makeLoggingErrorHandler(logger),
|
|
@@ -51,7 +52,7 @@ export class RunningPromise {
|
|
|
51
52
|
while (this.running) {
|
|
52
53
|
const hasRequested = this.requested !== undefined;
|
|
53
54
|
try {
|
|
54
|
-
await this.fn();
|
|
55
|
+
await this.fn(this.requestedArg);
|
|
55
56
|
} catch (err) {
|
|
56
57
|
const code = await this.handleError(err);
|
|
57
58
|
if (code === RunningPromise.EXIT) {
|
|
@@ -64,6 +65,7 @@ export class RunningPromise {
|
|
|
64
65
|
if (hasRequested) {
|
|
65
66
|
this.requested!.resolve();
|
|
66
67
|
this.requested = undefined;
|
|
68
|
+
this.requestedArg = undefined;
|
|
67
69
|
}
|
|
68
70
|
|
|
69
71
|
// If no immediate run was requested, sleep for the polling interval.
|
|
@@ -101,15 +103,16 @@ export class RunningPromise {
|
|
|
101
103
|
* Triggers an immediate run of the function, bypassing the polling interval.
|
|
102
104
|
* If the function is currently running, it will be allowed to continue and then called again immediately.
|
|
103
105
|
*/
|
|
104
|
-
public async trigger() {
|
|
106
|
+
public async trigger(arg?: T): Promise<void> {
|
|
105
107
|
if (!this.running) {
|
|
106
|
-
return this.fn();
|
|
108
|
+
return this.fn(arg);
|
|
107
109
|
}
|
|
108
110
|
|
|
109
111
|
let requested = this.requested;
|
|
110
112
|
if (!requested) {
|
|
111
113
|
requested = promiseWithResolvers<void>();
|
|
112
114
|
this.requested = requested;
|
|
115
|
+
this.requestedArg = arg;
|
|
113
116
|
this.interruptibleSleep.interrupt();
|
|
114
117
|
}
|
|
115
118
|
await requested!.promise;
|
package/src/retry/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TimeoutError } from '../error/index.js';
|
|
2
2
|
import { type Logger, createLogger } from '../log/index.js';
|
|
3
3
|
import { sleep } from '../sleep/index.js';
|
|
4
|
-
import { Timer } from '../timer/index.js';
|
|
4
|
+
import { type DateProvider, Timer } from '../timer/index.js';
|
|
5
5
|
|
|
6
6
|
/** An error that indicates that the operation should not be retried. */
|
|
7
7
|
export class NoRetryError extends Error {}
|
|
@@ -72,6 +72,34 @@ export async function retry<Result>(
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Timeout specification accepted by {@link retryUntil}. Either a plain number of seconds, an explicit
|
|
77
|
+
* `{ timeout }` in seconds, or an absolute `{ deadline }` with an optional {@link DateProvider} used to
|
|
78
|
+
* read the current time. A deadline is converted to the remaining seconds at call time; a deadline that
|
|
79
|
+
* has already passed yields a zero remaining budget, matching the immediate-timeout semantics of a
|
|
80
|
+
* non-positive numeric timeout.
|
|
81
|
+
*/
|
|
82
|
+
export type RetryUntilTimeout = number | { timeout: number } | { deadline: Date; dateProvider?: DateProvider };
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Resolves a {@link RetryUntilTimeout} to a numeric timeout in seconds for the legacy timer-based loop.
|
|
86
|
+
* A numeric/`{ timeout }` value passes through unchanged (0 means never time out, negative times out on the
|
|
87
|
+
* first interval). A `{ deadline }` is the remaining seconds until the deadline; when the deadline is already
|
|
88
|
+
* at or past `now` it resolves to a negative value so the loop times out immediately instead of being read as
|
|
89
|
+
* the never-timeout sentinel 0.
|
|
90
|
+
*/
|
|
91
|
+
function resolveRetryUntilTimeoutSeconds(timeout: RetryUntilTimeout): number {
|
|
92
|
+
if (typeof timeout === 'number') {
|
|
93
|
+
return timeout;
|
|
94
|
+
}
|
|
95
|
+
if ('deadline' in timeout) {
|
|
96
|
+
const now = timeout.dateProvider?.now() ?? Date.now();
|
|
97
|
+
const remainingSeconds = (timeout.deadline.getTime() - now) / 1000;
|
|
98
|
+
return remainingSeconds > 0 ? remainingSeconds : -1;
|
|
99
|
+
}
|
|
100
|
+
return timeout.timeout;
|
|
101
|
+
}
|
|
102
|
+
|
|
75
103
|
/**
|
|
76
104
|
* Retry an asynchronous function until it returns a truthy value or the specified timeout is exceeded.
|
|
77
105
|
* The function is retried periodically with a fixed interval between attempts. The operation can be named for better error messages.
|
|
@@ -79,16 +107,20 @@ export async function retry<Result>(
|
|
|
79
107
|
*
|
|
80
108
|
* @param fn - The asynchronous function to be retried, which should return a truthy value upon success or undefined otherwise.
|
|
81
109
|
* @param name - The optional name of the operation, used for generating timeout error message.
|
|
82
|
-
* @param timeout - The
|
|
110
|
+
* @param timeout - The maximum time to keep retrying before throwing a timeout error. Accepts a number of
|
|
111
|
+
* seconds (0 = never time out), an explicit `{ timeout }` in seconds, or an absolute `{ deadline }` with an
|
|
112
|
+
* optional `dateProvider`. A deadline already in the past times out on the first interval, the same as a
|
|
113
|
+
* zero/negative numeric timeout. Defaults to 0 (never timeout).
|
|
83
114
|
* @param interval - The optional interval, in seconds, between retry attempts. Defaults to 1 second.
|
|
84
115
|
* @returns A Promise that resolves with the successful (truthy) result of the provided function, or rejects if timeout is exceeded.
|
|
85
116
|
*/
|
|
86
117
|
export async function retryUntil<T>(
|
|
87
118
|
fn: () => (T | undefined) | Promise<T | undefined>,
|
|
88
119
|
name = '',
|
|
89
|
-
timeout = 0,
|
|
120
|
+
timeout: RetryUntilTimeout = 0,
|
|
90
121
|
interval = 1,
|
|
91
122
|
) {
|
|
123
|
+
const timeoutSeconds = resolveRetryUntilTimeoutSeconds(timeout);
|
|
92
124
|
const timer = new Timer();
|
|
93
125
|
while (true) {
|
|
94
126
|
const result = await fn();
|
|
@@ -98,7 +130,7 @@ export async function retryUntil<T>(
|
|
|
98
130
|
|
|
99
131
|
await sleep(interval * 1000);
|
|
100
132
|
|
|
101
|
-
if (
|
|
133
|
+
if (timeoutSeconds && timer.s() > timeoutSeconds) {
|
|
102
134
|
throw new TimeoutError(name ? `Timeout awaiting ${name}` : 'Timeout');
|
|
103
135
|
}
|
|
104
136
|
}
|
|
@@ -52,8 +52,7 @@ export function updateInlineTestData(targetFileFromRepoRoot: string, itemName: s
|
|
|
52
52
|
/**
|
|
53
53
|
* Updates the sample Prover.toml files in noir-projects/noir-protocol-circuits/crates/.
|
|
54
54
|
* @remarks Requires AZTEC_GENERATE_TEST_DATA=1 to be set
|
|
55
|
-
* To re-gen, run 'AZTEC_GENERATE_TEST_DATA=1 FAKE_PROOFS=1 yarn test:e2e full.test'
|
|
56
|
-
* To re-gen public base only, run 'AZTEC_GENERATE_TEST_DATA=1 yarn workspace @aztec/prover-client test orchestrator_public_functions'
|
|
55
|
+
* To re-gen, run 'AZTEC_GENERATE_TEST_DATA=1 FAKE_PROOFS=1 yarn test:e2e e2e_prover/full.test'
|
|
57
56
|
*/
|
|
58
57
|
export function updateProtocolCircuitSampleInputs(circuitName: string, value: string) {
|
|
59
58
|
const logger = createConsoleLogger('aztec:testing:test_data');
|
|
@@ -38,14 +38,6 @@ export class MembershipWitness<N extends number> {
|
|
|
38
38
|
return [new Fr(this.leafIndex), ...this.siblingPath];
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
/**
|
|
42
|
-
* Returns a representation of the membership witness as expected by intrinsic Noir deserialization.
|
|
43
|
-
*/
|
|
44
|
-
public toNoirRepresentation(): (string | string[])[] {
|
|
45
|
-
// TODO(#12874): remove the stupid as string conversion by modifying ForeignCallOutput type in acvm.js
|
|
46
|
-
return [new Fr(this.leafIndex).toString() as string, this.siblingPath.map(fr => fr.toString()) as string[]];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
41
|
static schemaFor<N extends number>(size: N) {
|
|
50
42
|
return schemas.Buffer.transform(b => MembershipWitness.fromBuffer(b, size));
|
|
51
43
|
}
|