Skip to content

Commit 325c725

Browse files
committed
Add whitelistforcerelay to control forced relaying.
Also renames whitelistalwaysrelay. Nodes relay all transactions from whitelisted peers, this gets in the way of some useful reasons for whitelisting peers-- for example, bypassing bandwidth limitations. The purpose of this forced relaying is for specialized gateway applications where a node is being used as a P2P connection filter and multiplexer, but where you don't want it getting in the way of (re-)broadcast. This change makes it configurable with whitelistforcerelay.
1 parent 326ffed commit 325c725

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

src/init.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@ std::string HelpMessage(HelpMessageMode mode)
388388
strUsage += HelpMessageOpt("-whitebind=<addr>", _("Bind to given address and whitelist peers connecting to it. Use [host]:port notation for IPv6"));
389389
strUsage += HelpMessageOpt("-whitelist=<netmask>", _("Whitelist peers connecting from the given netmask or IP address. Can be specified multiple times.") +
390390
" " + _("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"));
391-
strUsage += HelpMessageOpt("-whitelistalwaysrelay", strprintf(_("Always relay transactions received from whitelisted peers (default: %d)"), DEFAULT_WHITELISTALWAYSRELAY));
391+
strUsage += HelpMessageOpt("-whitelistrelay", strprintf(_("Accept relayed transactions received from whitelisted peers even when not relaying transactions (default: %d)"), DEFAULT_WHITELISTRELAY));
392+
strUsage += HelpMessageOpt("-whitelistforcerelay", strprintf(_("Force relay of transactions from whitelisted peers even they violate local relay policy (default: %d)"), DEFAULT_WHITELISTFORCERELAY));
392393
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));
393394

394395
#ifdef ENABLE_WALLET
@@ -752,13 +753,19 @@ void InitParameterInteraction()
752753

753754
// disable walletbroadcast and whitelistalwaysrelay in blocksonly mode
754755
if (GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)) {
755-
if (SoftSetBoolArg("-whitelistalwaysrelay", false))
756-
LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting -whitelistalwaysrelay=0\n", __func__);
756+
if (SoftSetBoolArg("-whitelistrelay", false))
757+
LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting -whitelistrelay=0\n", __func__);
757758
#ifdef ENABLE_WALLET
758759
if (SoftSetBoolArg("-walletbroadcast", false))
759760
LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting -walletbroadcast=0\n", __func__);
760761
#endif
761762
}
763+
764+
// Forcing relay from whitelisted hosts implies we will accept relays from them in the first place.
765+
if (GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY)) {
766+
if (SoftSetBoolArg("-whitelistrelay", true))
767+
LogPrintf("%s: parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1\n", __func__);
768+
}
762769
}
763770

764771
static std::string ResolveErrMsg(const char * const optname, const std::string& strBind)

src/main.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4495,8 +4495,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
44954495

44964496
bool fBlocksOnly = GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY);
44974497

4498-
// Allow whitelisted peers to send data other than blocks in blocks only mode if whitelistalwaysrelay is true
4499-
if (pfrom->fWhitelisted && GetBoolArg("-whitelistalwaysrelay", DEFAULT_WHITELISTALWAYSRELAY))
4498+
// Allow whitelisted peers to send data other than blocks in blocks only mode if whitelistrelay is true
4499+
if (pfrom->fWhitelisted && GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY))
45004500
fBlocksOnly = false;
45014501

45024502
LOCK(cs_main);
@@ -4675,8 +4675,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
46754675
else if (strCommand == NetMsgType::TX)
46764676
{
46774677
// Stop processing the transaction early if
4678-
// We are in blocks only mode and peer is either not whitelisted or whitelistalwaysrelay is off
4679-
if (GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY) && (!pfrom->fWhitelisted || !GetBoolArg("-whitelistalwaysrelay", DEFAULT_WHITELISTALWAYSRELAY)))
4678+
// We are in blocks only mode and peer is either not whitelisted or whitelistrelay is off
4679+
if (GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY) && (!pfrom->fWhitelisted || !GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY)))
46804680
{
46814681
LogPrint("net", "transaction sent in violation of protocol peer=%d\n", pfrom->id);
46824682
return true;
@@ -4776,7 +4776,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
47764776
assert(recentRejects);
47774777
recentRejects->insert(tx.GetHash());
47784778

4779-
if (pfrom->fWhitelisted && GetBoolArg("-whitelistalwaysrelay", DEFAULT_WHITELISTALWAYSRELAY)) {
4779+
if (pfrom->fWhitelisted && GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY)) {
47804780
// Always relay transactions received from whitelisted peers, even
47814781
// if they were already in the mempool or rejected from it due
47824782
// to policy, allowing the node to function as a gateway for

src/main.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ struct CNodeStateStats;
4242

4343
/** Default for accepting alerts from the P2P network. */
4444
static const bool DEFAULT_ALERTS = true;
45-
/** Default for DEFAULT_WHITELISTALWAYSRELAY. */
46-
static const bool DEFAULT_WHITELISTALWAYSRELAY = true;
45+
/** Default for DEFAULT_WHITELISTRELAY. */
46+
static const bool DEFAULT_WHITELISTRELAY = true;
47+
/** Default for DEFAULT_WHITELISTFORCERELAY. */
48+
static const bool DEFAULT_WHITELISTFORCERELAY = true;
4749
/** Default for -minrelaytxfee, minimum relay fee for transactions */
4850
static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000;
4951
/** Default for -maxorphantx, maximum number of orphan transactions kept in memory */

0 commit comments

Comments
 (0)