# Mining statistics by hour or day

`GET /stats/mining/buckets` · Lithos client API · Statistics

Source: https://lithosprotocol.org/docs/api/get-mining-buckets

The totals from `/stats/mining/totals` split into UTC hour or day buckets — the shape a
graph wants, for block counts, payments, fees, participation and difficulty. Buckets hold
exact sums and counts, so averages are yours to compute: `chain.difficultySum / chain.blocks`
for mean network difficulty, or `batching.lithosdex.grossNanoErg / batching.lithosdex.orders`
for the mean LithosDex executor fee. A zero denominator has no average.

`from` is inclusive, `until` is exclusive, both must sit on a boundary of the chosen
interval, and the range can cover at most 500 buckets. Buckets come oldest first, and a
missing one means nothing was retained for it. Past the reported coverage a gap means the
history is not available, not that nothing happened — check `partial`, `retainedFrom` and
`source.timestamp`, since the first and last bucket may also be incomplete.

The query reads collected history and never contacts the node. A busy or unavailable
history worker returns `503`; retry after the delay it gives.

## Parameters

| Name | In | Type | Required | Description |

|---|---|---|---|---|

| `from` | query | integer · int64 | yes | Inclusive start in Unix milliseconds, on a UTC hour or day boundary to match `interval`. |

| `until` | query | integer · int64 | yes | Exclusive end in Unix milliseconds. On the same boundary, later than `from`, and at most 500 intervals after it. |

| `interval` | query | string | no | Bucket size. Both range boundaries must be a whole number of these since the Unix epoch. |

## Responses

### 200: Graph data for the requested range, with source status and coverage.

`MiningBucketHistory`

- `source` (MiningCursor, required): The processed chain point a statistics result was read from.
  - `height` (integer, required)
  - `blockId` (string, required)
  - `parentId` (string, required)
  - `timestamp` (integer · int64, required): The block's own timestamp in Unix milliseconds, not the time the client read it.
- `retainedFrom` (integer · int64): Timestamp of the block before the first retained one. Absent when no block records remain.
- `from` (integer · int64, required): The inclusive start you asked for, in Unix milliseconds.
- `until` (integer · int64, required): The exclusive end you asked for, in Unix milliseconds.
- `widthMs` (integer · int64, required, one of 3600000, 86400000)
- `buckets` (MiningBucket[], required): Buckets with retained activity, oldest first. Use the coverage fields to tell a gap in history from a quiet hour.
  - `start` (integer · int64, required): Inclusive UTC bucket start in Unix milliseconds.
  - `widthMs` (integer · int64, required, one of 3600000, 86400000): Bucket duration in milliseconds.
  - `totals` (MiningAccountingMetrics, required): Exact sums and counts for the period, as decimal strings. A missing key means nothing was collected for it, which is not evidence that nothing happened outside the coverage. Amounts ending in `NanoErg` are nanoERG and LIT amounts are base units. New keys get added over time, so ignore ones you do not recognise. \| Key \| Meaning \| \| --- \| --- \| \| `chain.blocks`, `chain.difficultySum` \| Ergo blocks processed, and the sum of their network difficulty. \| \| `chain.transactionFeeNanoErg` \| Miner-fee outputs from every transaction in those blocks. \| \| `lithos.blocks`, `lithos.difficultySum` \| Blocks carrying a configured Lithos genesis — counted once each — and their difficulty. \| \| `lithos.transactionFeeNanoErg` \| Miner-fee outputs from the transactions inside those Lithos blocks. \| \| `local.payout.*` \| Confirmed payouts to this client's primary mining address. \| \| `local.slashed.count`, `.bondNanoErg` \| Fraud proofs that removed this client's own entry, and the bonds it lost. \| \| `network.payout.*` \| Every payout seen for the configured protocol, local ones included. \| \| `collateral.consumedNanoErg` \| Collateral spent by genesis transactions. Not income. \| \| `holding.genesisNanoErg` \| Value placed in holding boxes at genesis. Contains the pool's share of any priority bid. \| \| `lithos.priorityFeeNanoErg` \| Priority fees carried by the collateral boxes those blocks spent. \| \| `lithos.blocksWithPriorityFee` \| How many of those blocks carried a fee at all. \| \| `collateral.<path>.*` \| Lender cost and return by how the spent box was taken, `bid` or `clearance`: `boxes`, `priorityFeeNanoErg`, `costNanoErg`, `receivedNanoErg`, `waitBlocks`, and `capitalNanoErgBlocks`, the queue box's value times the blocks it stayed locked. `/stats/collateral` turns these into rates. \| \| `batching.<protocol>.*` \| Executor fees earned filling `ergodex` or `lithosdex` orders, builder takings from `forwards` recordings and settlements, and `arb` cycle profit. \| \| `batching.<protocol>.tokens.<tokenId>`, `.otherTokens` \| Tokens executors kept, by verified token id; `otherTokens` counts the times an unlisted token was kept, never its amount. \| \| `lithos.batching.<protocol>.*` \| The same, counting only blocks that carried a Lithos genesis. \| \| `pool.batching.<protocol>.orders`, `.grossNanoErg` \| Fee-less executions inside Lithos blocks. Their takings top up the rollup, so they reach miners through payouts. \| \| `local.batching.<protocol>.*` \| Executions whose takings went to this client, outside the pool. Paid straight to its wallet, less the transaction fee. \| \| `local.received.<protocol>.tokens.<tokenId>`, `.otherTokens` \| Tokens that reached this client's own address, in its own Lithos blocks too: a holding box never takes tokens, so they go to the block's finder. \| \| `rollup.<kind>.*` \| Confirmed rollup transitions: `topUp`, `submission`, `evaluation`, `fraudProof`, `payoutReady`. \| \| `transaction.<kind>.count`, `.feeNanoErg` \| Recognised transactions and the fees they paid. \| \| `registration.<kind>.count`, `.localCount` \| Miner Dictionary `add`, `remove` and `evict` events. \| **Payout families** hold `outputs`, `grossNanoErg`, `rewardNanoErg`, `bondNanoErg`, `surplusNanoErg`, `rewardLit` and `receivedLit`. Gross ERG is reward plus refunded bond plus any surplus. `rewardLit` is what the protocol owes; `receivedLit` is what the outputs actually carried. Network totals already contain the local ones — never add the two together. **Batching families** hold `orders`, `grossNanoErg`, `transactionFeeNanoErg` and `afterTransactionFeesNanoErg`, counting recognised execution layouts only, not all pool activity. Gross is newly earned executor fees and excludes takings carried in from earlier. Liquidity-provider fees are a different thing and live on the DEX API. `pool.batching` pays no transaction fee, so it holds only `orders` and `grossNanoErg`. It and `local.batching` never count the same execution. A `forwards` recording broadcast alone pays its fee from the wallet for LIT, so its fee is above its gross: that part is `feeAboveGrossNanoErg`, and the net is `afterTransactionFeesNanoErg - feeAboveGrossNanoErg`. Token keys are named only for tokens on the verified list when the execution was recorded; `tokens` in the response names each one. For `arb`, `orders` counts cycles and gross is the ERG a cycle returned above its stake. A cycle runs only in its own miner's block with no fee, so in a Lithos block it is counted in `pool.batching.arb`. **Rollup families** hold `count`, `miners`, `claimedScore`, `bondNanoErg` and `valueNanoErg`, plus `localCount`, `localValueNanoErg`, `localBondNanoErg` and `localClaimedScore` where the local miner is identifiable — the submitting miner for submissions, the prover input for fraud proofs. So `rollup.submission.localBondNanoErg` is the bond this client posted, and `rollup.fraudProof.localValueNanoErg` is the slashed bonds it was paid for proving fraud. `miners` counts entries at that transition, not unique people. `valueNanoErg` means a different thing per kind: added holding value for a top-up, zero for a submission, the full box value at evaluation, the slashed bond for a fraud proof, and distributable ERG excluding bonds at payout readiness. These are stages of the same funds, so summing them is not income. `transaction.<kind>` covers `genesis`, the rollup kinds above, `payout`, `registration`, `ergodex`, `lithosdex`, `forwards`, `arb` (each leg of a cycle), `ergodexOtherPoolSpend` and `lithosdexOtherPoolSpend`. Those fees overlap the block fee totals. **Priority fees.** `lithos.priorityFeeNanoErg / lithos.blocks` is the mean fee across every Lithos block; divide by `lithos.blocksWithPriorityFee` instead for the mean across the blocks that carried one. The amount is the WHOLE fee the lender posted, not the share the block's finder keeps out of it. The pool's share went into the holding box and is already inside `holding.genesisNanoErg`, so there is deliberately no separate key for it. Divide a sum by its matching count for an average. `claimedScore` is protocol accounting, not measured hashrate. A transaction fee is a transaction's cost and not automatically this client's expense, holding top-ups and executor fees can describe the same proceeds, and no key here is a net-income figure. 
- `partial` (boolean, required): True when retained coverage does not span the whole requested range, including when the history is empty.
- `status` (string, required, one of disabled, loading, ready, stale, unavailable, catching-up, recovering): How far collection has got. `ready` means it reached the last checked chain tip. `catching-up` and `recovering` mean replay or reorg work is still running, `stale` means the last successful check is too old, and `unavailable` means collection failed. On `disabled` or `loading` the numbers are not evidence that the period was quiet.
- `tokens` (map<string, VerifiedToken>): Every verified token a bucket's `.tokens.<tokenId>` key names, by id, so each amount can be shown in whole units.

### 400: A timestamp is missing, malformed, off a bucket boundary, or the range is too long; or `interval` is not hour or day.

`ApiError`

- `error` (integer, required): Error code
- `reason` (string, required): Error message explaining the reason of the error
- `detail` (string, required): Detailed error description

### 503: History is loading, disabled, busy, or unreadable. Check `mining.status` in /stats before retrying.

`ApiError`

- `error` (integer, required): Error code
- `reason` (string, required): Error message explaining the reason of the error
- `detail` (string, required): Detailed error description

## Example request

```bash
curl -X GET "http://localhost:9000/stats/mining/buckets?from=0&until=1"
```

## Example response

```json
{
  "source": {
    "height": 0,
    "blockId": "string",
    "parentId": "string",
    "timestamp": 0
  },
  "retainedFrom": 0,
  "from": 0,
  "until": 0,
  "widthMs": 3600000,
  "buckets": [
    {
      "start": 0,
      "widthMs": 3600000,
      "totals": {
        "chain.blocks": "720",
        "lithos.blocks": "12",
        "local.payout.outputs": "3",
        "local.payout.rewardNanoErg": "1500000000",
        "local.payout.bondNanoErg": "3000000",
        "batching.lithosdex.orders": "20",
        "batching.lithosdex.grossNanoErg": "40000000"
      }
    }
  ],
  "partial": true,
  "status": "disabled",
  "tokens": {
    "key": {
      "tokenId": "c1980d829988229516430a47a5eca376060b6ce859616db0936e78ab25cb6de7",
      "name": "LIT",
      "ticker": "LIT",
      "decimals": 9
    }
  }
}
```
