Skip to content

Commit

Permalink
Add gas allowance check to gear-eth-bridge builtin actor
Browse files Browse the repository at this point in the history
  • Loading branch information
ekovalev committed Nov 26, 2024
1 parent bab7890 commit f1257de
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion pallets/gear-eth-bridge/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{Config, Error, Pallet, WeightInfo};
use common::Origin;
use common::{storage::Limiter, BlockLimiter, Origin};
use core::marker::PhantomData;
use gbuiltin_eth_bridge::{Request, Response};
use gear_core::{
Expand All @@ -30,6 +30,8 @@ use parity_scale_codec::{Decode, Encode};
use sp_runtime::traits::Zero;
use sp_std::vec::Vec;

pub type GasAllowanceOf<T> = <<T as Config>::BlockLimiter as BlockLimiter>::GasAllowance;

/// Gear builtin actor providing functionality of `pallet-gear-eth-bridge`.
///
/// Check out `gbuiltin-eth-bridge` to observe builtin interface.
Expand Down Expand Up @@ -79,6 +81,9 @@ where
if gas_limit < gas_cost {
return (Err(BuiltinActorError::InsufficientGas), 0);
}
if GasAllowanceOf::<T>::get() < gas_cost {
return (Err(BuiltinActorError::GasAllowanceExceeded), 0);
}

let res = Pallet::<T>::queue_message(source, destination, payload)
.map(|(nonce, hash)| {
Expand Down
5 changes: 4 additions & 1 deletion pallets/gear-eth-bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mod tests;
#[frame_support::pallet]
pub mod pallet {
use super::*;
use common::Origin;
use common::{BlockLimiter, Origin};
use frame_support::{
pallet_prelude::*,
traits::{ConstBool, OneSessionHandler, StorageInstance, StorageVersion},
Expand Down Expand Up @@ -93,6 +93,9 @@ pub mod pallet {
#[pallet::constant]
type SessionsPerEra: Get<u32>;

/// Block limits.
type BlockLimiter: BlockLimiter<Balance = u64>;

/// Weight cost incurred by pallet calls.
type WeightInfo: WeightInfo;
}
Expand Down
1 change: 1 addition & 0 deletions pallets/gear-eth-bridge/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ impl pallet_gear_eth_bridge::Config for Test {
type MaxPayloadSize = ConstU32<1024>;
type QueueCapacity = ConstU32<32>;
type SessionsPerEra = SessionsPerEra;
type BlockLimiter = GearGas;
type WeightInfo = ();
}

Expand Down
1 change: 1 addition & 0 deletions runtime/vara/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,7 @@ impl pallet_gear_eth_bridge::Config for Runtime {
type MaxPayloadSize = ConstU32<16_384>; // 16 KiB
type QueueCapacity = ConstU32<2048>;
type SessionsPerEra = SessionsPerEra;
type BlockLimiter = GearGas;
type WeightInfo = weights::pallet_gear_eth_bridge::SubstrateWeight<Runtime>;
}

Expand Down

0 comments on commit f1257de

Please sign in to comment.