Skip to content

Commit

Permalink
Add pathfinding scores export method
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
joostjager committed Feb 6, 2025
1 parent 8bfa8ec commit fb299f0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ interface Node {
NetworkGraph network_graph();
string sign_message([ByRef]sequence<u8> msg);
boolean verify_signature([ByRef]sequence<u8> msg, [ByRef]string sig, [ByRef]PublicKey pkey);
[Throws=NodeError]
bytes export_pathfinding_scores();
};

[Enum]
Expand Down
17 changes: 15 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ mod wallet;
pub use bip39;
pub use bitcoin;
pub use lightning;
pub use lightning_invoice;
pub use lightning_types;
pub use vss_client;

pub use balance::{BalanceDetails, LightningBalance, PendingSweepBalance};
Expand Down Expand Up @@ -1509,6 +1507,21 @@ 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<Vec<u8>, 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 export pathfinding scores: {}", e);
Error::PersistenceFailed
})
}
}

impl Drop for Node {
Expand Down

0 comments on commit fb299f0

Please sign in to comment.