Skip to content

Conversation

dergoegge
Copy link
Member

@dergoegge dergoegge commented Jun 30, 2022

Another step in #19398. Which services we offer to a peer and which services they offer to us is application layer data and should not be stored on CNode.

This is also a prerequisite for adding PeerManager unit tests (See #25515).

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 30, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #25619 (net: avoid overriding non-virtual ToString() in CService and use better naming by vasild)
  • #25572 (refactor: Introduce EvictionManager and use it for the inbound eviction logic by dergoegge)
  • #25555 (refactor: Move num_unconnecting_headers_msgs out of cs_main guard by MarcoFalke)
  • #25355 (I2P: add support for transient addresses for outbound connections by vasild)
  • #25268 (refactor: Introduce EvictionManager by dergoegge)
  • #25174 (net/net_processing: Add thread safety related annotations for CNode and Peer by ajtowns)
  • #24697 (refactor address relay time by MarcoFalke)
  • #24571 (p2p: Prevent block index fingerprinting by sending additional getheaders messages by dergoegge)
  • #24170 (p2p, rpc: Manual block-relay-only connections with addnode by mzumsande)
  • #24008 (assumeutxo: net_processing changes by jamesob)
  • #23443 (p2p: Erlay support signaling by naumenkogs)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Copy link
Contributor

@jnewbery jnewbery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK.

@maflcko maflcko removed the P2P label Jul 4, 2022
@DrahtBot DrahtBot added the P2P label Jul 4, 2022
@dergoegge dergoegge force-pushed the 2022-06-move-services branch 2 times, most recently from f7965ef to fae6a00 Compare July 4, 2022 16:43
@dergoegge dergoegge force-pushed the 2022-06-move-services branch from fae6a00 to d5b6ba7 Compare July 5, 2022 15:48
@jnewbery
Copy link
Contributor

jnewbery commented Jul 6, 2022

utACK d5b6ba7

@dergoegge dergoegge force-pushed the 2022-06-move-services branch from d5b6ba7 to c38a00d Compare July 6, 2022 15:50
@jnewbery
Copy link
Contributor

jnewbery commented Jul 6, 2022

utACK c38a00d

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking a lot better with the Handshake test helper. Thanks.

review ACK 8f6ed20 though I have not yet reviewed the last two commits 🏼

Show signature

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

review ACK 8f6ed20acae2a4f93f5b52c3937ab704980db44b though I have not yet reviewed the last two commits 🏼
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUjqHwwAlNYcnHxFpa3FBWcBsYy2DSbbm3Ww6p+dqZLivANiuNWpc7qKrFYoVQKY
OlCbOyMJNHuGbC0ACwjSfVxh1VhyLpdW7qtrMr203XD3j3MRComWe1Q5h6jG4jfn
rEB0ybHIAowvoWQBfvtY5Ti20WEsiPvWL4qEgA+b+wYClG+42BCHUyRePkN+1k+u
0fD/BOhTiRszyXgfWNV5q1iI/UhR6caf213mV/5X+udIXWMgi1PRV+4HQG4GmZdq
s25Ua9Quzmgtjz3sUDb4op2ztlS8BOMpzulKqSiXmIyAQz72zODaYrCieHOItZs8
vRR/JbGs4IMF/whQFtzJgPIMQ+O6iO8V/VHBoYbrmhjcbxpX9ioXhpX4mXelepeN
NFkdOR9WQWpaMAfcOl948axSgfVaN7MFU+9+0rzpHLEamQj5wbzdP4xdtyXqFGA4
jf11QGqoAh3a0IvYhEoUgK0MPbeR6ASSvhzAtglIw6vFtCPkCXBRnM+8vqBmaLBr
iVM6GTFy
=YLIt
-----END PGP SIGNATURE-----

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to do some testing, but the second commit doesn't compile:

test/denialofservice_tests.cpp:75:23: error: too many arguments to function call, expected 6, have 7

@dergoegge dergoegge force-pushed the 2022-06-move-services branch 2 times, most recently from 54c7f95 to e7aea6a Compare July 13, 2022 15:59
@dergoegge
Copy link
Member Author

Thanks @MarcoFalke and @jnewbery for the reviews! I addressed all comments and rebased.

All commits should now build without issues.

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

review ACK e7aea6a 🏞

Show signature

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

review ACK e7aea6ae6d0cd668dc7228cc24d0a58419c6ebcd 🏞
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUjuqQv/aHcMUNox1MQBi+1Mj3WJorgEHy85MaRS3JiylOIrpUpGgtjvmh91HpoG
6ThPApvoEKGf3sYRKgU8COOVoEgzBj3AqXeG/RTu6wJaZNq3AFRmCjBtzzsxJjDJ
6w9SLoBexTQyTLLFEf/EvwxlE3ttldDgPQOQ0Ui6zZgxs1eCjpgBb119V41BTBmy
esOxtkE8ZHoPo+4nPYhB0d9f2i60wYX1jbeZAv0b3BDB+4XL67UUXhq8IhEJFvRY
LTDbgtSxhNQJAx3NOcOeHtmDdy8xfQe3Nnc7q8WAIfcitCa+DGXSIt5pKTzuwvut
bbPZroBqWarME+zSsVxvR6JMfAVoTrLO2zaFoAYrCvFQq6yrbq3OJZ6Rqq9GOJjj
kuwMGpW6yKJvTRb0qxgcds3Bgh6UJ/U3ZUVtfxNJ5LR7+JCpOkSBN1Ro+vH+amml
GZC7tDdeC7f8IaexX51tUXbweRzE49zK3NH5pYazHubyZDncMRM4dlLs8AtIzL8C
6XsRJRHp
=ZDto
-----END PGP SIGNATURE-----

@jnewbery
Copy link
Contributor

@dergoegge just checking that you saw my comment about member naming: #25514 (comment).

jnewbery and others added 7 commits July 14, 2022 14:44
Track services offered by us and the peer in the Peer object.
…essages

Prior to this commit, the peer was connected, and then the services and
connectivity fields in the CNode object were manually set. Instead, send
p2p `version` and `verack` messages, and have net_processing's internal
logic set the state of the node.

This ensures that the node's internal state is consistent with how it
would be set in the live code.

Prior to this commit, `dummyNode1.nServices` was set to `NODE_NONE`
which was not a problem since `CNode::fClient` and
`CNode::m_limited_node` are default initialised to false. Now that we
are doing the actual version handshake, the values of `fClient` and
`m_limited_node` are set during the handshake and cause the test to fail
if we do not set `dummyNode1.nServices` to a reasonable value
(NODE_NETWORK | NODE_WITNESS).
fClient is replaced by CanServeBlocks(), and m_limited_node is replaced
by IsLimitedPeer().
Use Peer::m_their_services instead
@dergoegge dergoegge force-pushed the 2022-06-move-services branch from e7aea6a to 8d8eeb4 Compare July 14, 2022 13:29
@maflcko
Copy link
Member

maflcko commented Jul 14, 2022

ACK 8d8eeb4 🔑

Show signature

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

ACK 8d8eeb422e64ccd08bce92eed2ee9cbbf55ffd67 🔑
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUjJZQv/TaiI8pAKqRBeggxNkZdPjDY4gnn1vJgyfjjDsVu1FrKZBbOm0AxGPmSP
o3N2x5ZZWcjIzU6Rmv0aWqxmz1yaHUByF9bHC8PBcfcdnb9ELVePbYApM3pcFZU1
DX/wR1RJcb+m9/h8Kl8f6wQMIHf/2fCuqi10/AX+RqLIgEpIRECnEGaHVE6jGV2k
gI+KDnQRxRBelpSloDK7lnTAOUbU0H9ReeILtpIDM6HNGynC50C2VEj29cSxjBdD
KaqNPbbcHyqXiDM0DhNtFRRWNS8PP2d46xWOK+yWr/sInPpmdns8xsA29s3FwUp0
mqpseRqrfRaFOZRqtDjVX1nxs3JeQNSkxCnJoVFMReWzZcvEe9PO0jZjOrntCAwU
cxJcrNsRlaxkIT3Ty2mKYuoRZKujxXUmHzBD4KOYiLd0DNHX+xCEcEb/aQFQM21g
cLOkVzMe8IDfocPtbKw38HQSHgsh/ppzWM61KBp8vBuI4jTlGY3XUieUFW6mlhgj
vGhOSGp+
=CVY2
-----END PGP SIGNATURE-----

Copy link
Contributor

@jnewbery jnewbery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 8d8eeb4

One missed our_services -> m_our_services in a comment, but that shouldn't hold up merge.

*
* \sa CNode::nLocalServices
* \sa Peer::our_services
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* \sa Peer::our_services
* \sa Peer::m_our_services

Copy link
Contributor

@mzumsande mzumsande left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review ACK 8d8eeb4

This looks good to me, only found nits/doc comments during review.

@@ -2650,7 +2649,7 @@ bool PeerManagerImpl::PrepareBlockFilterRequest(CNode& peer,
return true;
}

void PeerManagerImpl::ProcessGetCFilters(CNode& peer, CDataStream& vRecv)
void PeerManagerImpl::ProcessGetCFilters(CNode& node,Peer& peer, CDataStream& vRecv)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:space after node

* This data is replicated in each CNode instance we create during peer
* connection (in ConnectNode()) under a member also called
* nLocalServices.
* This data is replicated in each Peer instance we create.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This confused me during review, "replicated" makes it sound like the data is just copied to each peer (which was technically true before, when the comment specifically addressed ConnectNode() and ignored the CreateNodeFromAcceptedSocket() call site ).

It might be good to mention here and/or in the Peer::m_our_services doc that different peers can be offered different local services based on permissions - otherwise m_our_services wouldn't need to be a member of Peer but could exist on the level of PeerManagerImpl.

@maflcko maflcko merged commit 2bdce7f into bitcoin:master Jul 19, 2022
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jul 19, 2022
@dhruv
Copy link
Contributor

dhruv commented Jul 22, 2022

@dergoegge @jnewbery I am still digging deeper here, but I have a question (and might be terribly wrong). Moving nServices and nLocalServices into Peer seems to imply that the service bits only gain importance during the VERSION/VERACK handshake and are useful in the P2P layer, not in the transport layer.

However, I think service bits (also propagated with addr relay) are useful at the transport layer. For instance in BIP324, the proposed signaling method uses nServices from addr relay to branch logic in the establishment of the transport. Moving the service flags to net_processing will mean that I'll end up having to pass a boolean around. Is that an expected and acceptable consequence?

@dergoegge
Copy link
Member Author

@dhruv Currently all service bits signal readiness to serve application layer data (blocks, bloom/compact filters, witness data). The BIP324 service bit differs from that as it signals support for a new transport protocol, which would make it the only bit that is needed within our net layer. I would therefore argue that passing around a bool to/within the net layer for the v2 bit seems more appropriate than passing around all service bits.

@bitcoin bitcoin locked and limited conversation to collaborators Jul 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants