From e3760760796762a184dbca01163481947ec4edd2 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Fri, 11 Oct 2024 21:09:18 +0700 Subject: [PATCH] Add unit to config field names (cherry picked from commit 3fe701530d06d16abb6399a5195d096df1115554) --- packages/check/tests/cosmwasm_check_tests.rs | 2 +- packages/vm/benches/main.rs | 2 +- packages/vm/src/cache.rs | 36 ++++++++++---------- packages/vm/src/compatibility.rs | 6 ++-- packages/vm/src/config.rs | 26 +++++++------- 5 files changed, 37 insertions(+), 35 deletions(-) diff --git a/packages/check/tests/cosmwasm_check_tests.rs b/packages/check/tests/cosmwasm_check_tests.rs index d7e93f0263..e3f00cb645 100644 --- a/packages/check/tests/cosmwasm_check_tests.rs +++ b/packages/check/tests/cosmwasm_check_tests.rs @@ -103,7 +103,7 @@ fn wasm_limits_string_check() -> Result<(), Box> { let mut cmd = Command::cargo_bin("cosmwasm-check")?; let mut limits = WasmLimits::default(); - limits.initial_memory_limit = Some(10); + limits.initial_memory_limit_pages = Some(10); cmd.arg("--wasm-limits") .arg(to_json_string(&limits).unwrap()) diff --git a/packages/vm/benches/main.rs b/packages/vm/benches/main.rs index 872a5b4607..81705d88f8 100644 --- a/packages/vm/benches/main.rs +++ b/packages/vm/benches/main.rs @@ -386,7 +386,7 @@ fn bench_combined(c: &mut Criterion) { group.bench_function("get instance from fs cache and execute", |b| { let mut non_memcache = options.clone(); - non_memcache.memory_cache_size = Size::kibi(0); + non_memcache.memory_cache_size_bytes = Size::kibi(0); let cache: Cache = unsafe { Cache::new(non_memcache).unwrap() }; diff --git a/packages/vm/src/cache.rs b/packages/vm/src/cache.rs index e6fb0e3ec3..6d8d625a26 100644 --- a/packages/vm/src/cache.rs +++ b/packages/vm/src/cache.rs @@ -142,8 +142,8 @@ where CacheOptions { base_dir, available_capabilities, - memory_cache_size, - instance_memory_limit, + memory_cache_size_bytes, + instance_memory_limit_bytes, }, wasm_limits, } = config; @@ -165,11 +165,11 @@ where inner: Mutex::new(CacheInner { wasm_path, pinned_memory_cache: PinnedMemoryCache::new(), - memory_cache: InMemoryCache::new(memory_cache_size), + memory_cache: InMemoryCache::new(memory_cache_size_bytes), fs_cache, stats: Stats::default(), }), - instance_memory_limit, + instance_memory_limit: instance_memory_limit_bytes, type_storage: PhantomData::, type_api: PhantomData::, type_querier: PhantomData::, @@ -614,8 +614,8 @@ mod tests { CacheOptions { base_dir: TempDir::new().unwrap().into_path(), available_capabilities: default_capabilities(), - memory_cache_size: TESTING_MEMORY_CACHE_SIZE, - instance_memory_limit: TESTING_MEMORY_LIMIT, + memory_cache_size_bytes: TESTING_MEMORY_CACHE_SIZE, + instance_memory_limit_bytes: TESTING_MEMORY_LIMIT, } } @@ -625,8 +625,8 @@ mod tests { CacheOptions { base_dir: TempDir::new().unwrap().into_path(), available_capabilities: capabilities, - memory_cache_size: TESTING_MEMORY_CACHE_SIZE, - instance_memory_limit: TESTING_MEMORY_LIMIT, + memory_cache_size_bytes: TESTING_MEMORY_CACHE_SIZE, + instance_memory_limit_bytes: TESTING_MEMORY_LIMIT, } } @@ -755,8 +755,8 @@ mod tests { let options1 = CacheOptions { base_dir: tmp_dir.path().to_path_buf(), available_capabilities: default_capabilities(), - memory_cache_size: TESTING_MEMORY_CACHE_SIZE, - instance_memory_limit: TESTING_MEMORY_LIMIT, + memory_cache_size_bytes: TESTING_MEMORY_CACHE_SIZE, + instance_memory_limit_bytes: TESTING_MEMORY_LIMIT, }; let cache1: Cache = unsafe { Cache::new(options1).unwrap() }; @@ -767,8 +767,8 @@ mod tests { let options2 = CacheOptions { base_dir: tmp_dir.path().to_path_buf(), available_capabilities: default_capabilities(), - memory_cache_size: TESTING_MEMORY_CACHE_SIZE, - instance_memory_limit: TESTING_MEMORY_LIMIT, + memory_cache_size_bytes: TESTING_MEMORY_CACHE_SIZE, + instance_memory_limit_bytes: TESTING_MEMORY_LIMIT, }; let cache2: Cache = unsafe { Cache::new(options2).unwrap() }; @@ -800,8 +800,8 @@ mod tests { let options = CacheOptions { base_dir: tmp_dir.path().to_path_buf(), available_capabilities: default_capabilities(), - memory_cache_size: TESTING_MEMORY_CACHE_SIZE, - instance_memory_limit: TESTING_MEMORY_LIMIT, + memory_cache_size_bytes: TESTING_MEMORY_CACHE_SIZE, + instance_memory_limit_bytes: TESTING_MEMORY_LIMIT, }; let cache: Cache = unsafe { Cache::new(options).unwrap() }; @@ -1606,8 +1606,8 @@ mod tests { let options = CacheOptions { base_dir: tmp_dir.path().to_path_buf(), available_capabilities: default_capabilities(), - memory_cache_size: TESTING_MEMORY_CACHE_SIZE, - instance_memory_limit: TESTING_MEMORY_LIMIT, + memory_cache_size_bytes: TESTING_MEMORY_CACHE_SIZE, + instance_memory_limit_bytes: TESTING_MEMORY_LIMIT, }; let cache: Cache = unsafe { Cache::new(options).unwrap() }; @@ -1639,8 +1639,8 @@ mod tests { cache: CacheOptions { base_dir: tmp_dir.path().to_path_buf(), available_capabilities: default_capabilities(), - memory_cache_size: TESTING_MEMORY_CACHE_SIZE, - instance_memory_limit: TESTING_MEMORY_LIMIT, + memory_cache_size_bytes: TESTING_MEMORY_CACHE_SIZE, + instance_memory_limit_bytes: TESTING_MEMORY_LIMIT, }, }; diff --git a/packages/vm/src/compatibility.rs b/packages/vm/src/compatibility.rs index 6b0fd1b777..c77e09e58e 100644 --- a/packages/vm/src/compatibility.rs +++ b/packages/vm/src/compatibility.rs @@ -122,7 +122,7 @@ fn check_wasm_tables(module: &ParsedWasm, wasm_limits: &WasmLimits) -> VmResult< 1 => { let limits = &module.tables[0]; if let Some(maximum) = limits.maximum { - if maximum > wasm_limits.table_size_limit() { + if maximum > wasm_limits.table_size_limit_elements() { return Err(VmError::static_validation_err( "Wasm contract's first table section has a too large max limit", )); @@ -148,10 +148,10 @@ fn check_wasm_memories(module: &ParsedWasm, limits: &WasmLimits) -> VmResult<()> } let memory = &module.memories[0]; - if memory.initial > limits.initial_memory_limit() as u64 { + if memory.initial > limits.initial_memory_limit_pages() as u64 { return Err(VmError::static_validation_err(format!( "Wasm contract memory's minimum must not exceed {} pages.", - limits.initial_memory_limit() + limits.initial_memory_limit_pages() ))); } diff --git a/packages/vm/src/config.rs b/packages/vm/src/config.rs index e009b92692..088dab2343 100644 --- a/packages/vm/src/config.rs +++ b/packages/vm/src/config.rs @@ -52,7 +52,7 @@ pub struct WasmLimits { /// /// Every Wasm memory has an initial size and an optional maximum size, /// both measured in Wasm pages. This limit applies to the initial size. - pub initial_memory_limit: Option, + pub initial_memory_limit_pages: Option, /// The upper limit for the `max` value of each table. CosmWasm contracts have /// initial=max for 1 table. See /// @@ -64,7 +64,7 @@ pub struct WasmLimits { /// - table[0] type=funcref initial=161 max=161 /// ``` /// - pub table_size_limit: Option, + pub table_size_limit_elements: Option, /// If the contract has more than this amount of imports, it will be rejected /// during static validation before even looking into the imports. pub max_imports: Option, @@ -88,12 +88,14 @@ pub struct WasmLimits { } impl WasmLimits { - pub fn initial_memory_limit(&self) -> u32 { - self.initial_memory_limit.unwrap_or(DEFAULT_MEMORY_LIMIT) + pub fn initial_memory_limit_pages(&self) -> u32 { + self.initial_memory_limit_pages + .unwrap_or(DEFAULT_MEMORY_LIMIT) } - pub fn table_size_limit(&self) -> u32 { - self.table_size_limit.unwrap_or(DEFAULT_TABLE_SIZE_LIMIT) + pub fn table_size_limit_elements(&self) -> u32 { + self.table_size_limit_elements + .unwrap_or(DEFAULT_TABLE_SIZE_LIMIT) } pub fn max_imports(&self) -> usize { @@ -130,24 +132,24 @@ pub struct CacheOptions { pub base_dir: PathBuf, pub available_capabilities: HashSet, /// Memory limit for the cache, in bytes. - pub memory_cache_size: Size, + pub memory_cache_size_bytes: Size, /// Memory limit for instances, in bytes. Use a value that is divisible by the Wasm page size 65536, /// e.g. full MiBs. - pub instance_memory_limit: Size, + pub instance_memory_limit_bytes: Size, } impl CacheOptions { pub fn new( base_dir: impl Into, available_capabilities: impl Into>, - memory_cache_size: Size, - instance_memory_limit: Size, + memory_cache_size_bytes: Size, + instance_memory_limit_bytes: Size, ) -> Self { Self { base_dir: base_dir.into(), available_capabilities: available_capabilities.into(), - memory_cache_size, - instance_memory_limit, + memory_cache_size_bytes, + instance_memory_limit_bytes, } } }