From 45816e45270ab022bbd49ef7b78552f8694b3de2 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 23 Oct 2016 13:44:07 -0700 Subject: [PATCH] walletdb: better wallet commits. --- lib/wallet/walletdb.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/wallet/walletdb.js b/lib/wallet/walletdb.js index a2aaec09..ff39e971 100644 --- a/lib/wallet/walletdb.js +++ b/lib/wallet/walletdb.js @@ -421,9 +421,18 @@ WalletDB.prototype.batch = function batch(wallet) { */ WalletDB.prototype.commit = co(function* commit(wallet) { - var batch = wallet.current; + var batch = this.batch(wallet); + + try { + yield batch.write(); + } catch (e) { + wallet.current = null; + wallet.accountCache.drop(); + wallet.pathCache.drop(); + throw e; + } + wallet.current = null; - yield batch.write(); wallet.accountCache.commit(); wallet.pathCache.commit(); });