First exchange listing: the NonKYC campaign needs 100 backers by 2027-02-04, and $5 counts as one. Pledges are donations, refunded if the listing does not happen. Back the campaign →

Bitflash Download

Docs · P2Pool

P2Pool inside the node: pooled mining with no pool

Status: implemented (steps 1 to 6 below) and proven on testnet (step 7): a block found through it paid two miners, matured and was spent. Mainnet consensus does not change; this ships in an ordinary release.

Why

Today almost every Bitflash miner mines through one pool. Its operator receives every coinbase and pays the miners afterwards with ordinary transactions. That operator can:

All of that sits on one machine. Pooled mining is still needed: alone, a small miner waits weeks between blocks. What has to go is the pool.

The idea in one paragraph

Every node that mines keeps a second, faster chain: the share chain. A share is a block template whose RandomX hash meets a much easier target, one share every ~10 seconds across all miners. Every template pays, in its own coinbase, everyone who found a share in the recent window, in proportion to the work of each. All participating nodes compute that payout list from the same share chain, so they agree on it byte for byte. When some miner's share also meets the real difficulty, that template is a valid Bitflash block, and it already pays everyone. Nobody holds anybody's coins, and there is nobody to ask.

This is the design of P2Pool for Bitcoin (2011) and for Monero (2021, also RandomX), adapted to Bitflash.

Shares

A share carries:

The coinbase commits to the share chain: its scriptSig, after the block height (rules v2 / BIP34), carries "p2p" and the 32-byte hash of the share's own data (ShareData: its parent, uncles, share height, target and payout script). The PoW therefore cannot be lifted from one share chain onto another.

