From e911e9e7eeaf6367261ca3ecea514250d45b86b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Mon, 31 Jul 2023 15:52:06 +0100 Subject: [PATCH] wip --- .../validator-client/src/client.rs | 160 ++---------------- .../contract_traits/mixnet_query_client.rs | 48 ++++-- .../websocket/connection_handler/coconut.rs | 4 +- 3 files changed, 51 insertions(+), 161 deletions(-) diff --git a/common/client-libs/validator-client/src/client.rs b/common/client-libs/validator-client/src/client.rs index 854648bcc9..1925ee9910 100644 --- a/common/client-libs/validator-client/src/client.rs +++ b/common/client-libs/validator-client/src/client.rs @@ -205,130 +205,6 @@ impl Client { .clone() } - // pub async fn get_all_node_families(&self) -> Result, ValidatorClientError> - // where - // C: CosmWasmClient + Sync + Send, - // { - // let mut families = Vec::new(); - // let mut start_after = None; - // - // loop { - // let paged_response = self - // .nyxd - // .get_all_node_families_paged(start_after.take(), None) - // .await?; - // families.extend(paged_response.families); - // - // if let Some(start_after_res) = paged_response.start_next_after { - // start_after = Some(start_after_res) - // } else { - // break; - // } - // } - // - // Ok(families) - // } - // - // pub async fn get_all_family_members( - // &self, - // ) -> Result, ValidatorClientError> - // where - // C: CosmWasmClient + Sync + Send, - // { - // let mut members = Vec::new(); - // let mut start_after = None; - // - // loop { - // let paged_response = self - // .nyxd - // .get_all_family_members_paged(start_after.take(), None) - // .await?; - // members.extend(paged_response.members); - // - // if let Some(start_after_res) = paged_response.start_next_after { - // start_after = Some(start_after_res) - // } else { - // break; - // } - // } - // - // Ok(members) - // } - // - // // basically handles paging for us - // pub async fn get_all_nyxd_rewarded_set_mixnodes( - // &self, - // ) -> Result, ValidatorClientError> - // where - // C: CosmWasmClient + Sync + Send, - // { - // let mut identities = Vec::new(); - // let mut start_after = None; - // - // loop { - // let mut paged_response = self - // .nyxd - // .get_rewarded_set_paged(start_after.take(), self.rewarded_set_page_limit) - // .await?; - // identities.append(&mut paged_response.nodes); - // - // if let Some(start_after_res) = paged_response.start_next_after { - // start_after = Some(start_after_res) - // } else { - // break; - // } - // } - // - // Ok(identities) - // } - // - // pub async fn get_all_nyxd_mixnode_bonds(&self) -> Result, ValidatorClientError> - // where - // C: CosmWasmClient + Sync + Send, - // { - // let mut mixnodes = Vec::new(); - // let mut start_after = None; - // loop { - // let mut paged_response = self - // .nyxd - // .get_mixnode_bonds_paged(self.mixnode_page_limit, start_after.take()) - // .await?; - // mixnodes.append(&mut paged_response.nodes); - // - // if let Some(start_after_res) = paged_response.start_next_after { - // start_after = Some(start_after_res) - // } else { - // break; - // } - // } - // - // Ok(mixnodes) - // } - // - // pub async fn get_all_nyxd_mixnodes_detailed( - // &self, - // ) -> Result, ValidatorClientError> - // where - // C: CosmWasmClient + Sync + Send, - // { - // let mut mixnodes = Vec::new(); - // let mut start_after = None; - // loop { - // let mut paged_response = self - // .nyxd - // .get_mixnodes_detailed_paged(self.mixnode_page_limit, start_after.take()) - // .await?; - // mixnodes.append(&mut paged_response.nodes); - // - // if let Some(start_after_res) = paged_response.start_next_after { - // start_after = Some(start_after_res) - // } else { - // break; - // } - // } - // - // Ok(mixnodes) - // } // // pub async fn get_all_nyxd_unbonded_mixnodes( // &self, @@ -676,40 +552,40 @@ impl CoconutApiClient { #[derive(Clone)] pub struct NymApiClient { - pub nym_api_client: nym_api::Client, + pub nym_api: nym_api::Client, // TODO: perhaps if we really need it at some (currently I don't see any reasons for it) // we could re-implement the communication with the REST API on port 1317 } impl NymApiClient { pub fn new(api_url: Url) -> Self { - let nym_api_client = nym_api::Client::new(api_url); + let nym_api = nym_api::Client::new(api_url); - NymApiClient { nym_api_client } + NymApiClient { nym_api } } pub fn change_nym_api(&mut self, new_endpoint: Url) { - self.nym_api_client.change_url(new_endpoint); + self.nym_api.change_url(new_endpoint); } pub async fn get_cached_active_mixnodes( &self, ) -> Result, ValidatorClientError> { - Ok(self.nym_api_client.get_active_mixnodes().await?) + Ok(self.nym_api.get_active_mixnodes().await?) } pub async fn get_cached_rewarded_mixnodes( &self, ) -> Result, ValidatorClientError> { - Ok(self.nym_api_client.get_rewarded_mixnodes().await?) + Ok(self.nym_api.get_rewarded_mixnodes().await?) } pub async fn get_cached_mixnodes(&self) -> Result, ValidatorClientError> { - Ok(self.nym_api_client.get_mixnodes().await?) + Ok(self.nym_api.get_mixnodes().await?) } pub async fn get_cached_gateways(&self) -> Result, ValidatorClientError> { - Ok(self.nym_api_client.get_gateways().await?) + Ok(self.nym_api.get_gateways().await?) } pub async fn get_gateway_core_status_count( @@ -718,7 +594,7 @@ impl NymApiClient { since: Option, ) -> Result { Ok(self - .nym_api_client + .nym_api .get_gateway_core_status_count(identity, since) .await?) } @@ -729,7 +605,7 @@ impl NymApiClient { since: Option, ) -> Result { Ok(self - .nym_api_client + .nym_api .get_mixnode_core_status_count(mix_id, since) .await?) } @@ -738,34 +614,28 @@ impl NymApiClient { &self, mix_id: MixId, ) -> Result { - Ok(self.nym_api_client.get_mixnode_status(mix_id).await?) + Ok(self.nym_api.get_mixnode_status(mix_id).await?) } pub async fn get_mixnode_reward_estimation( &self, mix_id: MixId, ) -> Result { - Ok(self - .nym_api_client - .get_mixnode_reward_estimation(mix_id) - .await?) + Ok(self.nym_api.get_mixnode_reward_estimation(mix_id).await?) } pub async fn get_mixnode_stake_saturation( &self, mix_id: MixId, ) -> Result { - Ok(self - .nym_api_client - .get_mixnode_stake_saturation(mix_id) - .await?) + Ok(self.nym_api.get_mixnode_stake_saturation(mix_id).await?) } pub async fn blind_sign( &self, request_body: &BlindSignRequestBody, ) -> Result { - Ok(self.nym_api_client.blind_sign(request_body).await?) + Ok(self.nym_api.blind_sign(request_body).await?) } pub async fn verify_bandwidth_credential( @@ -773,7 +643,7 @@ impl NymApiClient { request_body: &VerifyCredentialBody, ) -> Result { Ok(self - .nym_api_client + .nym_api .verify_bandwidth_credential(request_body) .await?) } diff --git a/common/client-libs/validator-client/src/nyxd/contract_traits/mixnet_query_client.rs b/common/client-libs/validator-client/src/nyxd/contract_traits/mixnet_query_client.rs index 5b9e684fb1..981a6754f9 100644 --- a/common/client-libs/validator-client/src/nyxd/contract_traits/mixnet_query_client.rs +++ b/common/client-libs/validator-client/src/nyxd/contract_traits/mixnet_query_client.rs @@ -9,6 +9,7 @@ use async_trait::async_trait; use cosmrs::AccountId; use nym_contracts_common::signing::Nonce; use nym_mixnet_contract_common::delegation::{MixNodeDelegationResponse, OwnerProxySubKey}; +use nym_mixnet_contract_common::families::{Family, FamilyHead}; use nym_mixnet_contract_common::mixnode::{ MixnodeRewardingDetailsResponse, PagedMixnodesDetailsResponse, PagedUnbondedMixnodesResponse, StakeSaturationResponse, UnbondedMixnodeResponse, @@ -22,12 +23,13 @@ use nym_mixnet_contract_common::{ CurrentIntervalResponse, EpochEventId, EpochStatus, FamilyByHeadResponse, FamilyByLabelResponse, FamilyMembersByHeadResponse, FamilyMembersByLabelResponse, GatewayBondResponse, GatewayOwnershipResponse, IdentityKey, IntervalEventId, LayerDistribution, - MixId, MixOwnershipResponse, MixnodeDetailsByIdentityResponse, MixnodeDetailsResponse, - NumberOfPendingEventsResponse, PagedAllDelegationsResponse, PagedDelegatorDelegationsResponse, - PagedFamiliesResponse, PagedGatewayResponse, PagedMembersResponse, - PagedMixNodeDelegationsResponse, PagedMixnodeBondsResponse, PagedRewardedSetResponse, - PendingEpochEventResponse, PendingEpochEventsResponse, PendingIntervalEventResponse, - PendingIntervalEventsResponse, QueryMsg as MixnetQueryMsg, + MixId, MixNodeBond, MixNodeDetails, MixOwnershipResponse, MixnodeDetailsByIdentityResponse, + MixnodeDetailsResponse, NumberOfPendingEventsResponse, PagedAllDelegationsResponse, + PagedDelegatorDelegationsResponse, PagedFamiliesResponse, PagedGatewayResponse, + PagedMembersResponse, PagedMixNodeDelegationsResponse, PagedMixnodeBondsResponse, + PagedRewardedSetResponse, PendingEpochEventResponse, PendingEpochEventsResponse, + PendingIntervalEventResponse, PendingIntervalEventsResponse, QueryMsg as MixnetQueryMsg, + RewardedSetNodeStatus, }; use serde::Deserialize; @@ -94,8 +96,8 @@ pub trait MixnetQueryClient { async fn get_all_family_members_paged( &self, - limit: Option, start_after: Option, + limit: Option, ) -> Result { self.query_mixnet_contract(MixnetQueryMsg::GetAllMembersPaged { limit, start_after }) .await @@ -123,8 +125,8 @@ pub trait MixnetQueryClient { async fn get_mixnode_bonds_paged( &self, - limit: Option, start_after: Option, + limit: Option, ) -> Result { self.query_mixnet_contract(MixnetQueryMsg::GetMixNodeBonds { limit, start_after }) .await @@ -132,8 +134,8 @@ pub trait MixnetQueryClient { async fn get_mixnodes_detailed_paged( &self, - limit: Option, start_after: Option, + limit: Option, ) -> Result { self.query_mixnet_contract(MixnetQueryMsg::GetMixNodesDetailed { limit, start_after }) .await @@ -141,8 +143,8 @@ pub trait MixnetQueryClient { async fn get_unbonded_paged( &self, - limit: Option, start_after: Option, + limit: Option, ) -> Result { self.query_mixnet_contract(MixnetQueryMsg::GetUnbondedMixNodes { limit, start_after }) .await @@ -151,8 +153,8 @@ pub trait MixnetQueryClient { async fn get_unbonded_by_owner_paged( &self, owner: &AccountId, - limit: Option, start_after: Option, + limit: Option, ) -> Result { self.query_mixnet_contract(MixnetQueryMsg::GetUnbondedMixNodesByOwner { owner: owner.to_string(), @@ -165,8 +167,8 @@ pub trait MixnetQueryClient { async fn get_unbonded_by_identity_paged( &self, identity_key: String, - limit: Option, start_after: Option, + limit: Option, ) -> Result { self.query_mixnet_contract(MixnetQueryMsg::GetUnbondedMixNodesByIdentityKey { identity_key, @@ -454,14 +456,32 @@ pub trait MixnetQueryClient { // extension trait to the query client to deal with the paged queries // (it didn't feel appropriate to combine it with the existing trait #[async_trait] -pub trait PagedMixnetClient: MixnetQueryClient { +pub trait PagedMixnetQueryClient: MixnetQueryClient { async fn get_all_node_families(&self) -> Result, NyxdError> { collect_paged!(self, get_all_node_families_paged, families) } + + async fn get_all_family_members(&self) -> Result, NyxdError> { + collect_paged!(self, get_all_family_members_paged, members) + } + + async fn get_all_rewarded_set_mixnodes( + &self, + ) -> Result, NyxdError> { + collect_paged!(self, get_rewarded_set_paged, nodes) + } + + async fn get_all_mixnode_bonds(&self) -> Result, NyxdError> { + collect_paged!(self, get_mixnode_bonds_paged, nodes) + } + + async fn get_all_mixnodes_detailed(&self) -> Result, NyxdError> { + collect_paged!(self, get_mixnodes_detailed_paged, nodes) + } } #[async_trait] -impl PagedMixnetClient for T where T: MixnetQueryClient {} +impl PagedMixnetQueryClient for T where T: MixnetQueryClient {} #[async_trait] impl MixnetQueryClient for C diff --git a/gateway/src/node/client_handling/websocket/connection_handler/coconut.rs b/gateway/src/node/client_handling/websocket/connection_handler/coconut.rs index 8d2dcbebb6..da9e7fd217 100644 --- a/gateway/src/node/client_handling/websocket/connection_handler/coconut.rs +++ b/gateway/src/node/client_handling/websocket/connection_handler/coconut.rs @@ -123,11 +123,11 @@ impl CoconutVerifier { match ret { Ok(res) => { if !res.verification_result { - debug!("Validator {} didn't accept the credential. It will probably vote No on the spending proposal", client.api_client.nym_api_client.current_url()); + debug!("Validator {} didn't accept the credential. It will probably vote No on the spending proposal", client.api_client.nym_api.current_url()); } } Err(e) => { - warn!("Validator {} could not be reached. There might be a problem with the coconut endpoint - {:?}", client.api_client.nym_api_client.current_url(), e); + warn!("Validator {} could not be reached. There might be a problem with the coconut endpoint - {:?}", client.api_client.nym_api.current_url(), e); } } }