From: Matt Corallo Date: Mon, 7 Mar 2022 18:49:23 +0000 (+0000) Subject: Use new `ProbabilisticScorer` instead of the deprecated `Scorer` X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=6f6473bf1bb4a1b2149a9a5c3616c39653dec144;p=ldk-sample Use new `ProbabilisticScorer` instead of the deprecated `Scorer` --- diff --git a/src/disk.rs b/src/disk.rs index b019626..af565bc 100644 --- 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 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, @@ -94,7 +95,9 @@ pub(crate) fn read_network(path: &Path, genesis_hash: BlockHash) -> NetworkGraph 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>, +) -> 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)?; @@ -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, +) -> ProbabilisticScorer> { + 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) } diff --git a/src/main.rs b/src/main.rs index a974b76..cdbb178 100644 --- 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::routing::scoring::Scorer; +use lightning::routing::scoring::ProbabilisticScorer; 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 = payment::InvoicePayer< Arc, Router, - Arc>, + Arc>>>, Arc, 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));