Skip to content

Commit aa495a6

Browse files
committed
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.
1 parent 8bfa8ec commit aa495a6

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

bindings/ldk_node.udl

+2
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ interface Node {
126126
NetworkGraph network_graph();
127127
string sign_message([ByRef]sequence<u8> msg);
128128
boolean verify_signature([ByRef]sequence<u8> msg, [ByRef]string sig, [ByRef]PublicKey pkey);
129+
[Throws=NodeError]
130+
bytes export_pathfinding_scores();
129131
};
130132

131133
[Enum]

src/lib.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,25 @@ impl Node {
15091509
pub fn verify_signature(&self, msg: &[u8], sig: &str, pkey: &PublicKey) -> bool {
15101510
self.keys_manager.verify_signature(msg, sig, pkey)
15111511
}
1512+
1513+
/// Exports the current state of the scorer. The result can be shared with and merged by light nodes that only have
1514+
/// a limited view of the network.
1515+
pub fn export_pathfinding_scores(&self) -> Result<Vec<u8>, Error> {
1516+
self.kv_store
1517+
.read(
1518+
lightning::util::persist::SCORER_PERSISTENCE_PRIMARY_NAMESPACE,
1519+
lightning::util::persist::SCORER_PERSISTENCE_SECONDARY_NAMESPACE,
1520+
lightning::util::persist::SCORER_PERSISTENCE_KEY,
1521+
)
1522+
.map_err(|e| {
1523+
log_error!(
1524+
self.logger,
1525+
"Failed to access store while exporting pathfinding scores: {}",
1526+
e
1527+
);
1528+
Error::PersistenceFailed
1529+
})
1530+
}
15121531
}
15131532

15141533
impl Drop for Node {

0 commit comments

Comments
 (0)