mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-18 13:17:55 +02:00
Replace the use of fWhitelisted by permission checks
This commit is contained in:
parent
ecd5cf7ea4
commit
d541fa3918
5 changed files with 21 additions and 20 deletions
|
|
@ -526,7 +526,7 @@ void CNode::copyStats(CNodeStats &stats)
|
||||||
X(mapRecvBytesPerMsgCmd);
|
X(mapRecvBytesPerMsgCmd);
|
||||||
X(nRecvBytes);
|
X(nRecvBytes);
|
||||||
}
|
}
|
||||||
X(fWhitelisted);
|
X(m_legacyWhitelisted);
|
||||||
X(m_permissionFlags);
|
X(m_permissionFlags);
|
||||||
{
|
{
|
||||||
LOCK(cs_feeFilter);
|
LOCK(cs_feeFilter);
|
||||||
|
|
@ -812,7 +812,7 @@ bool CConnman::AttemptToEvictConnection()
|
||||||
LOCK(cs_vNodes);
|
LOCK(cs_vNodes);
|
||||||
|
|
||||||
for (const CNode* node : vNodes) {
|
for (const CNode* node : vNodes) {
|
||||||
if (node->fWhitelisted)
|
if (node->HasPermission(PF_NOBAN))
|
||||||
continue;
|
continue;
|
||||||
if (!node->fInbound)
|
if (!node->fInbound)
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -982,7 +982,7 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
|
||||||
pnode->AddRef();
|
pnode->AddRef();
|
||||||
pnode->m_permissionFlags = permissionFlags;
|
pnode->m_permissionFlags = permissionFlags;
|
||||||
// If this flag is present, the user probably expect that RPC and QT report it as whitelisted (backward compatibility)
|
// If this flag is present, the user probably expect that RPC and QT report it as whitelisted (backward compatibility)
|
||||||
pnode->fWhitelisted = legacyWhitelisted;
|
pnode->m_legacyWhitelisted = legacyWhitelisted;
|
||||||
pnode->m_prefer_evict = bannedlevel > 0;
|
pnode->m_prefer_evict = bannedlevel > 0;
|
||||||
m_msgproc->InitializeNode(pnode);
|
m_msgproc->InitializeNode(pnode);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -559,7 +559,7 @@ public:
|
||||||
uint64_t nRecvBytes;
|
uint64_t nRecvBytes;
|
||||||
mapMsgCmdSize mapRecvBytesPerMsgCmd;
|
mapMsgCmdSize mapRecvBytesPerMsgCmd;
|
||||||
NetPermissionFlags m_permissionFlags;
|
NetPermissionFlags m_permissionFlags;
|
||||||
bool fWhitelisted;
|
bool m_legacyWhitelisted;
|
||||||
double dPingTime;
|
double dPingTime;
|
||||||
double dPingWait;
|
double dPingWait;
|
||||||
double dMinPing;
|
double dMinPing;
|
||||||
|
|
@ -664,7 +664,8 @@ public:
|
||||||
bool HasPermission(NetPermissionFlags permission) const {
|
bool HasPermission(NetPermissionFlags permission) const {
|
||||||
return NetPermissions::HasFlag(m_permissionFlags, permission);
|
return NetPermissions::HasFlag(m_permissionFlags, permission);
|
||||||
}
|
}
|
||||||
bool fWhitelisted{false}; // This peer can bypass DoS banning.
|
// This boolean is unusued in actual processing, only present for backward compatibility at RPC/QT level
|
||||||
|
bool m_legacyWhitelisted{false};
|
||||||
bool fFeeler{false}; // If true this node is being used as a short lived feeler.
|
bool fFeeler{false}; // If true this node is being used as a short lived feeler.
|
||||||
bool fOneShot{false};
|
bool fOneShot{false};
|
||||||
bool m_manual_connection{false};
|
bool m_manual_connection{false};
|
||||||
|
|
|
||||||
|
|
@ -408,7 +408,7 @@ static void UpdatePreferredDownload(CNode* node, CNodeState* state) EXCLUSIVE_LO
|
||||||
nPreferredDownload -= state->fPreferredDownload;
|
nPreferredDownload -= state->fPreferredDownload;
|
||||||
|
|
||||||
// Whether this node should be marked as a preferred download node.
|
// Whether this node should be marked as a preferred download node.
|
||||||
state->fPreferredDownload = (!node->fInbound || node->fWhitelisted) && !node->fOneShot && !node->fClient;
|
state->fPreferredDownload = (!node->fInbound || node->HasPermission(PF_NOBAN)) && !node->fOneShot && !node->fClient;
|
||||||
|
|
||||||
nPreferredDownload += state->fPreferredDownload;
|
nPreferredDownload += state->fPreferredDownload;
|
||||||
}
|
}
|
||||||
|
|
@ -1398,7 +1398,7 @@ void static ProcessGetBlockData(CNode* pfrom, const CChainParams& chainparams, c
|
||||||
const CNetMsgMaker msgMaker(pfrom->GetSendVersion());
|
const CNetMsgMaker msgMaker(pfrom->GetSendVersion());
|
||||||
// disconnect node in case we have reached the outbound limit for serving historical blocks
|
// disconnect node in case we have reached the outbound limit for serving historical blocks
|
||||||
// never disconnect whitelisted nodes
|
// never disconnect whitelisted nodes
|
||||||
if (send && connman->OutboundTargetReached(true) && ( ((pindexBestHeader != nullptr) && (pindexBestHeader->GetBlockTime() - pindex->GetBlockTime() > HISTORICAL_BLOCK_AGE)) || inv.type == MSG_FILTERED_BLOCK) && !pfrom->fWhitelisted)
|
if (send && connman->OutboundTargetReached(true) && ( ((pindexBestHeader != nullptr) && (pindexBestHeader->GetBlockTime() - pindex->GetBlockTime() > HISTORICAL_BLOCK_AGE)) || inv.type == MSG_FILTERED_BLOCK) && !pfrom->HasPermission(PF_NOBAN))
|
||||||
{
|
{
|
||||||
LogPrint(BCLog::NET, "historical block serving limit reached, disconnect peer=%d\n", pfrom->GetId());
|
LogPrint(BCLog::NET, "historical block serving limit reached, disconnect peer=%d\n", pfrom->GetId());
|
||||||
|
|
||||||
|
|
@ -1407,7 +1407,7 @@ void static ProcessGetBlockData(CNode* pfrom, const CChainParams& chainparams, c
|
||||||
send = false;
|
send = false;
|
||||||
}
|
}
|
||||||
// Avoid leaking prune-height by never sending blocks below the NODE_NETWORK_LIMITED threshold
|
// Avoid leaking prune-height by never sending blocks below the NODE_NETWORK_LIMITED threshold
|
||||||
if (send && !pfrom->fWhitelisted && (
|
if (send && !pfrom->HasPermission(PF_NOBAN) && (
|
||||||
(((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 */) )
|
(((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 */) )
|
||||||
)) {
|
)) {
|
||||||
LogPrint(BCLog::NET, "Ignore block request below NODE_NETWORK_LIMITED threshold from peer=%d\n", pfrom->GetId());
|
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
|
||||||
bool fBlocksOnly = !g_relay_txes;
|
bool fBlocksOnly = !g_relay_txes;
|
||||||
|
|
||||||
// Allow whitelisted peers to send data other than blocks in blocks only mode if whitelistrelay is true
|
// Allow whitelisted peers to send data other than blocks in blocks only mode if whitelistrelay is true
|
||||||
if (pfrom->fWhitelisted && gArgs.GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY))
|
if (pfrom->HasPermission(PF_RELAY))
|
||||||
fBlocksOnly = false;
|
fBlocksOnly = false;
|
||||||
|
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
|
|
@ -2412,7 +2412,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
|
||||||
}
|
}
|
||||||
|
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
if (::ChainstateActive().IsInitialBlockDownload() && !pfrom->fWhitelisted) {
|
if (::ChainstateActive().IsInitialBlockDownload() && !pfrom->HasPermission(PF_NOBAN)) {
|
||||||
LogPrint(BCLog::NET, "Ignoring getheaders from peer=%d because node is in initial block download\n", pfrom->GetId());
|
LogPrint(BCLog::NET, "Ignoring getheaders from peer=%d because node is in initial block download\n", pfrom->GetId());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -2470,7 +2470,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
|
||||||
if (strCommand == NetMsgType::TX) {
|
if (strCommand == NetMsgType::TX) {
|
||||||
// Stop processing the transaction early if
|
// Stop processing the transaction early if
|
||||||
// We are in blocks only mode and peer is either not whitelisted or whitelistrelay is off
|
// We are in blocks only mode and peer is either not whitelisted or whitelistrelay is off
|
||||||
if (!g_relay_txes && (!pfrom->fWhitelisted || !gArgs.GetBoolArg("-whitelistrelay", DEFAULT_WHITELISTRELAY)))
|
if (!g_relay_txes && !pfrom->HasPermission(PF_RELAY))
|
||||||
{
|
{
|
||||||
LogPrint(BCLog::NET, "transaction sent in violation of protocol peer=%d\n", pfrom->GetId());
|
LogPrint(BCLog::NET, "transaction sent in violation of protocol peer=%d\n", pfrom->GetId());
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -2565,7 +2565,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
|
||||||
AddToCompactExtraTransactions(ptx);
|
AddToCompactExtraTransactions(ptx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pfrom->fWhitelisted && gArgs.GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY)) {
|
if (pfrom->HasPermission(PF_FORCERELAY)) {
|
||||||
// Always relay transactions received from whitelisted peers, even
|
// Always relay transactions received from whitelisted peers, even
|
||||||
// if they were already in the mempool or rejected from it due
|
// if they were already in the mempool or rejected from it due
|
||||||
// to policy, allowing the node to function as a gateway for
|
// 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
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strCommand == NetMsgType::MEMPOOL) {
|
if (strCommand == NetMsgType::MEMPOOL) {
|
||||||
if (!(pfrom->GetLocalServices() & NODE_BLOOM) && !pfrom->fWhitelisted)
|
if (!(pfrom->GetLocalServices() & NODE_BLOOM) && !pfrom->HasPermission(PF_MEMPOOL))
|
||||||
{
|
{
|
||||||
if (!pfrom->HasPermission(PF_NOBAN))
|
if (!pfrom->HasPermission(PF_NOBAN))
|
||||||
{
|
{
|
||||||
|
|
@ -3020,7 +3020,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connman->OutboundTargetReached(false) && !pfrom->fWhitelisted)
|
if (connman->OutboundTargetReached(false) && !pfrom->HasPermission(PF_MEMPOOL))
|
||||||
{
|
{
|
||||||
if (!pfrom->HasPermission(PF_NOBAN))
|
if (!pfrom->HasPermission(PF_NOBAN))
|
||||||
{
|
{
|
||||||
|
|
@ -3222,7 +3222,7 @@ bool PeerLogicValidation::SendRejectsAndCheckIfBanned(CNode* pnode, bool enable_
|
||||||
|
|
||||||
if (state.fShouldBan) {
|
if (state.fShouldBan) {
|
||||||
state.fShouldBan = false;
|
state.fShouldBan = false;
|
||||||
if (pnode->fWhitelisted)
|
if (pnode->HasPermission(PF_NOBAN))
|
||||||
LogPrintf("Warning: not punishing whitelisted peer %s!\n", pnode->addr.ToString());
|
LogPrintf("Warning: not punishing whitelisted peer %s!\n", pnode->addr.ToString());
|
||||||
else if (pnode->m_manual_connection)
|
else if (pnode->m_manual_connection)
|
||||||
LogPrintf("Warning: not punishing manually-connected peer %s!\n", pnode->addr.ToString());
|
LogPrintf("Warning: not punishing manually-connected peer %s!\n", pnode->addr.ToString());
|
||||||
|
|
@ -3792,7 +3792,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
|
||||||
pto->vInventoryBlockToSend.clear();
|
pto->vInventoryBlockToSend.clear();
|
||||||
|
|
||||||
// Check whether periodic sends should happen
|
// Check whether periodic sends should happen
|
||||||
bool fSendTrickle = pto->fWhitelisted;
|
bool fSendTrickle = pto->HasPermission(PF_NOBAN);
|
||||||
if (pto->nNextInvSend < nNow) {
|
if (pto->nNextInvSend < nNow) {
|
||||||
fSendTrickle = true;
|
fSendTrickle = true;
|
||||||
if (pto->fInbound) {
|
if (pto->fInbound) {
|
||||||
|
|
@ -3948,7 +3948,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
|
||||||
// Note: If all our peers are inbound, then we won't
|
// Note: If all our peers are inbound, then we won't
|
||||||
// disconnect our sync peer for stalling; we have bigger
|
// disconnect our sync peer for stalling; we have bigger
|
||||||
// problems if we can't get any outbound peers.
|
// problems if we can't get any outbound peers.
|
||||||
if (!pto->fWhitelisted) {
|
if (!pto->HasPermission(PF_NOBAN)) {
|
||||||
LogPrintf("Timeout downloading headers from peer=%d, disconnecting\n", pto->GetId());
|
LogPrintf("Timeout downloading headers from peer=%d, disconnecting\n", pto->GetId());
|
||||||
pto->fDisconnect = true;
|
pto->fDisconnect = true;
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -4066,7 +4066,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
|
||||||
//
|
//
|
||||||
// We don't want white listed peers to filter txs to us if we have -whitelistforcerelay
|
// We don't want white listed peers to filter txs to us if we have -whitelistforcerelay
|
||||||
if (pto->nVersion >= FEEFILTER_VERSION && gArgs.GetBoolArg("-feefilter", DEFAULT_FEEFILTER) &&
|
if (pto->nVersion >= FEEFILTER_VERSION && gArgs.GetBoolArg("-feefilter", DEFAULT_FEEFILTER) &&
|
||||||
!(pto->fWhitelisted && gArgs.GetBoolArg("-whitelistforcerelay", DEFAULT_WHITELISTFORCERELAY))) {
|
!pto->HasPermission(PF_FORCERELAY)) {
|
||||||
CAmount currentFilter = mempool.GetMinFee(gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFeePerK();
|
CAmount currentFilter = mempool.GetMinFee(gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFeePerK();
|
||||||
int64_t timeNow = GetTimeMicros();
|
int64_t timeNow = GetTimeMicros();
|
||||||
if (timeNow > pto->nextSendTimeFeeFilter) {
|
if (timeNow > pto->nextSendTimeFeeFilter) {
|
||||||
|
|
|
||||||
|
|
@ -1120,7 +1120,7 @@ void RPCConsole::updateNodeDetail(const CNodeCombinedStats *stats)
|
||||||
ui->peerSubversion->setText(QString::fromStdString(stats->nodeStats.cleanSubVer));
|
ui->peerSubversion->setText(QString::fromStdString(stats->nodeStats.cleanSubVer));
|
||||||
ui->peerDirection->setText(stats->nodeStats.fInbound ? tr("Inbound") : tr("Outbound"));
|
ui->peerDirection->setText(stats->nodeStats.fInbound ? tr("Inbound") : tr("Outbound"));
|
||||||
ui->peerHeight->setText(QString("%1").arg(QString::number(stats->nodeStats.nStartingHeight)));
|
ui->peerHeight->setText(QString("%1").arg(QString::number(stats->nodeStats.nStartingHeight)));
|
||||||
ui->peerWhitelisted->setText(stats->nodeStats.fWhitelisted ? tr("Yes") : tr("No"));
|
ui->peerWhitelisted->setText(stats->nodeStats.m_legacyWhitelisted ? tr("Yes") : tr("No"));
|
||||||
|
|
||||||
// This check fails for example if the lock was busy and
|
// This check fails for example if the lock was busy and
|
||||||
// nodeStateStats couldn't be fetched.
|
// nodeStateStats couldn't be fetched.
|
||||||
|
|
|
||||||
|
|
@ -178,7 +178,7 @@ static UniValue getpeerinfo(const JSONRPCRequest& request)
|
||||||
}
|
}
|
||||||
obj.pushKV("inflight", heights);
|
obj.pushKV("inflight", heights);
|
||||||
}
|
}
|
||||||
obj.pushKV("whitelisted", stats.fWhitelisted);
|
obj.pushKV("whitelisted", stats.m_legacyWhitelisted);
|
||||||
UniValue permissions(UniValue::VARR);
|
UniValue permissions(UniValue::VARR);
|
||||||
for (const auto& permission : NetPermissions::ToStrings(stats.m_permissionFlags)) {
|
for (const auto& permission : NetPermissions::ToStrings(stats.m_permissionFlags)) {
|
||||||
permissions.push_back(permission);
|
permissions.push_back(permission);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue