Feature/migrate hidden delegations (#786)

* Remove migration code

* Added function to iterate over delegation of variable type

* Add unit tests

* Refactored some naming and reused mix/gateway functionality

* Borrow bucket instead of move

* Linked with existing delegations function

* Migration of left-over delegations

* Remove unused imports

* Put a gateway test as well, next to the mix one

* Expose queries for all delegations

* Change break point

* Added client side calls to the new queries

* Fix clippy

* Added pagination and read check tests

* Fix gateway test from the last commit

* Test functions for (de)serialization of identity and owner (in)to storage keys

* Add delegation function unit test

* Feature guard import

* Changed UnpackedDelegation from type to struct

* Remove mutable parameter and put start_after in returned value

* Made all delegations into iterator for OOM safety

* Fix clippy

* Add test for delegations iterator size in memory

* Change map with if let for ease of read

* Use DENOM instead of hardcoded value
This commit is contained in:
Bogdan-Ștefan Neacşu
2021-09-30 15:04:33 +03:00
committed by GitHub
parent 12637d93ff
commit 2a98f7482d
13 changed files with 995 additions and 124 deletions
+17 -4
View File
@@ -3,14 +3,20 @@ use rocket::serde::json::Json;
use rocket::{Route, State};
use serde::Serialize;
use mixnet_contract::{Addr, Coin, Layer, MixNode};
use mixnet_contract::{Addr, Coin, Layer, MixNode, RawDelegationData};
use crate::mix_node::models::{NodeDescription, NodeStats};
use crate::mix_nodes::{get_mixnode_delegations, Location};
use crate::mix_nodes::{get_mixnode_delegations, get_single_mixnode_delegations, Location};
use crate::state::ExplorerApiStateContext;
pub fn mix_node_make_default_routes() -> Vec<Route> {
routes_with_openapi![get_delegations, get_description, get_stats, list]
routes_with_openapi![
get_delegations,
get_all_delegations,
get_description,
get_stats,
list
]
}
#[derive(Clone, Debug, Serialize, JsonSchema)]
@@ -54,7 +60,14 @@ pub(crate) async fn list(
#[openapi(tag = "mix_node")]
#[get("/<pubkey>/delegations")]
pub(crate) async fn get_delegations(pubkey: &str) -> Json<Vec<mixnet_contract::Delegation>> {
Json(get_mixnode_delegations(pubkey).await)
Json(get_single_mixnode_delegations(pubkey).await)
}
#[openapi(tag = "mix_node")]
#[get("/all_mix_delegations")]
pub(crate) async fn get_all_delegations(
) -> Json<Vec<mixnet_contract::UnpackedDelegation<RawDelegationData>>> {
Json(get_mixnode_delegations().await)
}
#[openapi(tag = "mix_node")]
+15 -3
View File
@@ -8,7 +8,7 @@ use rocket::tokio::sync::RwLock;
use serde::{Deserialize, Serialize};
use crate::mix_nodes::utils::map_2_letter_to_3_letter_country_code;
use mixnet_contract::{Delegation, MixNodeBond};
use mixnet_contract::{Delegation, MixNodeBond, RawDelegationData, UnpackedDelegation};
use network_defaults::{
default_api_endpoints, default_nymd_endpoints, DEFAULT_MIXNET_CONTRACT_ADDRESS,
};
@@ -166,10 +166,10 @@ pub(crate) async fn retrieve_mixnodes() -> Vec<MixNodeBond> {
bonds
}
pub(crate) async fn get_mixnode_delegations(pubkey: &str) -> Vec<Delegation> {
pub(crate) async fn get_single_mixnode_delegations(pubkey: &str) -> Vec<Delegation> {
let client = new_nymd_client();
let delegates = match client
.get_all_nymd_mixnode_delegations(pubkey.to_string())
.get_all_nymd_single_mixnode_delegations(pubkey.to_string())
.await
{
Ok(result) => result,
@@ -181,6 +181,18 @@ pub(crate) async fn get_mixnode_delegations(pubkey: &str) -> Vec<Delegation> {
delegates
}
pub(crate) async fn get_mixnode_delegations() -> Vec<UnpackedDelegation<RawDelegationData>> {
let client = new_nymd_client();
let delegates = match client.get_all_nymd_mixnode_delegations().await {
Ok(result) => result,
Err(e) => {
error!("Could not get all mix delegations: {:?}", e);
vec![]
}
};
delegates
}
fn new_nymd_client() -> validator_client::Client<QueryNymdClient> {
let mixnet_contract = DEFAULT_MIXNET_CONTRACT_ADDRESS.to_string();
let nymd_url = default_nymd_endpoints()[0].clone();