From ae8bfd12daa802d20791e69d3477e799d2b99f45 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Fri, 6 Jul 2012 16:33:34 +0200 Subject: Batch block connection during IBD During the initial block download (or -loadblock), delay connection of new blocks a bit, and perform them in a single action. This reduces the load on the database engine, as subsequent blocks often update an earlier block's transaction already. --- src/wallet.cpp | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'src/wallet.cpp') diff --git a/src/wallet.cpp b/src/wallet.cpp index 9b2960f64e..5b32034696 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -767,7 +767,6 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate) void CWallet::ReacceptWalletTransactions() { - CCoinsDB coinsdb("r"); bool fRepeat = true; while (fRepeat) { @@ -782,7 +781,7 @@ void CWallet::ReacceptWalletTransactions() CCoins coins; bool fUpdated = false; - bool fNotFound = coinsdb.ReadCoins(wtx.GetHash(), coins); + bool fNotFound = pcoinsTip->GetCoins(wtx.GetHash(), coins); if (!fNotFound || wtx.GetDepthInMainChain() > 0) { // Update fSpent if a tx got spent somewhere else by a copy of wallet.dat @@ -808,7 +807,7 @@ void CWallet::ReacceptWalletTransactions() { // Re-accept any txes of ours that aren't already in a block if (!wtx.IsCoinBase()) - wtx.AcceptWalletTransaction(coinsdb, false); + wtx.AcceptWalletTransaction(false); } } if (fMissing) @@ -820,21 +819,22 @@ void CWallet::ReacceptWalletTransactions() } } -void CWalletTx::RelayWalletTransaction(CCoinsDB& coinsdb) +void CWalletTx::RelayWalletTransaction() { + CCoinsViewCache& coins = *pcoinsTip; BOOST_FOREACH(const CMerkleTx& tx, vtxPrev) { if (!tx.IsCoinBase()) { uint256 hash = tx.GetHash(); - if (!coinsdb.HaveCoins(hash)) + if (!coins.HaveCoins(hash)) RelayMessage(CInv(MSG_TX, hash), (CTransaction)tx); } } if (!IsCoinBase()) { uint256 hash = GetHash(); - if (!coinsdb.HaveCoins(hash)) + if (!coins.HaveCoins(hash)) { printf("Relaying wtx %s\n", hash.ToString().substr(0,10).c_str()); RelayMessage(CInv(MSG_TX, hash), (CTransaction)*this); @@ -842,12 +842,6 @@ void CWalletTx::RelayWalletTransaction(CCoinsDB& coinsdb) } } -void CWalletTx::RelayWalletTransaction() -{ - CCoinsDB coinsdb("r"); - RelayWalletTransaction(coinsdb); -} - void CWallet::ResendWalletTransactions() { // Do this infrequently and randomly to avoid giving away @@ -868,7 +862,6 @@ void CWallet::ResendWalletTransactions() // Rebroadcast any of our txes that aren't in a block yet printf("ResendWalletTransactions()\n"); - CCoinsDB coinsdb("r"); { LOCK(cs_wallet); // Sort them in chronological order @@ -884,7 +877,7 @@ void CWallet::ResendWalletTransactions() BOOST_FOREACH(PAIRTYPE(const unsigned int, CWalletTx*)& item, mapSorted) { CWalletTx& wtx = *item.second; - wtx.RelayWalletTransaction(coinsdb); + wtx.RelayWalletTransaction(); } } } -- cgit v1.2.3