Skip to content

Commit b334565

Browse files
Merge #6674: feat(rpc): allow reporting multiple addresses with new addresses field, deprecate service field, allow submitting multiple addresses
7fdd642 docs: add documentation for deprecation, new field and renamed input (Kittywhiskers Van Gogh) 5c564c2 test: check pre-fork conditions for ProRegTx and ProUpServTx preparation (Kittywhiskers Van Gogh) 859ce5c test: validate common conditions for input validation (Kittywhiskers Van Gogh) a60c39a test: add functional test for `addresses` and deprecated `service` field (Kittywhiskers Van Gogh) e0d2a81 rpc: deprecate key "service" replaced by "addresses" (Kittywhiskers Van Gogh) d9247ad rpc: add new key "addresses" to allow reporting multiple entries (Kittywhiskers Van Gogh) 33e5f6a refactor: s/ipAndPort/coreP2PAddrs/g (Kittywhiskers Van Gogh) 4fd4e0e rpc: allow `ipAndPort` to accept multiple entries with arrays (Kittywhiskers Van Gogh) 8c28f30 rpc: spin-off `ipAndPort` and `platform{HTTP,P2P}Port` setters to util (Kittywhiskers Van Gogh) Pull request description: ## Motivation To enable including functional tests with the extended addresses (ExtAddr) implementation (i.e. [dash#6666](#6666)), we need the ability to _specify_ and _retrieve_ multiple addresses. The current RPCs do not allow for that and this pull request aims to remedy it. This _particular_ pull request does not include: * Compatibility logic to allow reporting Platform-specific addresses using legacy fields (will be submitted after ExtAddr impl) * Compatibility logic to allow deriving Platform ports from extended address entries to populate deprecated fields (will be submitted after ExtAddr impl) * The ability to submit multiple Platform addresses (done in conjunction with ExtAddr impl) ## Additional Information * Depends on #6665 * Depends on #6720 * Dependency for #6666 * ⚠️ The format for the field replacing `service`, `addresses` is not stable and is changed in [dash#6666](#6666) to allow reporting Platform-specific addresses. This should be acceptable as the whole extended addresses changeset across multiple PRs is expected to be part of a major release but is mentioned here for the sake of posterity. * As `IsDeprecatedRPCEnabled()` is defined in `libbitcoin_node` (see `rpc/server.cpp`, [source](https://github.com/dashpay/dash/blob/da8a475dfac9ad80d566eef8cf119c8036d6ebcc/src/rpc/server.cpp#L370-L375)), it is not available to `libbitcoin_common`, where special transaction and network information source files are included. To get around this, a practically identical function, `IsServiceDeprecatedRPCEnabled()` is defined and used in non-RPC code. * It is located in `evo/netinfo.cpp` instead of a more natural `rpc/evo_util.cpp` to avoid unnecessary circular dependencies. ## Breaking Changes * The input field `ipAndPort` has been renamed to `coreP2PAddrs`. * `coreP2PAddrs` can now, in addition to accepting a string, accept an array of strings, subject to validation rules. * The key `service` has been deprecated for some RPCs (`decoderawtransaction`, `decodepsbt`, `getblock`, `getrawtransaction`, `gettransaction`, `masternode status` (only for the `dmnState` key), `protx diff`, `protx listdiff`) and has been replaced with the field `addresses`. * The deprecated field can be re-enabled using `-deprecatedrpc=service` but is liable to be removed in future versions of Dash Core. * This change does not affect `masternode status` (except for the `dmnState` key) as `service` does not represent a payload value but the external address advertised by the active masternode. ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have added or updated relevant unit/integration/functional/e2e tests - [x] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: PastaPastaPasta: utACK 7fdd642 UdjinM6: utACK 7fdd642 Tree-SHA512: 75331a467e7170542349c94408b71f5d25ebd2bf418cb6bdf77866a342b9079ec795638535f67c6487739b37651bf8265dce66ef3b06e0732748a173441695ef
2 parents 9310ebc + 7fdd642 commit b334565

21 files changed

+532
-79
lines changed

contrib/seeds/makeseeds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def main():
164164
mns = filtermulticollateraladdress(mns)
165165
mns = filtermultipayoutaddress(mns)
166166
# Extract IPs
167-
ips = [parseip(mn['state']['service']) for mn in mns]
167+
ips = [parseip(mn['state']['addresses'][0]) for mn in mns]
168168
for onion in onions:
169169
parsed = parseip(onion)
170170
if parsed is not None:

doc/release-notes-6665.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Updated RPCs
2+
------------
3+
4+
* The input field `ipAndPort` has been renamed to `coreP2PAddrs`.
5+
* `coreP2PAddrs` can now, in addition to accepting a string, accept an array of strings, subject to validation rules.
6+
7+
* The key `service` has been deprecated for some RPCs (`decoderawtransaction`, `decodepsbt`, `getblock`, `getrawtransaction`,
8+
`gettransaction`, `masternode status` (only for the `dmnState` key), `protx diff`, `protx listdiff`) and has been replaced
9+
with the field `addresses`.
10+
* The deprecated field can be re-enabled using `-deprecatedrpc=service` but is liable to be removed in future versions
11+
of Dash Core.
12+
* This change does not affect `masternode status` (except for the `dmnState` key) as `service` does not represent a payload
13+
value but the external address advertised by the active masternode.

src/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ BITCOIN_CORE_H = \
300300
randomenv.h \
301301
rpc/blockchain.h \
302302
rpc/client.h \
303+
rpc/evo_util.h \
303304
rpc/index_util.h \
304305
rpc/mempool.h \
305306
rpc/mining.h \
@@ -801,6 +802,7 @@ libbitcoin_common_a_SOURCES = \
801802
policy/policy.cpp \
802803
protocol.cpp \
803804
psbt.cpp \
805+
rpc/evo_util.cpp \
804806
rpc/rawtransaction_util.cpp \
805807
rpc/util.cpp \
806808
saltedhasher.cpp \

src/coinjoin/client.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1879,7 +1879,10 @@ void CCoinJoinClientSession::GetJsonInfo(UniValue& obj) const
18791879
assert(mixingMasternode->pdmnState);
18801880
obj.pushKV("protxhash", mixingMasternode->proTxHash.ToString());
18811881
obj.pushKV("outpoint", mixingMasternode->collateralOutpoint.ToStringShort());
1882-
obj.pushKV("service", mixingMasternode->pdmnState->netInfo->GetPrimary().ToStringAddrPort());
1882+
if (m_wallet->chain().rpcEnableDeprecated("service")) {
1883+
obj.pushKV("service", mixingMasternode->pdmnState->netInfo->GetPrimary().ToStringAddrPort());
1884+
}
1885+
obj.pushKV("addresses", mixingMasternode->pdmnState->netInfo->ToJson());
18831886
}
18841887
obj.pushKV("denomination", ValueFromAmount(CoinJoin::DenominationToAmount(nSessionDenom)));
18851888
obj.pushKV("state", GetStateString());

