Correct format of AuxPow coinbase script.

AuxPoW coinbase scripts now include block height as per BIP0034, which also
resolves issue of transactions being generated which collide.
This commit is contained in:
Ross Nicoll 2014-08-17 11:22:02 +01:00
parent a8cdefe23f
commit 223ed2eadd
2 changed files with 10 additions and 7 deletions

View file

@ -104,13 +104,13 @@ bool CAuxPow::Check(uint256 hashAuxBlock, int nChainID)
return true;
}
CScript MakeCoinbaseWithAux(unsigned int nBits, unsigned int nExtraNonce, vector<unsigned char>& vchAux)
CScript MakeCoinbaseWithAux(unsigned int nHeight, unsigned int nExtraNonce, vector<unsigned char>& vchAux)
{
vector<unsigned char> vchAuxWithHeader(UBEGIN(pchMergedMiningHeader), UEND(pchMergedMiningHeader));
vchAuxWithHeader.insert(vchAuxWithHeader.end(), vchAux.begin(), vchAux.end());
// Push OP_2 just in case we want versioning later
return CScript() << nBits << nExtraNonce << OP_2 << vchAuxWithHeader;
return CScript() << nHeight << CScriptNum(nExtraNonce) << COINBASE_FLAGS << OP_2 << vchAuxWithHeader;
}
@ -125,7 +125,8 @@ void IncrementExtraNonceWithAux(CBlock* pblock, CBlockIndex* pindexPrev, unsigne
}
++nExtraNonce;
pblock->vtx[0].vin[0].scriptSig = MakeCoinbaseWithAux(pblock->nBits, nExtraNonce, vchAux);
unsigned int nHeight = pindexPrev->nHeight+1; // Height first in coinbase required for block.version=2
pblock->vtx[0].vin[0].scriptSig = MakeCoinbaseWithAux(nHeight, nExtraNonce, vchAux);
pblock->hashMerkleRoot = pblock->BuildMerkleTree();
}

View file

@ -763,7 +763,8 @@ Value getworkaux(const Array& params, bool fHelp)
RemoveMergedMiningHeader(vchAux);
pblock->vtx[0].vin[0].scriptSig = MakeCoinbaseWithAux(pblock->nBits, nExtraNonce, vchAux);
unsigned int nHeight = chainActive.Tip()->nHeight+1; // Height first in coinbase required for block.version=2
pblock->vtx[0].vin[0].scriptSig = MakeCoinbaseWithAux(nHeight, nExtraNonce, vchAux);
pblock->hashMerkleRoot = pblock->BuildMerkleTree();
if (params.size() > 2)
@ -859,9 +860,10 @@ Value getauxblock(const Array& params, bool fHelp)
pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
pblock->nNonce = 0;
// Push OP_2 just in case we want versioning later
pblock->vtx[0].vin[0].scriptSig = CScript() << pblock->nBits << CScriptNum(1) << OP_2;
pblock->hashMerkleRoot = pblock->BuildMerkleTree();
// Update nExtraNonce
static unsigned int nExtraNonce = 0;
IncrementExtraNonce(pblock, pindexPrev, nExtraNonce);
// Sets the version
pblock->SetAuxPow(new CAuxPow());