Commit 77430bf
committed
Stop re-hydrating pending payments once they are fully resolved
`MonitorEvent`s aren't delivered to the `ChannelManager` in a
durable fasion - if the `ChannelManager` fetches the pending
`MonitorEvent`s, then the `ChannelMonitor` gets persisted (i.e. due
to a block update) then the node crashes, prior to persisting the
`ChannelManager` again, the `MonitorEvent` and its effects on the
`ChannelManger` will be lost. This isn't likely in a sync persist
environment, but in an async one this could be an issue.
Note that this is only an issue for closed channels -
`MonitorEvent`s only inform the `ChannelManager` that a channel is
closed (which the `ChannelManager` will learn on startup or when it
next tries to advance the channel state), that
`ChannelMonitorUpdate` writes completed (which the `ChannelManager`
will detect on startup), or that HTLCs resolved on-chain post
closure. Of the three, only the last is problematic to lose prior
to a reload.
In previous commits we ensured that HTLC resolutions which came to
`ChannelManager` via a `MonitorEvent` were replayed on startup if
the `MonitorEvent` was lost. However, in cases where the
`ChannelManager` was so stale that it didn't have the payment state
for an HTLC at all, we only re-add it in cases where
`ChannelMonitor::get_pending_or_resolved_outbound_htlcs` includes
it.
Because constantly re-adding a payment state and then failing it
would generate lots of noise for users on startup (not to mention
risk of confusing stale payment events for the latest state of a
payment when the `PaymentId` has been reused to retry a payment).
Thus, `get_pending_or_resolved_outbound_htlcs` does not include
state for HTLCs which were resolved on chain with a preimage or
HTLCs which were resolved on chain with a timeout after
`ANTI_REORG_DELAY` confirmations.
This critera matches the critera for generating a `MonitorEvent`,
and works great under the assumption that `MonitorEvent`s are
reliably delivered. However, if they are not, and our
`ChannelManager` is lost or substantially old (or, in a future
where we do not persist `ChannelManager` at all), we will not end
up seeing payment resolution events for an HTLC.
Instead, we really want to tell our `ChannelMonitor`s when the
resolution of an HTLC is complete. Note that we don't particularly
care about non-payment HTLCs, as there is no re-hydration of state
to do there - `ChannelManager` load ignores forwarded HTLCs coming
back from `get_pending_or_resolved_outbound_htlcs` as there's
nothing to do - we always attempt to replay the success/failure and
figure out if it mattered based on whether there was still an HTLC
to claim/fail.
Here we, finally, begin actually using the new
`ChannelMonitorUpdateStep::ReleasePaymentComplete` updates,
skipping re-hydration of pending payments once they have been fully
resolved through to a user `Event`.
Backport of 226520b
Fixed conflicts in:
* lightning/src/chain/channelmonitor.rs
* lightning/src/ln/channelmanager.rs
* lightning/src/ln/functional_tests.rs to address differences
causing upstream to (somewhat spuriously) generate
`ChannelMonitorUpdate`s for channels force-closed by commitment
transaction confirmation whereas this branch does not,
* lightning/src/ln/payment_tests.rs1 parent e64ed33 commit 77430bf
File tree
4 files changed
+58
-126
lines changed- lightning/src
- chain
- ln
4 files changed
+58
-126
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2577 | 2577 | | |
2578 | 2578 | | |
2579 | 2579 | | |
2580 | | - | |
2581 | | - | |
2582 | | - | |
2583 | | - | |
2584 | 2580 | | |
2585 | 2581 | | |
2586 | 2582 | | |
| |||
2593 | 2589 | | |
2594 | 2590 | | |
2595 | 2591 | | |
2596 | | - | |
2597 | | - | |
| 2592 | + | |
| 2593 | + | |
| 2594 | + | |
| 2595 | + | |
| 2596 | + | |
2598 | 2597 | | |
2599 | 2598 | | |
2600 | 2599 | | |
| |||
2650 | 2649 | | |
2651 | 2650 | | |
2652 | 2651 | | |
| 2652 | + | |
| 2653 | + | |
| 2654 | + | |
| 2655 | + | |
| 2656 | + | |
2653 | 2657 | | |
2654 | 2658 | | |
2655 | 2659 | | |
| |||
2724 | 2728 | | |
2725 | 2729 | | |
2726 | 2730 | | |
2727 | | - | |
2728 | | - | |
2729 | | - | |
2730 | | - | |
2731 | | - | |
2732 | | - | |
2733 | | - | |
2734 | | - | |
2735 | | - | |
2736 | | - | |
2737 | | - | |
2738 | | - | |
2739 | | - | |
2740 | | - | |
2741 | | - | |
2742 | | - | |
2743 | | - | |
2744 | | - | |
2745 | | - | |
2746 | | - | |
2747 | | - | |
2748 | | - | |
2749 | | - | |
2750 | | - | |
2751 | | - | |
2752 | | - | |
2753 | | - | |
2754 | | - | |
2755 | | - | |
2756 | | - | |
2757 | | - | |
2758 | | - | |
2759 | | - | |
2760 | | - | |
2761 | | - | |
2762 | | - | |
2763 | | - | |
2764 | | - | |
2765 | | - | |
2766 | | - | |
2767 | | - | |
2768 | | - | |
2769 | | - | |
2770 | | - | |
2771 | | - | |
2772 | | - | |
2773 | | - | |
2774 | | - | |
2775 | | - | |
2776 | | - | |
2777 | | - | |
2778 | | - | |
2779 | | - | |
2780 | | - | |
2781 | | - | |
2782 | | - | |
2783 | | - | |
2784 | | - | |
2785 | | - | |
2786 | | - | |
2787 | | - | |
2788 | | - | |
2789 | | - | |
2790 | | - | |
2791 | | - | |
2792 | | - | |
2793 | | - | |
2794 | | - | |
2795 | | - | |
2796 | | - | |
2797 | | - | |
2798 | | - | |
2799 | | - | |
2800 | | - | |
2801 | | - | |
2802 | | - | |
2803 | | - | |
2804 | | - | |
2805 | | - | |
2806 | | - | |
2807 | | - | |
2808 | | - | |
2809 | | - | |
2810 | | - | |
2811 | | - | |
2812 | | - | |
2813 | | - | |
2814 | 2731 | | |
2815 | 2732 | | |
2816 | 2733 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14064 | 14064 | | |
14065 | 14065 | | |
14066 | 14066 | | |
14067 | | - | |
| 14067 | + | |
14068 | 14068 | | |
14069 | 14069 | | |
14070 | 14070 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3711 | 3711 | | |
3712 | 3712 | | |
3713 | 3713 | | |
| 3714 | + | |
| 3715 | + | |
3714 | 3716 | | |
3715 | 3717 | | |
3716 | 3718 | | |
| |||
3727 | 3729 | | |
3728 | 3730 | | |
3729 | 3731 | | |
3730 | | - | |
| 3732 | + | |
3731 | 3733 | | |
3732 | 3734 | | |
3733 | 3735 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
973 | 973 | | |
974 | 974 | | |
975 | 975 | | |
976 | | - | |
977 | | - | |
978 | | - | |
979 | 976 | | |
980 | 977 | | |
981 | 978 | | |
| |||
1005 | 1002 | | |
1006 | 1003 | | |
1007 | 1004 | | |
1008 | | - | |
1009 | | - | |
1010 | | - | |
1011 | 1005 | | |
1012 | 1006 | | |
1013 | 1007 | | |
| |||
1024 | 1018 | | |
1025 | 1019 | | |
1026 | 1020 | | |
1027 | | - | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
1028 | 1025 | | |
1029 | 1026 | | |
1030 | 1027 | | |
| |||
1115 | 1112 | | |
1116 | 1113 | | |
1117 | 1114 | | |
1118 | | - | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
1119 | 1119 | | |
1120 | 1120 | | |
1121 | 1121 | | |
1122 | 1122 | | |
1123 | 1123 | | |
1124 | 1124 | | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
1125 | 1130 | | |
1126 | 1131 | | |
1127 | 1132 | | |
1128 | 1133 | | |
1129 | 1134 | | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
1130 | 1139 | | |
1131 | 1140 | | |
1132 | 1141 | | |
1133 | | - | |
| 1142 | + | |
1134 | 1143 | | |
1135 | 1144 | | |
1136 | | - | |
| 1145 | + | |
1137 | 1146 | | |
1138 | | - | |
| 1147 | + | |
1139 | 1148 | | |
1140 | | - | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
1141 | 1153 | | |
| 1154 | + | |
1142 | 1155 | | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
1143 | 1161 | | |
1144 | | - | |
1145 | | - | |
1146 | | - | |
1147 | | - | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
1148 | 1167 | | |
1149 | 1168 | | |
1150 | 1169 | | |
| |||
1158 | 1177 | | |
1159 | 1178 | | |
1160 | 1179 | | |
1161 | | - | |
1162 | | - | |
1163 | | - | |
1164 | | - | |
1165 | | - | |
1166 | | - | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
1167 | 1189 | | |
1168 | 1190 | | |
1169 | 1191 | | |
| |||
3513 | 3535 | | |
3514 | 3536 | | |
3515 | 3537 | | |
3516 | | - | |
3517 | | - | |
3518 | | - | |
3519 | | - | |
3520 | 3538 | | |
3521 | | - | |
3522 | 3539 | | |
3523 | 3540 | | |
3524 | | - | |
3525 | 3541 | | |
3526 | 3542 | | |
3527 | 3543 | | |
| |||
3536 | 3552 | | |
3537 | 3553 | | |
3538 | 3554 | | |
3539 | | - | |
3540 | | - | |
3541 | | - | |
3542 | 3555 | | |
3543 | 3556 | | |
3544 | 3557 | | |
| |||
0 commit comments