# Statistics overview

`GET /stats` · Lithos client API · Statistics

Source: https://lithosprotocol.org/docs/api/get-stats

One snapshot of everything the collector tracks: the Stratum job being mined right now,
DEX and storage collection status, and a short summary of recent mining and payment history.

Each section carries its own `status` and observation time. The active job is the last
publication this client broadcast, which is not proof every worker received it. Payment
totals here are gross — reward plus refunded bond — so use `/stats/mining/totals` when
rewards and refunds have to be shown apart.

## Responses

### 200: The current snapshot, or the last one with a stale status.

`StatsView`

- `enabled` (boolean, required)
- `local` (object, required)
  - `stratum` (StratumStatsView, required)
    - `status` (string, required, one of disabled, waiting, active, stale, stopped): A stale snapshot can still show its last job. That job is not known to be live.
    - `observedAt` (integer · int64): When the producer last reported, in Unix milliseconds. Periodic refreshes count.
    - `connectedConnections` (integer, required): Open Stratum connections, not unique miners.
    - `activeJob` (ActiveStratumJob)
      - `jobId` (string, required)
      - `height` (integer, required)
      - `parentId` (string, required)
      - `workMessage` (string, required): Hex-encoded work message identifying the candidate.
      - `publicationId` (string · uuid, required)
      - `publishedAt` (integer · int64, required): When the job was published, in Unix milliseconds. Periodic observations do not move it.
      - `mode` (string, required, one of solo, genesis, augmented)
      - `blockPackage` (BlockPackageView): The transactions this client put into the job being served. The node can add mempool transactions on top that the client cannot see, so this is not the whole block. Expected revenue is what the package proposes to earn, not confirmed income, and the totals cover only the transactions whose size and cost are known — the rest report null. 
    - `difficulty` (StratumDifficulty): The difficulties this stratum works with, each as a score — the number a `diff` setting names, as an exact decimal string. The configured `diff` is on `/mining`.
      - `served` (string, required): What jobs are built on: the commitment in force, or the config diff when `forcedConfig` is true. A `pending` score higher than `committed` is served from two blocks before its declared height, 62 blocks before it binds, so the super shares its first rollups draw on are found at it.
      - `advertised` (string, required): What mining software is sent. `served` times `reductionMultiplier` under reduced reporting, otherwise `served`. Equals `superShare` at a multiplier of 10000.
      - `superShare` (string, required): The difficulty a share must clear to count toward a NISP, 10,000 times `served`.
      - `reducedReporting` (boolean, required): Whether miners are sent `advertised` instead of `served`.
      - `reductionMultiplier` (integer, required, one of 10, 100, 1000, 10000): The factor `advertised` sits above `served` while `reducedReporting` is true. Only a multiplier of 10000 makes every share a miner sends a super share.
      - `forcedConfig` (boolean, required): Whether `forceConfigDiff` makes the stratum serve the config diff instead of the commitment.
      - `committed` (string): The committed score NISPs are judged against now. Absent until a commitment is in force or before the first read.
      - `pending` (string): A newer commitment still waiting out the NISP window. Absent when there is none.
      - `pendingFromHeight` (integer): The height `pending` takes effect at.
      - `checkedHeight` (integer): The chain height the commitments were last read at.
- `dex` (DexStatsView, required)
  - `status` (string, required, one of disabled, loading, ready, stale, unavailable): Freshness only. Coverage is a separate question — read `historyComplete` and a graph's `partial`.
  - `updatedAt` (integer · int64): When the last successful refresh began, in Unix milliseconds, before it read the node.
  - `sourceHeight` (integer · int32)
  - `sourceBlockId` (string): The chain tip checked before and after the read. Current price and activity can also include the mempool.
  - `windowStartHeight` (integer · int32): Earliest height you can ask for, max(0, `sourceHeight` - 21600).
  - `coverageStartHeight` (integer · int32): Oldest retained pool snapshot, including a predecessor where one exists.
  - `historyComplete` (boolean): Whether the history read reached the start of the index, or a predecessor, before the requested window.
  - `refreshing` (boolean, required)
  - `restored` (boolean, required): Loaded from disk. Stale until a node read succeeds, and never overwrites newer live data.
  - `error` (string): Short refresh failure message. Details stay in the client log.
  - `collectedFrom` (integer · int32): The height a verified pool other than ERG:LIT joined the verified list. Nothing before it is collected, so a graph covering earlier heights shows that range as not collected. Absent for ERG:LIT, whose whole life is collected. 
