Created
June 23, 2021 14:45
-
-
Save andrewkkchan/21df1e5e9c751f0a890e70d754c5d75a to your computer and use it in GitHub Desktop.
IncrementExtraNonce at BitCoin Core
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned int& nExtraNonce) | |
{ | |
// Update nExtraNonce | |
static uint256 hashPrevBlock; | |
if (hashPrevBlock != pblock->hashPrevBlock) | |
{ | |
nExtraNonce = 0; | |
hashPrevBlock = pblock->hashPrevBlock; | |
} | |
++nExtraNonce; | |
unsigned int nHeight = pindexPrev->nHeight+1; // Height first in coinbase required for block.version=2 | |
CMutableTransaction txCoinbase(*pblock->vtx[0]); | |
txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(nExtraNonce)); | |
assert(txCoinbase.vin[0].scriptSig.size() <= 100); | |
pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase)); | |
pblock->hashMerkleRoot = BlockMerkleRoot(*pblock); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment