-
Notifications
You must be signed in to change notification settings - Fork 442
Reconstruct ChannelManager forwarded HTLCs maps from Channels
#4227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
valentinewallace
merged 9 commits into
lightningdevkit:main
from
valentinewallace:2025-10-reconstruct-mgr-fwd-htlcs
Dec 11, 2025
+575
−77
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4561bc5
Git-ignore lightning-tests/target
valentinewallace 4f055ac
Store inbound committed update_adds in Channel
valentinewallace c27093d
Extract util for HTLCIntercepted event creation
valentinewallace 26992e1
Extract method to dedup pre-decode update_add
valentinewallace 005da38
Rename manager HTLC forward maps to _legacy
valentinewallace 7c4d021
Tweak pending_htlc_intercepts ser on manager read
valentinewallace 64de989
Gather to-decode HTLC fwds from channels on manager read
valentinewallace cb398f6
Rebuild manager forwarded htlcs maps from Channels
valentinewallace a24dcff
Test 0.2 -> 0.3 reload with with forward htlcs present
valentinewallace File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18267,6 +18267,76 @@ where | |
| } | ||
| } | ||
|
|
||
| // Remove HTLCs from `forward_htlcs` if they are also present in `decode_update_add_htlcs`. | ||
| // | ||
| // In the future, the full set of pending HTLCs will be pulled from `Channel{Monitor}` data and | ||
| // placed in `ChannelManager::decode_update_add_htlcs` on read, to be handled on the next call | ||
| // to `process_pending_htlc_forwards`. This is part of a larger effort to remove the requirement | ||
| // of regularly persisting the `ChannelManager`. The new pipeline is supported for HTLC forwards | ||
| // received on LDK 0.3+ but not <= 0.2, so prune non-legacy HTLCs from `forward_htlcs`. | ||
valentinewallace marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| forward_htlcs_legacy.retain(|scid, pending_fwds| { | ||
| for fwd in pending_fwds { | ||
| let (prev_scid, prev_htlc_id) = match fwd { | ||
| HTLCForwardInfo::AddHTLC(htlc) => { | ||
| (htlc.prev_outbound_scid_alias, htlc.prev_htlc_id) | ||
| }, | ||
| HTLCForwardInfo::FailHTLC { htlc_id, .. } | ||
| | HTLCForwardInfo::FailMalformedHTLC { htlc_id, .. } => (*scid, *htlc_id), | ||
| }; | ||
| if let Some(pending_update_adds) = decode_update_add_htlcs.get_mut(&prev_scid) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if pending_update_adds | ||
| .iter() | ||
| .any(|update_add| update_add.htlc_id == prev_htlc_id) | ||
| { | ||
| return false; | ||
valentinewallace marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
| true | ||
| }); | ||
| // Remove intercepted HTLC forwards if they are also present in `decode_update_add_htlcs`. See | ||
| // the above comment. | ||
| pending_intercepted_htlcs_legacy.retain(|id, fwd| { | ||
| let prev_scid = fwd.prev_outbound_scid_alias; | ||
| if let Some(pending_update_adds) = decode_update_add_htlcs.get_mut(&prev_scid) { | ||
| if pending_update_adds | ||
| .iter() | ||
| .any(|update_add| update_add.htlc_id == fwd.prev_htlc_id) | ||
| { | ||
| pending_events_read.retain( | ||
| |(ev, _)| !matches!(ev, Event::HTLCIntercepted { intercept_id, .. } if intercept_id == id), | ||
| ); | ||
| return false; | ||
| } | ||
| } | ||
| if !pending_events_read.iter().any( | ||
| |(ev, _)| matches!(ev, Event::HTLCIntercepted { intercept_id, .. } if intercept_id == id), | ||
| ) { | ||
| match create_htlc_intercepted_event(*id, &fwd) { | ||
| Ok(ev) => pending_events_read.push_back((ev, None)), | ||
| Err(()) => debug_assert!(false), | ||
| } | ||
| } | ||
| true | ||
| }); | ||
| // Add legacy update_adds that were received on LDK <= 0.2 that are not present in the | ||
| // `decode_update_add_htlcs` map that was rebuilt from `Channel{Monitor}` data, see above | ||
| // comment. | ||
| for (scid, legacy_update_adds) in decode_update_add_htlcs_legacy.drain() { | ||
| match decode_update_add_htlcs.entry(scid) { | ||
| hash_map::Entry::Occupied(mut update_adds) => { | ||
| for legacy_update_add in legacy_update_adds { | ||
| if !update_adds.get().contains(&legacy_update_add) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. store .get_mut() in a var outside of the loop and reuse it inside? |
||
| update_adds.get_mut().push(legacy_update_add); | ||
| } | ||
| } | ||
| }, | ||
| hash_map::Entry::Vacant(entry) => { | ||
| entry.insert(legacy_update_adds); | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| let best_block = BestBlock::new(best_block_hash, best_block_height); | ||
| let flow = OffersMessageFlow::new( | ||
| chain_hash, | ||
|
|
@@ -18296,7 +18366,7 @@ where | |
| pending_intercepted_htlcs: Mutex::new(pending_intercepted_htlcs_legacy), | ||
|
|
||
| forward_htlcs: Mutex::new(forward_htlcs_legacy), | ||
| decode_update_add_htlcs: Mutex::new(decode_update_add_htlcs_legacy), | ||
| decode_update_add_htlcs: Mutex::new(decode_update_add_htlcs), | ||
joostjager marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| claimable_payments: Mutex::new(ClaimablePayments { | ||
| claimable_payments, | ||
| pending_claiming_payments: pending_claiming_payments.unwrap(), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.