aboutsummaryrefslogtreecommitdiff
path: root/src/coins.h
diff options
context:
space:
mode:
authorJames O'Beirne <james.obeirne@gmail.com>2019-03-27 14:17:13 -0400
committerJames O'Beirne <james.obeirne@gmail.com>2019-07-21 21:00:31 -0400
commit4f050b91c706181084b9288b8a87b7b637e4e4f7 (patch)
tree04d89c31739b0fd905dcab774726852d9653f40f /src/coins.h
parent2679bb8919b5089f8067ccfd94f766747b8df671 (diff)
move-onlyish: move CCoinsViewErrorCatcher out of init.cpp
and into coins.cpp. This move is necessary so that we can later include a CCoinsViewErrorCatcher instance under CChainState. Co-authored-by: MarcoFalke <falke.marco@gmail.com>
Diffstat (limited to 'src/coins.h')
-rw-r--r--src/coins.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/coins.h b/src/coins.h
index 482e233e8c..dca1beabb6 100644
--- a/src/coins.h
+++ b/src/coins.h
@@ -17,6 +17,7 @@
#include <assert.h>
#include <stdint.h>
+#include <functional>
#include <unordered_map>
/**
@@ -315,4 +316,28 @@ void AddCoins(CCoinsViewCache& cache, const CTransaction& tx, int nHeight, bool
//! lookups to database, so it should be used with care.
const Coin& AccessByTxid(const CCoinsViewCache& cache, const uint256& txid);
+/**
+ * This is a minimally invasive approach to shutdown on LevelDB read errors from the
+ * chainstate, while keeping user interface out of the common library, which is shared
+ * between bitcoind, and bitcoin-qt and non-server tools.
+ *
+ * Writes do not need similar protection, as failure to write is handled by the caller.
+*/
+class CCoinsViewErrorCatcher final : public CCoinsViewBacked
+{
+public:
+ explicit CCoinsViewErrorCatcher(CCoinsView* view) : CCoinsViewBacked(view) {}
+
+ void AddReadErrCallback(std::function<void()> f) {
+ m_err_callbacks.emplace_back(std::move(f));
+ }
+
+ bool GetCoin(const COutPoint &outpoint, Coin &coin) const override;
+
+private:
+ /** A list of callbacks to execute upon leveldb read error. */
+ std::vector<std::function<void()>> m_err_callbacks;
+
+};
+
#endif // BITCOIN_COINS_H