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:
parent
1055d2bb0d
commit
f910587553
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue