feat: Stellar Network Health Monitoring (#192)#198
Open
Peolite001 wants to merge 1 commit into
Open
Conversation
- Real-time Horizon API health checks with automatic polling - Network status tracking: healthy, degraded, unavailable - SSE endpoint /api/stellar/health for live frontend updates - Outage detection with structured logging and recovery tracking - /api/stellar/health/history for audit/debugging - Responsive UI component with badge, banner, and compact variants - Graceful fallback to polling when SSE unavailable - Unit tests for connectivity checks and error handling - Integrated into chat page banner and header compact indicator Closes Lumina-eX#192
|
@Peolite001 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Collaborator
|
@Peolite001 resolve conflicts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📌 Pull Request
🔗 Related Issue
Closes #192
📝 Description
What does this PR do?
Implements Stellar Network Health Monitoring — a complete real-time monitoring system that checks Horizon API connectivity at regular intervals, tracks network status (healthy/degraded/unavailable), exposes a status endpoint for frontend consumption, logs outages and recovery events, and provides a responsive UI component to display current network status across the application.
Why is this change necessary?
AnonChat relies on the Stellar blockchain for wallet authentication, group creation, and on-chain verification. Users currently have no visibility into network availability. When Stellar is degraded or down, users see confusing failures without context. This PR provides transparency, graceful degradation, and clear messaging so users understand when network issues affect functionality.
🚀 Changes Made
lib/stellar/health-monitor.ts — Core monitoring engine with automatic polling, status classification, outage detection, and structured logging
app/api/stellar/health/route.ts — REST + SSE endpoint for real-time health status
app/api/stellar/health/history/route.ts — Audit endpoint for outage history
components/stellar-network-status.tsx — Reusable UI component (badge / banner / compact variants)
lib/stellar/health-monitor.test.ts — Unit tests for connectivity checks and error handling
app/api/stellar/health/route.test.ts — API route tests
🧪 Testing & Validation
Unconfigured Stellar returns proper unavailable state with clear error message
SSE fallback to polling when stream connection fails
Multiple concurrent subscribers handled safely
Outage start/end/duration accurately tracked and logged
Component gracefully handles API downtime with retry button
If yes, explain:
N/A — All additions are net-new files and additive integrations. No existing APIs modified.
📋 Contributor Checklist (MANDATORY)
Closes #)💡 Notes for Reviewer
Key areas to review:
lib/stellar/health-monitor.ts — Check the outage detection logic and status transition boundaries (healthy < 2s, degraded 2–5s, unavailable > 5s)
app/api/stellar/health/route.ts — Verify SSE stream cleanup on client disconnect to prevent memory leaks
components/stellar-network-status.tsx — Confirm responsive behavior: compact dot on mobile header, full banner on chat page, details hidden appropriately
Known limitations:
Monitoring starts on first API request (lazy init). If no client ever hits /api/stellar/health, the background poller never starts. This is intentional to avoid unnecessary Horizon load on static pages.
The STELLAR_SOURCE_SECRET env var is required for loadStellarConfig() to succeed, but health checks only need STELLAR_HORIZON_URL and STELLAR_NETWORK. Consider decoupling in a future refactor.
Tests use vitest — ensure npm install -D vitest or equivalent is in the project's dev dependencies before running.