# Stratum on the BLAKE2b Bitcoin chain (XBT / BTCB2)

Endpoint: `stratum+tcp://stratum.awokenlazarus.xyz:23334`
Username: the address to be paid, optionally `address.worker`. Password: `x`.
There is no account and no registration; the username is the payout instruction.

This is stratum v1 over a newline-delimited JSON socket, but the work is a Sia-style
80-byte header hashed with BLAKE2b-256 rather than a Bitcoin header hashed with
SHA-256d. A stock Siacoin ASIC already does exactly this, which is why it needs no
firmware change to mine here. An SHA-256 miner cannot produce a valid share at all.

## Messages

    -> {"id":1,"method":"mining.subscribe","params":["your-miner/0.1"]}
    <- {"id":1,"result":[[notifications],"<extranonce1 hex>",<extranonce2 size>]}
    -> {"id":2,"method":"mining.authorize","params":["<payout address>","x"]}
    -> {"id":3,"method":"mining.suggest_difficulty","params":[<n>]}
    <- {"method":"mining.set_difficulty","params":[<n>]}
    <- {"method":"mining.notify","params":[job_id, prevhash, coinb1, ..., ntime, clean_jobs]}
    -> {"id":n,"method":"mining.submit",
        "params":["<payout address>", job_id, "<extranonce2 hex>", "<ntime hex>", "<nonce hex>"]}

`ntime` is `params[7]` of the notify and is 8 bytes (16 hex chars), not Bitcoin's 4.
A 4-byte value is accepted and zero-padded on the right. `clean_jobs` is `params[8]`.
New sessions start at difficulty 4096 and vardiff moves toward your hashrate from there.

## Building the work

`coinb1` is exactly 39 bytes. `extranonce1 + extranonce2` is exactly 12 bytes.

    sia_prev = tagged_sha256("Bitcoin prevblock header, hashed", reverse(prevhash))
    sia_prev[0:6] = 00 00 00 00 00 00
    root     = blake2b256(0x00 || coinb1[39] || extranonce[12])
    header   = sia_prev[32] || nonce[8] || ntime[8] || root[32]      # 80 bytes
    pow      = reverse(blake2b256(header))

where `tagged_sha256(tag, data) = sha256(sha256(tag) || sha256(tag) || data)`.

If the pool already sends a Sia prevhash in `mining.notify` — its first six bytes are
zero — use it as it stands rather than hashing it again. DATUM gateways do this.

## Share target

The target is a floor-power-of-two ladder, as on Sia, not Bitcoin's compact encoding:
take `bits = difficulty.bit_length() - 1`, start from `ff * 28 || 00 * 4`, and shift
right by `bits`. Above `2**224` it falls back to the Bitcoin-style target. A share is
valid when `pow <= target`.

## What makes a share acceptable here

Payouts are a split coinbase, so the pool hands every gateway the same coinbase output
list before any work goes out, and a share whose coinbase pays anything other than that
list is refused. The current list is public at `/api/coinbaser` — it is the next block's
payout, published before the block exists. See https://pool.awokenlazarus.xyz/tides.

## Running your own templates

A Bitcoin Knots node plus a DATUM gateway pointed here means you build the block
template and choose its transactions; the pool only supplies the coinbase split and
verifies shares. That path pays no fee and is credited a share of the public stratum's
fee on every block found. See https://pool.awokenlazarus.xyz/connect and https://pool.awokenlazarus.xyz/datum-subsidy.
A longer Knots + DATUM walkthrough is at https://convoy.xyz/getstarted
(Chinese: https://convoy.xyz/getstarted?lang=zh).

## Machine-readable pool data

`/api/pool`, `/api/coinbaser`, `/api/blocks`, `/api/found/<blockhash>`, `/api/miners`,
`/api/gateways`, `/api/payouts`, `/api/hardware` — public JSON, no key.
Full reference: https://pool.awokenlazarus.xyz/api
