Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a validator alias field to validator metadata #2911

Merged
merged 6 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changelog/unreleased/2911-validator-alias.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add a validator alias field to validator metadata
([\#2911](https://github.com/anoma/namada/pull/2911))
22 changes: 22 additions & 0 deletions crates/apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3259,6 +3259,7 @@ pub mod args {
pub const USE_DEVICE: ArgFlag = flag("use-device");
pub const VALIDATOR: Arg<WalletAddress> = arg("validator");
pub const VALIDATOR_OPT: ArgOpt<WalletAddress> = VALIDATOR.opt();
pub const VALIDATOR_ALIAS_OPT: ArgOpt<String> = arg_opt("validator-alias");
pub const VALIDATOR_ACCOUNT_KEY: ArgOpt<WalletPublicKey> =
arg_opt("account-key");
pub const VALIDATOR_ACCOUNT_KEYS: ArgMulti<WalletPublicKey, GlobStar> =
Expand Down Expand Up @@ -4347,6 +4348,7 @@ pub mod args {
website: self.website,
discord_handle: self.discord_handle,
avatar: self.avatar,
validator_alias: self.validator_alias,
unsafe_dont_encrypt: self.unsafe_dont_encrypt,
tx_code_path: self.tx_code_path.to_path_buf(),
}
Expand All @@ -4370,6 +4372,7 @@ pub mod args {
let website = WEBSITE_OPT.parse(matches);
let discord_handle = DISCORD_OPT.parse(matches);
let avatar = AVATAR_OPT.parse(matches);
let validator_alias = VALIDATOR_ALIAS_OPT.parse(matches);
let unsafe_dont_encrypt = UNSAFE_DONT_ENCRYPT.parse(matches);
let tx_code_path = PathBuf::from(TX_BECOME_VALIDATOR_WASM);
Self {
Expand All @@ -4387,6 +4390,7 @@ pub mod args {
website,
discord_handle,
avatar,
validator_alias,
unsafe_dont_encrypt,
tx_code_path,
}
Expand Down Expand Up @@ -4436,6 +4440,7 @@ pub mod args {
.arg(WEBSITE_OPT.def().help("The validator's website."))
.arg(DISCORD_OPT.def().help("The validator's discord handle."))
.arg(AVATAR_OPT.def().help("The validator's avatar."))
.arg(VALIDATOR_ALIAS_OPT.def().help("The validator's alias."))
.arg(VALIDATOR_CODE_PATH.def().help(
"The path to the validity predicate WASM code to be used \
for the validator account. Uses the default validator VP \
Expand Down Expand Up @@ -4472,6 +4477,7 @@ pub mod args {
website: self.website,
discord_handle: self.discord_handle,
avatar: self.avatar,
validator_alias: self.validator_alias,
validator_vp_code_path: self
.validator_vp_code_path
.to_path_buf(),
Expand Down Expand Up @@ -4503,6 +4509,7 @@ pub mod args {
let website = WEBSITE_OPT.parse(matches);
let discord_handle = DISCORD_OPT.parse(matches);
let avatar = AVATAR_OPT.parse(matches);
let validator_alias = VALIDATOR_ALIAS_OPT.parse(matches);
let validator_vp_code_path = VALIDATOR_CODE_PATH
.parse(matches)
.unwrap_or_else(|| PathBuf::from(VP_USER_WASM));
Expand All @@ -4527,6 +4534,7 @@ pub mod args {
website,
discord_handle,
avatar,
validator_alias,
validator_vp_code_path,
unsafe_dont_encrypt,
tx_init_account_code_path,
Expand Down Expand Up @@ -4580,6 +4588,7 @@ pub mod args {
.arg(WEBSITE_OPT.def().help("The validator's website."))
.arg(DISCORD_OPT.def().help("The validator's discord handle."))
.arg(AVATAR_OPT.def().help("The validator's avatar."))
.arg(VALIDATOR_ALIAS_OPT.def().help("The validator's alias."))
.arg(VALIDATOR_CODE_PATH.def().help(
"The path to the validity predicate WASM code to be used \
for the validator account. Uses the default validator VP \
Expand Down Expand Up @@ -5587,6 +5596,7 @@ pub mod args {
website: self.website,
discord_handle: self.discord_handle,
avatar: self.avatar,
validator_alias: self.validator_alias,
commission_rate: self.commission_rate,
tx_code_path: self.tx_code_path.to_path_buf(),
}
Expand All @@ -5602,6 +5612,7 @@ pub mod args {
let website = WEBSITE_OPT.parse(matches);
let discord_handle = DISCORD_OPT.parse(matches);
let avatar = AVATAR_OPT.parse(matches);
let validator_alias = VALIDATOR_ALIAS_OPT.parse(matches);
let commission_rate = COMMISSION_RATE_OPT.parse(matches);
let tx_code_path = PathBuf::from(TX_CHANGE_METADATA_WASM);
Self {
Expand All @@ -5612,6 +5623,7 @@ pub mod args {
website,
discord_handle,
avatar,
validator_alias,
commission_rate,
tx_code_path,
}
Expand Down Expand Up @@ -5644,6 +5656,10 @@ pub mod args {
"The desired new validator avatar url. To remove the \
existing avatar, pass an empty string to this argument.",
))
.arg(VALIDATOR_ALIAS_OPT.def().help(
"The desired new validator alias. To remove the existing \
validator alias, pass an empty string to this argument.",
))
.arg(
COMMISSION_RATE_OPT
.def()
Expand Down Expand Up @@ -7182,6 +7198,7 @@ pub mod args {
pub website: Option<String>,
pub discord_handle: Option<String>,
pub avatar: Option<String>,
pub validator_alias: Option<String>,
pub address: EstablishedAddress,
pub tx_path: PathBuf,
}
Expand All @@ -7202,6 +7219,7 @@ pub mod args {
let website = WEBSITE_OPT.parse(matches);
let discord_handle = DISCORD_OPT.parse(matches);
let avatar = AVATAR_OPT.parse(matches);
let validator_alias = VALIDATOR_ALIAS_OPT.parse(matches);
let address = RAW_ADDRESS_ESTABLISHED.parse(matches);
let tx_path = PATH.parse(matches);
Self {
Expand All @@ -7217,6 +7235,7 @@ pub mod args {
website,
discord_handle,
avatar,
validator_alias,
tx_path,
address,
}
Expand Down Expand Up @@ -7277,6 +7296,9 @@ pub mod args {
.arg(AVATAR_OPT.def().help(
"The validator's avatar. This is an optional parameter.",
))
.arg(VALIDATOR_ALIAS_OPT.def().help(
"The validator's alias. This is an optional parameter.",
))
}
}

Expand Down
10 changes: 10 additions & 0 deletions crates/apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2003,6 +2003,7 @@ pub async fn query_and_print_metadata(
website,
discord_handle,
avatar,
validator_alias,
}) => {
display_line!(
context.io(),
Expand Down Expand Up @@ -2034,6 +2035,15 @@ pub async fn query_and_print_metadata(
} else {
display_line!(context.io(), "No avatar");
}
if let Some(validator_alias) = validator_alias {
display_line!(
context.io(),
"Validator alias: {}",
validator_alias
);
} else {
display_line!(context.io(), "No validator alias");
}
}
None => display_line!(
context.io(),
Expand Down
2 changes: 2 additions & 0 deletions crates/apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ pub async fn submit_init_validator(
description,
discord_handle,
avatar,
validator_alias,
validator_vp_code_path,
unsafe_dont_encrypt,
tx_init_account_code_path,
Expand Down Expand Up @@ -729,6 +730,7 @@ pub async fn submit_init_validator(
website,
discord_handle,
avatar,
validator_alias,
tx_code_path: tx_become_validator_code_path,
unsafe_dont_encrypt,
},
Expand Down
2 changes: 2 additions & 0 deletions crates/apps/src/lib/client/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@ pub fn init_genesis_validator(
website,
discord_handle,
avatar,
validator_alias,
tx_path,
address,
}: args::InitGenesisValidator,
Expand Down Expand Up @@ -888,6 +889,7 @@ pub fn init_genesis_validator(
website,
discord_handle,
avatar,
validator_alias,
},
&validator_wallet,
);
Expand Down
1 change: 1 addition & 0 deletions crates/apps/src/lib/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ pub fn make_dev_genesis(
website: None,
discord_handle: None,
avatar: None,
validator_alias: None,
},
net_address: SocketAddr::new(
IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)),
Expand Down
4 changes: 4 additions & 0 deletions crates/apps/src/lib/config/genesis/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ pub struct GenesisValidatorData {
pub website: Option<String>,
pub discord_handle: Option<String>,
pub avatar: Option<String>,
pub validator_alias: Option<String>,
}

/// Panics if given `txs.validator_accounts` is not empty, because validator
Expand Down Expand Up @@ -285,6 +286,7 @@ pub fn init_validator(
website,
discord_handle,
avatar,
validator_alias,
}: GenesisValidatorData,
validator_wallet: &ValidatorWallet,
) -> (Address, UnsignedTransactions) {
Expand Down Expand Up @@ -319,6 +321,7 @@ pub fn init_validator(
website,
discord_handle,
avatar,
validator_alias,
},
};
let unsigned_validator_addr =
Expand Down Expand Up @@ -631,6 +634,7 @@ impl TxToSign for ValidatorAccountTx<SignedPk> {
website: self.metadata.website.clone(),
discord_handle: self.metadata.discord_handle.clone(),
avatar: self.metadata.avatar.clone(),
validator_alias: self.metadata.validator_alias.clone(),
},
)
}
Expand Down
2 changes: 2 additions & 0 deletions crates/benches/txs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ fn become_validator(c: &mut Criterion) {
website: None,
discord_handle: None,
avatar: None,
validator_alias: None,
};
let tx = shell.generate_tx(
TX_BECOME_VALIDATOR_WASM,
Expand Down Expand Up @@ -719,6 +720,7 @@ fn change_validator_metadata(c: &mut Criterion) {
website: None,
discord_handle: None,
avatar: None,
validator_alias: None,
commission_rate: None,
};

Expand Down
4 changes: 4 additions & 0 deletions crates/light_sdk/src/transaction/pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ impl BecomeValidator {
website: Option<String>,
discord_handle: Option<String>,
avatar: Option<String>,
validator_alias: Option<String>,
args: GlobalArgs,
) -> Self {
let update_account = namada_sdk::tx::data::pos::BecomeValidator {
Expand All @@ -171,6 +172,7 @@ impl BecomeValidator {
website,
discord_handle,
avatar,
validator_alias,
};

Self(transaction::build_tx(
Expand Down Expand Up @@ -464,6 +466,7 @@ impl ChangeMetaData {
website: Option<String>,
discord_handle: Option<String>,
avatar: Option<String>,
validator_alias: Option<String>,
commission_rate: Option<Dec>,
args: GlobalArgs,
) -> Self {
Expand All @@ -474,6 +477,7 @@ impl ChangeMetaData {
website,
discord_handle,
avatar,
validator_alias,
commission_rate,
};

Expand Down
5 changes: 5 additions & 0 deletions crates/proof_of_stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use namada_storage::collections::lazy_map::{self, Collectable, LazyMap};
use namada_storage::{StorageRead, StorageWrite};
pub use namada_trans_token as token;
pub use parameters::{OwnedPosParams, PosParams};
use storage::write_validator_alias;
use types::{into_tm_voting_power, DelegationEpochs};

use crate::queries::{find_bonds, has_bonds};
Expand Down Expand Up @@ -2679,6 +2680,7 @@ pub fn change_validator_metadata<S>(
website: Option<String>,
discord_handle: Option<String>,
avatar: Option<String>,
validator_alias: Option<String>,
commission_rate: Option<Dec>,
current_epoch: Epoch,
) -> namada_storage::Result<()>
Expand All @@ -2700,6 +2702,9 @@ where
if let Some(avatar) = avatar {
write_validator_avatar(storage, validator, &avatar)?;
}
if let Some(validator_alias) = validator_alias {
write_validator_alias(storage, validator, &validator_alias)?;
}
if let Some(commission_rate) = commission_rate {
change_validator_commission_rate(
storage,
Expand Down
31 changes: 31 additions & 0 deletions crates/proof_of_stake/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,34 @@ where
}
}

/// Read PoS validator's alias.
pub fn read_validator_alias<S>(
storage: &S,
validator: &Address,
) -> namada_storage::Result<Option<String>>
where
S: StorageRead,
{
storage.read(&storage_key::validator_alias_key(validator))
}

/// Write PoS validator's alias. If the provided arg is an empty
/// string, remove the data.
pub fn write_validator_alias<S>(
storage: &mut S,
validator: &Address,
validator_alias: &String,
) -> namada_storage::Result<()>
where
S: StorageRead + StorageWrite,
{
let key = storage_key::validator_alias_key(validator);
if validator_alias.is_empty() {
storage.delete(&key)
} else {
storage.write(&key, validator_alias)
}
}
/// Write validator's metadata.
pub fn write_validator_metadata<S>(
storage: &mut S,
Expand All @@ -905,6 +933,9 @@ where
if let Some(avatar) = metadata.avatar.as_ref() {
write_validator_avatar(storage, validator, avatar)?;
}
if let Some(validator_alias) = metadata.validator_alias.as_ref() {
write_validator_alias(storage, validator, validator_alias)?;
}
Ok(())
}

Expand Down
9 changes: 9 additions & 0 deletions crates/proof_of_stake/src/storage_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const VALIDATOR_DESCRIPTION_KEY: &str = "description";
const VALIDATOR_WEBSITE_KEY: &str = "website";
const VALIDATOR_DISCORD_KEY: &str = "discord_handle";
const VALIDATOR_AVATAR_KEY: &str = "avatar";
const VALIDATOR_ALIAS_KEY: &str = "validator_alias";
const LIVENESS_PREFIX: &str = "liveness";
const LIVENESS_MISSED_VOTES: &str = "missed_votes";
const LIVENESS_MISSED_VOTES_SUM: &str = "sum_missed_votes";
Expand Down Expand Up @@ -277,6 +278,7 @@ pub fn is_validator_metadata_key(key: &Key) -> Option<&Address> {
| VALIDATOR_WEBSITE_KEY
| VALIDATOR_DISCORD_KEY
| VALIDATOR_AVATAR_KEY
| VALIDATOR_ALIAS_KEY
) =>
{
Some(validator)
Expand Down Expand Up @@ -1028,6 +1030,13 @@ pub fn validator_avatar_key(validator: &Address) -> Key {
.expect("Cannot obtain a storage key")
}

/// Storage key for a validator's alias
pub fn validator_alias_key(validator: &Address) -> Key {
validator_prefix(validator)
.push(&VALIDATOR_ALIAS_KEY.to_owned())
.expect("Cannot obtain a storage key")
}

/// Storage prefix for the liveness data of the cosnensus validator set.
pub fn liveness_data_prefix() -> Key {
Key::from(ADDRESS.to_db_key())
Expand Down
Loading
Loading