Skip to content

Commit

Permalink
Handle ritual initialization timing out
Browse files Browse the repository at this point in the history
  • Loading branch information
theref committed Jul 17, 2023
1 parent 49fa8ab commit 1d53cae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/agents/coordinator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ export class DkgCoordinatorAgent {
return Coordinator.rituals(ritualId);
}

public static async getTimeout(
provider: ethers.providers.Web3Provider
): Promise<number> {
const Coordinator = await this.connectReadOnly(provider);
const timeout = await Coordinator.timeout();
return timeout;
}


public static async getRitualState(
provider: ethers.providers.Web3Provider,
ritualId: number
Expand Down
11 changes: 7 additions & 4 deletions src/dkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,13 @@ export class DkgClient {
);

if (waitUntilEnd) {
const isSuccessful = await DkgClient.waitUntilRitualEnd(
web3Provider,
ritualId
);
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 ritualState = await DkgCoordinatorAgent.getRitualState(
web3Provider,
Expand Down

0 comments on commit 1d53cae

Please sign in to comment.