Skip to content

Commit d541fa3

Browse files
committed
Replace the use of fWhitelisted by permission checks
1 parent ecd5cf7 commit d541fa3

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

src/net.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ void CNode::copyStats(CNodeStats &stats)
526526
X(mapRecvBytesPerMsgCmd);
527527
X(nRecvBytes);
528528
}
529-
X(fWhitelisted);
529+
X(m_legacyWhitelisted);
530530
X(m_permissionFlags);
531531
{
532532
LOCK(cs_feeFilter);
@@ -812,7 +812,7 @@ bool CConnman::AttemptToEvictConnection()
812812
LOCK(cs_vNodes);
813813

814814
for (const CNode* node : vNodes) {
815-
if (node->fWhitelisted)
815+
if (node->HasPermission(PF_NOBAN))
816816
continue;
817817
if (!node->fInbound)
818818
continue;
@@ -982,7 +982,7 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
982982
pnode->AddRef();
983983
pnode->m_permissionFlags = permissionFlags;
984984
// If this flag is present, the user probably expect that RPC and QT report it as whitelisted (backward compatibility)
985-
pnode->fWhitelisted = legacyWhitelisted;
985+
pnode->m_legacyWhitelisted = legacyWhitelisted;
986986
pnode->m_prefer_evict = bannedlevel > 0;
987987
m_msgproc->InitializeNode(pnode);
988988

src/net.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ class CNodeStats
559559
uint64_t nRecvBytes;
560560
mapMsgCmdSize mapRecvBytesPerMsgCmd;
561561
NetPermissionFlags m_permissionFlags;
562-
bool fWhitelisted;
562+
bool m_legacyWhitelisted;
563563
double dPingTime;
564564
double dPingWait;
565565
double dMinPing;
@@ -664,7 +664,8 @@ class CNode
664664
bool HasPermission(NetPermissionFlags permission) const {
665665
return NetPermissions::HasFlag(m_permissionFlags, permission);
666666
}
667-
bool fWhitelisted{false}; // This peer can bypass DoS banning.
667+
// This boolean is unusued in actual processing, only present for backward compatibility at RPC/QT level
668+
bool m_legacyWhitelisted{false};
668669
bool fFeeler{false}; // If true this node is being used as a short lived feeler.
669670
bool fOneShot{false};
670671
bool m_manual_connection{false};

src/net_processing.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ static void UpdatePreferredDownload(CNode* node, CNodeState* state) EXCLUSIVE_LO
408408
nPreferredDownload -= state->fPreferredDownload;
409409

410410
// Whether this node should be marked as a preferred download node.
411-
state->fPreferredDownload = (!node->fInbound || node->fWhitelisted) && !node->fOneShot && !node->fClient;
411+
state->fPreferredDownload = (!node->fInbound || node->HasPermission(PF_NOBAN)) && !node->fOneShot && !node->fClient;
412412

413413
nPreferredDownload += state->fPreferredDownload;
414414
}
@@ -1398,7 +1398,7 @@ void static ProcessGetBlockData(CNode* pfrom, const CChainParams& chainparams, c
13981398
const CNetMsgMaker msgMaker(pfrom->GetSendVersion());
13991399
// disconnect node in case we have reached the outbound limit for serving historical blocks
14001400
// never disconnect whitelisted nodes
1401-
if (send && connman->OutboundTargetReached(true) && ( ((pindexBestHeader != nullptr) && (pindexBestHeader->GetBlockTime() - pindex->GetBlockTime() > HISTORICAL_BLOCK_AGE)) || inv.type == MSG_FILTERED_BLOCK) && !pfrom->fWhitelisted)
1401+
if (send && connman->OutboundTargetReached(true) && ( ((pindexBestHeader != nullptr) && (pindexBestHeader->GetBlockTime() - pindex->GetBlockTime() > HISTORICAL_BLOCK_AGE)) || inv.type == MSG_FILTERED_BLOCK) && !pfrom->HasPermission(PF_NOBAN))
14021402
{
14031403
LogPrint(BCLog::NET, "historical block serving limit reached, disconnect peer=%d\n", pfrom->GetId());
14041404

@@ -1407,7 +1407,7 @@ void static ProcessGetBlockData(CNode* pfrom, const CChainParams& chainparams, c
14071407
send = false;
14081408
}
14091409
// Avoid leaking prune-height by never sending blocks below the NODE_NETWORK_LIMITED threshold
1410-
if (send && !pfrom->fWhitelisted && (
1410+
if (send && !pfrom->HasPermission(PF_NOBAN) && (
14111411
(((pfrom->GetLocalServices() & NODE_NETWORK_LIMITED) == NODE_NETWORK_LIMITED) && ((pfrom->GetLocalServices() & NODE_NETWORK) != NODE_NETWORK) && (::ChainActive().Tip()->nHeight - pindex->nHeight > (int)NODE_NETWORK_LIMITED_MIN_BLOCKS + 2 /* add two blocks buffer extension for possible races */) )
14121412
)) {
14131413
LogPrint(BCLog::NET, "Ignore block request below NODE_NETWORK_LIMITED threshold from peer=%d\n", pfrom->GetId());
@@ -2217,7 +2217,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
22172217
bool fBlocksOnly = !g_relay_txes;
22182218

22192219
// Allow whitelisted peers to send data other than blocks in blocks only mode if whitelistrelay is true
2220-
if (pfrom->fWhitelisted && gArgs.GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY))
2220+
if (pfrom->HasPermission(PF_RELAY))
22212221
fBlocksOnly = false;
22222222

22232223
LOCK(cs_main);
@@ -2412,7 +2412,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
24122412
}
24132413

24142414
LOCK(cs_main);
2415-
if (::ChainstateActive().IsInitialBlockDownload() && !pfrom->fWhitelisted) {
2415+
if (::ChainstateActive().IsInitialBlockDownload() && !pfrom->HasPermission(PF_NOBAN)) {
24162416
LogPrint(BCLog::NET, "Ignoring getheaders from peer=%d because node is in initial block download\n", pfrom->GetId());
24172417
return true;
24182418
}
@@ -2470,7 +2470,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
24702470
if (strCommand == NetMsgType::TX) {
24712471
// Stop processing the transaction early if
24722472
// We are in blocks only mode and peer is either not whitelisted or whitelistrelay is off
2473-
if (!g_relay_txes && (!pfrom->fWhitelisted || !gArgs.GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY)))
2473+
if (!g_relay_txes && !pfrom->HasPermission(PF_RELAY))
24742474
{
24752475
LogPrint(BCLog::NET, "transaction sent in violation of protocol peer=%d\n", pfrom->GetId());
24762476
return true;
@@ -2565,7 +2565,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
25652565
AddToCompactExtraTransactions(ptx);
25662566
}
25672567

2568-
if (pfrom->fWhitelisted && gArgs.GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY)) {
2568+
if (pfrom->HasPermission(PF_FORCERELAY)) {
25692569
// Always relay transactions received from whitelisted peers, even
25702570
// if they were already in the mempool or rejected from it due
25712571
// to policy, allowing the node to function as a gateway for
@@ -3010,7 +3010,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
30103010
}
30113011

30123012
if (strCommand == NetMsgType::MEMPOOL) {
3013-
if (!(pfrom->GetLocalServices() & NODE_BLOOM) && !pfrom->fWhitelisted)
3013+
if (!(pfrom->GetLocalServices() & NODE_BLOOM) && !pfrom->HasPermission(PF_MEMPOOL))
30143014
{
30153015
if (!pfrom->HasPermission(PF_NOBAN))
30163016
{
@@ -3020,7 +3020,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
30203020
return true;
30213021
}
30223022

3023-
if (connman->OutboundTargetReached(false) && !pfrom->fWhitelisted)
3023+
if (connman->OutboundTargetReached(false) && !pfrom->HasPermission(PF_MEMPOOL))
30243024
{
30253025
if (!pfrom->HasPermission(PF_NOBAN))
30263026
{
@@ -3222,7 +3222,7 @@ bool PeerLogicValidation::SendRejectsAndCheckIfBanned(CNode* pnode, bool enable_
32223222

32233223
if (state.fShouldBan) {
32243224
state.fShouldBan = false;
3225-
if (pnode->fWhitelisted)
3225+
if (pnode->HasPermission(PF_NOBAN))
32263226
LogPrintf("Warning: not punishing whitelisted peer %s!\n", pnode->addr.ToString());
32273227
else if (pnode->m_manual_connection)
32283228
LogPrintf("Warning: not punishing manually-connected peer %s!\n", pnode->addr.ToString());
@@ -3792,7 +3792,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
37923792
pto->vInventoryBlockToSend.clear();
37933793

37943794
// Check whether periodic sends should happen
3795-
bool fSendTrickle = pto->fWhitelisted;
3795+
bool fSendTrickle = pto->HasPermission(PF_NOBAN);
37963796
if (pto->nNextInvSend < nNow) {
37973797
fSendTrickle = true;
37983798
if (pto->fInbound) {
@@ -3948,7 +3948,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
39483948
// Note: If all our peers are inbound, then we won't
39493949
// disconnect our sync peer for stalling; we have bigger
39503950
// problems if we can't get any outbound peers.
3951-
if (!pto->fWhitelisted) {
3951+
if (!pto->HasPermission(PF_NOBAN)) {
39523952
LogPrintf("Timeout downloading headers from peer=%d, disconnecting\n", pto->GetId());
39533953
pto->fDisconnect = true;
39543954
return true;
@@ -4066,7 +4066,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
40664066
//
40674067
// We don't want white listed peers to filter txs to us if we have -whitelistforcerelay
40684068
if (pto->nVersion >= FEEFILTER_VERSION && gArgs.GetBoolArg("-feefilter", DEFAULT_FEEFILTER) &&
4069-
!(pto->fWhitelisted && gArgs.GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY))) {
4069+
!pto->HasPermission(PF_FORCERELAY)) {
40704070
CAmount currentFilter = mempool.GetMinFee(gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFeePerK();
40714071
int64_t timeNow = GetTimeMicros();
40724072
if (timeNow > pto->nextSendTimeFeeFilter) {

src/qt/rpcconsole.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ void RPCConsole::updateNodeDetail(const CNodeCombinedStats *stats)
11201120
ui->peerSubversion->setText(QString::fromStdString(stats->nodeStats.cleanSubVer));
11211121
ui->peerDirection->setText(stats->nodeStats.fInbound ? tr("Inbound") : tr("Outbound"));
11221122
ui->peerHeight->setText(QString("%1").arg(QString::number(stats->nodeStats.nStartingHeight)));
1123-
ui->peerWhitelisted->setText(stats->nodeStats.fWhitelisted ? tr("Yes") : tr("No"));
1123+
ui->peerWhitelisted->setText(stats->nodeStats.m_legacyWhitelisted ? tr("Yes") : tr("No"));
11241124

11251125
// This check fails for example if the lock was busy and
11261126
// nodeStateStats couldn't be fetched.

src/rpc/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static UniValue getpeerinfo(const JSONRPCRequest& request)
178178
}
179179
obj.pushKV("inflight", heights);
180180
}
181-
obj.pushKV("whitelisted", stats.fWhitelisted);
181+
obj.pushKV("whitelisted", stats.m_legacyWhitelisted);
182182
UniValue permissions(UniValue::VARR);
183183
for (const auto& permission : NetPermissions::ToStrings(stats.m_permissionFlags)) {
184184
permissions.push_back(permission);

0 commit comments

Comments
 (0)