/api/health/fix

GET ASYNC

Automatically heals fracked coins using a two-phase RAIDA ticket-based authentication system to repair partial authentication failures. Returns immediately with a task_id; poll /api/system/tasks using the provided url for progress and final results.

Description

The /api/health/fix endpoint implements an automatic healing workflow for coins in the Fracked folder. Fracked coins are those that have 13-24 successful authentications (out of 25 RAIDA servers), meaning they're authentic but have some failing RAIDAs. The Fix operation uses a ticket-based authentication protocol to convert failing RAIDAs to passing status.

The healing process uses two RAIDA commands executed in sequence:

  • Get Ticket (0x0228): Collects authentication tickets from passing RAIDAs
  • Fix2 (0x023D): Sends the coin's existing AN plus the collected tickets to each failing RAIDA so it can write the AN back into its database.
How It Works

The Fix protocol works on a simple principle: RAIDAs that have successfully authenticated a coin can vouch for it by providing tickets. Failing RAIDAs accept these tickets as proof of authenticity and update their databases accordingly.

Requirements:

  • Coins must already have some 'p' (pass) status RAIDAs to provide tickets
  • At least 13 tickets are needed to fix a failing RAIDA
  • Tickets are valid for only 1 minute
  • The process runs iteratively up to 10 rounds for maximum healing

Two-Phase RAIDA Protocol

Phase 1: Get Ticket (0x0228)

For each coin in the Fracked folder, the system identifies all RAIDAs with 'p' (pass) status and requests authentication tickets.

Get Ticket Request Format:
Challenge(16 bytes)
+ [DN(1) + SN(4) + AN(16)] × N coins
+ 3E3E (2-byte terminator)

Get Ticket Response Format:
- ALL_PASS (241): Ticket(4) + 3E3E(2)
- ALL_FAIL (242): 3E3E(2)
- MIXED (243): Bitfield(N) + Ticket(4) + 3E3E(2)

Ticket Characteristics:

  • 4-byte random token generated by passing RAIDAs
  • Valid for 1 minute from generation
  • Each passing RAIDA provides one ticket per coin
  • Up to 24 tickets can be collected per coin (one per passing RAIDA)

Phase 2: Fix2 (0x023D)

For each failing RAIDA, the coin's existing AN plus the 25-ticket pool are sent so the RAIDA can verify the tickets with its peers and write the AN back into its page.

Fix2 Request Format (per failing RAIDA):
[DN(1) + SN(4) + AN(16)] × N coins
+ [25 × Ticket(4)]
Total = 21*N + 100 bytes

Fix2 Response Format:
- ALL_PASS (241): 3E3E(2) - All coins fixed
- ALL_FAIL (242): 3E3E(2) - All coins rejected
- MIXED  (243): Bitfield(N) + 3E3E(2) - Some fixed

Fix Process:

  1. Failing RAIDA receives tickets from passing RAIDAs
  2. RAIDA verifies tickets with issuing RAIDAs (cross-validation)
  3. If 13+ valid tickets received: RAIDA updates its database and returns 'p'
  4. If fewer than 13 tickets or verification fails: Returns error or 'f'

Iterative Healing Workflow

The Fix operation runs iteratively to maximize healing success:

Healing Workflow:
1. Read all coins from Fracked folder
2. For each round (max 10):
   a. Identify RAIDAs needing fixing (non-'p' status)
   b. Identify RAIDAs that can provide tickets ('p' status)
   c. Execute Phase 1: Get Ticket (parallel on all 25 RAIDAs)
   d. Collect tickets (require 13+ per coin)
   e. Execute Phase 2: Fix (parallel on all 25 RAIDAs)
   f. Update POWN strings based on results
   g. If no changes from previous round: Stop
3. Run Grade command to sort coins to Bank/Fracked/Counterfeit
4. Generate receipt file
Why Multiple Rounds?

Each Fix round may heal some RAIDAs, which can then provide tickets in the next round. This cascading effect allows progressively more RAIDAs to be fixed:

  • Round 1: 15 'p' RAIDAs provide 15 tickets → Fix 2 more RAIDAs → 17 'p' total
  • Round 2: 17 'p' RAIDAs provide 17 tickets → Fix 3 more RAIDAs → 20 'p' total
  • Round 3: 20 'p' RAIDAs provide 20 tickets → Fix 5 more RAIDAs → 25 'p' total

The process stops automatically when no changes occur between rounds or all coins are fully healed.

