Skip to content
This repository was archived by the owner on Feb 9, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions lib/ios/Classes/LdkChannelManagerPersister.swift
Original file line number Diff line number Diff line change
Expand Up @@ -244,17 +244,19 @@ class LdkChannelManagerPersister: Persister, ExtendedChannelManagerPersister {
}

override func persistScorer(scorer: WriteableScore) -> Bindings.Result_NoneErrorZ {
guard let scorerStorage = Ldk.accountStoragePath?.appendingPathComponent(LdkFileNames.scorer.rawValue) else {
return Result_NoneErrorZ.initWithErr(e: .Other)
}

do {
try Data(scorer.write()).write(to: scorerStorage)

return Result_NoneErrorZ.initWithOk()
} catch {
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Error. Failed to persist scorer to disk Error \(error.localizedDescription).")
return Result_NoneErrorZ.initWithErr(e: .Other)
}
return Result_NoneErrorZ.initWithOk()

// guard let scorerStorage = Ldk.accountStoragePath?.appendingPathComponent(LdkFileNames.scorer.rawValue) else {
// return Result_NoneErrorZ.initWithErr(e: .Other)
// }
//
// do {
// try Data(scorer.write()).write(to: scorerStorage)
//
// return Result_NoneErrorZ.initWithOk()
// } catch {
// LdkEventEmitter.shared.send(withEvent: .native_log, body: "Error. Failed to persist scorer to disk Error \(error.localizedDescription).")
// return Result_NoneErrorZ.initWithErr(e: .Other)
// }
}
}
39 changes: 21 additions & 18 deletions lib/ios/Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,28 @@ func currencyString(_ currency: Currency) -> String {
func getProbabilisticScorer(path: URL, networkGraph: NetworkGraph, logger: LdkLogger) -> ProbabilisticScorer {
let scoringParams = ProbabilisticScoringParameters.initWithDefault()

var probabalisticScorer: ProbabilisticScorer?
if let storedScorer = try? Data(contentsOf: path.appendingPathComponent(LdkFileNames.scorer.rawValue).standardizedFileURL) {
let scorerRead = ProbabilisticScorer.read(ser: [UInt8](storedScorer), argA: scoringParams, argB: networkGraph, argC: logger)

if scorerRead.isOk() {
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Loaded scorer from disk")
probabalisticScorer = scorerRead.getValue()
} else {
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Failed to load cached scorer")
}
}

//Doesn't exist or error reading it
if probabalisticScorer == nil {
LdkEventEmitter.shared.send(withEvent: .native_log, body: "Starting scorer from scratch")
probabalisticScorer = ProbabilisticScorer(params: scoringParams, networkGraph: networkGraph, logger: logger)
}
//TODO remove below line and uncomment below to enable reading cached scorer again
return ProbabilisticScorer(params: scoringParams, networkGraph: networkGraph, logger: logger)

return probabalisticScorer!
// var probabalisticScorer: ProbabilisticScorer?
// if let storedScorer = try? Data(contentsOf: path.appendingPathComponent(LdkFileNames.scorer.rawValue).standardizedFileURL) {
// let scorerRead = ProbabilisticScorer.read(ser: [UInt8](storedScorer), argA: scoringParams, argB: networkGraph, argC: logger)
//
// if scorerRead.isOk() {
// LdkEventEmitter.shared.send(withEvent: .native_log, body: "Loaded scorer from disk")
// probabalisticScorer = scorerRead.getValue()
// } else {
// LdkEventEmitter.shared.send(withEvent: .native_log, body: "Failed to load cached scorer")
// }
// }
//
// //Doesn't exist or error reading it
// if probabalisticScorer == nil {
// LdkEventEmitter.shared.send(withEvent: .native_log, body: "Starting scorer from scratch")
// probabalisticScorer = ProbabilisticScorer(params: scoringParams, networkGraph: networkGraph, logger: logger)
// }
//
// return probabalisticScorer!
}

extension Invoice {
Expand Down