Skip to content

Commit

Permalink
[feature] hyperledger-iroha#3354: Different fuel limit for Executor
Browse files Browse the repository at this point in the history
Signed-off-by: Daniil Polyakov <[email protected]>
  • Loading branch information
Arjentix committed Feb 20, 2024
1 parent ac3d4c9 commit 64e9e31
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 4 deletions.
2 changes: 2 additions & 0 deletions config/src/parameters/actual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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(),
}
}
Expand Down
8 changes: 8 additions & 0 deletions config/src/parameters/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32>,
pub wasm_fuel_limit: u64,
pub wasm_max_memory: HumanBytes<u32>,
}
Expand All @@ -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;
Expand All @@ -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(),
Expand Down
6 changes: 6 additions & 0 deletions config/src/parameters/user/boilerplate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,8 @@ pub struct ChainWidePartial {
pub account_metadata_limits: UserField<MetadataLimits>,
pub domain_metadata_limits: UserField<MetadataLimits>,
pub ident_length_limits: UserField<LengthLimits>,
pub executor_fuel_limit: UserField<u64>,
pub executor_max_memory: UserField<HumanBytes<u32>>,
pub wasm_fuel_limit: UserField<u64>,
pub wasm_max_memory: UserField<HumanBytes<u32>>,
}
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions config/tests/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
},
Expand Down
6 changes: 6 additions & 0 deletions configs/swarm/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@
{
"NewParameter": "?WSVIdentLengthLimits=1,128_LL"
},
{
"NewParameter": "?ExecutorFuelLimit=55000000"
},
{
"NewParameter": "?ExecutorMaxMemory=524288000"
},
{
"NewParameter": "?WASMFuelLimit=55000000"
},
Expand Down
2 changes: 2 additions & 0 deletions core/benches/blocks/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 4 additions & 4 deletions core/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl Executor {
let runtime =
wasm::RuntimeBuilder::<wasm::state::executor::ValidateTransaction>::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(
Expand Down Expand Up @@ -191,7 +191,7 @@ impl Executor {
let runtime =
wasm::RuntimeBuilder::<wasm::state::executor::ValidateInstruction>::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(
Expand Down Expand Up @@ -224,7 +224,7 @@ impl Executor {
Self::UserProvided(UserProvidedExecutor(loaded_executor)) => {
let runtime = wasm::RuntimeBuilder::<wasm::state::executor::ValidateQuery>::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(
Expand Down Expand Up @@ -259,7 +259,7 @@ impl Executor {

let runtime = wasm::RuntimeBuilder::<wasm::state::executor::Migrate>::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
Expand Down
2 changes: 2 additions & 0 deletions core/src/wsv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions data_model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
2 changes: 2 additions & 0 deletions tools/kagami/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ pub fn generate_default(executor: ExecutorMode) -> color_eyre::Result<RawGenesis
.add_parameter(WSV_ACCOUNT_METADATA_LIMITS, DEFAULT_METADATA_LIMITS)?
.add_parameter(WSV_DOMAIN_METADATA_LIMITS, DEFAULT_METADATA_LIMITS)?
.add_parameter(WSV_IDENT_LENGTH_LIMITS, DEFAULT_IDENT_LENGTH_LIMITS)?
.add_parameter(EXECUTOR_FUEL_LIMIT, DEFAULT_WASM_FUEL_LIMIT)?
.add_parameter(EXECUTOR_MAX_MEMORY, DEFAULT_WASM_MAX_MEMORY_BYTES)?
.add_parameter(WASM_FUEL_LIMIT, DEFAULT_WASM_FUEL_LIMIT)?
.add_parameter(WASM_MAX_MEMORY, DEFAULT_WASM_MAX_MEMORY_BYTES)?
.into_create_parameters();
Expand Down

0 comments on commit 64e9e31

Please sign in to comment.