A peer re-offering the id of an HTLC we have already resolved must be rejected: channeld has forgotten it, but the db has not.
(node_factory)
| 5353 | |
| 5354 | @unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "rewinds the peers' dbs, which are assumed sqlite3") |
| 5355 | def test_peer_reuses_htlc_id(node_factory): |
| 5356 | """A peer re-offering the id of an HTLC we have already resolved must be |
| 5357 | rejected: channeld has forgotten it, but the db has not.""" |
| 5358 | peer_opts = {'may_reconnect': True, |
| 5359 | 'allow_warning': True, |
| 5360 | # We rewind their db behind their back, so they complain. |
| 5361 | 'broken_log': '.*'} |
| 5362 | l1, l2, l3 = node_factory.get_nodes(3, opts=[peer_opts, |
| 5363 | {'may_reconnect': True, |
| 5364 | 'allow_warning': True, |
| 5365 | # Without the fix lightningd |
| 5366 | # dies here, and we want |
| 5367 | # that to be a test failure |
| 5368 | # rather than a teardown |
| 5369 | # error. |
| 5370 | 'may_fail': True, |
| 5371 | 'broken_log': '.*'}, |
| 5372 | peer_opts]) |
| 5373 | node_factory.join_nodes([l1, l2]) |
| 5374 | node_factory.join_nodes([l3, l2]) |
| 5375 | |
| 5376 | # l2 receives, and fully resolves, HTLC id 0 from each of them. |
| 5377 | for peer in (l1, l3): |
| 5378 | peer.pay(l2, 100000) |
| 5379 | peer.wait_for_htlcs() |
| 5380 | l2.wait_for_htlcs() |
| 5381 | |
| 5382 | def rewind(peer): |
| 5383 | # peer forgets it ever offered an HTLC, so it uses id 0 again. |
| 5384 | peer.stop() |
| 5385 | peer.db_manip("DELETE FROM channel_htlcs;") |
| 5386 | peer.db_manip("UPDATE channels SET next_htlc_id=0;") |
| 5387 | |
| 5388 | def reuse_id(peer, label): |
| 5389 | peer.start() |
| 5390 | |
| 5391 | def reestablished(): |
| 5392 | chan = only_one(peer.rpc.listpeerchannels(l2.info['id'])['channels']) |
| 5393 | return any('Reconnected, and reestablished' in s for s in chan['status']) |
| 5394 | wait_for(reestablished) |
| 5395 | |
| 5396 | inv = l2.rpc.invoice(100000, label, 'desc') |
| 5397 | route = [{'amount_msat': 100000, 'id': l2.info['id'], 'delay': 18, |
| 5398 | 'channel': first_scid(peer, l2)}] |
| 5399 | peer.rpc.sendpay(route, inv['payment_hash'], |
| 5400 | payment_secret=inv['payment_secret']) |
| 5401 | line = l2.daemon.wait_for_log(r'{}-.*Bad peer_add_htlc: id 0 but expected 1|Error executing statement'.format(peer.info['id'])) |
| 5402 | assert 'Bad peer_add_htlc' in line |
| 5403 | l2.rpc.getinfo() |
| 5404 | |
| 5405 | # l2's channeld restarts on reconnect, lightningd tells it what to expect. |
| 5406 | rewind(l1) |
| 5407 | reuse_id(l1, 'reuse1') |
| 5408 | # l1 committed to that HTLC, which l2 never accepts, so it's done. |
| 5409 | l1.stop() |
| 5410 | |
| 5411 | # Same again, but l2 has to work out what to expect from its db. |
| 5412 | l2.stop() |
nothing calls this directly
no test coverage detected