10 using namespace boost;
17 throw runtime_error(
"merged mining aux too short");
21 bool CAuxPow::Check(
uint256 hashAuxBlock,
int nChainID)
24 return error(
"AuxPow is not a generate");
26 if (!fTestNet && parentBlock.GetChainID() == nChainID)
27 return error(
"Aux POW parent has our chain ID");
29 if (vChainMerkleBranch.size() > 30)
30 return error(
"Aux POW chain merkle branch too long");
34 vector<unsigned char> vchRootHash(nRootHash.
begin(), nRootHash.
end());
35 std::reverse(vchRootHash.begin(), vchRootHash.end());
39 return error(
"Aux POW merkle root incorrect");
41 const CScript script = vin[0].scriptSig;
46 CScript::const_iterator pcHead =
49 CScript::const_iterator pc =
50 std::search(script.begin(), script.end(), vchRootHash.begin(), vchRootHash.end());
52 if (pc == script.end())
53 return error(
"Aux POW missing chain merkle root in parent coinbase");
55 if (pcHead != script.end())
60 return error(
"Multiple merged mining headers in coinbase");
62 return error(
"Merged mining header is not just before chain merkle root");
69 if (pc - script.begin() > 20)
70 return error(
"Aux POW chain merkle root must start in the first 20 bytes of the parent coinbase");
76 pc += vchRootHash.size();
77 if (script.end() - pc < 8)
78 return error(
"Aux POW missing chain merkle tree size and nonce in parent coinbase");
82 if (nSize != (1 << vChainMerkleBranch.size()))
83 return error(
"Aux POW merkle branch size does not match parent coinbase");
86 memcpy(&nNonce, &pc[4], 4);
94 unsigned int rand = nNonce;
95 rand = rand * 1103515245 + 12345;
97 rand = rand * 1103515245 + 12345;
99 if (nChainIndex != (rand % nSize))
100 return error(
"Aux POW wrong index");
108 vchAuxWithHeader.insert(vchAuxWithHeader.end(), vchAux.begin(), vchAux.end());
111 return CScript() << nBits << nExtraNonce <<
OP_2 << vchAuxWithHeader;
119 if (++nExtraNonce >= 0x7f && nNow > nPrevTime+1)
unsigned char pchMergedMiningHeader[]
void IncrementExtraNonceWithAux(CBlock *pblock, CBlockIndex *pindexPrev, unsigned int &nExtraNonce, int64 &nPrevTime, vector< unsigned char > &vchAux)
uint256 BuildMerkleTree() const
int64_t GetAdjustedTime()
CScript MakeCoinbaseWithAux(unsigned int nBits, unsigned int nExtraNonce, vector< unsigned char > &vchAux)
The block chain is a tree shaped structure starting with the genesis block at the root...
Serialized script, used inside transaction inputs and outputs.
void * memcpy(void *a, const void *b, size_t c)
static uint256 CheckMerkleBranch(uint256 hash, const std::vector< uint256 > &vMerkleBranch, int nIndex)
std::vector< CTransaction > vtx
void RemoveMergedMiningHeader(vector< unsigned char > &vchAux)
int64_t GetMedianTimePast() const