From eecb1869370283d313c061523d8a9828806ad117 Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Mon, 13 Jul 2020 08:18:17 +0200 Subject: [PATCH] Fail GetTransaction when the block from txindex is not in mapBlockIndex 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. --- src/validation.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/validation.cpp b/src/validation.cpp index 84ca6df30076..91531b4bef18 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -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; }