Fail GetTransaction when the block from txindex is not in mapBlockIndex (#3606)

This indicates a previous crash where the TX made it into the txindex but
the block was not flushed to disk. When dashd is restarted then, there is
a short time where GetTransaction would return a non-existant block, while
callers very often assume that the returned block hash is known.
This commit is contained in:
Alexander Block 2020-07-14 11:22:36 +02:00 committed by pasta
parent 62c3fb5748
commit a170c649b8
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984

View File

@ -977,6 +977,9 @@ bool GetTransaction(const uint256& hash, CTransactionRef& txOut, const Consensus
hashBlock = header.GetHash();
if (txOut->GetHash() != hash)
return error("%s: txid mismatch", __func__);
if (!mapBlockIndex.count(hashBlock)) {
return error("%s: hashBlock %s not in mapBlockIndex", __func__, hashBlock.ToString());
}
return true;
}