mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-21 14:34:49 +01:00
Implement CCoinsViewErrorCatcher::HaveCoin
This commit is contained in:
parent
a52ff619a4
commit
7fe537f7a4
2 changed files with 14 additions and 3 deletions
|
@ -292,11 +292,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());
|
||||
|
@ -307,3 +309,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);
|
||||
}
|
||||
|
|
|
@ -349,6 +349,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. */
|
||||
|
|
Loading…
Add table
Reference in a new issue