Skip to content

Commit 86755bc

Browse files
gmaxwelllaanwj
authored andcommitted
Add whitelistforcerelay to control forced relaying. [#7099 redux]
- 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. - Blacklist -whitelistalwaysrelay; replaced by -whitelistrelay. Github-Pull: #7439 Rebased-From: 325c725 89d113e
1 parent e2d9a58 commit 86755bc

3 files changed

Lines changed: 23 additions & 11 deletions

File tree

src/init.cpp

Lines changed: 14 additions & 4 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
@@ -749,15 +750,21 @@ void InitParameterInteraction()
749750
LogPrintf("%s: parameter interaction: -zapwallettxes=<mode> -> setting -rescan=1\n", __func__);
750751
}
751752

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

763770
void InitLogging()
@@ -884,6 +891,9 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
884891
if (GetBoolArg("-benchmark", false))
885892
InitWarning(_("Unsupported argument -benchmark ignored, use -debug=bench."));
886893

894+
if (GetBoolArg("-whitelistalwaysrelay", false))
895+
InitWarning(_("Unsupported argument -whitelistalwaysrelay ignored, use -whitelistrelay and/or -whitelistforcerelay."));
896+
887897
// Checkmempool and checkblockindex default to true in regtest mode
888898
int ratio = std::min<int>(std::max<int>(GetArg("-checkmempool", chainparams.DefaultConsistencyChecks() ? 1 : 0), 0), 1000000);
889899
if (ratio != 0) {

src/main.cpp

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

44984498
bool fBlocksOnly = GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY);
44994499

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

45044504
LOCK(cs_main);
@@ -4677,8 +4677,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
46774677
else if (strCommand == NetMsgType::TX)
46784678
{
46794679
// Stop processing the transaction early if
4680-
// We are in blocks only mode and peer is either not whitelisted or whitelistalwaysrelay is off
4681-
if (GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY) && (!pfrom->fWhitelisted || !GetBoolArg("-whitelistalwaysrelay", DEFAULT_WHITELISTALWAYSRELAY)))
4680+
// We are in blocks only mode and peer is either not whitelisted or whitelistrelay is off
4681+
if (GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY) && (!pfrom->fWhitelisted || !GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY)))
46824682
{
46834683
LogPrint("net", "transaction sent in violation of protocol peer=%d\n", pfrom->id);
46844684
return true;
@@ -4778,7 +4778,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
47784778
assert(recentRejects);
47794779
recentRejects->insert(tx.GetHash());
47804780

4781-
if (pfrom->fWhitelisted && GetBoolArg("-whitelistalwaysrelay", DEFAULT_WHITELISTALWAYSRELAY)) {
4781+
if (pfrom->fWhitelisted && GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY)) {
47824782
// Always relay transactions received from whitelisted peers, even
47834783
// if they were already in the mempool or rejected from it due
47844784
// 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)