From a2833fbf3e2c98d2b677aae0a74c55df7834d887 Mon Sep 17 00:00:00 2001 From: Anton Yemelyanov Date: Mon, 16 Sep 2024 10:36:55 +0300 Subject: [PATCH] CAPS version update --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/connection.rs | 16 ++++++++++++++++ src/rpc/mod.rs | 13 +++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f54e888..f4200da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2268,7 +2268,7 @@ dependencies = [ [[package]] name = "kaspa-resolver" -version = "0.10.2" +version = "0.10.3" dependencies = [ "ahash", "arc-swap", diff --git a/Cargo.toml b/Cargo.toml index 57d369e..f5c9ff2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "kaspa-resolver" description = "Kaspa RPC endpoint resolver" -version = "0.10.2" +version = "0.10.3" edition = "2021" # authors.workspace = true # include.workspace = true diff --git a/src/connection.rs b/src/connection.rs index 6856ba5..72a49c2 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -317,6 +317,12 @@ impl Connection { // TODO: disabling for now - this may cause cyclic references // self.caps.store(None); // update state + + if self.caps().is_some() { + // trigger version update + let _ = self.update_caps().await; + } + if self.update_state().await.is_ok() { self.is_online.store(true, Ordering::Relaxed); self.update(); @@ -371,6 +377,16 @@ impl Connection { Ok(()) } + async fn update_caps(self: &Arc) -> Result<()> { + if let Some(prev_caps) = self.caps().as_ref() { + let new_caps = self.client.get_caps().await?; + let caps = Caps::with_version(prev_caps, new_caps.version); + self.caps.store(Some(Arc::new(caps))); + } + + Ok(()) + } + async fn update_state(self: &Arc) -> Result<()> { if !self.is_delegate() { if let Err(err) = self.client.ping().await { diff --git a/src/rpc/mod.rs b/src/rpc/mod.rs index 979f144..e5afe41 100644 --- a/src/rpc/mod.rs +++ b/src/rpc/mod.rs @@ -30,6 +30,19 @@ impl Caps { pub fn system_id(&self) -> u64 { self.system_id } + + pub fn with_version(&self, version: String) -> Self { + Self { + version, + system_id: self.system_id, + git_hash: self.git_hash.clone(), + total_memory: self.total_memory, + cpu_physical_cores: self.cpu_physical_cores, + fd_limit: self.fd_limit, + clients_limit: self.clients_limit, + capacity: self.capacity, + } + } } #[derive(Debug)]