-
Notifications
You must be signed in to change notification settings - Fork 0
Move closed channels tracking to LightningRepo #474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Code Review - PR #474: Move closed channels tracking to LightningRepoOverviewThis PR refactors closed channel tracking functionality from ✅ Strengths
🔍 Potential Issues & Recommendations1. Thread Safety Concern - Channel Cache UpdatesSeverity: Medium The private suspend fun refreshChannelCache() = withContext(bgDispatcher) {
val channels = lightningService.channels ?: return@withContext
channels.forEach { channel ->
channelCache[channel.channelId] = channel // ← Update
}
}
private fun handleLdkEvent(event: Event) {
when (event) {
is Event.ChannelClosed -> {
scope.launch {
registerClosedChannel(channelId, reason) // ← Read then remove
}
}
}
}Issue:
Recommendation: Make private suspend fun handleLdkEvent(event: Event) = withContext(bgDispatcher) {
when (event) {
is Event.ChannelClosed -> {
registerClosedChannel(channelId, reason)
}
// ...
}
}Then update the call sites to use lightningService.listenForEvents(onEvent = { event ->
scope.launch {
handleLdkEvent(event)
}
eventHandler?.invoke(event)
})2. Race Condition - Channel Closed Before Cache PopulationSeverity: Medium In the lightningService.start(timeout) { event ->
handleLdkEvent(event)
eventHandler?.invoke(event)
ldkNodeEventBus.emit(event)
}
// ...
refreshChannelCache() // ← Called AFTER start completesIssue: If a Recommendation: Call 3. Memory Leak Risk - Unbounded Cache GrowthSeverity: Low-Medium The
Recommendation: Consider adding:
4. Error Recovery - Missing Channel DetailsSeverity: Low When a channel isn't found in the cache, the code logs an error and returns: val channel = channelCache[channelId] ?: run {
Logger.error(
"Could not find channel details for closed channel: channelId=$channelId",
context = TAG
)
return@withContext
}Issue: This silently fails to persist closed channel information, which might be important for user history. Recommendation: Consider attempting to fetch channel details from 5. Exception Handling InconsistencySeverity: Low In the original code (LightningService:758): } catch (e: Exception) {In the new code (LightningRepo:393): } catch (e: Throwable) {Note: Catching 🔒 Security ConsiderationsNo significant security concerns identified. The code:
⚡ Performance Considerations
🧪 Test CoverageConcern: No new tests were added for the refactored functionality. Recommendation: Add unit tests for:
The existing 📋 Additional Notes
SummaryThis is a solid architectural improvement. The main concerns are around thread safety and race conditions with the channel cache. I recommend addressing the concurrency issues before merging to avoid potential bugs in production. Recommendation: Request changes to address the thread safety concerns in points #1 and #2. |
jvsena42
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested:
- Open and close a channel
- Wipe and restore app -> check channels
Addresses #472 (review)