Merge branch 'develop' into feature/vesting-full
This commit is contained in:
@@ -56,7 +56,6 @@ pub(crate) mod string_rfc3339_offset_date_time {
|
||||
}
|
||||
}
|
||||
|
||||
/// Representation of rewarding interval.
|
||||
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
|
||||
pub struct Interval {
|
||||
id: u32,
|
||||
@@ -67,11 +66,12 @@ pub struct Interval {
|
||||
|
||||
impl Interval {
|
||||
/// Initialize epoch in the contract with default values.
|
||||
/// FIXME: THIS unwrap!
|
||||
pub fn init_epoch(env: Env) -> Self {
|
||||
Interval {
|
||||
id: 0,
|
||||
start: OffsetDateTime::from_unix_timestamp(env.block.time.seconds() as i64).unwrap(),
|
||||
// I really don't see a way for this to fail, unless the blockchain is lying to us
|
||||
start: OffsetDateTime::from_unix_timestamp(env.block.time.seconds() as i64)
|
||||
.expect("Invalid timestamp from env.block.time"),
|
||||
length: Duration::from_secs(3600),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,9 +62,6 @@ pub enum ExecuteMsg {
|
||||
identity: IdentityKey,
|
||||
// percentage value in range 0-100
|
||||
params: NodeRewardParams,
|
||||
|
||||
// id of the current rewarding interval
|
||||
interval_id: u32,
|
||||
},
|
||||
// RewardNextMixDelegators {
|
||||
// mix_identity: IdentityKey,
|
||||
|
||||
@@ -146,13 +146,9 @@ pub fn execute(
|
||||
deps, info, params,
|
||||
)
|
||||
}
|
||||
#[allow(unused_variables)]
|
||||
// FIXME: remove interval_id
|
||||
ExecuteMsg::RewardMixnode {
|
||||
identity,
|
||||
params,
|
||||
interval_id,
|
||||
} => crate::rewards::transactions::try_reward_mixnode(deps, env, info, identity, params),
|
||||
ExecuteMsg::RewardMixnode { identity, params } => {
|
||||
crate::rewards::transactions::try_reward_mixnode(deps, env, info, identity, params)
|
||||
}
|
||||
ExecuteMsg::DelegateToMixnode { mix_identity } => {
|
||||
crate::delegations::transactions::try_delegate_to_mixnode(deps, env, info, mix_identity)
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ fn main() {
|
||||
mixnet::delegate::get_reverse_mix_delegations_paged,
|
||||
mixnet::delegate::undelegate_from_mixnode,
|
||||
mixnet::delegate::get_pending_delegation_events,
|
||||
mixnet::epoch::get_current_epoch,
|
||||
mixnet::send::send,
|
||||
utils::major_to_minor,
|
||||
utils::minor_to_major,
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
use crate::error::BackendError;
|
||||
use crate::nymd_client;
|
||||
use crate::state::State;
|
||||
use mixnet_contract_common::Interval;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
#[cfg_attr(test, derive(ts_rs::TS))]
|
||||
#[cfg_attr(test, ts(export, export_to = "../src/types/rust/epoch.ts"))]
|
||||
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
|
||||
pub struct Epoch {
|
||||
id: u32,
|
||||
start: i64,
|
||||
end: i64,
|
||||
duration_seconds: u64,
|
||||
}
|
||||
|
||||
impl From<Interval> for Epoch {
|
||||
fn from(interval: Interval) -> Self {
|
||||
Self {
|
||||
id: interval.id(),
|
||||
start: interval.start_unix_timestamp(),
|
||||
end: interval.end_unix_timestamp(),
|
||||
duration_seconds: interval.length().as_secs(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_current_epoch(
|
||||
state: tauri::State<'_, Arc<RwLock<State>>>,
|
||||
) -> Result<Epoch, BackendError> {
|
||||
let interval = nymd_client!(state).get_current_epoch().await?;
|
||||
Ok(interval.into())
|
||||
}
|
||||
@@ -2,4 +2,5 @@ pub mod account;
|
||||
pub mod admin;
|
||||
pub mod bond;
|
||||
pub mod delegate;
|
||||
pub mod epoch;
|
||||
pub mod send;
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
export interface Epoch { id: number, start: bigint, end: bigint, duration_seconds: bigint, }
|
||||
@@ -60,6 +60,7 @@ cfg-if = "1.0"
|
||||
|
||||
[features]
|
||||
coconut = ["coconut-interface", "credentials", "gateway-client/coconut"]
|
||||
no-reward = []
|
||||
|
||||
[build-dependencies]
|
||||
tokio = { version = "1.4", features = ["rt-multi-thread", "macros"] }
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::rewarded_set_updater::{error::RewardingError, MixnodeToReward};
|
||||
use crate::rewarded_set_updater::error::RewardingError;
|
||||
use config::defaults::{DEFAULT_NETWORK, DEFAULT_VALIDATOR_API_PORT};
|
||||
use mixnet_contract_common::Interval;
|
||||
use mixnet_contract_common::{
|
||||
@@ -332,13 +332,12 @@ impl<C> Client<C> {
|
||||
where
|
||||
C: SigningCosmWasmClient + Sync,
|
||||
{
|
||||
let mut msgs = vec![(ExecuteMsg::AdvanceCurrentEpoch {}, vec![])];
|
||||
|
||||
msgs.extend(reward_msgs);
|
||||
let mut msgs = reward_msgs;
|
||||
|
||||
let epoch_msgs = vec![
|
||||
(ExecuteMsg::ReconcileDelegations {}, vec![]),
|
||||
(ExecuteMsg::CheckpointMixnodes {}, vec![]),
|
||||
(ExecuteMsg::AdvanceCurrentEpoch {}, vec![]),
|
||||
(
|
||||
ExecuteMsg::WriteRewardedSet {
|
||||
rewarded_set,
|
||||
@@ -357,28 +356,6 @@ impl<C> Client<C> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn reward_mixnodes(
|
||||
&self,
|
||||
nodes: &[MixnodeToReward],
|
||||
interval_id: u32,
|
||||
) -> Result<Vec<(ExecuteMsg, Vec<CosmosCoin>)>, RewardingError>
|
||||
where
|
||||
C: SigningCosmWasmClient + Sync,
|
||||
{
|
||||
let msgs: Vec<(ExecuteMsg, _)> = nodes
|
||||
.iter()
|
||||
.map(|node| node.to_reward_execute_msg(interval_id))
|
||||
.zip(std::iter::repeat(Vec::new()))
|
||||
.collect();
|
||||
|
||||
// let memo = format!("rewarding {} mixnodes", msgs.len());
|
||||
|
||||
// self.execute_multiple_with_retry(msgs, Default::default(), memo)
|
||||
// .await
|
||||
|
||||
Ok(msgs)
|
||||
}
|
||||
|
||||
async fn execute_multiple_with_retry<M>(
|
||||
&self,
|
||||
msgs: Vec<(M, Vec<CosmosCoin>)>,
|
||||
|
||||
@@ -43,15 +43,16 @@ pub(crate) struct MixnodeToReward {
|
||||
}
|
||||
|
||||
impl MixnodeToReward {
|
||||
#[allow(dead_code)]
|
||||
fn params(&self) -> NodeRewardParams {
|
||||
self.params
|
||||
}
|
||||
|
||||
pub(crate) fn to_reward_execute_msg(&self, interval_id: u32) -> ExecuteMsg {
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn to_reward_execute_msg(&self) -> ExecuteMsg {
|
||||
ExecuteMsg::RewardMixnode {
|
||||
identity: self.identity.clone(),
|
||||
params: self.params(),
|
||||
interval_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -138,20 +139,25 @@ impl RewardedSetUpdater {
|
||||
.insert_rewarding_report(rewarding_report)
|
||||
.await?;
|
||||
|
||||
Ok(self.distribute_rewards(&to_reward).await?)
|
||||
Ok(self.generate_reward_messages(&to_reward).await?)
|
||||
}
|
||||
|
||||
async fn distribute_rewards(
|
||||
#[allow(unused_variables)]
|
||||
async fn generate_reward_messages(
|
||||
&self,
|
||||
eligible_mixnodes: &[MixnodeToReward],
|
||||
) -> Result<Vec<(ExecuteMsg, Vec<CosmosCoin>)>, RewardingError> {
|
||||
let epoch = self.epoch().await?;
|
||||
|
||||
let reward_msgs = self
|
||||
.nymd_client
|
||||
.reward_mixnodes(eligible_mixnodes, epoch.id())
|
||||
.await?;
|
||||
Ok(reward_msgs)
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(feature = "no-reward")] {
|
||||
Ok(vec![])
|
||||
} else {
|
||||
Ok(eligible_mixnodes
|
||||
.iter()
|
||||
.map(|node| node.to_reward_execute_msg())
|
||||
.zip(std::iter::repeat(Vec::new()))
|
||||
.collect())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn nodes_to_reward(&self) -> Result<Vec<MixnodeToReward>, RewardingError> {
|
||||
|
||||
Reference in New Issue
Block a user