From 2f4fad3ce392fe16e2ad79127798e4251ae6cb7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Fri, 9 Feb 2024 11:36:15 +0000 Subject: [PATCH] [bugfix] remove hard failure on dkg contract queries in case it doesn't exist --- .../websocket/connection_handler/coconut.rs | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/gateway/src/node/client_handling/websocket/connection_handler/coconut.rs b/gateway/src/node/client_handling/websocket/connection_handler/coconut.rs index 58b32f7031..89711d31e7 100644 --- a/gateway/src/node/client_handling/websocket/connection_handler/coconut.rs +++ b/gateway/src/node/client_handling/websocket/connection_handler/coconut.rs @@ -6,7 +6,7 @@ use log::*; use nym_coconut_interface::{Credential, VerificationKey}; use nym_validator_client::coconut::all_coconut_api_clients; use nym_validator_client::nym_api::EpochId; -use nym_validator_client::nyxd::contract_traits::MultisigQueryClient; +use nym_validator_client::nyxd::contract_traits::{MultisigQueryClient, NymContractsProvider}; use nym_validator_client::nyxd::AccountId; use nym_validator_client::{ nyxd::{ @@ -42,8 +42,33 @@ impl CoconutVerifier { let mut master_keys = HashMap::new(); let mut api_clients = HashMap::new(); + // don't make it a hard failure in case we're running on mainnet (where DKG hasn't been deployed yet) + if nyxd_client.dkg_contract_address().is_none() { + error!( + "DKG contract address is not available - no coconut credentials will be redeemable" + ); + return Ok(CoconutVerifier { + address, + nyxd_client: RwLock::new(nyxd_client), + api_clients: Default::default(), + master_keys: Default::default(), + mix_denom_base, + }); + } + + let Ok(current_epoch) = nyxd_client.get_current_epoch().await else { + // another case of somebody putting a placeholder address that doesn't exist + error!("the specified DKG contract address is invalid - no coconut credentials will be redeemable"); + return Ok(CoconutVerifier { + address, + nyxd_client: RwLock::new(nyxd_client), + api_clients: Default::default(), + master_keys: Default::default(), + mix_denom_base, + }); + }; + // might as well obtain the key for the current epoch, if applicable - let current_epoch = nyxd_client.get_current_epoch().await?; if current_epoch.state.is_in_progress() { // note: even though we're constructing clients here, we will NOT be making any network requests let epoch_api_clients =