Skip to content

Commit

Permalink
Add Scrypt hash and AuxPoW header to index database
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Ross Nicoll committed Jul 26, 2015
1 parent 8cd835c commit 35ed1cf
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
17 changes: 17 additions & 0 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ class CBlockIndex
//! 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;

Expand Down Expand Up @@ -145,6 +148,9 @@ class CBlockIndex
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;

Expand All @@ -153,6 +159,7 @@ class CBlockIndex
phashBlock = NULL;
pprev = NULL;
pskip = NULL;
pauxpow.reset();
nHeight = 0;
nFile = 0;
nDataPos = 0;
Expand All @@ -168,6 +175,7 @@ class CBlockIndex
nTime = 0;
nBits = 0;
nNonce = 0;
hashBlockPoW = uint256();
}

CBlockIndex()
Expand All @@ -184,6 +192,7 @@ class CBlockIndex
nTime = block.nTime;
nBits = block.nBits;
nNonce = block.nNonce;
hashBlockPoW = block.GetPoWHash();
}

CDiskBlockPos GetBlockPos() const {
Expand Down Expand Up @@ -309,6 +318,14 @@ class CDiskBlockIndex : public CBlockIndex
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
Expand Down
6 changes: 0 additions & 6 deletions src/dogecoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 5 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 10 additions & 4 deletions src/txdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down

0 comments on commit 35ed1cf

Please sign in to comment.