From aa495a624fe3de6364868a6dd08e14bb990e3c02 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Wed, 5 Feb 2025 11:55:15 +0100 Subject: [PATCH] Add pathfinding scores export method The exported scores can be shared with light nodes and used to improve pathfinding when only a limited local view on the network is available. --- bindings/ldk_node.udl | 2 ++ src/lib.rs | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/bindings/ldk_node.udl b/bindings/ldk_node.udl index be2befdba..632daa7df 100644 --- a/bindings/ldk_node.udl +++ b/bindings/ldk_node.udl @@ -126,6 +126,8 @@ interface Node { NetworkGraph network_graph(); string sign_message([ByRef]sequence msg); boolean verify_signature([ByRef]sequence msg, [ByRef]string sig, [ByRef]PublicKey pkey); + [Throws=NodeError] + bytes export_pathfinding_scores(); }; [Enum] diff --git a/src/lib.rs b/src/lib.rs index 793ab0d7f..2b292e3f6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1509,6 +1509,25 @@ impl Node { pub fn verify_signature(&self, msg: &[u8], sig: &str, pkey: &PublicKey) -> bool { self.keys_manager.verify_signature(msg, sig, pkey) } + + /// Exports the current state of the scorer. The result can be shared with and merged by light nodes that only have + /// a limited view of the network. + pub fn export_pathfinding_scores(&self) -> Result, Error> { + self.kv_store + .read( + lightning::util::persist::SCORER_PERSISTENCE_PRIMARY_NAMESPACE, + lightning::util::persist::SCORER_PERSISTENCE_SECONDARY_NAMESPACE, + lightning::util::persist::SCORER_PERSISTENCE_KEY, + ) + .map_err(|e| { + log_error!( + self.logger, + "Failed to access store while exporting pathfinding scores: {}", + e + ); + Error::PersistenceFailed + }) + } } impl Drop for Node {