Skip to content

Commit 7d0bf0b

Browse files
committed
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
1 parent 5548d9c commit 7d0bf0b

File tree

7 files changed

+16
-15
lines changed

7 files changed

+16
-15
lines changed

src/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState &state, const C
12341234
}
12351235
}
12361236

1237-
SyncWithWallets(tx, NULL);
1237+
SyncWithWallets(tx, NULL, NULL);
12381238

12391239
return true;
12401240
}
@@ -2391,7 +2391,7 @@ bool static DisconnectTip(CValidationState& state, const Consensus::Params& cons
23912391
// Let wallets know transactions went from 1-confirmed to
23922392
// 0-confirmed or conflicted:
23932393
BOOST_FOREACH(const CTransaction &tx, block.vtx) {
2394-
SyncWithWallets(tx, NULL);
2394+
SyncWithWallets(tx, pindexDelete->pprev, NULL);
23952395
}
23962396
return true;
23972397
}
@@ -2450,11 +2450,11 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
24502450
// Tell wallet about transactions that went from mempool
24512451
// to conflicted:
24522452
BOOST_FOREACH(const CTransaction &tx, txConflicted) {
2453-
SyncWithWallets(tx, NULL);
2453+
SyncWithWallets(tx, pindexNew, NULL);
24542454
}
24552455
// ... and about transactions that got confirmed:
24562456
BOOST_FOREACH(const CTransaction &tx, pblock->vtx) {
2457-
SyncWithWallets(tx, pblock);
2457+
SyncWithWallets(tx, pindexNew, pblock);
24582458
}
24592459

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

src/validationinterface.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ CMainSignals& GetMainSignals()
1414

1515
void RegisterValidationInterface(CValidationInterface* pwalletIn) {
1616
g_signals.UpdatedBlockTip.connect(boost::bind(&CValidationInterface::UpdatedBlockTip, pwalletIn, _1));
17-
g_signals.SyncTransaction.connect(boost::bind(&CValidationInterface::SyncTransaction, pwalletIn, _1, _2));
17+
g_signals.SyncTransaction.connect(boost::bind(&CValidationInterface::SyncTransaction, pwalletIn, _1, _2, _3));
1818
g_signals.UpdatedTransaction.connect(boost::bind(&CValidationInterface::UpdatedTransaction, pwalletIn, _1));
1919
g_signals.SetBestChain.connect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1));
2020
g_signals.Inventory.connect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1));
@@ -32,7 +32,7 @@ void UnregisterValidationInterface(CValidationInterface* pwalletIn) {
3232
g_signals.Inventory.disconnect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1));
3333
g_signals.SetBestChain.disconnect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1));
3434
g_signals.UpdatedTransaction.disconnect(boost::bind(&CValidationInterface::UpdatedTransaction, pwalletIn, _1));
35-
g_signals.SyncTransaction.disconnect(boost::bind(&CValidationInterface::SyncTransaction, pwalletIn, _1, _2));
35+
g_signals.SyncTransaction.disconnect(boost::bind(&CValidationInterface::SyncTransaction, pwalletIn, _1, _2, _3));
3636
g_signals.UpdatedBlockTip.disconnect(boost::bind(&CValidationInterface::UpdatedBlockTip, pwalletIn, _1));
3737
}
3838

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

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

src/validationinterface.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <boost/shared_ptr.hpp>
1111

1212
class CBlock;
13+
class CBlockIndex;
1314
struct CBlockLocator;
1415
class CBlockIndex;
1516
class CReserveScript;
@@ -27,12 +28,12 @@ void UnregisterValidationInterface(CValidationInterface* pwalletIn);
2728
/** Unregister all wallets from core */
2829
void UnregisterAllValidationInterfaces();
2930
/** Push an updated transaction to all registered wallets */
30-
void SyncWithWallets(const CTransaction& tx, const CBlock* pblock = NULL);
31+
void SyncWithWallets(const CTransaction& tx, const CBlockIndex *pindex, const CBlock* pblock = NULL);
3132

3233
class CValidationInterface {
3334
protected:
3435
virtual void UpdatedBlockTip(const CBlockIndex *pindex) {}
35-
virtual void SyncTransaction(const CTransaction &tx, const CBlock *pblock) {}
36+
virtual void SyncTransaction(const CTransaction &tx, const CBlockIndex *pindex, const CBlock *pblock) {}
3637
virtual void SetBestChain(const CBlockLocator &locator) {}
3738
virtual void UpdatedTransaction(const uint256 &hash) {}
3839
virtual void Inventory(const uint256 &hash) {}
@@ -49,7 +50,7 @@ struct CMainSignals {
4950
/** Notifies listeners of updated block chain tip */
5051
boost::signals2::signal<void (const CBlockIndex *)> UpdatedBlockTip;
5152
/** Notifies listeners of updated transaction data (transaction, and optionally the block it is found in. */
52-
boost::signals2::signal<void (const CTransaction &, const CBlock *)> SyncTransaction;
53+
boost::signals2::signal<void (const CTransaction &, const CBlockIndex *pindex, const CBlock *)> SyncTransaction;
5354
/** Notifies listeners of an updated transaction without new data (for now: a coinbase potentially becoming visible). */
5455
boost::signals2::signal<void (const uint256 &)> UpdatedTransaction;
5556
/** Notifies listeners of a new active block chain. */

src/wallet/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ void CWallet::MarkConflicted(const uint256& hashBlock, const uint256& hashTx)
815815
}
816816
}
817817

818-
void CWallet::SyncTransaction(const CTransaction& tx, const CBlock* pblock)
818+
void CWallet::SyncTransaction(const CTransaction& tx, const CBlockIndex *pindex, const CBlock* pblock)
819819
{
820820
LOCK2(cs_main, cs_wallet);
821821

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
635635

636636
void MarkDirty();
637637
bool AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletDB* pwalletdb);
638-
void SyncTransaction(const CTransaction& tx, const CBlock* pblock);
638+
void SyncTransaction(const CTransaction& tx, const CBlockIndex *pindex, const CBlock* pblock);
639639
bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate);
640640
int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false);
641641
void ReacceptWalletTransactions();

src/zmq/zmqnotificationinterface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ void CZMQNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindex)
142142
}
143143
}
144144

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

src/zmq/zmqnotificationinterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class CZMQNotificationInterface : public CValidationInterface
2424
void Shutdown();
2525

2626
// CValidationInterface
27-
void SyncTransaction(const CTransaction &tx, const CBlock *pblock);
27+
void SyncTransaction(const CTransaction& tx, const CBlockIndex *pindex, const CBlock* pblock);
2828
void UpdatedBlockTip(const CBlockIndex *pindex);
2929

3030
private:

0 commit comments

Comments
 (0)