init retry mechanism

This commit is contained in:
Justin (shocknet) 2024-07-05 22:55:00 -04:00
parent a79e0fe4ec
commit 78dc828624

View file

@ -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)
}