Skip to content

Fix issues #301, #302, #304, #305: robustness and state consistency#345

Merged
gboigwe merged 1 commit intoThinkLikeAFounder:mainfrom
walterthesmart:fix-issues-301-302-304-305
Mar 28, 2026
Merged

Fix issues #301, #302, #304, #305: robustness and state consistency#345
gboigwe merged 1 commit intoThinkLikeAFounder:mainfrom
walterthesmart:fix-issues-301-302-304-305

Conversation

@walterthesmart
Copy link
Copy Markdown
Contributor

Summary

This PR addresses four critical issues across the full stack (Soroban contract, Backend services, and Frontend hooks) to improve system robustness, state consistency, and performance.

Tasks and Fixes

1. Campaign Orchestrator: State Consistency (#305)

  • Problem: The active_campaigns counter in AdvertiserStats was not updated when campaigns were paused, resumed, or naturally completed.
  • Fix:
    • Updated pause_campaign to decrement the active_campaigns count.
    • Updated resume_campaign to increment the active_campaigns count.
    • Enhanced record_view to decrement the count when a campaign transitions to Completed status.
  • File: contracts/campaign-orchestrator/src/lib.rs

2. Frontend: Prevent Infinite Refetch Loops (#304)

  • Problem: useAnalyticsTimeseries hook used an array as a useEffect dependency, causing infinite re-renders and API hammering due to React's reference comparison for arrays.
  • Fix: Serialized campaignIds into a comma-separated string for stable string comparison in the dependency array.
  • File: frontend/src/hooks/useAnalytics.ts

3. Backend: Robust Horizon Stream Handling (#301)

  • Problem: The Horizon ledger stream could die silently on network disconnects or cause unhandled promise rejections.
  • Fix:
    • Refactored streamLedgers service to include built-in reconnection logic with exponential backoff (starting at 1s, capped at 30s).
    • Simplified websocket-server.ts to offload reconnection management to the service layer while maintaining client notifications.
  • Files: backend/src/services/horizon.ts, backend/src/services/websocket-server.ts

4. Backend: Simulation Account Validation (#302)

  • Problem: Read-only Soroban calls relied on a hardcoded account that wasn't validated, leading to cryptic failures if the account was unfunded or missing on the target network.
  • Fix:
    • Added SIMULATION_ACCOUNT environment variable support with a sensible fallback.
    • Implemented validateSimulationAccount to verify the account's existence on startup (failing hard in production).
    • Documented the new variable in .env.example.
  • Files: backend/src/services/soroban-client.ts, backend/src/index.ts, backend/.env.example

Verification

  • Code changes verified for logic consistency.
  • Lint errors in the environment were noted as pre-existing and unrelated to the specific bug fixes implemented.

Closes #301, #302, #304, #305 (upstream issues)

Summary by CodeRabbit

  • New Features

    • Automatic reconnection mechanism for ledger stream connectivity with exponential backoff.
    • Campaign status tracking now properly updates active campaign counts during completion, pause, and resume operations.
    • Simulation account configuration support.
  • Bug Fixes

    • Fixed analytics data to properly detect campaign ID changes.
  • Chores

    • Added startup validation for simulation account configuration.

Closes #301
Closes #302
Closes #304
Closes #305

…under#304, ThinkLikeAFounder#305: robustness and state consistency

- ThinkLikeAFounder#305: Fix campaign-orchestrator active_campaigns counter on pause/resume/completion
- ThinkLikeAFounder#304: Fix frontend useAnalytics infinite refetch loop by serializing array dependency
- ThinkLikeAFounder#301: Robust Horizon ledger stream with built-in reconnection and exponential backoff
- ThinkLikeAFounder#302: Validate simulation account on backend startup and allow configuration via env
@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 28, 2026

@walterthesmart 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! 🚀

Learn more about application limits

@gboigwe gboigwe merged commit 1a5107b into ThinkLikeAFounder:main Mar 28, 2026
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment