From 82851b439c2223fc5e114c42c97eb7f5121ef86c Mon Sep 17 00:00:00 2001 From: Oleg Girko Date: Fri, 21 Jul 2017 19:31:47 +0100 Subject: [PATCH] Backport Bitcoin PR#8049: Expose information on whether transaction relay is enabled in `getnetwork` (#1545) * net: Add fRelayTxes flag Add a fRelayTxes to keep track of the relay transaction flag we send to other peers. * rpc: Add `relaytxes` flag to `getnetworkinfo` Re-work of PR #7841 by dragongem45. Closes #7771. --- src/init.cpp | 1 + src/main.cpp | 4 ++-- src/net.cpp | 1 + src/net.h | 1 + src/rpc/net.cpp | 2 ++ 5 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 293152a26..8cb664d30 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1394,6 +1394,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) fListen = GetBoolArg("-listen", DEFAULT_LISTEN); fDiscover = GetBoolArg("-discover", true); fNameLookup = GetBoolArg("-dns", DEFAULT_NAME_LOOKUP); + fRelayTxes = !GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY); bool fBound = false; if (fListen) { diff --git a/src/main.cpp b/src/main.cpp index 18a21eb47..85b9a75f6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5556,7 +5556,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, return error("message inv size() = %u", vInv.size()); } - bool fBlocksOnly = GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY); + bool fBlocksOnly = !fRelayTxes; // Allow whitelisted peers to send data other than blocks in blocks only mode if whitelistrelay is true if (pfrom->fWhitelisted && GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY)) @@ -5746,7 +5746,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, { // Stop processing the transaction early if // We are in blocks only mode and peer is either not whitelisted or whitelistrelay is off - if (GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY) && (!pfrom->fWhitelisted || !GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY))) + if (!fRelayTxes && (!pfrom->fWhitelisted || !GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY))) { LogPrint("net", "transaction sent in violation of protocol peer=%d\n", pfrom->id); return true; diff --git a/src/net.cpp b/src/net.cpp index 06a2dadfc..6fe0dc721 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -73,6 +73,7 @@ const static std::string NET_MESSAGE_COMMAND_OTHER = "*other*"; // bool fDiscover = true; bool fListen = true; +bool fRelayTxes = true; CCriticalSection cs_mapLocalHost; std::map mapLocalHost; static bool vfLimited[NET_MAX] = {}; diff --git a/src/net.h b/src/net.h index e63381cbc..f0ae9d977 100644 --- a/src/net.h +++ b/src/net.h @@ -470,6 +470,7 @@ CAddress GetLocalAddress(const CNetAddr *paddrPeer, ServiceFlags nLocalServices) extern bool fDiscover; extern bool fListen; +extern bool fRelayTxes; extern std::map mapRelay; extern std::deque > vRelayExpiration; diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 9ae97872d..7c9ad7bdb 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -398,6 +398,7 @@ UniValue getnetworkinfo(const UniValue& params, bool fHelp) " \"subversion\": \"/Dash Core:x.x.x/\", (string) the server subversion string\n" " \"protocolversion\": xxxxx, (numeric) the protocol version\n" " \"localservices\": \"xxxxxxxxxxxxxxxx\", (string) the services we offer to the network\n" + " \"localrelay\": true|false, (bool) true if transaction relay is requested from peers\n" " \"timeoffset\": xxxxx, (numeric) the time offset\n" " \"connections\": xxxxx, (numeric) the number of connections\n" " \"networks\": [ (array) information per network\n" @@ -432,6 +433,7 @@ UniValue getnetworkinfo(const UniValue& params, bool fHelp) obj.push_back(Pair("protocolversion",PROTOCOL_VERSION)); if(g_connman) obj.push_back(Pair("localservices", strprintf("%016x", g_connman->GetLocalServices()))); + obj.push_back(Pair("localrelay", fRelayTxes)); obj.push_back(Pair("timeoffset", GetTimeOffset())); if(g_connman) obj.push_back(Pair("connections", (int)g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL)));