Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove print_debug flag #1953

Merged
merged 3 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,16 @@ and this project adheres to
- cosmwasm-storage: Removed, use [cw-storage-plus] instead. ([#1936])
- cosmwasm-std: Remove `IbcReceiveResponse`'s `Default` implementation. Use
`IbcReceiveResponse::new` instead. ([#1942])
- cosmwasm-vm: Remove `InstanceOptions::print_debug` flag. Set your own handler
using `Instance::set_debug_handler`. ([#1953])

[cw-storage-plus]: https://github.com/CosmWasm/cw-storage-plus
[#1875]: https://github.com/CosmWasm/cosmwasm/pull/1875
[#1890]: https://github.com/CosmWasm/cosmwasm/pull/1890
[#1896]: https://github.com/CosmWasm/cosmwasm/pull/1896
[#1936]: https://github.com/CosmWasm/cosmwasm/pull/1936
[#1942]: https://github.com/CosmWasm/cosmwasm/pull/1942
[#1953]: https://github.com/CosmWasm/cosmwasm/pull/1953

## [1.5.0] - 2023-10-31

Expand Down
4 changes: 0 additions & 4 deletions packages/vm/benches/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const DEFAULT_MEMORY_LIMIT: Size = Size::mebi(64);
const DEFAULT_GAS_LIMIT: u64 = 1_000_000_000; // ~1ms
const DEFAULT_INSTANCE_OPTIONS: InstanceOptions = InstanceOptions {
gas_limit: DEFAULT_GAS_LIMIT,
print_debug: false,
};
const HIGH_GAS_LIMIT: u64 = 20_000_000_000_000; // ~20s, allows many calls on one instance

Expand Down Expand Up @@ -50,7 +49,6 @@ fn bench_instance(c: &mut Criterion) {
let backend = mock_backend(&[]);
let much_gas: InstanceOptions = InstanceOptions {
gas_limit: HIGH_GAS_LIMIT,
..DEFAULT_INSTANCE_OPTIONS
};
let mut instance =
Instance::from_code(CONTRACT, backend, much_gas, Some(DEFAULT_MEMORY_LIMIT)).unwrap();
Expand All @@ -68,7 +66,6 @@ fn bench_instance(c: &mut Criterion) {
let backend = mock_backend(&[]);
let much_gas: InstanceOptions = InstanceOptions {
gas_limit: HIGH_GAS_LIMIT,
..DEFAULT_INSTANCE_OPTIONS
};
let mut instance =
Instance::from_code(CONTRACT, backend, much_gas, Some(DEFAULT_MEMORY_LIMIT)).unwrap();
Expand All @@ -92,7 +89,6 @@ fn bench_instance(c: &mut Criterion) {
let backend = mock_backend(&[]);
let much_gas: InstanceOptions = InstanceOptions {
gas_limit: HIGH_GAS_LIMIT,
..DEFAULT_INSTANCE_OPTIONS
};
let mut instance =
Instance::from_code(CYBERPUNK, backend, much_gas, Some(DEFAULT_MEMORY_LIMIT)).unwrap();
Expand Down
1 change: 0 additions & 1 deletion packages/vm/examples/multi_threaded_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const DEFAULT_MEMORY_LIMIT: Size = Size::mebi(64);
const DEFAULT_GAS_LIMIT: u64 = 400_000 * 150;
const DEFAULT_INSTANCE_OPTIONS: InstanceOptions = InstanceOptions {
gas_limit: DEFAULT_GAS_LIMIT,
print_debug: false,
};
// Cache
const MEMORY_CACHE_SIZE: Size = Size::mebi(200);
Expand Down
8 changes: 1 addition & 7 deletions packages/vm/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ where
&cached.module,
backend,
options.gas_limit,
options.print_debug,
None,
Some(&self.instantiation_lock),
)?;
Expand Down Expand Up @@ -532,7 +531,6 @@ mod tests {
const TESTING_MEMORY_LIMIT: Size = Size::mebi(16);
const TESTING_OPTIONS: InstanceOptions = InstanceOptions {
gas_limit: TESTING_GAS_LIMIT,
print_debug: false,
};
const TESTING_MEMORY_CACHE_SIZE: Size = Size::mebi(200);

Expand Down Expand Up @@ -1180,10 +1178,7 @@ mod tests {
let backend2 = mock_backend(&[]);

// Init from module cache
let options = InstanceOptions {
gas_limit: 10,
print_debug: false,
};
let options = InstanceOptions { gas_limit: 10 };
let mut instance1 = cache.get_instance(&checksum, backend1, options).unwrap();
assert_eq!(cache.stats().hits_fs_cache, 1);
assert_eq!(cache.stats().misses, 0);
Expand All @@ -1202,7 +1197,6 @@ mod tests {
// Init from memory cache
let options = InstanceOptions {
gas_limit: TESTING_GAS_LIMIT,
print_debug: false,
};
let mut instance2 = cache.get_instance(&checksum, backend2, options).unwrap();
assert_eq!(cache.stats().hits_pinned_memory_cache, 0);
Expand Down
36 changes: 3 additions & 33 deletions packages/vm/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ pub struct GasReport {
pub struct InstanceOptions {
/// Gas limit measured in [CosmWasm gas](https://github.com/CosmWasm/cosmwasm/blob/main/docs/GAS.md).
pub gas_limit: u64,
pub print_debug: bool,
}

pub struct Instance<A: BackendApi, S: Storage, Q: Querier> {
Expand Down Expand Up @@ -74,15 +73,7 @@ where
let engine = make_compiling_engine(memory_limit);
let module = compile(&engine, code)?;
let store = Store::new(engine);
Instance::from_module(
store,
&module,
backend,
options.gas_limit,
options.print_debug,
None,
None,
)
Instance::from_module(store, &module, backend, options.gas_limit, None, None)
}

#[allow(clippy::too_many_arguments)]
Expand All @@ -91,21 +82,10 @@ where
module: &Module,
backend: Backend<A, S, Q>,
gas_limit: u64,
print_debug: bool,
extra_imports: Option<HashMap<&str, Exports>>,
instantiation_lock: Option<&Mutex<()>>,
) -> VmResult<Self> {
let fe = FunctionEnv::new(&mut store, {
let e = Environment::new(backend.api, gas_limit);
if print_debug {
e.set_debug_handler(Some(Rc::new(RefCell::new(
|msg: &str, _info: DebugInfo<'_>| {
eprintln!("{msg}");
},
))))
}
e
});
let fe = FunctionEnv::new(&mut store, Environment::new(backend.api, gas_limit));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. A caller can do this now quite easily and powerful:

instance.set_debug_handler(|_msg, info| {
let _t = now_rfc3339();
let _gas = info.gas_remaining;
//eprintln!("[{t}]: {msg} (gas remaining: {gas})");
});


let mut import_obj = Imports::new();
let mut env_imports = Exports::new();
Expand Down Expand Up @@ -480,23 +460,14 @@ pub fn instance_from_module<A, S, Q>(
module: &Module,
backend: Backend<A, S, Q>,
gas_limit: u64,
print_debug: bool,
extra_imports: Option<HashMap<&str, Exports>>,
) -> VmResult<Instance<A, S, Q>>
where
A: BackendApi + 'static, // 'static is needed here to allow copying API instances into closures
S: Storage + 'static, // 'static is needed here to allow using this in an Environment that is cloned into closures
Q: Querier + 'static,
{
Instance::from_module(
store,
module,
backend,
gas_limit,
print_debug,
extra_imports,
None,
)
Instance::from_module(store, module, backend, gas_limit, extra_imports, None)
}

#[cfg(test)]
Expand Down Expand Up @@ -655,7 +626,6 @@ mod tests {
&module,
backend,
instance_options.gas_limit,
false,
Some(extra_imports),
None,
)
Expand Down
5 changes: 0 additions & 5 deletions packages/vm/src/testing/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use super::storage::MockStorage;
/// higher than the limit for a single execution that we have in the production setup.
const DEFAULT_GAS_LIMIT: u64 = 500_000_000; // ~0.5ms
const DEFAULT_MEMORY_LIMIT: Option<Size> = Some(Size::mebi(16));
const DEFAULT_PRINT_DEBUG: bool = true;

pub fn mock_instance(
wasm: &[u8],
Expand Down Expand Up @@ -90,7 +89,6 @@ pub struct MockInstanceOptions<'a> {
pub available_capabilities: HashSet<String>,
/// Gas limit measured in [CosmWasm gas](https://github.com/CosmWasm/cosmwasm/blob/main/docs/GAS.md).
pub gas_limit: u64,
pub print_debug: bool,
/// Memory limit in bytes. Use a value that is divisible by the Wasm page size 65536, e.g. full MiBs.
pub memory_limit: Option<Size>,
}
Expand Down Expand Up @@ -118,7 +116,6 @@ impl Default for MockInstanceOptions<'_> {
// instance
available_capabilities: Self::default_capabilities(),
gas_limit: DEFAULT_GAS_LIMIT,
print_debug: DEFAULT_PRINT_DEBUG,
memory_limit: DEFAULT_MEMORY_LIMIT,
}
}
Expand Down Expand Up @@ -155,7 +152,6 @@ pub fn mock_instance_with_options(
let memory_limit = options.memory_limit;
let options = InstanceOptions {
gas_limit: options.gas_limit,
print_debug: options.print_debug,
};
Instance::from_code(wasm, backend, options, memory_limit).unwrap()
}
Expand All @@ -165,7 +161,6 @@ pub fn mock_instance_options() -> (InstanceOptions, Option<Size>) {
(
InstanceOptions {
gas_limit: DEFAULT_GAS_LIMIT,
print_debug: DEFAULT_PRINT_DEBUG,
},
DEFAULT_MEMORY_LIMIT,
)
Expand Down
Loading