RPC Pool Failover
The transaction engine uses an intelligent RPC pool with automatic health scoring and failover.Configuration
Configure multiple RPC endpoints for high availability:.env
Health Scoring Algorithm
Each endpoint maintains a dynamic health score based on:- Success rate - Successful requests increase score
- Latency - High latency reduces score
- Failure streaks - Consecutive failures penalize score
- Recovery - Endpoints can recover score over time
Health Score Formula
Health Score Formula
Initial Score: On Failure:Latency Penalties:
1.0On Success:- ≤ 200ms:
0.00 - 201-500ms:
0.04 - 501-1000ms:
0.08 -
1000ms:
0.12
Failover Behavior
1
Sort by Score
Endpoints are sorted by health score (descending), then by average latency (ascending).
2
Attempt Primary
The highest-scored endpoint is tried first for each operation.
3
Cascade on Failure
If the primary fails, the next endpoint in the sorted list is tried automatically.
4
Update Health
Success or failure updates the endpoint’s health score for future requests.
Monitor Pool Status
Query the current health of all RPC endpoints:The pool continuously probes all endpoints in the background at the configured interval to maintain fresh health scores.
Durable Outbox Queue
The transaction engine uses a SQLite-backed outbox pattern for reliable transaction processing.Architecture
- Persistent Storage - Jobs survive process restarts
- Lease-based Claiming - Workers claim jobs with time-bound leases
- Automatic Retry - Failed jobs re-enter the queue
- Deduplication - Prevents duplicate pending jobs for the same transaction
Outbox Actions
execute- Process a new transaction requestretry- Retry a failed transactionapprove- Process an approval gate decision
Job States
Configuration
.env
Lease and Retry Semantics
1
Claim Job
Worker claims the oldest
pending job or a processing job with expired lease.2
Process with Lease
Job moves to
processing with a unique leaseId and expiration timestamp.3
Complete or Fail
Worker marks job as
done or failed.- Success:
status = 'done', lease cleared - Retryable Failure:
status = 'pending'ifattempts < TX_OUTBOX_MAX_ATTEMPTS - Permanent Failure:
status = 'failed'if max attempts exceeded
4
Automatic Recovery
If worker crashes, expired leases allow job to be reclaimed by another worker.
Monitor Outbox Status
Adaptive Priority Fee Tuning
The execution tuner automatically calculates optimal priority fees based on recent network activity.Configuration
.env
Fee Calculation Algorithm
1
Collect Recent Fees
Gather recent priority fees from the RPC endpoint’s recent blocks.
2
Calculate Percentile
Compute the configured percentile (e.g., 75th percentile).
3
Apply Multiplier
Boost the percentile fee by the configured multiplier.
4
Clamp to Bounds
Ensure the final fee is within min/max bounds.
Compute Unit Estimation
The tuner also calculates compute unit limits based on transaction type:Compute budgets are automatically injected as the first instructions in every transaction.
Delta Guard Checks
Delta guard validates that observed balance changes match expected deltas to detect simulation drift or unexpected fees.Configuration
.env
Expected Delta Calculation
Variance Evaluation
1
Compare Deltas
Calculate the absolute difference between expected and observed deltas.
2
Check Absolute Tolerance
If within the configured tolerance, delta guard passes.
3
Calculate Variance BPS
Compute variance in basis points.
4
Check Threshold
Compare variance to the configured threshold (typically 200-500 bps).
Delta Guard Result
Restart Recovery
The outbox queue automatically drains pending work on service restart.Recovery Flow
1
Load Persistent State
On startup, the transaction engine loads the SQLite database with all pending and processing jobs.
2
Reclaim Expired Leases
Jobs in
processing state with expired leases return to pending.3
Resume Processing
The outbox worker starts polling and claiming jobs from the queue.
4
Process Backlog
All pending jobs are processed in FIFO order (oldest first).
No manual intervention is required after a restart. The system automatically recovers and continues processing.
Database Migration
The system includes automatic migration from legacy JSON snapshots to SQLite.Migration Behavior
- Automatic Detection - On first startup, checks for legacy snapshot file
- One-time Import - Migrates jobs if SQLite database is empty
- Preserves History - All job states, attempts, and metadata are preserved
- Idempotent - Safe to restart during migration
After successful migration, you can safely delete the legacy JSON snapshot file.