|
15 | 15 | #include <blockfilter.h>
|
16 | 16 | #include <chain.h>
|
17 | 17 | #include <chainparams.h>
|
| 18 | +#include <coins.h> |
18 | 19 | #include <compat/sanity.h>
|
19 | 20 | #include <consensus/validation.h>
|
20 | 21 | #include <fs.h>
|
@@ -146,31 +147,6 @@ NODISCARD static bool CreatePidFile()
|
146 | 147 | // shutdown thing.
|
147 | 148 | //
|
148 | 149 |
|
149 |
| -/** |
150 |
| - * This is a minimally invasive approach to shutdown on LevelDB read errors from the |
151 |
| - * chainstate, while keeping user interface out of the common library, which is shared |
152 |
| - * between bitcoind, and bitcoin-qt and non-server tools. |
153 |
| -*/ |
154 |
| -class CCoinsViewErrorCatcher final : public CCoinsViewBacked |
155 |
| -{ |
156 |
| -public: |
157 |
| - explicit CCoinsViewErrorCatcher(CCoinsView* view) : CCoinsViewBacked(view) {} |
158 |
| - bool GetCoin(const COutPoint &outpoint, Coin &coin) const override { |
159 |
| - try { |
160 |
| - return CCoinsViewBacked::GetCoin(outpoint, coin); |
161 |
| - } catch(const std::runtime_error& e) { |
162 |
| - uiInterface.ThreadSafeMessageBox(_("Error reading from database, shutting down."), "", CClientUIInterface::MSG_ERROR); |
163 |
| - LogPrintf("Error reading from database: %s\n", e.what()); |
164 |
| - // Starting the shutdown sequence and returning false to the caller would be |
165 |
| - // interpreted as 'entry not found' (as opposed to unable to read data), and |
166 |
| - // could lead to invalid interpretation. Just exit immediately, as we can't |
167 |
| - // continue anyway, and all writes should be atomic. |
168 |
| - abort(); |
169 |
| - } |
170 |
| - } |
171 |
| - // Writes do not need similar protection, as failure to write is handled by the caller. |
172 |
| -}; |
173 |
| - |
174 | 150 | static std::unique_ptr<CCoinsViewErrorCatcher> pcoinscatcher;
|
175 | 151 | static std::unique_ptr<ECCVerifyHandle> globalVerifyHandle;
|
176 | 152 |
|
@@ -1544,6 +1520,11 @@ bool AppInitMain(InitInterfaces& interfaces)
|
1544 | 1520 |
|
1545 | 1521 | pcoinsdbview.reset(new CCoinsViewDB(nCoinDBCache, false, fReset || fReindexChainState));
|
1546 | 1522 | pcoinscatcher.reset(new CCoinsViewErrorCatcher(pcoinsdbview.get()));
|
| 1523 | + pcoinscatcher->AddReadErrCallback([]() { |
| 1524 | + uiInterface.ThreadSafeMessageBox( |
| 1525 | + _("Error reading from database, shutting down."), |
| 1526 | + "", CClientUIInterface::MSG_ERROR); |
| 1527 | + }); |
1547 | 1528 |
|
1548 | 1529 | // If necessary, upgrade from older database format.
|
1549 | 1530 | // This is a no-op if we cleared the coinsviewdb with -reindex or -reindex-chainstate
|
|
0 commit comments