P2Pool v2 for Bitcoin Cash: decentralized mining built for big blocks

I’ve been porting P2Pool v2 to Bitcoin Cash, together with Pickaxe (a mining app) and SV2 work in Knuth. It is alpha and runs on chipnet only. This is why I did it, where it differs from the Bitcoin version, and what is still open.

Repo: https://github.com/CyberAshven/BitcoinCash-p2poolv2

Why P2Pool, and why v2

Most BCH hashrate goes through a few pools, and the operator picks the transactions, holds the rewards and decides who mines. The alternative is solo mining, where a Bitaxe waits decades for a block. P2Pool takes the operator out. Each node builds its own template from its own BCH node, and the nodes keep a chain of shares, which are blocks that meet an easier target. When any node finds a block, its coinbase pays everyone in the recent window by their work (PPLNS). Nobody holds money for anyone else, and every node checks every payout.

P2Pool v1, written by Forrest Voight (forrestv) in 2011 and later kept going on BCH by @jtoomim, proved the idea and then faded: Python 2, 60 second shares, orphaned shares lost, and a hard fork for every change. P2Pool v2 is a Rust rewrite for Bitcoin by pool2win and others. I ported it to BCH and brought back the v1 ideas that worked.

P2Pool v1 on BCH This fork
Code Python 2 Rust
Share period 60 s 10 s
Stale shares lost paid 9/10 as uncles (a design from upstream v2)
Share difficulty retarget every 200 shares aserti3-2d
Coinbase payouts ~4,000 outputs, tail dropped ~29,400 direct, the rest through a covenant tree
Block size hard-coded 32 MB whatever the node says (ABLA)
Operator fee redirected shares an ordinary payee, capped at 10%

How Pickaxe, Knuth and P2Pool fit together

   native SV2              with Pickaxe

   SV2 ASICs               SV1 or SV2 ASICs
       β”‚                          β”‚
       β–Ό                          β–Ό
   your Knuth                  Pickaxe ◄── your Knuth
       β”‚                          β”‚
       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    β”‚  SV2 + Noise, Job Declaration,
                    β”‚  Coinbase-Only recommended
                    β–Ό
               P2Pool node ◄── share chain ──► other P2Pool nodes
                 β–²     β–²       TCP or Tor onion
   SV2 ASICs β”€β”€β”€β”€β”˜     └── templates over SV2 from
   with no node            Knuth beside the P2Pool node

When everything speaks SV2, Pickaxe isn’t needed. Your Knuth serves your SV2 ASICs over the Mining Protocol, declares its own template to the P2Pool node with its Job Declaration client, and broadcasts the block itself. That client is Coinbase-Only by default, which is the mode I recommend: the P2Pool node sees only the coinbase, never your transactions. A declarator whose transactions the node never sees could withhold blocks, so a P2Pool node takes Coinbase-Only from its own computer by default and from the addresses its operator adds. SV2 ASICs with no node of their own connect straight to a P2Pool node and mine on the templates its Knuth pushes over SV2 as soon as the tip or the fees change. BCHN and BCHD work there too, through getblocktemplate polling.

Pickaxe covers the rest, and it is built around BCH ASICs. It is a Stratum V1 and V2 server and proxy, so SV1 ASICs can mine on P2Pool too, it can declare jobs from your own node the same way, and it installs and runs a P2Pool node, much like Gupaxx does on Monero. When it mines BCH it also merge-mines minable CashTokens such as SAFA with the same hashes, so an ASIC earns tokens on top of BCH for no extra work. tSAFA is live on chipnet. A Coinbase-Only job carries no token leaves, so merge mining runs on Full-Template and pool-built jobs.

