File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -226,6 +226,7 @@ impl VTTransaction {
226226 /// This is the weight that will be used to calculate
227227 /// how many transactions can fit inside one block
228228 pub fn weight ( & self ) -> u32 {
229+ // TODO: witness length does not affect weight
229230 self . body . weight ( )
230231 }
231232
@@ -275,7 +276,17 @@ impl VTTransactionBody {
275276 . saturating_mul ( OUTPUT_SIZE )
276277 . saturating_mul ( GAMMA ) ;
277278
278- inputs_weight. saturating_add ( outputs_weight)
279+ // Add 1 weight unit for each byte in input script field
280+ // This ignores any potential serialization overhead
281+ let mut redeem_scripts_weight: u32 = 0 ;
282+ for input in & self . inputs {
283+ redeem_scripts_weight = redeem_scripts_weight
284+ . saturating_add ( u32:: try_from ( input. redeem_script . len ( ) ) . unwrap_or ( u32:: MAX ) ) ;
285+ }
286+
287+ inputs_weight
288+ . saturating_add ( outputs_weight)
289+ . saturating_add ( redeem_scripts_weight)
279290 }
280291}
281292
You can’t perform that action at this time.
0 commit comments