Skip to content

Commit d9079fe

Browse files
jnewberydergoegge
authored andcommitted
[net processing] Remove CNode::nServices
Use Peer::m_their_services instead
1 parent 7d1c036 commit d9079fe

File tree

7 files changed

+13
-12
lines changed

7 files changed

+13
-12
lines changed

src/net.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,6 @@ Network CNode::ConnectedThroughNetwork() const
603603
void CNode::CopyStats(CNodeStats& stats)
604604
{
605605
stats.nodeid = this->GetId();
606-
X(nServices);
607606
X(addr);
608607
X(addrBind);
609608
stats.m_network = ConnectedThroughNetwork();
@@ -880,7 +879,7 @@ bool CConnman::AttemptToEvictConnection()
880879
.m_min_ping_time = node->m_min_ping_time,
881880
.m_last_block_time = node->m_last_block_time,
882881
.m_last_tx_time = node->m_last_tx_time,
883-
.fRelevantServices = HasAllDesirableServiceFlags(node->nServices),
882+
.fRelevantServices = node->m_has_all_wanted_services,
884883
.m_relay_txs = node->m_relays_txs.load(),
885884
.fBloomFilter = node->m_bloom_filter_loaded.load(),
886885
.nKeyedNetGroup = node->nKeyedNetGroup,

src/net.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ class CNodeStats
187187
{
188188
public:
189189
NodeId nodeid;
190-
ServiceFlags nServices;
191190
std::chrono::seconds m_last_send;
192191
std::chrono::seconds m_last_recv;
193192
std::chrono::seconds m_last_tx_time;
@@ -346,7 +345,6 @@ class CNode
346345
std::unique_ptr<TransportSerializer> m_serializer;
347346

348347
NetPermissionFlags m_permissionFlags{NetPermissionFlags::None};
349-
std::atomic<ServiceFlags> nServices{NODE_NONE};
350348

351349
/**
352350
* Socket used for communication with the node.
@@ -482,6 +480,9 @@ class CNode
482480
// Peer selected us as (compact blocks) high-bandwidth peer (BIP152)
483481
std::atomic<bool> m_bip152_highbandwidth_from{false};
484482

483+
/** Whether this peer provides all services that we want. Used for eviction decisions */
484+
std::atomic_bool m_has_all_wanted_services{false};
485+
485486
/** Whether we should relay transactions to this peer (their version
486487
* message did not include fRelay=false and this is not a block-relay-only
487488
* connection). This only changes from false to true. It will never change

src/net_processing.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,7 @@ struct Peer {
223223
*
224224
* TODO: remove redundant CNode::nLocalServices*/
225225
const ServiceFlags m_our_services;
226-
/** Services this peer offered to us.
227-
*
228-
* TODO: remove redundant CNode::nServices */
226+
/** Services this peer offered to us. */
229227
std::atomic<ServiceFlags> m_their_services{NODE_NONE};
230228

231229
/** Protects misbehavior data members */
@@ -1472,6 +1470,7 @@ bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) c
14721470

14731471
PeerRef peer = GetPeerRef(nodeid);
14741472
if (peer == nullptr) return false;
1473+
stats.their_services = peer->m_their_services;
14751474
stats.m_starting_height = peer->m_starting_height;
14761475
// It is common for nodes with good ping times to suddenly become lagged,
14771476
// due to a new block arriving or other large transfer.
@@ -2885,7 +2884,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
28852884

28862885
m_connman.PushMessage(&pfrom, msg_maker.Make(NetMsgType::VERACK));
28872886

2888-
pfrom.nServices = nServices;
2887+
pfrom.m_has_all_wanted_services = HasAllDesirableServiceFlags(nServices);
28892888
peer->m_their_services = nServices;
28902889
pfrom.SetAddrLocal(addrMe);
28912890
{

src/net_processing.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct CNodeStateStats {
3434
uint64_t m_addr_processed = 0;
3535
uint64_t m_addr_rate_limited = 0;
3636
bool m_addr_relay_enabled{false};
37+
ServiceFlags their_services;
3738
};
3839

3940
class PeerManager : public CValidationInterface, public NetEventsInterface

src/qt/rpcconsole.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,6 @@ void RPCConsole::updateDetailWidget()
11621162
if (!stats->nodeStats.addrLocal.empty())
11631163
peerAddrDetails += "<br />" + tr("via %1").arg(QString::fromStdString(stats->nodeStats.addrLocal));
11641164
ui->peerHeading->setText(peerAddrDetails);
1165-
ui->peerServices->setText(GUIUtil::formatServicesStr(stats->nodeStats.nServices));
11661165
QString bip152_hb_settings;
11671166
if (stats->nodeStats.m_bip152_highbandwidth_to) bip152_hb_settings = ts.to;
11681167
if (stats->nodeStats.m_bip152_highbandwidth_from) bip152_hb_settings += (bip152_hb_settings.isEmpty() ? ts.from : QLatin1Char('/') + ts.from);
@@ -1197,6 +1196,7 @@ void RPCConsole::updateDetailWidget()
11971196
// This check fails for example if the lock was busy and
11981197
// nodeStateStats couldn't be fetched.
11991198
if (stats->fNodeStateStatsAvailable) {
1199+
ui->peerServices->setText(GUIUtil::formatServicesStr(stats->nodeStateStats.their_services));
12001200
// Sync height is init to -1
12011201
if (stats->nodeStateStats.nSyncHeight > -1) {
12021202
ui->peerSyncHeight->setText(QString("%1").arg(stats->nodeStateStats.nSyncHeight));

src/rpc/net.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,9 @@ static RPCHelpMan getpeerinfo()
195195
if (stats.m_mapped_as != 0) {
196196
obj.pushKV("mapped_as", uint64_t(stats.m_mapped_as));
197197
}
198-
obj.pushKV("services", strprintf("%016x", stats.nServices));
199-
obj.pushKV("servicesnames", GetServicesNames(stats.nServices));
198+
ServiceFlags services{fStateStats ? statestats.their_services : ServiceFlags::NODE_NONE};
199+
obj.pushKV("services", strprintf("%016x", services));
200+
obj.pushKV("servicesnames", GetServicesNames(services));
200201
obj.pushKV("lastsend", count_seconds(stats.m_last_send));
201202
obj.pushKV("lastrecv", count_seconds(stats.m_last_recv));
202203
obj.pushKV("last_transaction", count_seconds(stats.m_last_tx_time));

src/test/util/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ void ConnmanTestMsg::Handshake(CNode& node,
5151
if (node.fDisconnect) return;
5252
assert(node.nVersion == version);
5353
assert(node.GetCommonVersion() == std::min(version, PROTOCOL_VERSION));
54-
assert(node.nServices == remote_services);
5554
CNodeStateStats statestats;
5655
assert(peerman.GetNodeStateStats(node.GetId(), statestats));
5756
assert(statestats.m_relay_txs == (relay_txs && !node.IsBlockOnlyConn()));
57+
assert(statestats.their_services == remote_services);
5858
node.m_permissionFlags = permission_flags;
5959
if (successfully_connected) {
6060
CSerializedNetMsg msg_verack{mm.Make(NetMsgType::VERACK)};

0 commit comments

Comments
 (0)