diff --git a/metricsDatasource.js b/metricsDatasource.js index c1c3f493..aaf5ddbc 100644 --- a/metricsDatasource.js +++ b/metricsDatasource.js @@ -1,3 +1,14 @@ +/** + * TypeORM DataSource used only by the TypeORM CLI (e.g. migration:generate). + * + * Migrations at runtime are run from src/services/storage/migrations/runner.ts (allMigrations), + * not from this file. The app never uses this DataSource to run migrations. + * + * Workflow: update the migrations array in this file *before* running + * migration:generate, so TypeORM knows the current schema (entities + existing migrations). + * We do not update this file immediately after adding a new migration; update it when you + * are about to generate the next migration. + */ import { DataSource } from "typeorm" import { BalanceEvent } from "./build/src/services/storage/entity/BalanceEvent.js" import { ChannelBalanceEvent } from "./build/src/services/storage/entity/ChannelsBalanceEvent.js" @@ -11,13 +22,13 @@ import { BalanceEvents1724860966825 } from './build/src/services/storage/migrati import { RootOps1732566440447 } from './build/src/services/storage/migrations/1732566440447-root_ops.js' import { RootOpsTime1745428134124 } from './build/src/services/storage/migrations/1745428134124-root_ops_time.js' import { ChannelEvents1750777346411 } from './build/src/services/storage/migrations/1750777346411-channel_events.js' - +import { RootOpPending1771524665409 } from './build/src/services/storage/migrations/1771524665409-root_op_pending.js' export default new DataSource({ type: "better-sqlite3", database: "metrics.sqlite", entities: [BalanceEvent, ChannelBalanceEvent, ChannelRouting, RootOperation, ChannelEvent], migrations: [LndMetrics1703170330183, ChannelRouting1709316653538, HtlcCount1724266887195, BalanceEvents1724860966825, - RootOps1732566440447, RootOpsTime1745428134124, ChannelEvents1750777346411] + RootOps1732566440447, RootOpsTime1745428134124, ChannelEvents1750777346411, RootOpPending1771524665409] }); //npx typeorm migration:generate ./src/services/storage/migrations/root_op_pending -d ./metricsDatasource.js \ No newline at end of file diff --git a/src/services/main/watchdog.ts b/src/services/main/watchdog.ts index b02b9678..d9d585ba 100644 --- a/src/services/main/watchdog.ts +++ b/src/services/main/watchdog.ts @@ -98,12 +98,17 @@ export class Watchdog { let pendingChange = 0 const pendingChainPayments = await this.storage.metricsStorage.GetPendingChainPayments() for (const payment of pendingChainPayments) { - const tx = await this.lnd.GetTx(payment.operation_identifier) - if (tx.numConfirmations > 0) { - await this.storage.metricsStorage.SetRootOpConfirmed(payment.serial_id) - continue + try { + const tx = await this.lnd.GetTx(payment.operation_identifier) + if (tx.numConfirmations > 0) { + await this.storage.metricsStorage.SetRootOpConfirmed(payment.serial_id) + continue + } + tx.outputDetails.forEach(o => pendingChange += o.isOurAddress ? Number(o.amount) : 0) + } catch (err: any) { + this.log("Error getting tx for root operation", err.message || err) } - tx.outputDetails.forEach(o => pendingChange += o.isOurAddress ? Number(o.amount) : 0) + } let newReceived = 0 let newSpent = 0