@@ -3858,6 +3858,9 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
38583858 return true ;
38593859}
38603860
3861+ std::map<uint256, std::pair<int , int >> vCacheProposalsToUpdate;
3862+ std::map<uint256, std::pair<int , int >> vCachePaymentRequestToUpdate;
3863+
38613864void CountVotes (CValidationState& state, CBlockIndex *pindexNew, bool fUndo )
38623865{
38633866 int64_t nTimeStart = GetTimeMicros ();
@@ -3866,13 +3869,16 @@ void CountVotes(CValidationState& state, CBlockIndex *pindexNew, bool fUndo)
38663869 int nBlocks = (pindexNew->nHeight % Params ().GetConsensus ().nBlocksPerVotingCycle ) + 1 ;
38673870 CBlockIndex* pindexblock = pindexNew;
38683871
3869- std::map<uint256, std::pair<int , int >> vCacheProposalsToUpdate;
3870- std::map<uint256, std::pair<int , int >> vCachePaymentRequestToUpdate;
38713872 std::map<uint256, bool > vSeen;
38723873
3873- vCacheProposalsToUpdate.clear ();
3874- vCachePaymentRequestToUpdate.clear ();
3874+ if (fUndo || nBlocks == 1 || vCacheProposalsToUpdate.empty () || vCachePaymentRequestToUpdate.empty ()) {
3875+ vCacheProposalsToUpdate.clear ();
3876+ vCachePaymentRequestToUpdate.clear ();
3877+ } else {
3878+ nBlocks = 1 ;
3879+ }
38753880
3881+ int64_t nTimeStart2 = GetTimeMicros ();
38763882 while (nBlocks > 0 && pindexblock != NULL ) {
38773883 vSeen.clear ();
38783884 for (unsigned int i = 0 ; i < pindexblock->vProposalVotes .size (); i++) {
@@ -3911,9 +3917,13 @@ void CountVotes(CValidationState& state, CBlockIndex *pindexNew, bool fUndo)
39113917 pindexblock = pindexblock->pprev ;
39123918 nBlocks--;
39133919 }
3920+ int64_t nTimeEnd2 = GetTimeMicros ();
3921+ LogPrint (" bench-cfund" , " - CFund count votes from headers: %.2fms\n " , (nTimeEnd2 - nTimeStart2) * 0.001 );
3922+
39143923
39153924 vSeen.clear ();
39163925
3926+ int64_t nTimeStart3 = GetTimeMicros ();
39173927 std::map<uint256, std::pair<int , int >>::iterator it;
39183928 std::vector<std::pair<uint256, CFund::CProposal>> vecProposalsToUpdate;
39193929 std::vector<std::pair<uint256, CFund::CPaymentRequest>> vecPaymentRequestsToUpdate;
@@ -3941,9 +3951,12 @@ void CountVotes(CValidationState& state, CBlockIndex *pindexNew, bool fUndo)
39413951 if (!pblocktree->UpdateProposalIndex (vecProposalsToUpdate)) {
39423952 AbortNode (state, " Failed to write proposal index" );
39433953 }
3954+ int64_t nTimeEnd3 = GetTimeMicros ();
3955+ LogPrint (" bench-cfund" , " - CFund update votes: %.2fms\n " , (nTimeEnd3 - nTimeStart3) * 0.001 );
39443956
39453957 std::vector<CFund::CPaymentRequest> vecPaymentRequest;
39463958
3959+ int64_t nTimeStart4 = GetTimeMicros ();
39473960 if (pblocktree->GetPaymentRequestIndex (vecPaymentRequest)){
39483961 for (unsigned int i = 0 ; i < vecPaymentRequest.size (); i++) {
39493962 vecPaymentRequestsToUpdate.clear ();
@@ -4026,9 +4039,12 @@ void CountVotes(CValidationState& state, CBlockIndex *pindexNew, bool fUndo)
40264039 } else {
40274040 AbortNode (state, " Failed to read payment request index, please restart with -reindex-chainstate" );
40284041 }
4042+ int64_t nTimeEnd4 = GetTimeMicros ();
4043+ LogPrint (" bench-cfund" , " - CFund update payment request status: %.2fms\n " , (nTimeEnd4 - nTimeStart4) * 0.001 );
40294044
40304045 std::vector<CFund::CProposal> vecProposal;
40314046
4047+ int64_t nTimeStart5 = GetTimeMicros ();
40324048 if (pblocktree->GetProposalIndex (vecProposal)){
40334049 for (unsigned int i = 0 ; i < vecProposal.size (); i++) {
40344050 bool fUpdate = false ;
@@ -4116,6 +4132,9 @@ void CountVotes(CValidationState& state, CBlockIndex *pindexNew, bool fUndo)
41164132 } else {
41174133 AbortNode (state, " Failed to read proposal index, please restart with -reindex-chainstate" );
41184134 }
4135+ int64_t nTimeEnd5 = GetTimeMicros ();
4136+
4137+ LogPrint (" bench-cfund" , " - CFund update proposal status: %.2fms\n " , (nTimeEnd5 - nTimeStart5) * 0.001 );
41194138
41204139 if (!pblocktree->UpdatePaymentRequestIndex (vecPaymentRequestsToUpdate)) {
41214140 AbortNode (state, " Failed to write payment request index" );
@@ -4126,7 +4145,7 @@ void CountVotes(CValidationState& state, CBlockIndex *pindexNew, bool fUndo)
41264145 }
41274146
41284147 int64_t nTimeEnd = GetTimeMicros ();
4129- LogPrint (" bench" , " - CFund count votes : %.2fms\n " , (nTimeEnd - nTimeStart) * 0.001 );
4148+ LogPrint (" bench" , " - CFund total CountVotes() function : %.2fms\n " , (nTimeEnd - nTimeStart) * 0.001 );
41304149}
41314150
41324151/* *
0 commit comments