mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 23:29:12 +01:00
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.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user