Merge tree and boolean fields in ChainTip API
The trees were being unnecessarily fetched during DisconnectTip.
This commit is contained in:
parent
a28916d273
commit
a71a7341b9
|
@ -3014,18 +3014,13 @@ bool static DisconnectTip(CValidationState &state, const CChainParams& chainpara
|
|||
|
||||
// Update chainActive and related variables.
|
||||
UpdateTip(pindexDelete->pprev, chainparams);
|
||||
// Get the current commitment tree
|
||||
SproutMerkleTree newSproutTree;
|
||||
SaplingMerkleTree newSaplingTree;
|
||||
assert(pcoinsTip->GetSproutAnchorAt(pcoinsTip->GetBestAnchor(SPROUT), newSproutTree));
|
||||
assert(pcoinsTip->GetSaplingAnchorAt(pcoinsTip->GetBestAnchor(SAPLING), newSaplingTree));
|
||||
// Let wallets know transactions went from 1-confirmed to
|
||||
// 0-confirmed or conflicted:
|
||||
BOOST_FOREACH(const CTransaction &tx, block.vtx) {
|
||||
SyncWithWallets(tx, NULL);
|
||||
}
|
||||
// Update cached incremental witnesses
|
||||
GetMainSignals().ChainTip(pindexDelete, &block, newSproutTree, newSaplingTree, false);
|
||||
GetMainSignals().ChainTip(pindexDelete, &block, boost::none);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -3100,7 +3095,7 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
|
|||
SyncWithWallets(tx, pblock);
|
||||
}
|
||||
// Update cached incremental witnesses
|
||||
GetMainSignals().ChainTip(pindexNew, pblock, oldSproutTree, oldSaplingTree, true);
|
||||
GetMainSignals().ChainTip(pindexNew, pblock, std::make_pair(oldSproutTree, oldSaplingTree));
|
||||
|
||||
EnforceNodeDeprecation(pindexNew->nHeight);
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ void RegisterValidationInterface(CValidationInterface* pwalletIn) {
|
|||
g_signals.SyncTransaction.connect(boost::bind(&CValidationInterface::SyncTransaction, pwalletIn, _1, _2));
|
||||
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, _4, _5));
|
||||
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));
|
||||
|
@ -40,7 +40,7 @@ void UnregisterValidationInterface(CValidationInterface* pwalletIn) {
|
|||
g_signals.BlockChecked.disconnect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2));
|
||||
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, _4, _5));
|
||||
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));
|
||||
|
|
|
@ -36,7 +36,7 @@ protected:
|
|||
virtual void UpdatedBlockTip(const CBlockIndex *pindex) {}
|
||||
virtual void SyncTransaction(const CTransaction &tx, const CBlock *pblock) {}
|
||||
virtual void EraseFromWallet(const uint256 &hash) {}
|
||||
virtual void ChainTip(const CBlockIndex *pindex, const CBlock *pblock, SproutMerkleTree sproutTree, SaplingMerkleTree saplingTree, bool 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 Inventory(const uint256 &hash) {}
|
||||
|
@ -59,7 +59,7 @@ struct CMainSignals {
|
|||
/** Notifies listeners of an updated transaction without new data (for now: a coinbase potentially becoming visible). */
|
||||
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 *, SproutMerkleTree, SaplingMerkleTree, bool)> 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. */
|
||||
|
|
|
@ -574,12 +574,10 @@ void CWallet::ChainTipAdded(const CBlockIndex *pindex,
|
|||
|
||||
void CWallet::ChainTip(const CBlockIndex *pindex,
|
||||
const CBlock *pblock,
|
||||
SproutMerkleTree sproutTree,
|
||||
SaplingMerkleTree saplingTree,
|
||||
bool added)
|
||||
boost::optional<std::pair<SproutMerkleTree, SaplingMerkleTree>> added)
|
||||
{
|
||||
if (added) {
|
||||
ChainTipAdded(pindex, pblock, sproutTree, saplingTree);
|
||||
ChainTipAdded(pindex, pblock, added->first, added->second);
|
||||
// Prevent migration transactions from being created when node is syncing after launch,
|
||||
// and also when node wakes up from suspension/hibernation and incoming blocks are old.
|
||||
if (!IsInitialBlockDownload(Params()) &&
|
||||
|
|
|
@ -1195,7 +1195,10 @@ public:
|
|||
CAmount GetDebit(const CTransaction& tx, const isminefilter& filter) const;
|
||||
CAmount GetCredit(const CTransaction& tx, const isminefilter& filter) const;
|
||||
CAmount GetChange(const CTransaction& tx) const;
|
||||
void ChainTip(const CBlockIndex *pindex, const CBlock *pblock, SproutMerkleTree sproutTree, SaplingMerkleTree saplingTree, bool added);
|
||||
void ChainTip(
|
||||
const CBlockIndex *pindex,
|
||||
const CBlock *pblock,
|
||||
boost::optional<std::pair<SproutMerkleTree, SaplingMerkleTree>> added);
|
||||
void RunSaplingMigration(int blockHeight);
|
||||
void AddPendingSaplingMigrationTx(const CTransaction& tx);
|
||||
/** Saves witness caches and best block locator to disk. */
|
||||
|
|
|
@ -350,7 +350,7 @@ double benchmark_increment_sprout_note_witnesses(size_t nTxs)
|
|||
index1.nHeight = 1;
|
||||
|
||||
// Increment to get transactions witnessed
|
||||
wallet.ChainTip(&index1, &block1, sproutTree, saplingTree, true);
|
||||
wallet.ChainTip(&index1, &block1, std::make_pair(sproutTree, saplingTree));
|
||||
|
||||
// Second block
|
||||
CBlock block2;
|
||||
|
@ -366,7 +366,7 @@ double benchmark_increment_sprout_note_witnesses(size_t nTxs)
|
|||
|
||||
struct timeval tv_start;
|
||||
timer_start(tv_start);
|
||||
wallet.ChainTip(&index2, &block2, sproutTree, saplingTree, true);
|
||||
wallet.ChainTip(&index2, &block2, std::make_pair(sproutTree, saplingTree));
|
||||
return timer_stop(tv_start);
|
||||
}
|
||||
|
||||
|
@ -412,7 +412,7 @@ double benchmark_increment_sapling_note_witnesses(size_t nTxs)
|
|||
index1.nHeight = 1;
|
||||
|
||||
// Increment to get transactions witnessed
|
||||
wallet.ChainTip(&index1, &block1, sproutTree, saplingTree, true);
|
||||
wallet.ChainTip(&index1, &block1, std::make_pair(sproutTree, saplingTree));
|
||||
|
||||
// Second block
|
||||
CBlock block2;
|
||||
|
@ -428,7 +428,7 @@ double benchmark_increment_sapling_note_witnesses(size_t nTxs)
|
|||
|
||||
struct timeval tv_start;
|
||||
timer_start(tv_start);
|
||||
wallet.ChainTip(&index2, &block2, sproutTree, saplingTree, true);
|
||||
wallet.ChainTip(&index2, &block2, std::make_pair(sproutTree, saplingTree));
|
||||
return timer_stop(tv_start);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue