@@ -215,8 +215,6 @@ pub(crate) struct ConstructedTransaction {
215
215
pub ( crate ) struct NegotiatedTxInput {
216
216
serial_id : SerialId ,
217
217
txin : TxIn ,
218
- // The weight of the input including an estimate of its witness weight.
219
- weight : Weight ,
220
218
prev_output : TxOut ,
221
219
}
222
220
@@ -233,8 +231,7 @@ impl NegotiatedTxInput {
233
231
impl_writeable_tlv_based ! ( NegotiatedTxInput , {
234
232
( 1 , serial_id, required) ,
235
233
( 3 , txin, required) ,
236
- ( 5 , weight, required) ,
237
- ( 7 , prev_output, required) ,
234
+ ( 5 , prev_output, required) ,
238
235
} ) ;
239
236
240
237
impl_writeable_tlv_based ! ( ConstructedTransaction , {
@@ -278,6 +275,13 @@ impl ConstructedTransaction {
278
275
279
276
let remote_inputs_value_satoshis = context. remote_inputs_value ( ) ;
280
277
let remote_outputs_value_satoshis = context. remote_outputs_value ( ) ;
278
+
279
+ let satisfaction_weight = Weight :: from_wu ( context
280
+ . inputs
281
+ . iter ( )
282
+ . fold ( 0u64 , |value, ( _, input) | value. saturating_add ( input. satisfaction_weight ( ) . to_wu ( ) ) )
283
+ ) ;
284
+
281
285
let mut inputs: Vec < NegotiatedTxInput > =
282
286
context. inputs . into_values ( ) . map ( |tx_input| tx_input. into_negotiated_input ( ) ) . collect ( ) ;
283
287
let mut outputs: Vec < InteractiveTxOutput > = context. outputs . into_values ( ) . collect ( ) ;
@@ -310,17 +314,18 @@ impl ConstructedTransaction {
310
314
shared_input_index,
311
315
} ;
312
316
313
- if constructed_tx. weight ( ) . to_wu ( ) > MAX_STANDARD_TX_WEIGHT as u64 {
317
+ let tx_weight = constructed_tx. weight ( satisfaction_weight) ;
318
+ if tx_weight > Weight :: from_wu ( MAX_STANDARD_TX_WEIGHT as u64 ) {
314
319
return Err ( AbortReason :: TransactionTooLarge ) ;
315
320
}
316
321
317
322
Ok ( constructed_tx)
318
323
}
319
324
320
- pub fn weight ( & self ) -> Weight {
321
- let inputs_weight = self . inputs . iter ( ) . fold ( Weight :: from_wu ( 0 ) , |weight , input| {
322
- weight . checked_add ( input . weight ) . unwrap_or ( Weight :: MAX )
323
- } ) ;
325
+ fn weight ( & self , satisfaction_weight : Weight ) -> Weight {
326
+ let inputs_weight = Weight :: from_wu ( self . inputs . len ( ) as u64 * BASE_INPUT_WEIGHT )
327
+ . checked_add ( satisfaction_weight )
328
+ . unwrap_or ( Weight :: MAX ) ;
324
329
let outputs_weight = self . outputs . iter ( ) . fold ( Weight :: from_wu ( 0 ) , |weight, output| {
325
330
weight. checked_add ( get_output_weight ( output. script_pubkey ( ) ) ) . unwrap_or ( Weight :: MAX )
326
331
} ) ;
@@ -1844,9 +1849,8 @@ impl InteractiveTxInput {
1844
1849
}
1845
1850
1846
1851
fn into_negotiated_input ( self ) -> NegotiatedTxInput {
1847
- let weight = Weight :: from_wu ( BASE_INPUT_WEIGHT ) + self . input . satisfaction_weight ( ) ;
1848
1852
let ( txin, prev_output) = self . input . into_tx_in_with_prev_output ( ) ;
1849
- NegotiatedTxInput { serial_id : self . serial_id , txin, weight , prev_output }
1853
+ NegotiatedTxInput { serial_id : self . serial_id , txin, prev_output }
1850
1854
}
1851
1855
}
1852
1856
@@ -3316,7 +3320,6 @@ mod tests {
3316
3320
NegotiatedTxInput {
3317
3321
serial_id : idx as u64 , // even values will be holder (initiator in this test)
3318
3322
txin,
3319
- weight : Weight :: from_wu ( 0 ) , // N/A for test
3320
3323
prev_output,
3321
3324
}
3322
3325
} )
0 commit comments