git.delta.rocks / unique-network / refs/commits / 02b183a1e8fe

difftreelog

feat only enable sponsoring if rate limit is on

Yaroslav Bolyukin2021-07-28parent: #ea3a682.patch.diff
in: master

2 files changed

modifiedpallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth
5252
53 fn allowed(&self, contract: address, user: address) -> Result<bool> {53 fn allowed(&self, contract: address, user: address) -> Result<bool> {
54 self.0.consume_sload()?;54 self.0.consume_sload()?;
55 Ok(<Pallet<T>>::allowed(contract, user))55 Ok(<Pallet<T>>::allowed(contract, user, true))
56 }56 }
5757
58 fn allowlist_enabled(&self, contract: address) -> Result<bool> {58 fn allowlist_enabled(&self, contract: address) -> Result<bool> {
106 value: sp_core::U256,106 value: sp_core::U256,
107 ) -> Option<PrecompileOutput> {107 ) -> Option<PrecompileOutput> {
108 // TODO: Extract to another OnMethodCall handler108 // TODO: Extract to another OnMethodCall handler
109 if !<Pallet<T>>::allowed(*target, *source) {109 if !<Pallet<T>>::allowed(*target, *source, true) {
110 return Some(PrecompileOutput {110 return Some(PrecompileOutput {
111 exit_status: ExitReason::Revert(ExitRevert::Reverted),111 exit_status: ExitReason::Revert(ExitRevert::Reverted),
112 cost: 0,112 cost: 0,
144pub struct HelpersContractSponsoring<T: Config>(PhantomData<*const T>);144pub struct HelpersContractSponsoring<T: Config>(PhantomData<*const T>);
145impl<T: Config> SponsorshipHandler<H160, (H160, Vec<u8>)> for HelpersContractSponsoring<T> {145impl<T: Config> SponsorshipHandler<H160, (H160, Vec<u8>)> for HelpersContractSponsoring<T> {
146 fn get_sponsor(who: &H160, call: &(H160, Vec<u8>)) -> Option<H160> {146 fn get_sponsor(who: &H160, call: &(H160, Vec<u8>)) -> Option<H160> {
147 if <SelfSponsoring<T>>::get(&call.0) {147 if <SelfSponsoring<T>>::get(&call.0) && <Pallet<T>>::allowed(call.0, *who, false) {
148 let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;148 let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;
149 let limit = <SponsoringRateLimit<T>>::get(&call.0);149 if let Some(last_tx_block) = <SponsorBasket<T>>::get(&call.0, who) {
150 if let Some(last_tx_block) = <SponsorBasket<T>>::get(&call.0, who) {150 let rate_limit = <SponsoringRateLimit<T>>::get(&call.0);
151 let limit_time = last_tx_block + rate_limit;
152
153 if block_number > limit_time {
151 <SponsorBasket<T>>::insert(&call.0, who, block_number);154 <SponsorBasket<T>>::insert(&call.0, who, block_number);
152 let limit_time = last_tx_block + limit;
153 if block_number > limit_time {
154 return Some(call.0);155 return Some(call.0);
155 }
156 } else {156 }
157 } else {
157 <SponsorBasket<T>>::insert(&call.0, who, block_number);158 <SponsorBasket<T>>::insert(&call.0, who, block_number);
158 return Some(call.0);159 return Some(call.0);
159 }160 }
modifiedpallets/evm-contract-helpers/src/lib.rsdiffbeforeafterboth
76 <SponsoringRateLimit<T>>::insert(contract, rate_limit);76 <SponsoringRateLimit<T>>::insert(contract, rate_limit);
77 }77 }
7878
79 /// Default is returned if allowlist is disabled
79 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) == user
84 }85 }