From 4044f07d1c5eacb0ec732f1232489aa77fb7bb3b Mon Sep 17 00:00:00 2001 From: Patick Strateman Date: Sat, 14 Nov 2015 04:44:15 -0800 Subject: Add blocksonly mode --- src/net.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/net.cpp b/src/net.cpp index 1ea50b2493..a62e875f83 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -460,7 +460,7 @@ void CNode::PushVersion() else LogPrint("net", "send version message: version %d, blocks=%d, us=%s, peer=%d\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString(), id); PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe, - nLocalHostNonce, strSubVersion, nBestHeight, true); + nLocalHostNonce, strSubVersion, nBestHeight, !GetBoolArg("-blocksonly", false)); } -- cgit v1.2.3 From 420fa8143a81f60fea79ee05df553e89378f1054 Mon Sep 17 00:00:00 2001 From: Patick Strateman Date: Sat, 14 Nov 2015 04:44:59 -0800 Subject: Do not process tx inv's in blocksonly mode --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index 5208fbb031..b35a032733 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4218,7 +4218,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, bool fAlreadyHave = AlreadyHave(inv); LogPrint("net", "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom->id); - if (!fAlreadyHave && !fImporting && !fReindex && inv.type != MSG_BLOCK) + if (!fAlreadyHave && !fImporting && !fReindex && inv.type != MSG_BLOCK && !GetBoolArg("-blocksonly", false)) pfrom->AskFor(inv); if (inv.type == MSG_BLOCK) { -- cgit v1.2.3 From 3a964973fe9335f31c418b00e762ea04c3d3f088 Mon Sep 17 00:00:00 2001 From: Patick Strateman Date: Sat, 14 Nov 2015 04:46:23 -0800 Subject: Add whitelistalwaysrelay option --- src/init.cpp | 10 ++++++++++ src/main.cpp | 2 +- src/main.h | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/init.cpp b/src/init.cpp index f2001236a2..8e5c318352 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -816,6 +816,16 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) } #endif } + + // disable walletbroadcast in blocksonly mode + if (GetBoolArg("-blocksonly", false)) { + if (SoftSetBoolArg("-whitelistalwaysrelay", false)) + LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting -whitelistalwaysrelay=0\n", __func__); +#ifdef ENABLE_WALLET + if (SoftSetBoolArg("-walletbroadcast", false)) + LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting -walletbroadcast=0\n", __func__); +#endif + } // Make sure enough file descriptors are available int nBind = std::max((int)mapArgs.count("-bind") + (int)mapArgs.count("-whitebind"), 1); diff --git a/src/main.cpp b/src/main.cpp index b35a032733..9842acb4b3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4465,7 +4465,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, assert(recentRejects); recentRejects->insert(tx.GetHash()); - if (pfrom->fWhitelisted) { + if (pfrom->fWhitelisted && GetBoolArg("-whitelistalwaysrelay", DEFAULT_WHITELISTALWAYSRELAY)) { // Always relay transactions received from whitelisted peers, even // if they were rejected from the mempool, allowing the node to // function as a gateway for nodes hidden behind it. diff --git a/src/main.h b/src/main.h index 5fb5534860..c304b311e4 100644 --- a/src/main.h +++ b/src/main.h @@ -41,6 +41,8 @@ struct CNodeStateStats; /** Default for accepting alerts from the P2P network. */ static const bool DEFAULT_ALERTS = true; +/** Default for DEFAULT_WHITELISTALWAYSRELAY. */ +static const bool DEFAULT_WHITELISTALWAYSRELAY = true; /** Default for -minrelaytxfee, minimum relay fee for transactions */ static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000; /** Default for -maxorphantx, maximum number of orphan transactions kept in memory */ -- cgit v1.2.3 From 762b13b4d8cce325ed10de733a502fa3aadeadee Mon Sep 17 00:00:00 2001 From: Patick Strateman Date: Sat, 14 Nov 2015 04:47:53 -0800 Subject: Add help text for blocksonly and whitelistalwaysrelay --- src/init.cpp | 3 +++ src/net.h | 2 ++ 2 files changed, 5 insertions(+) (limited to 'src') diff --git a/src/init.cpp b/src/init.cpp index 8e5c318352..b228319564 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -310,6 +310,8 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-alerts", strprintf(_("Receive and display P2P network alerts (default: %u)"), DEFAULT_ALERTS)); strUsage += HelpMessageOpt("-alertnotify=", _("Execute command when a relevant alert is received or we see a really long fork (%s in cmd is replaced by message)")); strUsage += HelpMessageOpt("-blocknotify=", _("Execute command when the best block changes (%s in cmd is replaced by block hash)")); + if (showDebug) + strUsage += HelpMessageOpt("-blocksonly", strprintf(_("Whether to operate in a blocks only mode (default: %u)"), DEFAULT_BLOCKSONLY)); strUsage += HelpMessageOpt("-checkblocks=", strprintf(_("How many blocks to check at startup (default: %u, 0 = all)"), DEFAULT_CHECKBLOCKS)); strUsage += HelpMessageOpt("-checklevel=", strprintf(_("How thorough the block verification of -checkblocks is (0-4, default: %u)"), DEFAULT_CHECKLEVEL)); strUsage += HelpMessageOpt("-conf=", strprintf(_("Specify configuration file (default: %s)"), "bitcoin.conf")); @@ -375,6 +377,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-whitebind=", _("Bind to given address and whitelist peers connecting to it. Use [host]:port notation for IPv6")); strUsage += HelpMessageOpt("-whitelist=", _("Whitelist peers connecting from the given netmask or IP address. Can be specified multiple times.") + " " + _("Whitelisted peers cannot be DoS banned and their transactions are always relayed, even if they are already in the mempool, useful e.g. for a gateway")); + strUsage += HelpMessageOpt("-whitelistalwaysrelay", _("Always relay transactions received from whitelisted peers.")); strUsage += HelpMessageOpt("-maxuploadtarget=", strprintf(_("Tries to keep outbound traffic under the given target (in MiB per 24h), 0 = no limit (default: %d)"), DEFAULT_MAX_UPLOAD_TARGET)); #ifdef ENABLE_WALLET diff --git a/src/net.h b/src/net.h index cd2d225d73..a133818b4f 100644 --- a/src/net.h +++ b/src/net.h @@ -62,6 +62,8 @@ static const size_t MAPASKFOR_MAX_SZ = MAX_INV_SZ; static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS = 125; /** The default for -maxuploadtarget. 0 = Unlimited */ static const uint64_t DEFAULT_MAX_UPLOAD_TARGET = 0; +/** Default for blocks only*/ +static const bool DEFAULT_BLOCKSONLY = false; unsigned int ReceiveFloodSize(); unsigned int SendBufferSize(); -- cgit v1.2.3 From 71a2683f4b526b17adf317733b0aa18ffacecfdc Mon Sep 17 00:00:00 2001 From: Patick Strateman Date: Sat, 14 Nov 2015 05:10:59 -0800 Subject: Use DEFAULT_BLOCKSONLY and DEFAULT_WHITELISTALWAYSRELAY constants --- src/init.cpp | 2 +- src/main.cpp | 2 +- src/net.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/init.cpp b/src/init.cpp index b228319564..666fa87318 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -821,7 +821,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) } // disable walletbroadcast in blocksonly mode - if (GetBoolArg("-blocksonly", false)) { + if (GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)) { if (SoftSetBoolArg("-whitelistalwaysrelay", false)) LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting -whitelistalwaysrelay=0\n", __func__); #ifdef ENABLE_WALLET diff --git a/src/main.cpp b/src/main.cpp index 9842acb4b3..fb529eb5b6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4218,7 +4218,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, bool fAlreadyHave = AlreadyHave(inv); LogPrint("net", "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom->id); - if (!fAlreadyHave && !fImporting && !fReindex && inv.type != MSG_BLOCK && !GetBoolArg("-blocksonly", false)) + if (!fAlreadyHave && !fImporting && !fReindex && inv.type != MSG_BLOCK && !GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)) pfrom->AskFor(inv); if (inv.type == MSG_BLOCK) { diff --git a/src/net.cpp b/src/net.cpp index a62e875f83..000eefc858 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -460,7 +460,7 @@ void CNode::PushVersion() else LogPrint("net", "send version message: version %d, blocks=%d, us=%s, peer=%d\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString(), id); PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe, - nLocalHostNonce, strSubVersion, nBestHeight, !GetBoolArg("-blocksonly", false)); + nLocalHostNonce, strSubVersion, nBestHeight, !GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)); } -- cgit v1.2.3 From 59441a044570c4298f19b6bd873c8769e3ec0ba0 Mon Sep 17 00:00:00 2001 From: Patick Strateman Date: Sat, 14 Nov 2015 05:12:05 -0800 Subject: Display DEFAULT_WHITELISTALWAYSRELAY in help text --- src/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/init.cpp b/src/init.cpp index 666fa87318..3a4312ec0f 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -377,7 +377,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-whitebind=", _("Bind to given address and whitelist peers connecting to it. Use [host]:port notation for IPv6")); strUsage += HelpMessageOpt("-whitelist=", _("Whitelist peers connecting from the given netmask or IP address. Can be specified multiple times.") + " " + _("Whitelisted peers cannot be DoS banned and their transactions are always relayed, even if they are already in the mempool, useful e.g. for a gateway")); - strUsage += HelpMessageOpt("-whitelistalwaysrelay", _("Always relay transactions received from whitelisted peers.")); + strUsage += HelpMessageOpt("-whitelistalwaysrelay", strprintf(_("Always relay transactions received from whitelisted peers (default: %d)"), DEFAULT_WHITELISTALWAYSRELAY)); strUsage += HelpMessageOpt("-maxuploadtarget=", strprintf(_("Tries to keep outbound traffic under the given target (in MiB per 24h), 0 = no limit (default: %d)"), DEFAULT_MAX_UPLOAD_TARGET)); #ifdef ENABLE_WALLET -- cgit v1.2.3 From 6a4982fb836e51ec01501f019ca8bce2b80e1267 Mon Sep 17 00:00:00 2001 From: Patick Strateman Date: Sat, 14 Nov 2015 05:12:31 -0800 Subject: Fix fRelayTxs comment --- src/net.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/net.h b/src/net.h index a133818b4f..ebdbe77565 100644 --- a/src/net.h +++ b/src/net.h @@ -344,7 +344,7 @@ public: // We use fRelayTxes for two purposes - // a) it allows us to not relay tx invs before receiving the peer's version message // b) the peer may tell us in its version message that we should not relay tx invs - // until it has initialized its bloom filter. + // unless it loads a bloom filter. bool fRelayTxes; CSemaphoreGrant grantOutbound; CCriticalSection cs_filter; -- cgit v1.2.3 From bbf49da408a609a4ca9ed4028fa3071dc6e77233 Mon Sep 17 00:00:00 2001 From: Patick Strateman Date: Sat, 14 Nov 2015 05:14:01 -0800 Subject: Fix comment for blocksonly parameter interactions --- src/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/init.cpp b/src/init.cpp index 3a4312ec0f..36c1dfbe86 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -820,7 +820,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) #endif } - // disable walletbroadcast in blocksonly mode + // disable walletbroadcast and whitelistalwaysrelay in blocksonly mode if (GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)) { if (SoftSetBoolArg("-whitelistalwaysrelay", false)) LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting -whitelistalwaysrelay=0\n", __func__); -- cgit v1.2.3