Skip to content

Commit c18422d

Browse files
optout21jkczyz
authored andcommitted
Add Shared Input support
In interactivetxs, add support for shared inputs, similar to shared outputs. A shared input is optional, and is used in case of splicing to add the current funding as an input.
1 parent 62c8ecd commit c18422d

File tree

5 files changed

+616
-193
lines changed

5 files changed

+616
-193
lines changed

lightning/src/ln/channel.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2771,7 +2771,8 @@ where
27712771
};
27722772
let change_value_opt = calculate_change_output_value(
27732773
self.funding.is_outbound(), self.dual_funding_context.our_funding_satoshis,
2774-
&shared_funding_output.script_pubkey, &funding_inputs, &funding_outputs,
2774+
&funding_inputs, None,
2775+
&shared_funding_output.script_pubkey, &funding_outputs,
27752776
self.dual_funding_context.funding_feerate_sat_per_1000_weight,
27762777
change_script.minimal_non_dust().to_sat(),
27772778
)?;
@@ -2799,6 +2800,7 @@ where
27992800
is_initiator: self.funding.is_outbound(),
28002801
funding_tx_locktime: self.dual_funding_context.funding_tx_locktime,
28012802
inputs_to_contribute: funding_inputs,
2803+
shared_funding_input: None,
28022804
shared_funding_output: SharedOwnedOutput::new(shared_funding_output, self.dual_funding_context.our_funding_satoshis),
28032805
outputs_to_contribute: funding_outputs,
28042806
};
@@ -11812,6 +11814,7 @@ where
1181211814
funding_tx_locktime: dual_funding_context.funding_tx_locktime,
1181311815
is_initiator: false,
1181411816
inputs_to_contribute: our_funding_inputs,
11817+
shared_funding_input: None,
1181511818
shared_funding_output: SharedOwnedOutput::new(shared_funding_output, our_funding_satoshis),
1181611819
outputs_to_contribute: Vec::new(),
1181711820
}

lightning/src/ln/dual_funding_tests.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,14 @@ 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
};
97-
let input_value =
98-
tx_add_input_msg.prevtx.as_transaction().output[tx_add_input_msg.prevtx_out as usize].value;
97+
let input_value = tx_add_input_msg.prevtx.as_ref().unwrap().as_transaction().output
98+
[tx_add_input_msg.prevtx_out as usize]
99+
.value;
99100
assert_eq!(input_value.to_sat(), session.initiator_input_value_satoshis);
100101

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

0 commit comments

Comments
 (0)