diff --git a/pallets/on-demand/src/lib.rs b/pallets/on-demand/src/lib.rs index 8f45429..9104fe1 100644 --- a/pallets/on-demand/src/lib.rs +++ b/pallets/on-demand/src/lib.rs @@ -34,7 +34,10 @@ use frame_support::{ use frame_system::pallet_prelude::*; pub use pallet::*; use primitives::Balance; -use sp_runtime::sp_std::{prelude::*, vec}; +use sp_runtime::{ + sp_std::{prelude::*, vec}, + traits::Saturating, +}; pub mod weights; use cumulus_pallet_parachain_system::RelaychainStateProvider; use sp_runtime::Perbill; @@ -110,7 +113,7 @@ pub mod pallet { /// Gas threshold that triggers order placement. #[pallet::storage] #[pallet::getter(fn gas_threshold)] - pub(super) type GasThreshold = StorageValue<_, Perbill, ValueQuery>; + pub(super) type GasThreshold = StorageValue<_, u128, ValueQuery>; /// Order Information Map. #[pallet::storage] @@ -132,7 +135,7 @@ pub mod pallet { { pub slot_width: u32, pub price_limit: BalanceOf, - pub gas_threshold: Perbill, + pub gas_threshold: u128, } #[pallet::genesis_build] @@ -307,7 +310,7 @@ pub mod pallet { #[pallet::weight(::WeightInfo::set_gas_threshold())] pub fn set_gas_threshold( origin: OriginFor, - threshold: Perbill, + threshold: u128, ) -> DispatchResultWithPostInfo { T::UpdateOrigin::ensure_origin(origin)?; @@ -325,9 +328,14 @@ where /// /// Parameters: /// - `gas_balance`: The total gas. - pub fn reach_txpool_threshold(gas_balance: BalanceOf, core_price: BalanceOf) -> bool { + pub fn reach_txpool_threshold(gas_balance: BalanceOf, core_price: BalanceOf) -> bool + where + BalanceOf: Into, + { let txpool_threshold = GasThreshold::::get(); - gas_balance > txpool_threshold * core_price + let left = gas_balance.into(); + let right = txpool_threshold * core_price.into() / 100; + left > right } fn check_slot_author(relaychian_number: u32, author: T::AccountId) -> bool { diff --git a/pallets/on-demand/src/mock.rs b/pallets/on-demand/src/mock.rs index 62d8ab6..36bfb7c 100644 --- a/pallets/on-demand/src/mock.rs +++ b/pallets/on-demand/src/mock.rs @@ -229,7 +229,7 @@ impl ExtBuilder { crate::GenesisConfig:: { slot_width: 3, price_limit: 200000000, - gas_threshold: Perbill::one(), + gas_threshold: 1, } .assimilate_storage(&mut t) .unwrap();