Skip to content

Add Shared Input support in interactive TX construction #3842

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
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::types::features::{ChannelTypeFeatures, InitFeatures};
use crate::ln::interactivetxs::{
calculate_change_output_value, get_output_weight, AbortReason, HandleTxCompleteResult, InteractiveTxConstructor,
InteractiveTxConstructorArgs, InteractiveTxMessageSend, InteractiveTxSigningSession, InteractiveTxMessageSendResult,
OutputOwned, SharedOwnedOutput, TX_COMMON_FIELDS_WEIGHT,
NegotiationInput, OutputOwned, SharedOwnedOutput, TX_COMMON_FIELDS_WEIGHT,
};
use crate::ln::msgs;
use crate::ln::msgs::{ClosingSigned, ClosingSignedFeeRange, DecodeError, OnionErrorPacket};
Expand Down Expand Up @@ -2513,6 +2513,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
inputs_to_contribute: funding_inputs,
outputs_to_contribute: funding_outputs,
expected_remote_shared_funding_output,
expected_remote_shared_funding_input: None,
};
let mut tx_constructor = InteractiveTxConstructor::new(constructor_args)?;
let msg = tx_constructor.take_initiator_first_message();
Expand Down Expand Up @@ -5157,7 +5158,7 @@ pub(super) struct DualFundingChannelContext {
///
/// Note that this field may be emptied once the interactive negotiation has been started.
#[allow(dead_code)] // TODO(dual_funding): Remove once contribution to V2 channels is enabled.
pub our_funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
pub our_funding_inputs: Vec<NegotiationInput>,
}

// Holder designates channel data owned for the benefit of the user client.
Expand Down Expand Up @@ -10388,7 +10389,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
their_funding_satoshis: None,
funding_tx_locktime,
funding_feerate_sat_per_1000_weight,
our_funding_inputs: funding_inputs,
our_funding_inputs: funding_inputs.into_iter().map(|(txin, tx)| NegotiationInput::Nonshared(txin, tx)).collect(),
};
let chan = Self {
funding,
Expand Down Expand Up @@ -10554,6 +10555,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
inputs_to_contribute: our_funding_inputs,
outputs_to_contribute: Vec::new(),
expected_remote_shared_funding_output: Some((funding.get_funding_redeemscript().to_p2wsh(), funding.get_value_satoshis())),
expected_remote_shared_funding_input: None,
}
).map_err(|_| ChannelError::Close((
"V2 channel rejected due to sender error".into(),
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/dual_funding_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ fn do_test_v2_channel_establishment(session: V2ChannelEstablishmentTestSession)
let tx_add_input_msg = TxAddInput {
channel_id,
serial_id: 2, // Even serial_id from initiator.
prevtx: initiator_funding_inputs[0].1.clone(),
prevtx: Some(initiator_funding_inputs[0].1.clone()),
prevtx_out: 0,
sequence: initiator_funding_inputs[0].0.sequence.0,
shared_input_txid: None,
};
let input_value =
tx_add_input_msg.prevtx.as_transaction().output[tx_add_input_msg.prevtx_out as usize].value;
tx_add_input_msg.prevtx.as_ref().unwrap().as_transaction().output[tx_add_input_msg.prevtx_out as usize].value;
assert_eq!(input_value.to_sat(), session.initiator_input_value_satoshis);

nodes[1].node.handle_tx_add_input(nodes[0].node.get_our_node_id(), &tx_add_input_msg);
Expand Down
Loading
Loading