fix data corruption of block_info::hash

This commit is contained in:
Brannon King 2020-02-26 14:11:03 -07:00
parent a568691c10
commit 96bf1c4afa
2 changed files with 3 additions and 2 deletions

View file

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

View file

@ -315,11 +315,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;