Commit 19fb094
committed
Persist HTLCs before action calculation
htlc_intercepted only persisted HTLCs when a liquidity action
(splice/open) was needed. This prevents calculate_htlc_actions
from returning empty actions (i.e. "do nothing, let the timer
handle it") because the HTLC would never make it into the store
and the timer would never see it.
Move the insert before calculate_htlc_actions_for_peer so every
intercepted HTLC is in the store before we decide what to do
with it. execute_htlc_actions already removes the HTLC on
successful forward, so the store entry is short-lived on the
happy path.
The cost is two extra KV store round-trips (S3 write + delete)
per HTLC on the forward-only path, where previously there were
none. This hits every payment since LSPS4 intercepts all of
them. Unfortunately unavoidable: the insert must happen before
action calculation because we don't know yet whether the result
will be "forward now" or "do nothing and defer to the timer."
If we wait until after and the result is "do nothing," we've
already lost the HTLC.
Replace the unconditional unwrap on insert with explicit error
handling. On persistence failure:
- Forward-only: proceed. If the forward succeeds the store
entry was redundant. If persistence failed and the channel
becomes unusable between calculate and execute, the HTLC is
orphaned (not in store for timer retry, not forwarded) until
LDK's CLTV timeout cleans it up. Requires both S3 failure
and a channel state change between two adjacent calls.
- Liquidity action needed: fail the HTLC back to sender. The
splice/open is async and the timer needs the stored HTLC to
forward once the channel is ready. Without it, we'd spend
on-chain fees on a splice that never results in a forward.1 parent cadc8b7 commit 19fb094
1 file changed
Lines changed: 41 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
239 | 239 | | |
240 | 240 | | |
241 | 241 | | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
242 | 261 | | |
243 | 262 | | |
244 | | - | |
| 263 | + | |
245 | 264 | | |
246 | 265 | | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | 266 | | |
252 | 267 | | |
253 | 268 | | |
254 | 269 | | |
255 | 270 | | |
256 | 271 | | |
257 | 272 | | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
258 | 294 | | |
259 | 295 | | |
260 | 296 | | |
| |||
0 commit comments