projects
/
ldk-sample
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
cdd0111
)
Use new `ProbabilisticScorer` instead of the deprecated `Scorer`
2022-03-0.0.105
author
Matt Corallo
<git@bluematt.me>
Mon, 7 Mar 2022 18:49:23 +0000
(18:49 +0000)
committer
Matt Corallo
<git@bluematt.me>
Mon, 7 Mar 2022 19:51:41 +0000
(19:51 +0000)
src/disk.rs
patch
|
blob
|
history
src/main.rs
patch
|
blob
|
history
diff --git
a/src/disk.rs
b/src/disk.rs
index b019626440b6e80e9703d4e5de87d57658cd055a..af565bc5b8afac37e05c43bb2e6f2ce855800f47 100644
(file)
--- a/
src/disk.rs
+++ b/
src/disk.rs
@@
-3,15
+3,16
@@
use bitcoin::secp256k1::key::PublicKey;
use bitcoin::BlockHash;
use chrono::Utc;
use lightning::routing::network_graph::NetworkGraph;
use bitcoin::BlockHash;
use chrono::Utc;
use lightning::routing::network_graph::NetworkGraph;
-use lightning::routing::scoring::
Scorer
;
+use lightning::routing::scoring::
{ProbabilisticScorer, ProbabilisticScoringParameters}
;
use lightning::util::logger::{Logger, Record};
use lightning::util::logger::{Logger, Record};
-use lightning::util::ser::{Readable, Writeable, Writer};
+use lightning::util::ser::{Readable,
ReadableArgs,
Writeable, Writer};
use std::collections::HashMap;
use std::fs;
use std::fs::File;
use std::io::{BufRead, BufReader, BufWriter};
use std::net::SocketAddr;
use std::path::Path;
use std::collections::HashMap;
use std::fs;
use std::fs::File;
use std::io::{BufRead, BufReader, BufWriter};
use std::net::SocketAddr;
use std::path::Path;
+use std::sync::Arc;
pub(crate) struct FilesystemLogger {
data_dir: String,
pub(crate) struct FilesystemLogger {
data_dir: String,
@@
-94,7
+95,9
@@
pub(crate) fn read_network(path: &Path, genesis_hash: BlockHash) -> NetworkGraph
NetworkGraph::new(genesis_hash)
}
NetworkGraph::new(genesis_hash)
}
-pub(crate) fn persist_scorer(path: &Path, scorer: &Scorer) -> std::io::Result<()> {
+pub(crate) fn persist_scorer(
+ path: &Path, scorer: &ProbabilisticScorer<Arc<NetworkGraph>>,
+) -> std::io::Result<()> {
let mut tmp_path = path.to_path_buf().into_os_string();
tmp_path.push(".tmp");
let file = fs::OpenOptions::new().write(true).create(true).open(&tmp_path)?;
let mut tmp_path = path.to_path_buf().into_os_string();
tmp_path.push(".tmp");
let file = fs::OpenOptions::new().write(true).create(true).open(&tmp_path)?;
@@
-107,11
+110,16
@@
pub(crate) fn persist_scorer(path: &Path, scorer: &Scorer) -> std::io::Result<()
}
}
}
}
-pub(crate) fn read_scorer(path: &Path) -> Scorer {
+pub(crate) fn read_scorer(
+ path: &Path, graph: Arc<NetworkGraph>,
+) -> ProbabilisticScorer<Arc<NetworkGraph>> {
+ let params = ProbabilisticScoringParameters::default();
if let Ok(file) = File::open(path) {
if let Ok(file) = File::open(path) {
- if let Ok(scorer) = Scorer::read(&mut BufReader::new(file)) {
+ if let Ok(scorer) =
+ ProbabilisticScorer::read(&mut BufReader::new(file), (params, Arc::clone(&graph)))
+ {
return scorer;
}
}
return scorer;
}
}
-
Scorer::default(
)
+
ProbabilisticScorer::new(params, graph
)
}
}
diff --git
a/src/main.rs
b/src/main.rs
index a974b7684c14a67348cfe946fb54b644f650d565..cdbb178a5f82b64fe3c60ec196176045137badef 100644
(file)
--- a/
src/main.rs
+++ b/
src/main.rs
@@
-25,7
+25,7
@@
use lightning::ln::channelmanager::{
use lightning::ln::peer_handler::{IgnoringMessageHandler, MessageHandler, SimpleArcPeerManager};
use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
use lightning::routing::network_graph::{NetGraphMsgHandler, NetworkGraph};
use lightning::ln::peer_handler::{IgnoringMessageHandler, MessageHandler, SimpleArcPeerManager};
use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
use lightning::routing::network_graph::{NetGraphMsgHandler, NetworkGraph};
-use lightning::routing::scoring::Scorer;
+use lightning::routing::scoring::
Probabilistic
Scorer;
use lightning::util::config::UserConfig;
use lightning::util::events::{Event, PaymentPurpose};
use lightning::util::ser::ReadableArgs;
use lightning::util::config::UserConfig;
use lightning::util::events::{Event, PaymentPurpose};
use lightning::util::ser::ReadableArgs;
@@
-101,7
+101,7
@@
pub(crate) type ChannelManager =
pub(crate) type InvoicePayer<E> = payment::InvoicePayer<
Arc<ChannelManager>,
Router,
pub(crate) type InvoicePayer<E> = payment::InvoicePayer<
Arc<ChannelManager>,
Router,
- Arc<Mutex<
Scorer
>>,
+ Arc<Mutex<
ProbabilisticScorer<Arc<NetworkGraph>>
>>,
Arc<FilesystemLogger>,
E,
>;
Arc<FilesystemLogger>,
E,
>;
@@
-589,9
+589,12
@@
async fn start_ldk() {
));
};
));
};
- // Step 16: Initialize routing Scorer
- let scorer_path = format!("{}/scorer", ldk_data_dir.clone());
- let scorer = Arc::new(Mutex::new(disk::read_scorer(Path::new(&scorer_path))));
+ // Step 16: Initialize routing ProbabilisticScorer
+ let scorer_path = format!("{}/prob_scorer", ldk_data_dir.clone());
+ let scorer = Arc::new(Mutex::new(disk::read_scorer(
+ Path::new(&scorer_path),
+ Arc::clone(&network_graph),
+ )));
let scorer_persist = Arc::clone(&scorer);
tokio::spawn(async move {
let mut interval = tokio::time::interval(Duration::from_secs(600));
let scorer_persist = Arc::clone(&scorer);
tokio::spawn(async move {
let mut interval = tokio::time::interval(Duration::from_secs(600));