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

Function test_remote_addr

tests/test_connection.py:81–154  ·  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

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