This is a follow-up to #35728.
While reviewing that PR, I noticed that FindTx() could return nullopt even when LevelDB had encountered an error. I first confirmed that a transaction could be retrieved, then deliberately damaged part of the test’s temporary txindex database. LevelDB detected the corruption, but the same lookup returned nullopt instead of throwing. Restoring the original data made the lookup work again.
The candidate scan checks whether the iterator has a valid entry, but it does not check its error status. An invalid iterator can mean that the scan reached the end normally, or that it stopped because of a database error. This means a failed scan can be treated as an ordinary missing transaction.
This adds CDBIterator::CheckStatus() and calls it after the candidate scan, before choosing a result. Any iterator error goes through the existing HandleError() path and throws dbwrapper_error. A normal missing transaction still returns nullopt.
I added a reproducer on my branch. The first commit adds a test that fails before the fix. The second commit applies the fix, and the same test passes.