@@ -1540,7 +1540,8 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState &state, const C
1540
1540
}
1541
1541
}
1542
1542
1543
- if (!fDryRun ) SyncWithWallets (tx, NULL );
1543
+ if (!fDryRun )
1544
+ GetMainSignals ().SyncTransaction (tx, NULL );
1544
1545
1545
1546
return true ;
1546
1547
}
@@ -1966,17 +1967,6 @@ void static InvalidChainFound(CBlockIndex* pindexNew)
1966
1967
}
1967
1968
1968
1969
void static InvalidBlockFound (CBlockIndex *pindex, const CValidationState &state) {
1969
- int nDoS = 0 ;
1970
- if (state.IsInvalid (nDoS)) {
1971
- std::map<uint256, NodeId>::iterator it = mapBlockSource.find (pindex->GetBlockHash ());
1972
- if (it != mapBlockSource.end () && State (it->second )) {
1973
- assert (state.GetRejectCode () < REJECT_INTERNAL); // Blocks are never rejected with internal reject codes
1974
- CBlockReject reject = {(unsigned char )state.GetRejectCode (), state.GetRejectReason ().substr (0 , MAX_REJECT_MESSAGE_LENGTH), pindex->GetBlockHash ()};
1975
- State (it->second )->rejects .push_back (reject);
1976
- if (nDoS > 0 )
1977
- Misbehaving (it->second , nDoS);
1978
- }
1979
- }
1980
1970
if (!state.CorruptionPossible ()) {
1981
1971
pindex->nStatus |= BLOCK_FAILED_VALID;
1982
1972
setDirtyBlockIndex.insert (pindex);
@@ -3047,7 +3037,7 @@ bool static DisconnectTip(CValidationState& state, const Consensus::Params& cons
3047
3037
// Let wallets know transactions went from 1-confirmed to
3048
3038
// 0-confirmed or conflicted:
3049
3039
BOOST_FOREACH (const CTransaction &tx, block.vtx ) {
3050
- SyncWithWallets (tx, NULL );
3040
+ GetMainSignals (). SyncTransaction (tx, NULL );
3051
3041
}
3052
3042
return true ;
3053
3043
}
@@ -3086,7 +3076,6 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
3086
3076
InvalidBlockFound (pindexNew, state);
3087
3077
return error (" ConnectTip(): ConnectBlock %s failed" , pindexNew->GetBlockHash ().ToString ());
3088
3078
}
3089
- mapBlockSource.erase (pindexNew->GetBlockHash ());
3090
3079
nTime3 = GetTimeMicros (); nTimeConnectTotal += nTime3 - nTime2;
3091
3080
LogPrint (" bench" , " - Connect total: %.2fms [%.2fs]\n " , (nTime3 - nTime2) * 0.001 , nTimeConnectTotal * 0.000001 );
3092
3081
assert (view.Flush ());
@@ -3106,11 +3095,11 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
3106
3095
// Tell wallet about transactions that went from mempool
3107
3096
// to conflicted:
3108
3097
BOOST_FOREACH (const CTransaction &tx, txConflicted) {
3109
- SyncWithWallets (tx, NULL );
3098
+ GetMainSignals (). SyncTransaction (tx, NULL );
3110
3099
}
3111
3100
// ... and about transactions that got confirmed:
3112
3101
BOOST_FOREACH (const CTransaction &tx, pblock->vtx ) {
3113
- SyncWithWallets (tx, pblock);
3102
+ GetMainSignals (). SyncTransaction (tx, pblock);
3114
3103
}
3115
3104
3116
3105
int64_t nTime6 = GetTimeMicros (); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1;
@@ -3336,7 +3325,7 @@ static void NotifyHeaderTip() {
3336
3325
* or an activated best chain. pblock is either NULL or a pointer to a block
3337
3326
* that is already loaded (to avoid loading it again from disk).
3338
3327
*/
3339
- bool ActivateBestChain (CValidationState &state, const CChainParams& chainparams, const CBlock *pblock, CConnman* connman ) {
3328
+ bool ActivateBestChain (CValidationState &state, const CChainParams& chainparams, const CBlock *pblock) {
3340
3329
CBlockIndex *pindexMostWork = NULL ;
3341
3330
CBlockIndex *pindexNewTip = NULL ;
3342
3331
do {
@@ -3346,7 +3335,6 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
3346
3335
3347
3336
const CBlockIndex *pindexFork;
3348
3337
bool fInitialDownload ;
3349
- int nNewHeight;
3350
3338
{
3351
3339
LOCK (cs_main);
3352
3340
CBlockIndex *pindexOldTip = chainActive.Tip ();
@@ -3369,49 +3357,17 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
3369
3357
pindexNewTip = chainActive.Tip ();
3370
3358
pindexFork = chainActive.FindFork (pindexOldTip);
3371
3359
fInitialDownload = IsInitialBlockDownload ();
3372
- nNewHeight = chainActive.Height ();
3373
3360
}
3374
3361
// When we reach this point, we switched to a new tip (stored in pindexNewTip).
3375
3362
3376
3363
// Notifications/callbacks that can run without cs_main
3377
- if (connman)
3378
- connman->SetBestHeight (chainActive.Height ());
3364
+
3365
+ // Notify external listeners about the new tip.
3366
+ GetMainSignals ().UpdatedBlockTip (pindexNewTip, pindexFork, fInitialDownload );
3379
3367
3380
3368
// Always notify the UI if a new block tip was connected
3381
3369
if (pindexFork != pindexNewTip) {
3382
3370
uiInterface.NotifyBlockTip (fInitialDownload , pindexNewTip);
3383
-
3384
- if (!fInitialDownload ) {
3385
- // Find the hashes of all blocks that weren't previously in the best chain.
3386
- std::vector<uint256> vHashes;
3387
- CBlockIndex *pindexToAnnounce = pindexNewTip;
3388
- while (pindexToAnnounce != pindexFork) {
3389
- vHashes.push_back (pindexToAnnounce->GetBlockHash ());
3390
- pindexToAnnounce = pindexToAnnounce->pprev ;
3391
- if (vHashes.size () == MAX_BLOCKS_TO_ANNOUNCE) {
3392
- // Limit announcements in case of a huge reorganization.
3393
- // Rely on the peer's synchronization mechanism in that case.
3394
- break ;
3395
- }
3396
- }
3397
- // Relay inventory, but don't relay old inventory during initial block download.
3398
- int nBlockEstimate = 0 ;
3399
- if (fCheckpointsEnabled )
3400
- nBlockEstimate = Checkpoints::GetTotalBlocksEstimate (chainparams.Checkpoints ());
3401
- if (connman) {
3402
- connman->ForEachNode ([nNewHeight, nBlockEstimate, &vHashes](CNode* pnode) {
3403
- if (nNewHeight > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : nBlockEstimate)) {
3404
- BOOST_REVERSE_FOREACH (const uint256& hash, vHashes) {
3405
- pnode->PushBlockHash (hash);
3406
- }
3407
- }
3408
- });
3409
- }
3410
- // Notify external listeners about the new tip.
3411
- if (!vHashes.empty ()) {
3412
- GetMainSignals ().UpdatedBlockTip (pindexNewTip);
3413
- }
3414
- }
3415
3371
}
3416
3372
} while (pindexNewTip != pindexMostWork);
3417
3373
CheckBlockIndex (chainparams.GetConsensus ());
@@ -4003,7 +3959,7 @@ static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned
4003
3959
}
4004
3960
4005
3961
4006
- bool ProcessNewBlock (CValidationState& state, const CChainParams& chainparams, CNode* pfrom, const CBlock* pblock, bool fForceProcessing , const CDiskBlockPos* dbp, CConnman* connman )
3962
+ bool ProcessNewBlock (CValidationState& state, const CChainParams& chainparams, CNode* pfrom, const CBlock* pblock, bool fForceProcessing , const CDiskBlockPos* dbp)
4007
3963
{
4008
3964
{
4009
3965
LOCK (cs_main);
@@ -4025,7 +3981,7 @@ bool ProcessNewBlock(CValidationState& state, const CChainParams& chainparams, C
4025
3981
4026
3982
NotifyHeaderTip ();
4027
3983
4028
- if (!ActivateBestChain (state, chainparams, pblock, connman ))
3984
+ if (!ActivateBestChain (state, chainparams, pblock))
4029
3985
return error (" %s: ActivateBestChain failed" , __func__);
4030
3986
4031
3987
masternodeSync.IsBlockchainSynced (true );
@@ -4909,6 +4865,59 @@ std::string GetWarnings(const std::string& strFor)
4909
4865
4910
4866
4911
4867
4868
+ // ////////////////////////////////////////////////////////////////////////////
4869
+ //
4870
+ // blockchain -> download logic notification
4871
+ //
4872
+
4873
+ void PeerLogicValidation::UpdatedBlockTip (const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload ) {
4874
+ const int nNewHeight = pindexNew->nHeight ;
4875
+ connman->SetBestHeight (nNewHeight);
4876
+
4877
+ if (!fInitialDownload ) {
4878
+ // Find the hashes of all blocks that weren't previously in the best chain.
4879
+ std::vector<uint256> vHashes;
4880
+ const CBlockIndex *pindexToAnnounce = pindexNew;
4881
+ while (pindexToAnnounce != pindexFork) {
4882
+ vHashes.push_back (pindexToAnnounce->GetBlockHash ());
4883
+ pindexToAnnounce = pindexToAnnounce->pprev ;
4884
+ if (vHashes.size () == MAX_BLOCKS_TO_ANNOUNCE) {
4885
+ // Limit announcements in case of a huge reorganization.
4886
+ // Rely on the peer's synchronization mechanism in that case.
4887
+ break ;
4888
+ }
4889
+ }
4890
+ // Relay inventory, but don't relay old inventory during initial block download.
4891
+ connman->ForEachNode ([nNewHeight, &vHashes](CNode* pnode) {
4892
+ if (nNewHeight > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : 0 )) {
4893
+ BOOST_REVERSE_FOREACH (const uint256& hash, vHashes) {
4894
+ pnode->PushBlockHash (hash);
4895
+ }
4896
+ }
4897
+ });
4898
+ }
4899
+ }
4900
+
4901
+ void PeerLogicValidation::BlockChecked (const CBlock& block, const CValidationState& state) {
4902
+ LOCK (cs_main);
4903
+
4904
+ const uint256 hash (block.GetHash ());
4905
+ std::map<uint256, NodeId>::iterator it = mapBlockSource.find (hash);
4906
+
4907
+ int nDoS = 0 ;
4908
+ if (state.IsInvalid (nDoS)) {
4909
+ if (it != mapBlockSource.end () && State (it->second )) {
4910
+ assert (state.GetRejectCode () < REJECT_INTERNAL); // Blocks are never rejected with internal reject codes
4911
+ CBlockReject reject = {(unsigned char )state.GetRejectCode (), state.GetRejectReason ().substr (0 , MAX_REJECT_MESSAGE_LENGTH), hash};
4912
+ State (it->second )->rejects .push_back (reject);
4913
+ if (nDoS > 0 )
4914
+ Misbehaving (it->second , nDoS);
4915
+ }
4916
+ }
4917
+ if (it != mapBlockSource.end ())
4918
+ mapBlockSource.erase (it);
4919
+ }
4920
+
4912
4921
// ////////////////////////////////////////////////////////////////////////////
4913
4922
//
4914
4923
// Messages
@@ -6107,7 +6116,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
6107
6116
// Such an unrequested block may still be processed, subject to the
6108
6117
// conditions in AcceptBlock().
6109
6118
bool forceProcessing = pfrom->fWhitelisted && !IsInitialBlockDownload ();
6110
- ProcessNewBlock (state, chainparams, pfrom, &block, forceProcessing, NULL , &connman );
6119
+ ProcessNewBlock (state, chainparams, pfrom, &block, forceProcessing, NULL );
6111
6120
int nDoS;
6112
6121
if (state.IsInvalid (nDoS)) {
6113
6122
assert (state.GetRejectCode () < REJECT_INTERNAL); // Blocks are never rejected with internal reject codes
0 commit comments