@@ -197,14 +197,9 @@ impl Display for AbortReason {
197
197
#[ derive( Debug , Clone , PartialEq , Eq ) ]
198
198
pub ( crate ) struct ConstructedTransaction {
199
199
holder_is_initiator : bool ,
200
-
201
200
input_metadata : Vec < TxInMetadata > ,
202
201
output_metadata : Vec < TxOutMetadata > ,
203
202
tx : Transaction ,
204
-
205
- local_inputs_value_satoshis : u64 ,
206
- remote_inputs_value_satoshis : u64 ,
207
-
208
203
shared_input_index : Option < u32 > ,
209
204
}
210
205
@@ -249,9 +244,7 @@ impl_writeable_tlv_based!(ConstructedTransaction, {
249
244
( 3 , input_metadata, required) ,
250
245
( 5 , output_metadata, required) ,
251
246
( 7 , tx, required) ,
252
- ( 9 , local_inputs_value_satoshis, required) ,
253
- ( 11 , remote_inputs_value_satoshis, required) ,
254
- ( 13 , shared_input_index, option) ,
247
+ ( 9 , shared_input_index, option) ,
255
248
} ) ;
256
249
257
250
impl ConstructedTransaction {
@@ -271,12 +264,6 @@ impl ConstructedTransaction {
271
264
return Err ( AbortReason :: MissingFundingOutput ) ;
272
265
}
273
266
274
- let local_inputs_value_satoshis = context
275
- . inputs
276
- . iter ( )
277
- . fold ( 0u64 , |value, ( _, input) | value. saturating_add ( input. local_value ( ) ) ) ;
278
- let remote_inputs_value_satoshis = context. remote_inputs_value ( ) ;
279
-
280
267
let satisfaction_weight =
281
268
Weight :: from_wu ( context. inputs . iter ( ) . fold ( 0u64 , |value, ( _, input) | {
282
269
value. saturating_add ( input. satisfaction_weight ( ) . to_wu ( ) )
@@ -313,14 +300,9 @@ impl ConstructedTransaction {
313
300
314
301
Ok ( Self {
315
302
holder_is_initiator : context. holder_is_initiator ,
316
-
317
303
input_metadata,
318
304
output_metadata,
319
305
tx,
320
-
321
- local_inputs_value_satoshis,
322
- remote_inputs_value_satoshis,
323
-
324
306
shared_input_index,
325
307
} )
326
308
}
@@ -337,6 +319,26 @@ impl ConstructedTransaction {
337
319
self . tx ( ) . compute_txid ( )
338
320
}
339
321
322
+ /// Returns the total input value from all local contributions, including the entire shared
323
+ /// input value if applicable.
324
+ fn local_contributed_input_value ( & self ) -> Amount {
325
+ self . input_metadata
326
+ . iter ( )
327
+ . filter ( |input| input. is_local ( self . holder_is_initiator ) )
328
+ . map ( |input| input. prev_output . value )
329
+ . sum ( )
330
+ }
331
+
332
+ /// Returns the total input value from all remote contributions, including the entire shared
333
+ /// input value if applicable.
334
+ fn remote_contributed_input_value ( & self ) -> Amount {
335
+ self . input_metadata
336
+ . iter ( )
337
+ . filter ( |input| !input. is_local ( self . holder_is_initiator ) )
338
+ . map ( |input| input. prev_output . value )
339
+ . sum ( )
340
+ }
341
+
340
342
/// Adds provided holder witnesses to holder inputs of unsigned transaction.
341
343
///
342
344
/// Note that it is assumed that the witness count equals the holder input count.
@@ -1379,11 +1381,13 @@ macro_rules! define_state_transitions {
1379
1381
let tx = context. validate_tx( ) ?;
1380
1382
1381
1383
// Strict ordering prevents deadlocks during tx_signatures exchange
1384
+ let local_contributed_input_value = tx. local_contributed_input_value( ) ;
1385
+ let remote_contributed_input_value = tx. remote_contributed_input_value( ) ;
1382
1386
let holder_sends_tx_signatures_first =
1383
- if tx . local_inputs_value_satoshis == tx . remote_inputs_value_satoshis {
1387
+ if local_contributed_input_value == remote_contributed_input_value {
1384
1388
holder_node_id. serialize( ) < counterparty_node_id. serialize( )
1385
1389
} else {
1386
- tx . local_inputs_value_satoshis < tx . remote_inputs_value_satoshis
1390
+ local_contributed_input_value < remote_contributed_input_value
1387
1391
} ;
1388
1392
1389
1393
let signing_session = InteractiveTxSigningSession {
@@ -3306,8 +3310,6 @@ mod tests {
3306
3310
input_metadata,
3307
3311
output_metadata : vec ! [ ] , // N/A for test
3308
3312
tx : transaction. clone ( ) ,
3309
- local_inputs_value_satoshis : 0 , // N/A for test
3310
- remote_inputs_value_satoshis : 0 , // N/A for test
3311
3313
shared_input_index : None ,
3312
3314
} ;
3313
3315
0 commit comments