Skip to content

Commit

Permalink
review feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptoAtwill committed Dec 12, 2024
1 parent ac4ecd2 commit 3146752
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions fendermint/vm/interpreter/src/fvm/state/priority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0, MIT

use crate::fvm::FvmMessage;
use fvm_shared::bigint::BigInt;
use fvm_shared::econ::TokenAmount;
use num_traits::{ToPrimitive, Zero};

Expand Down Expand Up @@ -40,15 +39,12 @@ impl TxnPriorityCalculator {
pub fn priority(&self, msg: &FvmMessage) -> i64 {
let base_fee = self.lowest_base_fee();

if msg.gas_fee_cap >= base_fee {
let i = msg.gas_fee_cap.clone() - base_fee + msg.gas_premium.clone();
i.atto()
.min(&BigInt::from(i64::MAX))
.to_i64()
.expect("clipped to i64 max")
} else {
0
if msg.gas_fee_cap < base_fee {
return i64::MIN;
}

let effective_premium = msg.gas_premium.clone().min(&msg.gas_fee_cap - base_fee);
effective_premium.atto().to_i64().unwrap_or(i64::MAX)
}

fn lowest_base_fee(&self) -> TokenAmount {
Expand Down Expand Up @@ -187,17 +183,20 @@ mod tests {
// lowest base fee is 10

let msg = create_msg(TokenAmount::from_atto(1), TokenAmount::from_atto(20));
assert_eq!(cal.priority(&msg), 0);
assert_eq!(cal.priority(&msg), i64::MIN);

let msg = create_msg(TokenAmount::from_atto(10), TokenAmount::from_atto(20));
assert_eq!(cal.priority(&msg), 20);
assert_eq!(cal.priority(&msg), 0);

let msg = create_msg(TokenAmount::from_atto(15), TokenAmount::from_atto(20));
assert_eq!(cal.priority(&msg), 25);
assert_eq!(cal.priority(&msg), 5);

let msg = create_msg(TokenAmount::from_atto(40), TokenAmount::from_atto(20));
assert_eq!(cal.priority(&msg), 20);

let msg = create_msg(
TokenAmount::from_atto(BigInt::from(i64::MAX)),
TokenAmount::from_atto(BigInt::from(i64::MAX)),
TokenAmount::from_atto(BigInt::from(i128::MAX)),
TokenAmount::from_atto(BigInt::from(i128::MAX)),
);
assert_eq!(cal.priority(&msg), i64::MAX);
}
Expand Down

0 comments on commit 3146752

Please sign in to comment.