Skip to content

Commit

Permalink
Modify the gas threshold type, representing value/100
Browse files Browse the repository at this point in the history
  • Loading branch information
sulijia committed Aug 15, 2024
1 parent 44a1ab8 commit 85526b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 14 additions & 6 deletions pallets/on-demand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -110,7 +113,7 @@ pub mod pallet {
/// Gas threshold that triggers order placement.
#[pallet::storage]
#[pallet::getter(fn gas_threshold)]
pub(super) type GasThreshold<T: Config> = StorageValue<_, Perbill, ValueQuery>;
pub(super) type GasThreshold<T: Config> = StorageValue<_, u128, ValueQuery>;

/// Order Information Map.
#[pallet::storage]
Expand All @@ -132,7 +135,7 @@ pub mod pallet {
{
pub slot_width: u32,
pub price_limit: BalanceOf<T>,
pub gas_threshold: Perbill,
pub gas_threshold: u128,
}

#[pallet::genesis_build]
Expand Down Expand Up @@ -307,7 +310,7 @@ pub mod pallet {
#[pallet::weight(<T as pallet::Config>::WeightInfo::set_gas_threshold())]
pub fn set_gas_threshold(
origin: OriginFor<T>,
threshold: Perbill,
threshold: u128,
) -> DispatchResultWithPostInfo {
T::UpdateOrigin::ensure_origin(origin)?;

Expand All @@ -325,9 +328,14 @@ where
///
/// Parameters:
/// - `gas_balance`: The total gas.
pub fn reach_txpool_threshold(gas_balance: BalanceOf<T>, core_price: BalanceOf<T>) -> bool {
pub fn reach_txpool_threshold(gas_balance: BalanceOf<T>, core_price: BalanceOf<T>) -> bool
where
BalanceOf<T>: Into<u128>,
{
let txpool_threshold = GasThreshold::<T>::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 {
Expand Down
2 changes: 1 addition & 1 deletion pallets/on-demand/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl ExtBuilder {
crate::GenesisConfig::<Test> {
slot_width: 3,
price_limit: 200000000,
gas_threshold: Perbill::one(),
gas_threshold: 1,
}
.assimilate_storage(&mut t)
.unwrap();
Expand Down

0 comments on commit 85526b8

Please sign in to comment.