Skip to content

Commit

Permalink
Merge #942
Browse files Browse the repository at this point in the history
942: fix: read scorer r=holzeis a=bonomat

With this patch we don't read a historically stored scrorer from disk. It's not ideal, but at least users running into panics when loading the scorer will be able to run the app again

Workaround for #797 
fix #797 

Co-authored-by: Philipp Hoenisch <[email protected]>
  • Loading branch information
bors[bot] and bonomat authored Jul 13, 2023
2 parents 71c8237 + b5db6df commit 4f8caaa
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions crates/ln-dlc-node/src/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ use bitcoin::Network;
use lightning::routing::scoring::ProbabilisticScorer;
use lightning::routing::scoring::ProbabilisticScoringParameters;
use lightning::util::ser::ReadableArgs;
use std::fs;
use std::fs::File;
use std::io::BufReader;
use std::panic;
use std::path::Path;
use std::sync::Arc;

Expand All @@ -17,9 +19,21 @@ pub(crate) fn read_scorer(
let params = ProbabilisticScoringParameters::default();
if let Ok(file) = File::open(path) {
let args = (params.clone(), graph.clone(), logger.clone());
match ProbabilisticScorer::read(&mut BufReader::new(file), args) {
Ok(scorer) => return scorer,
Err(e) => tracing::error!("Failed to read scorer from disk: {e}"),
let result =
panic::catch_unwind(|| ProbabilisticScorer::read(&mut BufReader::new(file), args));
match result {
Ok(Ok(scorer)) => {
return scorer;
}
Ok(Err(err)) => {
tracing::error!("Could not decode scorer {err:#}");
}
Err(_) => {
tracing::error!("Reading scorer panicked");
if let Err(err) = fs::remove_file(path) {
tracing::error!("Could not even delete file #{err}");
}
}
}
}
ProbabilisticScorer::new(params, graph, logger)
Expand Down

0 comments on commit 4f8caaa

Please sign in to comment.