Skip to content

Commit 6b937ef

Browse files
tmpolaczyklrubiorod
andcommitted
feat(data_structures): Implement redeem script weight in Input
Co-authored-by: Luis Rubio <l.rubiorod@gmail.com>
1 parent 5368669 commit 6b937ef

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

data_structures/src/transaction.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)