aboutsummaryrefslogtreecommitdiff
path: root/src/wallet.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2012-07-06 16:33:34 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2012-10-20 23:08:57 +0200
commitae8bfd12daa802d20791e69d3477e799d2b99f45 (patch)
tree848867135da5954b7155ebe98c09db66d09d5737 /src/wallet.cpp
parent450cbb0944cd20a06ce806e6679a1f4c83c50db2 (diff)
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.
Diffstat (limited to 'src/wallet.cpp')
-rw-r--r--src/wallet.cpp21
1 files changed, 7 insertions, 14 deletions
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();
}
}
}