diff --git a/runtime-sdk/src/modules/core/mod.rs b/runtime-sdk/src/modules/core/mod.rs index 28cadacae3..0e9c9599b3 100644 --- a/runtime-sdk/src/modules/core/mod.rs +++ b/runtime-sdk/src/modules/core/mod.rs @@ -145,6 +145,7 @@ pub struct GasCosts { #[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)] pub struct Parameters { pub max_batch_gas: u64, + pub max_in_msgs_gas: u64, pub max_tx_signers: u32, pub max_multisig_signers: u32, pub gas_costs: GasCosts, @@ -169,6 +170,8 @@ pub trait API { /// Returns the remaining batch-wide gas. fn remaining_batch_gas(ctx: &mut C) -> u64; + fn remaining_in_msgs_gas(ctx: &mut C) -> u64; + /// Return the remaining tx-wide gas. fn remaining_tx_gas(ctx: &mut C) -> u64; @@ -300,6 +303,12 @@ impl API for Module { batch_gas_limit.saturating_sub(*batch_gas_used) } + fn remaining_in_msgs_gas(ctx: &mut C) -> u64 { + let in_msgs_gas_limit = Self::params(ctx.runtime_state()).max_in_msgs_gas; + let batch_gas_used = ctx.value::(CONTEXT_KEY_GAS_USED).or_default(); + in_msgs_gas_limit.saturating_sub(*batch_gas_used) + } + fn remaining_tx_gas(ctx: &mut C) -> u64 { let gas_limit = ctx.tx_auth_info().fee.gas; let gas_used = ctx.tx_value::(CONTEXT_KEY_GAS_USED).or_default(); diff --git a/runtime-sdk/src/modules/core/test.rs b/runtime-sdk/src/modules/core/test.rs index abfbd7bb7b..d143b78be8 100644 --- a/runtime-sdk/src/modules/core/test.rs +++ b/runtime-sdk/src/modules/core/test.rs @@ -31,6 +31,7 @@ fn test_use_gas() { ctx.runtime_state(), Parameters { max_batch_gas: BLOCK_MAX_GAS, + max_in_msgs_gas: BLOCK_MAX_GAS / 4, max_tx_signers: 8, max_multisig_signers: 8, gas_costs: Default::default(), @@ -126,6 +127,7 @@ fn test_query_min_gas_price() { ctx.runtime_state(), Parameters { max_batch_gas: 10000, + max_in_msgs_gas: 2500, max_tx_signers: 8, max_multisig_signers: 8, gas_costs: Default::default(), @@ -243,6 +245,7 @@ impl Runtime for GasWasterRuntime { super::Genesis { parameters: Parameters { max_batch_gas: u64::MAX, + max_in_msgs_gas: u64::MAX, max_tx_signers: 8, max_multisig_signers: 8, gas_costs: super::GasCosts { @@ -373,6 +376,7 @@ fn test_approve_unverified_tx() { ctx.runtime_state(), Parameters { max_batch_gas: u64::MAX, + max_in_msgs_gas: u64::MAX, max_tx_signers: 2, max_multisig_signers: 2, gas_costs: Default::default(), @@ -587,6 +591,7 @@ fn test_check_weights() { ctx.runtime_state(), Parameters { max_batch_gas: u64::MAX, + max_in_msgs_gas: u64::MAX, max_tx_signers: 8, max_multisig_signers: 8, gas_costs: super::GasCosts { @@ -650,6 +655,7 @@ fn test_min_gas_price() { ctx.runtime_state(), Parameters { max_batch_gas: u64::MAX, + max_in_msgs_gas: u64::MAX, max_tx_signers: 8, max_multisig_signers: 8, gas_costs: super::GasCosts { @@ -830,6 +836,7 @@ fn test_gas_used_events() { ctx.runtime_state(), Parameters { max_batch_gas: 1_000_000, + max_in_msgs_gas: 250_000, max_tx_signers: 8, max_multisig_signers: 8, gas_costs: Default::default(), diff --git a/tests/runtimes/benchmarking/src/lib.rs b/tests/runtimes/benchmarking/src/lib.rs index 37f202f74b..2e23f76209 100644 --- a/tests/runtimes/benchmarking/src/lib.rs +++ b/tests/runtimes/benchmarking/src/lib.rs @@ -47,6 +47,7 @@ impl sdk::Runtime for Runtime { modules::core::Genesis { parameters: modules::core::Parameters { max_batch_gas: 10_000_000, + max_in_msgs_gas: 2_500_000, max_tx_signers: 8, max_multisig_signers: 8, // These are free, in order to simplify benchmarking. diff --git a/tests/runtimes/simple-consensus/src/lib.rs b/tests/runtimes/simple-consensus/src/lib.rs index 2e1c493ebd..61fcf9a0db 100644 --- a/tests/runtimes/simple-consensus/src/lib.rs +++ b/tests/runtimes/simple-consensus/src/lib.rs @@ -65,6 +65,7 @@ impl sdk::Runtime for Runtime { modules::core::Genesis { parameters: modules::core::Parameters { max_batch_gas: 10_000, + max_in_msgs_gas: 2_500, max_tx_signers: 8, max_multisig_signers: 8, // These are free, in order to simplify testing. diff --git a/tests/runtimes/simple-contracts/src/lib.rs b/tests/runtimes/simple-contracts/src/lib.rs index ba572f33ff..64111473e5 100644 --- a/tests/runtimes/simple-contracts/src/lib.rs +++ b/tests/runtimes/simple-contracts/src/lib.rs @@ -89,6 +89,7 @@ impl sdk::Runtime for Runtime { modules::core::Genesis { parameters: modules::core::Parameters { max_batch_gas: 10_000_000, + max_in_msgs_gas: 2_500_000, max_tx_signers: 8, max_multisig_signers: 8, gas_costs: modules::core::GasCosts { diff --git a/tests/runtimes/simple-evm/src/lib.rs b/tests/runtimes/simple-evm/src/lib.rs index 65f0684af5..f2f92661db 100644 --- a/tests/runtimes/simple-evm/src/lib.rs +++ b/tests/runtimes/simple-evm/src/lib.rs @@ -69,6 +69,7 @@ impl sdk::Runtime for Runtime { modules::core::Genesis { parameters: modules::core::Parameters { max_batch_gas: 1_000_000, + max_in_msgs_gas: 250_000, max_tx_signers: 8, max_multisig_signers: 8, gas_costs: modules::core::GasCosts { diff --git a/tests/runtimes/simple-keyvalue/src/lib.rs b/tests/runtimes/simple-keyvalue/src/lib.rs index 80c4d77934..66c946439e 100644 --- a/tests/runtimes/simple-keyvalue/src/lib.rs +++ b/tests/runtimes/simple-keyvalue/src/lib.rs @@ -145,6 +145,7 @@ impl sdk::Runtime for Runtime { modules::core::Genesis { parameters: modules::core::Parameters { max_batch_gas: 2_000, + max_in_msgs_gas: 500, max_tx_signers: 8, max_multisig_signers: 8, gas_costs: modules::core::GasCosts { diff --git a/tests/runtimes/simple-keyvalue/src/test.rs b/tests/runtimes/simple-keyvalue/src/test.rs index 0a6ad2a25d..228179251d 100644 --- a/tests/runtimes/simple-keyvalue/src/test.rs +++ b/tests/runtimes/simple-keyvalue/src/test.rs @@ -16,6 +16,7 @@ fn test_impl_for_tuple() { ctx.runtime_state(), core::Parameters { max_batch_gas: u64::MAX, + max_in_msgs_gas: u64::MAX, max_tx_signers: 1, max_multisig_signers: 1, gas_costs: Default::default(),