Plain SV2 stops at 65,535 transactions and 16 MiB per message, below the 32 MB floor, and a standard JD client can’t build a P2Pool coinbase. So P2Pool, Pickaxe and Knuth share two BCH extensions of our own, on by default: 0x4C54 pages templates and declarations past those limits, and 0x5052 gives a JD client the payout outputs from the share chain. I proposed the payout extension to sv2-spec (#249). It was closed: the reviewer argued that a miner should run its own share-chain node instead, and that the repository specifies SV2 for Bitcoin, so an extension with no Bitcoin adopter is out of scope. So we maintain both ourselves.

The Template Provider is merged in Knuth 1.8.0 and later (built with the sv2 option). Mining channels, the JD client, Noise and the extensions are open Knuth PRs. With them applied on GitHub runners, a 100,001-transaction, 18.7 MB block went from Knuth through P2Pool and back, and was accepted. With Knuth as the JD client, 0x4C54 declared 100,000 transactions and the block paid the PPLNS split.

Where I diverge from upstream

Upstream is built for Bitcoin, with scarce block space, small coinbases and Lightning. BCH is different, so many parameters moved:

Upstream P2Pool v2 BCH fork
Share period 10 s 10 s
Difficulty aserti3-2d, anchored at genesis aserti3-2d, anchored at the parent of each share
PPLNS window fixed 120,960 shares (~14 days) the work of 3 BCH blocks, at most 120,960 shares
Payout maturity 6,048 shares 100 shares, like the BCH coinbase
Payouts per block ~500 outputs, with a raffle for the tail (proposed) ~29,400 direct, then a keyless tree
Small miners Hydrapool mode: one operator, vardiff weak shares and payout levels
Coinbase merkle branch up to 16 levels up to 32
Largest message between nodes 1 MiB about 2.1 MiB
Miner protocol Stratum V1 Stratum V2 required, V1 opt-in
Public node fee 0% default, at most 2% 1% once the operator sets a fee address, at most 10%
Share trading Lightning HTLC on P2SH32
Nodes Bitcoin Core 29+ Knuth over SV2, BCHN, BCHD

No transaction gets bigger than 1 MB. The largest message just bundles a coinbase of up to 1 MB with up to 200 KiB of share transactions and 960 KiB of weak shares.

Small miners took the most work. With one share difficulty, a small miner finds fewer shares as the pool grows and gets paid in big, rare lumps. Upstream answered with Hydrapool, which brings an operator back. My first version had Monero-style main and mini chains, but a second chain only splits the pool. What I settled on is one chain where a share can be up to 64 times harder than the ASERT minimum, plus weak shares and payout levels. Weak shares are proofs that miss the share target but meet an easier one; later shares carry them (up to 640 per share, and more than 64 only while small miners ask) and they are credited by their work. With payout levels, a slice too small to pay goes into a draw in the same block, at a level the miner picks (1,092 to 69,888 sat, default 17,472), so nobody gets dust and nobody is owed anything.

A simulated 1.2 TH/s Bitaxe next to 50% industrial hashrate (monthly swing / payments a month):

Pool size (share of BCH) 1% 10% 30%
Main + mini chains 0.29 / 45.8 0.92 / 4.7 1.57 / 1.5
One chain, plain ASERT 0.39 / 24.9 1.28 / 2.4 2.28 / 0.8
Band + weak shares + levels 0.20 / 25.2 0.27 / 24.8 0.39 / 24.0

The Bitaxe gets paid about the same at 1% or 30% of BCH. Weak work is left out of fork choice, since counting it in moved the gain of a refusing coalition by at most 0.12 points, and the default level loses 0.85% to fees. Shorter shares were the obvious alternative, but they go stale more: on 1,000 simulated nodes, 4.2% at 10 s, 7.8% at 5 s, 17.8% at 2 s and 30.7% at 1 s.

For payouts, the limit that matters is the 1,000,000-byte transaction, about 29,400 P2PKH outputs. The coinbase pays the window directly as far as it fits, and the rest goes into a keyless P2SH32 covenant tree with 500 outputs per node, 250,000 payees in two levels. Anyone can broadcast the tree after maturity, and every P2Pool node does. The covenant hashes only the outputs of the spending transaction, because the outpoint and script already commit to that hash. @bitcoincashautist sketched the same commitment in CashScript. I passed on a capped coinbase with a raffle (upstream) or a dropped tail (v1), which leave small miners out; pro-rata over a capped set, which rewards Sybils; balances carried to later blocks, which tie state to blocks that can be orphaned; operator-held balances, which are custody; Lightning, which BCH doesn’t use; and a coinbase size cap, which a BCHN maintainer opposed.

ASERT is anchored at the parent of each share instead of genesis. Both score the same in steady state (942.7 vs 942.4), but in a simulated two-day outage the genesis anchor held difficulty at its ceiling for about 24 hours and left two thirds of the work uncredited, while the parent anchor settled in 74 minutes with 3.7% uncredited. I compared LWMA, DGW and DigiShield too: twelve hours after a farm left, LWMA-45 still hadn’t come back down for a Bitaxe, where ASERT took 2.7 hours. The window is the work of 3 BCH blocks (SPREAD from v1), so a share misses every block 5% of the time, against 13.5% with K = 2. D comes from the header bits of the paying share, the one value every node agrees on. Maturity is 100 shares, like the BCH coinbase, which cuts the wait for a first payout at 10% of BCH from 185 hours to 2.8 hours.

SV2 is required, because SV1 sends logins, payout addresses and jobs in plain text. With Noise and a pinned authority key, nobody in the middle can swap jobs. SV1 stays opt-in for a local network the miner controls. A share with more than 50,000 bytes of coinbase outputs travels without them and peers rebuild them from the window; weak shares go by hash with a 400 ms prefill. In simulation that took a 29,402-payee coinbase from 25% stale shares to 2.6%.

Smaller choices, and what I passed on
Chosen Passed on Why
Share trading by HTLC on P2SH32, one right per output Lightning; proportional rights A few hundred sat and one block on chain; proportional rights allow endless slicing
Merge-mined CashTokens shares: one 53-byte commitment for any number of tokens One output per token One output covers them all; peers check only the format
Intervals stored per header in CHIP-2025-03 ticks Hard-coded intervals, per-process ticks Nodes can’t disagree about intervals; chipnet has had one-minute blocks since 2026-11-15
A share pays only if its BCH header is on the chain or one block off Rejecting all stale work A hostile fork gets paid for two blocks at most
No block limit of our own; ABLA comes from the node Hard-coded limits Consensus lives in the pool, policy in the node
16 outgoing peers spread over network groups 6 in v1, 8 in BCHN 1,000-node sim: stale shares 2.30% β†’ 2.00%
libp2p connection limits checked before request-response The upstream order Requests stopped vanishing; reported as rust-libp2p#6778 and p2poolv2#809
Share chain over Tor onion, onion-only mode Clearnet only Two nodes linked only by real onion services pass in CI
Share-owner key kept apart from the payout address Deriving it, or the node picking it A payout address may be receive-only; one key on two chains
Uncle counted once (upstream documents it, this fork enforces it) Crediting an uncle per nephew Keeps the window simple
Share chain only Hydrapool mode No operator, on purpose

Big blocks and ABLA

P2Pool adds no block limit of its own. The limit comes from the node, sizes are u64, merkle branches go up to 32 levels, 0x4C54 pages past the plain SV2 caps, and the covenant tree takes the payees that don’t fit in the coinbase. The one gap left is firmware. SV1 firmware and plain SV2 extended channels have small coinbase buffers, so P2Pool closes a plain extended channel cleanly once the coinbase outgrows it, at about 1,900 payees. SV2 standard channels never show the device a coinbase, so they aren’t affected.

What comes from BCH and from upstream

Share difficulty uses aserti3-2d, which upstream picked and BCH has used for blocks since November 2020. The shares form a DAG, also from upstream. A share can name up to three uncles, which are valid shares that lost a race at the same height. Each uncle is paid 90% of its work, the share that names it gets the other 10% as a bonus, and an uncle can be named only once, so a miner on a slow link or caught in a hashrate swing still gets paid. Upstream also counts uncle work in fork choice, and our selfish-mining model backs it up: with 45% of the pool and gamma 0.5, an attacker gains 19.0% under these rules, 55.7% if uncles are paid but left out of fork choice, and 67.5% under Bitcoin rules. Below 30% of the pool, withholding gains under 1%.

Upstream also load-tested its Stratum V1 server, which this fork shares, against CKPool with JMeter. Each simulated ASIC submitted a share every 3 seconds, and a mock bitcoind answered a submitblock for every one, on a Ryzen 7 8745H:

Load P2Pool v2 errors CKPool errors P2Pool v2 submit, avg / p99 CKPool submit, avg / p99
100 miners, 60 s 0 of 1,977 0 of 1,977 1.3 / 3 ms 1.3 / 2 ms
1,000 miners, 60 s, 10 s ramp-up 42 of 19,452 158 of 18,523 0.4 / 1 ms 0.4 / 2 ms
5,000 miners, 300 s, 90 s ramp-up 0 of 432,710 112,865 of 432,694 0.3 / 1 ms 0.4 / 2 ms

At 1,000 miners the errors were connections timing out in the ramp-up, about 2% for P2Pool v2 and 8% for CKPool, whose accept loop is single-threaded. At 5,000, CKPool turned away 27% of submits as stale jobs, where P2Pool v2 takes slightly stale job ids. A CPU-native build measured the same as the default one, since the work is I/O-bound.

The rest comes from BCH: ABLA, introspection, P2SH32, the 2025 VM limits and loops for the payout tree, CashTokens for token shares, CHIP-2025-03 ticks, and CashAddr, CTOR, Schnorr and SigChecks.

Some setup tests

What Result Setup
Check one share, 1k / 10k / 100k payees in the window 6.4 / 38 / 362 ms release build, one core
Load an 18,000-share window 126 s β†’ 0.5 s local
Rebuild a share relayed without payouts 0.55 ms (34 KB) to 20 ms (1 MB) 12-node swarm
Relayed share message 23.4 KB β†’ 4.7 KB 12-node swarm
Chain checks per share / shares missing the chain 8 β†’ 1 / 13.1% β†’ 2.9% 12-node swarm
Share spread on slow and Tor-like links 4.7 s β†’ 0.9 s and 11.8 s β†’ 3.1 s netem
Stale shares across the relay changes 4.26% β†’ 1.99% 1,000-node simulation
Real Tor onion up in 8 s, chains met within 72 s CI
Largest template through Knuth 100,001 transactions, 18.7 MB, accepted regtest
Chipnet, 2026-11-18 to 2026-12-03 6,111 of 21,942 blocks (~28%) live

Nothing has been measured on mainnet yet, nor propagation over real Tor, coinbase limits in stock ASIC firmware, or the payout tree and share trading on chipnet.

Knuth

Knuth is built for speed, with UTXO-Z storage, parallel validation and compact data layouts, and it keeps no transaction or address index, which suits a pool that wants many cheap nodes. A confirmed transaction is looked up by its block hash, which Rostrum passes in from its own records, so neither side needs a transaction index. Wallet filters are built from the block on request, and the opt-in compact-filter header store takes about 64 bytes per block. Blocks are in flat files, the UTXO set is in UTXO-Z, and LMDB only holds the small stuff. The Knuth README puts a full mainnet sync under an hour on typical hardware. It is C++23 with a C API and JS and WASM bindings, with SOCKS5, Neutrino and BIP37 as optional builds. SV2 is still work in progress: the Template Provider is merged, and the rest is in the open PRs below.

I’ve opened 111 PRs on Knuth, 47 merged and 36 open. The merged ones cover the JSON-RPC that pools and explorers need, the SV2 Template Provider, compact blocks, long-poll templates, Neutrino, BIP37, script filter type 1 and outbound SOCKS5.

Open Knuth PRs (36)
Area PRs
SV2 #807 Noise; #817 mining channels; #832 JD client; #833 JD failover; #834 0x5052; #835 0x4C54 for JD; #879 0x4C54 for templates; #880 higher-fee template on the same tip; #881 0x0002 worker hashrate; #1012 coinbase tag
Tor and I2P #808 I2P via SAM; #993 JD upstreams over Tor and I2P; #1005 Tor and I2P for every failover pool, with a per-route latency limit; #1129 I2P and Tor v3 peer addresses
Light wallets #1004 serve script filters; #1040–#1042 filter matching, store and scan; #1044 block checks; #1045 wallet support from peers without revealing what it watches; #1048 browser-node wallets; #1087–#1091 filter type 2 and wallet support; #1093 serve type 2
Explorer #1001 fees in getblock; #1007 getblockstats; #1009 getrawtransaction verbosity 2
CHIP-2025-03 #1107 BIP34 gate; #1108 parking; #1109 FTL, peer policy and template bounds; #1110 172,800-tick pruning window
Other #805 header inclusion proofs (CHIP-2026-02); #1083 null RPC params

Where it stands

It is alpha and chipnet only, and the first chipnet block was 328,451 on 2026-10-18. P2Pool v0.0.1-alpha binaries are out for Linux (x86_64 and ARM64), macOS on Apple Silicon and Windows. Pickaxe v0.0.5 runs on Windows, Linux, macOS, the browser, HiveOS, mmpOS, RaveOS and Docker. Every node serves a web dashboard designed by @CashDragon. Still to come: mainnet, the payout tree and share trading on chipnet, and stock ASIC firmware that handles large coinbases.

Open research

Three issues are open, and anyone can join by commenting, running a chipnet node or sending a PR.

#79, small miners in a big pool. The band, weak shares and payout levels have run on chipnet: over 26 hours there were 7,931 shares, 748 of 750 weak shares were carried, and 123 blocks were accepted. Upstream hit the same problem when a 200 TH/s S21 joined about 30 TH/s of NerdAxes, and answered with Hydrapool and a payout raffle; pool2win left nested share chains for later. Still open: the 1% carrier cut is a small cost to small miners, and no rule saves a 1.2 TH/s miner at Bitcoin-level hashrate.

#175, share ownership. Shares belong to a separate share key that the miner keeps. Upstream keeps that key on purpose and is building a descriptor wallet with an Electrum server for it. BCH can go further: ownership as CashTokens NFTs in ordinary wallets, transfers and expiry enforced by covenants, wallet-connect style signing, and shares usable in AMMs or as collateral, without custody or duplicate claims, and with the wallets people already use.

#194, transactions that relay drops. A valid but non-standard transaction never reaches independent template builders, whatever its fee. The idea is to broadcast a small claim (txid, fee, size, expiry) with a hashcash-style proof of work. Each listener sets its own bar, fetches the transaction over the same connection, checks it and passes it to pool peers, and since PPLNS shares the fee, passing it on pays better than hoarding. Upstream has no position on it and nothing is built, so it is the most open of the three.

Room for others

The pool is a base layer. Apps can hold share ownership as tokens, show and trade shares in wallets, and run markets for payout rights, and explorers can already group pool blocks by the β€œP2Poolv2” coinbase tag. Any SV2 Template Provider can feed a P2Pool node, but a share-chain coinbase has no output for a provider, so how to pay them is still open. A public P2Pool node takes a fee as an ordinary payee in the coinbase: 1% once its operator sets a fee address, and never more than 10%, which the share chain enforces. Hosted Pickaxe can charge pool and hosting fees. And Knuth nodes serving light wallets, Tor and I2P links and explorers are services anyone can run.

Thanks to Forrest Voight and @jtoomim for v1, pool2win and the upstream P2Pool v2 developers, @fpelliccioni for Knuth and for the reviews, @bitcoincashautist for the payout commitment idea, and @CashDragon for the node dashboard.

Docs: why P2Pool v2, plan and decisions, small miners, hybrid payouts and known attacks.

3 Likes

This one, although I think it’s a long-term research and solution would create an amazing decentralized relay layer which also could create a market to exploit for non standard transactions as long as you have some PoW for it.