Skip to content

Commit cffcd73

Browse files
committed
Fix comments
1 parent aadc31e commit cffcd73

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

app/src/main/java/to/bitkit/services/LightningService.kt

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import to.bitkit.utils.LdkError
5151
import to.bitkit.utils.LdkLogWriter
5252
import to.bitkit.utils.Logger
5353
import to.bitkit.utils.ServiceError
54+
import java.util.concurrent.ConcurrentHashMap
5455
import javax.inject.Inject
5556
import javax.inject.Singleton
5657
import kotlin.io.path.Path
@@ -73,7 +74,7 @@ class LightningService @Inject constructor(
7374

7475
private lateinit var trustedPeers: List<PeerDetails>
7576

76-
private val channelCache = mutableMapOf<String, ChannelDetails>()
77+
private val channelCache = ConcurrentHashMap<String, ChannelDetails>()
7778

7879
suspend fun setup(
7980
walletIndex: Int,
@@ -250,9 +251,7 @@ class LightningService @Inject constructor(
250251
private suspend fun registerClosedChannel(channelId: String, reason: String?) {
251252
try {
252253
val channel = ServiceQueue.LDK.background {
253-
channelCache[channelId]?.also {
254-
channelCache.remove(channelId)
255-
}
254+
channelCache[channelId]
256255
} ?: run {
257256
Logger.error(
258257
"Could not find channel details for closed channel: channelId=$channelId",
@@ -261,15 +260,18 @@ class LightningService @Inject constructor(
261260
return@registerClosedChannel
262261
}
263262

264-
val channelName = channel.inboundScidAlias?.toString()
265-
?: channel.channelId.take(10) + ""
266-
267263
val fundingTxo = channel.fundingTxo
268264
if (fundingTxo == null) {
269-
Logger.error("Channel has no funding transaction", context = TAG)
270-
return
265+
Logger.error(
266+
"Channel has no funding transaction, cannot persist closed channel: channelId=$channelId",
267+
context = TAG
268+
)
269+
return@registerClosedChannel
271270
}
272271

272+
val channelName = channel.inboundScidAlias?.toString()
273+
?: channel.channelId.take(CHANNEL_ID_PREVIEW_LENGTH) + ""
274+
273275
val closedAt = (System.currentTimeMillis() / 1000L).toULong()
274276

275277
val closedChannel = ClosedChannelDetails(
@@ -286,12 +288,17 @@ class LightningService @Inject constructor(
286288
forwardingFeeProportionalMillionths = channel.config.forwardingFeeProportionalMillionths,
287289
forwardingFeeBaseMsat = channel.config.forwardingFeeBaseMsat,
288290
channelName = channelName,
289-
channelClosureReason = reason ?: ""
291+
channelClosureReason = reason.orEmpty()
290292
)
291293

292294
ServiceQueue.CORE.background {
293295
upsertClosedChannel(closedChannel)
294296
}
297+
298+
ServiceQueue.LDK.background {
299+
channelCache.remove(channelId)
300+
}
301+
295302
Logger.info("Registered closed channel: ${channel.userChannelId}", context = TAG)
296303
} catch (e: Exception) {
297304
Logger.error("Failed to register closed channel: $e", e, context = TAG)
@@ -860,6 +867,7 @@ class LightningService @Inject constructor(
860867

861868
companion object {
862869
private const val TAG = "LightningService"
870+
private const val CHANNEL_ID_PREVIEW_LENGTH = 10
863871
}
864872
}
865873

app/src/main/java/to/bitkit/ui/settings/lightning/LightningConnectionsScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ private fun Content(
198198
Caption13Up(stringResource(R.string.lightning__conn_closed), color = Colors.White64)
199199
ChannelList(
200200
status = ChannelStatusUi.CLOSED,
201-
channels = uiState.closedChannels.reversed(),
201+
channels = uiState.closedChannels,
202202
onClickChannel = onClickChannel,
203203
)
204204
}

app/src/main/java/to/bitkit/ui/settings/lightning/LightningConnectionsViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class LightningConnectionsViewModel @Inject constructor(
8686
closedChannel.toChannelUi(
8787
baseIndex = openChannels.size + pendingConnections.size + index
8888
)
89-
}
89+
}.reversed()
9090
)
9191
}
9292
}

0 commit comments

Comments
 (0)