From 85cf4b042a67706669a1f1edea582d885b787a93 Mon Sep 17 00:00:00 2001 From: Cameron Harris Date: Tue, 15 Feb 2022 20:23:02 +0200 Subject: [PATCH] Added 'add_fuel' command line option (#3792) * Added 'add_fuel' command line option * Added default value to 'add_fuel' config option * Added 'add_fuel' to run command Store instantiation * Added comment * Added warning for add-fuel without consume-fuel * Formatting * Changed out --add-fuel and --consume-fuel to --fuel * Formatting * Update src/lib.rs * Update src/commands/run.rs Co-authored-by: Nick Fitzgerald --- src/commands/run.rs | 6 ++++++ src/lib.rs | 9 ++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/commands/run.rs b/src/commands/run.rs index ae228d480a..abd1e59a1d 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -164,6 +164,12 @@ impl RunCommand { let engine = Engine::new(&config)?; let mut store = Store::new(&engine, Host::default()); + // If fuel has been configured, we want to add the configured + // fuel amount to this store. + if let Some(fuel) = self.common.fuel { + store.add_fuel(fuel)?; + } + let preopen_sockets = self.compute_preopen_sockets()?; // Make wasi available by default. diff --git a/src/lib.rs b/src/lib.rs index b3cb8961f7..1a9b20c54f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -234,9 +234,8 @@ struct CommonOptions { #[structopt(long)] enable_cranelift_nan_canonicalization: bool, - /// Executing wasm code will consume fuel, limiting its execution. #[structopt(long)] - consume_fuel: bool, + fuel: Option, /// Executing wasm code will yield when a global epoch counter /// changes, allowing for async operation without blocking the @@ -328,7 +327,11 @@ impl CommonOptions { config.dynamic_memory_guard_size(size); } - config.consume_fuel(self.consume_fuel); + // If fuel has been configured, set the `consume fuel` flag on the config. + if self.fuel.is_some() { + config.consume_fuel(true); + } + config.epoch_interruption(self.epoch_interruption); config.generate_address_map(!self.disable_address_map); config.paged_memory_initialization(self.paged_memory_initialization);