|
| 1 | +# LeanViz Monitoring API Contract (v0) |
| 2 | + |
| 3 | +This document defines the minimum API surface required by the LeanViz dashboard. |
| 4 | +It is intentionally small and focused on monitoring data. |
| 5 | + |
| 6 | +## Status |
| 7 | +- UI defaults to Lean-style paths (`/lean/v0/...`). |
| 8 | +- Clients may also serve `/eth/v1/...` as a compatibility alias during migration. |
| 9 | + |
| 10 | +## Base URL |
| 11 | +All endpoints are relative to a base URL (configured in `web/config/config.json`). |
| 12 | + |
| 13 | +## Endpoints (Required) |
| 14 | +1. `GET /lean/v0/beacon/genesis` |
| 15 | +2. `GET /lean/v0/beacon/headers/head` |
| 16 | +3. `GET /lean/v0/beacon/states/head/finality_checkpoints` |
| 17 | +4. `GET /lean/v0/beacon/states/head/validators` |
| 18 | +5. `GET /lean/v0/node/peers` |
| 19 | +6. `GET /lean/v0/node/syncing` |
| 20 | +7. `GET /lean/v0/events` (SSE) |
| 21 | + |
| 22 | +Compatibility alias (optional): |
| 23 | +- `/eth/v1/...` with the same semantics |
| 24 | + |
| 25 | +## Response Shape (Minimum Fields) |
| 26 | +The UI only depends on the following fields. Extra fields are ignored. |
| 27 | + |
| 28 | +1. `/beacon/headers/head` |
| 29 | +- `data.root` or `root` |
| 30 | +- `data.header.message.slot` or `slot` |
| 31 | +- `data.header.message.proposer_index` or `proposer_index` |
| 32 | + |
| 33 | +2. `/beacon/states/head/finality_checkpoints` |
| 34 | +- `data.current_justified.slot` or `current_justified_slot` |
| 35 | +- `data.current_justified.epoch` or `current_justified.epoch` |
| 36 | +- `data.current_justified.root` or `current_justified.root` |
| 37 | +- `data.finalized.slot` or `finalized_slot` |
| 38 | +- `data.finalized.epoch` or `finalized.epoch` |
| 39 | +- `data.finalized.root` or `finalized.root` |
| 40 | + |
| 41 | +3. `/beacon/states/head/validators` |
| 42 | +- `data[]` array length determines validator count |
| 43 | +- `data[i].index` or `data[i].validator.index` |
| 44 | +- `data[i].status` or `data[i].validator.status` |
| 45 | + |
| 46 | +4. `/node/peers` |
| 47 | +- `data[]` array length determines peer count |
| 48 | + |
| 49 | +5. `/node/syncing` |
| 50 | +- `data.head_slot` (optional; used only for display) |
| 51 | + |
| 52 | +## Example Responses |
| 53 | +1. `/beacon/headers/head` |
| 54 | +```json |
| 55 | +{ |
| 56 | + "data": { |
| 57 | + "root": "0xabc123...", |
| 58 | + "header": { |
| 59 | + "message": { |
| 60 | + "slot": "107", |
| 61 | + "proposer_index": "22" |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | +2. `/beacon/states/head/finality_checkpoints` |
| 69 | +```json |
| 70 | +{ |
| 71 | + "data": { |
| 72 | + "current_justified": { |
| 73 | + "epoch": "3", |
| 74 | + "slot": "96", |
| 75 | + "root": "0xdef456..." |
| 76 | + }, |
| 77 | + "finalized": { |
| 78 | + "epoch": "3", |
| 79 | + "slot": "98", |
| 80 | + "root": "0x789abc..." |
| 81 | + } |
| 82 | + } |
| 83 | +} |
| 84 | +``` |
| 85 | + |
| 86 | +3. `/beacon/states/head/validators` |
| 87 | +```json |
| 88 | +{ |
| 89 | + "data": [ |
| 90 | + { "index": "0", "status": "active_ongoing" }, |
| 91 | + { "index": "1", "status": "active_ongoing" } |
| 92 | + ] |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | +4. `/node/peers` |
| 97 | +```json |
| 98 | +{ |
| 99 | + "data": [ |
| 100 | + { "peer_id": "16Uiu2H..." } |
| 101 | + ] |
| 102 | +} |
| 103 | +``` |
| 104 | + |
| 105 | +5. `/node/syncing` |
| 106 | +```json |
| 107 | +{ |
| 108 | + "data": { |
| 109 | + "head_slot": "107" |
| 110 | + } |
| 111 | +} |
| 112 | +``` |
| 113 | + |
| 114 | +## SSE Events |
| 115 | +Endpoint: `/events?topics=head,block,finalized_checkpoint,chain_reorg,attester_slashing,proposer_slashing` |
| 116 | + |
| 117 | +The UI uses only: |
| 118 | +- `head` or `block` events |
| 119 | + - `slot` |
| 120 | + - `proposer_index` (optional) |
| 121 | + - `block` or `root` |
| 122 | +- `finalized_checkpoint` events |
| 123 | + - `slot` or `finalized_slot` |
| 124 | + - `epoch` (optional) |
| 125 | + - `block` or `root` |
| 126 | +- `chain_reorg` events |
| 127 | + - payload is not parsed |
| 128 | +- `attester_slashing` or `proposer_slashing` events |
| 129 | + - `validator_index` or `proposer_index` or `index` |
| 130 | + |
| 131 | +## Example SSE Events |
| 132 | +``` |
| 133 | +event: head |
| 134 | +data: {"slot":"107","proposer_index":"22","block":"0xabc123..."} |
| 135 | +
|
| 136 | +event: finalized_checkpoint |
| 137 | +data: {"slot":"98","epoch":"3","block":"0x789abc..."} |
| 138 | +``` |
| 139 | + |
| 140 | +## CORS |
| 141 | +The API must allow the dashboard origin. |
| 142 | +Recommended: |
| 143 | +- `Access-Control-Allow-Origin: *` (dev) |
| 144 | +- Restrict origin in production. |
| 145 | + |
| 146 | +## Notes |
| 147 | +- The UI will run in "demo" mode if API calls fail. |
| 148 | +- Missing fields will degrade the display but should not crash the UI. |
0 commit comments