From 78dc82862405e309412d17662ed2754c82991a40 Mon Sep 17 00:00:00 2001 From: "Justin (shocknet)" Date: Fri, 5 Jul 2024 22:55:00 -0400 Subject: [PATCH] init retry mechanism --- src/services/main/unlocker.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/services/main/unlocker.ts b/src/services/main/unlocker.ts index 6d7ffdfb..f6a8bbf6 100644 --- a/src/services/main/unlocker.ts +++ b/src/services/main/unlocker.ts @@ -83,7 +83,16 @@ export class Unlocker { const initRes = await unlocker.initWallet(req, DeadLineMetadata(60 * 1000)) const adminMacaroon = Buffer.from(initRes.response.adminMacaroon).toString('hex') const ln = this.GetLightningClient(lndCert, adminMacaroon) - const info = await this.GetLndInfo(ln) + + // Retry mechanism to ensure LND is ready + let info; + for (let i = 0; i < 10; i++) { + info = await this.GetLndInfo(ln); + if (info.ok) break; + this.log("LND not ready, retrying in 5 seconds..."); + await new Promise(res => setTimeout(res, 5000)); + } + if (!info.ok) { throw new Error("failed to init lnd wallet " + info.failure) }