Test that we get a reasonable error from sendpay when an onion is bad
(node_factory, bitcoind)
| 2159 | |
| 2160 | |
| 2161 | def test_bad_onion(node_factory, bitcoind): |
| 2162 | """Test that we get a reasonable error from sendpay when an onion is bad""" |
| 2163 | l1, l2, l3, l4 = node_factory.line_graph(4, wait_for_announce=True, |
| 2164 | opts={'log-level': 'io'}) |
| 2165 | |
| 2166 | inv = l4.rpc.invoice(123000, 'test_bad_onion', 'description') |
| 2167 | route = l1.single_route(l4.info['id'], 123000) |
| 2168 | |
| 2169 | assert len(route) == 3 |
| 2170 | |
| 2171 | mangled_nodeid = '0265b6ab5ec860cd257865d61ef0bbf5b3339c36cbda8b26b74e7f1dca490b6518' |
| 2172 | |
| 2173 | # Replace id with a different pubkey, so onion encoded badly at third hop. |
| 2174 | route[2]['node_id_out'] = mangled_nodeid |
| 2175 | l1.rpc.sendpay(route, inv['payment_hash'], payment_secret=inv['payment_secret']) |
| 2176 | with pytest.raises(RpcError) as err: |
| 2177 | l1.rpc.waitsendpay(inv['payment_hash']) |
| 2178 | |
| 2179 | # FIXME: #define PAY_TRY_OTHER_ROUTE 204 |
| 2180 | PAY_TRY_OTHER_ROUTE = 204 |
| 2181 | assert err.value.error['code'] == PAY_TRY_OTHER_ROUTE |
| 2182 | # FIXME: WIRE_INVALID_ONION_HMAC = BADONION|PERM|5 |
| 2183 | WIRE_INVALID_ONION_HMAC = 0x8000 | 0x4000 | 5 |
| 2184 | assert err.value.error['data']['failcode'] == WIRE_INVALID_ONION_HMAC |
| 2185 | assert err.value.error['data']['erring_node'] == mangled_nodeid |
| 2186 | assert err.value.error['data']['erring_channel'] == route[2]['short_channel_id_dir'].split('/')[0] |
| 2187 | |
| 2188 | # We should see a WIRE_UPDATE_FAIL_MALFORMED_HTLC from l4. |
| 2189 | line = l4.daemon.is_in_log(r'\[OUT\] 0087') |
| 2190 | # 008739d3149a5c37e95f9dae718ce46efc60248e110e10117d384870a6762e8e33030000000000000000d7fc52f6c32773aabca55628fe616058aecc44a384e0abfa85c0c48b449dd38dc005 |
| 2191 | # type<--------------channelid---------------------------------------><--htlc-id-----><--------------------------------------------- sha_of_onion --->code |
| 2192 | sha = re.search(r' 0087.{64}.{16}(.{64})', line).group(1) |
| 2193 | |
| 2194 | # Should see same sha in onionreply |
| 2195 | l1.daemon.wait_for_log(r'failcode .* from onionreply .*{sha}'.format(sha=sha)) |
| 2196 | |
| 2197 | # Replace id with a different pubkey, so onion encoded badly at second hop. |
| 2198 | route[1]['node_id_out'] = mangled_nodeid |
| 2199 | l1.rpc.sendpay(route, inv['payment_hash'], payment_secret=inv['payment_secret']) |
| 2200 | with pytest.raises(RpcError) as err: |
| 2201 | l1.rpc.waitsendpay(inv['payment_hash']) |
| 2202 | |
| 2203 | # FIXME: #define PAY_TRY_OTHER_ROUTE 204 |
| 2204 | PAY_TRY_OTHER_ROUTE = 204 |
| 2205 | assert err.value.error['code'] == PAY_TRY_OTHER_ROUTE |
| 2206 | assert err.value.error['data']['failcode'] == WIRE_INVALID_ONION_HMAC |
| 2207 | assert err.value.error['data']['erring_node'] == mangled_nodeid |
| 2208 | assert err.value.error['data']['erring_channel'] == route[1]['short_channel_id_dir'].split('/')[0] |
| 2209 | |
| 2210 | |
| 2211 | def test_bad_onion_immediate_peer(node_factory, bitcoind): |
nothing calls this directly
no test coverage detected