difftreelog
feat only enable sponsoring if rate limit is on
in: master
2 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
@@ -52,7 +52,7 @@
fn allowed(&self, contract: address, user: address) -> Result<bool> {
self.0.consume_sload()?;
- Ok(<Pallet<T>>::allowed(contract, user))
+ Ok(<Pallet<T>>::allowed(contract, user, true))
}
fn allowlist_enabled(&self, contract: address) -> Result<bool> {
@@ -106,7 +106,7 @@
value: sp_core::U256,
) -> Option<PrecompileOutput> {
// TODO: Extract to another OnMethodCall handler
- if !<Pallet<T>>::allowed(*target, *source) {
+ if !<Pallet<T>>::allowed(*target, *source, true) {
return Some(PrecompileOutput {
exit_status: ExitReason::Revert(ExitRevert::Reverted),
cost: 0,
@@ -144,13 +144,14 @@
pub struct HelpersContractSponsoring<T: Config>(PhantomData<*const T>);
impl<T: Config> SponsorshipHandler<H160, (H160, Vec<u8>)> for HelpersContractSponsoring<T> {
fn get_sponsor(who: &H160, call: &(H160, Vec<u8>)) -> Option<H160> {
- if <SelfSponsoring<T>>::get(&call.0) {
+ if <SelfSponsoring<T>>::get(&call.0) && <Pallet<T>>::allowed(call.0, *who, false) {
let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;
- let limit = <SponsoringRateLimit<T>>::get(&call.0);
if let Some(last_tx_block) = <SponsorBasket<T>>::get(&call.0, who) {
- <SponsorBasket<T>>::insert(&call.0, who, block_number);
- let limit_time = last_tx_block + limit;
+ let rate_limit = <SponsoringRateLimit<T>>::get(&call.0);
+ let limit_time = last_tx_block + rate_limit;
+
if block_number > limit_time {
+ <SponsorBasket<T>>::insert(&call.0, who, block_number);
return Some(call.0);
}
} else {
pallets/evm-contract-helpers/src/lib.rsdiffbeforeafterboth76 <SponsoringRateLimit<T>>::insert(contract, rate_limit);76 <SponsoringRateLimit<T>>::insert(contract, rate_limit);77 }77 }787879 /// Default is returned if allowlist is disabled79 pub fn allowed(contract: H160, user: H160) -> bool {80 pub fn allowed(contract: H160, user: H160, default: bool) -> bool {80 if !<AllowlistEnabled<T>>::get(contract) {81 if !<AllowlistEnabled<T>>::get(contract) {81 return true;82 return default;82 }83 }83 <Allowlist<T>>::get(&contract, &user) || <Owner<T>>::get(&contract) == user84 <Allowlist<T>>::get(&contract, &user) || <Owner<T>>::get(&contract) == user84 }85 }