2222#include < stats/client.h>
2323#include < uint256.h>
2424#include < univalue.h>
25+ #include < util/pointer.h>
2526#include < validationinterface.h>
2627
2728#include < optional>
@@ -409,7 +410,7 @@ void CDeterministicMNList::AddMN(const CDeterministicMNCPtr& dmn, bool fBumpTota
409410 throw (std::runtime_error (strprintf (" %s: Can't add a masternode %s with a duplicate collateralOutpoint=%s" , __func__,
410411 dmn->proTxHash .ToString (), dmn->collateralOutpoint .ToStringShort ())));
411412 }
412- for (const NetInfoEntry& entry : dmn->pdmnState ->netInfo . GetEntries ()) {
413+ for (const NetInfoEntry& entry : dmn->pdmnState ->netInfo -> GetEntries ()) {
413414 if (const auto & service_opt{entry.GetAddrPort ()}; service_opt.has_value ()) {
414415 const CService& service{service_opt.value ()};
415416 if (!AddUniqueProperty (*dmn, service)) {
@@ -459,13 +460,13 @@ void CDeterministicMNList::UpdateMN(const CDeterministicMN& oldDmn, const std::s
459460 // Using this temporary map as a checkpoint to roll back to in case of any issues.
460461 decltype (mnUniquePropertyMap) mnUniquePropertyMapSaved = mnUniquePropertyMap;
461462
462- auto updateNetInfo = [this ](const CDeterministicMN& dmn, const MnNetInfo& oldInfo,
463- const MnNetInfo& newInfo) -> std::string {
464- if (oldInfo != newInfo) {
463+ auto updateNetInfo = [this ](const CDeterministicMN& dmn, const std::shared_ptr< MnNetInfo> & oldInfo,
464+ const std::shared_ptr< MnNetInfo> & newInfo) -> std::string {
465+ if (util::shared_ptr_not_equal ( oldInfo, newInfo) ) {
465466 // We track each individual entry in netInfo as opposed to netInfo itself (preventing us from
466467 // using UpdateUniqueProperty()), so we need to successfully purge all old entries and insert
467468 // new entries to successfully update.
468- for (const NetInfoEntry& old_entry : oldInfo. GetEntries ()) {
469+ for (const NetInfoEntry& old_entry : oldInfo-> GetEntries ()) {
469470 if (const auto & service_opt{old_entry.GetAddrPort ()}) {
470471 const CService& service{service_opt.value ()};
471472 if (!DeleteUniqueProperty (dmn, service)) {
@@ -475,7 +476,7 @@ void CDeterministicMNList::UpdateMN(const CDeterministicMN& oldDmn, const std::s
475476 return " invalid address" ;
476477 }
477478 }
478- for (const NetInfoEntry& new_entry : newInfo. GetEntries ()) {
479+ for (const NetInfoEntry& new_entry : newInfo-> GetEntries ()) {
479480 if (const auto & service_opt{new_entry.GetAddrPort ()}) {
480481 const CService& service{service_opt.value ()};
481482 if (!AddUniqueProperty (dmn, service)) {
@@ -489,6 +490,7 @@ void CDeterministicMNList::UpdateMN(const CDeterministicMN& oldDmn, const std::s
489490 return " " ;
490491 };
491492
493+ assert (oldState->netInfo && pdmnState->netInfo );
492494 if (auto err = updateNetInfo (*dmn, oldState->netInfo , pdmnState->netInfo ); !err.empty ()) {
493495 mnUniquePropertyMap = mnUniquePropertyMapSaved;
494496 throw (std::runtime_error (strprintf (" %s: Can't update masternode %s with addresses, reason=%s" , __func__,
@@ -549,7 +551,7 @@ void CDeterministicMNList::RemoveMN(const uint256& proTxHash)
549551 throw (std::runtime_error (strprintf (" %s: Can't delete a masternode %s with a collateralOutpoint=%s" , __func__,
550552 proTxHash.ToString (), dmn->collateralOutpoint .ToStringShort ())));
551553 }
552- for (const NetInfoEntry& entry : dmn->pdmnState ->netInfo . GetEntries ()) {
554+ for (const NetInfoEntry& entry : dmn->pdmnState ->netInfo -> GetEntries ()) {
553555 if (const auto & service_opt{entry.GetAddrPort ()}; service_opt.has_value ()) {
554556 const CService& service{service_opt.value ()};
555557 if (!DeleteUniqueProperty (*dmn, service)) {
@@ -777,7 +779,7 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, gsl::no
777779 }
778780 }
779781
780- for (const NetInfoEntry& entry : proTx.netInfo . GetEntries ()) {
782+ for (const NetInfoEntry& entry : proTx.netInfo -> GetEntries ()) {
781783 if (const auto & service_opt{entry.GetAddrPort ()}; service_opt.has_value ()) {
782784 const CService& service{service_opt.value ()};
783785 if (newList.HasUniqueProperty (service)) {
@@ -795,7 +797,7 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, gsl::no
795797
796798 auto dmnState = std::make_shared<CDeterministicMNState>(proTx);
797799 dmnState->nRegisteredHeight = nHeight;
798- if (proTx.netInfo . IsEmpty ()) {
800+ if (proTx.netInfo -> IsEmpty ()) {
799801 // start in banned pdmnState as we need to wait for a ProUpServTx
800802 dmnState->BanIfNotBanned (nHeight);
801803 }
@@ -813,7 +815,7 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, gsl::no
813815 return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-protx-payload" );
814816 }
815817
816- for (const NetInfoEntry& entry : opt_proTx->netInfo . GetEntries ()) {
818+ for (const NetInfoEntry& entry : opt_proTx->netInfo -> GetEntries ()) {
817819 if (const auto & service_opt{entry.GetAddrPort ()}; service_opt.has_value ()) {
818820 const CService& service{service_opt.value ()};
819821 if (newList.HasUniqueProperty (service) &&
@@ -1175,7 +1177,7 @@ void CDeterministicMNManager::CleanupCache(int nHeight)
11751177template <typename ProTx>
11761178static bool CheckService (const ProTx& proTx, TxValidationState& state)
11771179{
1178- switch (proTx.netInfo . Validate ()) {
1180+ switch (proTx.netInfo -> Validate ()) {
11791181 case NetInfoStatus::BadAddress:
11801182 return state.Invalid (TxValidationResult::TX_BAD_SPECIAL, " bad-protx-netinfo-addr" );
11811183 case NetInfoStatus::BadPort:
@@ -1228,8 +1230,8 @@ static bool CheckPlatformFields(const ProTx& proTx, TxValidationState& state)
12281230 return state.Invalid (TxValidationResult::TX_BAD_SPECIAL, " bad-protx-platform-http-port" );
12291231 }
12301232
1231- if (proTx.platformP2PPort == proTx.platformHTTPPort || proTx.platformP2PPort == proTx.netInfo . GetPrimary ().GetPort () ||
1232- proTx.platformHTTPPort == proTx.netInfo . GetPrimary ().GetPort ()) {
1233+ if (proTx.platformP2PPort == proTx.platformHTTPPort || proTx.platformP2PPort == proTx.netInfo -> GetPrimary ().GetPort () ||
1234+ proTx.platformHTTPPort == proTx.netInfo -> GetPrimary ().GetPort ()) {
12331235 return state.Invalid (TxValidationResult::TX_BAD_SPECIAL, " bad-protx-platform-dup-ports" );
12341236 }
12351237
@@ -1294,7 +1296,7 @@ bool CheckProRegTx(CDeterministicMNManager& dmnman, const CTransaction& tx, gsl:
12941296
12951297 // It's allowed to set addr to 0, which will put the MN into PoSe-banned state and require a ProUpServTx to be issues later
12961298 // If any of both is set, it must be valid however
1297- if (!opt_ptx->netInfo . IsEmpty () && !CheckService (*opt_ptx, state)) {
1299+ if (!opt_ptx->netInfo -> IsEmpty () && !CheckService (*opt_ptx, state)) {
12981300 // pass the state returned by the function above
12991301 return false ;
13001302 }
@@ -1354,7 +1356,7 @@ bool CheckProRegTx(CDeterministicMNManager& dmnman, const CTransaction& tx, gsl:
13541356 auto mnList = dmnman.GetListForBlock (pindexPrev);
13551357
13561358 // only allow reusing of addresses when it's for the same collateral (which replaces the old MN)
1357- for (const NetInfoEntry& entry : opt_ptx->netInfo . GetEntries ()) {
1359+ for (const NetInfoEntry& entry : opt_ptx->netInfo -> GetEntries ()) {
13581360 if (const auto & service_opt{entry.GetAddrPort ()}; service_opt.has_value ()) {
13591361 const CService& service{service_opt.value ()};
13601362 if (mnList.HasUniqueProperty (service) &&
@@ -1432,7 +1434,7 @@ bool CheckProUpServTx(CDeterministicMNManager& dmnman, const CTransaction& tx, g
14321434 }
14331435
14341436 // don't allow updating to addresses already used by other MNs
1435- for (const NetInfoEntry& entry : opt_ptx->netInfo . GetEntries ()) {
1437+ for (const NetInfoEntry& entry : opt_ptx->netInfo -> GetEntries ()) {
14361438 if (const auto & service_opt{entry.GetAddrPort ()}; service_opt.has_value ()) {
14371439 const CService& service{service_opt.value ()};
14381440 if (mnList.HasUniqueProperty (service) && mnList.GetUniquePropertyMN (service)->proTxHash != opt_ptx->proTxHash ) {
0 commit comments