Feature/nymd client integration (#736)

* Calculating gas fees

* Ability to set custom fees

* Added extra test

* Removed commented code

* Moved all msg types to common contract crate

* Temporarily disabling get_tx method

* Finishing up nymd client API

* Comment fix

* Remaining fee values

* Some cleanup

* Removed needless borrow

* Fixed imports in contract tests

* Moved error types around

* New ValidatorClient

* Experiment with new type of defaults

* Removed dead module

* Dealt with unwrap

* Migrated mixnode to use new validator client

* Migrated gateway to use new validator client

* Mixnode and gateway adjustments

* More exported defaults

* Clients using new validator client

* Fixed mixnode upgrade

* Moved default values to a new crate

* Changed behaviour of validator client features

* Migrated basic functions of validator api

* Updated config + fixed startup

* Fixed wasm client build

* Integration with the explorer api

* Removed tokio dev dependency

* Needless borrow

* Fixex wasm client build

* Fixed tauri client build

* Needless borrows

* Fixed client upgrade print

* Removed redundant comments

* Made note on aggregated verification key into a doc comment

* Removed mixnet contract references from verloc

* Modified default validators structure

* Reformatted validator-api Cargo.toml file

* Removed commented code

* Made the doc comment example a no-run

* Fixed a upgrade print... again

* Adjusted the doc example

* Removed unused import
This commit is contained in:
Jędrzej Stuczyński
2021-08-18 14:41:00 +01:00
committed by GitHub
parent eec211e038
commit a274edffba
91 changed files with 2249 additions and 2784 deletions
+20 -17
View File
@@ -1,7 +1,9 @@
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use crate::nymd_client::Client;
use anyhow::Result;
use config::defaults::VALIDATOR_API_VERSION;
use mixnet_contract::{GatewayBond, MixNodeBond};
use rocket::fairing::AdHoc;
use serde::Serialize;
@@ -10,13 +12,12 @@ use std::sync::Arc;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use tokio::sync::RwLock;
use tokio::time;
use validator_client::validator_api::VALIDATOR_API_CACHE_VERSION;
use validator_client::Client;
use validator_client::nymd::CosmWasmClient;
pub(crate) mod routes;
pub struct ValidatorCacheRefresher {
validator_client: Client,
pub struct ValidatorCacheRefresher<C> {
nymd_client: Client<C>,
cache: ValidatorCache,
caching_interval: Duration,
}
@@ -35,7 +36,6 @@ struct ValidatorCacheInner {
#[derive(Default, Serialize, Clone)]
pub struct Cache<T> {
value: T,
#[allow(dead_code)]
as_at: u64,
}
@@ -53,27 +53,26 @@ impl<T: Clone> Cache<T> {
}
}
impl ValidatorCacheRefresher {
impl<C> ValidatorCacheRefresher<C> {
pub(crate) fn new(
validators_rest_uris: Vec<String>,
mixnet_contract: String,
nymd_client: Client<C>,
caching_interval: Duration,
cache: ValidatorCache,
) -> Self {
let config = validator_client::Config::new(validators_rest_uris, mixnet_contract);
let validator_client = validator_client::Client::new(config);
ValidatorCacheRefresher {
validator_client,
nymd_client,
cache,
caching_interval,
}
}
async fn refresh_cache(&self) -> Result<()> {
async fn refresh_cache(&self) -> Result<()>
where
C: CosmWasmClient + Sync,
{
let (mixnodes, gateways) = tokio::try_join!(
self.validator_client.get_mix_nodes(),
self.validator_client.get_gateways()
self.nymd_client.get_mixnodes(),
self.nymd_client.get_gateways()
)?;
info!(
@@ -87,7 +86,10 @@ impl ValidatorCacheRefresher {
Ok(())
}
pub(crate) async fn run(&self) {
pub(crate) async fn run(&self)
where
C: CosmWasmClient + Sync,
{
let mut interval = time::interval(self.caching_interval);
loop {
interval.tick().await;
@@ -113,7 +115,8 @@ impl ValidatorCache {
pub fn stage() -> AdHoc {
AdHoc::on_ignite("Validator Cache Stage", |rocket| async {
rocket.manage(Self::new()).mount(
VALIDATOR_API_CACHE_VERSION,
// this format! is so ugly...
format!("/{}", VALIDATOR_API_VERSION),
routes![routes::get_mixnodes, routes::get_gateways],
)
})