@@ -121,12 +121,6 @@ pub(crate) enum AbortReason {
121121 DuplicateFundingOutput ,
122122 /// More than one funding (shared) input found.
123123 DuplicateFundingInput ,
124- /// The intended local part of the funding output is higher than the actual shared funding output,
125- /// if funding output is provided by the peer this is an interop error,
126- /// if provided by the same node than internal input consistency error.
127- InvalidLowFundingOutputValue ,
128- /// The intended local part of the funding input is higher than the actual shared funding input.
129- InvalidLowFundingInputValue ,
130124 /// Internal error
131125 InternalError ( & ' static str ) ,
132126}
@@ -186,12 +180,6 @@ impl Display for AbortReason {
186180 f. write_str ( "More than one funding output found" )
187181 } ,
188182 AbortReason :: DuplicateFundingInput => f. write_str ( "More than one funding input found" ) ,
189- AbortReason :: InvalidLowFundingOutputValue => f. write_str (
190- "Local part of funding output value is greater than the funding output value" ,
191- ) ,
192- AbortReason :: InvalidLowFundingInputValue => f. write_str (
193- "Local part of shared input value is greater than the shared input value" ,
194- ) ,
195183 AbortReason :: InternalError ( text) => {
196184 f. write_fmt ( format_args ! ( "Internal error: {}" , text) )
197185 } ,
@@ -1268,23 +1256,24 @@ struct SingleOwnedInput {
12681256#[ derive( Clone , Debug , Eq , PartialEq ) ]
12691257pub ( super ) struct SharedOwnedInput {
12701258 input : TxIn ,
1271- value : u64 ,
1259+ prev_output : TxOut ,
12721260 local_owned : u64 ,
12731261}
12741262
12751263impl SharedOwnedInput {
1276- pub fn new ( input : TxIn , value : u64 , local_owned : u64 ) -> Self {
1264+ pub fn new ( input : TxIn , prev_output : TxOut , local_owned : u64 ) -> Self {
1265+ let value = prev_output. value . to_sat ( ) ;
12771266 debug_assert ! (
12781267 local_owned <= value,
12791268 "SharedOwnedInput: Inconsistent local_owned value {}, larger than prev out value {}" ,
12801269 local_owned,
12811270 value,
12821271 ) ;
1283- Self { input, value , local_owned }
1272+ Self { input, prev_output , local_owned }
12841273 }
12851274
12861275 fn remote_owned ( & self ) -> u64 {
1287- self . value . saturating_sub ( self . local_owned )
1276+ self . prev_output . value . to_sat ( ) . saturating_sub ( self . local_owned )
12881277 }
12891278}
12901279
@@ -1296,7 +1285,7 @@ enum InputOwned {
12961285 /// Belongs to a single party -- controlled exclusively and fully belonging to a single party
12971286 /// Includes the input and the previous output
12981287 Single ( SingleOwnedInput ) ,
1299- // Input with shared control and value split between the two ends (or fully at one side)
1288+ /// Input with shared control and value split between the counterparties (or fully by one).
13001289 Shared ( SharedOwnedInput ) ,
13011290}
13021291
@@ -1325,7 +1314,7 @@ impl InputOwned {
13251314 pub fn value ( & self ) -> u64 {
13261315 match self {
13271316 InputOwned :: Single ( single) => single. prev_output . value . to_sat ( ) ,
1328- InputOwned :: Shared ( shared) => shared. value ,
1317+ InputOwned :: Shared ( shared) => shared. prev_output . value . to_sat ( ) ,
13291318 }
13301319 }
13311320
@@ -1359,7 +1348,7 @@ impl InputOwned {
13591348 fn estimate_input_weight ( & self ) -> Weight {
13601349 match self {
13611350 InputOwned :: Single ( single) => estimate_input_weight ( & single. prev_output ) ,
1362- InputOwned :: Shared ( _shared ) => Weight :: from_wu ( P2WSH_INPUT_WEIGHT_LOWER_BOUND ) ,
1351+ InputOwned :: Shared ( shared ) => estimate_input_weight ( & shared . prev_output ) ,
13631352 }
13641353 }
13651354}
@@ -1728,10 +1717,6 @@ impl InteractiveTxConstructor {
17281717 if is_initiator {
17291718 // Add shared funding input
17301719 let serial_id = generate_holder_serial_id ( entropy_source, is_initiator) ;
1731- // Sanity check
1732- if shared_funding_input. local_owned > shared_funding_input. value {
1733- return Err ( AbortReason :: InvalidLowFundingInputValue ) ;
1734- }
17351720 inputs_to_contribute
17361721 . push ( ( serial_id, InputOwned :: Shared ( shared_funding_input. clone ( ) ) ) ) ;
17371722 }
@@ -2046,12 +2031,12 @@ mod tests {
20462031 struct TestSession {
20472032 description : & ' static str ,
20482033 inputs_a : Vec < ( TxIn , TransactionU16LenLimited ) > ,
2049- a_shared_input : Option < ( OutPoint , u64 , u64 ) > ,
2034+ a_shared_input : Option < ( OutPoint , TxOut , u64 ) > ,
20502035 /// The funding output, with the value contributed
20512036 shared_output_a : ( TxOut , u64 ) ,
20522037 outputs_a : Vec < TxOut > ,
20532038 inputs_b : Vec < ( TxIn , TransactionU16LenLimited ) > ,
2054- b_shared_input : Option < ( OutPoint , u64 , u64 ) > ,
2039+ b_shared_input : Option < ( OutPoint , TxOut , u64 ) > ,
20552040 /// The funding output, with the value contributed
20562041 shared_output_b : ( TxOut , u64 ) ,
20572042 outputs_b : Vec < TxOut > ,
@@ -2096,14 +2081,14 @@ mod tests {
20962081 is_initiator : true ,
20972082 funding_tx_locktime,
20982083 inputs_to_contribute : session. inputs_a ,
2099- shared_funding_input : session. a_shared_input . map ( |( op, val , lo) | {
2084+ shared_funding_input : session. a_shared_input . map ( |( op, prev_output , lo) | {
21002085 SharedOwnedInput :: new (
21012086 TxIn {
21022087 previous_output : op,
21032088 sequence : Sequence :: ENABLE_RBF_NO_LOCKTIME ,
21042089 ..Default :: default ( )
21052090 } ,
2106- val ,
2091+ prev_output ,
21072092 lo,
21082093 )
21092094 } ) ,
@@ -2133,14 +2118,14 @@ mod tests {
21332118 is_initiator : false ,
21342119 funding_tx_locktime,
21352120 inputs_to_contribute : session. inputs_b ,
2136- shared_funding_input : session. b_shared_input . map ( |( op, val , lo) | {
2121+ shared_funding_input : session. b_shared_input . map ( |( op, prev_output , lo) | {
21372122 SharedOwnedInput :: new (
21382123 TxIn {
21392124 previous_output : op,
21402125 sequence : Sequence :: ENABLE_RBF_NO_LOCKTIME ,
21412126 ..Default :: default ( )
21422127 } ,
2143- val ,
2128+ prev_output ,
21442129 lo,
21452130 )
21462131 } ) ,
@@ -2319,16 +2304,17 @@ mod tests {
23192304
23202305 fn generate_shared_input (
23212306 prev_funding_tx : & Transaction , vout : u32 , local_owned : u64 ,
2322- ) -> ( OutPoint , u64 , u64 ) {
2307+ ) -> ( OutPoint , TxOut , u64 ) {
23232308 let txid = prev_funding_tx. compute_txid ( ) ;
2324- let value = prev_funding_tx. output . get ( vout as usize ) . unwrap ( ) . value . to_sat ( ) ;
2309+ let prev_output = prev_funding_tx. output . get ( vout as usize ) . unwrap ( ) ;
2310+ let value = prev_output. value . to_sat ( ) ;
23252311 assert ! (
23262312 local_owned <= value,
23272313 "local owned > value for shared input, {} {}" ,
23282314 local_owned,
23292315 value,
23302316 ) ;
2331- ( OutPoint { txid, vout } , value , local_owned)
2317+ ( OutPoint { txid, vout } , prev_output . clone ( ) , local_owned)
23322318 }
23332319
23342320 fn generate_p2wsh_script_pubkey ( ) -> ScriptBuf {
0 commit comments