Skip to content

Conversation

vasild
Copy link
Contributor

@vasild vasild commented Jun 28, 2023

In add_p2p_connection() we connect to bitcoind from the Python client and check that it has received our version string.

This check looked up the last/newest entry from getpeerinfo RPC, assuming that it must be the connection we have just opened. But this will not be the case if a new inbound or outbound connection is made to/from bitcoind in the meantime.

Instead of the last entry in getpeerinfo, check all and find the one which corresponds to our connection using our outgoing address:port tuple which is unique.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 28, 2023

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

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK jonatack
Concept ACK RandyMcMillan, MarcoFalke

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

@DrahtBot DrahtBot added the Tests label Jun 28, 2023
@vasild
Copy link
Contributor Author

vasild commented Jun 28, 2023

I stumbled on this playing with #27509:

https://cirrus-ci.com/task/6722465808777216?logs=ci#L8761-L8771

CI log
2023-06-27T09:50:26.796000Z TestFramework (ERROR): Assertion failed
Traceback (most recent call last):
  File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-i686-pc-linux-gnu/test/functional/test_framework/test_framework.py", line 132, in main
    self.run_test()
  File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-i686-pc-linux-gnu/test/functional/p2p_local_tx_relay.py", line 211, in run_test
    observer_inbound = node0.add_p2p_connection(P2PDataStore())
  File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-i686-pc-linux-gnu/test/functional/test_framework/test_node.py", line 639, in add_p2p_connection
    assert_equal(self.getpeerinfo()[-1]['subver'], P2P_SUBVERSION)
  File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-i686-pc-linux-gnu/test/functional/test_framework/util.py", line 57, in assert_equal
    raise AssertionError("not(%s)" % " == ".join(str(arg) for arg in (thing1, thing2) + args))
AssertionError: not( == /python-p2p-tester:0.0.3/)

The test calls add_p2p_connection() and at the same time bitcoind opens a new outbound connection. The subver field for the new connection in getpeerinfo is empty before the VERSION message is received.

@vasild vasild force-pushed the test_more_robust_ua_recv_check branch from 44d71cf to 9c46f3b Compare June 28, 2023 10:58
@vasild
Copy link
Contributor Author

vasild commented Jun 28, 2023

44d71cfd0e...9c46f3ba19: do #27986 (comment)

@vasild vasild force-pushed the test_more_robust_ua_recv_check branch from 9c46f3b to c1a1690 Compare June 28, 2023 14:19
@vasild
Copy link
Contributor Author

vasild commented Jun 28, 2023

9c46f3ba19...c1a169082a: take #27986 (comment)

Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

Light tested ACK c1a1690

@vasild vasild force-pushed the test_more_robust_ua_recv_check branch from c1a1690 to 28d26c4 Compare June 28, 2023 16:36
@vasild
Copy link
Contributor Author

vasild commented Jun 28, 2023

c1a169082a...28d26c4f37: take #27986 (comment)

Invalidates ACK from @jonatack

@jonatack
Copy link
Member

jonatack commented Jun 28, 2023

ACK 28d26c4

In `add_p2p_connection()` we connect to `bitcoind` from the Python
client and check that it has received our version string.

This check looked up the last/newest entry from `getpeerinfo` RPC,
assuming that it must be the connection we have just opened. But this
will not be the case if a new inbound or outbound connection is made
to/from `bitcoind` in the meantime.

Instead of the last entry in `getpeerinfo`, check all and find the one
which corresponds to our connection using our outgoing address:port
tuple which is unique.

Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
Co-authored-by: Jon Atack <jon@atack.com>
@vasild vasild force-pushed the test_more_robust_ua_recv_check branch from 28d26c4 to 20b4946 Compare July 6, 2023 15:49
@vasild
Copy link
Contributor Author

vasild commented Jul 6, 2023

28d26c4f37...20b49460b3: take #27986 (comment)

Invalidates ACK from @jonatack

@RandyMcMillan
Copy link
Contributor

Concept ACK

@jonatack
Copy link
Member

jonatack commented Jul 6, 2023

re-ACK 20b4946

@jonatack
Copy link
Member

Anything further needed here?

@maflcko
Copy link
Member

maflcko commented Jul 18, 2023

Concept ACK 20b4946

Probably an edge case, but it seems useful to have this in case connections are opened at the same time for some reason.

@vasild
Copy link
Contributor Author

vasild commented Jul 18, 2023

The tests from #27509 failed because of this which prompted me to open this PR.

@maflcko maflcko added this to the 26.0 milestone Jul 18, 2023
@fanquake fanquake merged commit 0be2f54 into bitcoin:master Jul 19, 2023
@vasild vasild deleted the test_more_robust_ua_recv_check branch July 19, 2023 11:33
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jul 19, 2023
@bitcoin bitcoin locked and limited conversation to collaborators Jul 18, 2024
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