Remove required deposit from signers (#1791)
This commit is contained in:
committed by
GitHub
parent
236594f0c6
commit
f4fb0d6d6c
@@ -8,7 +8,7 @@ use coconut_dkg_common::dealer::{
|
||||
DealerDetailsResponse, PagedDealerResponse, PagedDealingsResponse,
|
||||
};
|
||||
use coconut_dkg_common::msg::QueryMsg as DkgQueryMsg;
|
||||
use coconut_dkg_common::types::{EpochState, MinimumDepositResponse};
|
||||
use coconut_dkg_common::types::EpochState;
|
||||
use coconut_dkg_common::verification_key::PagedVKSharesResponse;
|
||||
use cosmrs::AccountId;
|
||||
|
||||
@@ -30,7 +30,6 @@ pub trait DkgQueryClient {
|
||||
page_limit: Option<u32>,
|
||||
) -> Result<PagedDealerResponse, NymdError>;
|
||||
|
||||
async fn get_deposit_amount(&self) -> Result<MinimumDepositResponse, NymdError>;
|
||||
async fn get_dealings_paged(
|
||||
&self,
|
||||
idx: usize,
|
||||
@@ -95,13 +94,6 @@ where
|
||||
.await
|
||||
}
|
||||
|
||||
async fn get_deposit_amount(&self) -> Result<MinimumDepositResponse, NymdError> {
|
||||
let request = DkgQueryMsg::GetDepositAmount {};
|
||||
self.client
|
||||
.query_contract_smart(self.coconut_dkg_contract_address(), &request)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn get_dealings_paged(
|
||||
&self,
|
||||
idx: usize,
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
use crate::nymd::cosmwasm_client::types::ExecuteResult;
|
||||
use crate::nymd::error::NymdError;
|
||||
use crate::nymd::traits::dkg_query_client::DkgQueryClient;
|
||||
use crate::nymd::{Fee, NymdClient, SigningCosmWasmClient};
|
||||
use async_trait::async_trait;
|
||||
use coconut_dkg_common::msg::ExecuteMsg as DkgExecuteMsg;
|
||||
@@ -48,7 +47,6 @@ where
|
||||
bte_key_with_proof: bte_key,
|
||||
announce_address,
|
||||
};
|
||||
let deposit = self.get_deposit_amount().await?;
|
||||
|
||||
self.client
|
||||
.execute(
|
||||
@@ -57,7 +55,7 @@ where
|
||||
&req,
|
||||
fee.unwrap_or_default(),
|
||||
format!("registering {} as a dealer", self.address()),
|
||||
vec![deposit.amount.into()],
|
||||
vec![],
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
@@ -2,17 +2,16 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::types::{ContractSafeBytes, EncodedBTEPublicKeyWithProof, NodeIndex};
|
||||
use cosmwasm_std::{Addr, Coin};
|
||||
use cosmwasm_std::Addr;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct DealerDetails {
|
||||
pub address: Addr,
|
||||
pub bte_public_key_with_proof: EncodedBTEPublicKeyWithProof,
|
||||
pub announce_address: String,
|
||||
pub assigned_index: NodeIndex,
|
||||
pub deposit: Coin,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
@@ -29,7 +28,7 @@ impl DealerType {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct DealerDetailsResponse {
|
||||
pub details: Option<DealerDetails>,
|
||||
@@ -45,7 +44,7 @@ impl DealerDetailsResponse {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct PagedDealerResponse {
|
||||
pub dealers: Vec<DealerDetails>,
|
||||
|
||||
@@ -53,7 +53,6 @@ pub enum QueryMsg {
|
||||
limit: Option<u32>,
|
||||
start_after: Option<String>,
|
||||
},
|
||||
GetDepositAmount {},
|
||||
GetDealing {
|
||||
idx: u64,
|
||||
limit: Option<u32>,
|
||||
|
||||
@@ -79,15 +79,3 @@ impl EpochState {
|
||||
states
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct MinimumDepositResponse {
|
||||
pub amount: Coin,
|
||||
}
|
||||
|
||||
impl MinimumDepositResponse {
|
||||
pub fn new(amount: Coin) -> Self {
|
||||
MinimumDepositResponse { amount }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use cosmwasm_std::Uint128;
|
||||
|
||||
// to be determined whether those should be constants or exist as contract state
|
||||
pub(crate) const MINIMUM_DEPOSIT: Uint128 = Uint128::new(1_000_000_000);
|
||||
// Wait time for the verification to take place (currently 24h)
|
||||
pub(crate) const BLOCK_TIME_FOR_VERIFICATION_SECS: u64 = 86400;
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::constants::MINIMUM_DEPOSIT;
|
||||
use crate::dealers::storage as dealers_storage;
|
||||
use crate::epoch_state::utils::check_epoch_state;
|
||||
use crate::{ContractError, State, STATE};
|
||||
use coconut_dkg_common::types::{DealerDetails, EncodedBTEPublicKeyWithProof, EpochState};
|
||||
use cosmwasm_std::{Addr, Coin, DepsMut, MessageInfo, Response};
|
||||
use cosmwasm_std::{Addr, DepsMut, MessageInfo, Response};
|
||||
|
||||
// currently we only require that
|
||||
// a) it's part of the signer group
|
||||
@@ -27,40 +26,6 @@ fn verify_dealer(deps: DepsMut<'_>, state: &State, dealer: &Addr) -> Result<(),
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_dealer_deposit(state: &State, mut deposit: Vec<Coin>) -> Result<Coin, ContractError> {
|
||||
// check if anything was put as deposit
|
||||
if deposit.is_empty() {
|
||||
return Err(ContractError::NoDepositFound {
|
||||
denom: state.mix_denom.clone(),
|
||||
});
|
||||
}
|
||||
|
||||
if deposit.len() > 1 {
|
||||
return Err(ContractError::MultipleDenoms);
|
||||
}
|
||||
|
||||
// check that the denomination is correct
|
||||
if deposit[0].denom != state.mix_denom {
|
||||
return Err(ContractError::WrongDenom {
|
||||
denom: state.mix_denom.clone(),
|
||||
});
|
||||
}
|
||||
|
||||
// check that we have at least MINIMUM_DEPOSIT coins in our deposit
|
||||
if deposit[0].amount < MINIMUM_DEPOSIT {
|
||||
return Err(ContractError::InsufficientDeposit {
|
||||
received: deposit[0].amount.into(),
|
||||
minimum: MINIMUM_DEPOSIT.into(),
|
||||
});
|
||||
}
|
||||
|
||||
// the unwrap would have been safe here under all circumstances, since we checked whether the vector is empty
|
||||
// but in case something did change, change option into an error
|
||||
deposit.pop().ok_or(ContractError::NoDepositFound {
|
||||
denom: state.mix_denom.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn try_add_dealer(
|
||||
mut deps: DepsMut<'_>,
|
||||
info: MessageInfo,
|
||||
@@ -72,9 +37,6 @@ pub fn try_add_dealer(
|
||||
|
||||
verify_dealer(deps.branch(), &state, &info.sender)?;
|
||||
|
||||
// validate and extract sent deposit
|
||||
let deposit = validate_dealer_deposit(&state, info.funds)?;
|
||||
|
||||
// if it was already a dealer in the past, assign the same node index
|
||||
let node_index = if let Some(prior_details) =
|
||||
dealers_storage::past_dealers().may_load(deps.storage, &info.sender)?
|
||||
@@ -97,7 +59,6 @@ pub fn try_add_dealer(
|
||||
bte_public_key_with_proof: bte_key_with_proof,
|
||||
announce_address,
|
||||
assigned_index: node_index,
|
||||
deposit,
|
||||
};
|
||||
dealers_storage::current_dealers().save(deps.storage, &info.sender, &dealer_details)?;
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::constants::MINIMUM_DEPOSIT;
|
||||
use crate::dealers::queries::{
|
||||
query_current_dealers_paged, query_dealer_details, query_past_dealers_paged,
|
||||
};
|
||||
@@ -11,9 +10,9 @@ use crate::error::ContractError;
|
||||
use crate::state::{State, ADMIN, MULTISIG, STATE};
|
||||
use crate::verification_key_shares::queries::query_vk_shares_paged;
|
||||
use coconut_dkg_common::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};
|
||||
use coconut_dkg_common::types::{EpochState, MinimumDepositResponse};
|
||||
use coconut_dkg_common::types::EpochState;
|
||||
use cosmwasm_std::{
|
||||
entry_point, to_binary, Coin, Deps, DepsMut, Env, MessageInfo, QueryResponse, Response,
|
||||
entry_point, to_binary, Deps, DepsMut, Env, MessageInfo, QueryResponse, Response,
|
||||
};
|
||||
use cw4::Cw4Contract;
|
||||
use epoch_state::storage::{advance_epoch_state, CURRENT_EPOCH_STATE};
|
||||
@@ -106,10 +105,6 @@ pub fn query(deps: Deps<'_>, _env: Env, msg: QueryMsg) -> Result<QueryResponse,
|
||||
QueryMsg::GetPastDealers { limit, start_after } => {
|
||||
to_binary(&query_past_dealers_paged(deps, start_after, limit)?)?
|
||||
}
|
||||
QueryMsg::GetDepositAmount {} => to_binary(&MinimumDepositResponse::new(Coin::new(
|
||||
MINIMUM_DEPOSIT.u128(),
|
||||
STATE.load(deps.storage)?.mix_denom,
|
||||
)))?,
|
||||
QueryMsg::GetDealing {
|
||||
idx,
|
||||
limit,
|
||||
|
||||
@@ -101,7 +101,7 @@ fn dkg_create_proposal() {
|
||||
bte_key_with_proof: "bte_key_with_proof".to_string(),
|
||||
announce_address: "127.0.0.1:8000".to_string(),
|
||||
},
|
||||
&coins(1000000000, TEST_COIN_DENOM),
|
||||
&vec![],
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user