@@ -1540,7 +1540,8 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState &state, const C
15401540 }
15411541 }
15421542
1543- if (!fDryRun ) SyncWithWallets (tx, NULL );
1543+ if (!fDryRun )
1544+ GetMainSignals ().SyncTransaction (tx, NULL );
15441545
15451546 return true ;
15461547}
@@ -1966,17 +1967,6 @@ void static InvalidChainFound(CBlockIndex* pindexNew)
19661967}
19671968
19681969void 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- }
19801970 if (!state.CorruptionPossible ()) {
19811971 pindex->nStatus |= BLOCK_FAILED_VALID;
19821972 setDirtyBlockIndex.insert (pindex);
@@ -3047,7 +3037,7 @@ bool static DisconnectTip(CValidationState& state, const Consensus::Params& cons
30473037 // Let wallets know transactions went from 1-confirmed to
30483038 // 0-confirmed or conflicted:
30493039 BOOST_FOREACH (const CTransaction &tx, block.vtx ) {
3050- SyncWithWallets (tx, NULL );
3040+ GetMainSignals (). SyncTransaction (tx, NULL );
30513041 }
30523042 return true ;
30533043}
@@ -3086,7 +3076,6 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
30863076 InvalidBlockFound (pindexNew, state);
30873077 return error (" ConnectTip(): ConnectBlock %s failed" , pindexNew->GetBlockHash ().ToString ());
30883078 }
3089- mapBlockSource.erase (pindexNew->GetBlockHash ());
30903079 nTime3 = GetTimeMicros (); nTimeConnectTotal += nTime3 - nTime2;
30913080 LogPrint (" bench" , " - Connect total: %.2fms [%.2fs]\n " , (nTime3 - nTime2) * 0.001 , nTimeConnectTotal * 0.000001 );
30923081 assert (view.Flush ());
@@ -3106,11 +3095,11 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
31063095 // Tell wallet about transactions that went from mempool
31073096 // to conflicted:
31083097 BOOST_FOREACH (const CTransaction &tx, txConflicted) {
3109- SyncWithWallets (tx, NULL );
3098+ GetMainSignals (). SyncTransaction (tx, NULL );
31103099 }
31113100 // ... and about transactions that got confirmed:
31123101 BOOST_FOREACH (const CTransaction &tx, pblock->vtx ) {
3113- SyncWithWallets (tx, pblock);
3102+ GetMainSignals (). SyncTransaction (tx, pblock);
31143103 }
31153104
31163105 int64_t nTime6 = GetTimeMicros (); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1;
@@ -3336,7 +3325,7 @@ static void NotifyHeaderTip() {
33363325 * or an activated best chain. pblock is either NULL or a pointer to a block
33373326 * that is already loaded (to avoid loading it again from disk).
33383327 */
3339- bool ActivateBestChain (CValidationState &state, const CChainParams& chainparams, const CBlock *pblock, CConnman* connman ) {
3328+ bool ActivateBestChain (CValidationState &state, const CChainParams& chainparams, const CBlock *pblock) {
33403329 CBlockIndex *pindexMostWork = NULL ;
33413330 CBlockIndex *pindexNewTip = NULL ;
33423331 do {
@@ -3346,7 +3335,6 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
33463335
33473336 const CBlockIndex *pindexFork;
33483337 bool fInitialDownload ;
3349- int nNewHeight;
33503338 {
33513339 LOCK (cs_main);
33523340 CBlockIndex *pindexOldTip = chainActive.Tip ();
@@ -3369,49 +3357,17 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
33693357 pindexNewTip = chainActive.Tip ();
33703358 pindexFork = chainActive.FindFork (pindexOldTip);
33713359 fInitialDownload = IsInitialBlockDownload ();
3372- nNewHeight = chainActive.Height ();
33733360 }
33743361 // When we reach this point, we switched to a new tip (stored in pindexNewTip).
33753362
33763363 // 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 );
33793367
33803368 // Always notify the UI if a new block tip was connected
33813369 if (pindexFork != pindexNewTip) {
33823370 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- }
34153371 }
34163372 } while (pindexNewTip != pindexMostWork);
34173373 CheckBlockIndex (chainparams.GetConsensus ());
@@ -4003,7 +3959,7 @@ static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned
40033959}
40043960
40053961
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)
40073963{
40083964 {
40093965 LOCK (cs_main);
@@ -4025,7 +3981,7 @@ bool ProcessNewBlock(CValidationState& state, const CChainParams& chainparams, C
40253981
40263982 NotifyHeaderTip ();
40273983
4028- if (!ActivateBestChain (state, chainparams, pblock, connman ))
3984+ if (!ActivateBestChain (state, chainparams, pblock))
40293985 return error (" %s: ActivateBestChain failed" , __func__);
40303986
40313987 masternodeSync.IsBlockchainSynced (true );
@@ -4909,6 +4865,59 @@ std::string GetWarnings(const std::string& strFor)
49094865
49104866
49114867
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+
49124921// ////////////////////////////////////////////////////////////////////////////
49134922//
49144923// Messages
@@ -6107,7 +6116,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
61076116 // Such an unrequested block may still be processed, subject to the
61086117 // conditions in AcceptBlock().
61096118 bool forceProcessing = pfrom->fWhitelisted && !IsInitialBlockDownload ();
6110- ProcessNewBlock (state, chainparams, pfrom, &block, forceProcessing, NULL , &connman );
6119+ ProcessNewBlock (state, chainparams, pfrom, &block, forceProcessing, NULL );
61116120 int nDoS;
61126121 if (state.IsInvalid (nDoS)) {
61136122 assert (state.GetRejectCode () < REJECT_INTERNAL); // Blocks are never rejected with internal reject codes
0 commit comments