| 518 | } |
| 519 | |
| 520 | void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned int& nExtraNonce) |
| 521 | { |
| 522 | // Update nExtraNonce |
| 523 | static uint256 hashPrevBlock; |
| 524 | if (hashPrevBlock != pblock->hashPrevBlock) { |
| 525 | nExtraNonce = 0; |
| 526 | hashPrevBlock = pblock->hashPrevBlock; |
| 527 | } |
| 528 | ++nExtraNonce; |
| 529 | unsigned int nHeight = pindexPrev->nHeight + 1; // Height first in coinbase required for block.version=2 |
| 530 | CMutableTransaction txCoinbase(*pblock->vtx[0]); |
| 531 | txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(nExtraNonce)); |
| 532 | assert(txCoinbase.vin[0].scriptSig.size() <= 100); |
| 533 | |
| 534 | pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase)); |
| 535 | pblock->hashMerkleRoot = BlockMerkleRoot(*pblock); |
| 536 | } |
| 537 | } // namespace node |