Merge pull request #613 from rnicoll/1.8-dev-coinbase

Correct format of AuxPoW coinbase script
This commit is contained in:
langerhans 2014-08-18 21:15:39 +02:00
commit ad579037c8
3 changed files with 18 additions and 9 deletions

View file

@ -104,13 +104,17 @@ 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());
CScript script = (CScript() << nHeight << CScriptNum(nExtraNonce)) + COINBASE_FLAGS;
// Push OP_2 just in case we want versioning later
return CScript() << nBits << nExtraNonce << OP_2 << vchAuxWithHeader;
script = script << OP_2 << vchAuxWithHeader;
return script;
}
@ -125,7 +129,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

@ -1889,9 +1889,11 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
if (fEnforceBIP30) {
for (unsigned int i = 0; i < block.vtx.size(); i++) {
uint256 hash = block.GetTxHash(i);
if (view.HaveCoins(hash) && !view.GetCoins(hash).IsPruned())
return state.DoS(100, error("ConnectBlock() : tried to overwrite transaction"),
if (view.HaveCoins(hash) && !view.GetCoins(hash).IsPruned()) {
std::string errorMsg = "ConnectBlock() : tried to overwrite transaction " + (hash.GetHex());
return state.DoS(100, error(errorMsg.data()),
REJECT_INVALID, "bad-txns-BIP30");
}
}
}

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());