85 return error(
"AuxPow is not a generate");
88 return error(
"Aux POW parent has our chain ID");
91 return error(
"Aux POW chain merkle branch too long");
96 std::vector<unsigned char> vchRootHash(nRootHash.
begin(), nRootHash.
end());
97 std::reverse(vchRootHash.begin(), vchRootHash.end());
102 return error(
"Aux POW merkle root incorrect");
104 const CScript script =
tx->vin[0].scriptSig;
110 std::search(script.
begin(), script.
end(),
UBEGIN(pchMergedMiningHeader),
UEND(pchMergedMiningHeader));
113 std::search(script.
begin(), script.
end(), vchRootHash.begin(), vchRootHash.end());
115 if (pc == script.
end())
116 return error(
"Aux POW missing chain merkle root in parent coinbase");
118 if (pcHead != script.
end())
122 if (script.
end() != std::search(pcHead + 1, script.
end(),
UBEGIN(pchMergedMiningHeader),
UEND(pchMergedMiningHeader)))
123 return error(
"Multiple merged mining headers in coinbase");
124 if (pcHead +
sizeof(pchMergedMiningHeader) != pc)
125 return error(
"Merged mining header is not just before chain merkle root");
132 if (pc - script.
begin() > 20)
133 return error(
"Aux POW chain merkle root must start in the first 20 bytes of the parent coinbase");
139 pc += vchRootHash.size();
140 if (script.
end() - pc < 8)
141 return error(
"Aux POW missing chain merkle tree size and nonce in parent coinbase");
144 memcpy(&nSize, &pc[0], 4);
147 if (nSize != (1u << merkleHeight))
148 return error(
"Aux POW merkle branch size does not match parent coinbase");
151 memcpy(&nNonce, &pc[4], 4);
154 return error(
"Aux POW wrong index");
177 uint32_t rand = nNonce;
178 rand = rand * 1103515245 + 12345;
180 rand = rand * 1103515245 + 12345;
182 return rand % (1 << h);
187 const std::vector<uint256>& vMerkleBranch,
192 for (std::vector<uint256>::const_iterator it(
vMerkleBranch.begin ());
212 std::vector<unsigned char> inputData(blockHash.
begin (), blockHash.
end ());
213 std::reverse (inputData.begin (), inputData.end ());
214 inputData.push_back (1);
215 inputData.insert (inputData.end (), 7, 0);
220 coinbase.
vin.resize(1);
221 coinbase.
vin[0].prevout.SetNull();
222 coinbase.
vin[0].scriptSig = (
CScript () << inputData);
223 assert (coinbase.
vout.empty());
229 parent.
vtx.resize(1);
230 parent.
vtx[0] = coinbaseRef;
235 assert (header.
auxpow->vChainMerkleBranch.empty());
236 header.
auxpow->nChainIndex = 0;
237 assert (header.
auxpow->vMerkleBranch.empty());
238 header.
auxpow->nIndex = 0;
239 header.
auxpow->parentBlock = parent;
int64_t CAmount
Amount in satoshis (Can be negative)
const CChainParams & Params()
Return the currently selected parameters.
static uint256 CheckMerkleBranch(uint256 hash, const std::vector< uint256 > &vMerkleBranch, int nIndex)
Check a merkle branch.
static void initAuxPow(CBlockHeader &header)
Initialise the auxpow of the given block header.
bool check(const uint256 &hashAuxBlock, int nChainId, const Consensus::Params ¶ms) const
Check the auxpow, given the merge-mined block's hash and our chain ID.
CPureBlockHeader parentBlock
Parent block header (on which the real PoW is done).
int nChainIndex
Merkle tree index of the aux block header in the coinbase.
static int getExpectedIndex(uint32_t nNonce, int nChainId, unsigned h)
Calculate the expected index in the merkle tree.
std::vector< uint256 > vChainMerkleBranch
The merkle branch connecting the aux block to our coinbase.
std::vector< CTransactionRef > vtx
The block chain is a tree shaped structure starting with the genesis block at the root,...
uint256 GetBlockHash() const
int nHeight
height of the entry in the chain. The genesis block has height 0
int Height() const
Return the maximal height in the chain.
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
const Consensus::Params & GetConsensus(uint32_t nTargetHeight) const
bool AcceptToMemoryPool(const CAmount &nAbsurdFee, CValidationState &state)
Pass this transaction to the mempool.
const uint256 & GetHash() const
int GetDepthInMainChain() const
static const uint256 ABANDON_HASH
Constant used in hashBlock to indicate tx has been abandoned.
int GetBlocksToMaturity() const
void InitMerkleBranch(const CBlock &block, int posInBlock)
Actually compute the Merkle branch.
std::vector< uint256 > vMerkleBranch
void SetMerkleBranch(const CBlockIndex *pindex, int posInBlock)
Serialized script, used inside transaction inputs and outputs.
Capture information about block/transaction validation.
uint32_t le32toh(uint32_t little_endian_32bits)
void * memcpy(void *a, const void *b, size_t c)
uint256 Hash(const T1 pbegin, const T1 pend)
Compute the 256-bit hash of an object.
std::vector< uint256 > BlockMerkleBranch(const CBlock &block, uint32_t position)
uint256 BlockMerkleRoot(const CBlock &block, bool *mutated)
A mutable version of CTransaction.
std::vector< CTxOut > vout
Parameters that influence chain consensus.
uint32_t nCoinbaseMaturity
#define AssertLockHeld(cs)
std::shared_ptr< const CTransaction > CTransactionRef
uint256 uint256S(const char *str)
bool error(const char *fmt, const Args &... args)
#define BEGIN(a)
Utilities for converting data from/to strings.
CCriticalSection cs_main
Global state.
CTxMemPool mempool(::minRelayTxFee)
bool AcceptToMemoryPool(CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree, bool *pfMissingInputs, std::list< CTransactionRef > *plTxnReplaced, bool fOverrideMempoolLimit, const CAmount nAbsurdFee)
(try to) add transaction to memory pool plTxnReplaced will be appended to with all transactions repla...
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).