Skip to content

Commit 1f3afb3

Browse files
committed
evo: allow deciding NetInfoInterface impl based on object version
1 parent 59a5e75 commit 1f3afb3

9 files changed

+21
-6
lines changed

src/evo/deterministicmns.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,7 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, gsl::no
934934
newState->BanIfNotBanned(nHeight);
935935
// we update pubKeyOperator here, make sure state version matches
936936
newState->nVersion = opt_proTx->nVersion;
937+
newState->netInfo = MakeNetInfo(*newState);
937938
newState->pubKeyOperator = opt_proTx->pubKeyOperator;
938939
}
939940
newState->keyIDVoting = opt_proTx->keyIDVoting;

src/evo/dmnstate.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class CDeterministicMNState
5454
CKeyID keyIDOwner;
5555
CBLSLazyPublicKey pubKeyOperator;
5656
CKeyID keyIDVoting;
57-
std::shared_ptr<NetInfoInterface> netInfo{MakeNetInfo()};
57+
std::shared_ptr<NetInfoInterface> netInfo{nullptr};
5858
CScript scriptPayout;
5959
CScript scriptOperatorPayout;
6060

@@ -112,7 +112,7 @@ class CDeterministicMNState
112112
{
113113
nVersion = ProTxVersion::LegacyBLS;
114114
pubKeyOperator = CBLSLazyPublicKey();
115-
netInfo = MakeNetInfo();
115+
netInfo = MakeNetInfo(*this);
116116
scriptOperatorPayout = CScript();
117117
nRevocationReason = CProUpRevTx::REASON_NOT_SPECIFIED;
118118
platformNodeID = uint160();

src/evo/netinfo.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,11 @@ class MnNetInfo final : public NetInfoInterface
211211
void Clear() override { m_addr.Clear(); }
212212
};
213213

214-
inline std::shared_ptr<NetInfoInterface> MakeNetInfo()
214+
/* Selects NetInfoInterface implementation to use based on object version */
215+
template <typename T1>
216+
std::shared_ptr<NetInfoInterface> MakeNetInfo(const T1& obj)
215217
{
218+
assert(obj.nVersion > 0);
216219
return std::make_shared<MnNetInfo>();
217220
}
218221

src/evo/providertx.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CProRegTx
4141
MnType nType{MnType::Regular};
4242
uint16_t nMode{0}; // only 0 supported for now
4343
COutPoint collateralOutpoint{uint256(), (uint32_t)-1}; // if hash is null, we refer to a ProRegTx output
44-
std::shared_ptr<NetInfoInterface> netInfo{MakeNetInfo()};
44+
std::shared_ptr<NetInfoInterface> netInfo{nullptr};
4545
uint160 platformNodeID{};
4646
uint16_t platformP2PPort{0};
4747
uint16_t platformHTTPPort{0};
@@ -110,7 +110,7 @@ class CProUpServTx
110110
uint16_t nVersion{ProTxVersion::LegacyBLS}; // message version
111111
MnType nType{MnType::Regular};
112112
uint256 proTxHash;
113-
std::shared_ptr<NetInfoInterface> netInfo{MakeNetInfo()};
113+
std::shared_ptr<NetInfoInterface> netInfo{nullptr};
114114
uint160 platformNodeID{};
115115
uint16_t platformP2PPort{0};
116116
uint16_t platformHTTPPort{0};

src/evo/simplifiedmns.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class CSimplifiedMNListEntry
3535
public:
3636
uint256 proRegTxHash;
3737
uint256 confirmedHash;
38-
std::shared_ptr<NetInfoInterface> netInfo{MakeNetInfo()};
38+
std::shared_ptr<NetInfoInterface> netInfo{nullptr};
3939
CBLSLazyPublicKey pubKeyOperator;
4040
CKeyID keyIDVoting;
4141
bool isValid{false};

src/rpc/evo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request,
658658
CProRegTx ptx;
659659
ptx.nType = mnType;
660660
ptx.nVersion = CProRegTx::GetMaxVersion(/*is_basic_scheme_active=*/!use_legacy);
661+
ptx.netInfo = MakeNetInfo(ptx);
661662

