-
Notifications
You must be signed in to change notification settings - Fork 0
fix: LightningNodeService startup #478
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
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as resolved.
This comment was marked as resolved.
…into fix/foreground-server-starting
This comment was marked as duplicate.
This comment was marked as duplicate.
|
on draft to check behavior of when disable notifications after previously enabled |
PR Review: Fix LightningNodeService startupSummaryThis PR improves the ✅ Strengths
🐛 Potential Issues1. Race Condition in MainActivity:91-108Location: LaunchedEffect(
walletExists,
isRecoveryMode,
notificationsGranted
) {
if (walletExists && !isRecoveryMode && notificationsGranted) {
tryStartForegroundService()
}
}Issue: The Recommendation: Consider initializing with the actual wallet state: val walletExists by walletViewModel.walletState
.map { it.walletExists }
.collectAsStateWithLifecycle(initialValue = walletViewModel.walletExists)2. Missing Service Stop Logic in ContentViewLocation: The
Recommendation: Consider stopping the service explicitly or document why this is intentional. 3. Redundant Try-Catch in onDestroyLocation: override fun onDestroy() {
super.onDestroy()
if (!settingsViewModel.notificationsGranted.value) {
runCatching {
stopService(Intent(this, LightningNodeService::class.java))
}
}
}Issue: The Recommendation: At minimum log the error: runCatching {
stopService(Intent(this, LightningNodeService::class.java))
}.onFailure { error ->
Logger.error("Failed to stop LightningNodeService", error, context = "MainActivity")
}4. Removed Error Handling in ContentView:202-204Location: Before: try {
walletViewModel.start()
} catch (e: Throwable) {
Logger.error("Failed to start wallet", e)
}After: if (walletExists && !isRecoveryMode) {
walletViewModel.start()
}Issue: The try-catch block was removed, but errors can still occur in Recommendation: Keep defensive error handling at the UI layer or document why it's safe to remove. 🔒 Security Considerations✅ No security concerns identified. The service start conditions appropriately check permissions and wallet state. ⚡ Performance Considerations
🧪 Test Coverage
📝 Code Quality & StyleMinor Issues:
🎯 RecommendationsHigh Priority:
Medium Priority: Low Priority: ✨ Overall AssessmentThis is a solid improvement that addresses a real issue with clear benefits. The main concerns are around edge cases and error handling rather than fundamental design issues. With the recommended fixes, this would be production-ready. Recommendation: Approve with minor changes requested. Review generated by Claude Code |
Code Review - PR #478: Fix LightningNodeService startupSummaryThis PR improves the LightningNodeService startup logic by ensuring it only starts when appropriate conditions are met (wallet exists, notifications enabled, not in recovery mode). The implementation looks solid overall, but I've identified several areas for improvement. ✅ Strengths
🔴 Critical Issues1. Removed Error Handling in ContentView.kt:202-203Location: The original try-catch block around // Before
try {
walletViewModel.start()
} catch (e: Throwable) {
Logger.error("Failed to start wallet", e)
}
// After
if (walletExists && !isRecoveryMode) {
walletViewModel.start()
}Issue: While Recommendation: Wrap the call in a if (walletExists && !isRecoveryMode) {
runCatching {
walletViewModel.start()
}.onFailure { error ->
Logger.error("Failed to start wallet in ON_START", error)
}
}
|
Code Review for PR #478OverviewThis PR improves the LightningNodeService startup logic by adding proper conditions to ensure the service only starts when appropriate (wallet exists, notifications enabled, not in recovery mode). Overall, this is a solid improvement to the service lifecycle management. ✅ Strengths
🐛 Potential Issues & Concerns1. Critical: Race Condition in MainActivity.kt:91-107val walletExists by walletViewModel.walletState
.map { it.walletExists }
.collectAsStateWithLifecycle(initialValue = walletViewModel.walletExists)
LaunchedEffect(
walletExists,
isRecoveryMode,
notificationsGranted
) {
if (walletExists && !isRecoveryMode && notificationsGranted) {
tryStartForegroundService()
}
}Issue: The Recommendation: Add logic to track whether the service is already running or use a more idempotent approach. 2. Service Lifecycle Issue in ContentView.kt:216-222Lifecycle.Event.ON_STOP -> {
if (walletExists && !isRecoveryMode && !notificationsGranted) {
walletViewModel.stop()
}
}Issue: This stops the node when backgrounded without notifications, but the service itself continues running. In Recommendation: Consider synchronizing the service state with the node state more consistently. 3. Removed Try-Catch in ContentView.kt:202-204// Old code:
try {
walletViewModel.start()
} catch (e: Throwable) {
Logger.error("Failed to start wallet", e)
}
// New code:
if (walletExists && !isRecoveryMode) {
walletViewModel.start()
}Issue: The explicit error handling was removed. While Recommendation: Consider keeping the try-catch or ensure error handling in 4. Typo in PR TitleThe PR title says "LightningNodeServic startup" - missing the "e" at the end. 🔒 Security Considerations
⚡ Performance Considerations
🧪 Test CoverageMissing tests for:
Recommendation: Add integration tests for 📝 Minor Code Quality Suggestions
// Could be more concise:
data class NodeServiceState(
val walletExists: Boolean,
val isRecoveryMode: Boolean,
val notificationsGranted: Boolean
)
if (!settingsViewModel.notificationsGranted.value) {This is synchronous access to a Flow. Consider using a collected value instead to avoid potential timing issues.
fun stop() {
if (!walletExists) returnThis is consistent with 🎯 Recommendations SummaryMust Fix:
Should Fix:
Nice to Have:
Overall AssessmentThis is a good improvement that addresses a real problem. The code is generally well-structured and improves battery life by preventing unnecessary service execution. However, the race condition issue should be addressed before merging, and test coverage should be added to prevent regressions. Recommendation: Request changes for the race condition fix, then approve. 🤖 Generated with Claude Code |
PR Review: Fix LightningNodeService StartupSummaryThis PR successfully addresses issue #134 by improving the LightningNodeService startup logic to only run when appropriate conditions are met (wallet exists, notifications enabled, not in recovery mode). The implementation is well-structured and addresses the core issue effectively. Code Quality & Best Practices ✅Strengths:
Minor Suggestions:
// These states control Lightning service lifecycle
val walletUiState by walletViewModel.walletState.collectAsStateWithLifecycle()
val lightningState by walletViewModel.lightningState.collectAsStateWithLifecycle()
Potential Issues
|
ovitrif
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.
tAck
Closes #134
Description
This PR improves the LightningNodeService startup. Now it is only called if the wallet exists, notifications are enabled and the app is not in recovery mode
Preview
recovery_mode.webm
create_allow_notifications.webm
node_working_without_service.webm
create_dont_allow.webm
QA Notes
Note: Notification permission is only required for API 33+