Changeset View
Changeset View
Standalone View
Standalone View
src/miner.cpp
Show All 21 Lines | |||||
#include <pow/pow.h> | #include <pow/pow.h> | ||||
#include <primitives/transaction.h> | #include <primitives/transaction.h> | ||||
#include <timedata.h> | #include <timedata.h> | ||||
#include <util/moneystr.h> | #include <util/moneystr.h> | ||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <validation.h> | #include <validation.h> | ||||
#include <algorithm> | #include <algorithm> | ||||
#include <atomic> | |||||
#include <utility> | #include <utility> | ||||
int64_t UpdateTime(CBlockHeader *pblock, const CChainParams &chainParams, | int64_t UpdateTime(CBlockHeader *pblock, const CChainParams &chainParams, | ||||
const CBlockIndex *pindexPrev) { | const CBlockIndex *pindexPrev) { | ||||
int64_t nOldTime = pblock->nTime; | int64_t nOldTime = pblock->nTime; | ||||
int64_t nNewTime = | int64_t nNewTime = | ||||
std::max(pindexPrev->GetMedianTimePast() + 1, GetAdjustedTime()); | std::max(pindexPrev->GetMedianTimePast() + 1, GetAdjustedTime()); | ||||
▲ Show 20 Lines • Show All 500 Lines • ▼ Show 20 Lines | |||||
static const std::vector<uint8_t> | static const std::vector<uint8_t> | ||||
getExcessiveBlockSizeSig(uint64_t nExcessiveBlockSize) { | getExcessiveBlockSizeSig(uint64_t nExcessiveBlockSize) { | ||||
std::string cbmsg = "/EB" + getSubVersionEB(nExcessiveBlockSize) + "/"; | std::string cbmsg = "/EB" + getSubVersionEB(nExcessiveBlockSize) + "/"; | ||||
std::vector<uint8_t> vec(cbmsg.begin(), cbmsg.end()); | std::vector<uint8_t> vec(cbmsg.begin(), cbmsg.end()); | ||||
return vec; | return vec; | ||||
} | } | ||||
void IncrementExtraNonce(CBlock *pblock, const CBlockIndex *pindexPrev, | uint32_t IncrementExtraNonce(CBlock *pblock, const CBlockIndex *pindexPrev, | ||||
uint64_t nExcessiveBlockSize, | uint64_t nExcessiveBlockSize) { | ||||
unsigned int &nExtraNonce) { | |||||
// Update nExtraNonce | // Update nExtraNonce | ||||
static uint256 hashPrevBlock; | static std::atomic_uint32_t nExtraNonce; | ||||
if (hashPrevBlock != pblock->hashPrevBlock) { | auto extraNonceReturn{nExtraNonce++}; | ||||
nExtraNonce = 0; | |||||
hashPrevBlock = pblock->hashPrevBlock; | |||||
} | |||||
++nExtraNonce; | |||||
// Height first in coinbase required for block.version=2 | // Height first in coinbase required for block.version=2 | ||||
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(extraNonceReturn) | ||||
<< getExcessiveBlockSizeSig(nExcessiveBlockSize)); | << getExcessiveBlockSizeSig(nExcessiveBlockSize)); | ||||
// Make sure the coinbase is big enough. | // Make sure the coinbase is big enough. | ||||
uint64_t coinbaseSize = ::GetSerializeSize(txCoinbase, PROTOCOL_VERSION); | uint64_t coinbaseSize = ::GetSerializeSize(txCoinbase, 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, PROTOCOL_VERSION) >= MIN_TX_SIZE); | assert(::GetSerializeSize(txCoinbase, PROTOCOL_VERSION) >= 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); | ||||
return extraNonceReturn; | |||||
} | } |