Skip to content

Commit c3a024e

Browse files
committed
modules/core: add incoming messages gas limit parameter
1 parent 879f012 commit c3a024e

File tree

8 files changed

+23
-0
lines changed

8 files changed

+23
-0
lines changed

runtime-sdk/src/modules/core/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ pub struct GasCosts {
145145
#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
146146
pub struct Parameters {
147147
pub max_batch_gas: u64,
148+
pub max_in_msgs_gas: u64,
148149
pub max_tx_signers: u32,
149150
pub max_multisig_signers: u32,
150151
pub gas_costs: GasCosts,
@@ -169,6 +170,9 @@ pub trait API {
169170
/// Returns the remaining batch-wide gas.
170171
fn remaining_batch_gas<C: Context>(ctx: &mut C) -> u64;
171172

173+
/// Returns the remaining batch-wide gas that can be used for roothash incoming messages.
174+
fn remaining_in_msgs_gas<C: Context>(ctx: &mut C) -> u64;
175+
172176
/// Return the remaining tx-wide gas.
173177
fn remaining_tx_gas<C: TxContext>(ctx: &mut C) -> u64;
174178

@@ -300,6 +304,12 @@ impl<Cfg: Config> API for Module<Cfg> {
300304
batch_gas_limit.saturating_sub(*batch_gas_used)
301305
}
302306

307+
fn remaining_in_msgs_gas<C: Context>(ctx: &mut C) -> u64 {
308+
let in_msgs_gas_limit = Self::params(ctx.runtime_state()).max_in_msgs_gas;
309+
let batch_gas_used = ctx.value::<u64>(CONTEXT_KEY_GAS_USED).or_default();
310+
in_msgs_gas_limit.saturating_sub(*batch_gas_used)
311+
}
312+
303313
fn remaining_tx_gas<C: TxContext>(ctx: &mut C) -> u64 {
304314
let gas_limit = ctx.tx_auth_info().fee.gas;
305315
let gas_used = ctx.tx_value::<u64>(CONTEXT_KEY_GAS_USED).or_default();

runtime-sdk/src/modules/core/test.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ fn test_use_gas() {
3131
ctx.runtime_state(),
3232
Parameters {
3333
max_batch_gas: BLOCK_MAX_GAS,
34+
max_in_msgs_gas: BLOCK_MAX_GAS / 4,
3435
max_tx_signers: 8,
3536
max_multisig_signers: 8,
3637
gas_costs: Default::default(),
@@ -126,6 +127,7 @@ fn test_query_min_gas_price() {
126127
ctx.runtime_state(),
127128
Parameters {
128129
max_batch_gas: 10000,
130+
max_in_msgs_gas: 2500,
129131
max_tx_signers: 8,
130132
max_multisig_signers: 8,
131133
gas_costs: Default::default(),
@@ -243,6 +245,7 @@ impl Runtime for GasWasterRuntime {
243245
super::Genesis {
244246
parameters: Parameters {
245247
max_batch_gas: u64::MAX,
248+
max_in_msgs_gas: u64::MAX,
246249
max_tx_signers: 8,
247250
max_multisig_signers: 8,
248251
gas_costs: super::GasCosts {
@@ -373,6 +376,7 @@ fn test_approve_unverified_tx() {
373376
ctx.runtime_state(),
374377
Parameters {
375378
max_batch_gas: u64::MAX,
379+
max_in_msgs_gas: u64::MAX,
376380
max_tx_signers: 2,
377381
max_multisig_signers: 2,
378382
gas_costs: Default::default(),
@@ -587,6 +591,7 @@ fn test_check_weights() {
587591
ctx.runtime_state(),
588592
Parameters {
589593
max_batch_gas: u64::MAX,
594+
max_in_msgs_gas: u64::MAX,
590595
max_tx_signers: 8,
591596
max_multisig_signers: 8,
592597
gas_costs: super::GasCosts {
@@ -650,6 +655,7 @@ fn test_min_gas_price() {
650655
ctx.runtime_state(),
651656
Parameters {
652657
max_batch_gas: u64::MAX,
658+
max_in_msgs_gas: u64::MAX,
653659
max_tx_signers: 8,
654660
max_multisig_signers: 8,
655661
gas_costs: super::GasCosts {
@@ -830,6 +836,7 @@ fn test_gas_used_events() {
830836
ctx.runtime_state(),
831837
Parameters {
832838
max_batch_gas: 1_000_000,
839+
max_in_msgs_gas: 250_000,
833840
max_tx_signers: 8,
834841
max_multisig_signers: 8,
835842
gas_costs: Default::default(),

tests/runtimes/benchmarking/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ impl sdk::Runtime for Runtime {
4747
modules::core::Genesis {
4848
parameters: modules::core::Parameters {
4949
max_batch_gas: 10_000_000,
50+
max_in_msgs_gas: 2_500_000,
5051
max_tx_signers: 8,
5152
max_multisig_signers: 8,
5253
// These are free, in order to simplify benchmarking.

tests/runtimes/simple-consensus/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ impl sdk::Runtime for Runtime {
6565
modules::core::Genesis {
6666
parameters: modules::core::Parameters {
6767
max_batch_gas: 10_000,
68+
max_in_msgs_gas: 2_500,
6869
max_tx_signers: 8,
6970
max_multisig_signers: 8,
7071
// These are free, in order to simplify testing.

tests/runtimes/simple-contracts/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ impl sdk::Runtime for Runtime {
8989
modules::core::Genesis {
9090
parameters: modules::core::Parameters {
9191
max_batch_gas: 10_000_000,
92+
max_in_msgs_gas: 2_500_000,
9293
max_tx_signers: 8,
9394
max_multisig_signers: 8,
9495
gas_costs: modules::core::GasCosts {

tests/runtimes/simple-evm/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ impl sdk::Runtime for Runtime {
6969
modules::core::Genesis {
7070
parameters: modules::core::Parameters {
7171
max_batch_gas: 1_000_000,
72+
max_in_msgs_gas: 250_000,
7273
max_tx_signers: 8,
7374
max_multisig_signers: 8,
7475
gas_costs: modules::core::GasCosts {

tests/runtimes/simple-keyvalue/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ impl sdk::Runtime for Runtime {
145145
modules::core::Genesis {
146146
parameters: modules::core::Parameters {
147147
max_batch_gas: 2_000,
148+
max_in_msgs_gas: 500,
148149
max_tx_signers: 8,
149150
max_multisig_signers: 8,
150151
gas_costs: modules::core::GasCosts {

tests/runtimes/simple-keyvalue/src/test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ fn test_impl_for_tuple() {
1616
ctx.runtime_state(),
1717
core::Parameters {
1818
max_batch_gas: u64::MAX,
19+
max_in_msgs_gas: u64::MAX,
1920
max_tx_signers: 1,
2021
max_multisig_signers: 1,
2122
gas_costs: Default::default(),

0 commit comments

Comments
 (0)