fix prioritization_fees overflow (#245)

* fix prioritization_fees overflow

* suggest inline

* Cargo fmt

---------

Co-authored-by: galactus <96341601+godmodegalactus@users.noreply.github.com>
Co-authored-by: godmodegalactus <godmodegalactus@gmail.com>
This commit is contained in:
Groovie | Mango 2024-01-11 14:16:32 +01:00 committed by GitHub
parent 1055d2bb0d
commit f910587553
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 1 deletions

View File

@ -122,7 +122,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))
}
};
@ -174,3 +174,18 @@ impl ProducedBlock {
}
}
}
#[inline]
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);
}