Flush witness data when consistent (part 2)
After CWallet::ChainTipAdded() updates the witness data, it may flush it to disk (SetBestChain()); make sure the locator part is consistent with the witnesses (height).
This commit is contained in:
parent
16c99c2c4e
commit
81db0a2fc7
|
@ -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))
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<std::pair<SproutMerkleTree, SaplingMerkleTree>> 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<void (const uint256 &)> UpdatedTransaction;
|
||||
/** Notifies listeners of a change to the tip of the active block chain. */
|
||||
boost::signals2::signal<void (const CBlockIndex *, const CBlock *, boost::optional<std::pair<SproutMerkleTree, SaplingMerkleTree>>)> ChainTip;
|
||||
/** Notifies listeners of a new active block chain. */
|
||||
boost::signals2::signal<void (const CBlockLocator &)> SetBestChain;
|
||||
/** Notifies listeners about an inventory item being seen on the network. */
|
||||
boost::signals2::signal<void (const uint256 &)> Inventory;
|
||||
/** Tells listeners to broadcast their data. */
|
||||
|
|
|
@ -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;
|
||||
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);
|
||||
SetBestChain(chainActive.GetLocator());
|
||||
loc = chainActive.GetLocator(pindex);
|
||||
}
|
||||
SetBestChain(loc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -767,6 +767,7 @@ private:
|
|||
int64_t nNextResend;
|
||||
int64_t nLastResend;
|
||||
int64_t nLastSetChain;
|
||||
int nSetChainUpdates;
|
||||
bool fBroadcastTransactions;
|
||||
|
||||
template <class T>
|
||||
|
@ -928,6 +929,7 @@ public:
|
|||
nNextResend = 0;
|
||||
nLastResend = 0;
|
||||
nLastSetChain = 0;
|
||||
nSetChainUpdates = 0;
|
||||
nTimeFirstKey = 0;
|
||||
fBroadcastTransactions = false;
|
||||
nWitnessCacheSize = 0;
|
||||
|
|
Loading…
Reference in New Issue