Skip to content

feat: expose per-endpoint circuit state for RPC calls - #674

Open
ZacLou wants to merge 2 commits into
conduit-protocol:mainfrom
ZacLou:feat/circuit-state-630
Open

ZacLou wants to merge 2 commits into
conduit-protocol:mainfrom
ZacLou:feat/circuit-state-630

Conversation

@ZacLou

@ZacLou ZacLou commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Addresses #630

Problem

Consumers had no way to check if an RPC endpoint was degraded without catching the thrown 'circuit open' error. There was no read-only state inspection.

Solution

src/rpc-circuit-state.ts (new)

A circuit breaker module with:

  • getCircuitState(scope) — returns { state, failureCount, lastFailureAt, lastSuccessAt, cooldownUntil }. State is 'closed' (healthy), 'open' (degraded, exceeding threshold), or 'half-open' (probing after cooldown).
  • recordSuccess(scope) — resets failure count, closes circuit
  • recordFailure(scope, options?) — increments failure count, opens circuit at threshold (default 5)
  • resetCircuit(scope) — clears all state
  • getAllCircuitStates() — returns all known circuit states for dashboards

src/soroban.ts

The createRpcServer proxy now calls recordSuccess(rpcUrl) on successful calls and recordFailure(rpcUrl) when the retry logic exhausts or hits a non-retriable error.

src/index.ts

Exports getCircuitState, recordSuccess, recordFailure, resetCircuit, getAllCircuitStates, CircuitState, CircuitStatus.

Usage

import { getCircuitState } from '@conduit-protocol/sdk';

const state = getCircuitState(rpcUrl);
if (state.state === 'open') {
  showBanner('RPC endpoint is degraded. Retrying...');
}

Verification

  • Typecheck passes
  • All 989 tests pass (78 test files)

…ol#630)

Adds a circuit breaker that tracks consecutive failures per RPC URL.
Consumers can call getCircuitState(rpcUrl) to check if the endpoint is
'closed' (healthy), 'open' (degraded), or 'half-open' (probing) without
catching thrown errors.

- src/rpc-circuit-state.ts: getCircuitState, recordSuccess, recordFailure,
  resetCircuit, getAllCircuitStates
- createRpcServer proxy now records success/failure on each RPC call
- Exported from the package entry point

Addresses conduit-protocol#630
@ZacLou
ZacLou force-pushed the feat/circuit-state-630 branch from 1e26d75 to e488f1f Compare September 5, 2026 14:47
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