Skip to content

Commit

Permalink
[query] create query view for validator config (#73)
Browse files Browse the repository at this point in the history
Co-authored-by: 0o-de-lally <[email protected]>
  • Loading branch information
sirouk and 0o-de-lally committed Aug 8, 2024
1 parent 84e0888 commit 6b192fb
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 16 deletions.
2 changes: 1 addition & 1 deletion tools/config/src/node_yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tools/genesis/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
9 changes: 8 additions & 1 deletion tools/query/src/account_queries.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -33,3 +33,10 @@ pub async fn get_tower_state(
.get_move_resource::<TowerProofHistoryView>(account)
.await
}

pub async fn get_val_config(
client: &Client,
account: AccountAddress,
) -> anyhow::Result<ValidatorConfig> {
client.get_move_resource::<ValidatorConfig>(account).await
}
20 changes: 18 additions & 2 deletions tools/query/src/query_type.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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
Expand Down Expand Up @@ -143,7 +149,6 @@ impl QueryType {
QueryType::Tower { account } => {
let res = get_tower_state(&client, *account).await?;
Ok(json!(res))

},
QueryType::View {
function_id,
Expand Down Expand Up @@ -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!(),
Expand Down
24 changes: 14 additions & 10 deletions tools/txs/src/txs_cli_vals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down

0 comments on commit 6b192fb

Please sign in to comment.