fix data corruption of block_info::hash

This commit is contained in:
Brannon King 2020-02-26 14:11:03 -07:00 committed by Anthony Fieroni
parent b7ad2beabd
commit 8c41ff1608
2 changed files with 3 additions and 2 deletions

View file

@ -261,7 +261,7 @@ public:
return block;
}
uint256 GetBlockHash() const
const uint256& GetBlockHash() const
{
return hash;
}

View file

@ -303,11 +303,12 @@ bool CBlockTreeDB::BatchWrite(const std::vector<std::pair<int, const CBlockFileI
db << "INSERT OR REPLACE INTO flag VALUES('last_block', ?)" << nLastFile; // TODO: is this always max(file column)?
if(!blockInfo.empty()) {
const static uint256 empty;
auto ibi = db << "INSERT OR REPLACE INTO block_info(hash, prevHash, height, file, dataPos, undoPos, "
"txCount, status, version, rootTxHash, rootTrieHash, time, bits, nonce) "
"VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
for (auto &bi: blockInfo) {
ibi << bi->GetBlockHash() << (bi->pprev ? bi->pprev->GetBlockHash() : uint256())
ibi << bi->hash << (bi->pprev ? bi->pprev->hash : empty)
<< bi->nHeight << bi->nFile << bi->nDataPos << bi->nUndoPos << bi->nTx
<< bi->nStatus << bi->nVersion << bi->hashMerkleRoot << bi->hashClaimTrie
<< bi->nTime << bi->nBits << bi->nNonce;