Changeset View
Standalone View
src/miner.cpp
| Show All 29 Lines | |||||
| #include <queue> | #include <queue> | ||||
| #include <utility> | #include <utility> | ||||
| #include <boost/thread.hpp> | #include <boost/thread.hpp> | ||||
| #include <boost/tuple/tuple.hpp> | #include <boost/tuple/tuple.hpp> | ||||
| static const int MAX_COINBASE_SCRIPTSIG_SIZE = 100; | static const int MAX_COINBASE_SCRIPTSIG_SIZE = 100; | ||||
| // Magic for an UNVERFIED UTXO commitment. | |||||
| // This should move to consensus when verifying | |||||
| static const char MAGIC_UTXO_COMMITMENT[4] = {'U', 'T', 'X', '0'}; | |||||
jasonbcox: The last char is a zero instead of an 'O'. Is that intended? | |||||
| ////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////// | ||||
| // | // | ||||
| // BitcoinMiner | // BitcoinMiner | ||||
| // | // | ||||
| // | // | ||||
| // Unconfirmed transactions in the memory pool often depend on other | // Unconfirmed transactions in the memory pool often depend on other | ||||
| // transactions in the memory pool. When we select transactions from the | // transactions in the memory pool. When we select transactions from the | ||||
| ▲ Show 20 Lines • Show All 145 Lines • ▼ Show 20 Lines | BlockAssembler::CreateNewBlock(const CScript &scriptPubKeyIn) { | ||||
| CMutableTransaction coinbaseTx; | CMutableTransaction coinbaseTx; | ||||
| coinbaseTx.vin.resize(1); | coinbaseTx.vin.resize(1); | ||||
| coinbaseTx.vin[0].prevout = COutPoint(); | coinbaseTx.vin[0].prevout = COutPoint(); | ||||
| coinbaseTx.vout.resize(1); | coinbaseTx.vout.resize(1); | ||||
| coinbaseTx.vout[0].scriptPubKey = scriptPubKeyIn; | coinbaseTx.vout[0].scriptPubKey = scriptPubKeyIn; | ||||
| coinbaseTx.vout[0].nValue = | coinbaseTx.vout[0].nValue = | ||||
| nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus()); | nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus()); | ||||
| coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0; | coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0; | ||||
| AddUtxoCommitment(coinbaseTx); | |||||
| pblock->vtx[0] = MakeTransactionRef(coinbaseTx); | pblock->vtx[0] = MakeTransactionRef(coinbaseTx); | ||||
| pblocktemplate->vTxFees[0] = -1 * nFees; | pblocktemplate->vTxFees[0] = -1 * nFees; | ||||
| uint64_t nSerializeSize = | uint64_t nSerializeSize = | ||||
| GetSerializeSize(*pblock, SER_NETWORK, PROTOCOL_VERSION); | GetSerializeSize(*pblock, SER_NETWORK, PROTOCOL_VERSION); | ||||
| LogPrintf("CreateNewBlock(): total size: %u txs: %u fees: %ld sigops %d\n", | LogPrintf("CreateNewBlock(): total size: %u txs: %u fees: %ld sigops %d\n", | ||||
| nSerializeSize, nBlockTx, nFees, nBlockSigOps); | nSerializeSize, nBlockTx, nFees, nBlockSigOps); | ||||
| Show All 21 Lines | LogPrint( | ||||
| BCLog::BENCH, "CreateNewBlock() packages: %.2fms (%d packages, %d " | BCLog::BENCH, "CreateNewBlock() packages: %.2fms (%d packages, %d " | ||||
| "updated descendants), validity: %.2fms (total %.2fms)\n", | "updated descendants), validity: %.2fms (total %.2fms)\n", | ||||
| 0.001 * (nTime1 - nTimeStart), nPackagesSelected, nDescendantsUpdated, | 0.001 * (nTime1 - nTimeStart), nPackagesSelected, nDescendantsUpdated, | ||||
| 0.001 * (nTime2 - nTime1), 0.001 * (nTime2 - nTimeStart)); | 0.001 * (nTime2 - nTime1), 0.001 * (nTime2 - nTimeStart)); | ||||
| return std::move(pblocktemplate); | return std::move(pblocktemplate); | ||||
| } | } | ||||
| void BlockAssembler::AddUtxoCommitment(CMutableTransaction &coinbase) { | |||||
| CTxOut out; | |||||
| uint256 hashCommit; | |||||
| CUtxoCommit *commit = pcoinsTip->GetCommitment(); | |||||
| if (commit == nullptr) { | |||||
| return; | |||||
| } | |||||
| hashCommit = commit->GetHash(); | |||||
| delete commit; | |||||
| out.nValue = Amount(0); | |||||
| out.scriptPubKey.push_back(OP_RETURN); | |||||
| out.scriptPubKey.push_back(0x24); // pushdata | |||||
jasonbcoxAuthorUnsubmitted Not Done Inline ActionsOP_PUSHDATA1,2,4 are 0x4c, 0x4d, 0x4e. What is 0x24? If the comment is inaccurate, please reword. jasonbcox: OP_PUSHDATA1,2,4 are 0x4c, 0x4d, 0x4e. What is 0x24? If the comment is inaccurate, please… | |||||
MengerianUnsubmitted Not Done Inline Actions@jasonbcox Op Codes 0x01 to 0x4b (1-75) mean that number of bytes get pushed to the stack. So in this case, op code 0x24 means the next 36 bytes get pushed to the stack. A good reference list of Op Codes here: https://en.bitcoin.it/wiki/Script Mengerian: @jasonbcox Op Codes 0x01 to 0x4b (1-75) mean that number of bytes get pushed to the stack.
So… | |||||
jasonbcoxAuthorUnsubmitted Not Done Inline ActionsPerhaps this comment would better serve as something like: // push 36 bytes on the stack Even better, it should detail what those bytes expect to contain. Looking below, it appears to be some number of bytes for the magic (4-bytes according to src/miner.cpp) + 32 bytes for the commitment. Additionally, this block of code will blindly accept longer magic values and commitment hashes, yet the push value here is hard-coded. Please fix this. jasonbcox: Perhaps this comment would better serve as something like: `// push 36 bytes on the stack`… | |||||
| // Add prefix | |||||
jasonbcoxAuthorUnsubmitted Not Done Inline ActionsInclude expected prefix length (4-bytes) in the comment. Either enforce it or change the bytes-to-push value to be dynamic based on the input. jasonbcox: Include expected prefix length (4-bytes) in the comment. Either enforce it or change the bytes… | |||||
| for (char c : MAGIC_UTXO_COMMITMENT) { | |||||
| out.scriptPubKey.push_back((uint8_t)c); | |||||
| } | |||||
| // Add commitment | |||||
jasonbcoxAuthorUnsubmitted Not Done Inline ActionsInclude expected commitment length (32-bytes). Either enforce it or change the bytes-to-push value to be dynamic based on the input. jasonbcox: Include expected commitment length (32-bytes). Either enforce it or change the bytes-to-push… | |||||
| for (uint8_t c : hashCommit) { | |||||
| out.scriptPubKey.push_back(c); | |||||
| } | |||||
| coinbase.vout.push_back(out); | |||||
| } | |||||
| bool BlockAssembler::isStillDependent(CTxMemPool::txiter iter) { | bool BlockAssembler::isStillDependent(CTxMemPool::txiter iter) { | ||||
| for (CTxMemPool::txiter parent : mempool.GetMemPoolParents(iter)) { | for (CTxMemPool::txiter parent : mempool.GetMemPoolParents(iter)) { | ||||
| if (!inBlock.count(parent)) { | if (!inBlock.count(parent)) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 427 Lines • Show Last 20 Lines | |||||
The last char is a zero instead of an 'O'. Is that intended?