diff --git a/src/chainparams.cpp b/src/chainparams.cpp index c436d872c..fd6191d17 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -225,7 +225,6 @@ public: (525000, uint256S("0x0000000001a36c500378be8862d9bf1bea8f1616da6e155971b608139cc7e39b")), 1556722044, // * UNIX timestamp of last checkpoint block 4653556, // * total number of transactions between genesis and last checkpoint - // (the tx=... number in the SetBestChain debug.log lines) 5106 // * estimated number of transactions per day after checkpoint // total number of tx / (checkpoint block height / (24 * 24)) }; @@ -513,7 +512,6 @@ public: (38000, uint256S("0x001e9a2d2e2892b88e9998cf7b079b41d59dd085423a921fe8386cecc42287b8")), 1486897419, // * UNIX timestamp of last checkpoint block 47163, // * total number of transactions between genesis and last checkpoint - // (the tx=... number in the SetBestChain debug.log lines) 715 // total number of tx / (checkpoint block height / (24 * 24)) }; diff --git a/src/init.cpp b/src/init.cpp index f082a840f..52303738b 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -223,9 +223,6 @@ void Shutdown() if (pcoinsTip != NULL) { FlushStateToDisk(); } - // Flush the wallet witness cache to disk (no longer done by FlushStateToDisk()) - GetMainSignals().SetBestChain(chainActive.GetLocator()); - delete pcoinsTip; pcoinsTip = NULL; delete pcoinscatcher; diff --git a/src/main.h b/src/main.h index fb0703273..e077dffcb 100644 --- a/src/main.h +++ b/src/main.h @@ -100,6 +100,10 @@ static const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024; static const unsigned int DATABASE_WRITE_INTERVAL = 60 * 60; /** Time to wait (in seconds) between flushing chainstate to disk. */ static const unsigned int DATABASE_FLUSH_INTERVAL = 24 * 60 * 60; +/** 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; /** Maximum length of reject messages. */ static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111; static const unsigned int DEFAULT_LIMITFREERELAY = 15; diff --git a/src/validationinterface.cpp b/src/validationinterface.cpp index db9f8e47e..984f68443 100644 --- a/src/validationinterface.cpp +++ b/src/validationinterface.cpp @@ -29,7 +29,6 @@ void RegisterValidationInterface(CValidationInterface* pwalletIn) { g_signals.EraseTransaction.connect(boost::bind(&CValidationInterface::EraseFromWallet, pwalletIn, _1)); g_signals.UpdatedTransaction.connect(boost::bind(&CValidationInterface::UpdatedTransaction, pwalletIn, _1)); g_signals.ChainTip.connect(boost::bind(&CValidationInterface::ChainTip, pwalletIn, _1, _2, _3)); - g_signals.SetBestChain.connect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1)); g_signals.Inventory.connect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1)); g_signals.Broadcast.connect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn, _1)); g_signals.BlockChecked.connect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2)); @@ -44,7 +43,6 @@ void UnregisterValidationInterface(CValidationInterface* pwalletIn) { g_signals.Broadcast.disconnect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn, _1)); g_signals.Inventory.disconnect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1)); g_signals.ChainTip.disconnect(boost::bind(&CValidationInterface::ChainTip, pwalletIn, _1, _2, _3)); - g_signals.SetBestChain.disconnect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1)); g_signals.UpdatedTransaction.disconnect(boost::bind(&CValidationInterface::UpdatedTransaction, pwalletIn, _1)); g_signals.EraseTransaction.disconnect(boost::bind(&CValidationInterface::EraseFromWallet, pwalletIn, _1)); g_signals.SyncTransaction.disconnect(boost::bind(&CValidationInterface::SyncTransaction, pwalletIn, _1, _2, _3)); @@ -58,7 +56,6 @@ void UnregisterAllValidationInterfaces() { g_signals.Broadcast.disconnect_all_slots(); g_signals.Inventory.disconnect_all_slots(); g_signals.ChainTip.disconnect_all_slots(); - g_signals.SetBestChain.disconnect_all_slots(); g_signals.UpdatedTransaction.disconnect_all_slots(); g_signals.EraseTransaction.disconnect_all_slots(); g_signals.SyncTransaction.disconnect_all_slots(); diff --git a/src/validationinterface.h b/src/validationinterface.h index f1694a313..127848947 100644 --- a/src/validationinterface.h +++ b/src/validationinterface.h @@ -36,7 +36,6 @@ protected: virtual void SyncTransaction(const CTransaction &tx, const CBlock *pblock, const int nHeight) {} virtual void EraseFromWallet(const uint256 &hash) {} virtual void ChainTip(const CBlockIndex *pindex, const CBlock *pblock, boost::optional> added) {} - virtual void SetBestChain(const CBlockLocator &locator) {} virtual void UpdatedTransaction(const uint256 &hash) {} virtual void Inventory(const uint256 &hash) {} virtual void ResendWalletTransactions(int64_t nBestBlockTime) {} @@ -59,8 +58,6 @@ struct CMainSignals { boost::signals2::signal UpdatedTransaction; /** Notifies listeners of a change to the tip of the active block chain. */ boost::signals2::signal>)> ChainTip; - /** Notifies listeners of a new active block chain. */ - boost::signals2::signal SetBestChain; /** Notifies listeners about an inventory item being seen on the network. */ boost::signals2::signal Inventory; /** Tells listeners to broadcast their data. */ diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 837a26a3e..0dabd6329 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -587,18 +587,26 @@ void CWallet::ChainTipAdded(const CBlockIndex *pindex, IncrementNoteWitnesses(pindex, pblock, sproutTree, saplingTree); UpdateSaplingNullifierNoteMapForBlock(pblock); - // SetBestChain() can be expensive for large wallets, so do this - // at most once per hour; the wallet state will be brought up to - // date during rescanning on startup. + // 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; } - if (nLastSetChain + (int64_t)DATABASE_WRITE_INTERVAL * 1000000 < nNow) { + if (++nSetChainUpdates >= WITNESS_WRITE_UPDATES || + nLastSetChain + (int64_t)WITNESS_WRITE_INTERVAL * 1000000 < nNow) { nLastSetChain = nNow; - LOCK(cs_main); - SetBestChain(chainActive.GetLocator()); + 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); + } + SetBestChain(loc); } } diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 9bf7001ae..d65e94e6b 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -767,6 +767,7 @@ private: int64_t nNextResend; int64_t nLastResend; int64_t nLastSetChain; + int nSetChainUpdates; bool fBroadcastTransactions; template @@ -928,6 +929,7 @@ public: nNextResend = 0; nLastResend = 0; nLastSetChain = 0; + nSetChainUpdates = 0; nTimeFirstKey = 0; fBroadcastTransactions = false; nWitnessCacheSize = 0;