Compare commits
18 commits
c08bf4b849
...
4c69a4d390
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c69a4d390 | ||
|
|
220a332196 | ||
|
|
1a1a3b2a38 | ||
|
|
61912ff5c6 | ||
|
|
b8e38aa383 | ||
|
|
b0747d42ea | ||
|
|
e3d70f84b9 | ||
|
|
4bc0e1801f | ||
|
|
5cc7f3998c | ||
|
|
c308d4be78 | ||
|
|
f1aa5d7139 | ||
|
|
9981e2628e | ||
|
|
ece75df22d | ||
|
|
c909cd660a | ||
|
|
5b88982fed | ||
|
|
4d19b55c57 | ||
|
|
071a27ad2d | ||
|
|
fee87e2741 |
3 changed files with 40 additions and 18 deletions
|
|
@ -192,6 +192,31 @@ export interface ExtensionContext {
|
||||||
log(level: 'debug' | 'info' | 'warn' | 'error', message: string, ...args: any[]): void
|
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<string, string>
|
||||||
|
query: Record<string, string>
|
||||||
|
headers: Record<string, string>
|
||||||
|
body?: any
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface HttpResponse {
|
||||||
|
status: number
|
||||||
|
body: any
|
||||||
|
headers?: Record<string, string>
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface HttpRoute {
|
||||||
|
method: 'GET' | 'POST'
|
||||||
|
path: string
|
||||||
|
handler: (req: HttpRequest) => Promise<HttpResponse>
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extension interface - what extensions must implement
|
* Extension interface - what extensions must implement
|
||||||
*/
|
*/
|
||||||
|
|
@ -218,6 +243,12 @@ export interface Extension {
|
||||||
* Return true if extension is healthy
|
* Return true if extension is healthy
|
||||||
*/
|
*/
|
||||||
healthCheck?(): Promise<boolean>
|
healthCheck?(): Promise<boolean>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get HTTP routes exposed by this extension
|
||||||
|
* The main HTTP server will mount these routes
|
||||||
|
*/
|
||||||
|
getHttpRoutes?(): HttpRoute[]
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -142,20 +142,15 @@ export default class {
|
||||||
return new Promise<void>((res, rej) => {
|
return new Promise<void>((res, rej) => {
|
||||||
const interval = setInterval(async () => {
|
const interval = setInterval(async () => {
|
||||||
try {
|
try {
|
||||||
const info = await this.GetInfo()
|
await this.GetInfo()
|
||||||
if (!info.syncedToChain || !info.syncedToGraph) {
|
|
||||||
this.log("LND responding but not synced yet, waiting...")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
clearInterval(interval)
|
clearInterval(interval)
|
||||||
this.ready = true
|
this.ready = true
|
||||||
res()
|
res()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.log(INFO, "LND is not ready yet, will try again in 1 second")
|
this.log(INFO, "LND is not ready yet, will try again in 1 second")
|
||||||
}
|
if (Date.now() - now > 1000 * 60) {
|
||||||
if (Date.now() - now > 1000 * 60 * 10) {
|
rej(new Error("LND not ready after 1 minute"))
|
||||||
clearInterval(interval)
|
}
|
||||||
rej(new Error("LND not synced after 10 minutes"))
|
|
||||||
}
|
}
|
||||||
}, 1000)
|
}, 1000)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -238,17 +238,13 @@ 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 deny = await this.checkBalanceUpdate(deltaLnd, deltaUsers)
|
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 (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.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