@@ -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 }
@@ -217,21 +217,21 @@ CDeterministicMNCPtr CDeterministicMNList::GetMNPayee() const
217217
218218std::vector<CDeterministicMNCPtr> CDeterministicMNList::GetProjectedMNPayees (int nCount) const
219219{
220+ if (nCount > GetValidMNsCount ()) {
221+ nCount = GetValidMNsCount ();
222+ }
223+
220224 std::vector<CDeterministicMNCPtr> result;
221225 result.reserve (nCount);
222226
223- CDeterministicMNList tmpMNList = *this ;
224- for (int h = nHeight; h < nHeight + nCount; h++) {
225- tmpMNList.SetHeight (h);
226-
227- CDeterministicMNCPtr payee = tmpMNList.GetMNPayee ();
228- // push the original MN object instead of the one from the temporary list
229- result.push_back (GetMN (payee->proTxHash ));
227+ ForEachMN (true , [&](const CDeterministicMNCPtr& dmn) {
228+ result.emplace_back (dmn);
229+ });
230+ std::sort (result.begin (), result.end (), [&](const CDeterministicMNCPtr& a, const CDeterministicMNCPtr& b) {
231+ return CompareByLastPaid (a, b);
232+ });
230233
231- CDeterministicMNStatePtr newState = std::make_shared<CDeterministicMNState>(*payee->pdmnState );
232- newState->nLastPaidHeight = h;
233- tmpMNList.UpdateMN (payee->proTxHash , newState);
234- }
234+ result.resize (nCount);
235235
236236 return result;
237237}
@@ -420,7 +420,7 @@ void CDeterministicMNList::AddMN(const CDeterministicMNCPtr& dmn)
420420 AddUniqueProperty (dmn, dmn->pdmnState ->addr );
421421 }
422422 AddUniqueProperty (dmn, dmn->pdmnState ->keyIDOwner );
423- if (dmn->pdmnState ->pubKeyOperator .IsValid ()) {
423+ if (dmn->pdmnState ->pubKeyOperator .Get (). IsValid ()) {
424424 AddUniqueProperty (dmn, dmn->pdmnState ->pubKeyOperator );
425425 }
426426}
@@ -448,7 +448,7 @@ void CDeterministicMNList::RemoveMN(const uint256& proTxHash)
448448 DeleteUniqueProperty (dmn, dmn->pdmnState ->addr );
449449 }
450450 DeleteUniqueProperty (dmn, dmn->pdmnState ->keyIDOwner );
451- if (dmn->pdmnState ->pubKeyOperator .IsValid ()) {
451+ if (dmn->pdmnState ->pubKeyOperator .Get (). IsValid ()) {
452452 DeleteUniqueProperty (dmn, dmn->pdmnState ->pubKeyOperator );
453453 }
454454 mnMap = mnMap.erase (proTxHash);
@@ -692,7 +692,7 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C
692692
693693 if (newState->nPoSeBanHeight != -1 ) {
694694 // only revive when all keys are set
695- if (newState->pubKeyOperator .IsValid () && !newState->keyIDVoting .IsNull () && !newState->keyIDOwner .IsNull ()) {
695+ if (newState->pubKeyOperator .Get (). IsValid () && !newState->keyIDVoting .IsNull () && !newState->keyIDOwner .IsNull ()) {
696696 newState->nPoSePenalty = 0 ;
697697 newState->nPoSeBanHeight = -1 ;
698698 newState->nPoSeRevivedHeight = nHeight;
@@ -720,12 +720,12 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C
720720 return _state.DoS (100 , false , REJECT_INVALID, " bad-protx-hash" );
721721 }
722722 auto newState = std::make_shared<CDeterministicMNState>(*dmn->pdmnState );
723- if (newState->pubKeyOperator != proTx.pubKeyOperator ) {
723+ if (newState->pubKeyOperator . Get () != proTx.pubKeyOperator ) {
724724 // reset all operator related fields and put MN into PoSe-banned state in case the operator key changes
725725 newState->ResetOperatorFields ();
726726 newState->BanIfNotBanned (nHeight);
727727 }
728- newState->pubKeyOperator = proTx.pubKeyOperator ;
728+ newState->pubKeyOperator . Set ( proTx.pubKeyOperator ) ;
729729 newState->keyIDVoting = proTx.keyIDVoting ;
730730 newState->scriptPayout = proTx.scriptPayout ;
731731
@@ -857,12 +857,14 @@ CDeterministicMNList CDeterministicMNManager::GetListForBlock(const uint256& blo
857857 }
858858
859859 if (evoDb.Read (std::make_pair (DB_LIST_SNAPSHOT, blockHashTmp), snapshot)) {
860+ mnListsCache.emplace (blockHashTmp, snapshot);
860861 break ;
861862 }
862863
863864 CDeterministicMNListDiff diff;
864865 if (!evoDb.Read (std::make_pair (DB_LIST_DIFF, blockHashTmp), diff)) {
865866 snapshot = CDeterministicMNList (blockHashTmp, -1 );
867+ mnListsCache.emplace (blockHashTmp, snapshot);
866868 break ;
867869 }
868870
@@ -877,9 +879,10 @@ CDeterministicMNList CDeterministicMNManager::GetListForBlock(const uint256& blo
877879 snapshot.SetBlockHash (diff.blockHash );
878880 snapshot.SetHeight (diff.nHeight );
879881 }
882+
883+ mnListsCache.emplace (diff.blockHash , snapshot);
880884 }
881885
882- mnListsCache.emplace (blockHash, snapshot);
883886 return snapshot;
884887}
885888
0 commit comments