Skip to content

Conversation

jnewbery
Copy link
Contributor

Next step in #19398. Moves additional members from CNode and CNodeState into Peer.

Also renames CNodeStateStats to PeerStats, since most of the stats are now taken from the Peer object.

@maflcko
Copy link
Member

maflcko commented Apr 25, 2022

Concept ACK

@fanquake fanquake added the P2P label Apr 25, 2022
@hebasto
Copy link
Member

hebasto commented Apr 25, 2022

Concept ACK.

@DrahtBot
Copy link
Contributor

DrahtBot commented Apr 25, 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:

  • #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)
  • #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)
  • #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.

@theStack
Copy link
Contributor

Concept ACK

@jnewbery
Copy link
Contributor Author

Fixed a bug (subver may not be present in the getpeerinfo results while the peer connection is being torn down, so needs to be marked as optional) and rebased on master.

I'm going to mark this as a draft since it conflicts with and overlaps with #24543, which has been open for longer.

@jnewbery
Copy link
Contributor Author

Rebased on master now that #24543 is merged.

Leaving this as draft for now. I think there may be a better way of handling the version nonces.

@jnewbery
Copy link
Contributor Author

Rebased on master and tidied up the nonce handling code. This is now ready for review.

@jnewbery jnewbery marked this pull request as ready for review May 16, 2022 18:21
@jnewbery jnewbery force-pushed the 202204_net_net_processing branch from 53d581f to db4eeb2 Compare May 16, 2022 21:46
jnewbery added 3 commits June 3, 2022 11:39
Most of the stats in CNodeStateStats are now taken from the Peer object.
Rename the struct to PeerStats.

-BEGIN VERIFY SCRIPT-
ren() { sed -i "s:\<$1\>:$2:g" $(git grep -l "\<$1\>" ./src ./test); }

ren CNodeStateStats          PeerStats
ren GetNodeStateStats        GetPeerStats
ren nodeStateStats           m_peer_stats
ren statestats               peer_stats
ren fNodeStateStatsAvailable m_peer_stats_available
ren fStateStats              peer_stats_available

-END VERIFY SCRIPT-
Also rename to m_clean_subversion.

Since the subversion is now contained in the Peer object, it may not be
available in `getpeerinfo` while the peer connection is being torn down.
Update the rpc help text to mark the field optional and update the tests
to tolerate the field being absent.
Also rename to m_preferred_download
@jnewbery jnewbery force-pushed the 202204_net_net_processing branch from 7ef17fe to f6bf0d1 Compare June 3, 2022 10:50
@jnewbery
Copy link
Contributor Author

jnewbery commented Jun 3, 2022

Rebased

Copy link
Contributor

@theStack theStack 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 f6bf0d1

Nice idea to use a std::map for the sent nonce values and only store them as long as necessary (that is, until the connection is fully established). Left two refactoring nits where one-liners could be used instead, feel free to ignore.

Handle version nonces entirely within net_processing.
@jnewbery
Copy link
Contributor Author

jnewbery commented Jun 6, 2022

Thanks for the review @theStack. I've taken your suggestions.

@jnewbery jnewbery force-pushed the 202204_net_net_processing branch from f6bf0d1 to 7df3d82 Compare June 6, 2022 11:22
Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

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

re-ACK 7df3d82

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.

concept ACK 4680a64 🚡

Show signature

Signature:

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

concept ACK 4680a64075758f3a08a69dc2bf9243631628900d 🚡
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUhd+gv+IJsGtuUaa3dRjoJRyLWYPP5KF8uARYx7CkD9oxwEaVycVUCrTvQevQFE
pT6AV7iljFwqfboaliFxveFaoJlZY314jNUtjlpADZS20FQrKvQN74ZEt8/WYWOy
aZ2KOaTd7+kxJOIAcIIPFuFPCZM/PYjuuEwO1POYtvUGCIQySCV15uoHALhklxmE
x8BcZ6PBycjLyCtZ9J6se6yB+PNoIoWZlELVEe5sX8cpWrloQVSfx89k9tRf7oMF
LrentpcIo3Iu/k2LTUw8yjeQGuq9c5OrSw0GxLo2J1vrB5LyKVSpca2VP29GOdnv
QgBBNIT2UQLCsWuHm/wQVdSqkDCxPAfXzLRFmXSbFCLQWuKpG4MxXSUXpKbzGD6i
W5E9Kbm24KR/TnkayAVOIIcJTMBuTvw2f3Mu0durb4dBaOo9ZMEAPOI4vvyE/Ohq
x1Zx+0Ecn5+CFuVQfFeXrBKTsREFn9YHomksVCdoBkaPPdzlEVOyQOWk2tHi1zhd
RSZPVvfl
=uVaU
-----END PGP SIGNATURE-----

@@ -210,6 +210,9 @@ struct Peer {
* This cleaned string can safely be logged or displayed. */
std::string m_clean_subversion GUARDED_BY(m_subver_mutex){};

/** Whether we consider this a preferred download peer. */
bool m_preferred_download{false};
Copy link
Member

Choose a reason for hiding this comment

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

fPreferredDownload used to be protected by cs_main. Can you explain why the lock is not needed anymore, considering that the socket thread and the p2p thread will both read this value?

@@ -656,7 +657,7 @@ class PeerManagerImpl final : public PeerManager
int m_outbound_peers_with_protect_from_disconnect GUARDED_BY(cs_main) = 0;

/** Number of preferable block download peers. */
int m_num_preferred_download_peers GUARDED_BY(cs_main){0};
std::atomic<int> m_num_preferred_download_peers{0};
Copy link
Member

Choose a reason for hiding this comment

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

can you explain why atomic is sufficient, given that the value is assumed to be changed atomically with fPreferredDownload, and is used in calculations with that assumption:

m_num_preferred_download_peers - state.fPreferredDownload >= 1

@jnewbery
Copy link
Contributor Author

Closing this since it needs a bit of work and I don't have time to maintain it. In terms of priority, I think there's more immediate benefit in moving the services fields from CNode to Peer (the last 6 commits in master...jnewbery:2020-06-cs-main-split), since that allows PeerManagerImpl to be unit tested through the public p2p interfaces.

@jnewbery jnewbery closed this Jun 20, 2022
@bitcoin bitcoin locked and limited conversation to collaborators Jun 20, 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.

6 participants