Browse Source

include the chaintip *blockIndex in the SyncTransaction signal

- allows reducing of calls to main.cpp for getting the chaintip during transaction syncing
- potentially allows reducing of cs_main locks
tags/v0.15.1
Jonas Schnelli 5 years ago
parent
commit
7d0bf0bb46
No account linked to committer's email address

+ 4
- 4
src/main.cpp View File

@@ -1234,7 +1234,7 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState &state, const C
}
}

SyncWithWallets(tx, NULL);
SyncWithWallets(tx, NULL, NULL);

return true;
}
@@ -2391,7 +2391,7 @@ bool static DisconnectTip(CValidationState& state, const Consensus::Params& cons
// Let wallets know transactions went from 1-confirmed to
// 0-confirmed or conflicted:
BOOST_FOREACH(const CTransaction &tx, block.vtx) {
SyncWithWallets(tx, NULL);
SyncWithWallets(tx, pindexDelete->pprev, NULL);
}
return true;
}
@@ -2450,11 +2450,11 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
// Tell wallet about transactions that went from mempool
// to conflicted:
BOOST_FOREACH(const CTransaction &tx, txConflicted) {
SyncWithWallets(tx, NULL);
SyncWithWallets(tx, pindexNew, NULL);
}
// ... and about transactions that got confirmed:
BOOST_FOREACH(const CTransaction &tx, pblock->vtx) {
SyncWithWallets(tx, pblock);
SyncWithWallets(tx, pindexNew, pblock);
}

int64_t nTime6 = GetTimeMicros(); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1;

+ 4
- 4
src/validationinterface.cpp View File

@@ -14,7 +14,7 @@ CMainSignals& GetMainSignals()

void RegisterValidationInterface(CValidationInterface* pwalletIn) {
g_signals.UpdatedBlockTip.connect(boost::bind(&CValidationInterface::UpdatedBlockTip, pwalletIn, _1));
g_signals.SyncTransaction.connect(boost::bind(&CValidationInterface::SyncTransaction, pwalletIn, _1, _2));
g_signals.SyncTransaction.connect(boost::bind(&CValidationInterface::SyncTransaction, pwalletIn, _1, _2, _3));
g_signals.UpdatedTransaction.connect(boost::bind(&CValidationInterface::UpdatedTransaction, pwalletIn, _1));
g_signals.SetBestChain.connect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1));
g_signals.Inventory.connect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1));
@@ -32,7 +32,7 @@ void UnregisterValidationInterface(CValidationInterface* pwalletIn) {
g_signals.Inventory.disconnect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1));
g_signals.SetBestChain.disconnect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1));
g_signals.UpdatedTransaction.disconnect(boost::bind(&CValidationInterface::UpdatedTransaction, pwalletIn, _1));
g_signals.SyncTransaction.disconnect(boost::bind(&CValidationInterface::SyncTransaction, pwalletIn, _1, _2));
g_signals.SyncTransaction.disconnect(boost::bind(&CValidationInterface::SyncTransaction, pwalletIn, _1, _2, _3));
g_signals.UpdatedBlockTip.disconnect(boost::bind(&CValidationInterface::UpdatedBlockTip, pwalletIn, _1));
}

@@ -48,6 +48,6 @@ void UnregisterAllValidationInterfaces() {
g_signals.UpdatedBlockTip.disconnect_all_slots();
}

void SyncWithWallets(const CTransaction &tx, const CBlock *pblock) {
g_signals.SyncTransaction(tx, pblock);
void SyncWithWallets(const CTransaction &tx, const CBlockIndex *pindex, const CBlock *pblock) {
g_signals.SyncTransaction(tx, pindex, pblock);
}

+ 4
- 3
src/validationinterface.h View File

@@ -10,6 +10,7 @@
#include <boost/shared_ptr.hpp>

class CBlock;
class CBlockIndex;
struct CBlockLocator;
class CBlockIndex;
class CReserveScript;
@@ -27,12 +28,12 @@ void UnregisterValidationInterface(CValidationInterface* pwalletIn);
/** Unregister all wallets from core */
void UnregisterAllValidationInterfaces();
/** Push an updated transaction to all registered wallets */
void SyncWithWallets(const CTransaction& tx, const CBlock* pblock = NULL);
void SyncWithWallets(const CTransaction& tx, const CBlockIndex *pindex, const CBlock* pblock = NULL);

class CValidationInterface {
protected:
virtual void UpdatedBlockTip(const CBlockIndex *pindex) {}
virtual void SyncTransaction(const CTransaction &tx, const CBlock *pblock) {}
virtual void SyncTransaction(const CTransaction &tx, const CBlockIndex *pindex, const CBlock *pblock) {}
virtual void SetBestChain(const CBlockLocator &locator) {}
virtual void UpdatedTransaction(const uint256 &hash) {}
virtual void Inventory(const uint256 &hash) {}
@@ -49,7 +50,7 @@ struct CMainSignals {
/** Notifies listeners of updated block chain tip */
boost::signals2::signal<void (const CBlockIndex *)> UpdatedBlockTip;
/** Notifies listeners of updated transaction data (transaction, and optionally the block it is found in. */
boost::signals2::signal<void (const CTransaction &, const CBlock *)> SyncTransaction;
boost::signals2::signal<void (const CTransaction &, const CBlockIndex *pindex, const CBlock *)> SyncTransaction;
/** 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 new active block chain. */

+ 1
- 1
src/wallet/wallet.cpp View File

@@ -815,7 +815,7 @@ void CWallet::MarkConflicted(const uint256& hashBlock, const uint256& hashTx)
}
}

void CWallet::SyncTransaction(const CTransaction& tx, const CBlock* pblock)
void CWallet::SyncTransaction(const CTransaction& tx, const CBlockIndex *pindex, const CBlock* pblock)
{
LOCK2(cs_main, cs_wallet);


+ 1
- 1
src/wallet/wallet.h View File

@@ -635,7 +635,7 @@ public:

void MarkDirty();
bool AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletDB* pwalletdb);
void SyncTransaction(const CTransaction& tx, const CBlock* pblock);
void SyncTransaction(const CTransaction& tx, const CBlockIndex *pindex, const CBlock* pblock);
bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate);
int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false);
void ReacceptWalletTransactions();

+ 1
- 1
src/zmq/zmqnotificationinterface.cpp View File

@@ -142,7 +142,7 @@ void CZMQNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindex)
}
}

void CZMQNotificationInterface::SyncTransaction(const CTransaction &tx, const CBlock *pblock)
void CZMQNotificationInterface::SyncTransaction(const CTransaction& tx, const CBlockIndex* pindex, const CBlock* pblock)
{
for (std::list<CZMQAbstractNotifier*>::iterator i = notifiers.begin(); i!=notifiers.end(); )
{

+ 1
- 1
src/zmq/zmqnotificationinterface.h View File

@@ -24,7 +24,7 @@ protected:
void Shutdown();

// CValidationInterface
void SyncTransaction(const CTransaction &tx, const CBlock *pblock);
void SyncTransaction(const CTransaction& tx, const CBlockIndex *pindex, const CBlock* pblock);
void UpdatedBlockTip(const CBlockIndex *pindex);

private:

Loading…
Cancel
Save