# Stratum and difficulty

> The stratum server your mining software connects to, and the difficulty that decides your payout.

Source: https://lithosprotocol.org/docs/configuration/stratum

**Level:** Standard

*For anyone running the Lithos client. No Ergo or smart contract experience needed.*

The `stratum` block controls the local server your mining software connects to, and the difficulty you
commit to on chain. This page covers everything under `stratum` except `stratum.candidate`, which is
large enough to have [its own page](https://lithosprotocol.org/docs/configuration/candidate).

`stratum.diff` is the most consequential setting in the whole file. It decides both what you are paid
and whether you are paid at all.

## Difficulty

| Setting | Default | Range | What it does |
|---|---|---|---|
| `stratum.diff` | `4.0M` | A parseable difficulty above zero. **Required** | The difficulty the stratum serves until your difficulty commitment takes effect, and the one `state.autoCommit` commits |
| `stratum.diffRefreshInterval` | 60000 | 1000 to 3600000 ms. **Required** | How often the client re-reads your committed difficulty from chain state |
| `stratum.forceConfigDiff` | `false` | `true` or `false` | Mine at `diff` instead of your on-chain commitment. For testing only |

The format is a number followed by a power-of-ten suffix: `K`, `M`, `G`, `T` or `P`. So `4.0G`,
`1.52M` and `300.1K` are all valid. Startup parses the value and refuses anything it cannot read or
that resolves to zero or less.

**Choosing the number is a real decision**, covered in the
[startup guide](https://lithosprotocol.org/docs/startup-intro#choosing-a-difficulty). In short: your payout is proportional to
your committed difficulty, but you earn nothing for a block unless you produced 10 super shares in the
60 blocks before it. Start at a value that averages 17 super shares per window, then raise it toward
one that averages 15.

### Testing without committing

Nothing is written on chain until you commit from the web interface or turn on `state.autoCommit`,
which ships off. That leaves you free to try values first. `forceConfigDiff` makes the client mine at the `diff` in your file rather than at
whatever it has committed, so with both settings as below you can measure super share rates at several
difficulties without writing any of them to the blockchain:

```hocon title="lithos-client/bin/lithos.conf"
stratum.forceConfigDiff = true
state.autoCommit = false
```

When you have chosen a value, set `forceConfigDiff = false` and commit it from the **Commitment** tab,
or set `autoCommit = true` to have the client commit `diff`. Both are described in
[Tasks and dispatchers](https://lithosprotocol.org/docs/configuration/runtime#committing-your-difficulty).

> **Warning: Turn `forceConfigDiff` off before mining for real**
>
> With `forceConfigDiff = true`, mining below your on-chain commitment produces NISPs that will not be
> accepted. The setting exists to measure hardware, not to run on.

## The stratum server

| Setting | Default | Range | What it does |
|---|---|---|---|
| `stratum.stratumPort` | 4444 | 1 to 65535. **Required** | The TCP port your mining software connects to |
| `stratum.bindAddress` | `0.0.0.0` | An IPv4 or IPv6 address, or a host name, without a port | The network interface the stratum listens on. `0.0.0.0` listens on all of them |
| `stratum.connectionTimeout` | 60000 | 1000 to 3600000 ms. **Required** | How long a silent connection is held before it is dropped |
| `stratum.blockRefreshInterval` | 1000 | 100 to 600000 ms. **Required** | How often the server checks whether it has new work to push |
| `stratum.reduceShareMessages` | `true` | `true` or `false`. **Required** | Raise the difficulty reported to your mining software without changing what Lithos pays you at |
| `stratum.reductionMultiplier` | 10000 | `10`, `100`, `1000` or `10000` | How many times your committed difficulty the stratum sends while `reduceShareMessages` is on |
| `stratum.niceHashMode` | `false` | `true` or `false` | Announce each job's share difficulty in `mining.set_difficulty` instead of 1. Turn it on only when NiceHash connects to this stratum |

### Which rigs can connect

`bindAddress` decides which network the stratum accepts rigs from. It ships at `0.0.0.0`, which
accepts rigs on every network this machine is connected to.

| `bindAddress` | Rigs accepted from |
|---|---|
| `0.0.0.0` (default) | Any network this machine is on |
| `127.0.0.1` | This machine only. Use it when your mining software runs on the same computer as the client |
| One of this machine's LAN addresses, such as `192.168.1.20` | The network that address belongs to |
| `::` or `::1` | The IPv6 equivalents of `0.0.0.0` and `127.0.0.1` |

```hocon title="lithos-client/bin/lithos.conf"
stratum.bindAddress = "127.0.0.1"
```

Write the address alone. The port comes from `stratumPort`, so `"127.0.0.1:4444"` is rejected.

**An address this machine does not have stops the stratum, not the client.** Startup checks only that
the value is an address or a host name that resolves. If the machine holds no such address, for example
because a LAN address changed after a router restart, the client starts and serves its API and web
interface, but no rig can connect. The log shows:

```text
Stratum is not accepting rigs on <address>, port <port>: ...
```

Fix the address and restart the client. If your router hands out addresses automatically, give this
machine a fixed LAN address before binding to it, or leave `bindAddress` at `0.0.0.0`.

### Share traffic

At low difficulties your mining software may send enough shares to trigger errors about duplicate or
old shares. `reduceShareMessages` raises the stratum difficulty to `reductionMultiplier` times your
committed difficulty, so your mining software sends fewer shares. **The difficulty Lithos evaluates
and pays you at is unchanged.**

| `reductionMultiplier` | Stratum difficulty | Shares sent per super share |
|---|---|---|
| `10000` (default) | Equal to the super-share difficulty | 1. Every accepted share is a super share |
| `1000` | 1/10 of the super-share difficulty | About 10 |
| `100` | 1/100 of the super-share difficulty | About 100 |
| `10` | 1/1,000 of the super-share difficulty | About 1,000 |

**At `10000`, your mining software's accepted-share count is your super-share count**, so you can read
it straight from its output.

The cost is how rarely your mining software sends a share. At a high committed difficulty that can be
a few an hour, so its hashrate and share readouts barely move. A lower multiplier gives your mining
software, and the Mining panel, more shares to measure from. Every share is still checked against the
super-share difficulty, so NISPs are built the same at any setting.

It ships on at `10000`. There is generally no reason to turn it off outside debugging.

### Connecting NiceHash

NiceHash reads the share difficulty from the stratum's `mining.set_difficulty` message. NiceHash refuses
a pool whose difficulty there is below its Autolykos minimum of 4,000,000,000. With `niceHashMode` off,
the stratum sends a difficulty of 1 and puts the real share target in each job, which is where mining
software reads it.

Set `niceHashMode = true` when you rent hashrate on NiceHash. The stratum then sends each job's share
difficulty, which is your committed difficulty times `reductionMultiplier` while `reduceShareMessages` is
on. If that product is below 4,000,000,000, the client logs a warning and NiceHash still refuses the
pool. Connect no other mining software to a stratum with `niceHashMode` on, because it may submit shares
at the wrong difficulty. [Renting hashrate into Lithos](https://lithosprotocol.org/docs/operations/renting-hashrate) covers the
rest of a rental setup.

## Extra nonce

| Setting | Default | Range | What it does |
|---|---|---|---|
| `stratum.extraNonce1Size` | 2 | 1 to 8 bytes. **Required** | Hex bytes of `extraNonce1` handed to each connection |
| `stratum.rotateExtraNonceInterval` | 0 | 0 to 3600000 ms | How long a connection may go without submitting work before its `extraNonce1` is rotated. `0` disables rotation |

`extraNonce1` splits the nonce space between connections so two rigs never search the same range. The
size trades that split against the space each rig gets to work through in a single job.

**Two is recommended and shipped.** It leaves each rig a large nonce space for one job. Raising it
narrows that space, which invites duplicate shares and extra nonce changes in your mining software.

Rotation exists only for setups that raised the size above 2 and are running out of distinct values.
At the shipped size you should not need it, which is why it ships disabled.

## Next steps

- [Block packages](https://lithosprotocol.org/docs/configuration/candidate): everything under `stratum.candidate`.
- [Choosing a difficulty](https://lithosprotocol.org/docs/startup-intro#choosing-a-difficulty): how to pick `diff`.