662663
if (action == ProTxRegisterAction::Fund) {
663664
CTxDestination collateralDest = DecodeDestination(request.params[paramIdx].get_str());
@@ -975,6 +976,7 @@ static UniValue protx_update_service_common_wrapper(const JSONRPCRequest& reques
975976
}
976977

977978
ptx.nVersion = dmn->pdmnState->nVersion;
979+
ptx.netInfo = MakeNetInfo(ptx);
978980

979981
if (auto entryRet = ptx.netInfo->AddEntry(request.params[1].get_str()); entryRet != NetInfoStatus::Success) {
980982
throw std::runtime_error(strprintf("%s (%s)", NISToString(entryRet), request.params[1].get_str()));

src/test/block_reward_reallocation_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ static CMutableTransaction CreateProRegTx(const CChain& active_chain, const CTxM
116116

117117
CProRegTx proTx;
118118
proTx.nVersion = CProRegTx::GetMaxVersion(!bls::bls_legacy_scheme);
119+
proTx.netInfo = MakeNetInfo(proTx);
119120
proTx.collateralOutpoint.n = 0;
120121
BOOST_CHECK_EQUAL(proTx.netInfo->AddEntry(strprintf("1.1.1.1:%d", port)), NetInfoStatus::Success);
121122
proTx.keyIDOwner = ownerKeyRet.GetPubKey().GetID();

src/test/evo_deterministicmns_tests.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ static CMutableTransaction CreateProRegTx(const CChain& active_chain, const CTxM
105105

106106
CProRegTx proTx;
107107
proTx.nVersion = CProRegTx::GetMaxVersion(!bls::bls_legacy_scheme);
108+
proTx.netInfo = MakeNetInfo(proTx);
108109
proTx.collateralOutpoint.n = 0;
109110
BOOST_CHECK_EQUAL(proTx.netInfo->AddEntry(strprintf("1.1.1.1:%d", port)), NetInfoStatus::Success);
110111
proTx.keyIDOwner = ownerKeyRet.GetPubKey().GetID();
@@ -127,6 +128,7 @@ static CMutableTransaction CreateProUpServTx(const CChain& active_chain, const C
127128
{
128129
CProUpServTx proTx;
129130
proTx.nVersion = CProUpServTx::GetMaxVersion(!bls::bls_legacy_scheme);
131+
proTx.netInfo = MakeNetInfo(proTx);
130132
proTx.proTxHash = proTxHash;
131133
BOOST_CHECK_EQUAL(proTx.netInfo->AddEntry(strprintf("1.1.1.1:%d", port)), NetInfoStatus::Success);
132134
proTx.scriptOperatorPayout = scriptOperatorPayout;
@@ -634,6 +636,7 @@ void FuncTestMempoolReorg(TestChainSetup& setup)
634636

635637
CProRegTx payload;
636638
payload.nVersion = CProRegTx::GetMaxVersion(!bls::bls_legacy_scheme);
639+
payload.netInfo = MakeNetInfo(payload);
637640
BOOST_CHECK_EQUAL(payload.netInfo->AddEntry("1.1.1.1:1"), NetInfoStatus::Success);
638641
payload.keyIDOwner = ownerKey.GetPubKey().GetID();
639642
payload.pubKeyOperator.Set(operatorKey.GetPublicKey(), bls::bls_legacy_scheme.load());
@@ -708,6 +711,8 @@ void FuncTestMempoolDualProregtx(TestChainSetup& setup)
708711
auto scriptPayout = GetScriptForDestination(PKHash(payoutKey.GetPubKey()));
709712

710713
CProRegTx payload;
714+
payload.nVersion = CProRegTx::GetMaxVersion(!bls::bls_legacy_scheme);
715+
payload.netInfo = MakeNetInfo(payload);
711716
BOOST_CHECK_EQUAL(payload.netInfo->AddEntry("1.1.1.1:2"), NetInfoStatus::Success);
712717
payload.keyIDOwner = ownerKey.GetPubKey().GetID();
713718
payload.pubKeyOperator.Set(operatorKey.GetPublicKey(), bls::bls_legacy_scheme.load());
@@ -776,6 +781,7 @@ void FuncVerifyDB(TestChainSetup& setup)
776781

777782
CProRegTx payload;
778783
payload.nVersion = CProRegTx::GetMaxVersion(!bls::bls_legacy_scheme);
784+
payload.netInfo = MakeNetInfo(payload);
779785
BOOST_CHECK_EQUAL(payload.netInfo->AddEntry("1.1.1.1:1"), NetInfoStatus::Success);
780786
payload.keyIDOwner = ownerKey.GetPubKey().GetID();
781787
payload.pubKeyOperator.Set(operatorKey.GetPublicKey(), bls::bls_legacy_scheme.load());

src/test/evo_simplifiedmns_tests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ BOOST_AUTO_TEST_CASE(simplifiedmns_merkleroots)
1919
std::vector<CSimplifiedMNListEntry> entries;
2020
for (size_t i = 1; i < 16; i++) {
2121
CSimplifiedMNListEntry smle;
22+
smle.nVersion = CProRegTx::GetMaxVersion(!bls::bls_legacy_scheme);
23+
smle.netInfo = MakeNetInfo(smle);
2224
smle.proRegTxHash.SetHex(strprintf("%064x", i));
2325
smle.confirmedHash.SetHex(strprintf("%064x", i));
2426

0 commit comments

Comments
 (0)