@@ -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,12 @@ 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 =
280
+ Weight :: from_wu ( context. inputs . iter ( ) . fold ( 0u64 , |value, ( _, input) | {
281
+ value. saturating_add ( input. satisfaction_weight ( ) . to_wu ( ) )
282
+ } ) ) ;
283
+
281
284
let mut inputs: Vec < NegotiatedTxInput > =
282
285
context. inputs . into_values ( ) . map ( |tx_input| tx_input. into_negotiated_input ( ) ) . collect ( ) ;
283
286
let mut outputs: Vec < InteractiveTxOutput > = context. outputs . into_values ( ) . collect ( ) ;
@@ -310,17 +313,18 @@ impl ConstructedTransaction {
310
313
shared_input_index,
311
314
} ;
312
315
313
- if constructed_tx. weight ( ) . to_wu ( ) > MAX_STANDARD_TX_WEIGHT as u64 {
316
+ let tx_weight = constructed_tx. weight ( satisfaction_weight) ;
317
+ if tx_weight > Weight :: from_wu ( MAX_STANDARD_TX_WEIGHT as u64 ) {
314
318
return Err ( AbortReason :: TransactionTooLarge ) ;
315
319
}
316
320
317
321
Ok ( constructed_tx)
318
322
}
319
323
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
- } ) ;
324
+ fn weight ( & self , satisfaction_weight : Weight ) -> Weight {
325
+ let inputs_weight = Weight :: from_wu ( self . inputs . len ( ) as u64 * BASE_INPUT_WEIGHT )
326
+ . checked_add ( satisfaction_weight )
327
+ . unwrap_or ( Weight :: MAX ) ;
324
328
let outputs_weight = self . outputs . iter ( ) . fold ( Weight :: from_wu ( 0 ) , |weight, output| {
325
329
weight. checked_add ( get_output_weight ( output. script_pubkey ( ) ) ) . unwrap_or ( Weight :: MAX )
326
330
} ) ;
@@ -1852,9 +1856,8 @@ impl InteractiveTxInput {
1852
1856
}
1853
1857
1854
1858
fn into_negotiated_input ( self ) -> NegotiatedTxInput {
1855
- let weight = Weight :: from_wu ( BASE_INPUT_WEIGHT ) + self . input . satisfaction_weight ( ) ;
1856
1859
let ( txin, prev_output) = self . input . into_tx_in_with_prev_output ( ) ;
1857
- NegotiatedTxInput { serial_id : self . serial_id , txin, weight , prev_output }
1860
+ NegotiatedTxInput { serial_id : self . serial_id , txin, prev_output }
1858
1861
}
1859
1862
}
1860
1863
@@ -3328,7 +3331,6 @@ mod tests {
3328
3331
NegotiatedTxInput {
3329
3332
serial_id : idx as u64 , // even values will be holder (initiator in this test)
3330
3333
txin,
3331
- weight : Weight :: from_wu ( 0 ) , // N/A for test
3332
3334
prev_output,
3333
3335
}
3334
3336
} )
0 commit comments