Skip to content

Commit

Permalink
prevent removal of validator email in client
Browse files Browse the repository at this point in the history
  • Loading branch information
brentstone committed Oct 25, 2023
1 parent 9d099b9 commit 45f547c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions sdk/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
18 changes: 17 additions & 1 deletion sdk/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;

Expand Down

0 comments on commit 45f547c

Please sign in to comment.