Skip to content

Commit

Permalink
update with new genesis + remove alias
Browse files Browse the repository at this point in the history
  • Loading branch information
brentstone committed Nov 6, 2023
1 parent 4577f70 commit 2e38800
Show file tree
Hide file tree
Showing 23 changed files with 161 additions and 96 deletions.
49 changes: 35 additions & 14 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2851,7 +2851,6 @@ pub mod args {
pub const MAX_ETH_GAS: ArgOpt<u64> = arg_opt("max_eth-gas");
pub const MODE: ArgOpt<String> = arg_opt("mode");
pub const NET_ADDRESS: Arg<SocketAddr> = arg("net-address");
pub const NEW_ALIAS: ArgOpt<String> = arg_opt("new-alias");
pub const NAMADA_START_TIME: ArgOpt<DateTimeUtc> = arg_opt("time");
pub const NO_CONVERSIONS: ArgFlag = flag("no-conversions");
pub const NUT: ArgFlag = flag("nut");
Expand Down Expand Up @@ -3900,6 +3899,10 @@ pub mod args {
.map(|x| chain_ctx.get_cached(&x)),
commission_rate: self.commission_rate,
max_commission_rate_change: self.max_commission_rate_change,
email: self.email,
description: self.description,
website: self.website,
discord_handle: self.discord_handle,
validator_vp_code_path: self
.validator_vp_code_path
.to_path_buf(),
Expand All @@ -3921,6 +3924,10 @@ pub mod args {
let commission_rate = COMMISSION_RATE.parse(matches);
let max_commission_rate_change =
MAX_COMMISSION_RATE_CHANGE.parse(matches);
let email = EMAIL.parse(matches);
let description = DESCRIPTION_OPT.parse(matches);
let website = WEBSITE_OPT.parse(matches);
let discord_handle = DISCORD_OPT.parse(matches);
let validator_vp_code_path = VALIDATOR_CODE_PATH
.parse(matches)
.unwrap_or_else(|| PathBuf::from(VP_USER_WASM));
Expand All @@ -3938,6 +3945,10 @@ pub mod args {
protocol_key,
commission_rate,
max_commission_rate_change,
email,
description,
website,
discord_handle,
validator_vp_code_path,
unsafe_dont_encrypt,
tx_code_path,
Expand Down Expand Up @@ -3985,6 +3996,24 @@ pub mod args {
Expressed as a decimal between 0 and 1. This is a \
required parameter.",
))
.arg(EMAIL_OPT.def().help(
"The desired new validator email. To remove the existing \
email, pass an empty string to this argument.",
))
.arg(DESCRIPTION_OPT.def().help(
"The desired new validator description. To remove the \
existing description, pass an empty string to this \
argument.",
))
.arg(WEBSITE_OPT.def().help(
"The desired new validator website. To remove the \
existing website, pass an empty string to this argument.",
))
.arg(DISCORD_OPT.def().help(
"The desired new validator discord handle. To remove the \
existing discord handle, pass an empty string to this \
argument.",
))
.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 @@ -4960,11 +4989,10 @@ pub mod args {
fn to_sdk(self, ctx: &mut Context) -> MetaDataChange<SdkTypes> {
MetaDataChange::<SdkTypes> {
tx: self.tx.to_sdk(ctx),
validator: ctx.get(&self.validator),
validator: ctx.borrow_chain_or_exit().get(&self.validator),
email: self.email,
description: self.description,
website: self.website,
alias: self.alias,
discord_handle: self.discord_handle,
commission_rate: self.commission_rate,
tx_code_path: self.tx_code_path.to_path_buf(),
Expand All @@ -4979,7 +5007,6 @@ pub mod args {
let email = EMAIL_OPT.parse(matches);
let description = DESCRIPTION_OPT.parse(matches);
let website = WEBSITE_OPT.parse(matches);
let alias = NEW_ALIAS.parse(matches);
let discord_handle = DISCORD_OPT.parse(matches);
let commission_rate = COMMISSION_RATE_OPT.parse(matches);
let tx_code_path = PathBuf::from(TX_CHANGE_METADATA_WASM);
Expand All @@ -4989,7 +5016,6 @@ pub mod args {
email,
description,
website,
alias,
discord_handle,
commission_rate,
tx_code_path,
Expand All @@ -5014,10 +5040,6 @@ pub mod args {
"The desired new validator website. To remove the \
existing website, pass an empty string to this argument.",
))
.arg(NEW_ALIAS.def().help(
"The desired new validator alias. To remove the existing \
website, pass an empty string to this argument.",
))
.arg(DISCORD_OPT.def().help(
"The desired new validator discord handle. To remove the \
existing discord handle, pass an empty string to this \
Expand Down Expand Up @@ -5195,7 +5217,7 @@ pub mod args {
fn to_sdk(self, ctx: &mut Context) -> QueryMetaData<SdkTypes> {
QueryMetaData::<SdkTypes> {
query: self.query.to_sdk(ctx),
validator: ctx.get(&self.validator),
validator: ctx.borrow_chain_or_exit().get(&self.validator),
}
}
}
Expand Down Expand Up @@ -6343,18 +6365,17 @@ pub mod args {
)
.arg(EMAIL.def().help(
"The email address of the validator. This is a required \
parameter.",
parameter.",
))
.arg(DESCRIPTION_OPT.def().help(
"The validator's description. This is an optional \
parameter.",
"The validator's description. This is an optional parameter.",
))
.arg(WEBSITE_OPT.def().help(
"The validator's website. This is an optional parameter.",
))
.arg(DISCORD_OPT.def().help(
"The validator's discord handle. This is an optional \
parameter.",
parameter.",
))
}
}
Expand Down
6 changes: 0 additions & 6 deletions apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1970,7 +1970,6 @@ pub async fn query_and_print_metadata<'a>(
email,
description,
website,
alias,
discord_handle,
}) => {
display_line!(
Expand All @@ -1989,11 +1988,6 @@ pub async fn query_and_print_metadata<'a>(
} else {
display_line!(context.io(), "No website");
}
if let Some(alias) = alias {
display_line!(context.io(), "Alias: {}", alias);
} else {
display_line!(context.io(), "No alias");
}
if let Some(discord_handle) = discord_handle {
display_line!(
context.io(),
Expand Down
19 changes: 19 additions & 0 deletions apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ pub async fn submit_init_validator<'a>(
protocol_key,
commission_rate,
max_commission_rate_change,
email,
website,
description,
discord_handle,
validator_vp_code_path,
unsafe_dont_encrypt,
tx_code_path: _,
Expand Down Expand Up @@ -368,6 +372,17 @@ pub async fn submit_init_validator<'a>(
safe_exit(1)
}
}
// Validate the email
if email.is_empty() {
edisplay_line!(
namada.io(),
"The validator email must not be an empty string"
);
if !tx_args.force {
safe_exit(1)
}
}

let tx_code_hash =
query_wasm_code_hash(namada, args::TX_INIT_VALIDATOR_WASM)
.await
Expand All @@ -390,6 +405,10 @@ pub async fn submit_init_validator<'a>(
dkg_key,
commission_rate,
max_commission_rate_change,
email,
description,
website,
discord_handle,
validator_vp_code_hash: extra_section_hash,
};

Expand Down
11 changes: 8 additions & 3 deletions apps/src/lib/client/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,11 @@ pub fn init_genesis_validator(
);
safe_exit(1)
}
// Validate the email
if email.is_empty() {
eprintln!("The validator email must not be an empty string");
safe_exit(1)
}
let pre_genesis_dir =
validator_pre_genesis_dir(&global_args.base_dir, &alias);
println!("Generating validator keys...");
Expand Down Expand Up @@ -666,9 +671,9 @@ pub fn init_genesis_validator(
transfer_from_source_amount,
self_bond_amount,
email,
description,
website,
discord_handle,
description,
website,
discord_handle,
},
&mut source_wallet,
&validator_wallet,
Expand Down
5 changes: 4 additions & 1 deletion apps/src/lib/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use namada::types::key::*;
use namada::types::time::{DateTimeUtc, DurationSecs};
use namada::types::token::Denomination;
use namada::types::{storage, token};
use namada_sdk::proof_of_stake::types::ValidatorMetaData;
use serde::{Deserialize, Serialize};

#[cfg(all(any(test, feature = "benches"), not(feature = "integration")))]
Expand Down Expand Up @@ -392,6 +391,10 @@ pub fn make_dev_genesis(
commission_rate: Dec::new(5, 2).expect("This can't fail"),
max_commission_rate_change: Dec::new(1, 2)
.expect("This can't fail"),
email: "[email protected]".to_string(),
description: None,
website: None,
discord_handle: None,
net_address: SocketAddr::new(
IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)),
8080,
Expand Down
33 changes: 33 additions & 0 deletions apps/src/lib/config/genesis/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ pub struct GenesisValidatorData {
pub net_address: SocketAddr,
pub transfer_from_source_amount: token::DenominatedAmount,
pub self_bond_amount: token::DenominatedAmount,
pub email: String,
pub description: Option<String>,
pub website: Option<String>,
pub discord_handle: Option<String>,
}

/// Panics if given `txs.validator_accounts` is not empty, because validator
Expand Down Expand Up @@ -120,6 +124,10 @@ pub fn init_validator(
net_address,
transfer_from_source_amount,
self_bond_amount,
email,
description,
website,
discord_handle,
}: GenesisValidatorData,
source_wallet: &mut Wallet<CliWalletUtils>,
validator_wallet: &ValidatorWallet,
Expand Down Expand Up @@ -158,6 +166,10 @@ pub fn init_validator(
vp: "vp_validator".to_string(),
commission_rate,
max_commission_rate_change,
email,
description,
website,
discord_handle,
net_address,
};
let validator_account = Some(vec![sign_validator_account_tx(
Expand Down Expand Up @@ -256,6 +268,10 @@ pub fn sign_validator_account_tx(
vp,
commission_rate,
max_commission_rate_change,
email,
description,
website,
discord_handle,
net_address,
eth_hot_key,
eth_cold_key,
Expand Down Expand Up @@ -298,6 +314,10 @@ pub fn sign_validator_account_tx(
vp,
commission_rate,
max_commission_rate_change,
email,
description,
website,
discord_handle,
net_address,
eth_hot_key,
eth_cold_key,
Expand Down Expand Up @@ -554,6 +574,11 @@ pub struct ValidatorAccountTx<PK> {
pub commission_rate: Dec,
/// Maximum change in commission rate permitted per epoch
pub max_commission_rate_change: Dec,
/// Validator metadata
pub email: String,
pub description: Option<String>,
pub website: Option<String>,
pub discord_handle: Option<String>,
/// P2P IP:port
pub net_address: SocketAddr,
/// PKs have to come last in TOML to avoid `ValueAfterTable` error
Expand Down Expand Up @@ -1443,6 +1468,10 @@ impl From<&SignedValidatorAccountTx> for UnsignedValidatorAccountTx {
vp,
commission_rate,
max_commission_rate_change,
email,
description,
website,
discord_handle,
net_address,
account_key,
consensus_key,
Expand All @@ -1458,6 +1487,10 @@ impl From<&SignedValidatorAccountTx> for UnsignedValidatorAccountTx {
vp: vp.clone(),
commission_rate: *commission_rate,
max_commission_rate_change: *max_commission_rate_change,
email: email.clone(),
description: description.clone(),
website: website.clone(),
discord_handle: discord_handle.clone(),
net_address: *net_address,
account_key: account_key.pk.clone(),
consensus_key: consensus_key.pk.clone(),
Expand Down
11 changes: 11 additions & 0 deletions apps/src/lib/node/ledger/shell/init_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use namada::types::storage::KeySeg;
use namada::types::time::{DateTimeUtc, TimeZone, Utc};
use namada::vm::validate_untrusted_wasm;
use namada_sdk::eth_bridge::EthBridgeStatus;
use namada_sdk::proof_of_stake::types::ValidatorMetaData;
use namada_sdk::proof_of_stake::PosParams;

use super::*;
Expand Down Expand Up @@ -416,6 +417,10 @@ where
dkg_key,
commission_rate,
max_commission_rate_change,
email,
description,
website,
discord_handle,
net_address: _,
account_key,
consensus_key,
Expand Down Expand Up @@ -468,6 +473,12 @@ where
current_epoch,
commission_rate: *commission_rate,
max_commission_rate_change: *max_commission_rate_change,
metadata: ValidatorMetaData {
email: email.clone(),
description: description.clone(),
website: website.clone(),
discord_handle: discord_handle.clone(),
},
offset_opt: Some(0),
},
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ mod test_bp_vote_extensions {
current_epoch: 0.into(),
commission_rate: Default::default(),
max_commission_rate_change: Default::default(),
metadata: Default::default(),
offset_opt: None,
})
.expect("Test failed");
Expand Down
5 changes: 4 additions & 1 deletion benches/txs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,10 @@ fn init_validator(c: &mut Criterion) {
dkg_key,
commission_rate: namada::types::dec::Dec::default(),
max_commission_rate_change: namada::types::dec::Dec::default(),
email: "[email protected]".to_string(),
description: None,
website: None,
discord_handle: None,
validator_vp_code_hash: extra_hash,
};
let tx = generate_tx(
Expand Down Expand Up @@ -664,7 +668,6 @@ fn change_validator_metadata(c: &mut Criterion) {
email: None,
description: Some("I will change this piece of data".to_string()),
website: None,
alias: None,
discord_handle: None,
commission_rate: None,
};
Expand Down
Loading

0 comments on commit 2e38800

Please sign in to comment.