Rescan unresolved LN channel force closes

This commit is contained in:
Mononaut
2022-11-02 16:45:19 -06:00
committed by mononaut
parent 18142538f8
commit 369b6f55d3
3 changed files with 31 additions and 3 deletions

View File

@@ -309,7 +309,7 @@ class NetworkSyncService {
└──────────────────┘
*/
private async $runClosedChannelsForensics(): Promise<void> {
private async $runClosedChannelsForensics(skipUnresolved: boolean = false): Promise<void> {
if (!config.ESPLORA.REST_API_URL) {
return;
}
@@ -318,9 +318,18 @@ class NetworkSyncService {
try {
logger.info(`Started running closed channel forensics...`);
const channels = await channelsApi.$getClosedChannelsWithoutReason();
let channels;
const closedChannels = await channelsApi.$getClosedChannelsWithoutReason();
if (skipUnresolved) {
channels = closedChannels;
} else {
const unresolvedChannels = await channelsApi.$getUnresolvedClosedChannels();
channels = [...closedChannels, ...unresolvedChannels];
}
for (const channel of channels) {
let reason = 0;
let resolvedForceClose = false;
// Only Esplora backend can retrieve spent transaction outputs
try {
let outspends: IEsploraApi.Outspend[] | undefined;
@@ -350,6 +359,7 @@ class NetworkSyncService {
reason = 3;
} else {
reason = 2;
resolvedForceClose = true;
}
} else {
/*
@@ -374,6 +384,9 @@ class NetworkSyncService {
if (reason) {
logger.debug('Setting closing reason ' + reason + ' for channel: ' + channel.id + '.');
await DB.query(`UPDATE channels SET closing_reason = ? WHERE id = ?`, [reason, channel.id]);
if (reason === 2 && resolvedForceClose) {
await DB.query(`UPDATE channels SET closing_resolved = ? WHERE id = ?`, [true, channel.id]);
}
}
} catch (e) {
logger.err(`$runClosedChannelsForensics() failed for channel ${channel.short_id}. Reason: ${e instanceof Error ? e.message : e}`);