Parameters

Parameter Type Required Description
wallet_path string Yes The file system path to the wallet directory to fix fracked coins in (e.g., C:/Wallets/MyWallet or E:/Client_Data/Wallets/MyWallet).

Response

This endpoint is asynchronous. It returns immediately with a task_id and a ready-to-use poll url. The actual Get-Ticket + Fix work runs in a background thread; clients poll /api/system/tasks to observe progress and the final result.

Response Properties

command string
Always "fix_fracked".
success boolean
True if the background task was started successfully. This indicates task spawn, not healing success — the healing result is on the polled task.
task_id string
Unique task identifier for polling progress via /api/system/tasks.
url string
Fully-formed poll URL the caller can GET to fetch this task's status. Equivalent to /api/system/tasks?task_id={task_id} on the same host. Provided so clients do not need to build the URL themselves.
wallet_path string
The wallet path used for the fix operation.
fix_command string
RAIDA command code used. Always "FIX2 (CMD 61)".
message string
Human-readable note that the task has started and the caller should poll /api/system/tasks for status.

Immediate Response (task started)

{
  "command": "fix_fracked",
  "success": true,
  "task_id": "Apr-24-26_12-41-07-pm-18e7",
  "url": "http://localhost:8080/api/system/tasks?task_id=Apr-24-26_12-41-07-pm-18e7",
  "wallet_path": "E:\\Client_Data\\Wallets\\Default",
  "fix_command": "FIX2 (CMD 61)",
  "message": "Fix fracked started — poll /api/system/tasks for status"
}

Error Response - Fix Operation Failed

{
  "error": "Fix operation failed",
  "status": 500
}

Healing Success Criteria

After healing completes, coins are automatically sorted to the appropriate folder based on their final POWN status:

POWN String Grading:
- 25 'p' (perfect)   → Bank (fully authenticated)
- 13-24 'p'          → Fracked (partial authentication)
- 0-12 'p'           → Counterfeit (failed authentication)

Healing Outcomes:
- Success: 13 'p' → 25 'p' (Fracked → Bank)
- Partial: 13 'p' → 20 'p' (Fracked → Fracked, improved)
- Failure: 13 'p' → 10 'p' (Fracked → Counterfeit, degraded)
POWN String Updates

The Fix operation updates POWN strings character-by-character based on Fix results:

  • 'p': RAIDA passed (successfully fixed or already passing)
  • 'f': RAIDA failed (counterfeit or rejected tickets)
  • 'e': RAIDA error (network issue or server error)
  • 'n': No reply (timeout)

Each Fix round attempts to convert 'f', 'n', 'e' status to 'p' status using tickets.

Receipt File Generation

The Fix operation generates a detailed receipt file in the wallet's Receipts folder.

Receipt Format: YYYY-MM-DD_HH-MM-SS.fix.txt

=== Receipt ===
Type: Fix Fracked Coins
Date: 2025-01-31 15:30:45
Task ID: Jan-31-25_03-30-45-PM

Summary:
- Total coins processed: 5
- Fully healed (25/25): 3
- Partially healed (13-24/25): 1
- Failed healing (0-12/25): 1

Coin Results:
SN 12345 (250): ppppppppppppppppppppppppp (25/25 Pass - Moved to Bank)
SN 67890 (100): pppppppppppppppppnnnpppppp (20/25 Pass - Still Fracked)
SN 54321 (25):  ppppppppppffffff (8/25 Pass - Moved to Counterfeit)
...

Examples

JavaScript (fetch)

const API_HOST = 'http://localhost:8080';

// Fix fracked coins in specified wallet
async function fixFrackedCoins(walletPath) {
    try {
        console.log(`Starting Fix operation on wallet: ${walletPath}`);
        const encodedPath = encodeURIComponent(walletPath);
        const response = await fetch(`${API_HOST}/api/health/fix?wallet_path=${encodedPath}`);
        const result = await response.json();

        if (result.status === 'success') {
            console.log('Fix completed successfully');
            console.log(`Wallet: ${result.wallet}`);
            console.log(`Path: ${result.wallet_path}`);
            console.log(`Note: ${result.note}`);
        } else {
            console.error('Fix failed:', result.error);
        }
    } catch (error) {
        console.error('Error during Fix operation:', error);
    }
}

// Usage
fixFrackedCoins('E:/Client_Data/Wallets/Default');

cURL

