-
Notifications
You must be signed in to change notification settings - Fork 424
Contribute funding inputs on accepting dual-funded channel #3735
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
Open
dunxen
wants to merge
4
commits into
lightningdevkit:main
Choose a base branch
from
dunxen:2025-04-contributeinputs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f312357
Allow passing funding inputs when manually accepting a dual-funded ch…
dunxen e247652
f - allow change script
jkczyz ac8803c
f - store funding_tx_locktime in PendingV2Channel
jkczyz 9a04ed0
Test acceptor contributions in dual-funding functional tests
dunxen 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
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 |
|---|---|---|
|
|
@@ -30,7 +30,7 @@ use bitcoin::hashes::{Hash, HashEngine, HmacEngine}; | |
|
|
||
| use bitcoin::secp256k1::Secp256k1; | ||
| use bitcoin::secp256k1::{PublicKey, SecretKey}; | ||
| use bitcoin::{secp256k1, Sequence, SignedAmount}; | ||
| use bitcoin::{secp256k1, Amount, ScriptBuf, Sequence}; | ||
|
|
||
| use crate::blinded_path::message::{ | ||
| AsyncPaymentsContext, BlindedMessagePath, MessageForwardNode, OffersContext, | ||
|
|
@@ -65,7 +65,7 @@ use crate::ln::channel::{ | |
| WithChannelContext, | ||
| }; | ||
| use crate::ln::channel_state::ChannelDetails; | ||
| use crate::ln::funding::SpliceContribution; | ||
| use crate::ln::funding::{FundingTxInput, SpliceContribution}; | ||
| use crate::ln::inbound_payment; | ||
| use crate::ln::interactivetxs::InteractiveTxMessageSend; | ||
| use crate::ln::msgs; | ||
|
|
@@ -9814,6 +9814,9 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ | |
| false, | ||
| user_channel_id, | ||
| config_overrides, | ||
| Amount::ZERO, | ||
| vec![], | ||
| None, | ||
| ) | ||
| } | ||
|
|
||
|
|
@@ -9845,15 +9848,73 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ | |
| true, | ||
| user_channel_id, | ||
| config_overrides, | ||
| Amount::ZERO, | ||
| vec![], | ||
| None, | ||
| ) | ||
| } | ||
|
|
||
| /// Accepts a request to open a dual-funded channel with a contribution provided after an | ||
| /// [`Event::OpenChannelRequest`]. | ||
| /// | ||
| /// The [`Event::OpenChannelRequest::channel_negotiation_type`] field will indicate the open channel | ||
| /// request is for a dual-funded channel when the variant is [`InboundChannelFunds::DualFunded`]. | ||
| /// | ||
| /// The `temporary_channel_id` parameter indicates which inbound channel should be accepted, | ||
| /// and the `counterparty_node_id` parameter is the id of the peer that has requested to open | ||
| /// the channel. | ||
| /// | ||
| /// The `user_channel_id` parameter will be provided back in | ||
| /// [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond | ||
| /// with which `accept_inbound_channel_*` call. | ||
| /// | ||
| /// The `funding_inputs` parameter provides which UTXOs to use for `our_funding_contribution` | ||
| /// along with the corresponding satisfaction weight. They must be able to cover any fees needed | ||
| /// to pay for the contributed weight to the funding transaction. This includes the witnesses | ||
| /// provided through calling [`ChannelManager::funding_transaction_signed`] after receiving | ||
| /// [`Event::FundingTransactionReadyForSigning`]. | ||
| /// | ||
| /// Note that this method will return an error and reject the channel if it requires support for | ||
| /// zero confirmations. | ||
| // TODO(dual_funding): Discussion on complications with 0conf dual-funded channels where "locking" | ||
| // of UTXOs used for funding would be required and other issues. | ||
| // See https://diyhpl.us/~bryan/irc/bitcoin/bitcoin-dev/linuxfoundation-pipermail/lightning-dev/2023-May/003922.txt | ||
| /// | ||
| /// [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest | ||
| /// [`Event::OpenChannelRequest::channel_negotiation_type`]: events::Event::OpenChannelRequest::channel_negotiation_type | ||
| /// [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id | ||
| /// [`Event::FundingTransactionReadyForSigning`]: events::Event::FundingTransactionReadyForSigning | ||
| /// [`ChannelManager::funding_transaction_signed`]: ChannelManager::funding_transaction_signed | ||
| pub fn accept_inbound_channel_with_contribution( | ||
| &self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, | ||
| user_channel_id: u128, config_overrides: Option<ChannelConfigOverrides>, | ||
| our_funding_contribution: Amount, funding_inputs: Vec<FundingTxInput>, | ||
|
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. We're also allowed to include outputs, behaving similar to the mixed mode splice, so maybe it's worth waiting until we figure that out in #4261 so we can adopt it here? |
||
| change_script: Option<ScriptBuf>, | ||
| ) -> Result<(), APIError> { | ||
| self.do_accept_inbound_channel( | ||
| temporary_channel_id, | ||
| counterparty_node_id, | ||
| false, | ||
| user_channel_id, | ||
| config_overrides, | ||
| our_funding_contribution, | ||
| funding_inputs, | ||
| change_script, | ||
| ) | ||
| } | ||
|
|
||
| /// TODO(dual_funding): Allow contributions, pass intended amount and inputs | ||
| #[rustfmt::skip] | ||
| fn do_accept_inbound_channel( | ||
| &self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, accept_0conf: bool, | ||
| user_channel_id: u128, config_overrides: Option<ChannelConfigOverrides> | ||
| &self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, | ||
| accept_0conf: bool, user_channel_id: u128, config_overrides: Option<ChannelConfigOverrides>, | ||
| our_funding_contribution: Amount, funding_inputs: Vec<FundingTxInput>, | ||
| change_script: Option<ScriptBuf>, | ||
| ) -> Result<(), APIError> { | ||
| if our_funding_contribution > Amount::MAX_MONEY { | ||
| return Err(APIError::APIMisuseError { | ||
| err: format!("the funding contribution must be smaller than the total bitcoin supply, it was {}", our_funding_contribution) | ||
| }); | ||
| } | ||
|
|
||
| let mut config = self.config.read().unwrap().clone(); | ||
|
|
||
|
|
@@ -9911,7 +9972,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ | |
| &self.channel_type_features(), &peer_state.latest_features, | ||
| &open_channel_msg, | ||
| user_channel_id, &config, best_block_height, | ||
| &self.logger, | ||
| &self.logger, our_funding_contribution, funding_inputs, change_script, | ||
| ).map_err(|e| { | ||
| let channel_id = open_channel_msg.common_fields.temporary_channel_id; | ||
| MsgHandleErrInternal::from_chan_no_close(e, channel_id) | ||
|
|
@@ -10055,7 +10116,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ | |
|
|
||
| // Inbound V2 channels with contributed inputs are not considered unfunded. | ||
| if let Some(unfunded_chan) = chan.as_unfunded_v2() { | ||
| if unfunded_chan.funding_negotiation_context.our_funding_contribution > SignedAmount::ZERO { | ||
| if unfunded_chan.our_funding_contribution() > Amount::ZERO { | ||
| continue; | ||
| } | ||
| } | ||
|
|
@@ -10197,7 +10258,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ | |
| &self.fee_estimator, &self.entropy_source, &self.signer_provider, | ||
| self.get_our_node_id(), *counterparty_node_id, &self.channel_type_features(), | ||
| &peer_state.latest_features, msg, user_channel_id, | ||
| &self.config.read().unwrap(), best_block_height, &self.logger, | ||
| &self.config.read().unwrap(), best_block_height, &self.logger, Amount::ZERO, vec![], None, | ||
| ).map_err(|e| MsgHandleErrInternal::from_chan_no_close(e, msg.common_fields.temporary_channel_id))?; | ||
| let message_send_event = MessageSendEvent::SendAcceptChannelV2 { | ||
| node_id: *counterparty_node_id, | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to reuse
FundingNegotiationhere, but it seems unclear whether the lastAwaitingSignaturesstate can be adapted to the initial dual funding state