Enforce ChannelTransactionParameters completeness#4464
Draft
jkczyz wants to merge 4 commits intolightningdevkit:mainfrom
Draft
Enforce ChannelTransactionParameters completeness#4464jkczyz wants to merge 4 commits intolightningdevkit:mainfrom
ChannelTransactionParameters completeness#4464jkczyz wants to merge 4 commits intolightningdevkit:mainfrom
Conversation
Introduce PendingV1Channel to represent the intermediate state where funding_created has been generated but funding_signed has not yet been received. This makes the channel state machine more explicit: UnfundedOutboundV1 -> PendingV1 -> Funded Move get_funding_created_msg, funding_signed, signer_maybe_unblocked (funding path), unset_funding_info, and the InitialRemoteCommitmentReceiver impl from OutboundV1Channel to PendingV1Channel. Change OutboundV1Channel::get_funding_created to consume self and return (PendingV1Channel, Option<FundingCreated>). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Mechanical rename to free the PendingV2Channel name for a new struct that will hold V2 channels with complete funding parameters, following the PendingV1 pattern. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Introduce a PendingV2Channel struct and ChannelPhase::PendingV2 variant to represent V2 channels that have completed funding transaction construction but have not yet received commitment_signed. The funding_tx_constructed method now performs the UnfundedV2 → PendingV2 phase transition using core::mem::replace, and funding_transaction_signed and commitment_signed now match on PendingV2 instead of UnfundedV2. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
ChannelTransactionParameters used Option fields for counterparty parameters and funding outpoint, relying on runtime unwrap/expect calls scattered throughout the codebase. This was fragile since it was easy to call code that assumed populated parameters on a not-yet-funded channel. Split into PartialChannelTransactionParameters (used during negotiation) and ChannelTransactionParameters (fully populated, used once funded). Make FundingScope generic over the parameters type so the compiler enforces which channel phases have complete data, eliminating the need for runtime is_populated() guards in signers and elsewhere. With the type-level distinction in place, also: - Remove the InitialRemoteCommitmentReceiver trait, replacing it with a ChannelContext method that takes complete parameters directly. - Replace unset_funding_info with Channel::unfund(), which properly transitions a funded channel back to unfunded state rather than leaving it in an inconsistent "funded without funding info" state. - Flatten DirectedChannelTransactionParameters to store resolved fields directly instead of computing them on each access. - Concretize methods that only work with complete parameters to take FundingScope<ChannelTransactionParameters> directly, using field access instead of trait-based Option-returning accessors. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
👋 Hi! I see this is a draft PR. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Introduces intermediate channel phases (
PendingV1,PendingV2) between unfunded and funded states, then leverages them to enforceChannelTransactionParameterscompleteness rather than relying on runtimeunwrap()/expect()calls.PendingV1phase betweenUnfundedOutboundV1andFunded, making the V1 state machine explicit:UnfundedOutboundV1 → PendingV1 → FundedPendingV2phase betweenUnfundedV2andFundedfor V2 channels that have constructed a funding transaction but not yet receivedcommitment_signedChannelTransactionParametersintoPartialChannelTransactionParameters(counterparty parameters and funding outpoint areOption) andChannelTransactionParameters(all fields required). Previously a single struct usedOptionfields withis_populated()runtime guards scattered across signer code.FundingScopegeneric over the parameters type (FundingScope<P>) so unfunded phases usePartialChannelTransactionParametersand funded phases useChannelTransactionParameters, letting the compiler enforce which phases have complete data.FundingScope<ChannelTransactionParameters>directly, replacing trait-basedOption-returning accessors with direct field access and eliminating theInitialRemoteCommitmentReceivertrait.DirectedChannelTransactionParametersto store resolved fields directly since theOption-based fields it previously delegated to are now split across two typesunset_funding_infowithChannel::unfund(), which transitions a funded channel back to its unfunded phase sinceFundedChannelusesFundingScope<ChannelTransactionParameters>where the funding outpoint and counterparty parameters are non-Optionand can't be cleared