diff --git a/Cargo.lock b/Cargo.lock index bfad3e35e..c229bd7b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8681,6 +8681,7 @@ dependencies = [ "sov-zk-cycle-macros", "tempfile", "thiserror", + "tracing", ] [[package]] diff --git a/examples/demo-rollup/provers/risc0/guest-celestia/Cargo.lock b/examples/demo-rollup/provers/risc0/guest-celestia/Cargo.lock index 07b25135e..bf18f4f17 100644 --- a/examples/demo-rollup/provers/risc0/guest-celestia/Cargo.lock +++ b/examples/demo-rollup/provers/risc0/guest-celestia/Cargo.lock @@ -2085,6 +2085,7 @@ dependencies = [ "sov-rollup-interface", "sov-state", "thiserror", + "tracing", ] [[package]] diff --git a/examples/demo-rollup/provers/risc0/guest-mock/Cargo.lock b/examples/demo-rollup/provers/risc0/guest-mock/Cargo.lock index c18d9b680..c561eba22 100644 --- a/examples/demo-rollup/provers/risc0/guest-mock/Cargo.lock +++ b/examples/demo-rollup/provers/risc0/guest-mock/Cargo.lock @@ -1068,6 +1068,7 @@ dependencies = [ "sov-rollup-interface", "sov-state", "thiserror", + "tracing", ] [[package]] diff --git a/module-system/sov-modules-api/Cargo.toml b/module-system/sov-modules-api/Cargo.toml index 80a6644a4..3a98da367 100644 --- a/module-system/sov-modules-api/Cargo.toml +++ b/module-system/sov-modules-api/Cargo.toml @@ -32,6 +32,7 @@ serde_json = { workspace = true, optional = true } hex = { workspace = true } clap = { workspace = true, optional = true } schemars = { workspace = true, optional = true, features = [] } +tracing = { workspace = true } ed25519-dalek = { version = "2.0.0", default-features = false, features = ["serde"] } rand = { version = "0.8", optional = true } diff --git a/module-system/sov-modules-api/src/lib.rs b/module-system/sov-modules-api/src/lib.rs index 2d7870788..57d3952ce 100644 --- a/module-system/sov-modules-api/src/lib.rs +++ b/module-system/sov-modules-api/src/lib.rs @@ -342,7 +342,8 @@ pub trait Module { impl Event for () { fn event_key(&self) -> &'static str { - unimplemented!("Event type for this module does not exist.") + tracing::warn!("Trying to get the event_key string for an undefined event."); + "NA-Event-Not-Defined" } } diff --git a/module-system/sov-modules-macros/src/runtime_event.rs b/module-system/sov-modules-macros/src/runtime_event.rs index e2bb4ba60..81d6fc418 100644 --- a/module-system/sov-modules-macros/src/runtime_event.rs +++ b/module-system/sov-modules-macros/src/runtime_event.rs @@ -19,8 +19,10 @@ impl<'a> StructDef<'a> { let name = &field.ident; let ty = &field.ty; + let doc: String = format!("An event emitted by the {} module", name.to_string()); + quote::quote!( - #[doc = "Module event."] + #[doc = #doc] #name(<#ty as ::sov_modules_api::Module>::Event), ) }) @@ -38,10 +40,7 @@ impl<'a> StructDef<'a> { let module_name_str = &field.ident.to_string(); quote::quote!( #enum_ident::#module_name(inner)=>{ - let enum_name: String = format!("{:?}", inner) - .split('(') - .collect::>()[0].to_string(); - format!("{}-{}", #module_name_str, enum_name) + format!("{}-{}", #module_name_str, inner.event_key()) }, ) }) @@ -57,6 +56,8 @@ impl<'a> StructDef<'a> { /// Returns a string that identifies both the module and the event type pub fn get_key_string(&self) -> String { + use ::sov_modules_api::Event as _; + match self { #(#match_legs)* } diff --git a/module-system/sov-modules-macros/tests/dispatch/derive_runtime_event.rs b/module-system/sov-modules-macros/tests/dispatch/derive_runtime_event.rs index aecda35c0..f6fee7104 100644 --- a/module-system/sov-modules-macros/tests/dispatch/derive_runtime_event.rs +++ b/module-system/sov-modules-macros/tests/dispatch/derive_runtime_event.rs @@ -1,5 +1,7 @@ mod modules; -use modules::{first_test_module, second_test_module, third_test_module, fourth_test_module, fourth_test_module::MyStruct, fourth_test_module::MyNewStruct, fourth_test_module::NestedEnum}; +use modules::{first_test_module, second_test_module, + third_test_module, + fourth_test_module, fourth_test_module::MyStruct, fourth_test_module::MyNewStruct, fourth_test_module::NestedEnum}; use sov_modules_api::default_context::DefaultContext; use sov_modules_api::macros::DefaultRuntime; use sov_modules_api::{ @@ -17,15 +19,24 @@ struct Runtime } fn main() { - // Check to see if the runtime events are getting initialized correctly - let _event = RuntimeEvent::::first(first_test_module::MyEvent::Variant1(10)); - let _event = RuntimeEvent::::first(first_test_module::MyEvent::Variant2); - let _event = RuntimeEvent::::first(first_test_module::MyEvent::Variant3(vec![1; 3])); - let _event = RuntimeEvent::::second(second_test_module::MyEvent::Variant); - let _event = RuntimeEvent::::third(()); - let _event = RuntimeEvent::::fourth(fourth_test_module::MyEvent::Variant1); - let _event = RuntimeEvent::::fourth(fourth_test_module::MyEvent::Variant2WithStruct(MyStruct { a: 10, b: "abc".to_string()})); - let _event = RuntimeEvent::::fourth(fourth_test_module::MyEvent::Variant3WithNewTypeStruct(MyNewStruct(10))); - let _event = RuntimeEvent::::fourth(fourth_test_module::MyEvent::Variant4WithUnnamedStruct { a: 10, b: "abc".to_string()}); - let _event = RuntimeEvent::::fourth(fourth_test_module::MyEvent::Variant5WithNestedEnum(NestedEnum::Variant1)); + let event = RuntimeEvent::::first(first_test_module::MyEvent::Variant1(10)); + assert_eq!(event.get_key_string(), "first-Variant1"); + let event = RuntimeEvent::::first(first_test_module::MyEvent::Variant2); + assert_eq!(event.get_key_string(), "first-Variant2"); + let event = RuntimeEvent::::first(first_test_module::MyEvent::Variant3(vec![1; 3])); + assert_eq!(event.get_key_string(), "first-Variant3"); + let event = RuntimeEvent::::second(second_test_module::MyEvent::Variant); + assert_eq!(event.get_key_string(), "second-Variant"); + let event = RuntimeEvent::::third(()); + assert_eq!(event.get_key_string(), "third-NA-Event-Not-Defined"); + let event = RuntimeEvent::::fourth(fourth_test_module::MyEvent::Variant1); + assert_eq!(event.get_key_string(), "fourth-Variant1"); + let event = RuntimeEvent::::fourth(fourth_test_module::MyEvent::Variant2WithStruct(MyStruct { a: 10, b: "abc".to_string()})); + assert_eq!(event.get_key_string(), "fourth-Variant2WithStruct"); + let event = RuntimeEvent::::fourth(fourth_test_module::MyEvent::Variant3WithNewTypeStruct(MyNewStruct(10))); + assert_eq!(event.get_key_string(), "fourth-Variant3WithNewTypeStruct"); + let event = RuntimeEvent::::fourth(fourth_test_module::MyEvent::Variant4WithUnnamedStruct { a: 10, b: "abc".to_string()}); + assert_eq!(event.get_key_string(), "fourth-Variant4WithUnnamedStruct"); + let event = RuntimeEvent::::fourth(fourth_test_module::MyEvent::Variant5WithNestedEnum(NestedEnum::Variant1)); + assert_eq!(event.get_key_string(), "fourth-Variant5WithNestedEnum"); }