From dbc5dcf33f833adbeb45bf2f1597367dd72941d2 Mon Sep 17 00:00:00 2001 From: sirouk <8901571+sirouk@users.noreply.github.com> Date: Tue, 31 Oct 2023 17:02:51 -0400 Subject: [PATCH] [query] create query view for validator config (#73) Co-authored-by: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com> --- tools/config/src/node_yaml.rs | 2 +- tools/genesis/Makefile | 4 ++-- tools/query/src/account_queries.rs | 9 ++++++++- tools/query/src/query_type.rs | 20 ++++++++++++++++++-- tools/txs/src/txs_cli_vals.rs | 24 ++++++++++++++---------- 5 files changed, 43 insertions(+), 16 deletions(-) diff --git a/tools/config/src/node_yaml.rs b/tools/config/src/node_yaml.rs index 543fa8940..5e989b5e8 100644 --- a/tools/config/src/node_yaml.rs +++ b/tools/config/src/node_yaml.rs @@ -53,7 +53,7 @@ full_node_networks: listen_address: '/ip4/0.0.0.0/tcp/6181' identity: type: 'from_file' - path: {path}/validator-identity.yaml + path: {path}/validator-full-node-identity.yaml api: enabled: true diff --git a/tools/genesis/Makefile b/tools/genesis/Makefile index 8dd398b26..2a02f1aab 100644 --- a/tools/genesis/Makefile +++ b/tools/genesis/Makefile @@ -41,7 +41,7 @@ genesis: --target-future-uses ${FUTURE_USES} \ --years-escrow ${YEARS} \ --map-dd-to-slow 3A6C51A0B786D644590E8A21591FA8E2 \ - --map-dd-to-slow 2B0E8325DEA5BE93D856CFDE2D0CBA12 + --map-dd-to-slow 2B0E8325DEA5BE93D856CFDE2D0CBA12 wizard: @@ -54,7 +54,7 @@ wizard: --target-future-uses ${FUTURE_USES} \ --years-escrow ${YEARS} \ --map-dd-to-slow 3A6C51A0B786D644590E8A21591FA8E2 \ - --map-dd-to-slow 2B0E8325DEA5BE93D856CFDE2D0CBA12 + --map-dd-to-slow 2B0E8325DEA5BE93D856CFDE2D0CBA12 stdlib: cargo r -p libra-framework -- release diff --git a/tools/query/src/account_queries.rs b/tools/query/src/account_queries.rs index 95f0d03a7..21891a3cd 100644 --- a/tools/query/src/account_queries.rs +++ b/tools/query/src/account_queries.rs @@ -1,6 +1,6 @@ use diem_sdk::{ rest_client::{diem_api_types::ViewRequest, Client}, - types::account_address::AccountAddress, + types::{account_address::AccountAddress, validator_config::ValidatorConfig}, }; use libra_types::{ legacy_types::tower::TowerProofHistoryView, @@ -33,3 +33,10 @@ pub async fn get_tower_state( .get_move_resource::(account) .await } + +pub async fn get_val_config( + client: &Client, + account: AccountAddress, +) -> anyhow::Result { + client.get_move_resource::(account).await +} diff --git a/tools/query/src/query_type.rs b/tools/query/src/query_type.rs index 40e15b1c0..0c973e49c 100644 --- a/tools/query/src/query_type.rs +++ b/tools/query/src/query_type.rs @@ -1,5 +1,5 @@ use crate::{ - account_queries::{get_account_balance_libra, get_tower_state}, + account_queries::{get_account_balance_libra, get_tower_state, get_val_config}, query_view::get_view, }; use anyhow::{bail, Result}; @@ -23,6 +23,12 @@ pub enum QueryType { /// account to query txs of account: AccountAddress, }, + /// A validator's on-chain configuration + ValConfig { + #[clap(short, long)] + /// account to query txs of + account: AccountAddress, + }, /// Epoch and waypoint Epoch, /// Network block height @@ -143,7 +149,6 @@ impl QueryType { QueryType::Tower { account } => { let res = get_tower_state(&client, *account).await?; Ok(json!(res)) - }, QueryType::View { function_id, @@ -181,6 +186,17 @@ impl QueryType { bail!("no resource {resource_path_string}, found at address {account}"); } }, + QueryType::ValConfig { account } => { + let res = get_val_config(&client, *account).await?; + + // make this readable, turn the network address into a string + Ok(json!({ + "consensus_public_key": res.consensus_public_key, + "validator_network_addresses": res.validator_network_addresses().unwrap(), + "fullnode_network_addresses": res.fullnode_network_addresses().unwrap(), + "validator_index": res.validator_index, + })) + } _ => { bail!("Not implemented for type: {:?}\n Ground control to major tom.", self) } // QueryType::BlockHeight => todo!(), diff --git a/tools/txs/src/txs_cli_vals.rs b/tools/txs/src/txs_cli_vals.rs index 082030624..220c5bfa6 100644 --- a/tools/txs/src/txs_cli_vals.rs +++ b/tools/txs/src/txs_cli_vals.rs @@ -107,11 +107,13 @@ impl ValidatorTxs { .validator_host .as_network_address(oc.validator_network_public_key)?; - let fullnode_host = oc.full_node_host.context("cannot find fullnode host")?; - let vfn_fullnode_protocol = fullnode_host.as_network_address( - oc.full_node_network_public_key - .context("cannot find fullnode network public key")?, - )?; + let fullnode_host = oc + .full_node_host + .context("cannot find fullnode host in operator config file")?; + let vfn_fullnode_protocol = + fullnode_host.as_network_address(oc.full_node_network_public_key.context( + "cannot find fullnode network public key in operator config file", + )?)?; ValidatorUniverseRegisterValidator { consensus_pubkey: oc.consensus_public_key.to_bytes().to_vec(), @@ -134,11 +136,13 @@ impl ValidatorTxs { .validator_host .as_network_address(oc.validator_network_public_key)?; - let fullnode_host = oc.full_node_host.context("cannot find fullnode host")?; - let vfn_fullnode_protocol = fullnode_host.as_network_address( - oc.full_node_network_public_key - .context("cannot find fullnode network public key")?, - )?; + let fullnode_host = oc + .full_node_host + .context("cannot find fullnode host in operator config file")?; + let vfn_fullnode_protocol = fullnode_host + .as_network_address(oc.full_node_network_public_key.context( + "cannot find fullnode network public key operator config file", + )?)?; StakeUpdateNetworkAndFullnodeAddresses { validator_address: oc.operator_account_address.into(),