# Fix all fracked coins in specified wallet
curl -X GET "http://localhost:8080/api/health/fix?wallet_path=E%3A%5CClient_Data%5CWallets%5CDefault"

# Fix fracked coins in another wallet
curl -X GET "http://localhost:8080/api/health/fix?wallet_path=E%3A%5CClient_Data%5CWallets%5CMyWallet"

# Fix fracked coins with pretty-printed output
curl -X GET "http://localhost:8080/api/health/fix?wallet_path=E%3A%5CClient_Data%5CWallets%5CDefault" | json_pp

# Unix path example
curl -X GET "http://localhost:8080/api/health/fix?wallet_path=E:/Client_Data/Wallets/Default"

Go

package main

import (
    "encoding/json"
    "fmt"
    "io/ioutil"
    "net/http"
    "net/url"
)

const ApiHost = "http://localhost:8080"

type FixResponse struct {
    Status    string `json:"status"`
    Operation string `json:"operation"`
    Message   string `json:"message"`
    Wallet    string `json:"wallet"`
    Note      string `json:"note"`
}

// Fix fracked coins in specified wallet
func fixFrackedCoins(walletPath string) error {
    fmt.Printf("Starting Fix operation on wallet: %s\n", walletPath)

    params := url.Values{}
    params.Add("wallet_path", walletPath)

    uri := fmt.Sprintf("%s/api/health/fix?%s", ApiHost, params.Encode())
    resp, err := http.Get(uri)
    if err != nil {
        return fmt.Errorf("request failed: %v", err)
    }
    defer resp.Body.Close()

    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        return fmt.Errorf("failed to read response: %v", err)
    }

    var result FixResponse
    if err := json.Unmarshal(body, &result); err != nil {
        return fmt.Errorf("failed to parse response: %v", err)
    }

    if result.Status == "success" {
        fmt.Println("Fix completed successfully")
        fmt.Printf("Wallet: %s\n", result.Wallet)
        fmt.Printf("Path: %s\n", result.WalletPath)
        fmt.Printf("Note: %s\n", result.Note)
        return nil
    }

    return fmt.Errorf("fix failed: %s", result.Message)
}

func main() {
    // Fix fracked coins in specified wallet
    if err := fixFrackedCoins("E:/Client_Data/Wallets/Default"); err != nil {
        panic(err)
    }
}

Important Considerations

Prerequisites

Coins must have existing 'p' (pass) status on some RAIDAs to provide tickets:

  • Coins with 0 'p' status cannot be healed (no ticket sources)
  • Run /api/health/authenticate first if coins have no 'p' status
  • Minimum 1 passing RAIDA required; 13+ recommended for best results
Ticket Validity

Tickets have a 1-minute expiration time:

  • Get Ticket and Fix operations run back-to-back automatically
  • All 25 RAIDAs execute in parallel (~1-2 seconds per phase)
  • No user action needed - timing is handled automatically
Parallel RAIDA Execution

Both Get Ticket and Fix requests execute on all 25 RAIDAs simultaneously:

  • Sequential execution: ~50 seconds (2 seconds × 25 RAIDAs)
  • Parallel execution: ~2 seconds (network RTT + processing)
  • 20-25x performance improvement
  • Default timeout: 10 seconds per RAIDA operation

Related Endpoints

/api/wallets/show-coins

View all coins in the wallet including those in the Fracked folder before and after healing.

/api/coins/grade

Manually grade and sort coins to Bank/Fracked/Counterfeit folders based on POWN status.

/api/health/authenticate

Re-authenticate coins with RAIDA servers. Use this first if coins have no 'p' status.

Troubleshooting

No Tickets Available

If the Fix operation reports "No ticket sources available":

  • Check that coins have at least one 'p' (pass) status RAIDA
  • Run /api/health/authenticate to re-authenticate coins
  • Verify RAIDA network connectivity with /api/program/echo

Coins Still Fracked After Fix

Some coins may remain fracked after healing:

  • Insufficient tickets collected (fewer than 13 per failing RAIDA)
  • Network issues preventing ticket verification
  • Some RAIDAs may be offline or unreachable
  • Run Fix operation again - may heal more coins in subsequent rounds

Coins Moved to Counterfeit

If coins move from Fracked to Counterfeit folder:

  • Coins fell below 13 'p' status during Fix operation
  • Likely genuine coins with severe network issues
  • Try authenticating again during better network conditions
  • Contact RAIDA administrators if persistent