From 0d20bc5e14bd2495d8c6a71d85e695c2dcd439ee Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Tue, 3 Sep 2019 10:38:12 -0700 Subject: [PATCH] Move solana-validator-info into cli (#5768) * Move solana-validator-info into cli * Remove solana-validator-info and update docs * Update test to use app() --- Cargo.lock | 19 +- Cargo.toml | 1 - book/src/validator-info.md | 8 +- book/src/validator-testnet.md | 4 +- cli/Cargo.toml | 2 + cli/src/input_validators.rs | 36 ++ cli/src/lib.rs | 2 + cli/src/main.rs | 23 +- cli/src/validator_info.rs | 434 +++++++++++++++++++++ cli/src/wallet.rs | 140 +++++-- net/remote/remote-node.sh | 4 +- scripts/cargo-install-all.sh | 1 - validator-info/.gitignore | 2 - validator-info/Cargo.toml | 30 -- validator-info/src/validator_info.rs | 560 --------------------------- 15 files changed, 595 insertions(+), 671 deletions(-) create mode 100644 cli/src/input_validators.rs create mode 100644 cli/src/validator_info.rs delete mode 100644 validator-info/.gitignore delete mode 100644 validator-info/Cargo.toml delete mode 100644 validator-info/src/validator_info.rs diff --git a/Cargo.lock b/Cargo.lock index 14324e3cb3..17ceff1185 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3199,6 +3199,7 @@ dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "pretty-hex 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "reqwest 0.9.20 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3206,6 +3207,7 @@ dependencies = [ "solana-budget-api 0.19.0-pre0", "solana-budget-program 0.19.0-pre0", "solana-client 0.19.0-pre0", + "solana-config-api 0.19.0-pre0", "solana-core 0.19.0-pre0", "solana-drone 0.19.0-pre0", "solana-logger 0.19.0-pre0", @@ -3898,23 +3900,6 @@ dependencies = [ "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "solana-validator-info" -version = "0.19.0-pre0" -dependencies = [ - "bincode 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", - "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "reqwest 0.9.20 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", - "solana-client 0.19.0-pre0", - "solana-config-api 0.19.0-pre0", - "solana-sdk 0.19.0-pre0", - "url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "solana-vote-api" version = "0.19.0-pre0" diff --git a/Cargo.toml b/Cargo.toml index b7d34558c6..305ad582a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,7 +50,6 @@ members = [ "sdk", "sdk-c", "upload-perf", - "validator-info", "netutil", "fixed-buf", "vote-signer", diff --git a/book/src/validator-info.md b/book/src/validator-info.md index ccc6245681..dd74827d19 100644 --- a/book/src/validator-info.md +++ b/book/src/validator-info.md @@ -3,10 +3,10 @@ You can publish your validator information to the chain to be publicly visible to other users. -## Run solana-validator-info -Run the solana-validator-info CLI to populate a validator-info account: +## Run solana validator-info +Run the solana CLI to populate a validator-info account: ```bash -$ solana-validator-info publish ~/validator-keypair.json +$ solana validator-info publish ~/validator-keypair.json ``` Optional fields for VALIDATOR_INFO_ARGS: * Website @@ -27,5 +27,5 @@ Keybase: a `solana` subdirectory in your public folder: `/keybase/public//solana` * To check your pubkey, ensure you can successfully browse to `https://keybase.pub//solana/validator-` -3. Add or update your `solana-validator-info` with your Keybase username. The +3. Add or update your `solana validator-info` with your Keybase username. The CLI will verify the `validator-` file diff --git a/book/src/validator-testnet.md b/book/src/validator-testnet.md index 097787490c..8cccc93911 100644 --- a/book/src/validator-testnet.md +++ b/book/src/validator-testnet.md @@ -42,9 +42,7 @@ $ solana-install init 0.18.0 If you are downloading pre-compiled binaries or building from source, simply choose the release matching your desired testnet. ### Validator Commands -Solana CLI tools like solana and solana-validator-info point at -testnet.solana.com by default. Include a `--url` argument to point at a -different testnet. For instance: +The Solana CLI tool points at testnet.solana.com by default. Include a `--url` argument to point at a different testnet. For instance: ```bash $ solana --url http://beta.testnet.solana.com:8899 balance ``` diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 33a3c6a878..1c288cc327 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -21,12 +21,14 @@ lazy_static = "1.4.0" log = "0.4.8" num-traits = "0.2" pretty-hex = "0.1.0" +reqwest = "0.9.20" serde = "1.0.99" serde_derive = "1.0.99" serde_json = "1.0.40" serde_yaml = "0.8.9" solana-budget-api = { path = "../programs/budget_api", version = "0.19.0-pre0" } solana-client = { path = "../client", version = "0.19.0-pre0" } +solana-config-api = { path = "../programs/config_api", version = "0.19.0-pre0" } solana-drone = { path = "../drone", version = "0.19.0-pre0" } solana-logger = { path = "../logger", version = "0.19.0-pre0" } solana-netutil = { path = "../netutil", version = "0.19.0-pre0" } diff --git a/cli/src/input_validators.rs b/cli/src/input_validators.rs new file mode 100644 index 0000000000..cca7c76b50 --- /dev/null +++ b/cli/src/input_validators.rs @@ -0,0 +1,36 @@ +use solana_sdk::pubkey::Pubkey; +use solana_sdk::signature::read_keypair; + +// Return an error if a pubkey cannot be parsed. +pub fn is_pubkey(string: String) -> Result<(), String> { + match string.parse::() { + Ok(_) => Ok(()), + Err(err) => Err(format!("{:?}", err)), + } +} + +// Return an error if a keypair file cannot be parsed. +pub fn is_keypair(string: String) -> Result<(), String> { + read_keypair(&string) + .map(|_| ()) + .map_err(|err| format!("{:?}", err)) +} + +// Return an error if string cannot be parsed as pubkey string or keypair file location +pub fn is_pubkey_or_keypair(string: String) -> Result<(), String> { + is_pubkey(string.clone()).or_else(|_| is_keypair(string)) +} + +// Return an error if a url cannot be parsed. +pub fn is_url(string: String) -> Result<(), String> { + match url::Url::parse(&string) { + Ok(url) => { + if url.has_host() { + Ok(()) + } else { + Err("no host provided".to_string()) + } + } + Err(err) => Err(format!("{:?}", err)), + } +} diff --git a/cli/src/lib.rs b/cli/src/lib.rs index fc2cecae67..b7bf1f31e9 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -3,4 +3,6 @@ extern crate lazy_static; pub mod config; pub mod display; +pub mod input_validators; +pub mod validator_info; pub mod wallet; diff --git a/cli/src/main.rs b/cli/src/main.rs index 569b180556..2c7f5b9f9f 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,8 +1,11 @@ use clap::{crate_description, crate_name, crate_version, Arg, ArgGroup, ArgMatches, SubCommand}; use console::style; -use solana_cli::config::{self, Config}; -use solana_cli::display::println_name_value; -use solana_cli::wallet::{app, parse_command, process_command, WalletConfig, WalletError}; +use solana_cli::{ + config::{self, Config}, + display::println_name_value, + input_validators::is_url, + wallet::{app, parse_command, process_command, WalletConfig, WalletError}, +}; use solana_sdk::signature::{gen_keypair_file, read_keypair, KeypairUtil}; use std::error; @@ -104,20 +107,6 @@ pub fn parse_args(matches: &ArgMatches<'_>) -> Result Result<(), String> { - match url::Url::parse(&string) { - Ok(url) => { - if url.has_host() { - Ok(()) - } else { - Err("no host provided".to_string()) - } - } - Err(err) => Err(format!("{:?}", err)), - } -} - fn main() -> Result<(), Box> { solana_logger::setup(); let matches = app(crate_name!(), crate_description!(), crate_version!()) diff --git a/cli/src/validator_info.rs b/cli/src/validator_info.rs new file mode 100644 index 0000000000..d793bf0ab4 --- /dev/null +++ b/cli/src/validator_info.rs @@ -0,0 +1,434 @@ +use crate::{ + input_validators::is_url, + wallet::{check_account_for_fee, ProcessResult, WalletCommand, WalletConfig, WalletError}, +}; +use bincode::deserialize; +use clap::ArgMatches; +use reqwest::Client; +use serde_derive::{Deserialize, Serialize}; +use serde_json::{Map, Value}; +use solana_client::rpc_client::RpcClient; +use solana_config_api::{config_instruction, get_config_data, ConfigKeys, ConfigState}; +use solana_sdk::account::Account; +use solana_sdk::message::Message; +use solana_sdk::pubkey::Pubkey; +use solana_sdk::signature::{Keypair, KeypairUtil}; +use solana_sdk::transaction::Transaction; +use std::error; + +pub const MAX_SHORT_FIELD_LENGTH: usize = 70; +pub const MAX_LONG_FIELD_LENGTH: usize = 300; +pub const MAX_VALIDATOR_INFO: u64 = 576; + +// Config account key: Va1idator1nfo111111111111111111111111111111 +pub const REGISTER_CONFIG_KEY: [u8; 32] = [ + 7, 81, 151, 1, 116, 72, 242, 172, 93, 194, 60, 158, 188, 122, 199, 140, 10, 39, 37, 122, 198, + 20, 69, 141, 224, 164, 241, 111, 128, 0, 0, 0, +]; + +solana_sdk::solana_name_id!( + REGISTER_CONFIG_KEY, + "Va1idator1nfo111111111111111111111111111111" +); + +#[derive(Debug, Deserialize, PartialEq, Serialize, Default)] +pub struct ValidatorInfo { + info: String, +} + +impl ConfigState for ValidatorInfo { + fn max_space() -> u64 { + MAX_VALIDATOR_INFO + } +} + +// Return an error if a validator details are longer than the max length. +pub fn check_details_length(string: String) -> Result<(), String> { + if string.len() > MAX_LONG_FIELD_LENGTH { + Err(format!( + "validator details longer than {:?}-byte limit", + MAX_LONG_FIELD_LENGTH + )) + } else { + Ok(()) + } +} + +// Return an error if url field is too long or cannot be parsed. +pub fn check_url(string: String) -> Result<(), String> { + is_url(string.clone())?; + if string.len() > MAX_SHORT_FIELD_LENGTH { + Err(format!( + "url longer than {:?}-byte limit", + MAX_SHORT_FIELD_LENGTH + )) + } else { + Ok(()) + } +} + +// Return an error if a validator field is longer than the max length. +pub fn is_short_field(string: String) -> Result<(), String> { + if string.len() > MAX_SHORT_FIELD_LENGTH { + Err(format!( + "validator field longer than {:?}-byte limit", + MAX_SHORT_FIELD_LENGTH + )) + } else { + Ok(()) + } +} + +fn verify_keybase( + validator_pubkey: &Pubkey, + keybase_username: &Value, +) -> Result<(), Box> { + if let Some(keybase_username) = keybase_username.as_str() { + let url = format!( + "https://keybase.pub/{}/solana/validator-{:?}", + keybase_username, validator_pubkey + ); + let client = Client::new(); + if client.head(&url).send()?.status().is_success() { + Ok(()) + } else { + Err(format!("keybase_username could not be confirmed at: {}. Please add this pubkey file to your keybase profile to connect", url))? + } + } else { + Err(format!( + "keybase_username could not be parsed as String: {}", + keybase_username + ))? + } +} + +fn parse_args(matches: &ArgMatches<'_>) -> Value { + println!("{:?}", matches); + let mut map = Map::new(); + map.insert( + "name".to_string(), + Value::String(matches.value_of("name").unwrap().to_string()), + ); + if let Some(url) = matches.value_of("website") { + map.insert("website".to_string(), Value::String(url.to_string())); + } + if let Some(details) = matches.value_of("details") { + map.insert("details".to_string(), Value::String(details.to_string())); + } + if let Some(keybase_username) = matches.value_of("keybase_username") { + map.insert( + "keybaseUsername".to_string(), + Value::String(keybase_username.to_string()), + ); + } + Value::Object(map) +} + +fn parse_validator_info( + pubkey: &Pubkey, + account_data: &[u8], +) -> Result<(Pubkey, String), Box> { + let key_list: ConfigKeys = deserialize(&account_data)?; + if !key_list.keys.is_empty() { + let (validator_pubkey, _) = key_list.keys[1]; + let validator_info: String = deserialize(&get_config_data(account_data)?)?; + Ok((validator_pubkey, validator_info)) + } else { + Err(format!( + "account {} found, but could not be parsed as ValidatorInfo", + pubkey + ))? + } +} + +fn parse_info_pubkey(matches: &ArgMatches<'_>) -> Result, WalletError> { + let info_pubkey = if let Some(pubkey) = matches.value_of("info_pubkey") { + Some(pubkey.parse::().map_err(|err| { + WalletError::BadParameter(format!("Invalid validator info pubkey: {:?}", err)) + })?) + } else { + None + }; + Ok(info_pubkey) +} + +pub fn parse_validator_info_command( + matches: &ArgMatches<'_>, + validator_pubkey: &Pubkey, +) -> Result { + let info_pubkey = parse_info_pubkey(matches)?; + // Prepare validator info + let validator_info = parse_args(&matches); + if let Some(string) = validator_info.get("keybaseUsername") { + let result = verify_keybase(&validator_pubkey, &string); + if result.is_err() { + if matches.is_present("force") { + println!("--force supplied, ignoring: {:?}", result); + } else { + result.map_err(|err| { + WalletError::BadParameter(format!( + "Invalid validator keybase username: {:?}", + err + )) + })?; + } + } + } + let validator_string = serde_json::to_string(&validator_info).unwrap(); + let validator_info = ValidatorInfo { + info: validator_string, + }; + Ok(WalletCommand::SetValidatorInfo(validator_info, info_pubkey)) +} + +pub fn parse_get_validator_info_command( + matches: &ArgMatches<'_>, +) -> Result { + let info_pubkey = parse_info_pubkey(matches)?; + Ok(WalletCommand::GetValidatorInfo(info_pubkey)) +} + +pub fn process_set_validator_info( + rpc_client: &RpcClient, + config: &WalletConfig, + validator_info: &ValidatorInfo, + info_pubkey: Option, +) -> ProcessResult { + // Check for existing validator-info account + let all_config = rpc_client.get_program_accounts(&solana_config_api::id())?; + let existing_account = all_config + .iter() + .filter(|(_, account)| { + let key_list: ConfigKeys = deserialize(&account.data).map_err(|_| false).unwrap(); + key_list.keys.contains(&(id(), false)) + }) + .find(|(pubkey, account)| { + let (validator_pubkey, _) = parse_validator_info(&pubkey, &account.data).unwrap(); + validator_pubkey == config.keypair.pubkey() + }); + + // Create validator-info keypair to use if info_pubkey not provided or does not exist + let info_keypair = Keypair::new(); + let mut info_pubkey = if let Some(pubkey) = info_pubkey { + pubkey + } else if let Some(validator_info) = existing_account { + validator_info.0 + } else { + info_keypair.pubkey() + }; + + // Check existence of validator-info account + let balance = rpc_client.poll_get_balance(&info_pubkey).unwrap_or(0); + + let keys = vec![(id(), false), (config.keypair.pubkey(), true)]; + let (message, signers): (Message, Vec<&Keypair>) = if balance == 0 { + if info_pubkey != info_keypair.pubkey() { + println!( + "Account {:?} does not exist. Generating new keypair...", + info_pubkey + ); + info_pubkey = info_keypair.pubkey(); + } + println!( + "Publishing info for Validator {:?}", + config.keypair.pubkey() + ); + let mut instructions = config_instruction::create_account::( + &config.keypair.pubkey(), + &info_keypair.pubkey(), + 1, + keys.clone(), + ); + instructions.extend_from_slice(&[config_instruction::store( + &info_keypair.pubkey(), + true, + keys, + validator_info, + )]); + let signers = vec![&config.keypair, &info_keypair]; + let message = Message::new(instructions); + (message, signers) + } else { + println!( + "Updating Validator {:?} info at: {:?}", + config.keypair.pubkey(), + info_pubkey + ); + let instructions = vec![config_instruction::store( + &info_pubkey, + false, + keys, + validator_info, + )]; + let message = Message::new_with_payer(instructions, Some(&config.keypair.pubkey())); + let signers = vec![&config.keypair]; + (message, signers) + }; + + // Submit transaction + let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?; + let mut tx = Transaction::new(&signers, message, recent_blockhash); + check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?; + let signature_str = rpc_client.send_and_confirm_transaction(&mut tx, &signers)?; + + println!("Success! Validator info published at: {:?}", info_pubkey); + println!("{}", signature_str); + Ok("".to_string()) +} + +pub fn process_get_validator_info(rpc_client: &RpcClient, pubkey: Option) -> ProcessResult { + if let Some(info_pubkey) = pubkey { + let validator_info_data = rpc_client.get_account_data(&info_pubkey)?; + let (validator_pubkey, validator_info) = + parse_validator_info(&info_pubkey, &validator_info_data)?; + println!("Validator pubkey: {:?}", validator_pubkey); + println!("Info: {}", validator_info); + } else { + let all_config = rpc_client.get_program_accounts(&solana_config_api::id())?; + let all_validator_info: Vec<&(Pubkey, Account)> = all_config + .iter() + .filter(|(_, account)| { + let key_list: ConfigKeys = deserialize(&account.data).map_err(|_| false).unwrap(); + key_list.keys.contains(&(id(), false)) + }) + .collect(); + if all_validator_info.is_empty() { + println!("No validator info accounts found"); + } + for (info_pubkey, account) in all_validator_info.iter() { + println!("Validator info from {:?}", info_pubkey); + let (validator_pubkey, validator_info) = + parse_validator_info(&info_pubkey, &account.data)?; + println!(" Validator pubkey: {:?}", validator_pubkey); + println!(" Info: {}", validator_info); + } + } + Ok("".to_string()) +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::wallet::app; + use bincode::{serialize, serialized_size}; + use serde_json::json; + + #[test] + fn test_check_url() { + let url = "http://test.com"; + assert_eq!(check_url(url.to_string()), Ok(())); + let long_url = "http://7cLvFwLCbyHuXQ1RGzhCMobAWYPMSZ3VbUml1qWi1nkc3FD7zj9hzTZzMvYJ.com"; + assert!(check_url(long_url.to_string()).is_err()); + let non_url = "not parseable"; + assert!(check_url(non_url.to_string()).is_err()); + } + + #[test] + fn test_is_short_field() { + let name = "Alice Validator"; + assert_eq!(is_short_field(name.to_string()), Ok(())); + let long_name = "Alice 7cLvFwLCbyHuXQ1RGzhCMobAWYPMSZ3VbUml1qWi1nkc3FD7zj9hzTZzMvYJt6rY9"; + assert!(is_short_field(long_name.to_string()).is_err()); + } + + #[test] + fn test_parse_args() { + let matches = app("test", "desc", "version").get_matches_from(vec![ + "test", + "validator-info", + "publish", + "Alice", + "-n", + "alice_keybase", + ]); + let subcommand_matches = matches.subcommand(); + assert_eq!(subcommand_matches.0, "validator-info"); + assert!(subcommand_matches.1.is_some()); + let subcommand_matches = subcommand_matches.1.unwrap().subcommand(); + assert_eq!(subcommand_matches.0, "publish"); + assert!(subcommand_matches.1.is_some()); + let matches = subcommand_matches.1.unwrap(); + let expected = json!({ + "name": "Alice", + "keybaseUsername": "alice_keybase", + }); + assert_eq!(parse_args(&matches), expected); + } + + #[test] + fn test_validator_info_serde() { + let mut info = Map::new(); + info.insert("name".to_string(), Value::String("Alice".to_string())); + let info_string = serde_json::to_string(&Value::Object(info)).unwrap(); + + let validator_info = ValidatorInfo { + info: info_string.clone(), + }; + + assert_eq!(serialized_size(&validator_info).unwrap(), 24); + assert_eq!( + serialize(&validator_info).unwrap(), + vec![ + 16, 0, 0, 0, 0, 0, 0, 0, 123, 34, 110, 97, 109, 101, 34, 58, 34, 65, 108, 105, 99, + 101, 34, 125 + ] + ); + + let deserialized: ValidatorInfo = deserialize(&[ + 16, 0, 0, 0, 0, 0, 0, 0, 123, 34, 110, 97, 109, 101, 34, 58, 34, 65, 108, 105, 99, 101, + 34, 125, + ]) + .unwrap(); + assert_eq!(deserialized.info, info_string); + } + + #[test] + fn test_parse_validator_info() { + let pubkey = Pubkey::new_rand(); + let keys = vec![(id(), false), (pubkey, true)]; + let config = ConfigKeys { keys }; + + let mut info = Map::new(); + info.insert("name".to_string(), Value::String("Alice".to_string())); + let info_string = serde_json::to_string(&Value::Object(info)).unwrap(); + let validator_info = ValidatorInfo { + info: info_string.clone(), + }; + let data = serialize(&(config, validator_info)).unwrap(); + + assert_eq!( + parse_validator_info(&Pubkey::default(), &data).unwrap(), + (pubkey, info_string) + ); + } + + #[test] + fn test_validator_info_max_space() { + // 70-character string + let max_short_string = + "Max Length String KWpP299aFCBWvWg1MHpSuaoTsud7cv8zMJsh99aAtP8X1s26yrR1".to_string(); + // 300-character string + let max_long_string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut libero quam, volutpat et aliquet eu, varius in mi. Aenean vestibulum ex in tristique faucibus. Maecenas in imperdiet turpis. Nullam feugiat aliquet erat. Morbi malesuada turpis sed dui pulvinar lobortis. Pellentesque a lectus eu leo nullam.".to_string(); + let mut info = Map::new(); + info.insert("name".to_string(), Value::String(max_short_string.clone())); + info.insert( + "website".to_string(), + Value::String(max_short_string.clone()), + ); + info.insert( + "keybaseUsername".to_string(), + Value::String(max_short_string), + ); + info.insert("details".to_string(), Value::String(max_long_string)); + let info_string = serde_json::to_string(&Value::Object(info)).unwrap(); + + let validator_info = ValidatorInfo { + info: info_string.clone(), + }; + + assert_eq!( + serialized_size(&validator_info).unwrap(), + ValidatorInfo::max_space() + ); + } +} diff --git a/cli/src/wallet.rs b/cli/src/wallet.rs index 2caae8427f..8e920b5047 100644 --- a/cli/src/wallet.rs +++ b/cli/src/wallet.rs @@ -1,4 +1,4 @@ -use crate::display::println_name_value; +use crate::{display::println_name_value, input_validators::*, validator_info::*}; use chrono::prelude::*; use clap::{value_t_or_exit, App, AppSettings, Arg, ArgMatches, SubCommand}; use console::{style, Emoji}; @@ -75,24 +75,23 @@ pub enum WalletCommand { GetSlot, GetTransactionCount, GetVersion, - // Pay(lamports, to, timestamp, timestamp_pubkey, witness(es), cancelable) Pay( - u64, - Pubkey, - Option>, - Option, - Option>, - Option, + u64, // lamports + Pubkey, // to + Option>, // timestamp + Option, // timestamp_pubkey + Option>, // witness(es) + Option, // cancelable ), Ping { interval: Duration, count: Option, timeout: Duration, }, - // TimeElapsed(to, process_id, timestamp) - TimeElapsed(Pubkey, Pubkey, DateTime), - // Witness(to, process_id) - Witness(Pubkey, Pubkey), + TimeElapsed(Pubkey, Pubkey, DateTime), // TimeElapsed(to, process_id, timestamp) + Witness(Pubkey, Pubkey), // Witness(to, process_id) + GetValidatorInfo(Option), + SetValidatorInfo(ValidatorInfo, Option), } #[derive(Debug, Clone)] @@ -424,6 +423,17 @@ pub fn parse_command( Ok(WalletCommand::TimeElapsed(to, process_id, dt)) } ("cluster-version", Some(_matches)) => Ok(WalletCommand::GetVersion), + ("validator-info", Some(matches)) => match matches.subcommand() { + ("publish", Some(matches)) => parse_validator_info_command(matches, pubkey), + ("get", Some(matches)) => parse_get_validator_info_command(matches), + ("", None) => { + eprintln!("{}", matches.usage()); + Err(WalletError::CommandNotRecognized( + "no validator-info subcommand given".to_string(), + )) + } + _ => unreachable!(), + }, ("", None) => { eprintln!("{}", matches.usage()); Err(WalletError::CommandNotRecognized( @@ -435,9 +445,9 @@ pub fn parse_command( Ok(response) } -type ProcessResult = Result>; +pub type ProcessResult = Result>; -fn check_account_for_fee( +pub fn check_account_for_fee( rpc_client: &RpcClient, config: &WalletConfig, fee_calculator: &FeeCalculator, @@ -1563,6 +1573,16 @@ pub fn process_command(config: &WalletConfig) -> ProcessResult { // Return software version of wallet and cluster entrypoint node WalletCommand::GetVersion => process_get_version(&rpc_client, config), + + // Return all or single validator info + WalletCommand::GetValidatorInfo(info_pubkey) => { + process_get_validator_info(&rpc_client, *info_pubkey) + } + + // Publish validator info + WalletCommand::SetValidatorInfo(validator_info, info_pubkey) => { + process_set_validator_info(&rpc_client, config, &validator_info, *info_pubkey) + } } } @@ -1656,26 +1676,6 @@ where } } -// Return an error if a pubkey cannot be parsed. -fn is_pubkey(string: String) -> Result<(), String> { - match string.parse::() { - Ok(_) => Ok(()), - Err(err) => Err(format!("{:?}", err)), - } -} - -// Return an error if a keypair file cannot be parsed. -fn is_keypair(string: String) -> Result<(), String> { - read_keypair(&string) - .map(|_| ()) - .map_err(|err| format!("{:?}", err)) -} - -// Return an error if string cannot be parsed as pubkey string or keypair file location -fn is_pubkey_or_keypair(string: String) -> Result<(), String> { - is_pubkey(string.clone()).or_else(|_| is_keypair(string)) -} - pub fn app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> App<'ab, 'v> { App::new(name) .about(about) @@ -2222,6 +2222,78 @@ pub fn app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> App<'ab, ' SubCommand::with_name("cluster-version") .about("Get the version of the cluster entrypoint"), ) + .subcommand( + SubCommand::with_name("validator-info") + .about("Publish/get Validator info on Solana") + .subcommand( + SubCommand::with_name("publish") + .about("Publish Validator info on Solana") + .arg( + Arg::with_name("info_pubkey") + .short("p") + .long("info-pubkey") + .value_name("PUBKEY") + .takes_value(true) + .validator(is_pubkey) + .help("The pubkey of the Validator info account to update"), + ) + .arg( + Arg::with_name("name") + .index(1) + .value_name("NAME") + .takes_value(true) + .required(true) + .validator(is_short_field) + .help("Validator name"), + ) + .arg( + Arg::with_name("website") + .short("w") + .long("website") + .value_name("URL") + .takes_value(true) + .validator(check_url) + .help("Validator website url"), + ) + .arg( + Arg::with_name("keybase_username") + .short("n") + .long("keybase") + .value_name("USERNAME") + .takes_value(true) + .validator(is_short_field) + .help("Validator Keybase username"), + ) + .arg( + Arg::with_name("details") + .short("d") + .long("details") + .value_name("DETAILS") + .takes_value(true) + .validator(check_details_length) + .help("Validator description") + ) + .arg( + Arg::with_name("force") + .long("force") + .takes_value(false) + .hidden(true) // Don't document this argument to discourage its use + .help("Override keybase username validity check"), + ), + ) + .subcommand( + SubCommand::with_name("get") + .about("Get and parse Solana Validator info") + .arg( + Arg::with_name("info_pubkey") + .index(1) + .value_name("PUBKEY") + .takes_value(true) + .validator(is_pubkey) + .help("The pubkey of the Validator info account; without this argument, returns all"), + ), + ) + ) } #[cfg(test)] diff --git a/net/remote/remote-node.sh b/net/remote/remote-node.sh index 498f068a91..4ee74ea0c9 100755 --- a/net/remote/remote-node.sh +++ b/net/remote/remote-node.sh @@ -177,7 +177,7 @@ local|tar|skip) oom_score_adj "$pid" 1000 waitForNodeToInit - solana-validator-info publish --url http://"$entrypointIp":8899 \ + solana validator-info publish --url http://"$entrypointIp":8899 \ config/bootstrap-leader/identity-keypair.json "$(hostname)" -k team/solana --force || true ;; validator|blockstreamer) @@ -282,7 +282,7 @@ local|tar|skip) ./multinode-demo/delegate-stake.sh "${args[@]}" fi - solana-validator-info publish --url http://"$entrypointIp":8899 \ + solana validator-info publish --url http://"$entrypointIp":8899 \ ~/solana/fullnode-identity.json "$(hostname)" -k team/solana --force || true ;; replicator) diff --git a/scripts/cargo-install-all.sh b/scripts/cargo-install-all.sh index 9ff97b1d35..4f5b8eeca4 100755 --- a/scripts/cargo-install-all.sh +++ b/scripts/cargo-install-all.sh @@ -46,7 +46,6 @@ BIN_CRATES=( ledger-tool replicator validator - validator-info cli bench-exchange bench-tps diff --git a/validator-info/.gitignore b/validator-info/.gitignore deleted file mode 100644 index 5404b132db..0000000000 --- a/validator-info/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/target/ -/farf/ diff --git a/validator-info/Cargo.toml b/validator-info/Cargo.toml deleted file mode 100644 index 5efa0627d3..0000000000 --- a/validator-info/Cargo.toml +++ /dev/null @@ -1,30 +0,0 @@ -[package] -name = "solana-validator-info" -version = "0.19.0-pre0" -description = "Solana validator registration tool" -authors = ["Solana Maintainers "] -repository = "https://github.com/solana-labs/solana" -license = "Apache-2.0" -homepage = "https://solana.com/" -edition = "2018" - -[features] -cuda = [] - - -[dependencies] -bincode = "1.1.4" -clap = "2.33" -dirs = "2.0.2" -reqwest = "0.9.20" -serde = "1.0.99" -serde_derive = "1.0.99" -serde_json = "1.0.40" -solana-client = { path = "../client", version = "0.19.0-pre0" } -solana-config-api = { path = "../programs/config_api", version = "0.19.0-pre0" } -solana-sdk = { path = "../sdk", version = "0.19.0-pre0" } -url = "2.1.0" - -[[bin]] -name = "solana-validator-info" -path = "src/validator_info.rs" diff --git a/validator-info/src/validator_info.rs b/validator-info/src/validator_info.rs deleted file mode 100644 index 023570738f..0000000000 --- a/validator-info/src/validator_info.rs +++ /dev/null @@ -1,560 +0,0 @@ -use bincode::deserialize; -use clap::{ - crate_description, crate_name, crate_version, App, AppSettings, Arg, ArgMatches, SubCommand, -}; -use reqwest::Client; -use serde_derive::{Deserialize, Serialize}; -use serde_json::{Map, Value}; -use solana_client::rpc_client::RpcClient; -use solana_config_api::{config_instruction, get_config_data, ConfigKeys, ConfigState}; -use solana_sdk::account::Account; -use solana_sdk::message::Message; -use solana_sdk::pubkey::Pubkey; -use solana_sdk::signature::{read_keypair, Keypair, KeypairUtil}; -use solana_sdk::transaction::Transaction; -use std::error; -use std::process::exit; - -pub const MAX_SHORT_FIELD_LENGTH: usize = 70; -pub const MAX_LONG_FIELD_LENGTH: usize = 300; -pub const MAX_VALIDATOR_INFO: u64 = 576; -pub const JSON_RPC_URL: &str = "http://127.0.0.1:8899"; - -// Config account key: Va1idator1nfo111111111111111111111111111111 -pub const REGISTER_CONFIG_KEY: [u8; 32] = [ - 7, 81, 151, 1, 116, 72, 242, 172, 93, 194, 60, 158, 188, 122, 199, 140, 10, 39, 37, 122, 198, - 20, 69, 141, 224, 164, 241, 111, 128, 0, 0, 0, -]; - -solana_sdk::solana_name_id!( - REGISTER_CONFIG_KEY, - "Va1idator1nfo111111111111111111111111111111" -); - -#[derive(Debug, Deserialize, Serialize, Default)] -struct ValidatorInfo { - info: String, -} - -impl ConfigState for ValidatorInfo { - fn max_space() -> u64 { - MAX_VALIDATOR_INFO - } -} - -// Return an error if a pubkey cannot be parsed. -fn is_pubkey(string: String) -> Result<(), String> { - match string.parse::() { - Ok(_) => Ok(()), - Err(err) => Err(format!("{:?}", err)), - } -} - -// Return an error if a keypair file cannot be parsed. -fn is_keypair(string: String) -> Result<(), String> { - read_keypair(&string) - .map(|_| ()) - .map_err(|err| format!("{:?}", err)) -} - -// Return an error if a url cannot be parsed. -fn is_url(string: String) -> Result<(), String> { - match url::Url::parse(&string) { - Ok(url) => { - if url.has_host() { - Ok(()) - } else { - Err("no host provided".to_string()) - } - } - Err(err) => Err(format!("{:?}", err)), - } -} - -// Return an error if url field is too long or cannot be parsed. -fn check_url(string: String) -> Result<(), String> { - is_url(string.clone())?; - if string.len() > MAX_SHORT_FIELD_LENGTH { - Err(format!( - "url longer than {:?}-byte limit", - MAX_SHORT_FIELD_LENGTH - )) - } else { - Ok(()) - } -} - -// Return an error if a validator field is longer than the max length. -fn is_short_field(string: String) -> Result<(), String> { - if string.len() > MAX_SHORT_FIELD_LENGTH { - Err(format!( - "validator field longer than {:?}-byte limit", - MAX_SHORT_FIELD_LENGTH - )) - } else { - Ok(()) - } -} - -// Return an error if a validator details are longer than the max length. -fn check_details_length(string: String) -> Result<(), String> { - if string.len() > MAX_LONG_FIELD_LENGTH { - Err(format!( - "validator details longer than {:?}-byte limit", - MAX_LONG_FIELD_LENGTH - )) - } else { - Ok(()) - } -} - -fn verify_keybase( - validator_pubkey: &Pubkey, - keybase_username: &Value, -) -> Result<(), Box> { - if let Some(keybase_username) = keybase_username.as_str() { - let url = format!( - "https://keybase.pub/{}/solana/validator-{:?}", - keybase_username, validator_pubkey - ); - let client = Client::new(); - if client.head(&url).send()?.status().is_success() { - Ok(()) - } else { - Err(format!("keybase_username could not be confirmed at: {}. Please add this pubkey file to your keybase profile to connect", url))? - } - } else { - Err(format!( - "keybase_username could not be parsed as String: {}", - keybase_username - ))? - } -} - -fn parse_args(matches: &ArgMatches<'_>) -> Value { - let mut map = Map::new(); - map.insert( - "name".to_string(), - Value::String(matches.value_of("name").unwrap().to_string()), - ); - if let Some(url) = matches.value_of("website") { - map.insert("website".to_string(), Value::String(url.to_string())); - } - if let Some(details) = matches.value_of("details") { - map.insert("details".to_string(), Value::String(details.to_string())); - } - if let Some(keybase_username) = matches.value_of("keybase_username") { - map.insert( - "keybaseUsername".to_string(), - Value::String(keybase_username.to_string()), - ); - } - Value::Object(map) -} - -fn parse_validator_info( - pubkey: &Pubkey, - account_data: &[u8], -) -> Result<(Pubkey, String), Box> { - let key_list: ConfigKeys = deserialize(&account_data)?; - if !key_list.keys.is_empty() { - let (validator_pubkey, _) = key_list.keys[1]; - let validator_info: String = deserialize(&get_config_data(account_data)?)?; - Ok((validator_pubkey, validator_info)) - } else { - Err(format!( - "account {} found, but could not be parsed as ValidatorInfo", - pubkey - ))? - } -} - -fn main() -> Result<(), Box> { - let matches = App::new(crate_name!()) - .about(crate_description!()) - .version(crate_version!()) - .setting(AppSettings::SubcommandRequiredElseHelp) - .subcommand( - SubCommand::with_name("publish") - .about("Publish Validator info on Solana") - .setting(AppSettings::DisableVersion) - .arg( - Arg::with_name("json_rpc_url") - .short("u") - .long("url") - .value_name("URL") - .takes_value(true) - .default_value(JSON_RPC_URL) - .validator(is_url) - .help("JSON RPC URL for the solana cluster"), - ) - .arg( - Arg::with_name("validator_keypair") - .index(1) - .value_name("KEYPAIR") - .takes_value(true) - .required(true) - .validator(is_keypair) - .help("/path/to/validator-keypair.json"), - ) - .arg( - Arg::with_name("info_pubkey") - .short("p") - .long("info-pubkey") - .value_name("PUBKEY") - .takes_value(true) - .validator(is_pubkey) - .help("The pubkey of the Validator info account to update"), - ) - .arg( - Arg::with_name("name") - .index(2) - .value_name("NAME") - .takes_value(true) - .required(true) - .validator(is_short_field) - .help("Validator name"), - ) - .arg( - Arg::with_name("website") - .short("w") - .long("website") - .value_name("URL") - .takes_value(true) - .validator(check_url) - .help("Validator website url"), - ) - .arg( - Arg::with_name("keybase_username") - .short("k") - .long("keybase") - .value_name("USERNAME") - .takes_value(true) - .validator(is_short_field) - .help("Validator Keybase username"), - ) - .arg( - Arg::with_name("details") - .short("d") - .long("details") - .value_name("DETAILS") - .takes_value(true) - .validator(check_details_length) - .help(&format!( - "Validator description, max characters: {}", - MAX_LONG_FIELD_LENGTH - )) - ) - .arg( - Arg::with_name("force") - .long("force") - .takes_value(false) - .hidden(true) // Don't document this argument to discourage its use - .help("Override keybase username validity check"), - ), - ) - .subcommand( - SubCommand::with_name("get") - .about("Get and parse Solana Validator info") - .setting(AppSettings::DisableVersion) - .arg( - Arg::with_name("json_rpc_url") - .short("u") - .long("url") - .value_name("URL") - .takes_value(true) - .default_value(JSON_RPC_URL) - .validator(is_url) - .help("JSON RPC URL for the solana cluster"), - ) - .arg( - Arg::with_name("info_pubkey") - .index(1) - .value_name("PUBKEY") - .takes_value(true) - .validator(is_pubkey) - .help("The pubkey of the Validator info account; without this argument, returns all"), - ), - ) - .get_matches(); - - match matches.subcommand() { - ("publish", Some(matches)) => { - let json_rpc_url = matches.value_of("json_rpc_url").unwrap(); - let rpc_client = RpcClient::new(json_rpc_url.to_string()); - - // Load validator-keypair - let mut path = dirs::home_dir().expect("home directory"); - let id_path = if matches.is_present("validator_keypair") { - matches.value_of("validator_keypair").unwrap() - } else { - path.extend(&[".config", "solana", "validator-keypair.json"]); - if !path.exists() { - println!("No validator keypair file found. Run solana-keygen to create one."); - exit(1); - } - path.to_str().unwrap() - }; - let validator_keypair = read_keypair(id_path)?; - - // Check for existing validator-info account - let all_config = rpc_client.get_program_accounts(&solana_config_api::id())?; - let existing_account = all_config - .iter() - .filter(|(_, account)| { - let key_list: ConfigKeys = - deserialize(&account.data).map_err(|_| false).unwrap(); - key_list.keys.contains(&(id(), false)) - }) - .find(|(pubkey, account)| { - let (validator_pubkey, _) = - parse_validator_info(&pubkey, &account.data).unwrap(); - validator_pubkey == validator_keypair.pubkey() - }); - - // Create validator-info keypair to use if info_pubkey not provided or does not exist - let info_keypair = Keypair::new(); - let mut info_pubkey = if let Some(pubkey) = matches.value_of("info_pubkey") { - pubkey.parse::().unwrap() - } else if let Some(validator_info) = existing_account { - validator_info.0 - } else { - info_keypair.pubkey() - }; - - // Prepare validator info - let keys = vec![(id(), false), (validator_keypair.pubkey(), true)]; - let validator_info = parse_args(&matches); - if let Some(string) = validator_info.get("keybaseUsername") { - let result = verify_keybase(&validator_keypair.pubkey(), &string); - if result.is_err() { - if matches.is_present("force") { - println!("--force supplied, ignoring: {:?}", result); - } else { - result?; - } - } - } - let validator_string = serde_json::to_string(&validator_info)?; - let validator_info = ValidatorInfo { - info: validator_string, - }; - - // Check existence of validator-info account - let balance = rpc_client.poll_get_balance(&info_pubkey).unwrap_or(0); - - let (message, signers): (Message, Vec<&Keypair>) = if balance == 0 { - if info_pubkey != info_keypair.pubkey() { - println!( - "Account {:?} does not exist. Generating new keypair...", - info_pubkey - ); - info_pubkey = info_keypair.pubkey(); - } - println!( - "Publishing info for Validator {:?}", - validator_keypair.pubkey() - ); - let mut instructions = config_instruction::create_account::( - &validator_keypair.pubkey(), - &info_keypair.pubkey(), - 1, - keys.clone(), - ); - instructions.extend_from_slice(&[config_instruction::store( - &info_keypair.pubkey(), - true, - keys, - &validator_info, - )]); - let signers = vec![&validator_keypair, &info_keypair]; - let message = Message::new(instructions); - (message, signers) - } else { - println!( - "Updating Validator {:?} info at: {:?}", - validator_keypair.pubkey(), - info_pubkey - ); - let instructions = vec![config_instruction::store( - &info_pubkey, - false, - keys, - &validator_info, - )]; - let message = - Message::new_with_payer(instructions, Some(&validator_keypair.pubkey())); - let signers = vec![&validator_keypair]; - (message, signers) - }; - - // Submit transaction - let (recent_blockhash, _fee_calculator) = rpc_client.get_recent_blockhash()?; - let mut transaction = Transaction::new(&signers, message, recent_blockhash); - let signature_str = - rpc_client.send_and_confirm_transaction(&mut transaction, &signers)?; - - println!("Success! Validator info published at: {:?}", info_pubkey); - println!("{}", signature_str); - } - ("get", Some(matches)) => { - let json_rpc_url = matches.value_of("json_rpc_url").unwrap(); - let rpc_client = RpcClient::new(json_rpc_url.to_string()); - - if matches.is_present("info_pubkey") { - if let Some(pubkey) = matches.value_of("info_pubkey") { - let info_pubkey = pubkey.parse::().unwrap(); - let validator_info_data = rpc_client.get_account_data(&info_pubkey)?; - let (validator_pubkey, validator_info) = - parse_validator_info(&info_pubkey, &validator_info_data)?; - println!("Validator pubkey: {:?}", validator_pubkey); - println!("Info: {}", validator_info); - } - } else { - let all_config = rpc_client.get_program_accounts(&solana_config_api::id())?; - let all_validator_info: Vec<&(Pubkey, Account)> = all_config - .iter() - .filter(|(_, account)| { - let key_list: ConfigKeys = - deserialize(&account.data).map_err(|_| false).unwrap(); - key_list.keys.contains(&(id(), false)) - }) - .collect(); - if all_validator_info.is_empty() { - println!("No validator info accounts found"); - } - for (info_pubkey, account) in all_validator_info.iter() { - println!("Validator info from {:?}", info_pubkey); - let (validator_pubkey, validator_info) = - parse_validator_info(&info_pubkey, &account.data)?; - println!(" Validator pubkey: {:?}", validator_pubkey); - println!(" Info: {}", validator_info); - } - } - } - _ => unreachable!(), - } - - Ok(()) -} - -#[cfg(test)] -mod tests { - use super::*; - use bincode::{serialize, serialized_size}; - use serde_json::json; - - #[test] - fn test_check_url() { - let url = "http://test.com"; - assert_eq!(check_url(url.to_string()), Ok(())); - let long_url = "http://7cLvFwLCbyHuXQ1RGzhCMobAWYPMSZ3VbUml1qWi1nkc3FD7zj9hzTZzMvYJ.com"; - assert!(check_url(long_url.to_string()).is_err()); - let non_url = "not parseable"; - assert!(check_url(non_url.to_string()).is_err()); - } - - #[test] - fn test_is_short_field() { - let name = "Alice Validator"; - assert_eq!(is_short_field(name.to_string()), Ok(())); - let long_name = "Alice 7cLvFwLCbyHuXQ1RGzhCMobAWYPMSZ3VbUml1qWi1nkc3FD7zj9hzTZzMvYJt6rY9"; - assert!(is_short_field(long_name.to_string()).is_err()); - } - - #[test] - fn test_parse_args() { - let matches = App::new("test") - .arg(Arg::with_name("name").short("n").takes_value(true)) - .arg(Arg::with_name("website").short("w").takes_value(true)) - .arg( - Arg::with_name("keybase_username") - .short("k") - .takes_value(true), - ) - .arg(Arg::with_name("details").short("d").takes_value(true)) - .get_matches_from(vec!["test", "-n", "Alice", "-k", "alice_keybase"]); - let expected = json!({ - "name": "Alice", - "keybaseUsername": "alice_keybase", - }); - assert_eq!(parse_args(&matches), expected); - } - - #[test] - fn test_validator_info_serde() { - let mut info = Map::new(); - info.insert("name".to_string(), Value::String("Alice".to_string())); - let info_string = serde_json::to_string(&Value::Object(info)).unwrap(); - - let validator_info = ValidatorInfo { - info: info_string.clone(), - }; - - assert_eq!(serialized_size(&validator_info).unwrap(), 24); - assert_eq!( - serialize(&validator_info).unwrap(), - vec![ - 16, 0, 0, 0, 0, 0, 0, 0, 123, 34, 110, 97, 109, 101, 34, 58, 34, 65, 108, 105, 99, - 101, 34, 125 - ] - ); - - let deserialized: ValidatorInfo = deserialize(&[ - 16, 0, 0, 0, 0, 0, 0, 0, 123, 34, 110, 97, 109, 101, 34, 58, 34, 65, 108, 105, 99, 101, - 34, 125, - ]) - .unwrap(); - assert_eq!(deserialized.info, info_string); - } - - #[test] - fn test_parse_validator_info() { - let pubkey = Pubkey::new_rand(); - let keys = vec![(id(), false), (pubkey, true)]; - let config = ConfigKeys { keys }; - - let mut info = Map::new(); - info.insert("name".to_string(), Value::String("Alice".to_string())); - let info_string = serde_json::to_string(&Value::Object(info)).unwrap(); - let validator_info = ValidatorInfo { - info: info_string.clone(), - }; - let data = serialize(&(config, validator_info)).unwrap(); - - assert_eq!( - parse_validator_info(&Pubkey::default(), &data).unwrap(), - (pubkey, info_string) - ); - } - - #[test] - fn test_validator_info_max_space() { - // 70-character string - let max_short_string = - "Max Length String KWpP299aFCBWvWg1MHpSuaoTsud7cv8zMJsh99aAtP8X1s26yrR1".to_string(); - // 300-character string - let max_long_string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut libero quam, volutpat et aliquet eu, varius in mi. Aenean vestibulum ex in tristique faucibus. Maecenas in imperdiet turpis. Nullam feugiat aliquet erat. Morbi malesuada turpis sed dui pulvinar lobortis. Pellentesque a lectus eu leo nullam.".to_string(); - let mut info = Map::new(); - info.insert("name".to_string(), Value::String(max_short_string.clone())); - info.insert( - "website".to_string(), - Value::String(max_short_string.clone()), - ); - info.insert( - "keybaseUsername".to_string(), - Value::String(max_short_string), - ); - info.insert("details".to_string(), Value::String(max_long_string)); - let info_string = serde_json::to_string(&Value::Object(info)).unwrap(); - - let validator_info = ValidatorInfo { - info: info_string.clone(), - }; - - assert_eq!( - serialized_size(&validator_info).unwrap(), - ValidatorInfo::max_space() - ); - } -}