aboutsummaryrefslogtreecommitdiff
path: root/src/wallet.cpp
diff options
context:
space:
mode:
authorCozz Lovan <cozzlovan@yahoo.com>2014-08-31 05:55:27 +0200
committerCozz Lovan <cozzlovan@yahoo.com>2014-10-03 05:11:27 +0200
commit44bc988e7becb492a78ed92ea1052f4789012534 (patch)
treee7ce5489c4f331b71bc55c24cfcd89393097f069 /src/wallet.cpp
parent29f96e8bc652cb14c6fdefe5279ee983054faa2a (diff)
[Wallet] Do not flush the wallet in AddToWalletIfInvolvingMe(..)
Diffstat (limited to 'src/wallet.cpp')
-rw-r--r--src/wallet.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/wallet.cpp b/src/wallet.cpp
index b20b0007ce..caf1f67f51 100644
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -512,7 +512,7 @@ void CWallet::MarkDirty()
}
}
-bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet)
+bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletDB* pwalletdb)
{
uint256 hash = wtxIn.GetHash();
@@ -533,7 +533,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet)
if (fInsertedNew)
{
wtx.nTimeReceived = GetAdjustedTime();
- wtx.nOrderPos = IncOrderPosNext();
+ wtx.nOrderPos = IncOrderPosNext(pwalletdb);
wtx.nTimeSmart = wtx.nTimeReceived;
if (wtxIn.hashBlock != 0)
@@ -610,7 +610,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet)
// Write to disk
if (fInsertedNew || fUpdated)
- if (!wtx.WriteToDisk())
+ if (!wtx.WriteToDisk(pwalletdb))
return false;
// Break debit/credit balance caches:
@@ -644,10 +644,16 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl
if (fExisted || IsMine(tx) || IsFromMe(tx))
{
CWalletTx wtx(this,tx);
+
// Get merkle branch if transaction was found in a block
if (pblock)
wtx.SetMerkleBranch(*pblock);
- return AddToWallet(wtx);
+
+ // Do not flush the wallet here for performance reasons
+ // this is safe, as in case of a crash, we rescan the necessary blocks on startup through our SetBestChain-mechanism
+ CWalletDB walletdb(strWalletFile, "r+", false);
+
+ return AddToWallet(wtx, false, &walletdb);
}
}
return false;
@@ -871,9 +877,9 @@ void CWalletTx::GetAccountAmounts(const string& strAccount, CAmount& nReceived,
}
-bool CWalletTx::WriteToDisk()
+bool CWalletTx::WriteToDisk(CWalletDB *pwalletdb)
{
- return CWalletDB(pwallet->strWalletFile).WriteTx(GetHash(), *this);
+ return pwalletdb->WriteTx(GetHash(), *this);
}
// Scan the block chain (starting in pindexStart) for transactions
@@ -1499,14 +1505,14 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey)
// This is only to keep the database open to defeat the auto-flush for the
// duration of this scope. This is the only place where this optimization
// maybe makes sense; please don't do it anywhere else.
- CWalletDB* pwalletdb = fFileBacked ? new CWalletDB(strWalletFile,"r") : NULL;
+ CWalletDB* pwalletdb = fFileBacked ? new CWalletDB(strWalletFile,"r+") : NULL;
// Take key pair from key pool so it won't be used again
reservekey.KeepKey();
// Add tx to wallet, because if it has change it's also ours,
// otherwise just for transaction history.
- AddToWallet(wtxNew);
+ AddToWallet(wtxNew, false, pwalletdb);
// Notify that old coins are spent
set<CWalletTx*> setCoins;