From fa54a4010a7c769a37706db4fed09806376c3fd2 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Wed, 17 Dec 2025 16:53:37 +0100 Subject: [PATCH] sdk: Fix two issues with the signer `Signer.start()` was not creating the runtime, and spawning the thread, rather it was assuming it already had a runtime. Since the signer is isolated, we can just have it spawn its own thread and runtime. The API will use a shared runtime it can block on, but the signer needs to run independently in the background. The second issue was that the `Signer.node_id()` method was still stubbed out. Now it delegates to the gl-client Signer. Reported-By: <@lvaccaro> --- Cargo.lock | 13 +++++++------ libs/gl-sdk/Cargo.toml | 1 + libs/gl-sdk/src/signer.rs | 18 +++++++++++++----- libs/gl-sdk/tests/test_scheduler.py | 14 ++++++++++---- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2a214c52..9db8a0a6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1519,6 +1519,7 @@ dependencies = [ "once_cell", "thiserror 2.0.17", "tokio", + "tracing", "uniffi", ] @@ -4307,9 +4308,9 @@ checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" [[package]] name = "tracing" -version = "0.1.41" +version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" +checksum = "2d15d90a0b5c19378952d479dc858407149d7bb45a14de0142f6c534b16fc647" dependencies = [ "log", "pin-project-lite", @@ -4319,9 +4320,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.30" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" dependencies = [ "proc-macro2", "quote", @@ -4330,9 +4331,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.34" +version = "0.1.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9d12581f227e93f094d3af2ae690a574abb8a2b9b7a96e7cfe9647b2b617678" +checksum = "7a04e24fab5c89c6a36eb8558c9656f30d81de51dfa4d3b45f26b21d61fa0a6c" dependencies = [ "once_cell", "valuable", diff --git a/libs/gl-sdk/Cargo.toml b/libs/gl-sdk/Cargo.toml index ccd1f600..3f7c636b 100644 --- a/libs/gl-sdk/Cargo.toml +++ b/libs/gl-sdk/Cargo.toml @@ -13,6 +13,7 @@ gl-client = { version = "0.3.1", path = "../gl-client" } once_cell = "1.21.3" thiserror = "2.0.17" tokio = { version = "1", features = ["sync"] } +tracing = { version = "0.1.43", features = ["async-await", "log"] } uniffi = { version = "0.29.4" } [build-dependencies] diff --git a/libs/gl-sdk/src/signer.rs b/libs/gl-sdk/src/signer.rs index 8b683e45..b9da527f 100644 --- a/libs/gl-sdk/src/signer.rs +++ b/libs/gl-sdk/src/signer.rs @@ -1,6 +1,7 @@ use crate::{Credentials, Error}; use bip39::Mnemonic; use std::str::FromStr; +use tracing; #[derive(uniffi::Object, Clone)] pub struct Signer { @@ -53,17 +54,24 @@ impl Signer { fn start(&self) -> Result { let (tx, rx) = tokio::sync::mpsc::channel(1); - - let clone = self.clone(); - tokio::spawn(async move { - clone.run(rx).await; + let inner = self.inner.clone(); + std::thread::spawn(move || { + let runtime = tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .expect("building tokio runtime"); + runtime.block_on(async move { + if let Err(e) = inner.run_forever(rx).await { + tracing::error!("Error running signer in thread: {e}") + } + }) }); Ok(Handle { chan: tx }) } fn node_id(&self) -> Vec { - unimplemented!() + self.inner.node_id() } } diff --git a/libs/gl-sdk/tests/test_scheduler.py b/libs/gl-sdk/tests/test_scheduler.py index 74be9073..ad409528 100644 --- a/libs/gl-sdk/tests/test_scheduler.py +++ b/libs/gl-sdk/tests/test_scheduler.py @@ -1,10 +1,16 @@ -"""Testing client-scheduler interactions -""" +"""Testing client-scheduler interactions""" import pytest import glsdk from gltesting.fixtures import * + def test_register(scheduler, clients): - signer = glsdk.Signer("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about") - + signer = glsdk.Signer(" ".join(["abandon"] * 11 + ["about"])) + signer.start() + + # Check that the derived node_id matches the Signer seed phrase. + assert ( + signer.node_id().hex() + == "03653e90c1ce4660fd8505dd6d643356e93cfe202af109d382787639dd5890e87d" + )