Skip to content

Commit c15e582

Browse files
committed
feat: add resetScores devtools command
1 parent 7948a5b commit c15e582

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

app/src/debug/java/to/bitkit/dev/DevToolsProvider.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ private sealed interface DevCommand {
6464
ProbeInvoice.METHOD -> ProbeInvoice.parse(arg)
6565
ProbeNode.METHOD -> ProbeNode.parse(arg)
6666
ProbeReadiness.METHOD -> ProbeReadiness
67+
ResetScores.METHOD -> ResetScores
6768
else -> null
6869
}
6970
}
@@ -172,6 +173,21 @@ private sealed interface DevCommand {
172173
override suspend fun execute(deps: DevToolsProvider.Dependencies): DevResult =
173174
DevResult.ProbeReadiness.from(deps.lightningRepo().probeReadiness())
174175
}
176+
177+
data object ResetScores : DevCommand {
178+
const val METHOD = "resetScores"
179+
180+
override suspend fun execute(deps: DevToolsProvider.Dependencies): DevResult {
181+
Logger.info("Resetting pathfinding scores via devtools", context = TAG)
182+
return deps.lightningRepo().resetPathfindingScores().fold(
183+
onSuccess = { DevResult.Ack() },
184+
onFailure = {
185+
Logger.error("Failed to reset pathfinding scores", it, context = TAG)
186+
DevResult.Error(it.message)
187+
},
188+
)
189+
}
190+
}
175191
}
176192

177193
@Serializable
@@ -183,6 +199,8 @@ private sealed interface DevResult {
183199

184200
@Serializable data class Invoice(val bolt11: String) : DevResult
185201

202+
@Serializable data class Ack(val success: Boolean = true) : DevResult
203+
186204
@Serializable
187205
data class ProbeSuccess(
188206
val success: Boolean = true,
@@ -224,6 +242,7 @@ private sealed interface DevResult {
224242
val graphNodeCount: Int? = null,
225243
val graphChannelCount: Int? = null,
226244
val latestRgsSyncTimestamp: ULong? = null,
245+
val latestPathfindingScoresSyncTimestamp: ULong? = null,
227246
) : DevResult {
228247
companion object {
229248
fun from(readiness: NodeProbeReadiness) = ProbeReadiness(
@@ -241,6 +260,7 @@ private sealed interface DevResult {
241260
graphNodeCount = readiness.graphNodeCount,
242261
graphChannelCount = readiness.graphChannelCount,
243262
latestRgsSyncTimestamp = readiness.latestRgsSyncTimestamp,
263+
latestPathfindingScoresSyncTimestamp = readiness.latestPathfindingScoresSyncTimestamp,
244264
)
245265
}
246266
}

app/src/main/java/to/bitkit/repositories/LightningRepo.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,9 +1620,34 @@ class LightningRepo @Inject constructor(
16201620
graphNodeCount = graph?.nodeCount,
16211621
graphChannelCount = graph?.channelCount,
16221622
latestRgsSyncTimestamp = graph?.latestRgsSyncTimestamp,
1623+
latestPathfindingScoresSyncTimestamp = state.nodeStatus?.latestPathfindingScoresSyncTimestamp,
16231624
syncHealthy = state.isSyncHealthy,
16241625
)
16251626
}
1627+
1628+
suspend fun resetPathfindingScores(walletIndex: Int = 0): Result<Unit> = withContext(bgDispatcher) {
1629+
Logger.info("Resetting pathfinding scores", context = TAG)
1630+
1631+
waitForNodeToStop().onFailure { return@withContext Result.failure(it) }
1632+
stop().onFailure {
1633+
Logger.error("Failed to stop node during pathfinding scores reset", it, context = TAG)
1634+
return@withContext Result.failure(it)
1635+
}
1636+
1637+
runCatching {
1638+
vssBackupClientLdk.setup(walletIndex).getOrThrow()
1639+
vssBackupClientLdk.deleteObject(VSS_KEY_SCORER).getOrThrow()
1640+
vssBackupClientLdk.deleteObject(VSS_KEY_EXTERNAL_SCORES_CACHE).getOrThrow()
1641+
}.onFailure {
1642+
Logger.error("Failed to delete pathfinding scores from VSS", it, context = TAG)
1643+
start(walletIndex = walletIndex, shouldRetry = false)
1644+
return@withContext Result.failure(it)
1645+
}
1646+
1647+
start(walletIndex = walletIndex, shouldRetry = false).onSuccess {
1648+
Logger.info("Pathfinding scores reset", context = TAG)
1649+
}
1650+
}
16261651
// endregion
16271652

16281653
suspend fun restartNode(): Result<Unit> = withContext(bgDispatcher) {
@@ -1642,6 +1667,8 @@ class LightningRepo @Inject constructor(
16421667
companion object {
16431668
private const val TAG = "LightningRepo"
16441669
private const val LENGTH_CHANNEL_ID_PREVIEW = 10
1670+
private const val VSS_KEY_SCORER = "scorer"
1671+
private const val VSS_KEY_EXTERNAL_SCORES_CACHE = "external_pathfinding_scores_cache"
16451672
private const val MS_SYNC_LOOP_DEBOUNCE = 500L
16461673
private const val SYNC_RETRY_DELAY_MS = 15_000L
16471674
private val CHANNELS_USABLE_TIMEOUT = 15.seconds
@@ -1702,6 +1729,7 @@ data class ProbeReadiness(
17021729
val graphNodeCount: Int?,
17031730
val graphChannelCount: Int?,
17041731
val latestRgsSyncTimestamp: ULong?,
1732+
val latestPathfindingScoresSyncTimestamp: ULong?,
17051733
val syncHealthy: Boolean,
17061734
) {
17071735
val ready: Boolean

0 commit comments

Comments
 (0)