@@ -38,7 +38,7 @@ std::string CDeterministicMNState::ToString() const
3838 return strprintf (" CDeterministicMNState(nRegisteredHeight=%d, nLastPaidHeight=%d, nPoSePenalty=%d, nPoSeRevivedHeight=%d, nPoSeBanHeight=%d, nRevocationReason=%d, "
3939 " ownerAddress=%s, pubKeyOperator=%s, votingAddress=%s, addr=%s, payoutAddress=%s, operatorPayoutAddress=%s)" ,
4040 nRegisteredHeight, nLastPaidHeight, nPoSePenalty, nPoSeRevivedHeight, nPoSeBanHeight, nRevocationReason,
41- CBitcoinAddress (keyIDOwner).ToString (), pubKeyOperator.ToString (), CBitcoinAddress (keyIDVoting).ToString (), addr.ToStringIPPort (false ), payoutAddress, operatorPayoutAddress);
41+ CBitcoinAddress (keyIDOwner).ToString (), pubKeyOperator.Get (). ToString (), CBitcoinAddress (keyIDVoting).ToString (), addr.ToStringIPPort (false ), payoutAddress, operatorPayoutAddress);
4242}
4343
4444void CDeterministicMNState::ToJson (UniValue& obj) const
@@ -60,7 +60,7 @@ void CDeterministicMNState::ToJson(UniValue& obj) const
6060 CBitcoinAddress payoutAddress (dest);
6161 obj.push_back (Pair (" payoutAddress" , payoutAddress.ToString ()));
6262 }
63- obj.push_back (Pair (" pubKeyOperator" , pubKeyOperator.ToString ()));
63+ obj.push_back (Pair (" pubKeyOperator" , pubKeyOperator.Get (). ToString ()));
6464 if (ExtractDestination (scriptOperatorPayout, dest)) {
6565 CBitcoinAddress operatorPayoutAddress (dest);
6666 obj.push_back (Pair (" operatorPayoutAddress" , operatorPayoutAddress.ToString ()));
@@ -147,7 +147,7 @@ CDeterministicMNCPtr CDeterministicMNList::GetValidMN(const uint256& proTxHash)
147147CDeterministicMNCPtr CDeterministicMNList::GetMNByOperatorKey (const CBLSPublicKey& pubKey)
148148{
149149 for (const auto & p : mnMap) {
150- if (p.second ->pdmnState ->pubKeyOperator == pubKey) {
150+ if (p.second ->pdmnState ->pubKeyOperator . Get () == pubKey) {
151151 return p.second ;
152152 }
153153 }
@@ -226,21 +226,21 @@ CDeterministicMNCPtr CDeterministicMNList::GetMNPayee() const
226226
227227std::vector<CDeterministicMNCPtr> CDeterministicMNList::GetProjectedMNPayees (int nCount) const
228228{
229+ if (nCount > GetValidMNsCount ()) {
230+ nCount = GetValidMNsCount ();
231+ }
232+
229233 std::vector<CDeterministicMNCPtr> result;
230234 result.reserve (nCount);
231235
232- CDeterministicMNList tmpMNList = *this ;
233- for (int h = nHeight; h < nHeight + nCount; h++) {
234- tmpMNList.SetHeight (h);
235-
236- CDeterministicMNCPtr payee = tmpMNList.GetMNPayee ();
237- // push the original MN object instead of the one from the temporary list
238- result.push_back (GetMN (payee->proTxHash ));
236+ ForEachMN (true , [&](const CDeterministicMNCPtr& dmn) {
237+ result.emplace_back (dmn);
238+ });
239+ std::sort (result.begin (), result.end (), [&](const CDeterministicMNCPtr& a, const CDeterministicMNCPtr& b) {
240+ return CompareByLastPaid (a, b);
241+ });
239242
240- CDeterministicMNStatePtr newState = std::make_shared<CDeterministicMNState>(*payee->pdmnState );
241- newState->nLastPaidHeight = h;
242- tmpMNList.UpdateMN (payee->proTxHash , newState);
243- }
243+ result.resize (nCount);
244244
245245 return result;
246246}
@@ -429,7 +429,7 @@ void CDeterministicMNList::AddMN(const CDeterministicMNCPtr& dmn)
429429 AddUniqueProperty (dmn, dmn->pdmnState ->addr );
430430 }
431431 AddUniqueProperty (dmn, dmn->pdmnState ->keyIDOwner );
432- if (dmn->pdmnState ->pubKeyOperator .IsValid ()) {
432+ if (dmn->pdmnState ->pubKeyOperator .Get (). IsValid ()) {
433433 AddUniqueProperty (dmn, dmn->pdmnState ->pubKeyOperator );
434434 }
435435}
@@ -457,7 +457,7 @@ void CDeterministicMNList::RemoveMN(const uint256& proTxHash)
457457 DeleteUniqueProperty (dmn, dmn->pdmnState ->addr );
458458 }
459459 DeleteUniqueProperty (dmn, dmn->pdmnState ->keyIDOwner );
460- if (dmn->pdmnState ->pubKeyOperator .IsValid ()) {
460+ if (dmn->pdmnState ->pubKeyOperator .Get (). IsValid ()) {
461461 DeleteUniqueProperty (dmn, dmn->pdmnState ->pubKeyOperator );
462462 }
463463 mnMap = mnMap.erase (proTxHash);
@@ -701,7 +701,7 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C
701701
702702 if (newState->nPoSeBanHeight != -1 ) {
703703 // only revive when all keys are set
704- if (newState->pubKeyOperator .IsValid () && !newState->keyIDVoting .IsNull () && !newState->keyIDOwner .IsNull ()) {
704+ if (newState->pubKeyOperator .Get (). IsValid () && !newState->keyIDVoting .IsNull () && !newState->keyIDOwner .IsNull ()) {
705705 newState->nPoSePenalty = 0 ;
706706 newState->nPoSeBanHeight = -1 ;
707707 newState->nPoSeRevivedHeight = nHeight;
@@ -729,12 +729,12 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C
729729 return _state.DoS (100 , false , REJECT_INVALID, " bad-protx-hash" );
730730 }
731731 auto newState = std::make_shared<CDeterministicMNState>(*dmn->pdmnState );
732- if (newState->pubKeyOperator != proTx.pubKeyOperator ) {
732+ if (newState->pubKeyOperator . Get () != proTx.pubKeyOperator ) {
733733 // reset all operator related fields and put MN into PoSe-banned state in case the operator key changes
734734 newState->ResetOperatorFields ();
735735 newState->BanIfNotBanned (nHeight);
736736 }
737- newState->pubKeyOperator = proTx.pubKeyOperator ;
737+ newState->pubKeyOperator . Set ( proTx.pubKeyOperator ) ;
738738 newState->keyIDVoting = proTx.keyIDVoting ;
739739 newState->scriptPayout = proTx.scriptPayout ;
740740
@@ -866,12 +866,14 @@ CDeterministicMNList CDeterministicMNManager::GetListForBlock(const uint256& blo
866866 }
867867
868868 if (evoDb.Read (std::make_pair (DB_LIST_SNAPSHOT, blockHashTmp), snapshot)) {
869+ mnListsCache.emplace (blockHashTmp, snapshot);
869870 break ;
870871 }
871872
872873 CDeterministicMNListDiff diff;
873874 if (!evoDb.Read (std::make_pair (DB_LIST_DIFF, blockHashTmp), diff)) {
874875 snapshot = CDeterministicMNList (blockHashTmp, -1 );
876+ mnListsCache.emplace (blockHashTmp, snapshot);
875877 break ;
876878 }
877879
@@ -886,9 +888,10 @@ CDeterministicMNList CDeterministicMNManager::GetListForBlock(const uint256& blo
886888 snapshot.SetBlockHash (diff.blockHash );
887889 snapshot.SetHeight (diff.nHeight );
888890 }
891+
892+ mnListsCache.emplace (diff.blockHash , snapshot);
889893 }
890894
891- mnListsCache.emplace (blockHash, snapshot);
892895 return snapshot;
893896}
894897
0 commit comments