@@ -496,7 +496,7 @@ struct NegotiationContext {
496
496
/// - For the acceptor:
497
497
/// The expected previous funding input. It should be added by the initiator node.
498
498
/// The values are the output value and the holder's part of the shared input.
499
- shared_funding_input : Option < ( OutPoint , u64 , u64 ) > ,
499
+ shared_funding_input : Option < SharedOwnedInput > ,
500
500
/// The intended/extended funding output, potentially co-owned by both peers (shared).
501
501
/// - For the initiator:
502
502
/// The output intended to be the new funding output. This will be added alonside to the
@@ -540,9 +540,8 @@ fn is_serial_id_valid_for_counterparty(holder_is_initiator: bool, serial_id: Ser
540
540
impl NegotiationContext {
541
541
fn new (
542
542
holder_node_id : PublicKey , counterparty_node_id : PublicKey , holder_is_initiator : bool ,
543
- shared_funding_input : Option < ( OutPoint , u64 , u64 ) > ,
544
- shared_funding_output : SharedOwnedOutput , tx_locktime : AbsoluteLockTime ,
545
- feerate_sat_per_kw : u32 ,
543
+ shared_funding_input : Option < SharedOwnedInput > , shared_funding_output : SharedOwnedOutput ,
544
+ tx_locktime : AbsoluteLockTime , feerate_sat_per_kw : u32 ,
546
545
) -> Self {
547
546
NegotiationContext {
548
547
holder_node_id,
@@ -636,21 +635,13 @@ impl NegotiationContext {
636
635
return Err ( AbortReason :: DuplicateFundingInput ) ;
637
636
}
638
637
// Check if received shared input matches the expected
639
- if !( shared_funding_input. 0 . txid == * shared_txid
640
- && shared_funding_input. 0 . vout == msg. prevtx_out )
638
+ if !( shared_funding_input. input . previous_output . txid == * shared_txid
639
+ && shared_funding_input. input . previous_output . vout == msg. prevtx_out )
641
640
{
642
641
return Err ( AbortReason :: UnexpectedFundingInput ) ;
643
642
} else {
644
643
let previous_output = OutPoint { txid : * shared_txid, vout : msg. prevtx_out } ;
645
- let txin = TxIn {
646
- previous_output,
647
- sequence : Sequence ( msg. sequence ) ,
648
- ..Default :: default ( )
649
- } ;
650
- let local_owned_sats = shared_funding_input. 2 ;
651
- let shared_input =
652
- SharedOwnedInput :: new ( txin, shared_funding_input. 1 , local_owned_sats) ;
653
- ( InputOwned :: Shared ( shared_input) , previous_output)
644
+ ( InputOwned :: Shared ( shared_funding_input. clone ( ) ) , previous_output)
654
645
}
655
646
} else {
656
647
return Err ( AbortReason :: UnexpectedFundingInput ) ;
@@ -837,15 +828,8 @@ impl NegotiationContext {
837
828
let vout = msg. prevtx_out as usize ;
838
829
let ( prev_outpoint, input) = if let Some ( shared_input_txid) = msg. shared_input_txid {
839
830
let prev_outpoint = OutPoint { txid : shared_input_txid, vout : msg. prevtx_out } ;
840
- let txin = TxIn {
841
- previous_output : prev_outpoint,
842
- sequence : Sequence ( msg. sequence ) ,
843
- ..Default :: default ( )
844
- } ;
845
831
if let Some ( shared_funding_input) = & self . shared_funding_input {
846
- let value = shared_funding_input. 1 ;
847
- let local_owned = shared_funding_input. 2 ;
848
- ( prev_outpoint, InputOwned :: Shared ( SharedOwnedInput :: new ( txin, value, local_owned) ) )
832
+ ( prev_outpoint, InputOwned :: Shared ( shared_funding_input. clone ( ) ) )
849
833
} else {
850
834
return Err ( AbortReason :: UnexpectedFundingInput ) ;
851
835
}
@@ -952,11 +936,9 @@ impl NegotiationContext {
952
936
let opt_shared_funding_input = self . shared_funding_input . clone ( ) ;
953
937
let constructed_tx = ConstructedTransaction :: new ( self ) ;
954
938
if let Some ( shared_funding_input) = & opt_shared_funding_input {
955
- if !constructed_tx
956
- . inputs
957
- . iter ( )
958
- . any ( |input| input. txin ( ) . previous_output == shared_funding_input. 0 )
959
- {
939
+ if !constructed_tx. inputs . iter ( ) . any ( |input| {
940
+ input. txin ( ) . previous_output == shared_funding_input. input . previous_output
941
+ } ) {
960
942
return Err ( AbortReason :: MissingFundingInput ) ;
961
943
}
962
944
}
@@ -1179,8 +1161,7 @@ impl StateMachine {
1179
1161
fn new (
1180
1162
holder_node_id : PublicKey , counterparty_node_id : PublicKey , feerate_sat_per_kw : u32 ,
1181
1163
is_initiator : bool , tx_locktime : AbsoluteLockTime ,
1182
- shared_funding_input : Option < ( OutPoint , u64 , u64 ) > ,
1183
- shared_funding_output : SharedOwnedOutput ,
1164
+ shared_funding_input : Option < SharedOwnedInput > , shared_funding_output : SharedOwnedOutput ,
1184
1165
) -> Self {
1185
1166
let context = NegotiationContext :: new (
1186
1167
holder_node_id,
@@ -1275,7 +1256,7 @@ impl_writeable_tlv_based!(SingleOwnedInput, {
1275
1256
} ) ;
1276
1257
1277
1258
#[ derive( Clone , Debug , Eq , PartialEq ) ]
1278
- struct SharedOwnedInput {
1259
+ pub ( super ) struct SharedOwnedInput {
1279
1260
input : TxIn ,
1280
1261
value : u64 ,
1281
1262
local_owned : u64 ,
@@ -1691,7 +1672,7 @@ where
1691
1672
pub is_initiator : bool ,
1692
1673
pub funding_tx_locktime : AbsoluteLockTime ,
1693
1674
pub inputs_to_contribute : Vec < ( TxIn , TransactionU16LenLimited ) > ,
1694
- pub shared_funding_input : Option < ( OutPoint , u64 , u64 ) > ,
1675
+ pub shared_funding_input : Option < SharedOwnedInput > ,
1695
1676
pub shared_funding_output : SharedOwnedOutput ,
1696
1677
pub outputs_to_contribute : Vec < TxOut > ,
1697
1678
}
@@ -1754,19 +1735,12 @@ impl InteractiveTxConstructor {
1754
1735
if is_initiator {
1755
1736
// Add shared funding input
1756
1737
let serial_id = generate_holder_serial_id ( entropy_source, is_initiator) ;
1757
- let value = shared_funding_input. 1 ;
1758
- let local_owned = shared_funding_input. 2 ;
1759
1738
// Sanity check
1760
- if local_owned > value {
1739
+ if shared_funding_input . local_owned > shared_funding_input . value {
1761
1740
return Err ( AbortReason :: InvalidLowFundingInputValue ) ;
1762
1741
}
1763
- let txin = TxIn {
1764
- previous_output : shared_funding_input. 0 ,
1765
- sequence : Sequence :: ENABLE_RBF_NO_LOCKTIME ,
1766
- ..Default :: default ( )
1767
- } ;
1768
- let input = SharedOwnedInput :: new ( txin, value, local_owned) ;
1769
- inputs_to_contribute. push ( ( serial_id, InputOwned :: Shared ( input) ) ) ;
1742
+ inputs_to_contribute
1743
+ . push ( ( serial_id, InputOwned :: Shared ( shared_funding_input. clone ( ) ) ) ) ;
1770
1744
}
1771
1745
}
1772
1746
// We'll sort by the randomly generated serial IDs, effectively shuffling the order of the inputs
@@ -1991,7 +1965,7 @@ mod tests {
1991
1965
use crate :: ln:: interactivetxs:: {
1992
1966
calculate_change_output_value, generate_holder_serial_id, AbortReason ,
1993
1967
HandleTxCompleteValue , InteractiveTxConstructor , InteractiveTxConstructorArgs ,
1994
- InteractiveTxMessageSend , SharedOwnedOutput , MAX_INPUTS_OUTPUTS_COUNT ,
1968
+ InteractiveTxMessageSend , SharedOwnedInput , SharedOwnedOutput , MAX_INPUTS_OUTPUTS_COUNT ,
1995
1969
MAX_RECEIVED_TX_ADD_INPUT_COUNT , MAX_RECEIVED_TX_ADD_OUTPUT_COUNT ,
1996
1970
} ;
1997
1971
use crate :: ln:: types:: ChannelId ;
@@ -2111,7 +2085,17 @@ mod tests {
2111
2085
is_initiator : true ,
2112
2086
funding_tx_locktime,
2113
2087
inputs_to_contribute : session. inputs_a ,
2114
- shared_funding_input : session. a_shared_input ,
2088
+ shared_funding_input : session. a_shared_input . map ( |( op, val, lo) | {
2089
+ SharedOwnedInput :: new (
2090
+ TxIn {
2091
+ previous_output : op,
2092
+ sequence : Sequence :: ENABLE_RBF_NO_LOCKTIME ,
2093
+ ..Default :: default ( )
2094
+ } ,
2095
+ val,
2096
+ lo,
2097
+ )
2098
+ } ) ,
2115
2099
shared_funding_output : SharedOwnedOutput :: new (
2116
2100
session. shared_output_a . 0 ,
2117
2101
session. shared_output_a . 1 ,
@@ -2138,7 +2122,17 @@ mod tests {
2138
2122
is_initiator : false ,
2139
2123
funding_tx_locktime,
2140
2124
inputs_to_contribute : session. inputs_b ,
2141
- shared_funding_input : session. b_shared_input ,
2125
+ shared_funding_input : session. b_shared_input . map ( |( op, val, lo) | {
2126
+ SharedOwnedInput :: new (
2127
+ TxIn {
2128
+ previous_output : op,
2129
+ sequence : Sequence :: ENABLE_RBF_NO_LOCKTIME ,
2130
+ ..Default :: default ( )
2131
+ } ,
2132
+ val,
2133
+ lo,
2134
+ )
2135
+ } ) ,
2142
2136
shared_funding_output : SharedOwnedOutput :: new (
2143
2137
session. shared_output_b . 0 ,
2144
2138
session. shared_output_b . 1 ,
0 commit comments