Skip to content

Commit b632145

Browse files
committed
Merge pull request #6993
bbf49da Fix comment for blocksonly parameter interactions (Patick Strateman) 6a4982f Fix fRelayTxs comment (Patick Strateman) 59441a0 Display DEFAULT_WHITELISTALWAYSRELAY in help text (Patick Strateman) 71a2683 Use DEFAULT_BLOCKSONLY and DEFAULT_WHITELISTALWAYSRELAY constants (Patick Strateman) 762b13b Add help text for blocksonly and whitelistalwaysrelay (Patick Strateman) 3a96497 Add whitelistalwaysrelay option (Patick Strateman) 420fa81 Do not process tx inv's in blocksonly mode (Patick Strateman) 4044f07 Add blocksonly mode (Patick Strateman)
2 parents 9ffc687 + bbf49da commit b632145

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

src/init.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ std::string HelpMessage(HelpMessageMode mode)
310310
strUsage += HelpMessageOpt("-alerts", strprintf(_("Receive and display P2P network alerts (default: %u)"), DEFAULT_ALERTS));
311311
strUsage += HelpMessageOpt("-alertnotify=<cmd>", _("Execute command when a relevant alert is received or we see a really long fork (%s in cmd is replaced by message)"));
312312
strUsage += HelpMessageOpt("-blocknotify=<cmd>", _("Execute command when the best block changes (%s in cmd is replaced by block hash)"));
313+
if (showDebug)
314+
strUsage += HelpMessageOpt("-blocksonly", strprintf(_("Whether to operate in a blocks only mode (default: %u)"), DEFAULT_BLOCKSONLY));
313315
strUsage += HelpMessageOpt("-checkblocks=<n>", strprintf(_("How many blocks to check at startup (default: %u, 0 = all)"), DEFAULT_CHECKBLOCKS));
314316
strUsage += HelpMessageOpt("-checklevel=<n>", strprintf(_("How thorough the block verification of -checkblocks is (0-4, default: %u)"), DEFAULT_CHECKLEVEL));
315317
strUsage += HelpMessageOpt("-conf=<file>", strprintf(_("Specify configuration file (default: %s)"), "bitcoin.conf"));
@@ -375,6 +377,7 @@ std::string HelpMessage(HelpMessageMode mode)
375377
strUsage += HelpMessageOpt("-whitebind=<addr>", _("Bind to given address and whitelist peers connecting to it. Use [host]:port notation for IPv6"));
376378
strUsage += HelpMessageOpt("-whitelist=<netmask>", _("Whitelist peers connecting from the given netmask or IP address. Can be specified multiple times.") +
377379
" " + _("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"));
380+
strUsage += HelpMessageOpt("-whitelistalwaysrelay", strprintf(_("Always relay transactions received from whitelisted peers (default: %d)"), DEFAULT_WHITELISTALWAYSRELAY));
378381
strUsage += HelpMessageOpt("-maxuploadtarget=<n>", strprintf(_("Tries to keep outbound traffic under the given target (in MiB per 24h), 0 = no limit (default: %d)"), DEFAULT_MAX_UPLOAD_TARGET));
379382

380383
#ifdef ENABLE_WALLET
@@ -816,6 +819,16 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
816819
}
817820
#endif
818821
}
822+
823+
// disable walletbroadcast and whitelistalwaysrelay in blocksonly mode
824+
if (GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)) {
825+
if (SoftSetBoolArg("-whitelistalwaysrelay", false))
826+
LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting -whitelistalwaysrelay=0\n", __func__);
827+
#ifdef ENABLE_WALLET
828+
if (SoftSetBoolArg("-walletbroadcast", false))
829+
LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting -walletbroadcast=0\n", __func__);
830+
#endif
831+
}
819832

820833
// Make sure enough file descriptors are available
821834
int nBind = std::max((int)mapArgs.count("-bind") + (int)mapArgs.count("-whitebind"), 1);

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4219,7 +4219,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
42194219
bool fAlreadyHave = AlreadyHave(inv);
42204220
LogPrint("net", "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom->id);
42214221

4222-
if (!fAlreadyHave && !fImporting && !fReindex && inv.type != MSG_BLOCK)
4222+
if (!fAlreadyHave && !fImporting && !fReindex && inv.type != MSG_BLOCK && !GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY))
42234223
pfrom->AskFor(inv);
42244224

42254225
if (inv.type == MSG_BLOCK) {
@@ -4466,7 +4466,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
44664466
assert(recentRejects);
44674467
recentRejects->insert(tx.GetHash());
44684468

4469-
if (pfrom->fWhitelisted) {
4469+
if (pfrom->fWhitelisted && GetBoolArg("-whitelistalwaysrelay", DEFAULT_WHITELISTALWAYSRELAY)) {
44704470
// Always relay transactions received from whitelisted peers, even
44714471
// if they were rejected from the mempool, allowing the node to
44724472
// function as a gateway for nodes hidden behind it.

src/main.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ struct CNodeStateStats;
4141

4242
/** Default for accepting alerts from the P2P network. */
4343
static const bool DEFAULT_ALERTS = true;
44+
/** Default for DEFAULT_WHITELISTALWAYSRELAY. */
45+
static const bool DEFAULT_WHITELISTALWAYSRELAY = true;
4446
/** Default for -minrelaytxfee, minimum relay fee for transactions */
4547
static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000;
4648
/** Default for -maxorphantx, maximum number of orphan transactions kept in memory */

src/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ void CNode::PushVersion()
460460
else
461461
LogPrint("net", "send version message: version %d, blocks=%d, us=%s, peer=%d\n", PROTOCOL_VERSION, nBestHeight, addrMe.ToString(), id);
462462
PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe,
463-
nLocalHostNonce, strSubVersion, nBestHeight, true);
463+
nLocalHostNonce, strSubVersion, nBestHeight, !GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY));
464464
}
465465

466466

src/net.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ static const size_t MAPASKFOR_MAX_SZ = MAX_INV_SZ;
6262
static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS = 125;
6363
/** The default for -maxuploadtarget. 0 = Unlimited */
6464
static const uint64_t DEFAULT_MAX_UPLOAD_TARGET = 0;
65+
/** Default for blocks only*/
66+
static const bool DEFAULT_BLOCKSONLY = false;
6567

6668
unsigned int ReceiveFloodSize();
6769
unsigned int SendBufferSize();
@@ -342,7 +344,7 @@ class CNode
342344
// We use fRelayTxes for two purposes -
343345
// a) it allows us to not relay tx invs before receiving the peer's version message
344346
// b) the peer may tell us in its version message that we should not relay tx invs
345-
// until it has initialized its bloom filter.
347+
// unless it loads a bloom filter.
346348
bool fRelayTxes;
347349
CSemaphoreGrant grantOutbound;
348350
CCriticalSection cs_filter;

0 commit comments

Comments
 (0)