Skip to content

Commit 76abd68

Browse files
committed
[DB] Data error checks and frequency changes
1 parent e993b7b commit 76abd68

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/chain.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) 2009-2010 Satoshi Nakamoto
22
// Copyright (c) 2009-2019 The Bitcoin Core developers
3+
// Copyright (c) 2019-2020 The Veil developers
34
// Distributed under the MIT software license, see the accompanying
45
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
56

@@ -105,6 +106,10 @@ const CBlockIndex* CBlockIndex::GetAncestor(int height) const
105106
pindexWalk = pindexWalk->pskip;
106107
heightWalk = heightSkip;
107108
} else {
109+
if (!pindexWalk->pprev) {
110+
LogPrintf("%s: pindexWalk failed: Hash: %s, Current Height: %d, Working Height: %d\n",
111+
__func__, pindexWalk->phashBlock->GetHex(), height, nHeight);
112+
}
108113
assert(pindexWalk->pprev);
109114
pindexWalk = pindexWalk->pprev;
110115
heightWalk--;

src/txdb.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) 2009-2010 Satoshi Nakamoto
22
// Copyright (c) 2009-2019 The Bitcoin Core developers
3+
// Copyright (c) 2019-2020 The Veil developers
34
// Distributed under the MIT software license, see the accompanying
45
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
56

@@ -240,6 +241,14 @@ bool CBlockTreeDB::WriteBatchSync(const std::vector<std::pair<int, const CBlockF
240241
}
241242
batch.Write(DB_LAST_BLOCK, nLastFile);
242243
for (std::vector<const CBlockIndex*>::const_iterator it=blockinfo.begin(); it != blockinfo.end(); it++) {
244+
CDiskBlockIndex diskindex = CDiskBlockIndex(*it);
245+
CBlockHeader bHeader = (*it)->GetBlockHeader();
246+
uint256 hashBlock = diskindex.GetBlockHash();
247+
if (arith_uint256(hashBlock.GetHex()) != arith_uint256((*it)->GetBlockHeader().GetHash().GetHex())) {
248+
LogPrintf("%s: *** Warning - Block %d: Hash: %s doesn't match Header Hash: %s\n", __func__,
249+
diskindex.nHeight, hashBlock.GetHex(), bHeader.GetHash().GetHex());
250+
continue; // Don't write it
251+
}
243252
batch.Write(std::make_pair(DB_BLOCK_INDEX, (*it)->GetBlockHash()), CDiskBlockIndex(*it));
244253
}
245254
return WriteBatch(batch, true);
@@ -276,6 +285,8 @@ bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams,
276285
// ignore any duplicates and mark them to be erased
277286
uint256 hashBlock = diskindex.GetBlockHash();
278287
if (hashBlock != key.second) {
288+
LogPrintf("%s: Skipping Block %d: %s - Block Hash does not match Index Key\n",
289+
__func__, diskindex.nStatus, hashBlock.GetHex());
279290
pcursor->Next();
280291
continue;
281292
}

src/validation.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ static const int MAX_BLOCKTXN_DEPTH = 10;
106106
* want to make this a per-peer adaptive value at some point. */
107107
static const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024;
108108
/** Time to wait (in seconds) between writing blocks/block index to disk. */
109-
static const unsigned int DATABASE_WRITE_INTERVAL = 60 * 60;
109+
static const unsigned int DATABASE_WRITE_INTERVAL = 60 * 6;
110110
/** Time to wait (in seconds) between flushing chainstate to disk. */
111-
static const unsigned int DATABASE_FLUSH_INTERVAL = 24 * 60 * 60;
111+
static const unsigned int DATABASE_FLUSH_INTERVAL = 24 * 60 * 6;
112112
/** Maximum length of reject messages. */
113113
static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111;
114114
/** Block download timeout base, expressed in millionths of the block interval (i.e. 10 min) */

0 commit comments

Comments
 (0)