From eab0e5b488062d3339b8a87913ad895b1585dbf7 Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Tue, 24 Sep 2024 11:22:16 +0700 Subject: [PATCH] feat: add force close all channels function, add error handling to get_encoded_channel_monitors --- bindings/ldk_node.udl | 1 + src/lib.rs | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/bindings/ldk_node.udl b/bindings/ldk_node.udl index 8b01e79cd..ca8c12f30 100644 --- a/bindings/ldk_node.udl +++ b/bindings/ldk_node.udl @@ -92,6 +92,7 @@ interface Node { boolean verify_signature([ByRef]sequence msg, [ByRef]string sig, [ByRef]PublicKey pkey); [Throws=NodeError] sequence get_encoded_channel_monitors(); + void force_close_all_channels_without_broadcasting_txn(); }; interface Bolt11Payment { diff --git a/src/lib.rs b/src/lib.rs index 2475828b3..219d21ded 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1539,23 +1539,28 @@ impl Node { self.payment_store.remove(&payment_id) } + /// Alby: Used to recover funds after restoring static channel backup + pub fn force_close_all_channels_without_broadcasting_txn(&self) { + self.channel_manager.force_close_all_channels_without_broadcasting_txn(); + } + /// Alby: Return encoded channel monitors for a recovery of last resort pub fn get_encoded_channel_monitors(&self) -> Result, Error> { let channel_monitor_store = Arc::clone(&self.kv_store); let channel_monitor_logger = Arc::clone(&self.logger); - // TODO: error handling - let keys = channel_monitor_store.list("monitors", "").unwrap_or_else(|e| { + let keys = channel_monitor_store.list("monitors", "").map_err(|e| { log_error!(channel_monitor_logger, "Failed to get monitor keys: {}", e); - return Vec::new(); - }); + Error::ConnectionFailed + })?; + let mut entries = Vec::new(); for key in keys { // TODO: error handling - let value = channel_monitor_store.read("monitors", "", &key).unwrap_or_else(|e| { + let value = channel_monitor_store.read("monitors", "", &key).map_err(|e| { log_error!(channel_monitor_logger, "Failed to get monitor value: {}", e); - return Vec::new(); - }); + Error::ConnectionFailed + })?; entries.push(KeyValue { key, value }) }