Skip to content

Conversation

pinheadmz
Copy link
Member

@pinheadmz pinheadmz commented Apr 12, 2023

Closes #27140

Adds test coverage for #20516 to ensure that #20511 is completed and may be closed.

This PR adds a test case to feature_anchors.py where an onion v3 address is set as a blocks-only relay peer and then shutdown, ensuring that the address is saved to anchors.dat in addrv2 format. We then ensure that bitcoin attempts to reconnect to that anchor address on restart.

To compute the addrv2 serialization of the onion v3 address, I added logic to CAddress in messages.py. This new logic is covered by extending p2p_addrv2_relay.py to include an onion v3 address. Future work will be adding coverage for ipv6, torv2 and cjdns in these modules and also feature_proxy.py

Also includes de/serialization unit test for CAddress in test framework.

@DrahtBot
Copy link
Contributor

DrahtBot commented Apr 12, 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, brunoerg, willcl-ark
Concept ACK edgardot14y
Approach ACK vasild

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #27509 (Relay own transactions only via short-lived Tor or I2P connections by vasild)

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.

@brunoerg
Copy link
Contributor

Did you take a look at #27295?

@pinheadmz
Copy link
Member Author

Did you take a look at #27295?

I will now!


self.log.info("Check peer info")
peer_info = self.nodes[0].getpeerinfo()
assert len(peer_info) == 1
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you could use assert_equal here and in the other similar cases

Suggested change
assert len(peer_info) == 1
assert_equal(len(peer_info), 1)

Copy link
Member Author

Choose a reason for hiding this comment

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

sure, done thanks!

Copy link
Contributor

@brunoerg brunoerg 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

@meuamigopedro

This comment was marked as spam.

@pinheadmz pinheadmz force-pushed the test-anchors-addrv2 branch from f06f28a to 076a36e Compare April 12, 2023 18:34
@pinheadmz pinheadmz force-pushed the test-anchors-addrv2 branch from 076a36e to 210d57c Compare May 31, 2023 14:14
@pinheadmz
Copy link
Member Author

Thanks for the review Will, nits addressed and pushed

@vasild
Copy link
Contributor

vasild commented Jun 1, 2023

Concept ACK, I guess we can forget about Torv2 and completely drop support about it from everywhere as if it never existed. The Tor network does not support those anymore.

onion_conf = Socks5Configuration()
onion_conf.auth = True
onion_conf.unauth = True
onion_conf.addr = ('127.0.0.1', 10000)
Copy link
Contributor

@vasild vasild Jun 1, 2023

Choose a reason for hiding this comment

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

This could collide with another port randomly assigned by the testing framework (even if it looks like that it currently cannot, it may do in the future) and also could collide with another instance of this test run in parallel on the same machine. Better use p2p_port().

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks, fixed.

Comment on lines 126 to 136
with open(node_anchors_path, "wb") as file_handler:
# Cheat: modify service flags for this address
# even though we never connected to it
new_data = bytearray(data)[:-32]
new_data[services_index] = P2P_SERVICES
new_data_hash = hash256(new_data)
file_handler.write(new_data + new_data_hash)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is it necessary to modify the services?

Copy link
Member Author

Choose a reason for hiding this comment

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

We won't attempt an anchor connection to a host that doesn't have services:

!HasAllDesirableServiceFlags(addr.nServices) ||

In the test we don't actually bother setting up a listening node at the onion address we connect to with block-relay-only so the services remain null, even though we do still write the host information to anchors.dat

I use this hack to ensure that we attempt a connection, and the last assertion in the test will fail without it

Copy link
Member

Choose a reason for hiding this comment

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

I think it would be helpful to explain this in the test.

@pinheadmz pinheadmz force-pushed the test-anchors-addrv2 branch 3 times, most recently from 4a1fb18 to 0a10285 Compare June 3, 2023 00:55
@DrahtBot DrahtBot removed the CI failed label Jun 3, 2023
@jonatack
Copy link
Member

jonatack commented Jun 22, 2023

Concept ACK, I guess we can forget about Torv2 and completely drop support about it from everywhere as if it never existed. The Tor network does not support those anymore.

