How to split up the coinbase reward? [ALTCOIN]
This should be an intriguing question/problem for anyone involved with bitcoin development or altcoin development.
Some Context...I'm currently in development of an altcoin based on the bitcoin source code, which is designed to help charities raise capital. It does this by sending 20% of the coinbase reward to a pre-defined wallet address, whenever a successful block is mined by a miner. Lets call this wallet the fund wallet. This 20% is used to fund the charity. As the coin is adopted and mined, this wallet receives a steady stream of coins.
The Part That Works...I have made some changes to the original bitcoin code so that the mining reward can be split over multiple wallets when the coin is mined in the QT wallet.
In src/miner.cpp the coinbase transaction is an object of type CMutableTransaction, which has a vector of outputs called vout.
Now, when a miner mines a block, the coinbase transaction's output is split into two parts. First I resized the vector of outputs:
coinbaseTx.vout.resize(2);
Then I define a hardcoded fund wallet like this:
std::string fundWallet = "A WALLET ADDRESS"; CTxDestination fundWalletDest = CBitcoinAddress(fundWallet).Get(); CScript fundCScript = GetScriptForDestination(fundWalletDest); coinbaseTx.vout[1].scriptPubKey = fundCScript;
Then I simply split the coinbase reward like this:
coinbaseTx.vout[0].nValue = 0.8 * (nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus())); coinbaseTx.vout[1].nValue = 0.2 * (nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus()));
This method seems to work beautifully, and on a network of 100 QT miners, it seems like every coin that the fund is owed is given to it correctly. I also added some code into the validation rules to ensure that blocks whose coinbase transaction vector is less than two in size, or whose second input is not the fund wallet, should be rejected.
The Problem...After the mining difficulty got too high for solo-mining with the QT software, a number of pools started opening and the miners moved to the pools to continue mining my coin.
HOWEVER - When mining in a pool, the coinbase transaction is not being split correctly and the part that should be given to the fund is never arriving. The miners are still getting their 80% of the coinbase reward, but for some reason the 20% that should go to the fund is going missing and never arriving. In fact it is never being written into the blockchain
Pool Mining is Different to QT MiningI am aware that the pool mining is a different section of the code to the QT mining. However, they both access the CreateNewBlock function which includes the new logic. I am not sure why the 20% is being lost.
My QuestionWhy is the pool mining disregarding the 20% block reward for the fund when it accesses the same code which creates the blocks? What do I need to add to the code to ensure that the pool splits the coinbase reward correctly?
http://ift.tt/2CotgJE
Comments
Post a Comment