aboutsummaryrefslogtreecommitdiff
path: root/src/primitives/block.h
diff options
context:
space:
mode:
authorRoss Nicoll <[email protected]>2017-08-13 13:31:12 +0100
committerRoss Nicoll <[email protected]>2018-09-19 19:22:45 +0100
commitbc8cca48968dfa3f60b5eae6a2b92bdd2870eee3 (patch)
treec885ee6a4370350c227b741d8284302974af050f /src/primitives/block.h
parentUpdate DB version to 5.1 (diff)
downloaddiscoin-bc8cca48968dfa3f60b5eae6a2b92bdd2870eee3.tar.xz
discoin-bc8cca48968dfa3f60b5eae6a2b92bdd2870eee3.zip
Merge AuxPoW support from Namecore
Changes are as below: Wrap CBlockHeader::nVersion into a new class (CBlockVersion). This allows to take care of interpreting the field into a base version, auxpow flag and the chain ID. Update getauxblock.py for new 'generate' RPC call. Add 'auxpow' to block JSON. Accept auxpow as PoW verification. Add unit tests for auxpow verification. Add check for memory-layout of CBlockVersion. Weaken auxpow chain ID checks for the testnet. Allow Params() to overrule when to check the auxpow chain ID and for legacy blocks. Use this to disable the checks on testnet. Introduce CPureBlockHeader. Split the block header part that is used by auxpow and the "real" block header (that uses auxpow) to resolve the cyclic dependency between the two. Differentiate between uint256 and arith_uint256. This change was done upstream, modify the auxpow code. Add missing lock in auxpow_tests. Fix REST header check for auxpow headers. Those can be longer, thus take that into account. Also perform the check actually on an auxpow header. Correctly set the coinbase for getauxblock results. Call IncrementExtraNonce in getauxblock so that the coinbase is actually initialised with the stuff it should be. (BIP30 block height and COINBASE_FLAGS.) Implement getauxblock plus regression test. Turn auxpow test into FIXTURE test. This allows using of the Params() calls. Move CMerkleTx code to auxpow.cpp. Otherwise we get linker errors when building without wallet. Fix rebase with BIP66. Update the code to handle BIP66's nVersion=3. Enforce that auxpow parent blocks have no auxpow block version. This is for compatibility with namecoind. See also https://github.com/namecoin/namecoin/pull/199. Move auxpow-related parameters to Consensus::Params.
Diffstat (limited to 'src/primitives/block.h')
-rw-r--r--src/primitives/block.h67
1 files changed, 34 insertions, 33 deletions
diff --git a/src/primitives/block.h b/src/primitives/block.h
index 8b2f1de89..dcde500ab 100644
--- a/src/primitives/block.h
+++ b/src/primitives/block.h
@@ -6,10 +6,14 @@
#ifndef BITCOIN_PRIMITIVES_BLOCK_H
#define BITCOIN_PRIMITIVES_BLOCK_H
+#include "auxpow.h"
#include "primitives/transaction.h"
+#include "primitives/pureheader.h"
#include "serialize.h"
#include "uint256.h"
+#include <boost/shared_ptr.hpp>
+
/** Nodes collect new transactions into a block, hash them into a hash tree,
* and scan through nonce values to make the block's hash satisfy proof-of-work
* requirements. When they solve the proof-of-work, they broadcast the block
@@ -17,16 +21,11 @@
* in the block is a special one that creates a new coin owned by the creator
* of the block.
*/
-class CBlockHeader
+class CBlockHeader : public CPureBlockHeader
{
public:
- // header
- int32_t nVersion;
- uint256 hashPrevBlock;
- uint256 hashMerkleRoot;
- uint32_t nTime;
- uint32_t nBits;
- uint32_t nNonce;
+ // auxpow (if this is a merge-minded block)
+ boost::shared_ptr<CAuxPow> auxpow;
CBlockHeader()
{
@@ -37,37 +36,30 @@ public:
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
- READWRITE(this->nVersion);
- READWRITE(hashPrevBlock);
- READWRITE(hashMerkleRoot);
- READWRITE(nTime);
- READWRITE(nBits);
- READWRITE(nNonce);
+ READWRITE(*(CPureBlockHeader*)this);
+
+ if (this->IsAuxpow())
+ {
+ if (ser_action.ForRead())
+ auxpow.reset(new CAuxPow());
+ assert(auxpow);
+ READWRITE(*auxpow);
+ } else if (ser_action.ForRead())
+ auxpow.reset();
}
void SetNull()
{
- nVersion = 0;
- hashPrevBlock.SetNull();
- hashMerkleRoot.SetNull();
- nTime = 0;
- nBits = 0;
- nNonce = 0;
- }
-
- bool IsNull() const
- {
- return (nBits == 0);
+ CPureBlockHeader::SetNull();
+ auxpow.reset();
}
- uint256 GetHash() const;
-
- uint256 GetPoWHash() const;
-
- int64_t GetBlockTime() const
- {
- return (int64_t)nTime;
- }
+ /**
+ * Set the block's auxpow (or unset it). This takes care of updating
+ * the version accordingly.
+ * @param apow Pointer to the auxpow to use or NULL.
+ */
+ void SetAuxpow(CAuxPow* apow);
};
@@ -115,9 +107,18 @@ public:
block.nTime = nTime;
block.nBits = nBits;
block.nNonce = nNonce;
+ block.auxpow = auxpow;
return block;
}
+ // Build the in-memory merkle tree for this block and return the merkle root.
+ // If non-NULL, *mutated is set to whether mutation was detected in the merkle
+ // tree (a duplication of transactions in the block leading to an identical
+ // merkle root).
+ uint256 BuildMerkleTree(bool* mutated = NULL) const;
+
+ std::vector<uint256> GetMerkleBranch(int nIndex) const;
+ static uint256 CheckMerkleBranch(uint256 hash, const std::vector<uint256>& vMerkleBranch, int nIndex);
std::string ToString() const;
};