difftreelog
chore store limits in BTreeMap
in: master
3 files changed
pallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth--- a/pallets/evm-contract-helpers/src/eth.rs
+++ b/pallets/evm-contract-helpers/src/eth.rs
@@ -26,7 +26,7 @@
};
use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder, dispatch_to_evm};
use pallet_evm_transaction_payment::CallContext;
-use sp_core::H160;
+use sp_core::{H160, U256};
use up_data_structs::SponsorshipState;
use crate::{
AllowlistEnabled, Config, Owner, Pallet, SponsorBasket, SponsoringFeeLimit,
@@ -258,12 +258,13 @@
fee_limit: uint256,
) -> Result<void> {
<Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;
- <Pallet<T>>::set_sponsoring_fee_limit(contract_address, fee_limit.into());
+ <Pallet<T>>::set_sponsoring_fee_limit(contract_address, fee_limit.into())
+ .map_err(dispatch_to_evm::<T>)?;
Ok(())
}
fn get_sponsoring_fee_limit(&self, contract_address: address) -> Result<uint256> {
- Ok(<SponsoringFeeLimit<T>>::get(contract_address, 0xffffffff))
+ Ok(get_sponsoring_fee_limit::<T>(contract_address))
}
/// Is specified user present in contract allow list
@@ -413,7 +414,7 @@
}
}
- let sponsored_fee_limit = <SponsoringFeeLimit<T>>::get(contract_address, 0xffffffff);
+ let sponsored_fee_limit = get_sponsoring_fee_limit::<T>(contract_address);
if call_context.max_fee > sponsored_fee_limit {
return None;
@@ -425,5 +426,12 @@
}
}
+fn get_sponsoring_fee_limit<T: Config>(contract_address: address) -> uint256 {
+ <SponsoringFeeLimit<T>>::get(contract_address)
+ .get(&0xffffffff)
+ .cloned()
+ .unwrap_or(U256::MAX)
+}
+
generate_stubgen!(contract_helpers_impl, ContractHelpersCall<()>, true);
generate_stubgen!(contract_helpers_iface, ContractHelpersCall<()>, false);
pallets/evm-contract-helpers/src/lib.rsdiffbeforeafterboth22pub use pallet::*;22pub use pallet::*;23pub use eth::*;23pub use eth::*;24use scale_info::TypeInfo;24use scale_info::TypeInfo;25use frame_support::storage::bounded_btree_map::BoundedBTreeMap;25pub mod eth;26pub mod eth;2728/// Maximum number of methods per contract that could have fee limit29pub const MAX_FEE_LIMITED_METHODS: u32 = 5;263027#[frame_support::pallet]31#[frame_support::pallet]28pub mod pallet {32pub mod pallet {48 /// In case of enabled sponsoring, but no sponsoring rate limit set,52 /// In case of enabled sponsoring, but no sponsoring rate limit set,49 /// this value will be used implicitly53 /// this value will be used implicitly50 type DefaultSponsoringRateLimit: Get<Self::BlockNumber>;54 type DefaultSponsoringRateLimit: Get<Self::BlockNumber>;51 /// In case of enabled sponsoring, but no sponsoring fee limit set,52 /// this value will be used implicitly53 type DefaultSponsoringFeeLimit: Get<U256>;54 }55 }555656 #[pallet::error]57 #[pallet::error]61 /// No pending sponsor for contract.62 /// No pending sponsor for contract.62 NoPendingSponsor,63 NoPendingSponsor,6465 /// Number of methods that sponsored limit is defined for exceeds maximum.66 TooManyMethodsHaveSponsoredLimit,63 }67 }646865 #[pallet::pallet]69 #[pallet::pallet]121 /// * **Key2** - sponsored user address.125 /// * **Key2** - sponsored user address.122 /// * **Value** - last sponsored block number.126 /// * **Value** - last sponsored block number.123 #[pallet::storage]127 #[pallet::storage]124 pub(super) type SponsoringFeeLimit<T: Config> = StorageDoubleMap<128 pub(super) type SponsoringFeeLimit<T: Config> = StorageMap<125 Hasher1 = Twox128,129 Hasher = Twox128,126 Key1 = H160,130 Key = H160,127 Hasher2 = Blake2_128Concat,128 Key2 = u32,129 Value = U256,131 Value = BoundedBTreeMap<u32, U256, ConstU32<MAX_FEE_LIMITED_METHODS>>,130 QueryKind = ValueQuery,132 QueryKind = ValueQuery,131 OnEmpty = T::DefaultSponsoringFeeLimit,132 >;133 >;133134134 #[pallet::storage]135 #[pallet::storage]368 }369 }369370370 /// Set maximum for gas limit of transaction371 /// Set maximum for gas limit of transaction371 pub fn set_sponsoring_fee_limit(contract: H160, fee_limit: U256) {372 pub fn set_sponsoring_fee_limit(contract: H160, fee_limit: U256) -> DispatchResult {372 <SponsoringFeeLimit<T>>::insert(contract, 0xffffffff, fee_limit);373 <SponsoringFeeLimit<T>>::try_mutate(contract, |limits_map| {374 limits_map375 .try_insert(0xffffffff, fee_limit)376 .map_err(|_| <Error<T>>::TooManyMethodsHaveSponsoredLimit)377 })?;378 Ok(())373 }379 }374380375 /// Is user added to allowlist, or he is owner of specified contract381 /// Is user added to allowlist, or he is owner of specified contractruntime/common/config/ethereum.rsdiffbeforeafterboth--- a/runtime/common/config/ethereum.rs
+++ b/runtime/common/config/ethereum.rs
@@ -7,10 +7,8 @@
use sp_runtime::{RuntimeAppPublic, Perbill};
use crate::{
runtime_common::{
- dispatch::CollectionDispatchT,
- ethereum::sponsoring::EvmSponsorshipHandler,
- config::sponsoring::{DefaultSponsoringFeeLimit, DefaultSponsoringRateLimit},
- DealWithFees,
+ dispatch::CollectionDispatchT, ethereum::sponsoring::EvmSponsorshipHandler,
+ config::sponsoring::DefaultSponsoringRateLimit, DealWithFees,
},
Runtime, Aura, Balances, Event, ChainId,
};
@@ -117,7 +115,6 @@
type Event = Event;
type ContractAddress = HelpersContractAddress;
type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;
- type DefaultSponsoringFeeLimit = DefaultSponsoringFeeLimit;
}
impl pallet_evm_coder_substrate::Config for Runtime {}