Skip to content

Commit

Permalink
CAPS version update
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Sep 16, 2024
1 parent 2774beb commit a2833fb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -371,6 +377,16 @@ impl Connection {
Ok(())
}

async fn update_caps(self: &Arc<Self>) -> 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<Self>) -> Result<()> {
if !self.is_delegate() {
if let Err(err) = self.client.ping().await {
Expand Down
13 changes: 13 additions & 0 deletions src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit a2833fb

Please sign in to comment.