Add htlc_id field to HTLCDescriptor and populate from channel context #1
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.
Overview
This PR adds support for passing
htlc_idin the signer interfaces by adding anhtlc_idfield to theHTLCDescriptorstruct and populating it from the channel context. This enables signers to uniquely identify HTLCs within a channel when signing HTLC transactions.Changes
Core Changes
pub htlc_id: Option<u64>field toHTLCDescriptorstruct inlightning/src/sign/mod.rshtlc_ids: Vec<u64>field toCommitmentDatastruct to track HTLC IDs during commitment transaction buildingpub htlc_ids: Vec<u64>field toHolderCommitmentTransactionto persist HTLC IDsHTLC ID Tracking Flow
pending_inbound_htlcsandpending_outbound_htlcswhich contain the originalhtlc_idvalueshtlcs_includedand sorted together to maintain correspondenceHolderCommitmentTransactionusing the HTLC indexUpdated Construction Sites
All locations where
HTLCDescriptoris instantiated now populatehtlc_idfrom theHolderCommitmentTransactioncontext:lightning/src/chain/package.rs: Extracts htlc_id using HTLC index from HolderCommitmentTransactionlightning/src/chain/channelmonitor.rs: Retrieves htlc_id from HolderCommitmentTransaction during HTLC descriptor creationlightning/src/chain/onchaintx.rs: Populates htlc_id from HolderCommitmentTransaction when building claim packageslightning/src/ln/channel.rs: Updated to track and pass htlc_ids through commitment transaction buildingDesign Rationale
The
htlc_idfield isOption<u64>rather than a requiredu64because:Option<u64>allows the field to beNonewhen deserializing old data that doesn't contain htlc_idsThe implementation tracks HTLC IDs from their source in the channel state through to the signer interface, ensuring that whenever possible, signers receive the HTLC ID for proper identification.
Testing
optionmodifierRelated
This change provides signers with HTLC ID information, which is useful for:
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.