Skip to content

Commit c51fe36

Browse files
committed
runtime: Prevent panic if gas limit is too large
1 parent bbdc3d8 commit c51fe36

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

graph/src/runtime/gas/costs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const GAS_PER_SECOND: u64 = 10_000_000_000;
1313
/// like 10 gas for ~1ns allows us to be granular in instructions which are aggregated into metered
1414
/// blocks via https://docs.rs/pwasm-utils/0.16.0/pwasm_utils/fn.inject_gas_counter.html But we can
1515
/// still charge very high numbers for other things.
16-
const CONST_MAX_GAS_PER_HANDLER: u64 = 1000 * GAS_PER_SECOND;
16+
pub const CONST_MAX_GAS_PER_HANDLER: u64 = 1000 * GAS_PER_SECOND;
1717

1818
lazy_static! {
1919
/// This is configurable only for debugging purposes. This value is set by the protocol,

runtime/wasm/src/gas_rules.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{convert::TryInto, num::NonZeroU32};
22

3-
use graph::runtime::gas::MAX_GAS_PER_HANDLER;
3+
use graph::runtime::gas::CONST_MAX_GAS_PER_HANDLER;
44
use parity_wasm::elements::Instruction;
55
use pwasm_utils::rules::{MemoryGrowCost, Rules};
66

@@ -158,7 +158,7 @@ impl Rules for GasRules {
158158
// free pages because this is 32bit WASM.
159159
const MAX_PAGES: u64 = 12 * GIB / PAGE;
160160
let gas_per_page =
161-
NonZeroU32::new((*MAX_GAS_PER_HANDLER / MAX_PAGES).try_into().unwrap()).unwrap();
161+
NonZeroU32::new((CONST_MAX_GAS_PER_HANDLER / MAX_PAGES).try_into().unwrap()).unwrap();
162162

163163
Some(MemoryGrowCost::Linear(gas_per_page))
164164
}

0 commit comments

Comments
 (0)