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

Function test_remote_addr

tests/test_connection.py:74–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

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