@@ -121,12 +121,6 @@ pub(crate) enum AbortReason {
121
121
DuplicateFundingOutput ,
122
122
/// More than one funding (shared) input found.
123
123
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 ,
130
124
/// Internal error
131
125
InternalError ( & ' static str ) ,
132
126
}
@@ -186,12 +180,6 @@ impl Display for AbortReason {
186
180
f. write_str ( "More than one funding output found" )
187
181
} ,
188
182
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
- ) ,
195
183
AbortReason :: InternalError ( text) => {
196
184
f. write_fmt ( format_args ! ( "Internal error: {}" , text) )
197
185
} ,
@@ -1268,23 +1256,24 @@ struct SingleOwnedInput {
1268
1256
#[ derive( Clone , Debug , Eq , PartialEq ) ]
1269
1257
pub ( super ) struct SharedOwnedInput {
1270
1258
input : TxIn ,
1271
- value : u64 ,
1259
+ prev_output : TxOut ,
1272
1260
local_owned : u64 ,
1273
1261
}
1274
1262
1275
1263
impl 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 ( ) ;
1277
1266
debug_assert ! (
1278
1267
local_owned <= value,
1279
1268
"SharedOwnedInput: Inconsistent local_owned value {}, larger than prev out value {}" ,
1280
1269
local_owned,
1281
1270
value,
1282
1271
) ;
1283
- Self { input, value , local_owned }
1272
+ Self { input, prev_output , local_owned }
1284
1273
}
1285
1274
1286
1275
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 )
1288
1277
}
1289
1278
}
1290
1279
@@ -1296,7 +1285,7 @@ enum InputOwned {
1296
1285
/// Belongs to a single party -- controlled exclusively and fully belonging to a single party
1297
1286
/// Includes the input and the previous output
1298
1287
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).
1300
1289
Shared ( SharedOwnedInput ) ,
1301
1290
}
1302
1291
@@ -1325,7 +1314,7 @@ impl InputOwned {
1325
1314
pub fn value ( & self ) -> u64 {
1326
1315
match self {
1327
1316
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 ( ) ,
1329
1318
}
1330
1319
}
1331
1320
@@ -1359,7 +1348,7 @@ impl InputOwned {
1359
1348
fn estimate_input_weight ( & self ) -> Weight {
1360
1349
match self {
1361
1350
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 ) ,
1363
1352
}
1364
1353
}
1365
1354
}
@@ -1728,10 +1717,6 @@ impl InteractiveTxConstructor {
1728
1717
if is_initiator {
1729
1718
// Add shared funding input
1730
1719
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
- }
1735
1720
inputs_to_contribute
1736
1721
. push ( ( serial_id, InputOwned :: Shared ( shared_funding_input. clone ( ) ) ) ) ;
1737
1722
}
@@ -2041,12 +2026,12 @@ mod tests {
2041
2026
struct TestSession {
2042
2027
description : & ' static str ,
2043
2028
inputs_a : Vec < ( TxIn , TransactionU16LenLimited ) > ,
2044
- a_shared_input : Option < ( OutPoint , u64 , u64 ) > ,
2029
+ a_shared_input : Option < ( OutPoint , TxOut , u64 ) > ,
2045
2030
/// The funding output, with the value contributed
2046
2031
shared_output_a : ( TxOut , u64 ) ,
2047
2032
outputs_a : Vec < TxOut > ,
2048
2033
inputs_b : Vec < ( TxIn , TransactionU16LenLimited ) > ,
2049
- b_shared_input : Option < ( OutPoint , u64 , u64 ) > ,
2034
+ b_shared_input : Option < ( OutPoint , TxOut , u64 ) > ,
2050
2035
/// The funding output, with the value contributed
2051
2036
shared_output_b : ( TxOut , u64 ) ,
2052
2037
outputs_b : Vec < TxOut > ,
@@ -2091,14 +2076,14 @@ mod tests {
2091
2076
is_initiator : true ,
2092
2077
funding_tx_locktime,
2093
2078
inputs_to_contribute : session. inputs_a ,
2094
- shared_funding_input : session. a_shared_input . map ( |( op, val , lo) | {
2079
+ shared_funding_input : session. a_shared_input . map ( |( op, prev_output , lo) | {
2095
2080
SharedOwnedInput :: new (
2096
2081
TxIn {
2097
2082
previous_output : op,
2098
2083
sequence : Sequence :: ENABLE_RBF_NO_LOCKTIME ,
2099
2084
..Default :: default ( )
2100
2085
} ,
2101
- val ,
2086
+ prev_output ,
2102
2087
lo,
2103
2088
)
2104
2089
} ) ,
@@ -2128,14 +2113,14 @@ mod tests {
2128
2113
is_initiator : false ,
2129
2114
funding_tx_locktime,
2130
2115
inputs_to_contribute : session. inputs_b ,
2131
- shared_funding_input : session. b_shared_input . map ( |( op, val , lo) | {
2116
+ shared_funding_input : session. b_shared_input . map ( |( op, prev_output , lo) | {
2132
2117
SharedOwnedInput :: new (
2133
2118
TxIn {
2134
2119
previous_output : op,
2135
2120
sequence : Sequence :: ENABLE_RBF_NO_LOCKTIME ,
2136
2121
..Default :: default ( )
2137
2122
} ,
2138
- val ,
2123
+ prev_output ,
2139
2124
lo,
2140
2125
)
2141
2126
} ) ,
@@ -2314,16 +2299,17 @@ mod tests {
2314
2299
2315
2300
fn generate_shared_input (
2316
2301
prev_funding_tx : & Transaction , vout : u32 , local_owned : u64 ,
2317
- ) -> ( OutPoint , u64 , u64 ) {
2302
+ ) -> ( OutPoint , TxOut , u64 ) {
2318
2303
let txid = prev_funding_tx. compute_txid ( ) ;
2319
- let value = prev_funding_tx. output . get ( vout as usize ) . unwrap ( ) . value . to_sat ( ) ;
2304
+ let prev_output = prev_funding_tx. output . get ( vout as usize ) . unwrap ( ) ;
2305
+ let value = prev_output. value . to_sat ( ) ;
2320
2306
assert ! (
2321
2307
local_owned <= value,
2322
2308
"local owned > value for shared input, {} {}" ,
2323
2309
local_owned,
2324
2310
value,
2325
2311
) ;
2326
- ( OutPoint { txid, vout } , value , local_owned)
2312
+ ( OutPoint { txid, vout } , prev_output . clone ( ) , local_owned)
2327
2313
}
2328
2314
2329
2315
fn generate_p2wsh_script_pubkey ( ) -> ScriptBuf {
0 commit comments