Recovering assigned node index
This commit is contained in:
@@ -320,6 +320,8 @@ pub trait SigningCosmWasmClient: CosmWasmClient {
|
||||
.await?
|
||||
.check_response()?;
|
||||
|
||||
println!("height: {}", tx_res.height);
|
||||
|
||||
let gas_info = GasInfo::new(tx_res.tx_result.gas_wanted, tx_res.tx_result.gas_used);
|
||||
|
||||
Ok(ExecuteResult {
|
||||
|
||||
@@ -5,16 +5,22 @@ use crate::nymd::cosmwasm_client::types::ExecuteResult;
|
||||
use crate::nymd::error::NymdError;
|
||||
use crate::nymd::{cosmwasm_coin_to_cosmos_coin, Fee, NymdClient, SigningCosmWasmClient};
|
||||
use async_trait::async_trait;
|
||||
use coconut_dkg_common::dealer::DealerDetailsResponse;
|
||||
use coconut_dkg_common::msg::ExecuteMsg as DkgExecuteMsg;
|
||||
use coconut_dkg_common::msg::QueryMsg as DkgQueryMsg;
|
||||
use coconut_dkg_common::types::{
|
||||
BlacklistingResponse, EncodedBTEPublicKeyWithProof, EncodedEd25519PublicKey, Epoch,
|
||||
MinimumDepositResponse, PagedBlacklistingResponse, PagedDealerResponse,
|
||||
};
|
||||
use cosmrs::AccountId;
|
||||
|
||||
#[async_trait]
|
||||
pub trait DkgClient {
|
||||
async fn get_current_dkg_epoch(&self) -> Result<Epoch, NymdError>;
|
||||
async fn get_dealer_details(
|
||||
&self,
|
||||
address: &AccountId,
|
||||
) -> Result<DealerDetailsResponse, NymdError>;
|
||||
async fn get_current_dealers_paged(
|
||||
&self,
|
||||
start_after: Option<String>,
|
||||
@@ -63,6 +69,19 @@ where
|
||||
.query_contract_smart(self.coconut_dkg_contract_address()?, &request)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn get_dealer_details(
|
||||
&self,
|
||||
address: &AccountId,
|
||||
) -> Result<DealerDetailsResponse, NymdError> {
|
||||
let request = DkgQueryMsg::GetDealerDetails {
|
||||
dealer_address: address.to_string(),
|
||||
};
|
||||
self.client
|
||||
.query_contract_smart(self.coconut_dkg_contract_address()?, &request)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn get_current_dealers_paged(
|
||||
&self,
|
||||
start_after: Option<String>,
|
||||
@@ -76,6 +95,7 @@ where
|
||||
.query_contract_smart(self.coconut_dkg_contract_address()?, &request)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn get_past_dealers_paged(
|
||||
&self,
|
||||
start_after: Option<String>,
|
||||
|
||||
@@ -88,6 +88,36 @@ impl Display for BlacklistingReason {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum DealerType {
|
||||
Current,
|
||||
Past,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
impl DealerType {
|
||||
pub fn is_current(&self) -> bool {
|
||||
matches!(&self, DealerType::Current)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct DealerDetailsResponse {
|
||||
pub details: Option<DealerDetails>,
|
||||
pub dealer_type: DealerType,
|
||||
}
|
||||
|
||||
impl DealerDetailsResponse {
|
||||
pub fn new(details: Option<DealerDetails>, dealer_type: DealerType) -> Self {
|
||||
DealerDetailsResponse {
|
||||
details,
|
||||
dealer_type,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct PagedDealerResponse {
|
||||
|
||||
@@ -38,6 +38,9 @@ pub enum ExecuteMsg {
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum QueryMsg {
|
||||
GetCurrentEpoch {},
|
||||
GetDealerDetails {
|
||||
dealer_address: String,
|
||||
},
|
||||
GetCurrentDealers {
|
||||
limit: Option<u32>,
|
||||
start_after: Option<String>,
|
||||
|
||||
Generated
+7
@@ -66,6 +66,12 @@ version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
|
||||
|
||||
[[package]]
|
||||
name = "bech32"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c5738be7561b0eeb501ef1d5c5db3f24e01ceb55fededd9b00039aada34966ad"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.3.2"
|
||||
@@ -227,6 +233,7 @@ dependencies = [
|
||||
name = "coconut-dkg"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bech32",
|
||||
"bs58",
|
||||
"coconut-dkg-common",
|
||||
"config",
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
use crate::dealers::storage;
|
||||
use crate::dealers::storage::{IndexedDealersMap, BLACKLISTED_DEALERS};
|
||||
use coconut_dkg_common::dealer::{
|
||||
BlacklistedDealer, BlacklistingResponse, PagedBlacklistingResponse, PagedDealerResponse,
|
||||
BlacklistedDealer, BlacklistingResponse, DealerDetailsResponse, DealerType,
|
||||
PagedBlacklistingResponse, PagedDealerResponse,
|
||||
};
|
||||
use cosmwasm_std::{Deps, Order, StdResult};
|
||||
use cw_storage_plus::Bound;
|
||||
@@ -36,6 +37,23 @@ fn query_dealers(
|
||||
Ok(PagedDealerResponse::new(dealers, limit, start_next_after))
|
||||
}
|
||||
|
||||
pub fn query_dealer_details(
|
||||
deps: Deps<'_>,
|
||||
dealer_address: String,
|
||||
) -> StdResult<DealerDetailsResponse> {
|
||||
let addr = deps.api.addr_validate(&dealer_address)?;
|
||||
if let Some(current) = storage::current_dealers().may_load(deps.storage, &addr)? {
|
||||
return Ok(DealerDetailsResponse::new(
|
||||
Some(current),
|
||||
DealerType::Current,
|
||||
));
|
||||
}
|
||||
if let Some(past) = storage::past_dealers().may_load(deps.storage, &addr)? {
|
||||
return Ok(DealerDetailsResponse::new(Some(past), DealerType::Past));
|
||||
}
|
||||
Ok(DealerDetailsResponse::new(None, DealerType::Unknown))
|
||||
}
|
||||
|
||||
pub fn query_current_dealers_paged(
|
||||
deps: Deps<'_>,
|
||||
start_after: Option<String>,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
use crate::constants::MINIMUM_DEPOSIT;
|
||||
use crate::dealers::queries::{
|
||||
query_blacklisted_dealers_paged, query_blacklisting, query_current_dealers_paged,
|
||||
query_past_dealers_paged,
|
||||
query_dealer_details, query_past_dealers_paged,
|
||||
};
|
||||
use crate::epoch::queries::query_current_epoch;
|
||||
use crate::error::ContractError;
|
||||
@@ -131,6 +131,9 @@ fn reset_contract_state(
|
||||
pub fn query(deps: Deps<'_>, _env: Env, msg: QueryMsg) -> Result<QueryResponse, ContractError> {
|
||||
let response = match msg {
|
||||
QueryMsg::GetCurrentEpoch {} => to_binary(&query_current_epoch(deps.storage)?)?,
|
||||
QueryMsg::GetDealerDetails { dealer_address } => {
|
||||
to_binary(&query_dealer_details(deps, dealer_address)?)?
|
||||
}
|
||||
QueryMsg::GetCurrentDealers { limit, start_after } => {
|
||||
to_binary(&query_current_dealers_paged(deps, start_after, limit)?)?
|
||||
}
|
||||
|
||||
@@ -23,9 +23,12 @@ pub enum DkgError {
|
||||
#[error("Failed to serialize message - {0}")]
|
||||
SerializationError(#[from] bincode::Error),
|
||||
|
||||
#[error("Failed to recover assigned node index")]
|
||||
NodeIndexRecoveryError,
|
||||
|
||||
#[error("todo")]
|
||||
MalformedDealerDetails,
|
||||
|
||||
|
||||
#[error("todo")]
|
||||
DeserializationError,
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ where
|
||||
.dkg_state
|
||||
.prepare_dealer_registration(chain_address, self.network_host.to_string());
|
||||
|
||||
if let Err(err) = self
|
||||
match self
|
||||
.contract_publisher
|
||||
.register_dealer(
|
||||
registration.identity,
|
||||
@@ -132,9 +132,14 @@ where
|
||||
)
|
||||
.await
|
||||
{
|
||||
error!("failed to register our dealer - {}", err)
|
||||
} else {
|
||||
info!("registered our dealer for this DKG round")
|
||||
Err(err) => error!("failed to register our dealer - {}", err),
|
||||
Ok(node_index) => {
|
||||
info!(
|
||||
"registered our dealer for this DKG round and got assigned index: {}",
|
||||
node_index
|
||||
);
|
||||
self.dkg_state.post_key_submission(node_index).await
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
use crate::dkg::error::DkgError;
|
||||
use crate::Client;
|
||||
use coconut_dkg_common::types::{EncodedBTEPublicKeyWithProof, EncodedEd25519PublicKey};
|
||||
use coconut_dkg_common::types::{EncodedBTEPublicKeyWithProof, EncodedEd25519PublicKey, NodeIndex};
|
||||
use validator_client::nymd::{AccountId, SigningCosmWasmClient};
|
||||
|
||||
pub(crate) struct Publisher<C> {
|
||||
@@ -28,11 +28,21 @@ where
|
||||
bte_key: EncodedBTEPublicKeyWithProof,
|
||||
owner_signature: String,
|
||||
listening_address: String,
|
||||
) -> Result<(), DkgError> {
|
||||
) -> Result<NodeIndex, DkgError> {
|
||||
self.client
|
||||
.register_dealer(identity, bte_key, owner_signature, listening_address)
|
||||
.await?;
|
||||
Ok(())
|
||||
|
||||
// once we figure out how to properly deserialize `data` field from the response use that
|
||||
// instead of this query
|
||||
let self_details = self.client.get_self_registered_dealer_details().await?;
|
||||
if let Some(details) = self_details.details {
|
||||
if self_details.dealer_type.is_current() {
|
||||
return Ok(details.assigned_index);
|
||||
}
|
||||
}
|
||||
|
||||
Err(DkgError::NodeIndexRecoveryError)
|
||||
}
|
||||
|
||||
pub(crate) async fn submit_dealing_commitment(&self) {
|
||||
|
||||
@@ -193,6 +193,12 @@ impl DkgState {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub(crate) async fn post_key_submission(&self, assigned_index: NodeIndex) {
|
||||
let mut guard = self.inner_state.lock().await;
|
||||
guard.submitted_keys = true;
|
||||
guard.assigned_index = assigned_index;
|
||||
}
|
||||
|
||||
pub(crate) async fn is_dealers_remote_address(&self, remote: SocketAddr) -> (bool, Epoch) {
|
||||
let guard = self.inner_state.lock().await;
|
||||
let epoch = guard.current_epoch;
|
||||
|
||||
@@ -5,6 +5,7 @@ use crate::config::Config;
|
||||
use crate::rewarded_set_updater::error::RewardingError;
|
||||
#[cfg(feature = "coconut")]
|
||||
use async_trait::async_trait;
|
||||
use coconut_dkg_common::dealer::DealerDetailsResponse;
|
||||
use coconut_dkg_common::types::{
|
||||
BlacklistedDealer, BlacklistingResponse, Coin, DealerDetails, EncodedBTEPublicKeyWithProof,
|
||||
EncodedEd25519PublicKey, Epoch as DkgEpoch,
|
||||
@@ -455,6 +456,18 @@ where
|
||||
self.0.read().await.nymd.get_current_dkg_epoch().await
|
||||
}
|
||||
|
||||
pub(crate) async fn get_self_registered_dealer_details(
|
||||
&self,
|
||||
) -> Result<DealerDetailsResponse, NymdError> {
|
||||
let self_address = &self.address().await;
|
||||
self.0
|
||||
.read()
|
||||
.await
|
||||
.nymd
|
||||
.get_dealer_details(self_address)
|
||||
.await
|
||||
}
|
||||
|
||||
pub(crate) async fn get_current_dealers(
|
||||
&self,
|
||||
) -> Result<Vec<DealerDetails>, ValidatorClientError> {
|
||||
|
||||
Reference in New Issue
Block a user