| 748 | } |
| 749 | |
| 750 | void MaybeCompactWalletDB() |
| 751 | { |
| 752 | static std::atomic<bool> fOneThread(false); |
| 753 | if (fOneThread.exchange(true)) { |
| 754 | return; |
| 755 | } |
| 756 | if (!gArgs.GetBoolArg("-flushwallet", DEFAULT_FLUSHWALLET)) { |
| 757 | return; |
| 758 | } |
| 759 | |
| 760 | for (const std::shared_ptr<CWallet>& pwallet : GetWallets()) { |
| 761 | WalletDatabase& dbh = pwallet->GetDBHandle(); |
| 762 | |
| 763 | unsigned int nUpdateCounter = dbh.nUpdateCounter; |
| 764 | |
| 765 | if (dbh.nLastSeen != nUpdateCounter) { |
| 766 | dbh.nLastSeen = nUpdateCounter; |
| 767 | dbh.nLastWalletUpdate = GetTime(); |
| 768 | } |
| 769 | |
| 770 | if (dbh.nLastFlushed != nUpdateCounter && GetTime() - dbh.nLastWalletUpdate >= 2) { |
| 771 | if (BerkeleyBatch::PeriodicFlush(dbh)) { |
| 772 | dbh.nLastFlushed = nUpdateCounter; |
| 773 | } |
| 774 | } |
| 775 | } |
| 776 | |
| 777 | fOneThread = false; |
| 778 | } |
| 779 | |
| 780 | // |
| 781 | // Try to (very carefully!) recover wallet file if there is a problem. |
nothing calls this directly
no test coverage detected