@aztec/foundation 0.0.1-commit.b9865e97 → 0.0.1-commit.be03c316
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/bls/bn254_keystore.d.ts +2 -2
- package/dest/crypto/bls/bn254_keystore.d.ts.map +1 -1
- package/dest/crypto/bls/bn254_keystore.js +22 -17
- 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/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/bls/bn254_keystore.ts +33 -20
- package/src/crypto/keys/index.ts +20 -4
- 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
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
|
}
|