Testnet5 is live. The latest iteration of Bitcoin’s test network — defined in BIP95, and shepherded to activation by MIT Digital Currency Initiative’s AJ Towns — activated at block height 975744 on Saturday, November 14th. Along with the new test network, which resolves some unpleasant edges with mining testnet4 had, comes the first testnet launch of the long promised version 2 of peer-to-peer mining pool: p2poolv2.
While the launch of testnet5 itself generated buzz, the real fanfare was for the launch of the P2Pool. In particular, miners were encouraged by Second Tech’s CEO Steven Roose and Bitcoin contributor Antoine Poinsot of Chaincode to point their hashrate to the pool: bootstrapping testnet5 while also testing the fledgling decentralized share pool software.
Immediately, several from the open source mining and Stratum v2 developer ecosystem answered the call. Average Gary, co-founder of the Bitcoin Veterans, shared his self-hosted Bitcoin testnet5 mining lab for the pool. He was soon followed by Bitaxe creator Skot9000, who posted a picture of the same dashboard with a classic message from Bitcoin lore: “running p2poolv2”.
V2 of P2Pool is live, and is powering testnet5. What does version 2 bring? And why do we need P2Pool? To find out we talked with Jungly, the lead behind the P2PoolV2 project.
Decentralizing Mining Payouts
P2Pool is a historical decentralized mining pool founded in 2011 as a first response to tackle mining centralization. Instead of relying on a centralized coordinator for managing payouts, P2Pool relied on a distributed, peer to peer network of nodes for mining share accounting and distribution. Basically, miners coordinated directly with each other and verified their rewards without centralized operators.
The original version of that mining pool, however, could not scale because outputs in the coinbase transaction do not scale. Ideally, when a new block is created, a pool includes outputs to all miners on the pool directly in the coinbase transaction the addresses of its miners to distribute the payouts. This would send the funds directly to the owed miners, removing the question of custody from pool payouts.
However, the space available for transactions in each block is capped by consensus to 4MB, which limits the number of outputs that can be created. Filling the block only with outputs in the coinbase transaction would be uneconomical, leaving fees from 3rd party transactions on the table for other pools. At the time the first P2Pool protocol was being developed, even the firmware installed on some of the miners of the day included a hard cap on the number of coinbase outputs.
Beyond the sheer number of pool participants, small miners with little hashrate presented yet another challenge. How do we reward miners providing hashrate but that had only earned a very small fraction of the block reward, under the dust limit?
Finally, orphans were another major problem with on the original distributed share protocol. P2Pool used a linear chain of shares to keep track of the work done by miners, often resulting in shares being orphaned and not accounted for. These orphaned shares represented work done by miners in the pool that wasn’t accounted for.
The original P2Pool protocol was never able to address these issues, and the pool was abandoned around 2019, when their last block was mined.
P2Pool is Making a Comeback
Jungly decided to take on the legacy of P2Pool and is now actively working to reboot it on Bitcoin as version 2. The updated version uses the same concepts and mechanisms the original P2Pool protocol pioneered, while leveraging more recent technological advancements in cryptography and blockchain technology to fix the issues that plagued the first version. By introducing Uncle Blocks, an orphan handling technique invented by Ethereum, and Atomic Swaps, Jungly was able to revive the peer to peer pool accounting protocol.
Let’s dive into how the P2PoolV2 works and how it addresses the technical limitations of its ancestor.
P2Pool Overview
P2Pool is a peer-to-peer network in which every peer is a P2Pool mining node. Accounting is entrusted to every node, and each one of them replicates the so-called sharechain — a dedicated chain, with its own difficulty target, that keeps track of the mining shares that each miner has contributed to the pool.
We will enter into the details later, but every time a valid block is added to the sharechain, it is gossiped to all other nodes and validated by the receivers. Then, nodes need to reach Nakamoto consensus on the state of the sharechain, recompute the Pay-Per-Last-N-Shares (PPLNS) window, and compute the reward due to every miner based on the amount of shares earned in that window..
Each node runs a local Stratum server and participates in the P2P network to communicate with other nodes and maintain the sharechain.
The Stratum server listens to events from the chosen Bitcoin backend — bitcoind classically, or the more recent rbitcoin implementation —, creates the template for the miner to work on, and builds work for mining devices using the Stratum protocol and the state of the sharechain locally available on the node. Any of the shares received from the Stratum server that meets the sharechain’s difficulty, aka the pool difficulty, are then gossiped to the other nodes on the pool’s network.
Each p2poolv2 node can independently verify share accounting since it has access to the global state of the sharechain. Share accounting is used to compute how much of a coinbase reward belongs to each miner in the pool, which in turn is used to build a candidate coinbase transaction. This coinbase candidate is then used by the Stratum server together with an updated difficulty target, computed by the difficulty adjustment algorithm for the sharechain.
A Separate, Shared Chain
The main structure that is found in P2Pool is the sharechain. Each block of the sharechain is called a shareblock, and embeds a Bitcoin block header that carries the pow. In the sharechain, each shareblock represents a mining share that needs to be paid out to the miner adding it to the chain.
The blocks that are added to the sharechain do not meet the difficulty of Bitcoin, but have their own target to reach. In technical terms, these are weak blocks — Bitcoin blocks with a certain amount of pow, but not enough to reach the network difficulty.
The difficulty target in the sharechain is adjusted after each shareblock using an algorithm called Absolutely Scheduled Exponentially Rising Targets (ASERT) — also used by the Bitcoin Cash network — which aims to keep a 10s time interval between each block. The P2Poolv2 team ran simulations to choose the difficulty adjustment algorithm that was most resistant to hashrate oscillation attacks and ASERT had the fastest response time to changes in hashrate.
As previously mentioned, one issue with the original P2Pool protocol design was block orphans. Version 2 introduces uncle blocks, a concept which is inspired by Ethereum Monero’s own version of P2Pool. Uncle blocks improve orphan rate by preventing race conditions in case shares were mined approximately at the same time.
While in the original pool those shares would be orphaned — denying honest miners reward for the work done — P2PoolV2 makes sure those shareblocks are accounted for as uncle blocks, granting the miners of Uncle Blocks 90% of their pow. The remaining 10% is awarded to the actual shareblock that is part of the sharechain, as an incentive to include them in the payout accounting.
Each shareblock can reference up to three uncle blocks, which must not be referencing shareblocks more than three blocks deep. These rules were added to prevent miners from mining on older blocks on purpose, to get rewarded for stale work.
The Shareblock
As in Bitcoin, each shareblock contains a header and a body.
In the header, it is possible to find all the information that is needed to make the sharechain work, such as the hash of the previous shareblock, the hashes of up to three uncle blocks, the difficulty target for the sharechain, the time, the height of the Bitcoin block being mined, and the miner’s Bitcoin and sharechain addresses for payouts.
The shareblock header also includes a full Bitcoin header. This represents the header of the actual weak block being mined on the main chain.
Fields in the sharechain header are hashed together, along with the share witness root, to create a share commitment. This makes sure that a pow can only build one share, and that each sharechain coinbase is unique.
To do so, the share commitment is added as last output to the Bitcoin block coinbase, which in turn is hashed into the Merkle Root, which is used to find the pow. Once a block matching the weak target is found, its hash is included in the shareblock coinbase’s `scriptSig` to make sure it is unique.
Another important part of the header is the coinbase proof. This field contains a proof of the coinbase that was included in the weak Bitcoin block and is used by all the nodes of the P2Pool network to validate or reject the shareblock.
A sharechain’s block’s body is composed of sharechain transactions. The sharechain has its own UTXO and Script-based transaction system, which can be used by miners to freely exchange shares between them. Notably, the shareblock hash does not take the block’s body into account, only the header. This is equivalent to bitcoin, where the block’s transaction set is committed to with the merkle root field in the header.
Finding a Shareblock
When a shareblock is found, it gets propagated to the P2Poolv2 network. Nodes validate the new block by taking the coinbase proof from the header and comparing it to their own local view of the PPLNS window. If they match, the newly found shareblock is added to the sharechain, otherwise it is rejected.
The coinbase is not the only thing that gets validated. Nodes also verify that the pow meets the difficulty target, the timestamp is inside the required window, pow is unique through the share commitment, uncle blocks follow the rules, and that share transactions are valid.
Finally, nodes check that the shareblock body actually matches the header by checking that each share transaction only appears once, their merkle root matches the share witness root that the coinbase proof carries, and the share coinbase is the one included in the header.
If every check is positive, the shareblock is added to the sharechain.
Shares earned need to reach a certain maturity — expressed as number of shareblocks — before being accounted for in the payout distribution system. On testnet5, a share is only taken into account after 6048 shareblocks, approximately the same time period as the 100 Bitcoin blocks constraint on the main chain. This maturity depth is required to resist reorg attacks on the sharechain.
What if the miner’s pow not only achieves the sharechain target, but also satisfies the difficulty requirement of the current Bitcoin blockchain? Finally, it’s payout time!
The Payout Process
Once a block is found that meets the Bitcoin difficulty target, the reward is paid to miners that have earned shares that are accounted for in the current Pay-Per-Last-N-Shares (PPLNS) window. An older share outside this window is considered as expired and not included in the payout.
Each node in the P2Poolv2 network should arrive at the same payout math, using the same data included in the sharechain.
The time window of the PPLNS mechanism is 120,960 shareblocks. At 10s target per shareblock, this is roughly the same time interval of the difficulty adjustment window of the Bitcoin chain — around two weeks.
Miners that have gathered enough shares in the PPLNS window are paid directly from the coinbase, with their own output.
What about small miners, whose payout share falls beneath the required dust limit for an on-chain output? For this, P2Poolv2 introduces a marketplace.
The Futures Market
For distributed mining to work, payouts to small miners that did not accumulate enough shares for an output in the coinbase needs a solution.
Lacking a more complex covenant solution, such as payout trees or JoinPools, today’s solution for small miners is a futures market for shares.
Here’s an example of how the futures market works. Alice, a small miner, is interested in getting paid for her mining work, but she doesn’t own enough shares in the sharechain to merit her own coinbase output. She agrees to trade her shares with Bob in exchange for sats, based on the current market price of those shares.
By acquiring Alice’s shares, Bob is risking that the share pool may not find a new block before the shares he’s bought expire. Each share has an expiry date, which coincides with the moment at which the share exits the PPLNS window — around two weeks after maturity. To account for this risk, Bob may pay more for shares at the beginning of the PPLNS window and less at the end. The chance of the pool finding a block in two weeks is higher than the chance of finding one in a single day, so it’s less risky to buy shares earlier in the PPLNS share window.
Futures markets haven’t been implemented yet and are one of the next features the team will work on before moving to mainnet.
Towards Mining Decentralization
It’s common to hear about the Stratum V2 and OCEAN’s DATUM pool mining protocols, which are touted as solutions for mining decentralization. These are great solutions to make mining more reliable and to allow any miner to make their own decision about what transactions to include in a block template.
While great for decentralizing block construction, neither protocol addresses the money centralization factor: payouts. If the pool you are working with does not grant you your payout, you go broke. WIth the power to deny payouts, pools still have the power to decide a miner’s life or death.
P2PoolV2 addresses this thorny payout issue, by reviving a once defunct decentralized mining pool protocol. Now on testnet5, the mining share protocol is ready for more testing and miners contributing hashrate.
If you want to know more about the project, check out the website, documentation, and GitHub repositories. It is also possible to direct your hashrate to the current instance of P2PoolV2 running on testnet5 by pointing your miners to testnet5.p2poolv2.org or tn5.21m.dev.