src/evo/core_write.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@
6767
ret.pushKV("type", ToUnderlying(nType));
6868
ret.pushKV("collateralHash", collateralOutpoint.hash.ToString());
6969
ret.pushKV("collateralIndex", (int)collateralOutpoint.n);
70-
ret.pushKV("service", netInfo->GetPrimary().ToStringAddrPort());
70+
if (IsServiceDeprecatedRPCEnabled()) {
71+
ret.pushKV("service", netInfo->GetPrimary().ToStringAddrPort());
72+
}
73+
ret.pushKV("addresses", netInfo->ToJson());
7174
ret.pushKV("ownerAddress", EncodeDestination(PKHash(keyIDOwner)));
7275
ret.pushKV("votingAddress", EncodeDestination(PKHash(keyIDVoting)));
7376
if (CTxDestination dest; ExtractDestination(scriptPayout, dest)) {
@@ -114,7 +117,10 @@
114117
ret.pushKV("version", nVersion);
115118
ret.pushKV("type", ToUnderlying(nType));
116119
ret.pushKV("proTxHash", proTxHash.ToString());
117-
ret.pushKV("service", netInfo->GetPrimary().ToStringAddrPort());
120+
if (IsServiceDeprecatedRPCEnabled()) {
121+
ret.pushKV("service", netInfo->GetPrimary().ToStringAddrPort());
122+
}
123+
ret.pushKV("addresses", netInfo->ToJson());
118124
if (CTxDestination dest; ExtractDestination(scriptOperatorPayout, dest)) {
119125
ret.pushKV("operatorPayoutAddress", EncodeDestination(dest));
120126
}

src/evo/dmnstate.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ UniValue CDeterministicMNState::ToJson(MnType nType) const
3838
{
3939
UniValue obj(UniValue::VOBJ);
4040
obj.pushKV("version", nVersion);
41-
obj.pushKV("service", netInfo->GetPrimary().ToStringAddrPort());
41+
if (IsServiceDeprecatedRPCEnabled()) {
42+
obj.pushKV("service", netInfo->GetPrimary().ToStringAddrPort());
43+
}
44+
obj.pushKV("addresses", netInfo->ToJson());
4245
obj.pushKV("registeredHeight", nRegisteredHeight);
4346
obj.pushKV("lastPaidHeight", nLastPaidHeight);
4447
obj.pushKV("consecutivePayments", nConsecutivePayments);
@@ -72,7 +75,10 @@ UniValue CDeterministicMNStateDiff::ToJson(MnType nType) const
7275
obj.pushKV("version", state.nVersion);
7376
}
7477
if (fields & Field_netInfo) {
75-
obj.pushKV("service", state.netInfo->GetPrimary().ToStringAddrPort());
78+
if (IsServiceDeprecatedRPCEnabled()) {
79+
obj.pushKV("service", state.netInfo->GetPrimary().ToStringAddrPort());
80+
}
81+
obj.pushKV("addresses", state.netInfo->ToJson());
7682
}
7783
if (fields & Field_nRegisteredHeight) {
7884
obj.pushKV("registeredHeight", state.nRegisteredHeight);

src/evo/netinfo.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <util/check.h>
1212
#include <util/system.h>
1313

14+
#include <univalue.h>
15+
1416
namespace {
1517
static std::unique_ptr<const CChainParams> g_main_params{nullptr};
1618
static std::once_flag g_main_params_flag;
@@ -33,6 +35,19 @@ bool MatchCharsFilter(std::string_view input, std::string_view filter)
3335
}
3436
} // anonymous namespace
3537

38+
UniValue ArrFromService(const CService& addr)
39+
{
40+
UniValue obj(UniValue::VARR);
41+
obj.push_back(addr.ToStringAddrPort());
42+
return obj;
43+
}
44+
45+
bool IsServiceDeprecatedRPCEnabled()
46+
{
47+
const auto args = gArgs.GetArgs("-deprecatedrpc");
48+
return std::find(args.begin(), args.end(), "service") != args.end();
49+
}
50+
3651
bool NetInfoEntry::operator==(const NetInfoEntry& rhs) const
3752
{
3853
if (m_type != rhs.m_type) return false;
@@ -227,6 +242,11 @@ NetInfoStatus MnNetInfo::Validate() const
227242
return ValidateService(GetPrimary());
228243
}
229244

245+
UniValue MnNetInfo::ToJson() const
246+
{
247+
return ArrFromService(GetPrimary());
248+
}
249+
230250
std::string MnNetInfo::ToString() const
231251
{
232252
// Extra padding to account for padding done by the calling function.

src/evo/netinfo.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
class CService;
1515

16+
class UniValue;
17+
1618
enum class NetInfoStatus : uint8_t {
1719
// Managing entries
1820
BadInput,
@@ -51,6 +53,9 @@ constexpr std::string_view NISToString(const NetInfoStatus code)
5153
assert(false);
5254
}
5355

56+
/* Identical to IsDeprecatedRPCEnabled("service"). For use outside of RPC code. */
57+
bool IsServiceDeprecatedRPCEnabled();
58+
5459
class NetInfoEntry
5560
{
5661
public:
@@ -141,6 +146,7 @@ class NetInfoInterface
141146
virtual bool CanStorePlatform() const = 0;
142147
virtual bool IsEmpty() const = 0;
143148
virtual NetInfoStatus Validate() const = 0;
149+
virtual UniValue ToJson() const = 0;
144150
virtual std::string ToString() const = 0;
145151

146152
virtual void Clear() = 0;
@@ -197,6 +203,7 @@ class MnNetInfo final : public NetInfoInterface
197203
bool IsEmpty() const override { return m_addr.IsEmpty(); }
198204
bool CanStorePlatform() const override { return false; }
199205
NetInfoStatus Validate() const override;
206+
UniValue ToJson() const override;
200207
std::string ToString() const override;
201208

202209
void Clear() override { m_addr.Clear(); }

src/evo/simplifiedmns.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44

55
#include <evo/simplifiedmns.h>
66

7-
#include <evo/cbtx.h>
87
#include <core_io.h>
98
#include <deploymentstatus.h>
9+
#include <evo/cbtx.h>
1010
#include <evo/deterministicmns.h>
11+
#include <evo/netinfo.h>
12+
#include <evo/specialtx.h>
1113
#include <llmq/blockprocessor.h>
1214
#include <llmq/commitment.h>
1315
#include <llmq/quorums.h>
1416
#include <node/blockstorage.h>
15-
#include <evo/specialtx.h>
1617

1718
#include <pubkey.h>
1819
#include <serialize.h>
@@ -80,7 +81,10 @@ UniValue CSimplifiedMNListEntry::ToJson(bool extended) const
8081
obj.pushKV("nType", ToUnderlying(nType));
8182
obj.pushKV("proRegTxHash", proRegTxHash.ToString());
8283
obj.pushKV("confirmedHash", confirmedHash.ToString());
83-
obj.pushKV("service", netInfo->GetPrimary().ToStringAddrPort());
84+
if (IsServiceDeprecatedRPCEnabled()) {
85+
obj.pushKV("service", netInfo->GetPrimary().ToStringAddrPort());
86+
}
87+
obj.pushKV("addresses", netInfo->ToJson());
8488
obj.pushKV("pubKeyOperator", pubKeyOperator.ToString());
8589
obj.pushKV("votingAddress", EncodeDestination(PKHash(keyIDVoting)));
8690
obj.pushKV("isValid", isValid);

src/rpc/coinjoin.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,13 @@ static RPCHelpMan getcoinjoininfo()
435435
{
436436
{RPCResult::Type::STR_HEX, "protxhash", "The ProTxHash of the masternode"},
437437
{RPCResult::Type::STR_HEX, "outpoint", "The outpoint of the masternode"},
438-
{RPCResult::Type::STR, "service", "The IP address and port of the masternode"},
438+
{RPCResult::Type::STR, "service", "The IP address and port of the masternode (DEPRECATED, returned only if config option -deprecatedrpc=service is passed)"},
439+
{RPCResult::Type::ARR, "addresses", "Network addresses of the masternode",
440+
{
441+
{
442+
{RPCResult::Type::STR, "address", ""},
443+
}
444+
}},
439445
{RPCResult::Type::NUM, "denomination", "The denomination of the mixing session in " + CURRENCY_UNIT + ""},
440446
{RPCResult::Type::STR_HEX, "state", "Current state of the mixing session"},
441447
{RPCResult::Type::NUM, "entries_count", "The number of entries in the mixing session"},

0 commit comments

Comments
 (0)