Commit f94de18
committed
Delay RAA-after-next processing until PaymentSent is are handled
In 0ad1f4c we fixed a nasty bug
where a failure to persist a `ChannelManager` faster than a
`ChannelMonitor` could result in the loss of a `PaymentSent` event,
eventually resulting in a `PaymentFailed` instead!
As noted in that commit, there's still some risk, though its been
substantially reduced - if we receive an `update_fulfill_htlc`
message for an outbound payment, and persist the initial removal
`ChannelMonitorUpdate`, then respond with our own
`commitment_signed` + `revoke_and_ack`, followed by receiving our
peer's final `revoke_and_ack`, and then persist the
`ChannelMonitorUpdate` generated from that, all prior to completing
a `ChannelManager` persistence, we'll still forget the HTLC and
eventually trigger a `PaymentFailed` rather than the correct
`PaymentSent`.
Here we fully fix the issue by delaying the final
`ChannelMonitorUpdate` persistence until the `PaymentSent` event
has been processed and document the fact that a spurious
`PaymentFailed` event can still be generated for a sent payment.
The original fix in 0ad1f4c is
still incredibly useful here, allowing us to avoid blocking the
first `ChannelMonitorUpdate` until the event processing completes,
as this would cause us to add event-processing delay in our general
commitment update latency. Instead, we ultimately race the user
handling the `PaymentSent` event with how long it takes our
`revoke_and_ack` + `commitment_signed` to make it to our
counterparty and receive the response `revoke_and_ack`. This should
give the user plenty of time to handle the event before we need to
make progress.
Sadly, because we change our `ChannelMonitorUpdate` semantics, this
change requires a number of test changes, avoiding checking for a
post-RAA `ChannelMonitorUpdate` until after we process a
`PaymentSent` event. Note that this does not apply to payments we
learned the preimage for on-chain - ensuring `PaymentSent` events
from such resolutions will be addressed in a future PR. Thus, tests
which resolve payments on-chain switch to a direct call to the
`expect_payment_sent` function with the claim-expected flag unset.1 parent 9852b84 commit f94de18
File tree
14 files changed
+293
-101
lines changed- lightning-invoice/src
- lightning/src
- chain
- ln
- util
- pending_changelog
14 files changed
+293
-101
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1091 | 1091 | | |
1092 | 1092 | | |
1093 | 1093 | | |
1094 | | - | |
1095 | | - | |
1096 | | - | |
1097 | | - | |
1098 | | - | |
1099 | | - | |
1100 | | - | |
1101 | | - | |
1102 | | - | |
1103 | | - | |
1104 | | - | |
1105 | | - | |
1106 | | - | |
1107 | | - | |
1108 | | - | |
1109 | | - | |
| 1094 | + | |
1110 | 1095 | | |
1111 | 1096 | | |
1112 | 1097 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
788 | 788 | | |
789 | 789 | | |
790 | 790 | | |
791 | | - | |
| 791 | + | |
792 | 792 | | |
793 | 793 | | |
794 | 794 | | |
| |||
871 | 871 | | |
872 | 872 | | |
873 | 873 | | |
874 | | - | |
| 874 | + | |
875 | 875 | | |
876 | 876 | | |
877 | 877 | | |
| |||
884 | 884 | | |
885 | 885 | | |
886 | 886 | | |
887 | | - | |
| 887 | + | |
888 | 888 | | |
889 | 889 | | |
890 | 890 | | |
| |||
972 | 972 | | |
973 | 973 | | |
974 | 974 | | |
975 | | - | |
| 975 | + | |
976 | 976 | | |
977 | 977 | | |
978 | 978 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1371 | 1371 | | |
1372 | 1372 | | |
1373 | 1373 | | |
| 1374 | + | |
1374 | 1375 | | |
1375 | 1376 | | |
1376 | 1377 | | |
| |||
1408 | 1409 | | |
1409 | 1410 | | |
1410 | 1411 | | |
1411 | | - | |
| 1412 | + | |
1412 | 1413 | | |
1413 | 1414 | | |
1414 | 1415 | | |
| |||
2140 | 2141 | | |
2141 | 2142 | | |
2142 | 2143 | | |
2143 | | - | |
| 2144 | + | |
2144 | 2145 | | |
2145 | 2146 | | |
2146 | 2147 | | |
| |||
2376 | 2377 | | |
2377 | 2378 | | |
2378 | 2379 | | |
2379 | | - | |
| 2380 | + | |
2380 | 2381 | | |
2381 | 2382 | | |
2382 | 2383 | | |
| |||
2393 | 2394 | | |
2394 | 2395 | | |
2395 | 2396 | | |
2396 | | - | |
| 2397 | + | |
2397 | 2398 | | |
2398 | 2399 | | |
2399 | 2400 | | |
| |||
2493 | 2494 | | |
2494 | 2495 | | |
2495 | 2496 | | |
2496 | | - | |
| 2497 | + | |
2497 | 2498 | | |
2498 | 2499 | | |
2499 | 2500 | | |
| |||
2520 | 2521 | | |
2521 | 2522 | | |
2522 | 2523 | | |
2523 | | - | |
| 2524 | + | |
2524 | 2525 | | |
2525 | 2526 | | |
2526 | 2527 | | |
| |||
2717 | 2718 | | |
2718 | 2719 | | |
2719 | 2720 | | |
2720 | | - | |
| 2721 | + | |
2721 | 2722 | | |
2722 | 2723 | | |
2723 | 2724 | | |
| |||
2940 | 2941 | | |
2941 | 2942 | | |
2942 | 2943 | | |
| 2944 | + | |
| 2945 | + | |
| 2946 | + | |
| 2947 | + | |
| 2948 | + | |
| 2949 | + | |
| 2950 | + | |
| 2951 | + | |
| 2952 | + | |
| 2953 | + | |
| 2954 | + | |
| 2955 | + | |
| 2956 | + | |
| 2957 | + | |
| 2958 | + | |
| 2959 | + | |
| 2960 | + | |
| 2961 | + | |
| 2962 | + | |
| 2963 | + | |
| 2964 | + | |
| 2965 | + | |
| 2966 | + | |
| 2967 | + | |
| 2968 | + | |
| 2969 | + | |
| 2970 | + | |
| 2971 | + | |
| 2972 | + | |
| 2973 | + | |
| 2974 | + | |
| 2975 | + | |
| 2976 | + | |
| 2977 | + | |
| 2978 | + | |
| 2979 | + | |
| 2980 | + | |
| 2981 | + | |
| 2982 | + | |
| 2983 | + | |
| 2984 | + | |
| 2985 | + | |
| 2986 | + | |
| 2987 | + | |
| 2988 | + | |
| 2989 | + | |
| 2990 | + | |
| 2991 | + | |
| 2992 | + | |
| 2993 | + | |
| 2994 | + | |
| 2995 | + | |
| 2996 | + | |
| 2997 | + | |
| 2998 | + | |
| 2999 | + | |
| 3000 | + | |
| 3001 | + | |
| 3002 | + | |
| 3003 | + | |
| 3004 | + | |
| 3005 | + | |
| 3006 | + | |
| 3007 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3427 | 3427 | | |
3428 | 3428 | | |
3429 | 3429 | | |
3430 | | - | |
| 3430 | + | |
| 3431 | + | |
3431 | 3432 | | |
3432 | 3433 | | |
3433 | 3434 | | |
| |||
3624 | 3625 | | |
3625 | 3626 | | |
3626 | 3627 | | |
3627 | | - | |
| 3628 | + | |
3628 | 3629 | | |
3629 | 3630 | | |
3630 | 3631 | | |
| |||
3641 | 3642 | | |
3642 | 3643 | | |
3643 | 3644 | | |
3644 | | - | |
| 3645 | + | |
3645 | 3646 | | |
3646 | 3647 | | |
3647 | 3648 | | |
| |||
3660 | 3661 | | |
3661 | 3662 | | |
3662 | 3663 | | |
3663 | | - | |
| 3664 | + | |
3664 | 3665 | | |
3665 | 3666 | | |
3666 | 3667 | | |
| |||
3669 | 3670 | | |
3670 | 3671 | | |
3671 | 3672 | | |
3672 | | - | |
| 3673 | + | |
3673 | 3674 | | |
3674 | 3675 | | |
3675 | 3676 | | |
| |||
0 commit comments