Concept ACK. Did you plan to drop the Tor v2 additions here? (No need to add code that we'll just remove.)

As mentioned in #27295 (review), I'm not sure how this was coordinated with that pull, and these changes could possibly be split into preparatory changes (insofar as they don't break any tests) and implementation commits.

@pinheadmz pinheadmz force-pushed the test-anchors-addrv2 branch from 0a10285 to 455f8c4 Compare June 23, 2023 16:45
@pinheadmz
Copy link
Member Author

@brunoerg @jonatack thanks for your reviews, pushing to 455f8c4:

Includes and expands on #27295 including a unit test to de- and re-serialize CAddress from every network type. TorV2 is also completely dropped from the test framework.

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

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

Approach ACK b5e0398

Comment on lines 302 to 304
assert self.net in (self.NET_IPV4, self.NET_IPV6,
self.NET_I2P, self.NET_CJDNS,
self.NET_TORV3)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this use self.ADDRV2_NET_NAME?

Suggested change
assert self.net in (self.NET_IPV4, self.NET_IPV6,
self.NET_I2P, self.NET_CJDNS,
self.NET_TORV3)
assert self.net in self.ADDRV2_NET_NAME

Copy link
Member Author

Choose a reason for hiding this comment

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

yes thanks

Comment on lines -124 to +126
self.conn.close()
if not self.serv.keep_alive:
self.conn.close()
Copy link
Contributor

Choose a reason for hiding this comment

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

When would this socket be closed if keep_alive is true?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question, I'm just letting it drop out of scope at the end of the test, but looking into it more it may actually be staying alive until the entire test runner exits.

Should I add a manual close function?

Copy link
Member Author

Choose a reason for hiding this comment

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

update: no longer needed

Copy link
Member Author

Choose a reason for hiding this comment

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

update update: manually calling onion_proxy.close() in the test now with a comment

else:
addr.ip = f"123.123.123.{i % 256}"
addr.port = 8333 + i
msg_size += addr.ADDRV2_ADDRESS_LENGTH[addr.NET_IPV4]
msg_size += 4 + 1 + 1 + 2 + 1 # time, services, networkID, port, address length byte
Copy link
Contributor

Choose a reason for hiding this comment

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

The port is serialized last, but in the comment is comes after networkID. Would it be better to calculate the message size separately, given an array of addresses as input?

[patch] calculate addrv2 message size separately
diff --git i/test/functional/p2p_addrv2_relay.py w/test/functional/p2p_addrv2_relay.py
index 23d7c94fd0..f9a8c44be2 100755
--- i/test/functional/p2p_addrv2_relay.py
+++ w/test/functional/p2p_addrv2_relay.py
@@ -20,32 +20,27 @@ from test_framework.test_framework import BitcoinTestFramework
 from test_framework.util import assert_equal
 
 I2P_ADDR = "c4gfnttsuwqomiygupdqqqyy5y5emnk5c73hrfvatri67prd7vyq.b32.i2p"
 ONION_ADDR = "pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion"
 
 ADDRS = []
-msg_size = 1  # vector length byte
 for i in range(10):
     addr = CAddress()
     addr.time = int(time.time()) + i
     addr.port = 8333 + i
     addr.nServices = P2P_SERVICES
     # Add one I2P and one onion V3 address at an arbitrary position.
     if i == 5:
         addr.net = addr.NET_I2P
         addr.ip = I2P_ADDR
         addr.port = 0
-        msg_size += addr.ADDRV2_ADDRESS_LENGTH[addr.NET_I2P]
     elif i == 8:
         addr.net = addr.NET_TORV3
         addr.ip = ONION_ADDR
-        msg_size += addr.ADDRV2_ADDRESS_LENGTH[addr.NET_TORV3]
     else:
         addr.ip = f"123.123.123.{i % 256}"
-        msg_size += addr.ADDRV2_ADDRESS_LENGTH[addr.NET_IPV4]
-    msg_size += 4 + 1 + 1 + 2 + 1  # time, services, networkID, port, address length byte
     ADDRS.append(addr)
 
 
 class AddrReceiver(P2PInterface):
     addrv2_received_and_checked = False
 
@@ -59,12 +54,23 @@ class AddrReceiver(P2PInterface):
             self.addrv2_received_and_checked = True
 
     def wait_for_addrv2(self):
         self.wait_until(lambda: "addrv2" in self.last_message)
 
 
+def calc_addrv2_msg_size(addrs):
+    size = 1  # vector length byte
+    for addr in addrs:
+        size += 4  # time
+        size += 1  # services, COMPACTSIZE(P2P_SERVICES)
+        size += 1  # network id
+        size += 1  # address length byte
+        size += addr.ADDRV2_ADDRESS_LENGTH[addr.net]  # address
+        size += 2  # port
+    return size
+
 class AddrTest(BitcoinTestFramework):
     def set_test_params(self):
         self.setup_clean_chain = True
         self.num_nodes = 1
         self.extra_args = [["-whitelist=addr@127.0.0.1"]]
 
@@ -78,12 +84,13 @@ class AddrTest(BitcoinTestFramework):
         with self.nodes[0].assert_debug_log(['addrv2 message size = 1010']):
             addr_source.send_and_ping(msg)
 
         self.log.info('Check that addrv2 message content is relayed and added to addrman')
         addr_receiver = self.nodes[0].add_p2p_connection(AddrReceiver())
         msg.addrs = ADDRS
+        msg_size = calc_addrv2_msg_size(ADDRS)
         with self.nodes[0].assert_debug_log([
                 f'received: addrv2 ({msg_size} bytes) peer=0',
                 f'sending addrv2 ({msg_size} bytes) peer=1',
         ]):
             addr_source.send_and_ping(msg)
             self.nodes[0].setmocktime(int(time.time()) + 30 * 60)

Copy link
Member Author

Choose a reason for hiding this comment

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

fantastic, thanks for the patch

Comment on lines 100 to 110
self.restart_node(0, extra_args=[f"-onion={onion_conf.addr[0]}:{onion_conf.addr[1]}"])

self.log.info(f"Add 256-bit-address block-relay-only connections to node")
ONION_ADDR = "pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion:8333"
self.nodes[0].addconnection(ONION_ADDR, 'block-relay-only')

self.log.info("Check peer info")
peer_info = self.nodes[0].getpeerinfo()
assert_equal(len(peer_info), 1)
assert_equal(peer_info[0]["network"], "onion")
assert_equal(peer_info[0]["connection_type"], "block-relay-only")
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this suffice to ensure 1 block-only was opened:

[patch] check log at shutdown
diff --git i/test/functional/feature_anchors.py w/test/functional/feature_anchors.py
index e7cd642484..327533a340 100755
--- i/test/functional/feature_anchors.py
+++ w/test/functional/feature_anchors.py
@@ -91,29 +91,23 @@ class AnchorsTest(BitcoinTestFramework):
         self.log.info("Ensure addrv2 support")
         # Use proxies to catch outbound connections to networks with 256-bit addresses
         onion_conf = Socks5Configuration()
         onion_conf.auth = True
         onion_conf.unauth = True
         onion_conf.addr = ('127.0.0.1', p2p_port(self.num_nodes))
-        onion_conf.keep_alive = True
         onion_proxy = Socks5Server(onion_conf)
         onion_proxy.start()
         self.restart_node(0, extra_args=[f"-onion={onion_conf.addr[0]}:{onion_conf.addr[1]}"])
 
         self.log.info(f"Add 256-bit-address block-relay-only connections to node")
         ONION_ADDR = "pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion:8333"
         self.nodes[0].addconnection(ONION_ADDR, 'block-relay-only')
 
-        self.log.info("Check peer info")
-        peer_info = self.nodes[0].getpeerinfo()
-        assert_equal(len(peer_info), 1)
-        assert_equal(peer_info[0]["network"], "onion")
-        assert_equal(peer_info[0]["connection_type"], "block-relay-only")
-
         self.log.info("Stop node 0")
-        self.stop_node(0)
+        with self.nodes[0].assert_debug_log([f"DumpAnchors: Flush 1 outbound block-relay-only peer addresses to anchors.dat"]):
+            self.stop_node(0)
 
         self.log.info("Check for addrv2 addresses in anchors.dat")
         caddr = CAddress()
         caddr.net = CAddress.NET_TORV3
         [caddr.ip, port_str] = ONION_ADDR.split(":")
         caddr.port = int(port_str)

If "yes", then no need for keep_alive.

Copy link
Member Author

@pinheadmz pinheadmz Jul 5, 2023

Choose a reason for hiding this comment

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

oh sweet! awesome, i'll remove the socks5.py commit and apply this instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

https://cirrus-ci.com/task/5531648075235328?logs=ci#L4421

Actually there is still a race condition there. I think the keep_alive is necessary for bitcoind to even acknowledge the blocks only peer exists. We can use debug log or getpeerinfo but seems like either way the socks proxy is closing too soon

self.nodes[0].addconnection(ONION_ADDR, 'block-relay-only')

self.log.info("Stop node 0")
with self.nodes[0].assert_debug_log([f"DumpAnchors: Flush 1 outbound block-relay-only peer addresses to anchors.dat"]):
Copy link
Member

Choose a reason for hiding this comment

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

CI failing at this line.

https://cirrus-ci.com/task/5531648075235328?logs=ci#L3397
https://cirrus-ci.com/task/5531648075235328?logs=ci#L4424

Expected messages "['DumpAnchors: Flush 1 outbound block-relay-only peer addresses to anchors.dat']" does not partially match log:

 - 2023-07-05T18:23:01.237732Z [shutoff] [logging/timer.h:56] [Log] DumpAnchors: Flush 0 outbound block-relay-only peer addresses to anchors.dat started
 - 2023-07-05T18:23:01.286842Z [shutoff] [logging/timer.h:56] [Log] DumpAnchors: Flush 0 outbound block-relay-only peer addresses to anchors.dat completed 

Copy link
Member

Choose a reason for hiding this comment

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

Reproduced this test failure locally on the 4th run of test/functional/feature_anchors.py (arm64 macOS 13.4.1)

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed :-( see #27452 (comment) unless @vasild disagrees I'll revert part of my last update and put keep_alive back in socks5.py

@pinheadmz pinheadmz force-pushed the test-anchors-addrv2 branch from 991a478 to 805692f Compare July 7, 2023 15:24
@pinheadmz
Copy link
Member Author

@jonatack @vasild thanks for reviewing guys. I put back the keep_alive option to ensure the onion peer is logged, expecting successful CI on this push 🤞

@DrahtBot DrahtBot removed the CI failed label Jul 7, 2023
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.

Tested Approach ACK

@@ -80,6 +80,7 @@
"ripemd160",
"script",
"segwit_addr",
"messages"
Copy link
Member

Choose a reason for hiding this comment

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

f6bd653

suggested diff

@@ -76,11 +76,11 @@ TEST_FRAMEWORK_MODULES = [
     "blocktools",
     "ellswift",
     "key",
+    "messages",
     "muhash",
     "ripemd160",
     "script",
     "segwit_addr",
-    "messages"
 ]

(Also, project convention is to leave a comma after the last element, to minimize the diff in future changes)

@@ -1852,3 +1887,23 @@ def serialize(self):
def __repr__(self):
return "msg_sendtxrcncl(version=%lu, salt=%lu)" %\
(self.version, self.salt)

class TestFrameworkScript(unittest.TestCase):
def test_addrv2encodedecode(self):
Copy link
Member

Choose a reason for hiding this comment

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

f6bd653 naming, this would be more readable in case of a test failure (also, remove 2 extra LF at EOF)

diff

 class TestFrameworkScript(unittest.TestCase):
-    def test_addrv2encodedecode(self):
+    def test_addrv2_encode_decode(self):
         def check_addrv2(ip, net):
@@ -1905,5 +1905,3 @@ class TestFrameworkScript(unittest.TestCase):
         check_addrv2("fc32:17ea:e415:c3bf:9808:149d:b5a2:c9aa", CAddress.NET_CJDNS)
-
-
Running Unit Tests for Test Framework Modules
................E
======================================================================
ERROR: test_addrv2_encode_decode (test_framework.messages.TestFrameworkScript.test_addrv2_encode_decode)
----------------------------------------------------------------------

actual = CAddress()
actual.deserialize_v2(BytesIO(ser))
self.assertEqual(actual.ip, ip)
self.assertEqual(actual.net, net)
Copy link
Member

Choose a reason for hiding this comment

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

f6bd653 nit, can be simplified

diff

         def check_addrv2(ip, net):
             addr = CAddress()
-            addr.net = net
-            addr.ip = ip
+            addr.net, addr.ip = net, ip
             ser = addr.serialize_v2()
             actual = CAddress()
             actual.deserialize_v2(BytesIO(ser))
-            self.assertEqual(actual.ip, ip)
-            self.assertEqual(actual.net, net)
+            self.assertEqual(actual, addr)


self.log.info("Restarting node attempts to reconnect to anchors")
with self.nodes[0].assert_debug_log([f"Trying to make an anchor connection to {ONION_ADDR}"]):
self.start_node(0, extra_args=[f"-onion={onion_conf.addr[0]}:{onion_conf.addr[1]}"])
Copy link
Member

@jonatack jonatack Jul 7, 2023

Choose a reason for hiding this comment

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

805692f

Various suggestions

diff --git a/test/functional/feature_anchors.py b/test/functional/feature_anchors.py
index 6c97eed9d86..87c6082b3e0 100755
--- a/test/functional/feature_anchors.py
+++ b/test/functional/feature_anchors.py
@@ -14,6 +14,7 @@ from test_framework.util import check_node_connections, assert_equal, p2p_port
 
 INBOUND_CONNECTIONS = 5
 BLOCK_RELAY_CONNECTIONS = 2
+ONION_ADDR = "pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion:8333"
 
 
 class AnchorsTest(BitcoinTestFramework):
@@ -56,7 +57,7 @@ class AnchorsTest(BitcoinTestFramework):
             else:
                 inbound_nodes_port.append(hex(int(addr_split[1]))[2:])
 
-        self.log.info("Stop node 0")
+        self.log.debug("Stop node")
         self.stop_node(0)
 
         # It should contain only the block-relay-only addresses
@@ -80,7 +81,7 @@ class AnchorsTest(BitcoinTestFramework):
                 tweaked_contents[20:20] = b'1'
                 out_file_handler.write(bytes(tweaked_contents))
 
-            self.log.info("Start node")
+            self.log.debug("Start node")
             self.start_node(0)
 
         self.log.info("When node starts, check if anchors.dat doesn't exist anymore")
@@ -97,11 +98,9 @@ class AnchorsTest(BitcoinTestFramework):
         onion_proxy.start()
         self.restart_node(0, extra_args=[f"-onion={onion_conf.addr[0]}:{onion_conf.addr[1]}"])
 
-        self.log.info(f"Add 256-bit-address block-relay-only connections to node")
-        ONION_ADDR = "pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion:8333"
+        self.log.info("Add 256-bit-address block-relay-only connection to node")
         self.nodes[0].addconnection(ONION_ADDR, 'block-relay-only')
-
-        self.log.info("Stop node 0")
+        self.log.debug("Stop node")
         with self.nodes[0].assert_debug_log([f"DumpAnchors: Flush 1 outbound block-relay-only peer addresses to anchors.dat"]):
             self.stop_node(0)
         # Manually close keep_alive proxy connection
@@ -110,7 +109,7 @@ class AnchorsTest(BitcoinTestFramework):
         self.log.info("Check for addrv2 addresses in anchors.dat")
         caddr = CAddress()
         caddr.net = CAddress.NET_TORV3
-        [caddr.ip, port_str] = ONION_ADDR.split(":")
+        caddr.ip, port_str = ONION_ADDR.split(":")
         caddr.port = int(port_str)
         # TorV3 addrv2 serialization:
         # time(4) | services(1) | networkID(1) | address length(1) | address(32)
@@ -122,7 +121,7 @@ class AnchorsTest(BitcoinTestFramework):
         data = bytes()
         with open(node_anchors_path, "rb") as file_handler:
             data = file_handler.read()
-            assert_equal(data[services_index], 0x00) # services == NONE
+            assert_equal(data[services_index], 0x00)  # services == NONE
             anchors2 = data.hex()
             assert expected_pubkey in anchors2

@@ -138,5 +138,6 @@ class AnchorsTest(BitcoinTestFramework):
         with self.nodes[0].assert_debug_log([f"Trying to make an anchor connection to {ONION_ADDR}"]):
             self.start_node(0, extra_args=[f"-onion={onion_conf.addr[0]}:{onion_conf.addr[1]}"])
+

if __name__ == "__main__":
     AnchorsTest().main()

--- a/test/functional/test_framework/socks5.py
+++ b/test/functional/test_framework/socks5.py
@@ -116,7 +116,7 @@ class Socks5Connection():
 
             cmdin = Socks5Command(cmd, atyp, addr, port, username, password)
             self.serv.queue.put(cmdin)
-            logger.info('Proxy: %s', cmdin)
+            logger.debug('Proxy: %s', cmdin)
             # Fall through to disconnect
         except Exception as e:
             logger.exception("socks5 request handling failed.")
@@ -160,4 +160,3 @@ class Socks5Server():
         s.connect(self.conf.addr)
         s.close()
         self.thread.join()
-

(the newline changes are on purpose)

Comment on lines 126 to 136
with open(node_anchors_path, "wb") as file_handler:
# Cheat: modify service flags for this address
# even though we never connected to it
new_data = bytearray(data)[:-32]
new_data[services_index] = P2P_SERVICES
new_data_hash = hash256(new_data)
file_handler.write(new_data + new_data_hash)
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be helpful to explain this in the test.

brunoerg and others added 3 commits July 10, 2023 10:07
Also removes TorV2 from messages.py
See bitcoin#22050

Co-authored-by: Matthew Zipkin <pinheadmz@gmail.com>
The Socks5 server we use in the test framework would disconnect
by default immediately after the handshake and sometimes would
not register as a connected peer by bitcoind.
@pinheadmz pinheadmz force-pushed the test-anchors-addrv2 branch from 805692f to a5c9e05 Compare July 10, 2023 14:28
@pinheadmz
Copy link
Member Author

@jonatack thank you sir for the great review and suggested patches, all nits addressed

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.

ACK a5c9e05

@pinheadmz pinheadmz force-pushed the test-anchors-addrv2 branch from a5c9e05 to ba8ab4f Compare July 19, 2023 17:25
@jonatack
Copy link
Member

ACK ba8ab4f

Copy link
Contributor

@brunoerg brunoerg left a comment

Choose a reason for hiding this comment

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

crACK ba8ab4f

code lgtm!

Copy link
Member

@willcl-ark willcl-ark left a comment

Choose a reason for hiding this comment

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

ACK ba8ab4f

Nice to have this additional coverage for TorV3 addresses 👍🏼

It's not intruduced by this PR, but I notice a mypy error in feature_anchors.py where a tuple is assigned to onion_conf.addr which is initialized to None in socks5.py.

image

If you do end up re-touching this for some reason, you can fix the warning by specifying the type of .addr in socks5.py (which will also fix the other 3 ocurrences of it in the tests):

diff --git a/test/functional/test_framework/socks5.py b/test/functional/test_framework/socks5.py
index 0ca06a7396..5315f39142 100644
--- a/test/functional/test_framework/socks5.py
+++ b/test/functional/test_framework/socks5.py
@@ -8,6 +8,7 @@ import socket
 import threading
 import queue
 import logging
+from typing import Tuple
 
 logger = logging.getLogger("TestFramework.socks5")
 
@@ -36,7 +37,7 @@ def recvall(s, n):
 class Socks5Configuration():
     """Proxy configuration."""
     def __init__(self):
-        self.addr = None # Bind address (must be set)
+        self.addr: Tuple[str, int] # Bind address (must be set)
         self.af = socket.AF_INET # Bind address family
         self.unauth = False  # Support unauthenticated
         self.auth = False  # Support authentication

@fanquake fanquake merged commit 2fa60f0 into bitcoin:master Aug 2, 2023
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 9, 2023
@bitcoin bitcoin locked and limited conversation to collaborators Aug 2, 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.

Add support for all networks in deserialize_v2 in test_framework
8 participants