diff options
| author | Ross Nicoll <[email protected]> | 2015-07-24 19:56:03 +0000 |
|---|---|---|
| committer | Ross Nicoll <[email protected]> | 2015-07-26 20:07:48 +0000 |
| commit | 35ed1cfce1cf679ed051fa2ab8d00f8878fec576 (patch) | |
| tree | e5cc7d0166abfbd2b5d4789e5f3695fde0d4535b | |
| parent | Merge pull request #1201 from rnicoll/1.10-sync (diff) | |
| download | discoin-35ed1cfce1cf679ed051fa2ab8d00f8878fec576.tar.xz discoin-35ed1cfce1cf679ed051fa2ab8d00f8878fec576.zip | |
Add Scrypt hash and AuxPoW header to index database
Add Scrypt hash and AuxPoW header to index database so that index can be validated
(a check that both Litecoin and Namecoin disable for simplicity). The index format
is incompatible with 1.8, as a result, however, and guidelines on performing the
upgrade will need to be prepared.
Given scope of the change, it may be advisable for services to prepare bootstrap files and destroy existing index databases entirely before reindexing. To discuss.
| -rw-r--r-- | src/chain.h | 17 | ||||
| -rw-r--r-- | src/dogecoin.cpp | 6 | ||||
| -rw-r--r-- | src/main.cpp | 5 | ||||
| -rw-r--r-- | src/txdb.cpp | 14 |
4 files changed, 32 insertions, 10 deletions
diff --git a/src/chain.h b/src/chain.h index c735f6a70..359a14771 100644 --- a/src/chain.h +++ b/src/chain.h @@ -111,6 +111,9 @@ public: //! pointer to the index of some further predecessor of this block CBlockIndex* pskip; + //! pointer to the AuxPoW header, if this block has one + boost::shared_ptr<CAuxPow> pauxpow; + //! height of the entry in the chain. The genesis block has height 0 int nHeight; @@ -145,6 +148,9 @@ public: unsigned int nBits; unsigned int nNonce; + // Dogecoin: Keep the Scrypt hash as well as SHA256 + uint256 hashBlockPoW; + //! (memory only) Sequential id assigned to distinguish order in which blocks are received. uint32_t nSequenceId; @@ -153,6 +159,7 @@ public: phashBlock = NULL; pprev = NULL; pskip = NULL; + pauxpow.reset(); nHeight = 0; nFile = 0; nDataPos = 0; @@ -168,6 +175,7 @@ public: nTime = 0; nBits = 0; nNonce = 0; + hashBlockPoW = uint256(); } CBlockIndex() @@ -184,6 +192,7 @@ public: nTime = block.nTime; nBits = block.nBits; nNonce = block.nNonce; + hashBlockPoW = block.GetPoWHash(); } CDiskBlockPos GetBlockPos() const { @@ -309,6 +318,14 @@ public: READWRITE(nTime); READWRITE(nBits); READWRITE(nNonce); + READWRITE(hashBlockPoW); + if (this->nVersion.IsAuxpow()) { + if (ser_action.ForRead()) + pauxpow.reset(new CAuxPow()); + assert(pauxpow); + READWRITE(*pauxpow); + } else if (ser_action.ForRead()) + pauxpow.reset(); } uint256 GetBlockHash() const diff --git a/src/dogecoin.cpp b/src/dogecoin.cpp index 6916982e0..2443732b2 100644 --- a/src/dogecoin.cpp +++ b/src/dogecoin.cpp @@ -113,12 +113,6 @@ bool CheckAuxPowProofOfWork(const CBlockHeader& block, const Consensus::Params& if (!block.nVersion.IsAuxpow()) return error("%s : auxpow on block with non-auxpow version", __func__); - /* Temporary check: Disallow parent blocks with auxpow version. This is - for compatibility with the old client. */ - /* FIXME: Remove this check with a hardfork later on. */ - if (block.auxpow->getParentBlock().nVersion.IsAuxpow()) - return error("%s : auxpow parent block has auxpow version", __func__); - if (!block.auxpow->check(block.GetHash(), block.nVersion.GetChainId(), params)) return error("%s : AUX POW is not valid", __func__); if (!CheckProofOfWork(block.auxpow->getParentBlockPoWHash(), block.nBits, params)) diff --git a/src/main.cpp b/src/main.cpp index dfcd50310..80d301d54 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2531,6 +2531,11 @@ CBlockIndex* AddToBlockIndex(const CBlockHeader& block) pindexNew->BuildSkip(); } pindexNew->nChainWork = (pindexNew->pprev ? pindexNew->pprev->nChainWork : 0) + GetBlockProof(*pindexNew); + // Dogecoin: Add AuxPoW + if (block.nVersion.IsAuxpow()) { + pindexNew->pauxpow = block.auxpow; + assert(NULL != pindexNew->pauxpow.get()); + } pindexNew->RaiseValidity(BLOCK_VALID_TREE); if (pindexBestHeader == NULL || pindexBestHeader->nChainWork < pindexNew->nChainWork) pindexBestHeader = pindexNew; diff --git a/src/txdb.cpp b/src/txdb.cpp index bdc67a049..7eb857ed5 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -213,6 +213,7 @@ bool CBlockTreeDB::LoadBlockIndexGuts() // Construct block index object CBlockIndex* pindexNew = InsertBlockIndex(diskindex.GetBlockHash()); pindexNew->pprev = InsertBlockIndex(diskindex.hashPrev); + pindexNew->pauxpow = diskindex.pauxpow; pindexNew->nHeight = diskindex.nHeight; pindexNew->nFile = diskindex.nFile; pindexNew->nDataPos = diskindex.nDataPos; @@ -224,11 +225,16 @@ bool CBlockTreeDB::LoadBlockIndexGuts() pindexNew->nNonce = diskindex.nNonce; pindexNew->nStatus = diskindex.nStatus; pindexNew->nTx = diskindex.nTx; + pindexNew->hashBlockPoW = diskindex.hashBlockPoW; - /* Bitcoin checks the PoW here. We don't do this because - the CDiskBlockIndex does not contain the auxpow. - This check isn't important, since the data on disk should - already be valid and can be trusted. */ + if (pindexNew->nVersion.IsAuxpow()) { + if (!diskindex.pauxpow->check(diskindex.GetBlockHash(), pindexNew->nVersion.GetChainId(), Params().GetConsensus(pindexNew->nHeight))) { + return error("LoadBlockIndex(): CheckProofOfWork failed: %s", pindexNew->ToString()); + } + } else { + if (!CheckProofOfWork(pindexNew->hashBlockPoW, pindexNew->nBits, Params().GetConsensus(pindexNew->nHeight))) + return error("LoadBlockIndex(): CheckProofOfWork failed: %s", pindexNew->ToString()); + } pcursor->Next(); } else { |