Changeset View
Changeset View
Standalone View
Standalone View
src/miner.cpp
Show First 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | BlockAssembler::CreateNewBlock(const CScript &scriptPubKeyIn) { | ||||
if (!pblocktemplate.get()) { | if (!pblocktemplate.get()) { | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
// Pointer for convenience. | // Pointer for convenience. | ||||
pblock = &pblocktemplate->block; | pblock = &pblocktemplate->block; | ||||
// Add dummy coinbase tx as first transaction. It is updated at the end. | // Add dummy coinbase tx as first transaction. It is updated at the end. | ||||
pblocktemplate->entries.emplace_back(CTransactionRef(), -SATOSHI, -1); | pblocktemplate->entries.emplace_back(CTransactionRef(), -SATOSHI, 0, -1); | ||||
LOCK2(cs_main, mempool->cs); | LOCK2(cs_main, mempool->cs); | ||||
CBlockIndex *pindexPrev = chainActive.Tip(); | CBlockIndex *pindexPrev = chainActive.Tip(); | ||||
nHeight = pindexPrev->nHeight + 1; | nHeight = pindexPrev->nHeight + 1; | ||||
const CChainParams &chainparams = config->GetChainParams(); | const CChainParams &chainparams = config->GetChainParams(); | ||||
pblock->nVersion = | pblock->nVersion = | ||||
ComputeBlockVersion(pindexPrev, chainparams.GetConsensus()); | ComputeBlockVersion(pindexPrev, chainparams.GetConsensus()); | ||||
Show All 33 Lines | BlockAssembler::CreateNewBlock(const CScript &scriptPubKeyIn) { | ||||
nLastBlockSize = nBlockSize; | nLastBlockSize = nBlockSize; | ||||
// Create coinbase transaction. | // Create coinbase transaction. | ||||
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 = | ||||
schancel: @jasonbcox You can see right here that these fees are not negative. They are added to the… | |||||
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, SER_NETWORK, 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); | ||||
pblocktemplate->entries[0].fees = -1 * nFees; | pblocktemplate->entries[0].txFee = -1 * nFees; | ||||
jasonbcoxUnsubmitted Not Done Inline ActionsWhy is the coinbase tx size not set? jasonbcox: Why is the coinbase tx size not set? | |||||
schancelAuthorUnsubmitted Done Inline ActionsI don't know. Apparently it's not important. This change is trying to rename a variable. schancel: I don't know. Apparently it's not important. This change is trying to rename a variable. | |||||
jasonbcoxUnsubmitted Not Done Inline ActionsClearly txSize is being added in this diff, so it's absolutely applicable to review here. jasonbcox: Clearly txSize is being added in this diff, so it's absolutely applicable to review here. | |||||
schancelAuthorUnsubmitted Done Inline ActionsThese original entries predate anything I've done, and the coinbase transaction is discarded in getblocktemplate with only fees being returned. The mining pool software is expected to fill in the details within the 1000 bytes of reserved space. When the generate rpc is called on regtest the IncramentExtraNonce function *does* use the coinbase, but these fields are also not used. schancel: These original entries predate anything I've done, and the coinbase transaction is discarded in… | |||||
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); | ||||
// Fill in header. | // Fill in header. | ||||
pblock->hashPrevBlock = pindexPrev->GetBlockHash(); | pblock->hashPrevBlock = pindexPrev->GetBlockHash(); | ||||
UpdateTime(pblock, *config, pindexPrev); | UpdateTime(pblock, *config, pindexPrev); | ||||
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, *config); | pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, *config); | ||||
pblock->nNonce = 0; | pblock->nNonce = 0; | ||||
pblocktemplate->entries[0].sigOpCount = GetSigOpCountWithoutP2SH( | pblocktemplate->entries[0].txSigOps = GetSigOpCountWithoutP2SH( | ||||
*pblocktemplate->entries[0].tx, STANDARD_CHECKDATASIG_VERIFY_FLAGS); | *pblocktemplate->entries[0].tx, STANDARD_CHECKDATASIG_VERIFY_FLAGS); | ||||
// Copy all the transactions into the block | // Copy all the transactions into the block | ||||
// FIXME: This should be removed as it is significant overhead. | // FIXME: This should be removed as it is significant overhead. | ||||
// See T479 | // See T479 | ||||
for (const CBlockTemplateEntry &tx : pblocktemplate->entries) { | for (const CBlockTemplateEntry &tx : pblocktemplate->entries) { | ||||
pblock->vtx.push_back(tx.tx); | pblock->vtx.push_back(tx.tx); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Lines | if (!ContextualCheckTransaction(*config, it->GetTx(), state, nHeight, | ||||
return TestForBlockResult::TXCantFit; | return TestForBlockResult::TXCantFit; | ||||
} | } | ||||
return TestForBlockResult::TXFits; | return TestForBlockResult::TXFits; | ||||
} | } | ||||
void BlockAssembler::AddToBlock(CTxMemPool::txiter iter) { | void BlockAssembler::AddToBlock(CTxMemPool::txiter iter) { | ||||
pblocktemplate->entries.emplace_back(iter->GetSharedTx(), iter->GetFee(), | pblocktemplate->entries.emplace_back(iter->GetSharedTx(), iter->GetFee(), | ||||
iter->GetTxSize(), | |||||
iter->GetSigOpCount()); | iter->GetSigOpCount()); | ||||
nBlockSize += iter->GetTxSize(); | nBlockSize += iter->GetTxSize(); | ||||
++nBlockTx; | ++nBlockTx; | ||||
nBlockSigOps += iter->GetSigOpCount(); | nBlockSigOps += iter->GetSigOpCount(); | ||||
nFees += iter->GetFee(); | nFees += iter->GetFee(); | ||||
schancelAuthorUnsubmitted Done Inline Actions@jasonbcox And they are added together here. So there's no funny business going on with the sign. schancel: @jasonbcox And they are added together here. So there's no funny business going on with the… | |||||
inBlock.insert(iter); | inBlock.insert(iter); | ||||
bool fPrintPriority = | bool fPrintPriority = | ||||
gArgs.GetBoolArg("-printpriority", DEFAULT_PRINTPRIORITY); | gArgs.GetBoolArg("-printpriority", DEFAULT_PRINTPRIORITY); | ||||
if (fPrintPriority) { | if (fPrintPriority) { | ||||
double dPriority = iter->GetPriority(nHeight); | double dPriority = iter->GetPriority(nHeight); | ||||
Amount dummy; | Amount dummy; | ||||
mempool->ApplyDeltas(iter->GetTx().GetId(), dPriority, dummy); | mempool->ApplyDeltas(iter->GetTx().GetId(), dPriority, dummy); | ||||
▲ Show 20 Lines • Show All 346 Lines • Show Last 20 Lines |
@jasonbcox You can see right here that these fees are not negative. They are added to the subsidy to generate the coinbase vout.