From 89154933b9cc62df42dcf46a44671ca007b1d081 Mon Sep 17 00:00:00 2001 From: boufni95 Date: Fri, 31 Oct 2025 18:25:40 +0000 Subject: [PATCH] unlock on reconnect --- src/services/lnd/lnd.ts | 8 +++++--- src/services/main/index.ts | 2 +- src/services/main/unlocker.ts | 4 ++-- src/tests/networkSetup.ts | 4 ++-- src/tests/testBase.ts | 4 ++-- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/services/lnd/lnd.ts b/src/services/lnd/lnd.ts index b68975b5..6aaa7f9b 100644 --- a/src/services/lnd/lnd.ts +++ b/src/services/lnd/lnd.ts @@ -21,7 +21,7 @@ import { Utils } from '../helpers/utilsWrapper.js'; import { TxPointSettings } from '../storage/tlv/stateBundler.js'; import { WalletKitClient } from '../../../proto/lnd/walletkit.client.js'; const DeadLineMetadata = (deadline = 10 * 1000) => ({ deadline: Date.now() + deadline }) -const deadLndRetrySeconds = 5 +const deadLndRetrySeconds = 20 type TxActionOptions = { useProvider: boolean, from: 'user' | 'system' } export default class { lightning: LightningClient @@ -43,9 +43,11 @@ export default class { outgoingOpsLocked = false liquidProvider: LiquidityProvider utils: Utils - constructor(settings: LndSettings, liquidProvider: LiquidityProvider, utils: Utils, addressPaidCb: AddressPaidCb, invoicePaidCb: InvoicePaidCb, newBlockCb: NewBlockCb, htlcCb: HtlcCb, channelEventCb: ChannelEventCb) { + unlockLnd: () => Promise + constructor(settings: LndSettings, liquidProvider: LiquidityProvider, unlockLnd: () => Promise, utils: Utils, addressPaidCb: AddressPaidCb, invoicePaidCb: InvoicePaidCb, newBlockCb: NewBlockCb, htlcCb: HtlcCb, channelEventCb: ChannelEventCb) { this.settings = settings this.utils = utils + this.unlockLnd = unlockLnd this.addressPaidCb = addressPaidCb this.invoicePaidCb = invoicePaidCb this.newBlockCb = newBlockCb @@ -168,7 +170,7 @@ export default class { this.log("LND is dead, will try to reconnect in", deadLndRetrySeconds, "seconds") const interval = setInterval(async () => { try { - await this.Health() + await this.unlockLnd() this.log("LND is back online") clearInterval(interval) await this.Warmup() diff --git a/src/services/main/index.ts b/src/services/main/index.ts index 71c64592..5c5fef16 100644 --- a/src/services/main/index.ts +++ b/src/services/main/index.ts @@ -74,7 +74,7 @@ export default class { const updateProviderBalance = (b: number) => this.storage.liquidityStorage.IncrementTrackedProviderBalance('lnPub', settings.liquiditySettings.liquidityProviderPub, b) this.liquidityProvider = new LiquidityProvider(settings.liquiditySettings.liquidityProviderPub, this.utils, this.invoicePaidCb, updateProviderBalance) this.rugPullTracker = new RugPullTracker(this.storage, this.liquidityProvider) - this.lnd = new LND(settings.lndSettings, this.liquidityProvider, this.utils, this.addressPaidCb, this.invoicePaidCb, this.newBlockCb, this.htlcCb, this.channelEventCb) + this.lnd = new LND(settings.lndSettings, this.liquidityProvider, () => this.unlocker.Unlock(), this.utils, this.addressPaidCb, this.invoicePaidCb, this.newBlockCb, this.htlcCb, this.channelEventCb) this.liquidityManager = new LiquidityManager(this.settings.liquiditySettings, this.storage, this.utils, this.liquidityProvider, this.lnd, this.rugPullTracker) this.metricsManager = new MetricsManager(this.storage, this.lnd) diff --git a/src/services/main/unlocker.ts b/src/services/main/unlocker.ts index b104ffd3..7221d183 100644 --- a/src/services/main/unlocker.ts +++ b/src/services/main/unlocker.ts @@ -301,12 +301,12 @@ export class Unlocker { GetWalletPassword = () => { const path = this.settings.walletPasswordPath - let password = Buffer.alloc(0) + let password: Buffer | null = null try { password = fs.readFileSync(path) } catch { } - if (password.length === 0) { + if (!password || password.length === 0) { this.log("no wallet password configured, using wallet secret") const secret = this.GetWalletSecret(false) if (secret === "") { diff --git a/src/tests/networkSetup.ts b/src/tests/networkSetup.ts index 5944a1fc..40f0e58b 100644 --- a/src/tests/networkSetup.ts +++ b/src/tests/networkSetup.ts @@ -14,8 +14,8 @@ export const setupNetwork = async (): Promise => { await core.InitAddress() await core.Mine(1) const setupUtils = new Utils({ dataDir: settings.storageSettings.dataDir, allowResetMetricsStorages: settings.allowResetMetricsStorages }) - const alice = new LND(settings.lndSettings, new LiquidityProvider("", setupUtils, async () => { }, async () => { }), setupUtils, async () => { }, async () => { }, () => { }, () => { }, () => { }) - const bob = new LND({ ...settings.lndSettings, mainNode: settings.lndSettings.otherNode }, new LiquidityProvider("", setupUtils, async () => { }, async () => { }), setupUtils, async () => { }, async () => { }, () => { }, () => { }, () => { }) + const alice = new LND(settings.lndSettings, new LiquidityProvider("", setupUtils, async () => { }, async () => { }), async () => { }, setupUtils, async () => { }, async () => { }, () => { }, () => { }, () => { }) + const bob = new LND({ ...settings.lndSettings, mainNode: settings.lndSettings.otherNode }, new LiquidityProvider("", setupUtils, async () => { }, async () => { }), async () => { }, setupUtils, async () => { }, async () => { }, () => { }, () => { }, () => { }) await tryUntil(async i => { const peers = await alice.ListPeers() if (peers.peers.length > 0) { diff --git a/src/tests/testBase.ts b/src/tests/testBase.ts index 95454a95..fdd599b9 100644 --- a/src/tests/testBase.ts +++ b/src/tests/testBase.ts @@ -78,11 +78,11 @@ export const SetupTest = async (d: Describe, chainTools: ChainTools): Promise { }, async () => { }), extermnalUtils, async () => { }, async () => { }, () => { }, () => { }, () => { }) + const externalAccessToOtherLnd = new LND(otherLndSetting, new LiquidityProvider("", extermnalUtils, async () => { }, async () => { }), async () => { }, extermnalUtils, async () => { }, async () => { }, () => { }, () => { }, () => { }) await externalAccessToOtherLnd.Warmup() const thirdLndSetting = { ...settings.lndSettings, mainNode: settings.lndSettings.thirdNode } - const externalAccessToThirdLnd = new LND(thirdLndSetting, new LiquidityProvider("", extermnalUtils, async () => { }, async () => { }), extermnalUtils, async () => { }, async () => { }, () => { }, () => { }, () => { }) + const externalAccessToThirdLnd = new LND(thirdLndSetting, new LiquidityProvider("", extermnalUtils, async () => { }, async () => { }), async () => { }, extermnalUtils, async () => { }, async () => { }, () => { }, () => { }, () => { }) await externalAccessToThirdLnd.Warmup()