Skip to content

Commit 28e98f8

Browse files
committed
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>
1 parent 1c272de commit 28e98f8

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

Cargo.lock

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/gl-sdk/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ gl-client = { version = "0.3.1", path = "../gl-client" }
1313
once_cell = "1.21.3"
1414
thiserror = "2.0.17"
1515
tokio = { version = "1", features = ["sync"] }
16+
tracing = { version = "0.1.43", features = ["async-await", "log"] }
1617
uniffi = { version = "0.29.4" }
1718

1819
[build-dependencies]

libs/gl-sdk/src/signer.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::{Credentials, Error};
22
use bip39::Mnemonic;
33
use std::str::FromStr;
4+
use tracing;
45

56
#[derive(uniffi::Object, Clone)]
67
pub struct Signer {
@@ -53,17 +54,24 @@ impl Signer {
5354

5455
fn start(&self) -> Result<Handle, Error> {
5556
let (tx, rx) = tokio::sync::mpsc::channel(1);
56-
57-
let clone = self.clone();
58-
tokio::spawn(async move {
59-
clone.run(rx).await;
57+
let inner = self.inner.clone();
58+
std::thread::spawn(move || {
59+
let runtime = tokio::runtime::Builder::new_current_thread()
60+
.enable_all()
61+
.build()
62+
.expect("building tokio runtime");
63+
runtime.block_on(async move {
64+
if let Err(e) = inner.run_forever(rx).await {
65+
tracing::error!("Error running signer in thread: {e}")
66+
}
67+
})
6068
});
6169

6270
Ok(Handle { chan: tx })
6371
}
6472

6573
fn node_id(&self) -> Vec<u8> {
66-
unimplemented!()
74+
self.inner.node_id()
6775
}
6876
}
6977

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
"""Testing client-scheduler interactions
2-
"""
1+
"""Testing client-scheduler interactions"""
32

43
import pytest
54
import glsdk
65
from gltesting.fixtures import *
76

7+
88
def test_register(scheduler, clients):
9-
signer = glsdk.Signer("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about")
10-
9+
signer = glsdk.Signer(" ".join(["abandon"] * 11 + ["about"]))
10+
signer.start()
11+
12+
# Check that the derived node_id matches the Signer seed phrase.
13+
assert (
14+
signer.node_id().hex()
15+
== "03653e90c1ce4660fd8505dd6d643356e93cfe202af109d382787639dd5890e87d"
16+
)

0 commit comments

Comments
 (0)