Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport: merge bitcoin#21594, #21843, #22306, #22211, #22387, #21528, #22616, #22604, #22960, #23218 (networking backports: part 3) #5978

Merged
merged 13 commits into from
Apr 15, 2024

Conversation

kwvg
Copy link
Collaborator

@kwvg kwvg commented Apr 9, 2024

Additional Information

  • Dependency for backport: merge bitcoin#20769, #19499, #23575, #23695, #21160, #24692, partial bitcoin#20196, #25176, merge bitcoin-core/gui#526 (networking backports: part 4) #5982
  • Population of ADDRS in p2p_addr(v2)_relay in Dash is done in the test object (source) as opposed to upstream, where it is done in the global state (source). This is because Dash specifically relies on self.mocktime instead of Bitcoin, which will work with simply sampling current time (time.time()).
    • bitcoin#22211 adds changes (source) that add usage of ADDRS outside the test object. That, alongside with other considerations, resulted in dash#5967 and a discussion (source)
    • Eventually, following the footsteps of dash#5967, ADDRS was defined outside but setup within the test object. This worked just fine (build) but displeased the linter (build) because ADDRS type could not be implicitly determined solely on usage in the global scope.
    • An attempt to correct this was done by realignment with upstream (commit), which pleased the linter (build) but broken the test (build) for the reasons as mentioned above.
    • Therefore, to keep the linter happy, ADDRS has been annotated as a List[CAddress] (which involved importing List but that's fine) (commit)
  • Working on bitcoin#21528 proved challenging due to differences in Dash's and Bitcoin's approach to relaying and the workarounds used to accommodate for that.
    • Bitcoin conditionally initializes m_tx_relay (source) and can always check if transaction relaying is permitted by checking if it's initialized (source).
    • Dash unconditionally initializes it (source). Earlier, Dash used to check if it's appropriate to relay transactions by checking if it can relay addresses (source), which at the time, simply meant, it wasn't a block-only connection (source).
    • This mutual exclusivity no longer held true in dash#5964 and therefore, some transaction relay decisions were bound to not being a block-only connection (commit) but some were left behind, adopting RelayAddrsWithPeer() (source), which, to be noted, is determined by the initialization status of Peer::m_addr_known (source), which, so far, was pegged to not block-relay connection status (source).
    • bitcoin#21528 got rid of RelayAddrsWithPeer() and replaced it with Peer::m_addr_relay_enabled (source), which is setup using Peer::SetupAddressRelay() (source). This means, rather than defining the address relay status during construction, it is setup during the first address-related message (i.e. ADDR, ADDRV2, GETADDR) (source).
      • Meaning, until the first addr-related message happens, the state is has not been determined and defaults to false. Because some m_tx_relay usage still piggybacked on addr-relay permission to determine tx-relay, if a transaction message is processed before an address message is processed, there will be a false-negative condition.

        The transaction relay logic won't run since it's expecting that if transactions can be relayed, so can addresses and checks for address relaying but believes that it cannot do address relaying, borrowing that state for transaction relaying, despite address relaying permissions actually being indeterminate since it hasn't had a chance to validate its eligibility.

      • There were two approaches, run SetupAddressRelay() as early in the connection as possible to substitute for the "determine at construction" behaviour and change no other conditional statements... and break address-related tests or move the remaining conditional transaction relay logic to use not block-only connection checks instead.

      • We've gone with the latter, resulting in some changes where the condition only changes form but is the same (RelayAddrsWithPeer() > Peer::m_addr_relay_enabled) (source) but other changes where the condition itself has been changed (RelayAddrsWithPeer() > !CNode::IsBlockOnlyConn()) (source)

    • This does mean that in dash#5982, Peer::m_block_relay_only is introduced to be the counterpart to Peer::m_addr_relay_enabled (source) to account for some CConnman logic being moved into PeerManager (source), which, in a way, reverts dash#5339 but also, doesn't, since it moves the information into Peer instead of reinstating it into CNode.
      • This was eventual since the underlying presumption that CNode::IsAddrRelayPeer() == !CNode::IsBlockOnlyConn() no longer holds true (also because CNode::IsAddrRelayPeer() doesn't exist anymore).

Special thanks to @UdjinM6 for help with understanding Dash-specifics with respect to functional tests through help on dash#5964 and dash#5967

Breaking Changes

None expected.

RPC changes have been introduced in getnodeaddresses, where a new input network, can filter addresses based on desired network and a new output, also network, will associate the address with the origin network. This change is expected to be backwards-compatible.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

@kwvg kwvg changed the title backport: merge bitcoin#21594, #21843, #22306, #22211, #22387, #21528, #22616, #22604, #22960, #23218, #19499, #23575, #23695, #21160, partial bitcoin#20196, merge bitcoin-core/gui#526 (networking backports: part 3) backport: merge bitcoin#21594, #21843, #22306, #22211, #22387, #21528, #22616, #22604, #22960, #23218 (networking backports: part 3) Apr 10, 2024
@kwvg kwvg added this to the 21 milestone Apr 10, 2024
@kwvg kwvg marked this pull request as ready for review April 11, 2024 19:15
@UdjinM6 UdjinM6 added the RPC Some notable changes to RPC params/behaviour/descriptions label Apr 11, 2024
src/rpc/net.cpp Outdated
@@ -104,6 +104,7 @@ static RPCHelpMan getpeerinfo()
{RPCResult::Type::STR, "addr", "(host:port) The IP address and port of the peer"},
{RPCResult::Type::STR, "addrbind", "(ip:port) Bind address of the connection to the peer"},
{RPCResult::Type::STR, "addrlocal", "(ip:port) Local address as reported by the peer"},
{RPCResult::Type::BOOL, "addr_relay_enabled", "Whether we participate in address relay with this peer"},
Copy link
Collaborator

Choose a reason for hiding this comment

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

21528 - please include backport bitcoin#22618 which has release notes for this changes

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Resolved in latest push!

Copy link
Member

@PastaPastaPasta PastaPastaPasta left a comment

Choose a reason for hiding this comment

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

Generally looks good

Comment on lines -5339 to +5385
if (RelayAddrsWithPeer(*peer)) {
if (!pto->IsBlockOnlyConn()) {
Copy link
Member

Choose a reason for hiding this comment

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

this feels wrong; 21528 doesn't introduce any usage of IsBlockOnlyConn? why not use peer->m_addr_relay_enabled?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This has already been explained in the PR description but the switchover to IsBlockOnlyConn has been split into a separate commit to avoid association with changes from the backport.

kwvg added 13 commits April 12, 2024 16:37
…es by network

continuation of cf27db8 from dash#5491

includes:
- 6c98c09
- 3f89c0e
- ce6bca8
In bitcoin#21528, the value of `m_addr_relay_enabled` isn't determined
until the first ADDR/ADDRV2/GETADDR call. Until then, it'll always default
to `false`. This creates a false-negative where a term equivalent to "not
a block connection" no longer reliably means that.

Therefore we need to switch to directly querying "not a block-only
connection".
Required to avoid unhappy python linter[1] result. Have to use annotation
instead of re-aligning with upstream (where ADDRS is populated in the
global state) due to reliance on `self.mocktime`, without which, the test
fails[2]

[1] - https://gitlab.com/dashpay/dash/-/jobs/6594035886
[2] - https://gitlab.com/dashpay/dash/-/jobs/6597322548
Copy link
Collaborator

@knst knst left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

@UdjinM6 UdjinM6 left a comment

Choose a reason for hiding this comment

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

utACK

Copy link
Member

@PastaPastaPasta PastaPastaPasta left a comment

Choose a reason for hiding this comment

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

utACK 1fedf47

@PastaPastaPasta PastaPastaPasta merged commit 9240967 into dashpay:develop Apr 15, 2024
9 of 11 checks passed
PastaPastaPasta added a commit that referenced this pull request Apr 28, 2024
, bitcoin#23695, bitcoin#21160, bitcoin#24692, partial bitcoin#20196, bitcoin#25176, merge bitcoin-core/gui#526 (networking backports: part 4)

ab7ac1b partial bitcoin#25176: Fix frequent -netinfo JSON errors from null getpeerinfo#relaytxes (Kittywhiskers Van Gogh)
c89799d merge bitcoin#24692: Follow-ups to bitcoin#21160 (Kittywhiskers Van Gogh)
33098ae merge bitcoin#21160: Move tx inventory into net_processing (Kittywhiskers Van Gogh)
24205d9 partial bitcoin#20196: fix GetListenPort() to derive the proper port (Kittywhiskers Van Gogh)
7f72009 merge bitcoin-core/gui#526: Add address relay/processed/rate-limited fields to peer details (Kittywhiskers Van Gogh)
a9114f1 merge bitcoin#23695: Always serialize local timestamp for version msg (Kittywhiskers Van Gogh)
d936c28 merge bitcoin#23575: Rework FillNode (Kittywhiskers Van Gogh)
6f8c730 merge bitcoin#19499: Make timeout mockable and type safe, speed up test (Kittywhiskers Van Gogh)
43a82bd merge bitcoin#20769: fixes "advertised address where nobody is listening" (Kittywhiskers Van Gogh)

Pull request description:

  ## Additional Information

  * Dependent on #5978
  * Dependent on #5977

  ## Breaking Changes

  None observed.

  ## Checklist:

  - [x] I have performed a self-review of my own code
  - [x] I have commented my code, particularly in hard-to-understand areas **(note: N/A)**
  - [x] I have added or updated relevant unit/integration/functional/e2e tests
  - [x] I have made corresponding changes to the documentation **(note: N/A)**
  - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_

ACKs for top commit:
  PastaPastaPasta:
    utACK ab7ac1b

Tree-SHA512: 87bf5108bb80576c5bff8cd577add7800044da252fd18590e06a727f0bf70de94e2e9294b4412cdd9f1f6676472b0359902af361aaffc4c9ee299ad07d6af009
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RPC Some notable changes to RPC params/behaviour/descriptions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants