minimization of rpc calls based on the responses

Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
Uncle Stretch 2025-02-18 17:10:04 +03:00
parent 33027f96d5
commit 2635792dab
Signed by: str3tch
GPG Key ID: 84F3190747EE79AA
4 changed files with 28 additions and 21 deletions

View File

@ -2,7 +2,7 @@
name = "ghost-eye" name = "ghost-eye"
authors = ["str3tch <stretch@ghostchain.io>"] authors = ["str3tch <stretch@ghostchain.io>"]
description = "Application for interacting with Casper/Ghost nodes that are exposing RPC only to the localhost" description = "Application for interacting with Casper/Ghost nodes that are exposing RPC only to the localhost"
version = "0.3.37" version = "0.3.38"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View File

@ -94,17 +94,20 @@ impl CurrentValidatorDetails {
} }
fn update_choosen_validator(&mut self, account_id: [u8; 32], individual: u32, total: u32) { fn update_choosen_validator(&mut self, account_id: [u8; 32], individual: u32, total: u32) {
self.choosen = account_id;
self.points_ratio = match total { self.points_ratio = match total {
0 => 0.0, 0 => 0.0,
_ => (individual as f64 / total as f64) * 100.0, _ => (individual as f64 / total as f64) * 100.0,
}; };
if let Some(network_tx) = &self.network_tx {
let _ = network_tx.send(Action::GetErasStakersOverview(account_id, false)); if self.choosen != account_id {
let _ = network_tx.send(Action::GetNominatorsByValidator(account_id, false)); self.choosen = account_id;
let _ = network_tx.send(Action::GetValidatorPrefs(account_id, false)); if let Some(network_tx) = &self.network_tx {
let _ = network_tx.send(Action::GetValidatorLedger(account_id, false)); let _ = network_tx.send(Action::GetErasStakersOverview(account_id, false));
let _ = network_tx.send(Action::GetValidatorLatestClaim(account_id, false)); let _ = network_tx.send(Action::GetNominatorsByValidator(account_id, false));
let _ = network_tx.send(Action::GetValidatorPrefs(account_id, false));
let _ = network_tx.send(Action::GetValidatorLedger(account_id, false));
let _ = network_tx.send(Action::GetValidatorLatestClaim(account_id, false));
}
} }
} }
} }

View File

@ -127,6 +127,7 @@ impl Network {
predefined_calls::get_nominators_by_validator(&self.action_tx, &self.online_client_api, &validator_details_to_watch).await?; predefined_calls::get_nominators_by_validator(&self.action_tx, &self.online_client_api, &validator_details_to_watch).await?;
predefined_calls::get_validator_prefs(&self.action_tx, &self.online_client_api, &validator_details_to_watch).await?; predefined_calls::get_validator_prefs(&self.action_tx, &self.online_client_api, &validator_details_to_watch).await?;
predefined_calls::get_staking_value_ratio(&self.action_tx, &self.online_client_api, &validator_details_to_watch).await?; predefined_calls::get_staking_value_ratio(&self.action_tx, &self.online_client_api, &validator_details_to_watch).await?;
predefined_calls::get_validator_latest_claim(&self.action_tx, &self.online_client_api, &validator_details_to_watch).await?;
} }
for account_id in self.accounts_to_watch.iter() { for account_id in self.accounts_to_watch.iter() {
predefined_calls::get_balance(&self.action_tx, &self.online_client_api, &account_id).await?; predefined_calls::get_balance(&self.action_tx, &self.online_client_api, &account_id).await?;

View File

@ -284,7 +284,9 @@ pub async fn get_validator_staking_results(
let current_era = super::raw_calls::staking::current_era(api, None).await?.unwrap_or(0); let current_era = super::raw_calls::staking::current_era(api, None).await?.unwrap_or(0);
let era_depth = super::raw_calls::staking::history_depth(api).unwrap_or(0); let era_depth = super::raw_calls::staking::history_depth(api).unwrap_or(0);
for era_index in current_era.saturating_sub(era_depth)..current_era { for era_index in current_era.saturating_sub(era_depth)..current_era {
get_validator_staking_result(action_tx, api, account_id, era_index).await?; if get_validator_staking_result(action_tx, api, account_id, era_index).await? {
break;
}
} }
Ok(()) Ok(())
} }
@ -294,11 +296,11 @@ pub async fn get_validator_staking_result(
api: &OnlineClient<CasperConfig>, api: &OnlineClient<CasperConfig>,
account_id: &[u8; 32], account_id: &[u8; 32],
era_index: u32, era_index: u32,
) -> Result<()> { ) -> Result<bool> {
get_validator_reward_in_era(action_tx, api, account_id, era_index).await?; let no_more_rewards = get_validator_reward_in_era(action_tx, api, account_id, era_index).await?;
get_validator_claims_in_era(action_tx, api, account_id, era_index).await?; get_validator_claims_in_era(action_tx, api, account_id, era_index).await?;
get_validator_slashes_in_era(action_tx, api, account_id, era_index).await?; get_validator_slashes_in_era(action_tx, api, account_id, era_index).await?;
Ok(()) Ok(no_more_rewards)
} }
pub async fn get_current_validator_reward_in_era( pub async fn get_current_validator_reward_in_era(
@ -351,13 +353,9 @@ async fn get_validator_reward_in_era(
api: &OnlineClient<CasperConfig>, api: &OnlineClient<CasperConfig>,
account_id: &[u8; 32], account_id: &[u8; 32],
era_index: u32, era_index: u32,
) -> Result<()> { ) -> Result<bool> {
let maybe_era_reward_points = super::raw_calls::staking::eras_reward_points(api, None, era_index) let maybe_era_reward_points = super::raw_calls::staking::eras_reward_points(api, None, era_index).await?;
.await?; let era_reward = super::raw_calls::staking::eras_validator_reward(api, None, era_index).await?.unwrap_or_default();
let era_reward = super::raw_calls::staking::eras_validator_reward(api, None, era_index)
.await?
.unwrap_or_default();
let my_reward = match maybe_era_reward_points { let my_reward = match maybe_era_reward_points {
Some(era_reward_points) => { Some(era_reward_points) => {
@ -373,9 +371,14 @@ async fn get_validator_reward_in_era(
None => 0u128, None => 0u128,
}; };
action_tx.send(Action::SetValidatorEraReward(era_index, my_reward))?; let no_more_rewards = if my_reward > 0 {
action_tx.send(Action::SetValidatorEraReward(era_index, my_reward))?;
false
} else {
true
};
Ok(()) Ok(no_more_rewards)
} }
async fn get_validator_claims_in_era( async fn get_validator_claims_in_era(