fix(watchdog): handle LND restarts without locking outgoing operations
Some checks failed
Docker Compose Actions Workflow / test (push) Has been cancelled
Some checks failed
Docker Compose Actions Workflow / test (push) Has been cancelled
When the payment index advances (e.g. after an LND restart or external payment), update the cached offset instead of immediately locking. Only lock if both a history mismatch AND a balance discrepancy are detected — indicating a real security concern rather than a benign LND restart. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b1fd18d45c
commit
e6513b4797
1 changed files with 9 additions and 5 deletions
|
|
@ -196,15 +196,19 @@ export class Watchdog {
|
||||||
const knownMaxIndex = Math.max(maxFromDb, this.latestPaymentIndexOffset)
|
const knownMaxIndex = Math.max(maxFromDb, this.latestPaymentIndexOffset)
|
||||||
const newLatest = await this.lnd.GetLatestPaymentIndex(knownMaxIndex)
|
const newLatest = await this.lnd.GetLatestPaymentIndex(knownMaxIndex)
|
||||||
const historyMismatch = newLatest > knownMaxIndex
|
const historyMismatch = newLatest > knownMaxIndex
|
||||||
|
if (historyMismatch) {
|
||||||
|
this.log("Payment index advanced from", knownMaxIndex, "to", newLatest, "- updating offset (likely LND restart or external payment)")
|
||||||
|
this.latestPaymentIndexOffset = newLatest
|
||||||
|
}
|
||||||
const other = { ilnd: this.initialLndBalance, hf: this.accumulatedHtlcFees, iu: this.initialUsersBalance, tu: totalUsersBalance, km: knownMaxIndex, nl: newLatest, oext: otherExternal }
|
const other = { ilnd: this.initialLndBalance, hf: this.accumulatedHtlcFees, iu: this.initialUsersBalance, tu: totalUsersBalance, km: knownMaxIndex, nl: newLatest, oext: otherExternal }
|
||||||
//getLogger({ component: 'watchdog_debug2' })(JSON.stringify({ deltaLnd, deltaUsers, totalExternal, other }))
|
//getLogger({ component: 'watchdog_debug2' })(JSON.stringify({ deltaLnd, deltaUsers, totalExternal, other }))
|
||||||
const deny = await this.checkBalanceUpdate(deltaLnd, deltaUsers)
|
const deny = await this.checkBalanceUpdate(deltaLnd, deltaUsers)
|
||||||
|
if (deny) {
|
||||||
if (historyMismatch) {
|
if (historyMismatch) {
|
||||||
getLogger({ component: 'bark' })("History mismatch detected in absolute update, locking outgoing operations")
|
getLogger({ component: 'bark' })("Balance mismatch with unexpected payment history, locking outgoing operations")
|
||||||
this.lnd.LockOutgoingOperations()
|
this.lnd.LockOutgoingOperations()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (deny) {
|
|
||||||
this.log("Balance mismatch detected in absolute update, but history is ok")
|
this.log("Balance mismatch detected in absolute update, but history is ok")
|
||||||
}
|
}
|
||||||
this.lnd.UnlockOutgoingOperations()
|
this.lnd.UnlockOutgoingOperations()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue