Recovering assigned node index
This commit is contained in:
@@ -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