Rescan unresolved LN channel force closes
This commit is contained in:
@@ -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}`);
|
||||
|
||||
Reference in New Issue
Block a user