Stratum Local is a binary
mining protocol for miners on a local network, such as the Bitaxe and
other ESP32 boards: each message is an unpacked Cap'n Proto
StratumMessage, so a microcontroller reads its fields at fixed
offsets, with no JSON or hex to parse. Its reference implementation is a
daemon beside Bitcoin Core, which reaches the node over IPC. bs serves
the protocol itself, from the [stratum_sl] service, as a solo pool:
each job is a template of the next block from the bs transaction pool,
its coinbase pays the address in the miner's user identity (or the
configured one, or outputs of the miner's own), and a share that meets the network target is submitted
as a block.
Each connection is detected from its first bytes, so its transports share one port, and their secure forms share another:
| Port | Default | Protocols |
|---|---|---|
Clear (bind) |
9080 | TCP, WS |
Secure (safe) |
9043 | TLS, WSS |
Over TCP, each message is framed by a 4 byte big-endian length; over WS, each binary message carries one. The protocol's own default ports, 3332 and 4332, are not used, so a miner is given the host and port 9080 (or 9043 for TLS).
1. Setup#
The service is disabled by default. Bind an address, allow connections, and optionally set the payout address:
[stratum_sl]
bind = 0.0.0.0:9080
connections = 10
payout_address = bc1q...
Without payout_address, the user identity of the registration is the
payout: the miner registers as <address> or <address>.<worker>, the
address being the identity up to its first dot. It may be P2PKH, P2SH,
P2WPKH, P2WSH or P2TR, of at most a 34 byte output script, on the node's
network. With payout_address, every block pays that address, and user
identities are free. With miner_outputs, the miner pays itself
(Open coinbase), and user identities are also free.
As with the other services, connections are refused until the chain is
current (Service Settings).
safe serves TLS with cert_path and key_path
(Secure connections).
| Setting | Default | Purpose |
|---|---|---|
stratum_sl.payout_address |
empty | Address paid by the coinbase; empty, the user identity |
stratum_sl.check_blocks |
false | Validate found blocks; false, organize them as a milestone |
stratum_sl.coinbase_tag |
empty | Text carried by the coinbase input script (at most 75 bytes) |
stratum_sl.extranonce_prefix_size |
4 | Coinbase extranonce bytes assigned to each session (at least 4) |
stratum_sl.extranonce_size |
4 | Coinbase extranonce bytes rolled by the miner (at least 1) |
stratum_sl.graffiti_budget |
0 | Graffiti bytes the miner may add to the coinbase input script |
stratum_sl.miner_outputs |
0 | Outputs the miner may add to the coinbase, allocating the reward; 0, the server pays |
stratum_sl.minimum_difficulty |
1 | Share difficulty floor of a session |
stratum_sl.start_difficulty |
0 | Share difficulty of a new session; 0, from the miner's nominal hash rate |
stratum_sl.share_interval_seconds |
10 | Target seconds between shares (0 fixes the difficulty) |
stratum_sl.authorize_timeout_seconds |
15 | Seconds to register before the connection is closed (0 is unlimited) |
stratum_sl.credential |
empty | username:password required at the websocket upgrade |
pool.template_interval_seconds |
30 | Seconds between replacements of the template (0 disables) |
pool.template_fee_increase |
0 | Satoshis of fees a replacement template must add |
Startup fails if extranonce_prefix_size is below 4, extranonce_size
is zero, the tag exceeds 75 bytes, the coinbase input script would exceed
100 bytes, or the minimum difficulty is not positive. An open coinbase
also fails startup if its input script, with the whole graffiti budget,
would exceed 100 bytes, or miner_outputs exceeds 250.
With the service enabled, pool.coinbase_weight and
pool.coinbase_sigops are derived from this coinbase, as for
Stratum v1, the largest of the stratum services
enabled. An open coinbase reserves for the whole graffiti budget and for
miner_outputs outputs of the largest address script, of one sigop each.
Open coinbase#
By default the coinbase is closed: the server pays the reward, and the
miner rolls only the extranonce. A graffiti_budget or miner_outputs
opens it to the miner's additions:
[stratum_sl]
bind = 0.0.0.0:9080
connections = 10
graffiti_budget = 16
miner_outputs = 2
- Graffiti. The miner may add up to
graffiti_budgetbytes to the coinbase input script, after its extranonce. - Miner outputs. The miner allocates the whole block reward, in up to
miner_outputsoutputs of its own, and the server adds only the witness commitment. With only graffiti, the server still pays the reward, and the miner may add only zero value outputs that cannot be spent, such asOP_RETURN. - Extranonce. The miner chooses the size of its extranonce, which begins with the session's prefix.
The input script given the miner ends in a one byte push of 255 bytes, which takes in the rest of the script, so the miner's bytes are never counted as sigops. On a signed signet the coinbase stays closed, since the signature cannot cover the miner's additions.
Credentials#
The protocol carries no credential, and leaves authentication to the
transport. With a credential configured, a WS connection presents it as
HTTP Basic at the upgrade, and a TCP connection, which has no upgrade, is
refused. Without one, any connection may register, so a clear binding
belongs on a trusted local network.
Start difficulty#
A session starts at start_difficulty if set, otherwise at the rate of
the nominal hash rate of its registration: the hash rate times
share_interval_seconds divided by 232. Its floor is
minimum_difficulty. Vardiff then adjusts it, as for
Stratum v1.
2. Messages#
| Message | Direction | Served |
|---|---|---|
RegisterRequest |
miner to bs |
Handled |
RegisterResponse |
bs to miner |
Sent |
SetTarget |
bs to miner |
Sent |
MiningJob |
bs to miner |
Sent |
SubmitShare |
miner to bs |
Handled |
ShareResponse |
bs to miner |
Sent |
A connection is one session, which mines one job stream.
RegisterRequest#
Registers the session, with the miner's user identity, user agent and nominal hash rate. It is sent once, first.
RegisterResponse#
Accepts the session, with the server agent, the network magic of the
node's network and the session's extranonce prefix. It is sent once the
first job is ready, followed by SetTarget and that job.
A registration is rejected, and the connection closed, with
invalid-identity if the user identity is not such an address and
neither payout_address nor miner_outputs is configured, or extranonce-exhausted if no prefix
is free.
SetTarget#
Sets the target of the shares the session submits: the session's difficulty, bounded by that of the block. It is sent before the first job, then only when the target changes.
MiningJob#
A job: the coinbase around the extranonce, the merkle path, the version
and its rolling mask (BIP320, 0x1fffe000), the previous block, time,
bits and height. A new previous block, or a replacement template, issues
a new job.
A closed coinbase is managed by the server: unallocatedSats and
graffitiBudget are zero, the miner adds no outputs or graffiti, and
its coinbase weight budget is only the extranonce. An open coinbase
gives graffitiBudget, a scriptSigLen of zero (the miner sizes its
extranonce), and a coinbaseWeightBudget of the reserved coinbase
weight less that of the coinbase without additions. With miner outputs,
unallocatedSats is the whole reward, and the template outputs are only
the witness commitment.
SubmitShare#
Submits a share: its job, extranonce, version, time and nonce.
ShareResponse#
Answers a share as accepted (with blockFound where it mined a
block), stale (stale-job, a job no longer held), or rejected
(low-difficulty or duplicate). A share that cannot be valid is
answered as rejected and the connection closed: invalid-session,
graffiti-budget-exceeded, unexpected-miner-vouts,
coinbase-weight-exceeded, invalid-scriptsig-length,
invalid-extranonce-prefix, invalid-version-mask or
consensus-invalid.
An open coinbase adds the rules of the miner's additions, each also rejected with the connection closed:
| Reason | Share |
|---|---|
graffiti-budget-exceeded |
Graffiti exceeds graffiti_budget |
malformed-payout-output, payout-output-size-mismatch, unexpected-miner-vouts |
Outputs do not parse as the count given |
script0-prohibited |
An output has an empty script |
dust-output |
A spendable output is below 546 satoshis |
reward-overclaim |
Outputs exceed the unallocated value |
unallocated-funds-prohibited |
Outputs fall short of it, which would burn part of the reward |
invalid-scriptsig-length |
The input script is not 2 to 100 bytes |
coinbase-weight-exceeded |
Additions exceed coinbaseWeightBudget |
coinbase-sigops-exceeded |
Output sigops exceed the reserved coinbase sigops |
3. Miners#
Miners that implement the protocol connect with
stratum-local://<host>:9080, such as the ESP-Miner firmware of the
Bitaxe built from its stratum-local branch. The web miner mines it over
WS, as "Stratum local", at the URL given by stratum_sl.advertise.
On a signed signet the node signs each job's coinbase, so the miner may roll only the nonce: the session's extranonce is assigned whole, the version rolling mask is zero, and the coinbase stays closed (Signet mining).
The session appears in the admin mining registry as
service stratum_sl, channel 1 of its connection, with the user agent
as client and the user identity as its worker.