Commit 5b5b974
committed
Fix TOCTOU races in LSPS4 JIT channel flow
process_pending_htlcs and htlc_intercepted both call
calculate_htlc_actions_for_peer independently. When both
observe insufficient capacity on an existing channel, both
emit OpenChannel — opening two JIT channels for one payment.
The timer's role is to retry deferred forwards through channels
that became usable after reestablish, not to open new channels.
Restrict it to forwarding only: if the action set contains a
new channel request, skip and let htlc_intercepted,
peer_connected, or channel_ready handle it.
A second race hid behind non-usable channels appearing in the
capacity map. A still-opening channel advertised high
outbound_capacity, so the HTLC was routed into it. The forward
failed (channel still opening), consuming the InterceptId.
channel_ready fired moments later but found an empty store —
the payment hung until the payer retried. Filter the capacity
map to usable channels only.
A third window exists between the usability check and the
actual forward_intercepted_htlc call: the peer can disconnect
in between, wasting the InterceptId on a doomed forward. Add
a peer liveness check immediately before forwarding so the
HTLC survives for retry on the next timer tick. The residual
sub-millisecond window is acceptable; plumbing connection
state into the channel manager's forward path would be far
more invasive for marginal gain.1 parent c14b445 commit 5b5b974
1 file changed
Lines changed: 53 additions & 42 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
523 | 523 | | |
524 | 524 | | |
525 | 525 | | |
526 | | - | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
527 | 540 | | |
528 | 541 | | |
529 | 542 | | |
| |||
614 | 627 | | |
615 | 628 | | |
616 | 629 | | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
617 | 633 | | |
618 | 634 | | |
619 | 635 | | |
| |||
726 | 742 | | |
727 | 743 | | |
728 | 744 | | |
729 | | - | |
730 | | - | |
731 | | - | |
732 | | - | |
733 | | - | |
734 | | - | |
735 | | - | |
736 | | - | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
737 | 748 | | |
738 | 749 | | |
739 | | - | |
740 | | - | |
741 | | - | |
742 | | - | |
743 | | - | |
744 | | - | |
745 | | - | |
746 | | - | |
747 | | - | |
748 | | - | |
749 | | - | |
750 | | - | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
751 | 754 | | |
| 755 | + | |
752 | 756 | | |
753 | 757 | | |
754 | 758 | | |
| |||
771 | 775 | | |
772 | 776 | | |
773 | 777 | | |
774 | | - | |
| 778 | + | |
| 779 | + | |
775 | 780 | | |
776 | | - | |
| 781 | + | |
| 782 | + | |
777 | 783 | | |
778 | 784 | | |
779 | 785 | | |
780 | | - | |
| 786 | + | |
781 | 787 | | |
782 | | - | |
| 788 | + | |
| 789 | + | |
783 | 790 | | |
784 | 791 | | |
785 | | - | |
| 792 | + | |
| 793 | + | |
786 | 794 | | |
787 | 795 | | |
788 | 796 | | |
789 | 797 | | |
790 | | - | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
791 | 804 | | |
792 | | - | |
793 | | - | |
794 | | - | |
795 | | - | |
796 | | - | |
797 | | - | |
798 | | - | |
799 | | - | |
800 | | - | |
801 | | - | |
802 | | - | |
803 | | - | |
804 | | - | |
805 | | - | |
806 | | - | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
807 | 818 | | |
808 | 819 | | |
809 | 820 | | |
| |||
0 commit comments