diff options
author | Luke Dashjr <luke-jr+git@utopios.org> | 2017-03-09 20:29:01 +0000 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2017-06-05 21:04:42 +0000 |
commit | f28eb8020e3bb341e7f16c6bf93da7e92c82ec94 (patch) | |
tree | ec6ab61e235bcd4cf0d3cdda2bf517ed6590db9f /src/wallet/walletdb.h | |
parent | 9fec4da0bec93a49798b5f5e92cf76e900759ee4 (diff) |
Bugfix: wallet: Increment "update counter" only after actually making the applicable db changes to avoid potential races
Also does all "update counter" access via IncrementUpdateCounter
Diffstat (limited to 'src/wallet/walletdb.h')
-rw-r--r-- | src/wallet/walletdb.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/wallet/walletdb.h b/src/wallet/walletdb.h index cd9fe279c5..0fafdb6a1b 100644 --- a/src/wallet/walletdb.h +++ b/src/wallet/walletdb.h @@ -140,6 +140,27 @@ public: */ class CWalletDB { +private: + template <typename K, typename T> + bool WriteIC(const K& key, const T& value, bool fOverwrite = true) + { + if (!batch.Write(key, value, fOverwrite)) { + return false; + } + IncrementUpdateCounter(); + return true; + } + + template <typename K> + bool EraseIC(const K& key) + { + if (!batch.Erase(key)) { + return false; + } + IncrementUpdateCounter(); + return true; + } + public: CWalletDB(CWalletDBWrapper& dbw, const char* pszMode = "r+", bool _fFlushOnClose = true) : batch(dbw, pszMode, _fFlushOnClose) |