Changeset View
Changeset View
Standalone View
Standalone View
src/miner.cpp
Show First 20 Lines • Show All 182 Lines • ▼ Show 20 Lines | BlockAssembler::CreateNewBlock(const CScript &scriptPubKeyIn) { | ||||
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; | ||||
// Make sure the coinbase is big enough. | // Make sure the coinbase is big enough. | ||||
uint64_t coinbaseSize = | uint64_t coinbaseSize = ::GetSerializeSize(coinbaseTx, PROTOCOL_VERSION); | ||||
::GetSerializeSize(coinbaseTx, SER_NETWORK, PROTOCOL_VERSION); | |||||
if (coinbaseSize < MIN_TX_SIZE) { | if (coinbaseSize < MIN_TX_SIZE) { | ||||
coinbaseTx.vin[0].scriptSig | coinbaseTx.vin[0].scriptSig | ||||
<< std::vector<uint8_t>(MIN_TX_SIZE - coinbaseSize - 1); | << std::vector<uint8_t>(MIN_TX_SIZE - coinbaseSize - 1); | ||||
} | } | ||||
pblocktemplate->entries[0].tx = MakeTransactionRef(coinbaseTx); | pblocktemplate->entries[0].tx = MakeTransactionRef(coinbaseTx); | ||||
// Note: For the Coinbase, the template entry fields aside from the `tx` are | // Note: For the Coinbase, the template entry fields aside from the `tx` are | ||||
// not used anywhere at the time of writing. The mining rpc throws out the | // not used anywhere at the time of writing. The mining rpc throws out the | ||||
// entire transaction in fact. The tx itself is only used during regtest | // entire transaction in fact. The tx itself is only used during regtest | ||||
// mode. | // mode. | ||||
pblocktemplate->entries[0].txFee = -1 * nFees; | pblocktemplate->entries[0].txFee = -1 * nFees; | ||||
uint64_t nSerializeSize = | uint64_t nSerializeSize = GetSerializeSize(*pblock, 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); | ||||
// Fill in header. | // Fill in header. | ||||
pblock->hashPrevBlock = pindexPrev->GetBlockHash(); | pblock->hashPrevBlock = pindexPrev->GetBlockHash(); | ||||
UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); | UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); | ||||
pblock->nBits = | pblock->nBits = | ||||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | bool BlockAssembler::TestPackageTransactions( | ||||
for (CTxMemPool::txiter it : package) { | for (CTxMemPool::txiter it : package) { | ||||
CValidationState state; | CValidationState state; | ||||
if (!ContextualCheckTransaction(chainparams.GetConsensus(), it->GetTx(), | if (!ContextualCheckTransaction(chainparams.GetConsensus(), it->GetTx(), | ||||
state, nHeight, nLockTimeCutoff, | state, nHeight, nLockTimeCutoff, | ||||
nMedianTimePast)) { | nMedianTimePast)) { | ||||
return false; | return false; | ||||
} | } | ||||
uint64_t nTxSize = | uint64_t nTxSize = ::GetSerializeSize(it->GetTx(), PROTOCOL_VERSION); | ||||
::GetSerializeSize(it->GetTx(), SER_NETWORK, PROTOCOL_VERSION); | |||||
if (nPotentialBlockSize + nTxSize >= nMaxGeneratedBlockSize) { | if (nPotentialBlockSize + nTxSize >= nMaxGeneratedBlockSize) { | ||||
return false; | return false; | ||||
} | } | ||||
nPotentialBlockSize += nTxSize; | nPotentialBlockSize += nTxSize; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
BlockAssembler::TestForBlockResult | BlockAssembler::TestForBlockResult | ||||
BlockAssembler::TestForBlock(CTxMemPool::txiter it) { | BlockAssembler::TestForBlock(CTxMemPool::txiter it) { | ||||
auto blockSizeWithTx = | auto blockSizeWithTx = | ||||
nBlockSize + | nBlockSize + ::GetSerializeSize(it->GetTx(), PROTOCOL_VERSION); | ||||
::GetSerializeSize(it->GetTx(), SER_NETWORK, PROTOCOL_VERSION); | |||||
if (blockSizeWithTx >= nMaxGeneratedBlockSize) { | if (blockSizeWithTx >= nMaxGeneratedBlockSize) { | ||||
if (nBlockSize > nMaxGeneratedBlockSize - 100 || lastFewTxs > 50) { | if (nBlockSize > nMaxGeneratedBlockSize - 100 || lastFewTxs > 50) { | ||||
return TestForBlockResult::BlockFinished; | return TestForBlockResult::BlockFinished; | ||||
} | } | ||||
if (nBlockSize > nMaxGeneratedBlockSize - 1000) { | if (nBlockSize > nMaxGeneratedBlockSize - 1000) { | ||||
lastFewTxs++; | lastFewTxs++; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 378 Lines • ▼ Show 20 Lines | void IncrementExtraNonce(CBlock *pblock, const CBlockIndex *pindexPrev, | ||||
unsigned int nHeight = pindexPrev->nHeight + 1; | unsigned int nHeight = pindexPrev->nHeight + 1; | ||||
CMutableTransaction txCoinbase(*pblock->vtx[0]); | CMutableTransaction txCoinbase(*pblock->vtx[0]); | ||||
txCoinbase.vin[0].scriptSig = | txCoinbase.vin[0].scriptSig = | ||||
(CScript() << nHeight << CScriptNum(nExtraNonce) | (CScript() << nHeight << CScriptNum(nExtraNonce) | ||||
<< getExcessiveBlockSizeSig(nExcessiveBlockSize)) + | << getExcessiveBlockSizeSig(nExcessiveBlockSize)) + | ||||
COINBASE_FLAGS; | COINBASE_FLAGS; | ||||
// Make sure the coinbase is big enough. | // Make sure the coinbase is big enough. | ||||
uint64_t coinbaseSize = | uint64_t coinbaseSize = ::GetSerializeSize(txCoinbase, PROTOCOL_VERSION); | ||||
::GetSerializeSize(txCoinbase, SER_NETWORK, PROTOCOL_VERSION); | |||||
if (coinbaseSize < MIN_TX_SIZE) { | if (coinbaseSize < MIN_TX_SIZE) { | ||||
txCoinbase.vin[0].scriptSig | txCoinbase.vin[0].scriptSig | ||||
<< std::vector<uint8_t>(MIN_TX_SIZE - coinbaseSize - 1); | << std::vector<uint8_t>(MIN_TX_SIZE - coinbaseSize - 1); | ||||
} | } | ||||
assert(txCoinbase.vin[0].scriptSig.size() <= MAX_COINBASE_SCRIPTSIG_SIZE); | assert(txCoinbase.vin[0].scriptSig.size() <= MAX_COINBASE_SCRIPTSIG_SIZE); | ||||
assert(::GetSerializeSize(txCoinbase, SER_NETWORK, PROTOCOL_VERSION) >= | assert(::GetSerializeSize(txCoinbase, PROTOCOL_VERSION) >= MIN_TX_SIZE); | ||||
MIN_TX_SIZE); | |||||
pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase)); | pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase)); | ||||
pblock->hashMerkleRoot = BlockMerkleRoot(*pblock); | pblock->hashMerkleRoot = BlockMerkleRoot(*pblock); | ||||
} | } |