Skip to content

Commit

Permalink
Merge #2873: [RPC][MN] Serialize in ADDRV2 for TorV3 in RPC's
Browse files Browse the repository at this point in the history
6d3d535 Deserialize AddrV1 first if fails deserialize AddrV2 (Liquid369)
afd0c73 Fix MNB Serialization for ADDRv2 in RPCs (Liquid369)

Pull request description:

  With some work being done in PIVX-Labs by @Duddino we noticed that the RPC's for decoding and creating master node broadcasts are in Pre-BIP 155 format or AddrV1 serialization.
  In order for us to create support for Tor master nodes in MPW, we need these RPC's to be able to serialize a TorV3 address.

  There's a few caveats for decoding that there may be other solutions provided by someone else, but for now since receiving the stream, we cannot tell if its PreBIP155 or not, so we unserialize by AddrV1 first and if it fails, we check and attempt AddrV2.

ACKs for top commit:
  Liquid369:
    > tACK [6d3d535](6d3d535) tested on Duddino's node throught MPW, works as intended.
  Duddino:
    tACK 6d3d535 because the above is a really small nitpick
  panleone:
    tACK 6d3d535 tested on Duddino's node throught MPW, works as intended.
  Fuzzbawls:
    ACK 6d3d535

Tree-SHA512: a5f66ef17a8c2d33240bb37e4f6c166ba76cbc5c43de0bc9f92209f44846ab73f41ba146a9d17284ea418af356e7d898f9ee2b1c4c4f3bc3436206712be18389
  • Loading branch information
Fuzzbawls committed Aug 10, 2023
2 parents 6c26a0e + 6d3d535 commit 05fdf60
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/rpc/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "masternode-payments.h"
#include "masternodeconfig.h"
#include "masternodeman.h"
#include "netaddress.h"
#include "netbase.h"
#include "tiertwo/tiertwo_sync_state.h"
#include "rpc/server.h"
Expand Down Expand Up @@ -390,9 +391,11 @@ void RelayMNB(CMasternodeBroadcast& mnb, const bool fSucces)

void SerializeMNB(UniValue& statusObjRet, const CMasternodeBroadcast& mnb, const bool fSuccess, int& successful, int& failed)
{
bool isBIP155 = mnb.addr.IsAddrV1Compatible();
int version = isBIP155 ? PROTOCOL_VERSION | ADDRV2_FORMAT : PROTOCOL_VERSION;
if(fSuccess) {
successful++;
CDataStream ssMnb(SER_NETWORK, PROTOCOL_VERSION);
CDataStream ssMnb(SER_NETWORK, version);
ssMnb << mnb;
statusObjRet.pushKV("hex", HexStr(ssMnb));
} else {
Expand Down Expand Up @@ -875,11 +878,7 @@ UniValue getmasternodescores(const JSONRPCRequest& request)
return obj;
}

bool DecodeHexMnb(CMasternodeBroadcast& mnb, std::string strHexMnb) {

if (!IsHex(strHexMnb))
return false;

bool DecodeAddrV1(CMasternodeBroadcast& mnb, std::string strHexMnb) {
std::vector<unsigned char> mnbData(ParseHex(strHexMnb));
CDataStream ssData(mnbData, SER_NETWORK, PROTOCOL_VERSION);
try {
Expand All @@ -891,6 +890,27 @@ bool DecodeHexMnb(CMasternodeBroadcast& mnb, std::string strHexMnb) {

return true;
}

bool DecodeHexMnb(CMasternodeBroadcast& mnb, std::string strHexMnb) {

if (!IsHex(strHexMnb))
return false;

bool MNAddrV1 = DecodeAddrV1(mnb, strHexMnb);
if (!MNAddrV1) {
std::vector<unsigned char> mnbData(ParseHex(strHexMnb));
CDataStream ssData(mnbData, SER_NETWORK, PROTOCOL_VERSION | ADDRV2_FORMAT);
try {
ssData >> mnb;
}
catch (const std::exception&) {
return false;
}
return true;
}
return true;
}

UniValue createmasternodebroadcast(const JSONRPCRequest& request)
{
CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
Expand Down

0 comments on commit 05fdf60

Please sign in to comment.