- `storage` (StatsStorageView, required): Whether DEX snapshots are being saved. Mining history reports its own storage failures through `mining.status`.
  - `status` (string, required, one of disabled, loading, ready, error)
  - `busy` (boolean, required): A write is running. No second writer starts until it finishes.
  - `pending` (boolean, required): One newer snapshot is queued behind the running write.
  - `lastSavedObservationAt` (integer · int64): Observation time of the last snapshot saved or restored, in Unix milliseconds.
  - `lastPrunedAt` (integer · int64): Last successful pruning pass, in Unix milliseconds. A backlog can remain after one.
  - `coalescedSnapshots` (integer · int64, required): Queued snapshots dropped in favour of a newer one since the client started.
  - `error` (string): Short storage failure message. Details stay in the client log.
- `mining` (MiningStatsView, required): A summary of canonical mining history, held in memory. Counts cover retained history, not everything that ever happened. Only `ready` has caught up to the checked chain tip; other statuses can hold older or partial data. A reorg removes the displaced contributions before the status goes back to `ready`.
  - `status` (string, required, one of disabled, loading, ready, stale, unavailable, catching-up, recovering)
  - `observedAt` (integer · int64): When the last replay cycle started, in Unix milliseconds. Absent after a disk restore with no replay yet.
  - `persistent` (boolean, required): False when storage is off, in which case history lives only in process memory.
  - `sourceHeight` (integer): Last processed height, or the starting anchor if nothing has been collected yet.
  - `sourceBlockId` (string)
  - `targetHeight` (integer): Last checked chain height. It can run ahead of what is indexed and readable.
  - `fromHeight` (integer): First retained height. Higher than `sourceHeight` while the history is empty.
  - `fromTimestamp` (integer · int64): Timestamp of the first retained block. Retention keeps a 256-block rollback buffer.
  - `recentFromHeight` (integer): The recent lists below cover the latest 120 retained chain blocks, capped at 50 records each.
  - `totalsScope` (string, required, one of retained-history)
  - `blockScope` (string, required, one of configured-protocol): Genesis transactions under this client's configured protocol contracts.
  - `paymentScope` (string, required, one of primary-mining-address)
  - `paymentAmountScope` (string, required, one of gross-output-including-bond-refund): Payout amounts are gross — reward plus refunded bond plus any surplus. Not net earnings.
  - `totals` (MiningTotals, required)
    - `blocks` (integer · int64, required): Distinct chain blocks in retained history that carried a Lithos genesis transaction.
    - `payments` (integer · int64, required): Payout outputs to the primary mining address in retained history.
    - `grossPaidNanoErg` (string, required): Exact decimal integer. Includes bond refunds and any surplus, so it is not net earnings.
  - `blocks` (LithosBlockRecord[], required): Recent Lithos genesis records, newest first.
    - `blockId` (string, required)
    - `height` (integer, required)
    - `timestamp` (integer · int64, required)
    - `transactionId` (string, required)
    - `holdingBoxId` (string, required)
    - `collateralBoxId` (string, required)
    - `collateralNanoErg` (string, required): Exact value of the collateral box that was spent.
    - `initialHoldingNanoErg` (string, required): Exact value of genesis output zero, before any top-ups. Not the block's final revenue.
    - `priorityFeeNanoErg` (string, required): The whole fee the collateral box carried above the floor. The pool's share of it is already in `initialHoldingNanoErg`.
    - `selection` (CollateralSelection): How the block's collateral box came to be spent. Absent when the stored record lacks it, and where the index does not show the box's activation.
      - `path` (string, required, one of bid, clearance): `clearance` when the box was at least the shipped clearance age when spent, otherwise `bid`.
      - `joinedHeight` (integer, required): The block that included the lender's queue box.
      - `activatedHeight` (integer, required): The block that included the collateral box. Its age counts from here.
      - `queueNanoErg` (string, required): The queue box's value, the lender's cost.
      - `receivedNanoErg` (string, required): The block reward less re-emission, and the block's fees, paid to the lender's key.
  - `payments` (MiningPaymentRecord[], required): Recent confirmed payouts to this client, newest first. Wallet change and empty-tree drains are left out.
    - `transactionId` (string, required)
    - `outputId` (string, required)
    - `payoutBoxId` (string, required)
    - `rollupNft` (string, required): NFT minted from the original collateral box id.
    - `minedBlockId` (string, required): The block holding the rollup genesis, even when that block is older than retained history.
    - `minedHeight` (integer, required)
    - `minedTimestamp` (integer · int64, required): Timestamp of `minedBlockId`, in Unix milliseconds. With `timestamp`, how long the payout took.
    - `blockId` (string, required): The block holding this payout transaction.
    - `height` (integer, required)
    - `timestamp` (integer · int64, required)
    - `grossNanoErg` (string, required): Exact output value, including the refunded bond and any surplus.
  - `difficulty` (string, required): Network difficulty at `sourceHeight`, as an exact decimal integer. For the curve over time use /stats/mining/difficulty.
  - `error` (string): Short failure message. Details stay in the client log.

