Skip to content

Commit c9b3161

Browse files
authored
fix: tune lightning probe routing (#623)
* fix: tune lightning probe routing * fix: avoid scorer config startup crash
1 parent d2d1e56 commit c9b3161

4 files changed

Lines changed: 45 additions & 5 deletions

File tree

Bitkit/Services/LightningService.swift

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@ class LightningService {
2828

2929
static var shared = LightningService()
3030

31+
private static let scoringBasePenaltyMsat: UInt64 = 50000
32+
private static let scoringLiquidityPenaltyMultiplierMsat: UInt64 = 10000
33+
private static let scoringLiquidityPenaltyAmountMultiplierMsat: UInt64 = 10000
34+
private static let scoringHistoricalLiquidityPenaltyAmountMultiplierMsat: UInt64 = 20000
35+
private static let scoringConsideredImpossiblePenaltyMsat: UInt64 = 1_000_000_000_000
36+
private static let scoringProbingDiversityPenaltyMsat: UInt64 = 60000
37+
38+
private static let defaultScoringFeeParameters = ScoringFeeParameters(
39+
basePenaltyMsat: 1024,
40+
basePenaltyAmountMultiplierMsat: 131_072,
41+
liquidityPenaltyMultiplierMsat: 0,
42+
liquidityPenaltyAmountMultiplierMsat: 0,
43+
historicalLiquidityPenaltyMultiplierMsat: 10000,
44+
historicalLiquidityPenaltyAmountMultiplierMsat: 1250,
45+
antiProbingPenaltyMsat: 250,
46+
consideredImpossiblePenaltyMsat: 100_000_000_000,
47+
linearSuccessProbability: false,
48+
probingDiversityPenaltyMsat: 0
49+
)
50+
3151
private init() {}
3252

3353
/// Flag and lock to prevent concurrent setup calls
@@ -107,6 +127,8 @@ class LightningService {
107127
builder.setPathfindingScoresSource(url: scorerUrl)
108128
}
109129

130+
builder.setScoringFeeParams(params: Self.scoringFeeParameters(config: config))
131+
110132
// Configure gossip source from current settings
111133
configureGossipSource(builder: builder, rgsServerUrl: rgsServerUrl)
112134

@@ -1575,6 +1597,23 @@ extension LightningService {
15751597

15761598
// MARK: - Probing
15771599

1600+
private static func scoringFeeParameters(config: Config) -> ScoringFeeParameters {
1601+
let defaultParameters = config.scoringFeeParams ?? defaultScoringFeeParameters
1602+
1603+
return ScoringFeeParameters(
1604+
basePenaltyMsat: scoringBasePenaltyMsat,
1605+
basePenaltyAmountMultiplierMsat: defaultParameters.basePenaltyAmountMultiplierMsat,
1606+
liquidityPenaltyMultiplierMsat: scoringLiquidityPenaltyMultiplierMsat,
1607+
liquidityPenaltyAmountMultiplierMsat: scoringLiquidityPenaltyAmountMultiplierMsat,
1608+
historicalLiquidityPenaltyMultiplierMsat: defaultParameters.historicalLiquidityPenaltyMultiplierMsat,
1609+
historicalLiquidityPenaltyAmountMultiplierMsat: scoringHistoricalLiquidityPenaltyAmountMultiplierMsat,
1610+
antiProbingPenaltyMsat: defaultParameters.antiProbingPenaltyMsat,
1611+
consideredImpossiblePenaltyMsat: scoringConsideredImpossiblePenaltyMsat,
1612+
linearSuccessProbability: defaultParameters.linearSuccessProbability,
1613+
probingDiversityPenaltyMsat: scoringProbingDiversityPenaltyMsat
1614+
)
1615+
}
1616+
15781617
/// Sends a probe to test if a payment route exists for the given invoice.
15791618
/// - Parameters:
15801619
/// - bolt11: The Lightning invoice string (BOLT 11)

Bitkit/ViewModels/WalletViewModel.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class WalletViewModel: ObservableObject {
195195
success: false,
196196
paymentId: paymentId,
197197
paymentHash: paymentHash,
198-
shortChannelId: shortChannelId,
198+
shortChannelId: shortChannelId.map(String.init),
199199
routeFeeMsat: routeFeeMsat
200200
)
201201
case let .paymentReceived(_, paymentHash, _, _):
@@ -681,7 +681,7 @@ class WalletViewModel: ObservableObject {
681681
let success: Bool
682682
let paymentId: PaymentId
683683
let paymentHash: PaymentHash
684-
let shortChannelId: UInt64?
684+
let shortChannelId: String?
685685
let routeFeeMsat: UInt64?
686686
}
687687

@@ -724,7 +724,7 @@ class WalletViewModel: ObservableObject {
724724
success: false,
725725
paymentId: paymentId,
726726
paymentHash: paymentHash,
727-
shortChannelId: shortChannelId,
727+
shortChannelId: shortChannelId.map(String.init),
728728
routeFeeMsat: routeFeeMsat
729729
)
730730
if pendingPaymentIds.isEmpty, let lastFailure {
@@ -739,7 +739,7 @@ class WalletViewModel: ObservableObject {
739739
}
740740
}
741741

742-
private func cacheProbeOutcome(success: Bool, paymentId: PaymentId, paymentHash: PaymentHash, shortChannelId: UInt64?, routeFeeMsat: UInt64?) {
742+
private func cacheProbeOutcome(success: Bool, paymentId: PaymentId, paymentHash: PaymentHash, shortChannelId: String?, routeFeeMsat: UInt64?) {
743743
probeOutcomes[paymentId] = ProbeOutcome(
744744
success: success,
745745
paymentId: paymentId,

Bitkit/Views/Settings/ProbingTool/ProbingToolScreen.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ struct ProbingToolScreen: View {
259259
}
260260
app.toast(type: .success, title: "Probe Successful", description: "Route verified in \(durationMs) ms")
261261
} else {
262-
let scidText = resolved.shortChannelId.map(String.init) ?? "unknown"
262+
let scidText = resolved.shortChannelId ?? "unknown"
263263
let message = "Hash: \(resolved.paymentHash), SCID: \(scidText)"
264264
await MainActor.run {
265265
probeResult = ProbeResult(

changelog.d/next/623.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improved Lightning payment route selection reliability.

0 commit comments

Comments
 (0)