Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ use crate::nyxd::error::NyxdError;
use crate::nyxd::CosmWasmClient;
use async_trait::async_trait;
use cosmrs::AccountId;
use serde::Deserialize;

pub use nym_performance_contract_common::{
msg::QueryMsg as PerformanceQueryMsg, types::NetworkMonitorResponse,
msg::QueryMsg as PerformanceQueryMsg, types::NetworkMonitorResponse, EpochId,
EpochMeasurementsPagedResponse, EpochNodePerformance, EpochPerformancePagedResponse,
FullHistoricalPerformancePagedResponse, HistoricalPerformance, LastSubmission,
NetworkMonitorInformation, NetworkMonitorsPagedResponse, NodeId, NodeMeasurement,
NodeMeasurementsResponse, NodePerformance, NodePerformancePagedResponse,
NodePerformanceResponse, RetiredNetworkMonitor, RetiredNetworkMonitorsPagedResponse,
};
use nym_performance_contract_common::{
EpochId, EpochMeasurementsPagedResponse, EpochNodePerformance, EpochPerformancePagedResponse,
FullHistoricalPerformancePagedResponse, HistoricalPerformance, NetworkMonitorInformation,
NetworkMonitorsPagedResponse, NodeId, NodeMeasurement, NodeMeasurementsResponse,
NodePerformance, NodePerformancePagedResponse, NodePerformanceResponse, RetiredNetworkMonitor,
RetiredNetworkMonitorsPagedResponse,
};
use serde::Deserialize;

#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
Expand Down Expand Up @@ -139,6 +138,11 @@ pub trait PerformanceQueryClient {
})
.await
}

async fn get_last_submission(&self) -> Result<LastSubmission, NyxdError> {
self.query_performance_contract(PerformanceQueryMsg::LastSubmittedMeasurement {})
.await
}
}

// extension trait to the query client to deal with the paged queries
Expand Down Expand Up @@ -212,6 +216,7 @@ where
mod tests {
use super::*;
use crate::nyxd::contract_traits::tests::IgnoreValue;
use nym_performance_contract_common::QueryMsg;

// it's enough that this compiles and clippy is happy about it
#[allow(dead_code)]
Expand Down Expand Up @@ -260,6 +265,7 @@ mod tests {
PerformanceQueryMsg::RetiredNetworkMonitorsPaged { start_after, limit } => client
.get_retired_network_monitors_paged(start_after, limit)
.ignore(),
QueryMsg::LastSubmittedMeasurement {} => client.get_last_submission().ignore(),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ pub struct RewardEstimate {
pub operating_cost: Decimal,
}

impl RewardEstimate {
pub const fn zero() -> RewardEstimate {
RewardEstimate {
total_node_reward: Decimal::zero(),
operator: Decimal::zero(),
delegates: Decimal::zero(),
operating_cost: Decimal::zero(),
}
}
}

#[cw_serde]
#[derive(Copy, Default)]
pub struct RewardDistribution {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
pub mod storage_keys {
pub const CONTRACT_ADMIN: &str = "contract-admin";
pub const INITIAL_EPOCH_ID: &str = "initial-epoch-id";
pub const LAST_SUBMISSION: &str = "last-submission";
pub const MIXNET_CONTRACT: &str = "mixnet-contract";
pub const AUTHORISED_COUNT: &str = "authorised-count";
pub const AUTHORISED: &str = "authorised";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use cosmwasm_schema::cw_serde;
#[cfg(feature = "schema")]
use crate::types::{
EpochMeasurementsPagedResponse, EpochPerformancePagedResponse,
FullHistoricalPerformancePagedResponse, NetworkMonitorResponse, NetworkMonitorsPagedResponse,
NodeMeasurementsResponse, NodePerformancePagedResponse, NodePerformanceResponse,
RetiredNetworkMonitorsPagedResponse,
FullHistoricalPerformancePagedResponse, LastSubmission, NetworkMonitorResponse,
NetworkMonitorsPagedResponse, NodeMeasurementsResponse, NodePerformancePagedResponse,
NodePerformanceResponse, RetiredNetworkMonitorsPagedResponse,
};

#[cw_serde]
Expand Down Expand Up @@ -113,6 +113,10 @@ pub enum QueryMsg {
start_after: Option<String>,
limit: Option<u32>,
},

/// Returns information regarding the latest submitted performance data
#[cfg_attr(feature = "schema", returns(LastSubmission))]
LastSubmittedMeasurement {},
}

#[cw_serde]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,28 @@
// SPDX-License-Identifier: Apache-2.0

use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Addr, Env};
use cosmwasm_std::{Addr, Env, Timestamp};
use nym_contracts_common::Percent;

pub type EpochId = u32;
pub type NodeId = u32;

#[cw_serde]
pub struct LastSubmission {
pub block_height: u64,
pub block_time: Timestamp,

// not as relevant, but might as well store it
pub data: Option<LastSubmittedData>,
}

#[cw_serde]
pub struct LastSubmittedData {
pub sender: Addr,
pub epoch_id: EpochId,
pub data: NodePerformance,
}

#[cw_serde]
pub struct NetworkMonitorDetails {
pub address: Addr,
Expand Down
Loading
Loading