Merge branch 'develop' into feature/additional-bond-validation

merge develop
This commit is contained in:
fmtabbara
2022-01-17 17:36:41 +00:00
19 changed files with 85 additions and 69 deletions
Generated
+2 -2
View File
@@ -1255,9 +1255,9 @@ dependencies = [
[[package]]
name = "cw-storage-plus"
version = "0.10.3"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3b8b840947313c1a1cccf056836cd79a60b4526bdcd6582995be37dc97be4ae"
checksum = "7d7ee1963302b0ac2a9d42fe0faec826209c17452bfd36fbfd9d002a88929261"
dependencies = [
"cosmwasm-std",
"schemars",
+12 -12
View File
@@ -245,9 +245,9 @@ dependencies = [
[[package]]
name = "cosmwasm-crypto"
version = "1.0.0-beta3"
version = "1.0.0-beta4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a380b87642204557629c9b72988c47b55fbfe6d474960adba56b22331504956a"
checksum = "f903ebbabc0d4880dbc76148efb8be8fc29fa4bf294c440c3d70da1c8bcafff7"
dependencies = [
"digest 0.9.0",
"ed25519-zebra",
@@ -258,9 +258,9 @@ dependencies = [
[[package]]
name = "cosmwasm-derive"
version = "1.0.0-beta3"
version = "1.0.0-beta4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "866713b2fe13f23038c7d8824c3059d1f28dd94685fb406d1533c4eeeefeefae"
checksum = "832bebef577ecb394603de8e2bf0de429b74aa364e17dec18e15ce37e71b0cae"
dependencies = [
"syn",
]
@@ -277,9 +277,9 @@ dependencies = [
[[package]]
name = "cosmwasm-std"
version = "1.0.0-beta3"
version = "1.0.0-beta4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8dbb9939b31441dfa9af3ec9740c8a24d585688401eff1b6b386abb7ad0d10a8"
checksum = "6238c45840cc9de5a39f0f619e3a4f7c38c5d2c6ac9e3e4d72751ee045e6d7da"
dependencies = [
"base64",
"cosmwasm-crypto",
@@ -293,9 +293,9 @@ dependencies = [
[[package]]
name = "cosmwasm-storage"
version = "1.0.0-beta3"
version = "1.0.0-beta4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4a4e55f0d64fed54cd2202301b8d466af8de044589247dabd77a4222f52f749"
checksum = "f472c0bfd584a4510702537d0b65c5331095e76099586a12f749fd69afda9c5e"
dependencies = [
"cosmwasm-std",
"serde",
@@ -394,9 +394,9 @@ dependencies = [
[[package]]
name = "cw-storage-plus"
version = "0.10.3"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3b8b840947313c1a1cccf056836cd79a60b4526bdcd6582995be37dc97be4ae"
checksum = "7d7ee1963302b0ac2a9d42fe0faec826209c17452bfd36fbfd9d002a88929261"
dependencies = [
"cosmwasm-std",
"schemars",
@@ -1202,9 +1202,9 @@ dependencies = [
[[package]]
name = "serde-json-wasm"
version = "0.3.1"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50eef3672ec8fa45f3457fd423ba131117786784a895548021976117c1ded449"
checksum = "042ac496d97e5885149d34139bad1d617192770d7eb8f1866da2317ff4501853"
dependencies = [
"serde",
]
+3 -3
View File
@@ -1556,9 +1556,9 @@
}
},
"@openzeppelin/contracts": {
"version": "4.4.1",
"resolved": "https://registry.npmjs.org/@openzeppelin/contracts/-/contracts-4.4.1.tgz",
"integrity": "sha512-o+pHCf/yMLSlV5MkDQEzEQL402i6SoRnktru+0rdSxVEFZcTzzGhZCAtZjUFyKGazMSv1TilzMg+RbED1N8XHQ=="
"version": "4.4.2",
"resolved": "https://registry.npmjs.org/@openzeppelin/contracts/-/contracts-4.4.2.tgz",
"integrity": "sha512-NyJV7sJgoGYqbtNUWgzzOGW4T6rR19FmX1IJgXGdapGPWsuMelGJn9h03nos0iqfforCbCB0iYIR0MtIuIFLLw=="
},
"@openzeppelin/test-helpers": {
"version": "0.5.15",
@@ -12,7 +12,7 @@
"dependencies": {
"@nomiclabs/hardhat-truffle5": "^2.0.2",
"@nomiclabs/hardhat-web3": "^2.0.0",
"@openzeppelin/contracts": "^4.4.1",
"@openzeppelin/contracts": "^4.4.2",
"@openzeppelin/test-helpers": "^0.5.15",
"dotenv": "^10.0.0",
"find-config": "^1.0.0"
+3 -3
View File
@@ -20,9 +20,9 @@ mixnet-contract-common = { path = "../../common/cosmwasm-smart-contracts/mixnet-
config = { path = "../../common/config"}
vesting-contract = { path = "../vesting" }
cosmwasm-std = "1.0.0-beta3"
cosmwasm-storage = "1.0.0-beta3"
cw-storage-plus = "0.10.3"
cosmwasm-std = "1.0.0-beta4"
cosmwasm-storage = "1.0.0-beta4"
cw-storage-plus = "0.11.1"
bs58 = "0.4.0"
schemars = "0.8"
+4 -4
View File
@@ -17,9 +17,9 @@ pub(crate) const DELEGATION_PAGE_DEFAULT_LIMIT: u32 = 250;
type PrimaryKey = Vec<u8>;
pub(crate) struct DelegationIndex<'a> {
pub(crate) owner: MultiIndex<'a, (Addr, PrimaryKey), Delegation>,
pub(crate) owner: MultiIndex<'a, Addr, Delegation>,
pub(crate) mixnode: MultiIndex<'a, (IdentityKey, PrimaryKey), Delegation>,
pub(crate) mixnode: MultiIndex<'a, IdentityKey, Delegation>,
}
impl<'a> IndexList<Delegation> for DelegationIndex<'a> {
@@ -46,12 +46,12 @@ impl<'a> IndexList<Delegation> for DelegationIndex<'a> {
pub(crate) fn delegations<'a>() -> IndexedMap<'a, PrimaryKey, Delegation, DelegationIndex<'a>> {
let indexes = DelegationIndex {
owner: MultiIndex::new(
|d, pk| (d.owner.clone(), pk),
|d| d.owner.clone(),
DELEGATION_PK_NAMESPACE,
DELEGATION_OWNER_IDX_NAMESPACE,
),
mixnode: MultiIndex::new(
|d, pk| (d.node_identity.clone(), pk),
|d| d.node_identity.clone(),
DELEGATION_PK_NAMESPACE,
DELEGATION_MIXNODE_IDX_NAMESPACE,
),
+2 -2
View File
@@ -64,7 +64,7 @@ pub(crate) fn update_rewarding_status(
if let Some(next_start) = next_start {
storage::REWARDING_STATUS.save(
storage,
(rewarding_interval_nonce.into(), mix_identity),
(rewarding_interval_nonce, mix_identity),
&RewardingStatus::PendingNextDelegatorPage(PendingDelegatorRewarding {
running_results: rewarding_results,
next_start,
@@ -74,7 +74,7 @@ pub(crate) fn update_rewarding_status(
} else {
storage::REWARDING_STATUS.save(
storage,
(rewarding_interval_nonce.into(), mix_identity),
(rewarding_interval_nonce, mix_identity),
&RewardingStatus::Complete(rewarding_results),
)?;
}
+2 -4
View File
@@ -19,10 +19,8 @@ pub(crate) fn query_rewarding_status(
mix_identity: IdentityKey,
rewarding_interval_nonce: u32,
) -> StdResult<MixnodeRewardingStatusResponse> {
let status = storage::REWARDING_STATUS.may_load(
deps.storage,
(rewarding_interval_nonce.into(), mix_identity),
)?;
let status = storage::REWARDING_STATUS
.may_load(deps.storage, (rewarding_interval_nonce, mix_identity))?;
Ok(MixnodeRewardingStatusResponse { status })
}
+3 -2
View File
@@ -4,11 +4,12 @@
use crate::error::ContractError;
use config::defaults::TOTAL_SUPPLY;
use cosmwasm_std::{StdResult, Storage, Uint128};
use cw_storage_plus::{Item, Map, U32Key};
use cw_storage_plus::{Item, Map};
use mixnet_contract_common::{IdentityKey, RewardingStatus};
pub(crate) const REWARD_POOL: Item<Uint128> = Item::new("pool");
pub(crate) const REWARDING_STATUS: Map<(U32Key, IdentityKey), RewardingStatus> = Map::new("rm");
// TODO: Do we need a migration for this?
pub(crate) const REWARDING_STATUS: Map<(u32, IdentityKey), RewardingStatus> = Map::new("rm");
// approximately 1 day (assuming 5s per block)
pub(crate) const MINIMUM_BLOCK_AGE_FOR_REWARDING: u64 = 17280;
+6 -6
View File
@@ -201,7 +201,7 @@ pub(crate) fn try_reward_next_mixnode_delegators(
match storage::REWARDING_STATUS.may_load(
deps.storage,
(rewarding_interval_nonce.into(), mix_identity.clone()),
(rewarding_interval_nonce, mix_identity.clone()),
)? {
None => {
// we haven't called 'regular' try_reward_mixnode, i.e. the operator itself
@@ -271,7 +271,7 @@ pub(crate) fn try_reward_mixnode(
// check if the mixnode hasn't been rewarded in this rewarding interval already
match storage::REWARDING_STATUS.may_load(
deps.storage,
(rewarding_interval_nonce.into(), mix_identity.clone()),
(rewarding_interval_nonce, mix_identity.clone()),
)? {
None => (),
Some(RewardingStatus::Complete(_)) => {
@@ -304,7 +304,7 @@ pub(crate) fn try_reward_mixnode(
if current_bond.block_height + storage::MINIMUM_BLOCK_AGE_FOR_REWARDING > env.block.height {
storage::REWARDING_STATUS.save(
deps.storage,
(rewarding_interval_nonce.into(), mix_identity.clone()),
(rewarding_interval_nonce, mix_identity.clone()),
&RewardingStatus::Complete(Default::default()),
)?;
@@ -320,7 +320,7 @@ pub(crate) fn try_reward_mixnode(
if params.uptime() == 0 {
storage::REWARDING_STATUS.save(
deps.storage,
(rewarding_interval_nonce.into(), mix_identity.clone()),
(rewarding_interval_nonce, mix_identity.clone()),
&RewardingStatus::Complete(Default::default()),
)?;
@@ -1257,7 +1257,7 @@ pub mod tests {
// it's all correctly saved
match storage::REWARDING_STATUS
.load(deps.as_ref().storage, (1.into(), node_identity))
.load(deps.as_ref().storage, (1u32, node_identity))
.unwrap()
{
RewardingStatus::Complete(result) => assert_eq!(
@@ -1635,7 +1635,7 @@ pub mod tests {
.idx
.mixnode
.prefix(node_identity.clone())
.range(deps.as_ref().storage, None, None, Order::Ascending)
.range_raw(deps.as_ref().storage, None, None, Order::Ascending)
{
let (primary_key, delegation) = delegation.unwrap();
let delegator_reward = Uint128::new(delegation.amount.amount.u128() - base_delegation);
+1 -1
View File
@@ -19,7 +19,7 @@ vesting-contract-common = { path = "../../common/cosmwasm-smart-contracts/vestin
config = { path = "../../common/config" }
cosmwasm-std = { version = "1.0.0-beta3"}
cw-storage-plus = { version = "0.10.3", features = ["iterator"] }
cw-storage-plus = { version = "0.11.1", features = ["iterator"] }
schemars = "0.8"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
@@ -111,8 +111,8 @@ impl DelegatingAccount for Account {
// Iterate over keys matching the prefix and remove them from the map
let block_times = delegations
.prefix_de(mix_bytes)
.keys_de(storage, None, None, Order::Ascending)
.prefix(mix_bytes)
.keys(storage, None, None, Order::Ascending)
// Scan will blow up on first error
.scan((), |_, x| x.ok())
.collect::<Vec<u64>>();
+2 -2
View File
@@ -196,8 +196,8 @@ impl Account {
let key = self.delegations_key();
let delegations: Map<(&[u8], u64), Uint128> = Map::new(&key);
delegations
.prefix_de(mix.as_bytes())
.keys_de(storage, None, None, Order::Ascending)
.prefix(mix.as_bytes())
.keys(storage, None, None, Order::Ascending)
// Scan will blow up on first error
.scan((), |_, x| x.ok())
.collect::<Vec<u64>>()
@@ -119,7 +119,7 @@ impl VestingAccount for Account {
let delegations: Map<(&[u8], u64), Uint128> = Map::new(&delegations_key);
let delegations_keys = delegations
.keys_de(storage, None, None, Order::Ascending)
.keys(storage, None, None, Order::Ascending)
.scan((), |_, x| x.ok())
.filter(|(_mix, block_time)| *block_time < start_time)
.map(|(mix, block_time)| (mix, block_time))
+2 -2
View File
@@ -954,9 +954,9 @@ dependencies = [
[[package]]
name = "cw-storage-plus"
version = "0.10.3"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3b8b840947313c1a1cccf056836cd79a60b4526bdcd6582995be37dc97be4ae"
checksum = "7d7ee1963302b0ac2a9d42fe0faec826209c17452bfd36fbfd9d002a88929261"
dependencies = [
"cosmwasm-std",
"schemars",
+22 -12
View File
@@ -131,18 +131,28 @@ pub(crate) async fn get_mixnode_reward_estimation(
.await
.map_err(|err| ErrorResponse::new(err.to_string(), Status::NotFound))?;
let (estimated_total_node_reward, estimated_operator_reward, estimated_delegators_reward) =
epoch_reward_params.estimate_reward(&bond, uptime.u8(), status.is_active());
Ok(Json(RewardEstimationResponse {
estimated_total_node_reward,
estimated_operator_reward,
estimated_delegators_reward,
current_epoch_start: current_epoch.start_unix_timestamp(),
current_epoch_end: current_epoch.end_unix_timestamp(),
current_epoch_uptime: uptime.u8(),
as_at,
}))
match epoch_reward_params.estimate_reward(&bond, uptime.u8(), status.is_active()) {
Ok((
estimated_total_node_reward,
estimated_operator_reward,
estimated_delegators_reward,
)) => {
let reponse = RewardEstimationResponse {
estimated_total_node_reward,
estimated_operator_reward,
estimated_delegators_reward,
current_epoch_start: current_epoch.start_unix_timestamp(),
current_epoch_end: current_epoch.end_unix_timestamp(),
current_epoch_uptime: uptime.u8(),
as_at,
};
Ok(Json(reponse))
}
Err(e) => Err(ErrorResponse::new(
e.to_string(),
Status::InternalServerError,
)),
}
} else {
Err(ErrorResponse::new(
"mixnode bond not found",
+6
View File
@@ -23,6 +23,12 @@ pub(crate) enum RewardingError {
#[error("Failed to query the smart contract - {0}")]
ValidatorClientError(ValidatorClientError),
#[error("Error downcasting u128 -> u64")]
DowncastingError {
#[from]
source: std::num::TryFromIntError,
},
}
impl From<NymdError> for RewardingError {
+8 -7
View File
@@ -58,7 +58,7 @@ impl EpochRewardParams {
node: &MixNodeBond,
uptime: u8,
in_active_set: bool,
) -> (u128, u128, u128) {
) -> Result<(u64, u64, u64), RewardingError> {
let node_reward_params = NodeRewardParams::new(
self.period_reward_pool,
self.rewarded_set_size.into(),
@@ -76,14 +76,15 @@ impl EpochRewardParams {
let delegators_reward =
node.reward_delegation(node.total_delegation().amount, &node_reward_params);
(
Ok((
total_node_reward
.reward()
.checked_to_num()
.unwrap_or_default(),
operator_reward,
delegators_reward,
)
.checked_to_num::<u128>()
.unwrap_or_default()
.try_into()?,
operator_reward.try_into()?,
delegators_reward.try_into()?,
))
}
}
@@ -35,9 +35,9 @@ pub struct MixnodeStatusResponse {
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
pub struct RewardEstimationResponse {
pub estimated_total_node_reward: u128,
pub estimated_operator_reward: u128,
pub estimated_delegators_reward: u128,
pub estimated_total_node_reward: u64,
pub estimated_operator_reward: u64,
pub estimated_delegators_reward: u64,
pub current_epoch_start: i64,
pub current_epoch_end: i64,