Skip to content

Commit 4caa9f0

Browse files
authored
Merge pull request #1953 from CosmWasm/1841-remove-debug
Remove `print_debug` flag
2 parents b0ff68d + a7c58a0 commit 4caa9f0

File tree

6 files changed

+7
-50
lines changed

6 files changed

+7
-50
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,16 @@ and this project adheres to
7676
- cosmwasm-storage: Removed, use [cw-storage-plus] instead. ([#1936])
7777
- cosmwasm-std: Remove `IbcReceiveResponse`'s `Default` implementation. Use
7878
`IbcReceiveResponse::new` instead. ([#1942])
79+
- cosmwasm-vm: Remove `InstanceOptions::print_debug` flag. Set your own handler
80+
using `Instance::set_debug_handler`. ([#1953])
7981

8082
[cw-storage-plus]: https://github.com/CosmWasm/cw-storage-plus
8183
[#1875]: https://github.com/CosmWasm/cosmwasm/pull/1875
8284
[#1890]: https://github.com/CosmWasm/cosmwasm/pull/1890
8385
[#1896]: https://github.com/CosmWasm/cosmwasm/pull/1896
8486
[#1936]: https://github.com/CosmWasm/cosmwasm/pull/1936
8587
[#1942]: https://github.com/CosmWasm/cosmwasm/pull/1942
88+
[#1953]: https://github.com/CosmWasm/cosmwasm/pull/1953
8689

8790
## [1.5.0] - 2023-10-31
8891

packages/vm/benches/main.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const DEFAULT_MEMORY_LIMIT: Size = Size::mebi(64);
2020
const DEFAULT_GAS_LIMIT: u64 = 1_000_000_000; // ~1ms
2121
const DEFAULT_INSTANCE_OPTIONS: InstanceOptions = InstanceOptions {
2222
gas_limit: DEFAULT_GAS_LIMIT,
23-
print_debug: false,
2423
};
2524
const HIGH_GAS_LIMIT: u64 = 20_000_000_000_000; // ~20s, allows many calls on one instance
2625

@@ -50,7 +49,6 @@ fn bench_instance(c: &mut Criterion) {
5049
let backend = mock_backend(&[]);
5150
let much_gas: InstanceOptions = InstanceOptions {
5251
gas_limit: HIGH_GAS_LIMIT,
53-
..DEFAULT_INSTANCE_OPTIONS
5452
};
5553
let mut instance =
5654
Instance::from_code(CONTRACT, backend, much_gas, Some(DEFAULT_MEMORY_LIMIT)).unwrap();
@@ -68,7 +66,6 @@ fn bench_instance(c: &mut Criterion) {
6866
let backend = mock_backend(&[]);
6967
let much_gas: InstanceOptions = InstanceOptions {
7068
gas_limit: HIGH_GAS_LIMIT,
71-
..DEFAULT_INSTANCE_OPTIONS
7269
};
7370
let mut instance =
7471
Instance::from_code(CONTRACT, backend, much_gas, Some(DEFAULT_MEMORY_LIMIT)).unwrap();
@@ -92,7 +89,6 @@ fn bench_instance(c: &mut Criterion) {
9289
let backend = mock_backend(&[]);
9390
let much_gas: InstanceOptions = InstanceOptions {
9491
gas_limit: HIGH_GAS_LIMIT,
95-
..DEFAULT_INSTANCE_OPTIONS
9692
};
9793
let mut instance =
9894
Instance::from_code(CYBERPUNK, backend, much_gas, Some(DEFAULT_MEMORY_LIMIT)).unwrap();

packages/vm/examples/multi_threaded_cache.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const DEFAULT_MEMORY_LIMIT: Size = Size::mebi(64);
1414
const DEFAULT_GAS_LIMIT: u64 = 400_000 * 150;
1515
const DEFAULT_INSTANCE_OPTIONS: InstanceOptions = InstanceOptions {
1616
gas_limit: DEFAULT_GAS_LIMIT,
17-
print_debug: false,
1817
};
1918
// Cache
2019
const MEMORY_CACHE_SIZE: Size = Size::mebi(200);

packages/vm/src/cache.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,6 @@ where
357357
&cached.module,
358358
backend,
359359
options.gas_limit,
360-
options.print_debug,
361360
None,
362361
Some(&self.instantiation_lock),
363362
)?;
@@ -532,7 +531,6 @@ mod tests {
532531
const TESTING_MEMORY_LIMIT: Size = Size::mebi(16);
533532
const TESTING_OPTIONS: InstanceOptions = InstanceOptions {
534533
gas_limit: TESTING_GAS_LIMIT,
535-
print_debug: false,
536534
};
537535
const TESTING_MEMORY_CACHE_SIZE: Size = Size::mebi(200);
538536

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

11821180
// Init from module cache
1183-
let options = InstanceOptions {
1184-
gas_limit: 10,
1185-
print_debug: false,
1186-
};
1181+
let options = InstanceOptions { gas_limit: 10 };
11871182
let mut instance1 = cache.get_instance(&checksum, backend1, options).unwrap();
11881183
assert_eq!(cache.stats().hits_fs_cache, 1);
11891184
assert_eq!(cache.stats().misses, 0);
@@ -1202,7 +1197,6 @@ mod tests {
12021197
// Init from memory cache
12031198
let options = InstanceOptions {
12041199
gas_limit: TESTING_GAS_LIMIT,
1205-
print_debug: false,
12061200
};
12071201
let mut instance2 = cache.get_instance(&checksum, backend2, options).unwrap();
12081202
assert_eq!(cache.stats().hits_pinned_memory_cache, 0);

packages/vm/src/instance.rs

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ pub struct GasReport {
4343
pub struct InstanceOptions {
4444
/// Gas limit measured in [CosmWasm gas](https://github.com/CosmWasm/cosmwasm/blob/main/docs/GAS.md).
4545
pub gas_limit: u64,
46-
pub print_debug: bool,
4746
}
4847

4948
pub struct Instance<A: BackendApi, S: Storage, Q: Querier> {
@@ -74,15 +73,7 @@ where
7473
let engine = make_compiling_engine(memory_limit);
7574
let module = compile(&engine, code)?;
7675
let store = Store::new(engine);
77-
Instance::from_module(
78-
store,
79-
&module,
80-
backend,
81-
options.gas_limit,
82-
options.print_debug,
83-
None,
84-
None,
85-
)
76+
Instance::from_module(store, &module, backend, options.gas_limit, None, None)
8677
}
8778

8879
#[allow(clippy::too_many_arguments)]
@@ -91,21 +82,10 @@ where
9182
module: &Module,
9283
backend: Backend<A, S, Q>,
9384
gas_limit: u64,
94-
print_debug: bool,
9585
extra_imports: Option<HashMap<&str, Exports>>,
9686
instantiation_lock: Option<&Mutex<()>>,
9787
) -> VmResult<Self> {
98-
let fe = FunctionEnv::new(&mut store, {
99-
let e = Environment::new(backend.api, gas_limit);
100-
if print_debug {
101-
e.set_debug_handler(Some(Rc::new(RefCell::new(
102-
|msg: &str, _info: DebugInfo<'_>| {
103-
eprintln!("{msg}");
104-
},
105-
))))
106-
}
107-
e
108-
});
88+
let fe = FunctionEnv::new(&mut store, Environment::new(backend.api, gas_limit));
10989

11090
let mut import_obj = Imports::new();
11191
let mut env_imports = Exports::new();
@@ -480,23 +460,14 @@ pub fn instance_from_module<A, S, Q>(
480460
module: &Module,
481461
backend: Backend<A, S, Q>,
482462
gas_limit: u64,
483-
print_debug: bool,
484463
extra_imports: Option<HashMap<&str, Exports>>,
485464
) -> VmResult<Instance<A, S, Q>>
486465
where
487466
A: BackendApi + 'static, // 'static is needed here to allow copying API instances into closures
488467
S: Storage + 'static, // 'static is needed here to allow using this in an Environment that is cloned into closures
489468
Q: Querier + 'static,
490469
{
491-
Instance::from_module(
492-
store,
493-
module,
494-
backend,
495-
gas_limit,
496-
print_debug,
497-
extra_imports,
498-
None,
499-
)
470+
Instance::from_module(store, module, backend, gas_limit, extra_imports, None)
500471
}
501472

502473
#[cfg(test)]
@@ -655,7 +626,6 @@ mod tests {
655626
&module,
656627
backend,
657628
instance_options.gas_limit,
658-
false,
659629
Some(extra_imports),
660630
None,
661631
)

packages/vm/src/testing/instance.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use super::storage::MockStorage;
1919
/// higher than the limit for a single execution that we have in the production setup.
2020
const DEFAULT_GAS_LIMIT: u64 = 500_000_000; // ~0.5ms
2121
const DEFAULT_MEMORY_LIMIT: Option<Size> = Some(Size::mebi(16));
22-
const DEFAULT_PRINT_DEBUG: bool = true;
2322

2423
pub fn mock_instance(
2524
wasm: &[u8],
@@ -90,7 +89,6 @@ pub struct MockInstanceOptions<'a> {
9089
pub available_capabilities: HashSet<String>,
9190
/// Gas limit measured in [CosmWasm gas](https://github.com/CosmWasm/cosmwasm/blob/main/docs/GAS.md).
9291
pub gas_limit: u64,
93-
pub print_debug: bool,
9492
/// Memory limit in bytes. Use a value that is divisible by the Wasm page size 65536, e.g. full MiBs.
9593
pub memory_limit: Option<Size>,
9694
}
@@ -118,7 +116,6 @@ impl Default for MockInstanceOptions<'_> {
118116
// instance
119117
available_capabilities: Self::default_capabilities(),
120118
gas_limit: DEFAULT_GAS_LIMIT,
121-
print_debug: DEFAULT_PRINT_DEBUG,
122119
memory_limit: DEFAULT_MEMORY_LIMIT,
123120
}
124121
}
@@ -155,7 +152,6 @@ pub fn mock_instance_with_options(
155152
let memory_limit = options.memory_limit;
156153
let options = InstanceOptions {
157154
gas_limit: options.gas_limit,
158-
print_debug: options.print_debug,
159155
};
160156
Instance::from_code(wasm, backend, options, memory_limit).unwrap()
161157
}
@@ -165,7 +161,6 @@ pub fn mock_instance_options() -> (InstanceOptions, Option<Size>) {
165161
(
166162
InstanceOptions {
167163
gas_limit: DEFAULT_GAS_LIMIT,
168-
print_debug: DEFAULT_PRINT_DEBUG,
169164
},
170165
DEFAULT_MEMORY_LIMIT,
171166
)

0 commit comments

Comments
 (0)