Repository: tangle-network/gadget (language: rust)

Issue:
[BUG] Operator profile not found while trying to self-register from my gadget
### Overview
While running my gadget using frost-blueprint I've noticed it always returns `"Operator profile not found"` error. This error is clearly meaning my operator does not have a profile, and this correct, I will need to register on the blueprint. However, I'm telling the gadget to do that for me by setting `requires_registration` on my blueprint config, this is also done behind the scene in the `BlueprintRunner`. 

Anyway, the issue is that we return this error early here:

https://github.com/tangle-network/gadget/blob/28c3cbcc9ba6e10e75503119a0df8945bf4e8ed3/sdk/src/runners/tangle.rs#L68-L75

But instead, if no profile is not found, we should assume this our first blueprint, so we should try to register right away.


Discussion / hints:

Fix patch:
diff --git a/Cargo.toml b/Cargo.toml
index 47c17172c..9b37b4d66 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -96,6 +96,7 @@ cargo-generate = { version = "0.21.3", default-features = false }
 cfg-if = "1.0.0"
 clap = "4.5.16"
 clap-cargo = "0.14"
+eyre = { version = "0.6.12" }
 color-eyre = { version = "0.6", features = ["tracing-error", "color-spantrace"] }
 ed25519-zebra = { version = "4" }
 elliptic-curve = { version = "0.13.8" }
diff --git a/blueprints/incredible-squaring-eigenlayer/contracts/lib/forge-std b/blueprints/incredible-squaring-eigenlayer/contracts/lib/forge-std
index 1eea5bae1..1de6eecf8 160000
--- a/blueprints/incredible-squaring-eigenlayer/contracts/lib/forge-std
+++ b/blueprints/incredible-squaring-eigenlayer/contracts/lib/forge-std
@@ -1,1 +1,1 @@
-Subproject commit 1eea5bae12ae557d589f9f0f0edae2faa47cb262
+Subproject commit 1de6eecf821de7fe2c908cc48d3ab3dced20717f
diff --git a/blueprints/incredible-squaring/contracts/lib/forge-std b/blueprints/incredible-squaring/contracts/lib/forge-std
index 1eea5bae1..1de6eecf8 160000
--- a/blueprints/incredible-squaring/contracts/lib/forge-std
+++ b/blueprints/incredible-squaring/contracts/lib/forge-std
@@ -1,1 +1,1 @@
-Subproject commit 1eea5bae12ae557d589f9f0f0edae2faa47cb262
+Subproject commit 1de6eecf821de7fe2c908cc48d3ab3dced20717f
diff --git a/macros/blueprint-proc-macro/src/sdk_main.rs b/macros/blueprint-proc-macro/src/sdk_main.rs
index 1a86a9246..5a573c7de 100644
--- a/macros/blueprint-proc-macro/src/sdk_main.rs
+++ b/macros/blueprint-proc-macro/src/sdk_main.rs
@@ -64,11 +64,15 @@ pub(crate) fn sdk_main_impl(args: &SdkMainArgs, input: &ItemFn) -> syn::Result<T
 
     // Next, we need to consider the input. It should be in the form "async fn main() { ... }"
     // We must remove all the async fn main() and keep everything else
+    let main_ret = match &input.sig.output {
+        syn::ReturnType::Default => quote! { Result<(), Box<dyn std::error::Error>> },
+        syn::ReturnType::Type(_, ty) => quote! { #ty },
+    };
+    let input_attrs = input.attrs.iter();
     let input = input.block.clone();
 
     let tokens = quote! {
-        use gadget_sdk::tokio;
-        #[tokio::main #tokio_args]
+        #[gadget_sdk::tokio::main #tokio_args]
         async fn main() -> Result<(), Box<dyn std::error::Error>> {
             #logger
             #standard_setup
@@ -76,7 +80,8 @@ pub(crate) fn sdk_main_impl(args: &SdkMainArgs, input: &ItemFn) -> syn::Result<T
             Ok(())
         }
 
-        async fn inner_main(#env_function_signature) -> Result<(), Box<dyn std::error::Error>> {
+        #(#input_attrs)*
+        async fn inner_main(#env_function_signature) -> #main_ret {
             #input
         }
     };
diff --git a/sdk/src/runners/mod.rs b/sdk/src/runners/mod.rs
index 245f1c20c..b88da5996 100644
--- a/sdk/src/runners/mod.rs
+++ b/sdk/src/runners/mod.rs
@@ -19,6 +19,9 @@ pub enum RunnerError {
     #[error("Job already initialized")]
     AlreadyInitialized,
 
+    #[error("You are currently not an active operator\nPlease checkout the docs here: https://docs.tangle.tools/restake/join_operator/join")]
+    NotActiveOperator,
+
     #[error(transparent)]
     Recv(#[from] tokio::sync::oneshot::error::RecvError),
 
diff --git a/sdk/src/runners/tangle.rs b/sdk/src/runners/tangle.rs
index 077a9ce27..d6fdda6ef 100644
--- a/sdk/src/runners/tangle.rs
+++ b/sdk/src/runners/tangle.rs
@@ -71,13 +71,10 @@ impl BlueprintConfig for TangleConfig {
             .at_latest()
             .await?
             .fetch(&operator_profile_query)
-            .await?
-            .ok_or_else(|| RunnerError::StorageError("Operator profile not found".into()))?;
+            .await?;
         let is_registered = operator_profile
-            .blueprints
-            .0
-            .iter()
-            .any(|&id| id == blueprint_id);
+            .map(|p| p.blueprints.0.iter().any(|&id| id == blueprint_id))
+            .unwrap_or(false);
 
         Ok(!is_registered)
     }
@@ -96,6 +93,22 @@ impl BlueprintConfig for TangleConfig {
                 "Expected Tangle protocol".into(),
             ));
         };
+
+        let account_id = signer.account_id();
+        // Check if the operator is active operator.
+        let operator_active_query = api::storage()
+            .multi_asset_delegation()
+            .operators(account_id);
+        let operator_active = client
+            .storage()
+            .at_latest()
+            .await?
+            .fetch(&operator_active_query)
+            .await?;
+        if operator_active.is_none() {
+            return Err(RunnerError::NotActiveOperator);
+        }
+
         let blueprint_id = blueprint_settings.blueprint_id;
 
         let xt = api::tx().services().register(


Test patch: