Commit ffdb611
committed
Narrow TOCTOU window in execute_htlc_actions
forward_intercepted_htlc consumes the InterceptId on Ok, but Ok
only means the HTLC was queued internally — the actual send_htlc
can still fail if the peer disconnects before the commitment
update is exchanged. This created two problems:
1. The peer could disconnect between computing actions (usability
check passes) and executing the forward. The forward would
succeed at the LDK API layer but silently fail at send_htlc,
leaving the HTLC in limbo with a consumed InterceptId.
2. Removing the HTLC from the store immediately after Ok meant
the retry timer could never re-attempt it. If the internal
send_htlc failed, the HTLC was lost until a new
HTLCIntercepted event arrived with a fresh InterceptId.
Add a pre-forward peer liveness check to skip forwarding when
the peer has already disconnected. On Ok, keep the HTLC in the
store so the retry timer can detect and re-process it. On Err,
remove it — the InterceptId is consumed or stale, so a new
HTLCIntercepted event will arrive for a fresh retry.
An alternative considered was making forward_intercepted_htlc
itself check peer liveness, but that would require plumbing
connection state into the channel manager's intercept path. The
pre-check here is simpler and sufficient — the residual race
window is sub-millisecond.1 parent c14b445 commit ffdb611
1 file changed
Lines changed: 38 additions & 44 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
726 | 726 | | |
727 | 727 | | |
728 | 728 | | |
729 | | - | |
730 | | - | |
731 | | - | |
732 | | - | |
733 | | - | |
734 | | - | |
735 | | - | |
736 | | - | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
737 | 732 | | |
738 | 733 | | |
739 | | - | |
740 | | - | |
741 | | - | |
742 | | - | |
743 | | - | |
744 | | - | |
745 | | - | |
746 | | - | |
747 | | - | |
748 | | - | |
749 | | - | |
750 | | - | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
751 | 738 | | |
| 739 | + | |
752 | 740 | | |
753 | 741 | | |
754 | 742 | | |
| |||
769 | 757 | | |
770 | 758 | | |
771 | 759 | | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
772 | 767 | | |
773 | 768 | | |
774 | | - | |
| 769 | + | |
775 | 770 | | |
776 | | - | |
| 771 | + | |
| 772 | + | |
777 | 773 | | |
778 | 774 | | |
779 | 775 | | |
780 | | - | |
781 | | - | |
782 | | - | |
783 | | - | |
784 | | - | |
785 | | - | |
786 | | - | |
787 | | - | |
788 | | - | |
789 | | - | |
790 | | - | |
791 | | - | |
792 | | - | |
793 | | - | |
794 | | - | |
795 | | - | |
796 | | - | |
797 | | - | |
798 | | - | |
799 | | - | |
| 776 | + | |
800 | 777 | | |
801 | 778 | | |
802 | | - | |
| 779 | + | |
803 | 780 | | |
804 | | - | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
805 | 784 | | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
806 | 800 | | |
807 | 801 | | |
808 | 802 | | |
| |||
0 commit comments