Skip to content

Commit 660dd6b

Browse files
committed
Add Shared Input support
1 parent 7b62ea4 commit 660dd6b

File tree

4 files changed

+551
-147
lines changed

4 files changed

+551
-147
lines changed

lightning/src/ln/channel.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::types::features::{ChannelTypeFeatures, InitFeatures};
3434
use crate::ln::interactivetxs::{
3535
calculate_change_output_value, get_output_weight, AbortReason, HandleTxCompleteResult, InteractiveTxConstructor,
3636
InteractiveTxConstructorArgs, InteractiveTxMessageSend, InteractiveTxSigningSession, InteractiveTxMessageSendResult,
37-
OutputOwned, SharedOwnedOutput, TX_COMMON_FIELDS_WEIGHT,
37+
NegotiationInput, OutputOwned, SharedOwnedOutput, TX_COMMON_FIELDS_WEIGHT,
3838
};
3939
use crate::ln::msgs;
4040
use crate::ln::msgs::{ClosingSigned, ClosingSignedFeeRange, DecodeError, OnionErrorPacket};
@@ -2513,6 +2513,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
25132513
inputs_to_contribute: funding_inputs,
25142514
outputs_to_contribute: funding_outputs,
25152515
expected_remote_shared_funding_output,
2516+
expected_remote_shared_funding_input: None,
25162517
};
25172518
let mut tx_constructor = InteractiveTxConstructor::new(constructor_args)?;
25182519
let msg = tx_constructor.take_initiator_first_message();
@@ -5157,7 +5158,7 @@ pub(super) struct DualFundingChannelContext {
51575158
///
51585159
/// Note that this field may be emptied once the interactive negotiation has been started.
51595160
#[allow(dead_code)] // TODO(dual_funding): Remove once contribution to V2 channels is enabled.
5160-
pub our_funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
5161+
pub our_funding_inputs: Vec<NegotiationInput>,
51615162
}
51625163

51635164
// Holder designates channel data owned for the benefit of the user client.
@@ -10388,7 +10389,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
1038810389
their_funding_satoshis: None,
1038910390
funding_tx_locktime,
1039010391
funding_feerate_sat_per_1000_weight,
10391-
our_funding_inputs: funding_inputs,
10392+
our_funding_inputs: funding_inputs.into_iter().map(|(txin, tx)| NegotiationInput::Nonshared(txin, tx)).collect(),
1039210393
};
1039310394
let chan = Self {
1039410395
funding,
@@ -10554,6 +10555,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
1055410555
inputs_to_contribute: our_funding_inputs,
1055510556
outputs_to_contribute: Vec::new(),
1055610557
expected_remote_shared_funding_output: Some((funding.get_funding_redeemscript().to_p2wsh(), funding.get_value_satoshis())),
10558+
expected_remote_shared_funding_input: None,
1055710559
}
1055810560
).map_err(|_| ChannelError::Close((
1055910561
"V2 channel rejected due to sender error".into(),

lightning/src/ln/dual_funding_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ fn do_test_v2_channel_establishment(session: V2ChannelEstablishmentTestSession)
8989
let tx_add_input_msg = TxAddInput {
9090
channel_id,
9191
serial_id: 2, // Even serial_id from initiator.
92-
prevtx: initiator_funding_inputs[0].1.clone(),
92+
prevtx: Some(initiator_funding_inputs[0].1.clone()),
9393
prevtx_out: 0,
9494
sequence: initiator_funding_inputs[0].0.sequence.0,
9595
shared_input_txid: None,
9696
};
9797
let input_value =
98-
tx_add_input_msg.prevtx.as_transaction().output[tx_add_input_msg.prevtx_out as usize].value;
98+
tx_add_input_msg.prevtx.as_ref().unwrap().as_transaction().output[tx_add_input_msg.prevtx_out as usize].value;
9999
assert_eq!(input_value.to_sat(), session.initiator_input_value_satoshis);
100100

101101
nodes[1].node.handle_tx_add_input(nodes[0].node.get_our_node_id(), &tx_add_input_msg);

0 commit comments

Comments
 (0)