Auto merge of #4690 - LarryRuane:CopyPreviousWitnessesPart2, r=str4d
Flush witness data when consistent (part 2) Closes #4680. 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:
commit
31f48caf0e
|
@ -278,7 +278,6 @@ public:
|
||||||
(525000, uint256S("0x0000000001a36c500378be8862d9bf1bea8f1616da6e155971b608139cc7e39b")),
|
(525000, uint256S("0x0000000001a36c500378be8862d9bf1bea8f1616da6e155971b608139cc7e39b")),
|
||||||
1556722044, // * UNIX timestamp of last checkpoint block
|
1556722044, // * UNIX timestamp of last checkpoint block
|
||||||
4653556, // * total number of transactions between genesis and last checkpoint
|
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
|
5106 // * estimated number of transactions per day after checkpoint
|
||||||
// total number of tx / (checkpoint block height / (24 * 24))
|
// total number of tx / (checkpoint block height / (24 * 24))
|
||||||
};
|
};
|
||||||
|
@ -566,7 +565,6 @@ public:
|
||||||
(38000, uint256S("0x001e9a2d2e2892b88e9998cf7b079b41d59dd085423a921fe8386cecc42287b8")),
|
(38000, uint256S("0x001e9a2d2e2892b88e9998cf7b079b41d59dd085423a921fe8386cecc42287b8")),
|
||||||
1486897419, // * UNIX timestamp of last checkpoint block
|
1486897419, // * UNIX timestamp of last checkpoint block
|
||||||
47163, // * total number of transactions between genesis and last checkpoint
|
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))
|
715 // total number of tx / (checkpoint block height / (24 * 24))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -223,9 +223,6 @@ void Shutdown()
|
||||||
if (pcoinsTip != NULL) {
|
if (pcoinsTip != NULL) {
|
||||||
FlushStateToDisk();
|
FlushStateToDisk();
|
||||||
}
|
}
|
||||||
// Flush the wallet witness cache to disk (no longer done by FlushStateToDisk())
|
|
||||||
GetMainSignals().SetBestChain(chainActive.GetLocator());
|
|
||||||
|
|
||||||
delete pcoinsTip;
|
delete pcoinsTip;
|
||||||
pcoinsTip = NULL;
|
pcoinsTip = NULL;
|
||||||
delete pcoinscatcher;
|
delete pcoinscatcher;
|
||||||
|
|
|
@ -100,6 +100,10 @@ static const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024;
|
||||||
static const unsigned int DATABASE_WRITE_INTERVAL = 60 * 60;
|
static const unsigned int DATABASE_WRITE_INTERVAL = 60 * 60;
|
||||||
/** Time to wait (in seconds) between flushing chainstate to disk. */
|
/** Time to wait (in seconds) between flushing chainstate to disk. */
|
||||||
static const unsigned int DATABASE_FLUSH_INTERVAL = 24 * 60 * 60;
|
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. */
|
/** Maximum length of reject messages. */
|
||||||
static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111;
|
static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111;
|
||||||
static const unsigned int DEFAULT_LIMITFREERELAY = 15;
|
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.EraseTransaction.connect(boost::bind(&CValidationInterface::EraseFromWallet, pwalletIn, _1));
|
||||||
g_signals.UpdatedTransaction.connect(boost::bind(&CValidationInterface::UpdatedTransaction, 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.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.Inventory.connect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1));
|
||||||
g_signals.Broadcast.connect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn, _1));
|
g_signals.Broadcast.connect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn, _1));
|
||||||
g_signals.BlockChecked.connect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2));
|
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.Broadcast.disconnect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn, _1));
|
||||||
g_signals.Inventory.disconnect(boost::bind(&CValidationInterface::Inventory, 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.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.UpdatedTransaction.disconnect(boost::bind(&CValidationInterface::UpdatedTransaction, pwalletIn, _1));
|
||||||
g_signals.EraseTransaction.disconnect(boost::bind(&CValidationInterface::EraseFromWallet, pwalletIn, _1));
|
g_signals.EraseTransaction.disconnect(boost::bind(&CValidationInterface::EraseFromWallet, pwalletIn, _1));
|
||||||
g_signals.SyncTransaction.disconnect(boost::bind(&CValidationInterface::SyncTransaction, pwalletIn, _1, _2, _3));
|
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.Broadcast.disconnect_all_slots();
|
||||||
g_signals.Inventory.disconnect_all_slots();
|
g_signals.Inventory.disconnect_all_slots();
|
||||||
g_signals.ChainTip.disconnect_all_slots();
|
g_signals.ChainTip.disconnect_all_slots();
|
||||||
g_signals.SetBestChain.disconnect_all_slots();
|
|
||||||
g_signals.UpdatedTransaction.disconnect_all_slots();
|
g_signals.UpdatedTransaction.disconnect_all_slots();
|
||||||
g_signals.EraseTransaction.disconnect_all_slots();
|
g_signals.EraseTransaction.disconnect_all_slots();
|
||||||
g_signals.SyncTransaction.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 SyncTransaction(const CTransaction &tx, const CBlock *pblock, const int nHeight) {}
|
||||||
virtual void EraseFromWallet(const uint256 &hash) {}
|
virtual void EraseFromWallet(const uint256 &hash) {}
|
||||||
virtual void ChainTip(const CBlockIndex *pindex, const CBlock *pblock, boost::optional<std::pair<SproutMerkleTree, SaplingMerkleTree>> added) {}
|
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 UpdatedTransaction(const uint256 &hash) {}
|
||||||
virtual void Inventory(const uint256 &hash) {}
|
virtual void Inventory(const uint256 &hash) {}
|
||||||
virtual void ResendWalletTransactions(int64_t nBestBlockTime) {}
|
virtual void ResendWalletTransactions(int64_t nBestBlockTime) {}
|
||||||
|
@ -59,8 +58,6 @@ struct CMainSignals {
|
||||||
boost::signals2::signal<void (const uint256 &)> UpdatedTransaction;
|
boost::signals2::signal<void (const uint256 &)> UpdatedTransaction;
|
||||||
/** Notifies listeners of a change to the tip of the active block chain. */
|
/** 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;
|
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. */
|
/** Notifies listeners about an inventory item being seen on the network. */
|
||||||
boost::signals2::signal<void (const uint256 &)> Inventory;
|
boost::signals2::signal<void (const uint256 &)> Inventory;
|
||||||
/** Tells listeners to broadcast their data. */
|
/** Tells listeners to broadcast their data. */
|
||||||
|
|
|
@ -587,18 +587,26 @@ void CWallet::ChainTipAdded(const CBlockIndex *pindex,
|
||||||
IncrementNoteWitnesses(pindex, pblock, sproutTree, saplingTree);
|
IncrementNoteWitnesses(pindex, pblock, sproutTree, saplingTree);
|
||||||
UpdateSaplingNullifierNoteMapForBlock(pblock);
|
UpdateSaplingNullifierNoteMapForBlock(pblock);
|
||||||
|
|
||||||
// SetBestChain() can be expensive for large wallets, so do this
|
// SetBestChain() can be expensive for large wallets, so do only
|
||||||
// at most once per hour; the wallet state will be brought up to
|
// this sometimes; the wallet state will be brought up to date
|
||||||
// date during rescanning on startup.
|
// during rescanning on startup.
|
||||||
int64_t nNow = GetTimeMicros();
|
int64_t nNow = GetTimeMicros();
|
||||||
if (nLastSetChain == 0) {
|
if (nLastSetChain == 0) {
|
||||||
// Don't flush during startup.
|
// Don't flush during startup.
|
||||||
nLastSetChain = nNow;
|
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;
|
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);
|
LOCK(cs_main);
|
||||||
SetBestChain(chainActive.GetLocator());
|
loc = chainActive.GetLocator(pindex);
|
||||||
|
}
|
||||||
|
SetBestChain(loc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -767,6 +767,7 @@ private:
|
||||||
int64_t nNextResend;
|
int64_t nNextResend;
|
||||||
int64_t nLastResend;
|
int64_t nLastResend;
|
||||||
int64_t nLastSetChain;
|
int64_t nLastSetChain;
|
||||||
|
int nSetChainUpdates;
|
||||||
bool fBroadcastTransactions;
|
bool fBroadcastTransactions;
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
|
@ -928,6 +929,7 @@ public:
|
||||||
nNextResend = 0;
|
nNextResend = 0;
|
||||||
nLastResend = 0;
|
nLastResend = 0;
|
||||||
nLastSetChain = 0;
|
nLastSetChain = 0;
|
||||||
|
nSetChainUpdates = 0;
|
||||||
nTimeFirstKey = 0;
|
nTimeFirstKey = 0;
|
||||||
fBroadcastTransactions = false;
|
fBroadcastTransactions = false;
|
||||||
nWitnessCacheSize = 0;
|
nWitnessCacheSize = 0;
|
||||||
|
|
Loading…
Reference in New Issue