# suprnova MCA (Mercatura) stratum protocol — nomp-mca

Standard **stratum v1 for Bitcoin-family coins** (the protocol cpuminer-opt, cgminer-style miners and every pool-side
library implement). Nothing Mercatura-specific on the wire except the proof-of-work function.

Transport: TCP via the edge `mca.suprnova.cc` (port 8493 CPU VarDiff, 8494 GPU VarDiff; 8492 = ping server) or direct
on gadtr01. One JSON object per line (`\n`), client lines ≤ 10 KB, ≤ 50 messages/s per connection, ≤ 16 shares in
flight. Requests carry `id`, notifications `id: null`. Unknown methods → `error [20, "Unknown method", null]`, no disconnect.

## Proof of work
- **MercaHash V2** (Mercatura Core `src/crypto/mercahash_v2.cpp`): 16 MiB scratchpad, 16384 mix steps, SHA3 based.
  Input = the serialized 80-byte header (version LE, prevhash, merkle root, ntime LE, nbits LE, nonce LE), output 32 bytes.
- The 32 output bytes are compared as a **little-endian uint256** against the target (same as Mercatura Core `pow.cpp`,
  same as cpuminer-opt `valid_hash`). The block hash the chain uses is `sha256d(header)` as in Bitcoin.
- **Difficulty units = Bitcoin diff1**: difficulty 1 ⇔ target `0x00000000ffff0000…` ⇔ 2^32 expected hashes. No target
  factor / multiplier (unlike yespower's 65536). Because MercaHash is a CPU algorithm (~50–100 H/s per core), pool
  difficulties are small fractions: **1e-6 = 4,295 hashes per share**. The network difficulty from
  `getblocktemplate.bits` is in the same units (Mercatura testnet ~1e-6 .. 1e-4).
- Share target = `floor(diff1 × 1e9 / round(difficulty × 1e9))`, capped at 2^256−1. Smallest useful difficulty 1e-9.

## Session
```
→ {"id":1,"method":"mining.subscribe","params":["cpuminer-opt-supr/1.0"]}
← {"id":1,"result":[[["mining.set_difficulty","mca000000000001"],["mining.notify","mca000000000001"]],"150a1b2c",4],"error":null}
                                                                                              extranonce1 (4 bytes hex)  extranonce2 size (4)
→ {"id":2,"method":"mining.authorize","params":["tmca1zg99mg6a...57deqd.rig01","x"]}
← {"id":null,"method":"mining.set_difficulty","params":[0.000002]}       (sent BEFORE the authorize result)
← {"id":null,"method":"mining.notify","params":[...]}                      (sent BEFORE the authorize result)
← {"id":2,"result":true,"error":null}
```
- Username = `address.worker`. Address: bech32m `tmca1…` (testnet) / `mca1…` (mainnet), any witness version incl.
  Mercatura PQ v2 (`tmca1z…`) and MercaWeave v3, or base58check P2PKH/P2SH. Worker 1–32 chars of `A-Za-z0-9_-`.
- Password `x`, or `d=N` (fractions allowed, e.g. `d=0.00001`) for a fixed start difficulty within the port band.
- `mining.suggest_difficulty [N]` honoured within the port limits. `mining.configure` → `{}` (no version rolling).
  `mining.extranonce.subscribe` → not supported (extranonce1 is fixed for the session).

## mining.notify
```
params: [job_id, prevhash, coinb1, coinb2, merkle_branch[], version, nbits, ntime, clean_jobs]
         "503f"  64 hex    hex     hex     [64 hex,...]     8 hex    8 hex 8 hex  bool
```
- `prevhash`: the previous block hash as 8 × 32-bit words, each word byte-swapped (classic stratum order).
- Coinbase = `coinb1 ‖ extranonce1 ‖ extranonce2 ‖ coinb2` (non-witness serialization). Coinbase txid = sha256d of
  that. The merkle root is built from the coinbase txid and `merkle_branch` (sha256d pairs, classic). The pool inserts
  the segwit marker/flag and the 32-zero-byte coinbase witness itself when it submits the block.
- `version`, `nbits`, `ntime` big-endian hex as in every Bitcoin stratum; the miner may roll `ntime` forward up to
  2 hours (not below the template's curtime).
- `clean_jobs` true = new block, drop old work. A re-notify with the same prevhash (new transactions / rebroadcast every
  ≤ 55 s / after a difficulty change) carries `false`.

## mining.submit
```
→ {"id":4,"method":"mining.submit","params":["tmca1z….rig01","503f","00000001","6a0b1c2d","1f2e3d4c"]}
                                              worker          job_id  extranonce2  ntime     nonce   (each 8 hex)
← {"id":4,"result":true,"error":null}
```
A 6th parameter (version bits) is ignored. The pool rebuilds coinbase, merkle root and header, computes MercaHash V2
itself (the miner's hash is never trusted) and accepts when `hash ≤ share target` (also against the previous difficulty
right after a VarDiff change). `hash ≤ network target` → the pool submits the block (`submitblock`) and confirms it with
`getblock`.

Errors: `[20, ...]` malformed, `[21, "job not found"]` (stale, not counted for the ban), `[22, "duplicate share"]`,
`[23, "low difficulty share of …"]`, `[24, "unauthorized worker"]`, `[25, "not subscribed"]`.
Ban: 50 % invalid of the last 100 shares (stale excluded) → disconnect; 10 min IP ban off (owner rule).

## Ports / difficulty (pool_configs/mca.json)
| port | use | start diff | VarDiff band | target |
|---|---|---|---|---|
| 8493 | CPU | 2e-6 (8,590 hashes) | 1e-7 … 1e-2 | 1 share / 15 s, retarget 30 s, ×8 jumps |
| 8494 | GPU | 3e-5 (128,849 hashes) | 1e-6 … 1e-1 | same |

## Reference miner
`cpuminer-opt-supr` algo **`mercahash`** (algo/mercahash in ocminer/cpuminer-opt-supr-priv), e.g.
`cpuminer -a mercahash -o stratum+tcp://mca.suprnova.cc:8493 -u tmca1z….rig01 -p x -t 16`
