Skip to content

client: resilient oracle subscriptions#14

Merged
martonp merged 6 commits intobisoncraft:masterfrom
dnldd:oracle_client_helpers
Mar 13, 2026
Merged

client: resilient oracle subscriptions#14
martonp merged 6 commits intobisoncraft:masterfrom
dnldd:oracle_client_helpers

Conversation

@dnldd
Copy link
Copy Markdown
Contributor

@dnldd dnldd commented Feb 26, 2026

Add oracle subscription APIs (SubscribeToPriceOracle/SubscribeToFeeRateOracle) with
automatic reconnection handling. Introduce pub-sub ConnectionStateFeed pattern for
efficient multi-subscriber connection tracking. Decouple subscription registration from
wire connectivity—subscriptions persist in registry and sync automatically on reconnect.

  • ConnectionStateFeed: pub-sub pattern replaces blocking WaitForConnection
  • Resilient subscriptions: register locally, persist across reconnects, auto-sync
  • Simplified oracle retry: removed exponential backoff, direct subscription on connection
  • Tests: comprehensive coverage of oracle subscriptions, connection state, and no-connection behavior

Add SubscribeToPriceOracle() and SubscribeToFeeRateOracle() APIs for real-time asset
price and fee rate updates. Test client now accepts configurable OracleTickers list,
with async subscription including exponential backoff retry (100ms-5s), deduplication,
and automatic event streaming to frontend. Comprehensive tests cover success, error,
and redundant subscription cases. Config supports comma-separated tickers: oracle=BTC,DCR
@dnldd dnldd force-pushed the oracle_client_helpers branch from b7b82a4 to a3c3eff Compare February 26, 2026 19:05
@dnldd dnldd mentioned this pull request Feb 26, 2026
Comment thread client/client.go Outdated
Copy link
Copy Markdown
Contributor

@martonp martonp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the test client, we don't need separate oracle clients. Regular clients are the same as oracle clients. I guess we could add a special UI to subscribe to oracles, but I don't think we need that right now.

@dnldd
Copy link
Copy Markdown
Contributor Author

dnldd commented Feb 27, 2026

There isn't an oracle test client currently. It's the same test client with a command option to setup oracle updates for the tickers provided. I thought that would simplify testing with it instead of using the UI to setup the subscriptions.

- Replace one-shot WaitForConnection with pub-sub ConnectionStateFeed API
- Add subscriber registry (subscribe/unsubscribe) to meshConnectionManager
- Implement state change broadcasting to all subscribers via buffered channels
- ConnectionStateFeed returns channel delivering true/false state updates
- Context cancellation unsubscribes and closes subscriber channels
- Updated mesh_connection_manager_test with TestConnectionStateFeed covering all cases
- Updated testing/client to use ConnectionStateFeed for oracle subscriptions
- Non-blocking sends with drop-on-slow-reader semantics ensure consistency
- Multiple concurrent subscribers now supported
…ment

- Subscribe now registers in topic registry before attempting wire call
- Unsubscribe now unregisters from topic registry before attempting wire call
- Both return nil silently when no connection is available (not an error)
- Connection sync happens automatically via openPushStream on reconnect
- Topic registry is source of truth; subscriptions persist across reconnects
- Broadcast unchanged: still requires active connection (has no local state)
- Added tests verifying Subscribe/Unsubscribe succeed without connection
- Simplified testing/client.subscribeToOracles: removed connection-wait loop
- Errors from wire calls still propagate; only missing connection is silent
@dnldd dnldd changed the title client: add configurable oracle subscriptions with frontend integration client: resilient oracle subscriptions Feb 28, 2026
Revert testclient and harness.sh to pre-oracle configuration state.
Simplifies test infrastructure while keeping oracle subscription APIs in client.
@dnldd
Copy link
Copy Markdown
Contributor Author

dnldd commented Feb 28, 2026

For the test client, we don't need separate oracle clients. Regular clients are the same as oracle clients. I guess we could add a special UI to subscribe to oracles, but I don't think we need that right now.

Reverted the test client and harness changes.

Copy link
Copy Markdown
Contributor

@martonp martonp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • setPrimaryConnection is called both in run and attemptConnect, causing double notifications each time. The call in attemptConnect can be removed.

Comment thread client/mesh_connection_manager.go Outdated
Comment thread client/client.go
Comment thread client/client.go
Comment thread client/mesh_connection_manager.go
Comment thread client/oracle.go Outdated
Comment thread client/mesh_connection_manager.go Outdated
Comment thread testing/client/client.go Outdated
- Remove unmarshalOracleData wrapper from oracle.go; use proto.Unmarshal directly
- Remove TestUnmarshalOracleData test from oracle_test.go
- Rename meshConnectionManager.subscribe/unsubscribe to subscribeToConnectionState/unsubscribeFromConnectionState
- Remove connMtx and connChanged from meshConnectionManager; simplify synchronization
- Improve slow subscriber handling: drain full buffer and send latest state
- Update ConnectionStateFeed to return (chan bool, error) for consistency
- Fix Subscribe to not unregister topic on wire failure; retain for reconnect retry
- Fix Unsubscribe to unregister at correct point in flow
- Remove OracleTickers from test client Config; remove subscribeToOracles from testing/client
@dnldd dnldd force-pushed the oracle_client_helpers branch from 0b3f585 to 1add712 Compare March 12, 2026 03:14
Comment thread client/mesh_connection_manager.go
Co-authored-by: Marton <marci93@gmail.com>
@martonp martonp merged commit 3969094 into bisoncraft:master Mar 13, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants