@@ -1567,7 +1567,7 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C
1567
1567
}
1568
1568
}
1569
1569
1570
- SyncWithWallets ( tx, NULL );
1570
+ GetMainSignals (). SyncTransaction ( tx, NULL , CMainSignals::SYNC_TRANSACTION_NOT_IN_BLOCK );
1571
1571
1572
1572
return true ;
1573
1573
}
@@ -1882,17 +1882,6 @@ void static InvalidChainFound(CBlockIndex* pindexNew)
1882
1882
}
1883
1883
1884
1884
void static InvalidBlockFound (CBlockIndex *pindex, const CValidationState &state) {
1885
- int nDoS = 0 ;
1886
- if (state.IsInvalid (nDoS)) {
1887
- std::map<uint256, NodeId>::iterator it = mapBlockSource.find (pindex->GetBlockHash ());
1888
- if (it != mapBlockSource.end () && State (it->second )) {
1889
- assert (state.GetRejectCode () < REJECT_INTERNAL); // Blocks are never rejected with internal reject codes
1890
- CBlockReject reject = {(unsigned char )state.GetRejectCode (), state.GetRejectReason ().substr (0 , MAX_REJECT_MESSAGE_LENGTH), pindex->GetBlockHash ()};
1891
- State (it->second )->rejects .push_back (reject);
1892
- if (nDoS > 0 )
1893
- Misbehaving (it->second , nDoS);
1894
- }
1895
- }
1896
1885
if (!state.CorruptionPossible ()) {
1897
1886
pindex->nStatus |= BLOCK_FAILED_VALID;
1898
1887
setDirtyBlockIndex.insert (pindex);
@@ -2800,7 +2789,7 @@ bool static DisconnectTip(CValidationState& state, const CChainParams& chainpara
2800
2789
// Let wallets know transactions went from 1-confirmed to
2801
2790
// 0-confirmed or conflicted:
2802
2791
BOOST_FOREACH (const CTransaction &tx, block.vtx ) {
2803
- SyncWithWallets ( tx, pindexDelete->pprev );
2792
+ GetMainSignals (). SyncTransaction ( tx, pindexDelete->pprev , CMainSignals::SYNC_TRANSACTION_NOT_IN_BLOCK );
2804
2793
}
2805
2794
return true ;
2806
2795
}
@@ -2839,7 +2828,6 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
2839
2828
InvalidBlockFound (pindexNew, state);
2840
2829
return error (" ConnectTip(): ConnectBlock %s failed" , pindexNew->GetBlockHash ().ToString ());
2841
2830
}
2842
- mapBlockSource.erase (pindexNew->GetBlockHash ());
2843
2831
nTime3 = GetTimeMicros (); nTimeConnectTotal += nTime3 - nTime2;
2844
2832
LogPrint (" bench" , " - Connect total: %.2fms [%.2fs]\n " , (nTime3 - nTime2) * 0.001 , nTimeConnectTotal * 0.000001 );
2845
2833
assert (view.Flush ());
@@ -3038,7 +3026,7 @@ static void NotifyHeaderTip() {
3038
3026
* or an activated best chain. pblock is either NULL or a pointer to a block
3039
3027
* that is already loaded (to avoid loading it again from disk).
3040
3028
*/
3041
- bool ActivateBestChain (CValidationState &state, const CChainParams& chainparams, const CBlock *pblock, CConnman* connman ) {
3029
+ bool ActivateBestChain (CValidationState &state, const CChainParams& chainparams, const CBlock *pblock) {
3042
3030
CBlockIndex *pindexMostWork = NULL ;
3043
3031
CBlockIndex *pindexNewTip = NULL ;
3044
3032
std::vector<std::tuple<CTransaction,CBlockIndex*,int >> txChanged;
@@ -3053,7 +3041,6 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
3053
3041
const CBlockIndex *pindexFork;
3054
3042
std::list<CTransaction> txConflicted;
3055
3043
bool fInitialDownload ;
3056
- int nNewHeight;
3057
3044
{
3058
3045
LOCK (cs_main);
3059
3046
CBlockIndex *pindexOldTip = chainActive.Tip ();
@@ -3076,59 +3063,27 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
3076
3063
pindexNewTip = chainActive.Tip ();
3077
3064
pindexFork = chainActive.FindFork (pindexOldTip);
3078
3065
fInitialDownload = IsInitialBlockDownload ();
3079
- nNewHeight = chainActive.Height ();
3080
3066
}
3081
3067
// When we reach this point, we switched to a new tip (stored in pindexNewTip).
3082
3068
3083
3069
// Notifications/callbacks that can run without cs_main
3084
- if (connman)
3085
- connman->SetBestHeight (nNewHeight);
3086
3070
3087
3071
// throw all transactions though the signal-interface
3088
3072
// while _not_ holding the cs_main lock
3089
3073
BOOST_FOREACH (const CTransaction &tx, txConflicted)
3090
3074
{
3091
- SyncWithWallets ( tx, pindexNewTip);
3075
+ GetMainSignals (). SyncTransaction ( tx, pindexNewTip, CMainSignals::SYNC_TRANSACTION_NOT_IN_BLOCK );
3092
3076
}
3093
3077
// ... and about transactions that got confirmed:
3094
3078
for (unsigned int i = 0 ; i < txChanged.size (); i++)
3095
- SyncWithWallets (std::get<0 >(txChanged[i]), std::get<1 >(txChanged[i]), std::get<2 >(txChanged[i]));
3079
+ GetMainSignals ().SyncTransaction (std::get<0 >(txChanged[i]), std::get<1 >(txChanged[i]), std::get<2 >(txChanged[i]));
3080
+
3081
+ // Notify external listeners about the new tip.
3082
+ GetMainSignals ().UpdatedBlockTip (pindexNewTip, pindexFork, fInitialDownload );
3096
3083
3097
3084
// Always notify the UI if a new block tip was connected
3098
3085
if (pindexFork != pindexNewTip) {
3099
3086
uiInterface.NotifyBlockTip (fInitialDownload , pindexNewTip);
3100
-
3101
- if (!fInitialDownload ) {
3102
- // Find the hashes of all blocks that weren't previously in the best chain.
3103
- std::vector<uint256> vHashes;
3104
- CBlockIndex *pindexToAnnounce = pindexNewTip;
3105
- while (pindexToAnnounce != pindexFork) {
3106
- vHashes.push_back (pindexToAnnounce->GetBlockHash ());
3107
- pindexToAnnounce = pindexToAnnounce->pprev ;
3108
- if (vHashes.size () == MAX_BLOCKS_TO_ANNOUNCE) {
3109
- // Limit announcements in case of a huge reorganization.
3110
- // Rely on the peer's synchronization mechanism in that case.
3111
- break ;
3112
- }
3113
- }
3114
- // Relay inventory, but don't relay old inventory during initial block download.
3115
- int nBlockEstimate = 0 ;
3116
- if (fCheckpointsEnabled )
3117
- nBlockEstimate = Checkpoints::GetTotalBlocksEstimate (chainparams.Checkpoints ());
3118
- if (connman) {
3119
- connman->ForEachNode ([nNewHeight, nBlockEstimate, &vHashes](CNode* pnode) {
3120
- if (nNewHeight > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : nBlockEstimate)) {
3121
- BOOST_REVERSE_FOREACH (const uint256& hash, vHashes) {
3122
- pnode->PushBlockHash (hash);
3123
- }
3124
- }
3125
- });
3126
- }
3127
- // Notify external listeners about the new tip.
3128
- if (!vHashes.empty ()) {
3129
- GetMainSignals ().UpdatedBlockTip (pindexNewTip);
3130
- }
3131
- }
3132
3087
}
3133
3088
} while (pindexNewTip != pindexMostWork);
3134
3089
CheckBlockIndex (chainparams.GetConsensus ());
@@ -3787,7 +3742,7 @@ static bool AcceptBlock(const CBlock& block, CValidationState& state, const CCha
3787
3742
return true ;
3788
3743
}
3789
3744
3790
- bool ProcessNewBlock (CValidationState& state, const CChainParams& chainparams, CNode* pfrom, const CBlock* pblock, bool fForceProcessing , const CDiskBlockPos* dbp, CConnman* connman )
3745
+ bool ProcessNewBlock (CValidationState& state, const CChainParams& chainparams, CNode* pfrom, const CBlock* pblock, bool fForceProcessing , const CDiskBlockPos* dbp)
3791
3746
{
3792
3747
{
3793
3748
LOCK (cs_main);
@@ -3809,7 +3764,7 @@ bool ProcessNewBlock(CValidationState& state, const CChainParams& chainparams, C
3809
3764
3810
3765
NotifyHeaderTip ();
3811
3766
3812
- if (!ActivateBestChain (state, chainparams, pblock, connman ))
3767
+ if (!ActivateBestChain (state, chainparams, pblock))
3813
3768
return error (" %s: ActivateBestChain failed" , __func__);
3814
3769
3815
3770
return true ;
@@ -4742,6 +4697,59 @@ std::string GetWarnings(const std::string& strFor)
4742
4697
4743
4698
4744
4699
4700
+ // ////////////////////////////////////////////////////////////////////////////
4701
+ //
4702
+ // blockchain -> download logic notification
4703
+ //
4704
+
4705
+ void PeerLogicValidation::UpdatedBlockTip (const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload ) {
4706
+ const int nNewHeight = pindexNew->nHeight ;
4707
+ connman->SetBestHeight (nNewHeight);
4708
+
4709
+ if (!fInitialDownload ) {
4710
+ // Find the hashes of all blocks that weren't previously in the best chain.
4711
+ std::vector<uint256> vHashes;
4712
+ const CBlockIndex *pindexToAnnounce = pindexNew;
4713
+ while (pindexToAnnounce != pindexFork) {
4714
+ vHashes.push_back (pindexToAnnounce->GetBlockHash ());
4715
+ pindexToAnnounce = pindexToAnnounce->pprev ;
4716
+ if (vHashes.size () == MAX_BLOCKS_TO_ANNOUNCE) {
4717
+ // Limit announcements in case of a huge reorganization.
4718
+ // Rely on the peer's synchronization mechanism in that case.
4719
+ break ;
4720
+ }
4721
+ }
4722
+ // Relay inventory, but don't relay old inventory during initial block download.
4723
+ connman->ForEachNode ([nNewHeight, &vHashes](CNode* pnode) {
4724
+ if (nNewHeight > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : 0 )) {
4725
+ BOOST_REVERSE_FOREACH (const uint256& hash, vHashes) {
4726
+ pnode->PushBlockHash (hash);
4727
+ }
4728
+ }
4729
+ });
4730
+ }
4731
+ }
4732
+
4733
+ void PeerLogicValidation::BlockChecked (const CBlock& block, const CValidationState& state) {
4734
+ LOCK (cs_main);
4735
+
4736
+ const uint256 hash (block.GetHash ());
4737
+ std::map<uint256, NodeId>::iterator it = mapBlockSource.find (hash);
4738
+
4739
+ int nDoS = 0 ;
4740
+ if (state.IsInvalid (nDoS)) {
4741
+ if (it != mapBlockSource.end () && State (it->second )) {
4742
+ assert (state.GetRejectCode () < REJECT_INTERNAL); // Blocks are never rejected with internal reject codes
4743
+ CBlockReject reject = {(unsigned char )state.GetRejectCode (), state.GetRejectReason ().substr (0 , MAX_REJECT_MESSAGE_LENGTH), hash};
4744
+ State (it->second )->rejects .push_back (reject);
4745
+ if (nDoS > 0 )
4746
+ Misbehaving (it->second , nDoS);
4747
+ }
4748
+ }
4749
+ if (it != mapBlockSource.end ())
4750
+ mapBlockSource.erase (it);
4751
+ }
4752
+
4745
4753
// ////////////////////////////////////////////////////////////////////////////
4746
4754
//
4747
4755
// Messages
@@ -5845,7 +5853,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
5845
5853
pfrom->PushMessage (NetMsgType::GETDATA, invs);
5846
5854
} else {
5847
5855
CValidationState state;
5848
- ProcessNewBlock (state, chainparams, pfrom, &block, false , NULL , &connman );
5856
+ ProcessNewBlock (state, chainparams, pfrom, &block, false , NULL );
5849
5857
int nDoS;
5850
5858
if (state.IsInvalid (nDoS)) {
5851
5859
assert (state.GetRejectCode () < REJECT_INTERNAL); // Blocks are never rejected with internal reject codes
@@ -6021,7 +6029,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
6021
6029
// Such an unrequested block may still be processed, subject to the
6022
6030
// conditions in AcceptBlock().
6023
6031
bool forceProcessing = pfrom->fWhitelisted && !IsInitialBlockDownload ();
6024
- ProcessNewBlock (state, chainparams, pfrom, &block, forceProcessing, NULL , &connman );
6032
+ ProcessNewBlock (state, chainparams, pfrom, &block, forceProcessing, NULL );
6025
6033
int nDoS;
6026
6034
if (state.IsInvalid (nDoS)) {
6027
6035
assert (state.GetRejectCode () < REJECT_INTERNAL); // Blocks are never rejected with internal reject codes
0 commit comments