[20 BTC] Multithreaded Keep-alive Implementation in Bitcoind
Even if too late in this thread, I’d like to make some comments. Partly because I feel some guilt over the notorious ‘getwork’ RPC call.
It was made with only one purpose - to experiment with mining outside of Satoshi’s code. I never imagined it will feed heavy loaded servers in the way it is doing it now. Sadly, it made pooled mining possible and at the same time allowed de-democratization of the mining process. I believe this can be fixed.
Right now, classic ‘getwork’ is re-processing all transactions whenever there are new ones and 60 seconds have passed or when there is new block*(1). Worse, because each worker needs its own hash space, the Merkle tree is recalculated entirely with each request(2)*. When the size of transaction pool (unconfirmed transactions) gets really large, this becomes unfeasible. There were episodes with significant numbers of spam transactions which proved this.
Some months ago I made https://github.com/m0mchil/bitcoin/tree/poolmode
About (1), transaction processing was moved out of the RPC thread (to main.cpp, ProcessTransactions) to make ‘getwork’ always return as fast as possible. For (2) UpdateMerkleTree was introduced to allow only specific branch to be rebuilt (specifically the first one). Bitcoind was creating new thread handle for each connection accepted (I guess it was needed for connection timeout guard) - this was removed (see rpc.cpp, around ‘boost::thread api_caller’) because with pools the server is always used locally, by trusted process(es). Even still single threaded, ‘getwork’ performance improved drastically.
But it is time for a new scheme. I see Gavin’s monitorX (https://github.com/gavinandresen/bitcoin-git/tree/monitorreceived) patch as a good candidate. We need something like ‘monitorTransactionPool’ to push whenever there is change in the set of transactions currently ready to be included in a block.
Also, pools should be changed to allow miners to just prove they included pool’s coin base in the block they solve. This is possible by sending the transaction with pool’s address in it and the next Merkle branch. Then miners will have complete control over which transactions to include and which block chain to build on.
I am intending to have this implemented soon.
