Browse Source

Periodically call SetBestChain #370

setbestchain
Duke 6 months ago
parent
commit
a65beaf65b
  1. 4
      src/main.h
  2. 25
      src/wallet/wallet.cpp
  3. 4
      src/wallet/wallet.h

4
src/main.h

@ -113,6 +113,10 @@ static const unsigned int DATABASE_WRITE_INTERVAL = 60 * 60;
static const unsigned int DATABASE_FLUSH_INTERVAL = 24 * 60 * 60;
/** Maximum length of reject messages. */
static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111;
/** Time to wait (in seconds) between writing wallet witness data to disk. */
static const unsigned int WITNESS_WRITE_INTERVAL = 10 * 60;
/** Number of updates between writing wallet witness data to disk. */
static const unsigned int WITNESS_WRITE_UPDATES = 10000;
static const int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60;
// NSPV enabled?

25
src/wallet/wallet.cpp

@ -504,6 +504,31 @@ void CWallet::ChainTip(const CBlockIndex *pindex,
DecrementNoteWitnesses(pindex);
UpdateNullifierNoteMapForBlock(pblock);
}
// SetBestChain() can be expensive for large wallets, so do only
// this sometimes; the wallet state will be brought up to date
// during rescanning on startup.
int64_t nNow = GetTimeMicros();
if (nLastSetChain == 0) {
// Don't flush during startup.
nLastSetChain = nNow;
}
// TODO: SetBestChain if DeleteWalletTransactions deletes txs
if (++nSetChainUpdates >= WITNESS_WRITE_UPDATES || nLastSetChain + (int64_t)WITNESS_WRITE_INTERVAL * 1000000 < nNow) {
nLastSetChain = nNow;
nSetChainUpdates = 0;
CBlockLocator loc;
{
// The locator must be derived from the pindex used to increment
// the witnesses above; pindex can be behind chainActive.Tip().
LOCK(cs_main);
loc = chainActive.GetLocator(pindex);
}
{
LOCK(cs_wallet);
SetBestChain(loc);
}
}
}
void CWallet::RunSaplingSweep(int blockHeight) {

4
src/wallet/wallet.h

@ -764,6 +764,10 @@ private:
int64_t nNextResend;
int64_t nLastResend;
bool fBroadcastTransactions;
// The time we last did a SetBestChain
int64_t nLastSetChain;
// How many chain tips we have added since the last time we did a SetBestChain
int nSetChainUpdates;
template <class T>
using TxSpendMap = std::multimap<T, uint256>;

Loading…
Cancel
Save