Skip to content

Commit

Permalink
feat: restore encoded channel monitors
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Sep 24, 2024
1 parent eab0e5b commit e863459
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ interface Node {
boolean verify_signature([ByRef]sequence<u8> msg, [ByRef]string sig, [ByRef]PublicKey pkey);
[Throws=NodeError]
sequence<KeyValue> get_encoded_channel_monitors();
[Throws=NodeError]
void restore_encoded_channel_monitors(sequence<KeyValue> monitors);
void force_close_all_channels_without_broadcasting_txn();
};

Expand Down
18 changes: 17 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,6 @@ impl Node {
let mut entries = Vec::new();

for key in keys {
// TODO: error handling
let value = channel_monitor_store.read("monitors", "", &key).map_err(|e| {
log_error!(channel_monitor_logger, "Failed to get monitor value: {}", e);
Error::ConnectionFailed
Expand All @@ -1567,6 +1566,23 @@ impl Node {
return Ok(entries);
}

/// Alby: Restore encoded channel monitors for a recovery of last resort
pub fn restore_encoded_channel_monitors(&self, monitors: Vec<KeyValue>) -> Result<(), Error> {
let channel_monitor_store = Arc::clone(&self.kv_store);
let channel_monitor_logger = Arc::clone(&self.logger);

for monitor in monitors {
channel_monitor_store.write("monitors", "", &monitor.key, &monitor.value).map_err(
|e| {
log_error!(channel_monitor_logger, "Failed to restore monitor: {}", e);
Error::ConnectionFailed
},
)?;
}

return Ok(());
}

/// Retrieves an overview of all known balances.
pub fn list_balances(&self) -> BalanceDetails {
let cur_anchor_reserve_sats =
Expand Down

0 comments on commit e863459

Please sign in to comment.