Skip to content

Commit

Permalink
feat: add force close all channels function, add error handling to ge…
Browse files Browse the repository at this point in the history
…t_encoded_channel_monitors
  • Loading branch information
rolznz committed Sep 24, 2024
1 parent 1514d33 commit eab0e5b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ interface Node {
boolean verify_signature([ByRef]sequence<u8> msg, [ByRef]string sig, [ByRef]PublicKey pkey);
[Throws=NodeError]
sequence<KeyValue> get_encoded_channel_monitors();
void force_close_all_channels_without_broadcasting_txn();
};

interface Bolt11Payment {
Expand Down
19 changes: 12 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<KeyValue>, 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 })
}

Expand Down

0 comments on commit eab0e5b

Please sign in to comment.