Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configurable gas limit #21

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions esdt-safe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
multiversx_sc::imports!();
multiversx_sc::derive_imports!();

use transaction::GasLimit;
use tx_batch_module::FIRST_BATCH_ID;

const DEFAULT_MAX_TX_BATCH_SIZE: usize = 10;
const DEFAULT_MAX_TX_BATCH_BLOCK_DURATION: u64 = 100; // ~10 minutes
const DEFAULT_MAX_USER_TX_GAS_LIMIT: GasLimit = 300_000_000;

pub mod from_sovereign;
pub mod to_sovereign;
Expand Down Expand Up @@ -40,6 +42,8 @@ pub trait EsdtSafe:
self.max_tx_batch_size().set(DEFAULT_MAX_TX_BATCH_SIZE);
self.max_tx_batch_block_duration()
.set(DEFAULT_MAX_TX_BATCH_BLOCK_DURATION);
self.max_user_tx_gas_limit()
.set(DEFAULT_MAX_USER_TX_GAS_LIMIT);

// batch ID 0 is considered invalid
self.first_batch_id().set(FIRST_BATCH_ID);
Expand Down
33 changes: 31 additions & 2 deletions esdt-safe/src/to_sovereign/create_tx.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use bls_signature::BlsSignature;
use fee_market::subtract_fee::{FinalPayment, ProxyTrait as _};
use transaction::{GasLimit, StolenFromFrameworkEsdtTokenData, Transaction, TransferData};

use crate::to_sovereign::events::DepositEvent;

multiversx_sc::imports!();

const MAX_USER_TX_GAS_LIMIT: GasLimit = 300_000_000;
const MAX_TRANSFERS_PER_TX: usize = 10;

#[multiversx_sc::module]
Expand All @@ -19,6 +19,31 @@ pub trait CreateTxModule:
+ utils::UtilsModule
+ multiversx_sc_modules::pause::PauseModule
{
#[endpoint(setMaxUserTxGasLimit)]
fn set_max_user_tx_gas_limit(
&self,
new_value: GasLimit,
opt_sig: OptionalValue<BlsSignature<Self::Api>>,
) {
if !self.is_setup_phase_complete() {
self.require_caller_initiator();
self.max_user_tx_gas_limit().set(new_value);

return;
}

let opt_signature = opt_sig.into_option();
require!(opt_signature.is_some(), "Must provide signature");

let signature = unsafe { opt_signature.unwrap_unchecked() };
let mut signature_data = ManagedBuffer::new();
let _ = new_value.dep_encode(&mut signature_data);

self.multi_verify_signature(&signature_data, &signature);

self.max_user_tx_gas_limit().set(new_value);
}

/// Create an Elrond -> Sovereign transaction.
#[payable("*")]
#[endpoint]
Expand All @@ -37,8 +62,9 @@ pub trait CreateTxModule:

let opt_gas_limit = match &opt_transfer_data {
OptionalValue::Some(transfer_data) => {
let max_gas_limit = self.max_user_tx_gas_limit().get();
require!(
transfer_data.gas_limit <= MAX_USER_TX_GAS_LIMIT,
transfer_data.gas_limit <= max_gas_limit,
"Gas limit too high"
);

Expand Down Expand Up @@ -109,4 +135,7 @@ pub trait CreateTxModule:

#[storage_mapper("feeMarketAddress")]
fn fee_market_address(&self) -> SingleValueMapper<ManagedAddress>;

#[storage_mapper("maxUserTxGasLimit")]
fn max_user_tx_gas_limit(&self) -> SingleValueMapper<GasLimit>;
}
5 changes: 3 additions & 2 deletions esdt-safe/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
////////////////////////////////////////////////////

// Init: 1
// Endpoints: 31
// Endpoints: 32
// Async Callback: 1
// Promise callbacks: 1
// Total number of exported functions: 34
// Total number of exported functions: 35

#![no_std]
#![allow(internal_features)]
Expand All @@ -23,6 +23,7 @@ multiversx_sc_wasm_adapter::endpoints! {
init => init
setFeeMarketAddress => set_fee_market_address
upgrade => upgrade
setMaxUserTxGasLimit => set_max_user_tx_gas_limit
deposit => deposit
claimRefund => claim_refund
setTransactionBatchStatus => set_transaction_batch_status
Expand Down