Skip to content

Commit 1bf8335

Browse files
committed
evo: allow deciding NetInfoInterface impl based on object version
1 parent fa9993f commit 1bf8335

File tree

9 files changed

+22
-6
lines changed

9 files changed

+22
-6
lines changed

src/evo/deterministicmns.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,7 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, gsl::no
885885
}
886886

887887
auto newState = std::make_shared<CDeterministicMNState>(*dmn->pdmnState);
888+
newState->nVersion = opt_proTx->nVersion;
888889
newState->netInfo = opt_proTx->netInfo;
889890
newState->scriptOperatorPayout = opt_proTx->scriptOperatorPayout;
890891
if (opt_proTx->nType == MnType::Evo) {
@@ -926,6 +927,7 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, gsl::no
926927
newState->BanIfNotBanned(nHeight);
927928
// we update pubKeyOperator here, make sure state version matches
928929
newState->nVersion = opt_proTx->nVersion;
930+
newState->netInfo = MakeNetInfo(*newState);
929931
newState->pubKeyOperator = opt_proTx->pubKeyOperator;
930932
}
931933
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

@@ -108,7 +108,7 @@ class CDeterministicMNState
108108
{
109109
nVersion = ProTxVersion::LegacyBLS;
110110
pubKeyOperator = CBLSLazyPublicKey();
111-
netInfo = MakeNetInfo();
111+
netInfo = MakeNetInfo(*this);
112112
scriptOperatorPayout = CScript();
113113
nRevocationReason = CProUpRevTx::REASON_NOT_SPECIFIED;
114114
platformNodeID = uint160();

src/evo/netinfo.h

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

200-
inline std::shared_ptr<NetInfoInterface> MakeNetInfo()
200+
/* Selects NetInfoInterface implementation to use based on object version */
201+
template <typename T1>
202+
std::shared_ptr<NetInfoInterface> MakeNetInfo(const T1& obj)
201203
{
204+
assert(obj.nVersion > 0);
202205
return std::make_shared<MnNetInfo>();
203206
}
204207

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
@@ -657,6 +657,7 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request,
657657
CProRegTx ptx;
658658
ptx.nType = mnType;
659659
ptx.nVersion = CProRegTx::GetMaxVersion(/*is_basic_scheme_active=*/!use_legacy);
660+
ptx.netInfo = MakeNetInfo(ptx);
660661

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

976977
ptx.nVersion = dmn->pdmnState->nVersion;
978+
ptx.netInfo = MakeNetInfo(ptx);
977979

978980
if (auto entryRet = ptx.netInfo->AddEntry(request.params[1].get_str()); entryRet != NetInfoStatus::Success) {
979981
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;
@@ -637,6 +639,7 @@ void FuncTestMempoolReorg(TestChainSetup& setup)
637639

638640
CProRegTx payload;
639641
payload.nVersion = CProRegTx::GetMaxVersion(!bls::bls_legacy_scheme);
642+
payload.netInfo = MakeNetInfo(payload);
640643
BOOST_CHECK_EQUAL(payload.netInfo->AddEntry("1.1.1.1:1"), NetInfoStatus::Success);
641644
payload.keyIDOwner = ownerKey.GetPubKey().GetID();
642645
payload.pubKeyOperator.Set(operatorKey.GetPublicKey(), bls::bls_legacy_scheme.load());
@@ -711,6 +714,8 @@ void FuncTestMempoolDualProregtx(TestChainSetup& setup)
711714
auto scriptPayout = GetScriptForDestination(PKHash(payoutKey.GetPubKey()));
712715

713716
CProRegTx payload;
717+
payload.nVersion = CProRegTx::GetMaxVersion(!bls::bls_legacy_scheme);
718+
payload.netInfo = MakeNetInfo(payload);
714719
BOOST_CHECK_EQUAL(payload.netInfo->AddEntry("1.1.1.1:2"), NetInfoStatus::Success);
715720
payload.keyIDOwner = ownerKey.GetPubKey().GetID();
716721
payload.pubKeyOperator.Set(operatorKey.GetPublicKey(), bls::bls_legacy_scheme.load());
@@ -779,6 +784,7 @@ void FuncVerifyDB(TestChainSetup& setup)
779784

780785
CProRegTx payload;
781786
payload.nVersion = CProRegTx::GetMaxVersion(!bls::bls_legacy_scheme);
787+
payload.netInfo = MakeNetInfo(payload);
782788
BOOST_CHECK_EQUAL(payload.netInfo->AddEntry("1.1.1.1:1"), NetInfoStatus::Success);
783789
payload.keyIDOwner = ownerKey.GetPubKey().GetID();
784790
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)