diff --git a/Cargo.lock b/Cargo.lock index 8a2a03dded1..670fcec5e1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1426,15 +1426,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef033ed5e9bad94e55838ca0ca906db0e043f517adda0c8b79c7a8c66c93c1b5" dependencies = [ "cfg-if", - "rustix 0.38.24", + "rustix 0.38.25", "windows-sys 0.48.0", ] [[package]] name = "fiat-crypto" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53a56f0780318174bad1c127063fd0c5fdfb35398e3cd79ffaab931a6c79df80" +checksum = "27573eac26f4dd11e2b1916c3fe1baa56407c83c71a773a8ba17ec0bca03b6b7" [[package]] name = "fixedbitset" @@ -1768,9 +1768,9 @@ checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" [[package]] name = "hdrhistogram" -version = "7.5.3" +version = "7.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5b38e5c02b7c7be48c8dc5217c4f1634af2ea221caae2e024bffc7a7651c691" +checksum = "765c9198f173dd59ce26ff9f95ef0aafd0a0fe01fb9d72841bc5066a4c06511d" dependencies = [ "byteorder", "num-traits", @@ -2032,7 +2032,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ "hermit-abi", - "rustix 0.38.24", + "rustix 0.38.25", "windows-sys 0.48.0", ] @@ -2572,7 +2572,7 @@ dependencies = [ [[package]] name = "massa-sc-runtime" version = "0.10.0" -source = "git+https://github.com/massalabs/massa-sc-runtime?rev=0be22626a5a873e6a17893e1ad8cc3a44a539308#0be22626a5a873e6a17893e1ad8cc3a44a539308" +source = "git+https://github.com/massalabs/massa-sc-runtime?rev=32eaf5e65972da79c0357ee9f1827bcaf7b02b94#32eaf5e65972da79c0357ee9f1827bcaf7b02b94" dependencies = [ "anyhow", "as-ffi-bindings", @@ -4221,9 +4221,9 @@ dependencies = [ [[package]] name = "prost" -version = "0.12.1" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4fdd22f3b9c31b53c060df4a0613a1c7f062d4115a2b984dd15b1858f7e340d" +checksum = "5a5a410fc7882af66deb8d01d01737353cf3ad6204c408177ba494291a626312" dependencies = [ "bytes", "prost-derive", @@ -4231,9 +4231,9 @@ dependencies = [ [[package]] name = "prost-build" -version = "0.12.1" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bdf592881d821b83d471f8af290226c8d51402259e9bb5be7f9f8bdebbb11ac" +checksum = "1fa3d084c8704911bfefb2771be2f9b6c5c0da7343a71e0021ee3c665cada738" dependencies = [ "bytes", "heck", @@ -4253,9 +4253,9 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.12.1" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "265baba7fabd416cf5078179f7d2cbeca4ce7a9041111900675ea7c4cb8a4c32" +checksum = "065717a5dfaca4a83d2fe57db3487b311365200000551d7a364e715dbf4346bc" dependencies = [ "anyhow", "itertools 0.11.0", @@ -4266,9 +4266,9 @@ dependencies = [ [[package]] name = "prost-types" -version = "0.12.1" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e081b29f63d83a4bc75cfc9f3fe424f9156cf92d8a4f0c9407cce9a1b67327cf" +checksum = "8339f32236f590281e2f6368276441394fcd1b2133b549cc895d0ae80f2f9a52" dependencies = [ "prost", ] @@ -4626,9 +4626,9 @@ dependencies = [ [[package]] name = "rust_decimal" -version = "1.33.0" +version = "1.33.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "076ba1058b036d3ca8bcafb1d54d0b0572e99d7ecd3e4222723e18ca8e9ca9a8" +checksum = "06676aec5ccb8fc1da723cc8c0f9a46549f21ebb8753d3915c6c41db1e7f1dc4" dependencies = [ "arrayvec", "num-traits", @@ -4680,9 +4680,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.24" +version = "0.38.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ad981d6c340a49cdc40a1028d9c6084ec7e9fa33fcb839cab656a267071e234" +checksum = "dc99bc2d4f1fed22595588a013687477aedf3cdcfb26558c559edb67b4d9b22e" dependencies = [ "bitflags 2.4.1", "errno", @@ -4693,9 +4693,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.8" +version = "0.21.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "446e14c5cda4f3f30fe71863c34ec70f5ac79d6087097ad0bb433e1be5edf04c" +checksum = "629648aced5775d558af50b2b4c7b02983a04b312126d45eeead26e7caa498b9" dependencies = [ "log", "ring 0.17.5", @@ -4874,9 +4874,9 @@ checksum = "f638d531eccd6e23b980caf34876660d38e265409d8e99b397ab71eb3612fad0" [[package]] name = "serde" -version = "1.0.192" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" dependencies = [ "serde_derive", ] @@ -4894,9 +4894,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.192" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2 1.0.69", "quote 1.0.33", @@ -5306,7 +5306,7 @@ dependencies = [ "cfg-if", "fastrand", "redox_syscall", - "rustix 0.38.24", + "rustix 0.38.25", "windows-sys 0.48.0", ] @@ -5885,9 +5885,9 @@ checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] name = "uuid" -version = "1.5.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ad59a7560b41a70d191093a945f0b87bc1deeda46fb237479708a1d6b6cdfc" +checksum = "5e395fcf16a7a3d8127ec99782007af141946b4795001f876d54fb0d55978560" [[package]] name = "valuable" @@ -6269,7 +6269,7 @@ dependencies = [ "either", "home", "once_cell", - "rustix 0.38.24", + "rustix 0.38.25", ] [[package]] @@ -6281,7 +6281,7 @@ dependencies = [ "either", "home", "once_cell", - "rustix 0.38.24", + "rustix 0.38.25", "windows-sys 0.48.0", ] @@ -6576,9 +6576,9 @@ dependencies = [ [[package]] name = "zeroize" -version = "1.6.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12a3946ecfc929b583800f4629b6c25b88ac6e92a40ea5670f77112a85d40a8b" +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" dependencies = [ "zeroize_derive", ] diff --git a/Cargo.toml b/Cargo.toml index 6e8f4095b46..7460a602eae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -101,7 +101,7 @@ massa_wallet = { path = "./massa-wallet" } # Massa projects dependencies massa-proto-rs = { git = "https://github.com/massalabs/massa-proto-rs", "rev" = "effc0418977cd64402172b7eb749a2fc7537771a" } -massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime", "rev" = "0be22626a5a873e6a17893e1ad8cc3a44a539308" } +massa-sc-runtime = { git = "https://github.com/massalabs/massa-sc-runtime", "rev" = "32eaf5e65972da79c0357ee9f1827bcaf7b02b94" } peernet = { git = "https://github.com/massalabs/PeerNet", "branch" = "main" } # Common dependencies diff --git a/massa-execution-worker/src/tests/scenarios_mandatories.rs b/massa-execution-worker/src/tests/scenarios_mandatories.rs index 81f428d07a3..b44be1893ba 100644 --- a/massa-execution-worker/src/tests/scenarios_mandatories.rs +++ b/massa-execution-worker/src/tests/scenarios_mandatories.rs @@ -1814,7 +1814,7 @@ fn not_enough_instance_gas() { .get_filtered_sc_output_event(EventFilter::default()); assert!(events[0] .data - .contains("Provided max gas is below the default instance creation cost")); + .contains("is lower than the base instance creation gas")); } #[test] diff --git a/massa-module-cache/src/controller.rs b/massa-module-cache/src/controller.rs index 16a84b4fd5e..7b26940bb52 100644 --- a/massa-module-cache/src/controller.rs +++ b/massa-module-cache/src/controller.rs @@ -2,7 +2,7 @@ use massa_hash::Hash; use massa_models::prehash::BuildHashMapper; use massa_sc_runtime::{Compiler, RuntimeModule}; use schnellru::{ByLength, LruMap}; -use tracing::{debug, info, warn}; +use tracing::debug; use crate::{ config::ModuleCacheConfig, error::CacheError, hd_cache::HDCache, lru_cache::LRUCache, @@ -47,8 +47,9 @@ impl ModuleCache { ModuleInfo::Module(module) } Err(e) => { - warn!("compilation of module {} failed with: {}", hash, e); - ModuleInfo::Invalid + let err_msg = format!("compilation of module {} failed: {}", hash, e); + debug!(err_msg); + ModuleInfo::Invalid(err_msg) } } } @@ -78,10 +79,10 @@ impl ModuleCache { } /// Set a cached module as invalid - pub fn set_invalid(&mut self, bytecode: &[u8]) { + pub fn set_invalid(&mut self, bytecode: &[u8], err_msg: String) { let hash = Hash::compute_from(bytecode); - self.lru_cache.set_invalid(hash); - self.hd_cache.set_invalid(hash); + self.lru_cache.set_invalid(hash, err_msg.clone()); + self.hd_cache.set_invalid(hash, err_msg); } /// Load a cached module for execution @@ -91,13 +92,19 @@ impl ModuleCache { /// * `ModuleInfo::Module` if the module is valid and has no delta /// * `ModuleInfo::ModuleAndDelta` if the module is valid and has a delta fn load_module_info(&mut self, bytecode: &[u8]) -> ModuleInfo { + if bytecode.is_empty() { + let error_msg = "load_module: bytecode is absent".to_string(); + debug!(error_msg); + return ModuleInfo::Invalid(error_msg); + } if bytecode.len() > self.cfg.max_module_length as usize { - info!( + let error_msg = format!( "load_module: bytecode length {} exceeds max module length {}", bytecode.len(), self.cfg.max_module_length ); - return ModuleInfo::Invalid; + debug!(error_msg); + return ModuleInfo::Invalid(error_msg); } let hash = Hash::compute_from(bytecode); if let Some(lru_module_info) = self.lru_cache.get(hash) { @@ -129,22 +136,25 @@ impl ModuleCache { // This is only supposed to be a check execution_gas .checked_sub(self.cfg.gas_costs.max_instance_cost) - .ok_or(CacheError::LoadError( - "Provided max gas is below the default instance creation cost".to_string(), - ))?; + .ok_or(CacheError::LoadError(format!( + "Provided gas {} is lower than the base instance creation gas cost {}", + execution_gas, self.cfg.gas_costs.max_instance_cost + )))?; // TODO: interesting but unimportant optim // remove max_instance_cost hard check if module is cached and has a delta let module_info = self.load_module_info(bytecode); let module = match module_info { - ModuleInfo::Invalid => { - return Err(CacheError::LoadError("Loading invalid module".to_string())); + ModuleInfo::Invalid(err) => { + let err_msg = format!("invalid module: {}", err); + return Err(CacheError::LoadError(err_msg)); } ModuleInfo::Module(module) => module, ModuleInfo::ModuleAndDelta((module, delta)) => { if delta > execution_gas { - return Err(CacheError::LoadError( - "Provided max gas is below the instance creation cost".to_string(), - )); + return Err(CacheError::LoadError(format!( + "Provided gas {} is below the gas cost of instance creation ({})", + execution_gas, delta + ))); } else { module } @@ -167,9 +177,10 @@ impl ModuleCache { // This is only supposed to be a check limit .checked_sub(self.cfg.gas_costs.max_instance_cost) - .ok_or(CacheError::LoadError( - "Provided max gas is below the default instance creation cost".to_string(), - ))?; + .ok_or(CacheError::LoadError(format!( + "Provided gas {} is lower than the base instance creation gas cost {}", + limit, self.cfg.gas_costs.max_instance_cost + )))?; let module = RuntimeModule::new(bytecode, self.cfg.gas_costs.clone(), Compiler::SP)?; Ok((module, limit)) } diff --git a/massa-module-cache/src/hd_cache.rs b/massa-module-cache/src/hd_cache.rs index 85bcf0aae36..5eb59cad25d 100644 --- a/massa-module-cache/src/hd_cache.rs +++ b/massa-module-cache/src/hd_cache.rs @@ -1,7 +1,6 @@ use crate::types::{ ModuleInfo, ModuleMetadata, ModuleMetadataDeserializer, ModuleMetadataSerializer, }; -use core::panic; use massa_hash::Hash; use massa_sc_runtime::{GasCosts, RuntimeModule}; use massa_serialization::{DeserializeError, Deserializer, Serializer}; @@ -81,9 +80,9 @@ impl HDCache { let mut ser_metadata = Vec::new(); let ser_module = match module_info { - ModuleInfo::Invalid => { + ModuleInfo::Invalid(err_msg) => { self.meta_ser - .serialize(&ModuleMetadata::Invalid, &mut ser_metadata) + .serialize(&ModuleMetadata::Invalid(err_msg), &mut ser_metadata) .expect(DATA_SER_ERROR); Vec::new() } @@ -127,10 +126,10 @@ impl HDCache { } /// Sets a given module as invalid - pub fn set_invalid(&self, hash: Hash) { + pub fn set_invalid(&self, hash: Hash, err_msg: String) { let mut ser_metadata = Vec::new(); self.meta_ser - .serialize(&ModuleMetadata::Invalid, &mut ser_metadata) + .serialize(&ModuleMetadata::Invalid(err_msg), &mut ser_metadata) .expect(DATA_SER_ERROR); self.db .put(metadata_key!(hash), ser_metadata) @@ -151,14 +150,14 @@ impl HDCache { .meta_deser .deserialize::(&ser_metadata) .expect(DATA_DESER_ERROR); - if metadata == ModuleMetadata::Invalid { - return Some(ModuleInfo::Invalid); + if let ModuleMetadata::Invalid(err_msg) = metadata { + return Some(ModuleInfo::Invalid(err_msg)); } let module = RuntimeModule::deserialize(&ser_module, gas_costs.max_instance_cost, gas_costs) .expect(MOD_DESER_ERROR); let result = match metadata { - ModuleMetadata::Invalid => ModuleInfo::Invalid, + ModuleMetadata::Invalid(err_msg) => ModuleInfo::Invalid(err_msg), ModuleMetadata::NotExecuted => ModuleInfo::Module(module), ModuleMetadata::Delta(delta) => ModuleInfo::ModuleAndDelta((module, delta)), }; @@ -261,9 +260,13 @@ mod tests { let cached_module_v2 = cache.get(hash, gas_costs.clone()).unwrap(); assert!(matches!(cached_module_v2, ModuleInfo::ModuleAndDelta(_))); - cache.set_invalid(hash); + let err_msg = "test_error".to_string(); + cache.set_invalid(hash, err_msg.clone()); let cached_module_v3 = cache.get(hash, gas_costs).unwrap(); - assert!(matches!(cached_module_v3, ModuleInfo::Invalid)); + let ModuleInfo::Invalid(res_err) = cached_module_v3 else { + panic!("expected ModuleInfo::Invalid"); + }; + assert_eq!(res_err, err_msg); } #[test] diff --git a/massa-module-cache/src/lru_cache.rs b/massa-module-cache/src/lru_cache.rs index 1c152f76390..a6ea66eeea8 100644 --- a/massa-module-cache/src/lru_cache.rs +++ b/massa-module-cache/src/lru_cache.rs @@ -1,7 +1,7 @@ use massa_hash::Hash; use massa_models::prehash::BuildHashMapper; use schnellru::{ByLength, LruMap}; -use tracing::{debug, warn}; +use tracing::debug; use crate::types::ModuleInfo; @@ -48,17 +48,20 @@ impl LRUCache { *content = ModuleInfo::ModuleAndDelta((module.clone(), init_cost)) } ModuleInfo::ModuleAndDelta((_module, delta)) => *delta = init_cost, - ModuleInfo::Invalid => { - warn!("tried to set the init cost of an invalid module"); + ModuleInfo::Invalid(err_msg) => { + debug!( + "tried to set the init cost of an invalid module. Invalidity reason: {}", + err_msg + ); } } } } /// Set a module as invalid - pub fn set_invalid(&mut self, hash: Hash) { + pub fn set_invalid(&mut self, hash: Hash, err_msg: String) { if let Some(content) = self.cache.get(&hash) { - *content = ModuleInfo::Invalid; + *content = ModuleInfo::Invalid(err_msg); } } } diff --git a/massa-module-cache/src/types.rs b/massa-module-cache/src/types.rs index 25ec6ab5bd1..18667006b2b 100644 --- a/massa-module-cache/src/types.rs +++ b/massa-module-cache/src/types.rs @@ -1,3 +1,4 @@ +use massa_models::serialization::{StringDeserializer, StringSerializer}; use massa_sc_runtime::RuntimeModule; use massa_serialization::{ Deserializer, SerializeError, Serializer, U64VarIntDeserializer, U64VarIntSerializer, @@ -12,7 +13,7 @@ use std::ops::Bound::Included; /// Main type #[derive(Clone)] pub enum ModuleInfo { - Invalid, + Invalid(String), // contains the error message Module(RuntimeModule), ModuleAndDelta((RuntimeModule, u64)), } @@ -20,7 +21,7 @@ pub enum ModuleInfo { #[derive(PartialEq, Eq)] /// Metadata type pub enum ModuleMetadata { - Invalid, + Invalid(String), // contains the error message NotExecuted, Delta(u64), } @@ -37,12 +38,14 @@ enum ModuleMetadataId { /// Metadata serializer pub struct ModuleMetadataSerializer { u64_ser: U64VarIntSerializer, + err_msg_ser: StringSerializer, } impl ModuleMetadataSerializer { pub fn new() -> Self { Self { u64_ser: U64VarIntSerializer::new(), + err_msg_ser: StringSerializer::new(U64VarIntSerializer::new()), } } } @@ -63,9 +66,11 @@ impl Serializer for ModuleMetadataSerializer { ModuleMetadata::NotExecuted => self .u64_ser .serialize(&u64::from(ModuleMetadataId::NotExecuted), buffer)?, - ModuleMetadata::Invalid => self - .u64_ser - .serialize(&u64::from(ModuleMetadataId::Invalid), buffer)?, + ModuleMetadata::Invalid(err_msg) => { + self.u64_ser + .serialize(&u64::from(ModuleMetadataId::Invalid), buffer)?; + self.err_msg_ser.serialize(err_msg, buffer)?; + } ModuleMetadata::Delta(delta) => { self.u64_ser .serialize(&u64::from(ModuleMetadataId::Delta), buffer)?; @@ -80,6 +85,7 @@ impl Serializer for ModuleMetadataSerializer { pub struct ModuleMetadataDeserializer { id_deser: U64VarIntDeserializer, delta_deser: U64VarIntDeserializer, + err_msg_deser: StringDeserializer, } impl ModuleMetadataDeserializer { @@ -90,6 +96,10 @@ impl ModuleMetadataDeserializer { Included(u64::from(ModuleMetadataId::Delta)), ), delta_deser: U64VarIntDeserializer::new(Included(0), Included(u64::MAX)), + err_msg_deser: StringDeserializer::new(U64VarIntDeserializer::new( + Included(0), + Included(u64::MAX), + )), } } } @@ -111,13 +121,17 @@ impl Deserializer for ModuleMetadataDeserializer { .map(|id| ModuleMetadataId::try_from(id).unwrap()) .parse(buffer)?; match id { - ModuleMetadataId::Invalid => Ok((input, ModuleMetadata::Invalid)), + ModuleMetadataId::Invalid => context("ModuleMetadata::Invalid", |input| { + self.err_msg_deser.deserialize(input) + }) + .map(ModuleMetadata::Invalid) + .parse(input), ModuleMetadataId::NotExecuted => Ok((input, ModuleMetadata::NotExecuted)), - ModuleMetadataId::Delta => { - context("Delta", |input| self.delta_deser.deserialize(input)) - .map(ModuleMetadata::Delta) - .parse(input) - } + ModuleMetadataId::Delta => context("ModuleMetadata::Delta", |input| { + self.delta_deser.deserialize(input) + }) + .map(ModuleMetadata::Delta) + .parse(input), } }) .parse(buffer) diff --git a/massa-versioning/src/versioning.rs b/massa-versioning/src/versioning.rs index 9ff49ddc983..370b50e6ea3 100644 --- a/massa-versioning/src/versioning.rs +++ b/massa-versioning/src/versioning.rs @@ -558,7 +558,7 @@ pub enum StateAtError { BeforeInitialState(ComponentStateTypeId, MassaTime), #[error("Empty history, should never happen")] EmptyHistory, - #[error("Cannot predict in the future (~ threshold not reach yet)")] + #[error("Cannot predict value: threshold not reached yet")] Unpredictable, }