MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_remote_addr

Function test_remote_addr

tests/test_connection.py:62–147  ·  view source on GitHub ↗

Check address discovery (BOLT1 #917) init remote_addr works as designed: `node_announcement` update must only be send out when: - at least two peers - we have a channel with - report the same `remote_addr` We perform logic tests on L2, setup: l1 -->

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

60
61@pytest.mark.developer("needs DEVELOPER=1 for fast gossip and --dev-allow-localhost for local remote_addr")
62def test_remote_addr(node_factory, bitcoind):
63 """Check address discovery (BOLT1 #917) init remote_addr works as designed:
64
65 `node_announcement` update must only be send out when:
66 - at least two peers
67 - we have a channel with
68 - report the same `remote_addr`
69
70 We perform logic tests on L2, setup:
71 l1 --> [l2] <-- l3
72 """
73 # don't announce anything per se
74 opts = {'may_reconnect': True,
75 'dev-allow-localhost': None,
76 'dev-no-reconnect': None}
77 l1, l2, l3 = node_factory.get_nodes(3, opts)
78
79 # Disable announcing local autobind addresses with dev-allow-localhost.
80 # We need to have l2 opts 'bind-addr' to the (generated) value of 'addr'.
81 # So we stop, set 'bind-addr' option, delete 'addr' and restart first.
82 l2.stop()
83 l2.daemon.opts['bind-addr'] = l2.daemon.opts['addr']
84 del l2.daemon.opts['addr']
85 l2.start()
86 assert len(l2.rpc.getinfo()['address']) == 0
87
88 l2.rpc.connect(l1.info['id'], 'localhost', l1.port)
89 logmsg = l2.daemon.wait_for_log("Peer says it sees our address as: 127.0.0.1:[0-9]{5}")
90 # check 'listpeers' contains the 'remote_addr' as logged
91 assert logmsg.endswith(l2.rpc.listpeers()['peers'][0]['remote_addr'])
92
93 # Fund first channel so initial node_announcement is send
94 # and also check no addresses have been announced yet
95 l1.fundchannel(l2)
96 bitcoind.generate_block(5)
97 l1.daemon.wait_for_log(f"Received node_announcement for node {l2.info['id']}")
98 assert(len(l1.rpc.listnodes(l2.info['id'])['nodes'][0]['addresses']) == 0)
99 assert len(l2.rpc.getinfo()['address']) == 0
100
101 def_port = default_ln_port(l2.info["network"])
102
103 # when we restart l1 with a channel and reconnect, node_annoucement update
104 # must not yet be send as we need the same `remote_addr` confirmed from a
105 # another peer we have a channel with.
106 # Note: In this state l2 stores remote_addr as reported by l1
107 assert not l2.daemon.is_in_log("Update our node_announcement for discovered address: 127.0.0.1:{}".format(def_port))
108 l1.restart()
109 l2.rpc.connect(l1.info['id'], 'localhost', l1.port)
110 l2.daemon.wait_for_log("Peer says it sees our address as: 127.0.0.1:[0-9]{5}")
111
112 # Now l1 sees l2 but without announced addresses.
113 assert(len(l1.rpc.listnodes(l2.info['id'])['nodes'][0]['addresses']) == 0)
114 assert not l2.daemon.is_in_log("Update our node_announcement for discovered address: 127.0.0.1:{}".format(def_port))
115 assert len(l2.rpc.getinfo()['address']) == 0
116
117 # connect second node. This will not yet trigger `node_annoucement` update,
118 # as we again do not have a channel at the time we connected.
119 l2.rpc.connect(l3.info['id'], 'localhost', l3.port)

Callers

nothing calls this directly

Calls 13

default_ln_portFunction · 0.90
get_nodesMethod · 0.80
wait_for_logMethod · 0.80
generate_blockMethod · 0.80
is_in_logMethod · 0.80
restartMethod · 0.80
stopMethod · 0.45
startMethod · 0.45
getinfoMethod · 0.45
connectMethod · 0.45
listpeersMethod · 0.45
fundchannelMethod · 0.45

Tested by

no test coverage detected