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::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::sync::Arc;
pub(crate) struct FilesystemLogger {
data_dir: String,
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)?;
}
}
-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(scorer) = Scorer::read(&mut BufReader::new(file)) {
+ if let Ok(scorer) =
+ ProbabilisticScorer::read(&mut BufReader::new(file), (params, Arc::clone(&graph)))
+ {
return scorer;
}
}
- Scorer::default()
+ ProbabilisticScorer::new(params, graph)
}
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::ProbabilisticScorer;
use lightning::util::config::UserConfig;
use lightning::util::events::{Event, PaymentPurpose};
use lightning::util::ser::ReadableArgs;
pub(crate) type InvoicePayer<E> = payment::InvoicePayer<
Arc<ChannelManager>,
Router,
- Arc<Mutex<Scorer>>,
+ Arc<Mutex<ProbabilisticScorer<Arc<NetworkGraph>>>>,
Arc<FilesystemLogger>,
E,
>;
));
};
- // 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));