Stratum Server & Vardiff
Each P2Poolv2 node comes with its own Stratum server, which generates work for the mining rigs and keeps them at a target share interval.
The Stratum implementation closely follows CKPool’s parameters: the 3s share interval and the vardiff algorithm. CKPool is a robust, battle-tested Stratum server, and P2Poolv2 draws on the years of experience captured in its difficulty adjustment algorithm.
Our code base implements the Stratum server in Rust, with extensive test coverage to ease future changes.
Components
The diagram shows a simplified view of the Stratum server’s components.
- Template fetcher
-
Asks bitcoind for a new block template with
getblocktemplate. It fetches one as soon as bitcoind announces a new block over ZMQ (zmqpubhashblock), and polls at a fixed interval in between so that new transactions make it into the work. - Job builder
-
Turns each template into a mining job. The coinbase transaction pays miners according to PPLNS accounting over the sharechain, and each job commits to the current sharechain tip. Every connected miner is sent the new job with
mining.notify. - Vardiff
-
Adjusts each miner’s difficulty so that it submits roughly one share every 3.3 seconds, whatever its hashrate. It follows CKPool’s algorithm and waits for enough shares, or enough time, before changing difficulty, so that it does not overreact to luck.
- Share validator
-
Checks every submitted share against the miner’s current difficulty, and rejects duplicates. Then:
-
a share that meets the pool target is sent to the sharechain, which stores it and relays it to peers;
-
a share that also meets the bitcoin target is a block, and is submitted to bitcoind straight away with
submitblock.
Shares below the pool target still count towards the miner’s measured hashrate and vardiff, but they do not enter the sharechain.
-
Miner Options
Miners pass options in the password field of mining.authorize, as
key=value pairs separated by commas, semicolons, or spaces, for
example d=65536,p2p=tp2pool1p….
| Option | Effect |
|---|---|
|
Asks the stratum server to start at this difficulty instead of the pool default. Useful for a miner whose hashrate calls for a high starting difficulty. |
|
Your miner’s hashrate in TH/s, from which a starting difficulty is worked out.
If both |
|
The P2Poolv2 address that owns your sharechain outputs. Not needed if the node operator has set one for the whole pool. |
Suggested difficulties are kept within the pool’s configured minimum
and maximum. See the configuration documentation in the P2Poolv2
node’s config.toml file.