From 45f547ce18acc9723383de37b42d8318fbbad9ea Mon Sep 17 00:00:00 2001 From: brentstone Date: Wed, 25 Oct 2023 15:44:02 -0400 Subject: [PATCH] prevent removal of validator email in client --- sdk/src/error.rs | 3 +++ sdk/src/tx.rs | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/sdk/src/error.rs b/sdk/src/error.rs index 9f84195cc21..9d3ecc18467 100644 --- a/sdk/src/error.rs +++ b/sdk/src/error.rs @@ -310,6 +310,9 @@ pub enum TxError { still subject to possible slashing" )] IncomingRedelIsStillSlashable(Address, Address), + /// An empty string was provided as a new email + #[error("An empty string cannot be provided as a new email")] + InvalidEmail, /// Other Errors that may show up when using the interface #[error("{0}")] Other(String), diff --git a/sdk/src/tx.rs b/sdk/src/tx.rs index 87b6611f44d..2c786505c08 100644 --- a/sdk/src/tx.rs +++ b/sdk/src/tx.rs @@ -640,6 +640,20 @@ pub async fn build_validator_metadata_change<'a>( known_validator_or_err(validator.clone(), tx_args.force, context) .await?; + // If there is a new email, it cannot be an empty string that indicates to + // remove the data (email data cannot be removed) + if let Some(email) = email.as_ref() { + if email.is_empty() { + edisplay_line!( + context.io(), + "Cannot remove a validator's email, which was implied by the \ + string {}", + email + ); + return Err(Error::from(TxError::InvalidEmail)); + } + } + // If there's a new commission rate, it must be valid if let Some(rate) = commission_rate.as_ref() { if *rate < Dec::zero() || *rate > Dec::one() { @@ -648,7 +662,9 @@ pub async fn build_validator_metadata_change<'a>( "Invalid new commission rate, received {}", rate ); - return Err(Error::from(TxError::InvalidCommissionRate(*rate))); + if !tx_args.force { + return Err(Error::from(TxError::InvalidCommissionRate(*rate))); + } } let pipeline_epoch_minus_one = epoch + params.pipeline_len - 1;