Actually attempting to register dealer keys
This commit is contained in:
@@ -10,6 +10,8 @@ use coconut_dkg_common::types::{Addr, BlockHeight, DealerDetails};
|
||||
use futures::channel::mpsc;
|
||||
use futures::StreamExt;
|
||||
use log::{debug, info, trace};
|
||||
use std::net::SocketAddr;
|
||||
use validator_client::nymd::SigningCosmWasmClient;
|
||||
|
||||
// essentially events originating from the contract watcher could only drive our state forward
|
||||
// (TODO: is it actually true? I guess we'll find out soon enough)
|
||||
@@ -26,20 +28,28 @@ pub(crate) struct ProcessingLoop<C> {
|
||||
|
||||
contract_publisher: Publisher<C>,
|
||||
// network_sender: Sender
|
||||
|
||||
// TODO: this HAS to go away from here as it doesn't fit. but I've put it here temporarily to validate dealer registration
|
||||
network_host: SocketAddr,
|
||||
}
|
||||
|
||||
impl<C> ProcessingLoop<C> {
|
||||
impl<C> ProcessingLoop<C>
|
||||
where
|
||||
C: SigningCosmWasmClient + Send + Sync,
|
||||
{
|
||||
pub(crate) fn new(
|
||||
dkg_state: DkgState,
|
||||
dispatcher_sender: DispatcherSender,
|
||||
contract_events_receiver: ContractEventsReceiver,
|
||||
contract_publisher: Publisher<C>,
|
||||
network_host: SocketAddr,
|
||||
) -> Self {
|
||||
ProcessingLoop {
|
||||
dkg_state,
|
||||
dispatcher_sender,
|
||||
contract_events_receiver,
|
||||
contract_publisher,
|
||||
network_host,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +116,26 @@ impl<C> ProcessingLoop<C> {
|
||||
|
||||
async fn process_new_key_submission(&self, height: BlockHeight) {
|
||||
debug!("attempting to register our own dealer keys for this round of dkg");
|
||||
info!(".... but that's not implemented yet....");
|
||||
|
||||
let chain_address = self.contract_publisher.get_address().await;
|
||||
let registration = self
|
||||
.dkg_state
|
||||
.prepare_dealer_registration(chain_address, self.network_host.to_string());
|
||||
|
||||
if let Err(err) = self
|
||||
.contract_publisher
|
||||
.register_dealer(
|
||||
registration.identity,
|
||||
registration.bte_key,
|
||||
registration.owner_signature,
|
||||
registration.listening_address,
|
||||
)
|
||||
.await
|
||||
{
|
||||
error!("failed to register our dealer - {}", err)
|
||||
} else {
|
||||
info!("registered our dealer for this DKG round")
|
||||
}
|
||||
}
|
||||
|
||||
async fn process_dealer_changes(&self, changes: Vec<DealerChange>, height: BlockHeight) {
|
||||
|
||||
@@ -72,13 +72,14 @@ where
|
||||
config.contract_polling_interval,
|
||||
);
|
||||
let publisher = smart_contract::Publisher::new(nyxd_client);
|
||||
let mut net_listener = Listener::new(config.network_address, state_accessor);
|
||||
let mut net_listener = Listener::new(config.network_address.clone(), state_accessor);
|
||||
|
||||
let mut processing_loop = ProcessingLoop::new(
|
||||
state,
|
||||
dispatcher_sender,
|
||||
contracts_events_receiver,
|
||||
publisher,
|
||||
config.network_address,
|
||||
);
|
||||
|
||||
tokio::spawn(async move { event_dispatcher.run().await });
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::dkg::error::DkgError;
|
||||
use crate::Client;
|
||||
use validator_client::nymd::SigningCosmWasmClient;
|
||||
use coconut_dkg_common::types::{EncodedBTEPublicKeyWithProof, EncodedEd25519PublicKey};
|
||||
use validator_client::nymd::{AccountId, SigningCosmWasmClient};
|
||||
|
||||
pub(crate) struct Publisher<C> {
|
||||
client: Client<C>,
|
||||
@@ -16,6 +18,23 @@ where
|
||||
Publisher { client }
|
||||
}
|
||||
|
||||
pub(crate) async fn get_address(&self) -> AccountId {
|
||||
self.client.address().await
|
||||
}
|
||||
|
||||
pub(crate) async fn register_dealer(
|
||||
&self,
|
||||
identity: EncodedEd25519PublicKey,
|
||||
bte_key: EncodedBTEPublicKeyWithProof,
|
||||
owner_signature: String,
|
||||
listening_address: String,
|
||||
) -> Result<(), DkgError> {
|
||||
self.client
|
||||
.register_dealer(identity, bte_key, owner_signature, listening_address)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn submit_dealing_commitment(&self) {
|
||||
// self.client.submit_dealing_commitment().await;
|
||||
//
|
||||
|
||||
@@ -133,6 +133,9 @@ where
|
||||
.await;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// TODO: change to trace
|
||||
debug!("our dkg key is already registered in the dkg contract")
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::Client;
|
||||
use coconut_dkg_common::types::{Addr, BlockHeight, DealerDetails, Epoch, NodeIndex};
|
||||
use coconut_dkg_common::types::{
|
||||
Addr, BlockHeight, DealerDetails, EncodedBTEPublicKeyWithProof, EncodedEd25519PublicKey, Epoch,
|
||||
NodeIndex,
|
||||
};
|
||||
use crypto::asymmetric::identity;
|
||||
use dkg::{bte, Dealing};
|
||||
use futures::lock::Mutex;
|
||||
@@ -17,7 +20,7 @@ mod accessor;
|
||||
|
||||
use crate::dkg::error::DkgError;
|
||||
pub(crate) use accessor::StateAccessor;
|
||||
use validator_client::nymd::SigningCosmWasmClient;
|
||||
use validator_client::nymd::{AccountId, SigningCosmWasmClient};
|
||||
|
||||
type IdentityBytes = [u8; identity::PUBLIC_KEY_LENGTH];
|
||||
|
||||
@@ -99,6 +102,13 @@ pub struct ReceivedDealing {
|
||||
signature: identity::Signature,
|
||||
}
|
||||
|
||||
pub(crate) struct DealerRegistration {
|
||||
pub(crate) identity: EncodedEd25519PublicKey,
|
||||
pub(crate) bte_key: EncodedBTEPublicKeyWithProof,
|
||||
pub(crate) owner_signature: String,
|
||||
pub(crate) listening_address: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct DkgState {
|
||||
inner_state: Arc<Mutex<DkgStateInner>>,
|
||||
@@ -286,4 +296,26 @@ impl DkgState {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn prepare_dealer_registration(
|
||||
&self,
|
||||
chain_address: AccountId,
|
||||
listening_address: String,
|
||||
) -> DealerRegistration {
|
||||
let bte_key = bs58::encode(&self.keys.bte_public_key.to_bytes()).into_string();
|
||||
|
||||
// chain_address || host || bte_keys
|
||||
let mut plaintext = chain_address.to_string();
|
||||
plaintext.push_str(&listening_address);
|
||||
plaintext.push_str(&bte_key);
|
||||
|
||||
let owner_signature = self.keys.identity.private_key().sign_text(&plaintext);
|
||||
|
||||
DealerRegistration {
|
||||
identity: self.keys.identity.public_key().to_base58_string(),
|
||||
bte_key,
|
||||
owner_signature,
|
||||
listening_address,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,8 @@ use crate::rewarded_set_updater::error::RewardingError;
|
||||
#[cfg(feature = "coconut")]
|
||||
use async_trait::async_trait;
|
||||
use coconut_dkg_common::types::{
|
||||
BlacklistedDealer, BlacklistingResponse, DealerDetails, Epoch as DkgEpoch,
|
||||
BlacklistedDealer, BlacklistingResponse, Coin, DealerDetails, EncodedBTEPublicKeyWithProof,
|
||||
EncodedEd25519PublicKey, Epoch as DkgEpoch,
|
||||
};
|
||||
use config::defaults::{DEFAULT_NETWORK, DEFAULT_VALIDATOR_API_PORT};
|
||||
use mixnet_contract_common::Interval;
|
||||
@@ -479,6 +480,31 @@ where
|
||||
self.0.read().await.nymd.get_blacklisting(address).await
|
||||
}
|
||||
|
||||
pub(crate) async fn get_minimum_deposit(&self) -> Result<Coin, NymdError> {
|
||||
self.0
|
||||
.read()
|
||||
.await
|
||||
.nymd
|
||||
.get_deposit_amount()
|
||||
.await
|
||||
.map(|res| res.amount)
|
||||
}
|
||||
|
||||
pub(crate) async fn register_dealer(
|
||||
&self,
|
||||
identity: EncodedEd25519PublicKey,
|
||||
bte_key: EncodedBTEPublicKeyWithProof,
|
||||
owner_signature: String,
|
||||
listening_address: String,
|
||||
) -> Result<ExecuteResult, NymdError> {
|
||||
self.0
|
||||
.write()
|
||||
.await
|
||||
.nymd
|
||||
.register_dealer(identity, bte_key, owner_signature, listening_address, None)
|
||||
.await
|
||||
}
|
||||
|
||||
pub(crate) async fn submit_dealing_commitment(
|
||||
&self,
|
||||
epoch_id: u32,
|
||||
|
||||
Reference in New Issue
Block a user