@@ -470,11 +470,17 @@ void CDeterministicMNList::AddMN(const CDeterministicMNCPtr& dmn, bool fBumpTota
470
470
throw (std::runtime_error (strprintf (" %s: Can't add a masternode %s with a duplicate collateralOutpoint=%s" , __func__,
471
471
dmn->proTxHash .ToString (), dmn->collateralOutpoint .ToStringShort ())));
472
472
}
473
- for (const CService& entry : dmn->pdmnState ->netInfo .GetEntries ()) {
474
- if (!AddUniqueProperty (*dmn, entry)) {
475
- mnUniquePropertyMap = mnUniquePropertyMapSaved;
476
- throw (std::runtime_error (strprintf (" %s: Can't add a masternode %s with a duplicate address=%s" , __func__,
477
- dmn->proTxHash .ToString (), entry.ToStringAddrPort ())));
473
+ for (const NetInfoEntry& entry : dmn->pdmnState ->netInfo .GetEntries ()) {
474
+ if (const auto & service_opt{entry.GetAddrPort ()}; service_opt.has_value ()) {
475
+ const CService& service{service_opt.value ()};
476
+ if (!AddUniqueProperty (*dmn, service)) {
477
+ mnUniquePropertyMap = mnUniquePropertyMapSaved;
478
+ throw std::runtime_error (strprintf (" %s: Can't add a masternode %s with a duplicate address=%s" ,
479
+ __func__, dmn->proTxHash .ToString (), service.ToStringAddrPort ()));
480
+ }
481
+ } else {
482
+ throw std::runtime_error (
483
+ strprintf (" %s: Can't add a masternode %s with invalid address" , __func__, dmn->proTxHash .ToString ()));
478
484
}
479
485
}
480
486
if (!AddUniqueProperty (*dmn, dmn->pdmnState ->keyIDOwner )) {
@@ -518,14 +524,24 @@ void CDeterministicMNList::UpdateMN(const CDeterministicMN& oldDmn, const std::s
518
524
// We track each individual entry in netInfo as opposed to netInfo itself (preventing us from
519
525
// using UpdateUniqueProperty()), so we need to successfully purge all old entries and insert
520
526
// new entries to successfully update.
521
- for (const CService& old_entry : oldState->netInfo .GetEntries ()) {
522
- if (!DeleteUniqueProperty (*dmn, old_entry)) {
523
- return strprintf (" internal error" ); // This shouldn't be possible
527
+ for (const NetInfoEntry& old_entry : oldState->netInfo .GetEntries ()) {
528
+ if (const auto & service_opt{old_entry.GetAddrPort ()}; service_opt.has_value ()) {
529
+ const CService& service{service_opt.value ()};
530
+ if (!DeleteUniqueProperty (*dmn, service)) {
531
+ return strprintf (" internal error" ); // This shouldn't be possible
532
+ }
533
+ } else {
534
+ return strprintf (" invalid address" );
524
535
}
525
536
}
526
- for (const CService& new_entry : pdmnState->netInfo .GetEntries ()) {
527
- if (!AddUniqueProperty (*dmn, new_entry)) {
528
- return strprintf (" duplicate (%s)" , new_entry.ToStringAddrPort ());
537
+ for (const NetInfoEntry& new_entry : pdmnState->netInfo .GetEntries ()) {
538
+ if (const auto & service_opt{new_entry.GetAddrPort ()}; service_opt.has_value ()) {
539
+ const CService& service{service_opt.value ()};
540
+ if (!AddUniqueProperty (*dmn, service)) {
541
+ return strprintf (" duplicate (%s)" , service.ToStringAddrPort ());
542
+ }
543
+ } else {
544
+ return strprintf (" invalid address" );
529
545
}
530
546
}
531
547
}
@@ -591,11 +607,17 @@ void CDeterministicMNList::RemoveMN(const uint256& proTxHash)
591
607
throw (std::runtime_error (strprintf (" %s: Can't delete a masternode %s with a collateralOutpoint=%s" , __func__,
592
608
proTxHash.ToString (), dmn->collateralOutpoint .ToStringShort ())));
593
609
}
594
- for (const CService& entry : dmn->pdmnState ->netInfo .GetEntries ()) {
595
- if (!DeleteUniqueProperty (*dmn, entry)) {
596
- mnUniquePropertyMap = mnUniquePropertyMapSaved;
597
- throw (std::runtime_error (strprintf (" %s: Can't delete a masternode %s with an address=%s" , __func__,
598
- proTxHash.ToString (), entry.ToStringAddrPort ())));
610
+ for (const NetInfoEntry& entry : dmn->pdmnState ->netInfo .GetEntries ()) {
611
+ if (const auto & service_opt{entry.GetAddrPort ()}; service_opt.has_value ()) {
612
+ const CService& service{service_opt.value ()};
613
+ if (!DeleteUniqueProperty (*dmn, service)) {
614
+ mnUniquePropertyMap = mnUniquePropertyMapSaved;
615
+ throw std::runtime_error (strprintf (" %s: Can't delete a masternode %s with an address=%s" , __func__,
616
+ proTxHash.ToString (), service.ToStringAddrPort ()));
617
+ }
618
+ } else {
619
+ throw std::runtime_error (strprintf (" %s: Can't delete a masternode %s with invalid address" , __func__,
620
+ dmn->proTxHash .ToString ()));
599
621
}
600
622
}
601
623
if (!DeleteUniqueProperty (*dmn, dmn->pdmnState ->keyIDOwner )) {
@@ -811,9 +833,14 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, gsl::no
811
833
}
812
834
}
813
835
814
- for (const CService& entry : proTx.netInfo .GetEntries ()) {
815
- if (newList.HasUniqueProperty (entry)) {
816
- return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-protx-dup-netinfo-entry" );
836
+ for (const NetInfoEntry& entry : proTx.netInfo .GetEntries ()) {
837
+ if (const auto & service_opt{entry.GetAddrPort ()}; service_opt.has_value ()) {
838
+ const CService& service{service_opt.value ()};
839
+ if (newList.HasUniqueProperty (service)) {
840
+ return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-protx-dup-netinfo-entry" );
841
+ }
842
+ } else {
843
+ return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-protx-netinfo-entry" );
817
844
}
818
845
}
819
846
if (newList.HasUniqueProperty (proTx.keyIDOwner ) || newList.HasUniqueProperty (proTx.pubKeyOperator )) {
@@ -842,10 +869,15 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, gsl::no
842
869
return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-protx-payload" );
843
870
}
844
871
845
- for (const CService& entry : opt_proTx->netInfo .GetEntries ()) {
846
- if (newList.HasUniqueProperty (entry) &&
847
- newList.GetUniquePropertyMN (entry)->proTxHash != opt_proTx->proTxHash ) {
848
- return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-protx-dup-netinfo-entry" );
872
+ for (const NetInfoEntry& entry : opt_proTx->netInfo .GetEntries ()) {
873
+ if (const auto & service_opt{entry.GetAddrPort ()}; service_opt.has_value ()) {
874
+ const CService& service{service_opt.value ()};
875
+ if (newList.HasUniqueProperty (service) &&
876
+ newList.GetUniquePropertyMN (service)->proTxHash != opt_proTx->proTxHash ) {
877
+ return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-protx-dup-netinfo-entry" );
878
+ }
879
+ } else {
880
+ return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-protx-netinfo-entry" );
849
881
}
850
882
}
851
883
@@ -1382,10 +1414,15 @@ bool CheckProRegTx(CDeterministicMNManager& dmnman, const CTransaction& tx, gsl:
1382
1414
auto mnList = dmnman.GetListForBlock (pindexPrev);
1383
1415
1384
1416
// only allow reusing of addresses when it's for the same collateral (which replaces the old MN)
1385
- for (const CService& entry : opt_ptx->netInfo .GetEntries ()) {
1386
- if (mnList.HasUniqueProperty (entry) &&
1387
- mnList.GetUniquePropertyMN (entry)->collateralOutpoint != collateralOutpoint) {
1388
- return state.Invalid (TxValidationResult::TX_BAD_SPECIAL, " bad-protx-dup-netinfo-entry" );
1417
+ for (const NetInfoEntry& entry : opt_ptx->netInfo .GetEntries ()) {
1418
+ if (const auto & service_opt{entry.GetAddrPort ()}; service_opt.has_value ()) {
1419
+ const CService& service{service_opt.value ()};
1420
+ if (mnList.HasUniqueProperty (service) &&
1421
+ mnList.GetUniquePropertyMN (service)->collateralOutpoint != collateralOutpoint) {
1422
+ return state.Invalid (TxValidationResult::TX_BAD_SPECIAL, " bad-protx-dup-netinfo-entry" );
1423
+ }
1424
+ } else {
1425
+ return state.Invalid (TxValidationResult::TX_BAD_SPECIAL, " bad-protx-netinfo-entry" );
1389
1426
}
1390
1427
}
1391
1428
@@ -1455,9 +1492,14 @@ bool CheckProUpServTx(CDeterministicMNManager& dmnman, const CTransaction& tx, g
1455
1492
}
1456
1493
1457
1494
// don't allow updating to addresses already used by other MNs
1458
- for (const CService& entry : opt_ptx->netInfo .GetEntries ()) {
1459
- if (mnList.HasUniqueProperty (entry) && mnList.GetUniquePropertyMN (entry)->proTxHash != opt_ptx->proTxHash ) {
1460
- return state.Invalid (TxValidationResult::TX_BAD_SPECIAL, " bad-protx-dup-netinfo-entry" );
1495
+ for (const NetInfoEntry& entry : opt_ptx->netInfo .GetEntries ()) {
1496
+ if (const auto & service_opt{entry.GetAddrPort ()}; service_opt.has_value ()) {
1497
+ const CService& service{service_opt.value ()};
1498
+ if (mnList.HasUniqueProperty (service) && mnList.GetUniquePropertyMN (service)->proTxHash != opt_ptx->proTxHash ) {
1499
+ return state.Invalid (TxValidationResult::TX_BAD_SPECIAL, " bad-protx-dup-netinfo-entry" );
1500
+ }
1501
+ } else {
1502
+ return state.Invalid (TxValidationResult::TX_BAD_SPECIAL, " bad-protx-netinfo-entry" );
1461
1503
}
1462
1504
}
1463
1505
0 commit comments