## Example request

```bash
curl -X GET "http://localhost:9000/stats"
```

## Example response

```json
{
  "enabled": true,
  "local": {
    "stratum": {
      "status": "disabled",
      "observedAt": 0,
      "connectedConnections": 0,
      "activeJob": {
        "jobId": "string",
        "height": 0,
        "parentId": "string",
        "workMessage": "string",
        "publicationId": "string",
        "publishedAt": 0,
        "mode": "solo",
        "blockPackage": {
          "genesisId": "string",
          "collateralBoxId": "string",
          "lenderAddress": "string",
          "collateralPriorityFeeNanoErg": "0",
          "collateralFinderFeeNanoErg": "0",
          "revision": 0,
          "expectedRevenueNanoErg": "string",
          "sources": [
            "string"
          ],
          "lateSources": [
            "string"
          ],
          "transactions": [
            {
              "id": "string",
              "kind": "string",
              "sizeBytes": 0,
              "cost": "string",
              "revenueNanoErg": "0",
              "proofLeafMatched": true
            }
          ],
          "transactionScope": "client-supplied",
          "knownSizeBytes": "string",
          "knownCost": "string",
          "allSizesKnown": true,
          "allCostsKnown": true,
          "blockMaxSizeBytes": "0",
          "blockMaxCost": "0",
          "packageMaxSizeBytes": "0",
          "packageMaxCost": "0"
        }
      },
      "difficulty": {
        "served": "0",
        "advertised": "0",
        "superShare": "0",
        "reducedReporting": true,
        "reductionMultiplier": 10,
        "forcedConfig": true,
        "committed": "0",
        "pending": "0",
        "pendingFromHeight": 0,
        "checkedHeight": 0
      }
    }
  },
  "dex": {
    "status": "disabled",
    "updatedAt": 0,
    "sourceHeight": 0,
    "sourceBlockId": "string",
    "windowStartHeight": 0,
    "coverageStartHeight": 0,
    "historyComplete": true,
    "refreshing": true,
    "restored": true,
    "error": "string",
    "collectedFrom": 0
  },
  "storage": {
    "status": "disabled",
    "busy": true,
    "pending": true,
    "lastSavedObservationAt": 0,
    "lastPrunedAt": 0,
    "coalescedSnapshots": 0,
    "error": "string"
  },
  "mining": {
    "status": "disabled",
    "observedAt": 0,
    "persistent": true,
    "sourceHeight": 0,
    "sourceBlockId": "string",
    "targetHeight": 0,
    "fromHeight": 0,
    "fromTimestamp": 0,
    "recentFromHeight": 0,
    "totalsScope": "retained-history",
    "blockScope": "configured-protocol",
    "paymentScope": "primary-mining-address",
    "paymentAmountScope": "gross-output-including-bond-refund",
    "totals": {
      "blocks": 0,
      "payments": 0,
      "grossPaidNanoErg": "string"
    },
    "blocks": [
      {
        "blockId": "string",
        "height": 0,
        "timestamp": 0,
        "transactionId": "string",
        "holdingBoxId": "string",
        "collateralBoxId": "string",
        "collateralNanoErg": "string",
        "initialHoldingNanoErg": "string",
        "priorityFeeNanoErg": "string",
        "selection": {
          "path": "bid",
          "joinedHeight": 0,
          "activatedHeight": 0,
          "queueNanoErg": "string",
          "receivedNanoErg": "string"
        }
      }
    ],
    "payments": [
      {
        "transactionId": "string",
        "outputId": "string",
        "payoutBoxId": "string",
        "rollupNft": "string",
        "minedBlockId": "string",
        "minedHeight": 0,
        "minedTimestamp": 0,
        "blockId": "string",
        "height": 0,
        "timestamp": 0,
        "grossNanoErg": "string"
      }
    ],
    "difficulty": "string",
    "error": "string"
  }
}
```
