From 64e9e311e57dabae9f01b8453d76c33e8d4b9c1a Mon Sep 17 00:00:00 2001 From: Daniil Polyakov Date: Mon, 19 Feb 2024 18:08:01 +0300 Subject: [PATCH] [feature] #3354: Different fuel limit for Executor Signed-off-by: Daniil Polyakov --- config/src/parameters/actual.rs | 2 ++ config/src/parameters/user.rs | 8 ++++++++ config/src/parameters/user/boilerplate.rs | 6 ++++++ config/tests/fixtures.rs | 6 ++++++ configs/swarm/genesis.json | 6 ++++++ core/benches/blocks/common.rs | 2 ++ core/src/executor.rs | 8 ++++---- core/src/wsv.rs | 2 ++ data_model/src/lib.rs | 2 ++ tools/kagami/src/genesis.rs | 2 ++ 10 files changed, 40 insertions(+), 4 deletions(-) diff --git a/config/src/parameters/actual.rs b/config/src/parameters/actual.rs index 9a54da8e990..249553d7195 100644 --- a/config/src/parameters/actual.rs +++ b/config/src/parameters/actual.rs @@ -182,6 +182,7 @@ pub struct ChainWide { pub account_metadata_limits: MetadataLimits, pub domain_metadata_limits: MetadataLimits, pub ident_length_limits: LengthLimits, + pub executor_runtime: WasmRuntime, pub wasm_runtime: WasmRuntime, } @@ -204,6 +205,7 @@ impl Default for ChainWide { asset_definition_metadata_limits: defaults::chain_wide::DEFAULT_METADATA_LIMITS, asset_metadata_limits: defaults::chain_wide::DEFAULT_METADATA_LIMITS, ident_length_limits: defaults::chain_wide::DEFAULT_IDENT_LENGTH_LIMITS, + executor_runtime: WasmRuntime::default(), wasm_runtime: WasmRuntime::default(), } } diff --git a/config/src/parameters/user.rs b/config/src/parameters/user.rs index 57238af0aaf..97aeb290bab 100644 --- a/config/src/parameters/user.rs +++ b/config/src/parameters/user.rs @@ -557,6 +557,8 @@ pub struct ChainWide { pub account_metadata_limits: MetadataLimits, pub domain_metadata_limits: MetadataLimits, pub ident_length_limits: LengthLimits, + pub executor_fuel_limit: u64, + pub executor_max_memory: HumanBytes, pub wasm_fuel_limit: u64, pub wasm_max_memory: HumanBytes, } @@ -573,6 +575,8 @@ impl ChainWide { account_metadata_limits, domain_metadata_limits, ident_length_limits: identifier_length_limits, + executor_fuel_limit, + executor_max_memory, wasm_fuel_limit, wasm_max_memory, } = self; @@ -587,6 +591,10 @@ impl ChainWide { account_metadata_limits, domain_metadata_limits, ident_length_limits: identifier_length_limits, + executor_runtime: actual::WasmRuntime { + fuel_limit: executor_fuel_limit, + max_memory_bytes: executor_max_memory.get(), + }, wasm_runtime: actual::WasmRuntime { fuel_limit: wasm_fuel_limit, max_memory_bytes: wasm_max_memory.get(), diff --git a/config/src/parameters/user/boilerplate.rs b/config/src/parameters/user/boilerplate.rs index 64b81d9d6ff..4fc88772ad5 100644 --- a/config/src/parameters/user/boilerplate.rs +++ b/config/src/parameters/user/boilerplate.rs @@ -664,6 +664,8 @@ pub struct ChainWidePartial { pub account_metadata_limits: UserField, pub domain_metadata_limits: UserField, pub ident_length_limits: UserField, + pub executor_fuel_limit: UserField, + pub executor_max_memory: UserField>, pub wasm_fuel_limit: UserField, pub wasm_max_memory: UserField>, } @@ -698,6 +700,10 @@ impl UnwrapPartial for ChainWidePartial { ident_length_limits: self .ident_length_limits .unwrap_or(DEFAULT_IDENT_LENGTH_LIMITS), + executor_fuel_limit: self.executor_fuel_limit.unwrap_or(DEFAULT_WASM_FUEL_LIMIT), + executor_max_memory: self + .executor_max_memory + .unwrap_or(HumanBytes(DEFAULT_WASM_MAX_MEMORY_BYTES)), wasm_fuel_limit: self.wasm_fuel_limit.unwrap_or(DEFAULT_WASM_FUEL_LIMIT), wasm_max_memory: self .wasm_max_memory diff --git a/config/tests/fixtures.rs b/config/tests/fixtures.rs index 214290a1eb2..7cfd467fa29 100644 --- a/config/tests/fixtures.rs +++ b/config/tests/fixtures.rs @@ -157,6 +157,10 @@ fn minimal_config_snapshot() -> Result<()> { min: 1, max: 128, }, + executor_runtime: WasmRuntime { + fuel_limit: 55000000, + max_memory_bytes: 524288000, + }, wasm_runtime: WasmRuntime { fuel_limit: 55000000, max_memory_bytes: 524288000, @@ -397,6 +401,8 @@ fn full_envs_set_is_consumed() -> Result<()> { account_metadata_limits: None, domain_metadata_limits: None, ident_length_limits: None, + executor_fuel_limit: None, + executor_max_memory: None, wasm_fuel_limit: None, wasm_max_memory: None, }, diff --git a/configs/swarm/genesis.json b/configs/swarm/genesis.json index c532ef5411b..06ff98e60d6 100644 --- a/configs/swarm/genesis.json +++ b/configs/swarm/genesis.json @@ -153,6 +153,12 @@ { "NewParameter": "?WSVIdentLengthLimits=1,128_LL" }, + { + "NewParameter": "?ExecutorFuelLimit=55000000" + }, + { + "NewParameter": "?ExecutorMaxMemory=524288000" + }, { "NewParameter": "?WASMFuelLimit=55000000" }, diff --git a/core/benches/blocks/common.rs b/core/benches/blocks/common.rs index a81cd11a8e3..bfe24efe223 100644 --- a/core/benches/blocks/common.rs +++ b/core/benches/blocks/common.rs @@ -185,6 +185,8 @@ pub fn build_wsv( ); let mut wsv = WorldStateView::new(World::with([domain], UniqueVec::new()), kura, query_handle); wsv.config.transaction_limits = TransactionLimits::new(u64::MAX, u64::MAX); + wsv.config.executor_runtime.fuel_limit = u64::MAX; + wsv.config.executor_runtime.max_memory_bytes = u32::MAX; wsv.config.wasm_runtime.fuel_limit = u64::MAX; wsv.config.wasm_runtime.max_memory_bytes = u32::MAX; diff --git a/core/src/executor.rs b/core/src/executor.rs index 70eb4c5fc0a..dcc12a9fa42 100644 --- a/core/src/executor.rs +++ b/core/src/executor.rs @@ -157,7 +157,7 @@ impl Executor { let runtime = wasm::RuntimeBuilder::::new() .with_engine(wsv.engine.clone()) // Cloning engine is cheap, see [`wasmtime::Engine`] docs - .with_config(wsv.config.wasm_runtime) + .with_config(wsv.config.executor_runtime) .build()?; runtime.execute_executor_validate_transaction( @@ -191,7 +191,7 @@ impl Executor { let runtime = wasm::RuntimeBuilder::::new() .with_engine(wsv.engine.clone()) // Cloning engine is cheap, see [`wasmtime::Engine`] docs - .with_config(wsv.config.wasm_runtime) + .with_config(wsv.config.executor_runtime) .build()?; runtime.execute_executor_validate_instruction( @@ -224,7 +224,7 @@ impl Executor { Self::UserProvided(UserProvidedExecutor(loaded_executor)) => { let runtime = wasm::RuntimeBuilder::::new() .with_engine(wsv.engine.clone()) // Cloning engine is cheap, see [`wasmtime::Engine`] docs - .with_config(wsv.config.wasm_runtime) + .with_config(wsv.config.executor_runtime) .build()?; runtime.execute_executor_validate_query( @@ -259,7 +259,7 @@ impl Executor { let runtime = wasm::RuntimeBuilder::::new() .with_engine(wsv.engine.clone()) // Cloning engine is cheap, see [`wasmtime::Engine`] docs - .with_config(wsv.config.wasm_runtime) + .with_config(wsv.config.executor_runtime) .build()?; runtime diff --git a/core/src/wsv.rs b/core/src/wsv.rs index 17dee33d3df..7baae7259ce 100644 --- a/core/src/wsv.rs +++ b/core/src/wsv.rs @@ -689,6 +689,8 @@ impl WorldStateView { WSV_ACCOUNT_METADATA_LIMITS => self.config.account_metadata_limits, WSV_DOMAIN_METADATA_LIMITS => self.config.domain_metadata_limits, WSV_IDENT_LENGTH_LIMITS => self.config.ident_length_limits, + EXECUTOR_FUEL_LIMIT => self.config.executor_runtime.fuel_limit, + EXECUTOR_MAX_MEMORY => self.config.executor_runtime.max_memory_bytes, WASM_FUEL_LIMIT => self.config.wasm_runtime.fuel_limit, WASM_MAX_MEMORY => self.config.wasm_runtime.max_memory_bytes, TRANSACTION_LIMITS => self.config.transaction_limits, diff --git a/data_model/src/lib.rs b/data_model/src/lib.rs index 561228a73cc..b124e7e678d 100644 --- a/data_model/src/lib.rs +++ b/data_model/src/lib.rs @@ -275,6 +275,8 @@ pub mod parameter { pub const WSV_ACCOUNT_METADATA_LIMITS: &str = "WSVAccountMetadataLimits"; pub const WSV_DOMAIN_METADATA_LIMITS: &str = "WSVDomainMetadataLimits"; pub const WSV_IDENT_LENGTH_LIMITS: &str = "WSVIdentLengthLimits"; + pub const EXECUTOR_FUEL_LIMIT: &str = "ExecutorFuelLimit"; + pub const EXECUTOR_MAX_MEMORY: &str = "ExecutorMaxMemory"; pub const WASM_FUEL_LIMIT: &str = "WASMFuelLimit"; pub const WASM_MAX_MEMORY: &str = "WASMMaxMemory"; } diff --git a/tools/kagami/src/genesis.rs b/tools/kagami/src/genesis.rs index 4c6d5e67e75..7f4ed34ea8a 100644 --- a/tools/kagami/src/genesis.rs +++ b/tools/kagami/src/genesis.rs @@ -191,6 +191,8 @@ pub fn generate_default(executor: ExecutorMode) -> color_eyre::Result