Skip to content

Commit

Permalink
Add timeout buffer, catch timeout errors, check the ritual state, and…
Browse files Browse the repository at this point in the history
… return a new error
  • Loading branch information
theref committed Jul 19, 2023
1 parent 35df81f commit 6d7ae37
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/dkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,24 @@ export class DkgClient {

if (waitUntilEnd) {
const timeout = await DkgCoordinatorAgent.getTimeout(web3Provider);
const isSuccessful = await Promise.race([
DkgClient.waitUntilRitualEnd(web3Provider, ritualId),
new Promise((_, reject) =>
setTimeout(() => reject(new Error('Ritual initialization timed out')), timeout)
),
]);
if (!isSuccessful) {
const bufferedTimeout = timeout * 1.1;
try {
const isSuccessful = await Promise.race([
DkgClient.waitUntilRitualEnd(web3Provider, ritualId),
new Promise((_, reject) =>
setTimeout(() => reject(new Error('Ritual initialization timed out')), bufferedTimeout)
),
]);

if (!isSuccessful) {
throw new Error(`Ritual initialization failed. Ritual id ${ritualId}`);
}
} catch (error) {
const ritualState = await DkgCoordinatorAgent.getRitualState(
web3Provider,
ritualId
);

throw new Error(
`Ritual initialization failed. Ritual id ${ritualId} is in state ${ritualState}`
);
Expand Down

0 comments on commit 6d7ae37

Please sign in to comment.