diff --git a/src/extensions/types.ts b/src/extensions/types.ts index e67c1e4f..66a4c46a 100644 --- a/src/extensions/types.ts +++ b/src/extensions/types.ts @@ -192,6 +192,31 @@ export interface ExtensionContext { log(level: 'debug' | 'info' | 'warn' | 'error', message: string, ...args: any[]): void } +/** + * HTTP route handler types + * Used by extensions that expose HTTP endpoints (e.g. LNURL, .well-known) + */ +export interface HttpRequest { + method: string + path: string + params: Record + query: Record + headers: Record + body?: any +} + +export interface HttpResponse { + status: number + body: any + headers?: Record +} + +export interface HttpRoute { + method: 'GET' | 'POST' + path: string + handler: (req: HttpRequest) => Promise +} + /** * Extension interface - what extensions must implement */ @@ -218,6 +243,12 @@ export interface Extension { * Return true if extension is healthy */ healthCheck?(): Promise + + /** + * Get HTTP routes exposed by this extension + * The main HTTP server will mount these routes + */ + getHttpRoutes?(): HttpRoute[] } /** diff --git a/src/services/lnd/lnd.ts b/src/services/lnd/lnd.ts index ce19eae5..fb3815dd 100644 --- a/src/services/lnd/lnd.ts +++ b/src/services/lnd/lnd.ts @@ -142,20 +142,15 @@ export default class { return new Promise((res, rej) => { const interval = setInterval(async () => { try { - const info = await this.GetInfo() - if (!info.syncedToChain || !info.syncedToGraph) { - this.log("LND responding but not synced yet, waiting...") - return - } + await this.GetInfo() clearInterval(interval) this.ready = true res() } catch (err) { this.log(INFO, "LND is not ready yet, will try again in 1 second") - } - if (Date.now() - now > 1000 * 60 * 10) { - clearInterval(interval) - rej(new Error("LND not synced after 10 minutes")) + if (Date.now() - now > 1000 * 60) { + rej(new Error("LND not ready after 1 minute")) + } } }, 1000) }) diff --git a/src/services/main/watchdog.ts b/src/services/main/watchdog.ts index 3c12b676..d9d585ba 100644 --- a/src/services/main/watchdog.ts +++ b/src/services/main/watchdog.ts @@ -238,17 +238,13 @@ export class Watchdog { const knownMaxIndex = Math.max(maxFromDb, this.latestPaymentIndexOffset) const newLatest = await this.lnd.GetLatestPaymentIndex(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 deny = await this.checkBalanceUpdate(deltaLnd, deltaUsers) + if (historyMismatch) { + getLogger({ component: 'bark' })("History mismatch detected in absolute update, locking outgoing operations") + this.lnd.LockOutgoingOperations() + return + } if (deny) { - if (historyMismatch) { - getLogger({ component: 'bark' })("Balance mismatch with unexpected payment history, locking outgoing operations") - this.lnd.LockOutgoingOperations() - return - } this.log("Balance mismatch detected in absolute update, but history is ok") } this.lnd.UnlockOutgoingOperations()