Valid share: the header hashes (RandomX, the main chain's own PoW v2) under the share target; the coinbase outputs equal the payout list computed from the parent; the parent and uncles are known (a missing one is fetched, never held against the sender); the timestamp is sane; the coinbase states its block height (rules v2), which sets the subsidy it must pay, and meets every rule a block's coinbase meets; the payout script is a P2PKH or P2SH address, nothing else (every payout script of the window becomes an output of every coinbase, so a script of signature operations would push every P2Pool block over the block's limit).

A share is judged on the share chain and itself alone, never on the main blocks a node holds. Its nBits decides only whether its work is also a block, which is the main chain's business. Checking nBits against the main block it was mined on made two honest nodes, one holding that block and one not, judge the same share differently and part ways; taking nBits on the share's word let anybody name an easy one.

How far behind the main tip a share was mined does not decide its validity: that would depend on when the share arrived, and two honest nodes would disagree about the same share. On testnet that is exactly what split two nodes, over an uncle fetched minutes after it was mined. Work on an old main block is still work the window pays; mining on the tip is the miner's own interest, and a node's templates are always on its tip.

Share target: a chain's first 720 shares are at the floor (the network's easiest target); from then on it retargets every share over the last 720 to keep 10 seconds per share, never easier than the floor. It is not held to the block target: when blocks are the easier of the two, the miner is given the block target, and work that meets it but not the share target is a block and not a share.

Chain choice: most cumulative share work, uncles included, between lines that meet in the shares a node holds. Two lines that do not meet (a node that mined alone before it heard the network, or was cut off for long) began their sums at different shares, so a long run alone would outweigh the network for good; those are weighed on the work of their last 2160 shares instead. Work is summed share by share above the point where two lines meet. The tip is always a share checked in full (see Starting), and a line whose newest share is more than 30 minutes old by this node's clock does not replace a livelier tip: a share's time has no lower bound, so the network's own line of some days ago, when difficulty was higher, could otherwise be played back to a starting node. This decides which line a node mines on, never whether a share is valid.

Uncles: a share found at the same time as another is not wasted. The next share may reference it as an uncle (up to 3 shares back); the uncle is paid 80% of its work, the 20% going to the share that included it, so including uncles pays.

Payouts (PPLNS)

The coinbase of every template pays the last 2160 shares (about 6 hours at 10 s), each in proportion to its difficulty, grouped by payout key:

Size: 1 MB blocks hold the coinbase easily. 1000 distinct miners in a window is ~34 KB of outputs.

Maturity: coinbase outputs can be spent after 100 blocks, as every coinbase; the wallet counts them as balance after 120, as it does for any.

Network

Starting

A node that starts, or hears a share far past its own tip whose parent it lacks, asks a peer for its line (p2psync) and takes the answer for five minutes only. The answer is the line behind the peer's tip, about 2900 shares with their uncles:

The node keeps its line in p2pool.dat and reads it back the same way.

Memory: a node keeps the shares a window, a retarget and the uncle rules can reach (about 2900 behind the tip). Past 11,584 shares it drops the lightest side lines; it never refuses a share for want of room, since that would make a share's validity depend on what else a node holds.

Mining

Options:

optionwhat it does
-p2poolturns P2Pool on
-p2poolport=Nthe stratum port, 1025 to 65535 (default 3333)
-p2poolpayto=ADDRESSwhere payouts go (default: a fresh address of the node's own wallet, changed every 24 hours)
-p2poolbind=IPalso serve the stratum on this private address, for miners on your local network (default: none, 127.0.0.1 only)
-p2poolbridgebridge mode (below): the stratum on this node's onion at the P2P port + 1, every share paying the miner's own login
-pooldrainpay out the pending rounds an operator pool left in this data directory, and start no new ones (below)

Mining from other machines on your local network

One node can take the hashrate of every machine in the house. On the node, add -p2poolbind with the node machine's own address on the local network:

bitflash-node -p2pool -p2poolbind=192.168.1.10

On each other machine, point the Bitflash Miner or XMRig at that address:

Linux, macOS: P2POOL_HOST=192.168.1.10 ./mine.sh p2pool Windows: set P2POOL_HOST=192.168.1.10 mine.cmd p2pool XMRig by hand: xmrig -a rx/0 -o 192.168.1.10:3333 -u p2pool -p x

The node keeps listening on 127.0.0.1 as well, so a miner on the node's own machine needs no change. For an IPv6 address, put it in brackets for the miner: P2POOL_HOST=[fd00::10], -o [fd00::10]:3333.

What to know before turning it on:

Bridge mode: an operator pool's miners on pool zero

-p2pool -p2poolbridge turns an operator pool into a P2Pool node without its miners changing anything. It is meant for one move, the central pool's miners onto pool zero, until they run nodes of their own; it is not a way to run a pool.

The old ledger: -pooldrain

An operator pool owes its miners for every round it found until the round matures (120 blocks). -pooldrain, with -p2pool, loads that ledger (pending_payouts.json, pool_rounds.json in the data directory) and runs the operator's payout thread on it: each round is paid from the node's wallet once it matures, only if its block is still in the main chain, and recorded and recovered after a restart exactly as before. P2Pool's blocks pay their miners themselves, so no new round is ever added. The log says how much is owed at start and when the ledger is empty (paid, or its last round dropped because its block left the main chain); pool_status.json keeps listing the pending rounds (node.drainingLedger), with node.pool set to p2pool-bridge and a fee of 0.

Two things it does not do. It does not pay the round that was still open when the operator stopped: those shares were never in a block, and an operator restart has never paid them either. And it must run on the one ledger in use: a payout already made is recognised only by the wallet transactions of the node that made it, so -pooldrain on a copy of the ledger while the operator is still paying from its own would pay twice.

Privacy

central pool (today)P2Pool in the node
who sees your hashratethe operatornobody: a share says nothing about who sent it, and arrives over Tor
who holds your coinsthe operator, until he paysnobody: the block pays you
your payout addressin the operator's paymentin the coinbase, public, as with any payment. A fresh address every 24 h, by default, unlinks the days
who picks the transactionsthe operatorevery miner's own node

What changes for whom

Attacks considered

Implementation plan

  1. Share data structure, serialization, id, verification (with selftests and a fuzz target for the share parser).
  2. Payout list (PPLNS window, grouping, sorting, dust carry-over) as a pure function, tested against hand-computed cases.
  3. Share chain store, chain choice, uncles, share retarget.
  4. Gossip messages over the peer-to-peer network.
  5. Local stratum serving templates that commit to the share chain.
  6. Bitflash Miner wired to 127.0.0.1:3333.
  7. Testnet: several nodes on several machines, real blocks, payouts checked to the satoshi against the share chain.
  8. Mainnet: release; the central pool stays up in parallel until P2Pool has paid real blocks to several miners; then it is switched off.

Rendered from docs/p2pool.md in the repository. Read the source.