Skip to content

Commit

Permalink
fix prioritization_fees overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
grooviegermanikus committed Nov 19, 2023
1 parent b6b879d commit d78e96f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion core/src/structures/produced_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl ProducedBlock {
if let Some((units, additional_fee)) = legacy_compute_budget {
cu_requested = Some(units);
if additional_fee > 0 {
prioritization_fees = Some(((units * 1000) / additional_fee).into())
prioritization_fees = Some(calc_prioritization_fees(units, additional_fee))
}
};

Expand Down Expand Up @@ -170,4 +170,20 @@ impl ProducedBlock {
rewards,
}
}


}

fn calc_prioritization_fees(units: u32, additional_fee: u32) -> u64 {
(units as u64 * 1000) / additional_fee as u64
}

#[test]
fn overflow_u32() {
// value high enough to overflow u32 if multiplied by 1000
let units: u32 = 4_000_000_000;
let additional_fee: u32 = 100;
let prioritization_fees: u64 = calc_prioritization_fees(units, additional_fee);

assert_eq!(40_000_000_000, prioritization_fees);
}

0 comments on commit d78e96f

Please sign in to comment.