Skip to content
Draft
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
1 change: 0 additions & 1 deletion app/src/main/java/to/bitkit/env/Env.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ internal object Env {
val ldkScorerUrl
get() = when (network) {
Network.BITCOIN -> "https://api.blocktank.to/scorer-prod"
Network.REGTEST -> "https://api.stag0.blocktank.to/scorer"
else -> null
}

Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/to/bitkit/repositories/LightningRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,11 @@ class LightningRepo @Inject constructor(
executeWhenNodeRunning("exportNetworkGraphToFile") {
lightningService.exportNetworkGraphToFile(outputDir)
}

suspend fun exportPathfindingScoresToFile(outputDir: String): Result<File> =
executeWhenNodeRunning("exportPathfindingScoresToFile") {
lightningService.exportPathfindingScoresToFile(outputDir)
}
// endregion

// region probing
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/to/bitkit/services/LightningService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,14 @@ class LightningService @Inject constructor(
return loggerLdk.exportNetworkGraphToFile(node, outputDir, fileName)
}

suspend fun exportPathfindingScoresToFile(
outputDir: String,
fileName: String = "pathfinding_scores.bin",
): Result<File> {
val node = this.node ?: return Result.failure(ServiceError.NodeNotSetup())
return loggerLdk.exportPathfindingScoresToFile(node, outputDir, fileName)
}

// endregion
}

Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/to/bitkit/ui/screens/settings/LdkDebugScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ fun LdkDebugScreen(
onPasteAndAddPeer = viewModel::pasteAndAddPeer,
onLogNetworkGraphInfo = viewModel::logNetworkGraphInfo,
onExportNetworkGraph = viewModel::exportNetworkGraph,
onExportScorer = viewModel::exportScorer,
onRestartNode = viewModel::restartNode,
)
}
Expand All @@ -70,6 +71,7 @@ private fun LdkDebugContent(
onPasteAndAddPeer: () -> Unit,
onLogNetworkGraphInfo: () -> Unit,
onExportNetworkGraph: (onFileReady: (File) -> Unit) -> Unit,
onExportScorer: (onFileReady: (File) -> Unit) -> Unit,
onRestartNode: () -> Unit,
) {
val context = LocalContext.current
Expand Down Expand Up @@ -143,6 +145,20 @@ private fun LdkDebugContent(
},
)

SectionHeader("PATHFINDING SCORER")
SettingsTextButtonRow(
title = "Export Scorer",
iconRes = R.drawable.ic_share,
iconSize = 24.dp,
enabled = !uiState.isLoading,
onClick = {
onExportScorer { file ->
val uri = FileProvider.getUriForFile(context, Env.FILE_PROVIDER_AUTHORITY, file)
context.shareFile(uri, "application/octet-stream")
}
},
)

SectionHeader("NODE")
SettingsTextButtonRow(
title = "Restart",
Expand Down Expand Up @@ -171,6 +187,7 @@ private fun Preview() {
onPasteAndAddPeer = {},
onLogNetworkGraphInfo = {},
onExportNetworkGraph = {},
onExportScorer = {},
onRestartNode = {},
)
}
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/to/bitkit/utils/LoggerLdk.kt
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,25 @@ class LoggerLdk @Inject constructor(
Logger.error("Failed to export network graph to file", it, context = TAG)
}
}

suspend fun exportPathfindingScoresToFile(
node: Node,
outputDir: String,
fileName: String = "pathfinding_scores.bin",
): Result<File> = withContext(ioDispatcher) {
runCatching {
val bytes = node.exportPathfindingScores()
val outputFile = File(outputDir, fileName)
outputFile.writeBytes(bytes)
Logger.info(
"Exported pathfinding scores '${bytes.size}' bytes to '${outputFile.absolutePath}'",
context = TAG,
)
outputFile
}.onFailure {
Logger.error("Failed to export pathfinding scores to file", it, context = TAG)
}
}
}

class LdkLogWriter(
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/java/to/bitkit/viewmodels/LdkDebugViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,32 @@ class LdkDebugViewModel @Inject constructor(
}
}

fun exportScorer(onFileReady: (File) -> Unit) {
viewModelScope.launch(bgDispatcher) {
_uiState.update { it.copy(isLoading = true) }
val outputDir = File(context.cacheDir, DIR_EXPORTS).apply { mkdirs() }.absolutePath
lightningRepo.exportPathfindingScoresToFile(outputDir).onSuccess { file ->
Logger.info(
"Pathfinding scores exported to '${file.absolutePath}' (${file.length()} bytes)",
context = TAG,
)
ToastEventBus.send(
type = Toast.ToastType.INFO,
title = "Scorer exported (${file.length()} bytes)",
)
onFileReady(file)
}.onFailure { e ->
Logger.error("Failed to export pathfinding scores", e, context = TAG)
ToastEventBus.send(
type = Toast.ToastType.ERROR,
title = "Failed to export scorer",
description = e.message,
)
}
_uiState.update { it.copy(isLoading = false) }
}
}

fun restartNode() {
viewModelScope.launch(bgDispatcher) {
_uiState.update { it.copy(isLoading = true) }
Expand Down
Loading