@@ -1541,7 +1541,7 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C
1541
1541
}
1542
1542
}
1543
1543
1544
- SyncWithWallets (tx, NULL , NULL );
1544
+ SyncWithWallets (tx, NULL );
1545
1545
1546
1546
return true ;
1547
1547
}
@@ -2770,7 +2770,7 @@ bool static DisconnectTip(CValidationState& state, const CChainParams& chainpara
2770
2770
// Let wallets know transactions went from 1-confirmed to
2771
2771
// 0-confirmed or conflicted:
2772
2772
BOOST_FOREACH (const CTransaction &tx, block.vtx ) {
2773
- SyncWithWallets (tx, pindexDelete->pprev , NULL );
2773
+ SyncWithWallets (tx, pindexDelete->pprev );
2774
2774
}
2775
2775
return true ;
2776
2776
}
@@ -2785,7 +2785,7 @@ static int64_t nTimePostConnect = 0;
2785
2785
* Connect a new block to chainActive. pblock is either NULL or a pointer to a CBlock
2786
2786
* corresponding to pindexNew, to bypass loading it again from disk.
2787
2787
*/
2788
- bool static ConnectTip (CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const CBlock* pblock)
2788
+ bool static ConnectTip (CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const CBlock* pblock, std::list<CTransaction> &txConflicted, std::vector<std::tuple<CTransaction,CBlockIndex*, int > > &txChanged )
2789
2789
{
2790
2790
assert (pindexNew->pprev == chainActive.Tip ());
2791
2791
// Read block from disk.
@@ -2821,20 +2821,13 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
2821
2821
return false ;
2822
2822
int64_t nTime5 = GetTimeMicros (); nTimeChainState += nTime5 - nTime4;
2823
2823
LogPrint (" bench" , " - Writing chainstate: %.2fms [%.2fs]\n " , (nTime5 - nTime4) * 0.001 , nTimeChainState * 0.000001 );
2824
- // Remove conflicting transactions from the mempool.
2825
- list<CTransaction> txConflicted;
2824
+ // Remove conflicting transactions from the mempool.;
2826
2825
mempool.removeForBlock (pblock->vtx , pindexNew->nHeight , txConflicted, !IsInitialBlockDownload ());
2827
2826
// Update chainActive & related variables.
2828
2827
UpdateTip (pindexNew, chainparams);
2829
- // Tell wallet about transactions that went from mempool
2830
- // to conflicted:
2831
- BOOST_FOREACH (const CTransaction &tx, txConflicted) {
2832
- SyncWithWallets (tx, pindexNew, NULL );
2833
- }
2834
- // ... and about transactions that got confirmed:
2835
- BOOST_FOREACH (const CTransaction &tx, pblock->vtx ) {
2836
- SyncWithWallets (tx, pindexNew, pblock);
2837
- }
2828
+
2829
+ for (unsigned int i=0 ; i < pblock->vtx .size (); i++)
2830
+ txChanged.push_back (std::make_tuple (pblock->vtx [i], pindexNew, i));
2838
2831
2839
2832
int64_t nTime6 = GetTimeMicros (); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1;
2840
2833
LogPrint (" bench" , " - Connect postprocess: %.2fms [%.2fs]\n " , (nTime6 - nTime5) * 0.001 , nTimePostConnect * 0.000001 );
@@ -2916,7 +2909,7 @@ static void PruneBlockIndexCandidates() {
2916
2909
* Try to make some progress towards making pindexMostWork the active block.
2917
2910
* pblock is either NULL or a pointer to a CBlock corresponding to pindexMostWork.
2918
2911
*/
2919
- static bool ActivateBestChainStep (CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const CBlock* pblock, bool & fInvalidFound )
2912
+ static bool ActivateBestChainStep (CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const CBlock* pblock, bool & fInvalidFound , std::list<CTransaction>& txConflicted, std::vector<std::tuple<CTransaction,CBlockIndex*, int > >& txChanged )
2920
2913
{
2921
2914
AssertLockHeld (cs_main);
2922
2915
const CBlockIndex *pindexOldTip = chainActive.Tip ();
@@ -2949,7 +2942,7 @@ static bool ActivateBestChainStep(CValidationState& state, const CChainParams& c
2949
2942
2950
2943
// Connect new blocks.
2951
2944
BOOST_REVERSE_FOREACH (CBlockIndex *pindexConnect, vpindexToConnect) {
2952
- if (!ConnectTip (state, chainparams, pindexConnect, pindexConnect == pindexMostWork ? pblock : NULL )) {
2945
+ if (!ConnectTip (state, chainparams, pindexConnect, pindexConnect == pindexMostWork ? pblock : NULL , txConflicted, txChanged )) {
2953
2946
if (state.IsInvalid ()) {
2954
2947
// The block violates a consensus rule.
2955
2948
if (!state.CorruptionPossible ())
@@ -3024,6 +3017,8 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
3024
3017
break ;
3025
3018
3026
3019
const CBlockIndex *pindexFork;
3020
+ std::list<CTransaction> txConflicted;
3021
+ std::vector<std::tuple<CTransaction,CBlockIndex*,int > > txChanged;
3027
3022
bool fInitialDownload ;
3028
3023
int nNewHeight;
3029
3024
{
@@ -3038,7 +3033,7 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
3038
3033
return true ;
3039
3034
3040
3035
bool fInvalidFound = false ;
3041
- if (!ActivateBestChainStep (state, chainparams, pindexMostWork, pblock && pblock->GetHash () == pindexMostWork->GetBlockHash () ? pblock : NULL , fInvalidFound ))
3036
+ if (!ActivateBestChainStep (state, chainparams, pindexMostWork, pblock && pblock->GetHash () == pindexMostWork->GetBlockHash () ? pblock : NULL , fInvalidFound , txConflicted, txChanged ))
3042
3037
return false ;
3043
3038
3044
3039
if (fInvalidFound ) {
@@ -3053,6 +3048,17 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
3053
3048
// When we reach this point, we switched to a new tip (stored in pindexNewTip).
3054
3049
3055
3050
// Notifications/callbacks that can run without cs_main
3051
+
3052
+ // throw all transactions though the signal-interface
3053
+ // while _not_ holding the cs_main lock
3054
+ BOOST_FOREACH (const CTransaction &tx, txConflicted)
3055
+ {
3056
+ SyncWithWallets (tx, pindexNewTip);
3057
+ }
3058
+ // ... and about transactions that got confirmed:
3059
+ for (unsigned int i = 0 ; i < txChanged.size (); i++)
3060
+ SyncWithWallets (std::get<0 >(txChanged[i]), std::get<1 >(txChanged[i]), std::get<2 >(txChanged[i]));
3061
+
3056
3062
// Always notify the UI if a new block tip was connected
3057
3063
if (pindexFork != pindexNewTip) {
3058
3064
uiInterface.NotifyBlockTip (fInitialDownload , pindexNewTip);
0 commit comments