aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/coins.cpp16
-rw-r--r--src/coins.h1
-rw-r--r--src/init.cpp9
3 files changed, 23 insertions, 3 deletions
diff --git a/src/coins.cpp b/src/coins.cpp
index 0fe642e46b..b44d920ee1 100644
--- a/src/coins.cpp
+++ b/src/coins.cpp
@@ -353,11 +353,13 @@ const Coin& AccessByTxid(const CCoinsViewCache& view, const uint256& txid)
return coinEmpty;
}
-bool CCoinsViewErrorCatcher::GetCoin(const COutPoint &outpoint, Coin &coin) const {
+template <typename Func>
+static bool ExecuteBackedWrapper(Func func, const std::vector<std::function<void()>>& err_callbacks)
+{
try {
- return CCoinsViewBacked::GetCoin(outpoint, coin);
+ return func();
} catch(const std::runtime_error& e) {
- for (const auto& f : m_err_callbacks) {
+ for (const auto& f : err_callbacks) {
f();
}
LogPrintf("Error reading from database: %s\n", e.what());
@@ -368,3 +370,11 @@ bool CCoinsViewErrorCatcher::GetCoin(const COutPoint &outpoint, Coin &coin) cons
std::abort();
}
}
+
+bool CCoinsViewErrorCatcher::GetCoin(const COutPoint &outpoint, Coin &coin) const {
+ return ExecuteBackedWrapper([&]() { return CCoinsViewBacked::GetCoin(outpoint, coin); }, m_err_callbacks);
+}
+
+bool CCoinsViewErrorCatcher::HaveCoin(const COutPoint &outpoint) const {
+ return ExecuteBackedWrapper([&]() { return CCoinsViewBacked::HaveCoin(outpoint); }, m_err_callbacks);
+}
diff --git a/src/coins.h b/src/coins.h
index 039a07054d..a6cbb03133 100644
--- a/src/coins.h
+++ b/src/coins.h
@@ -383,6 +383,7 @@ public:
}
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override;
+ bool HaveCoin(const COutPoint &outpoint) const override;
private:
/** A list of callbacks to execute upon leveldb read error. */
diff --git a/src/init.cpp b/src/init.cpp
index 98f233d9df..22100dfbf9 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -1138,6 +1138,15 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
RandAddPeriodic();
}, std::chrono::minutes{1});
+ // Check disk space every 5 minutes to avoid db corruption.
+ node.scheduler->scheduleEvery([&args]{
+ constexpr uint64_t min_disk_space = 50 << 20; // 50 MB
+ if (!CheckDiskSpace(args.GetBlocksDirPath(), min_disk_space)) {
+ LogPrintf("Shutting down due to lack of disk space!\n");
+ StartShutdown();
+ }
+ }, std::chrono::minutes{5});
+
GetMainSignals().RegisterBackgroundSignalScheduler(*node.scheduler);
// Create client interfaces for wallets that are supposed to be loaded