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

Bengt/Add unjail validator CLI command #1654

Merged
merged 8 commits into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from all 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/improvements/1656-pos-cli-queries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Added a client query for `validator-state` and improved the slashes query to
show more info. ([\#1656](https://github.com/anoma/namada/pull/1656))
30 changes: 30 additions & 0 deletions apps/src/bin/namada-client/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,20 @@ pub async fn main() -> Result<()> {
sdk_tx::process_tx(&client, &mut ctx.wallet, &tx_args, tx)
.await?;
}
Sub::TxUnjailValidator(TxUnjailValidator(mut args)) => {
let client = HttpClient::new(utils::take_config_address(
&mut args.tx.ledger_address,
))
.unwrap();
wait_until_node_is_synched(&client)
.await
.proceed_or_else(error)?;
let args = args.to_sdk(&mut ctx);
tx::submit_unjail_validator::<HttpClient>(
&client, ctx, args,
)
.await?;
}
// Ledger queries
Sub::QueryEpoch(QueryEpoch(mut args)) => {
let client = HttpClient::new(utils::take_config_address(
Expand Down Expand Up @@ -325,6 +339,22 @@ pub async fn main() -> Result<()> {
let args = args.to_sdk(&mut ctx);
rpc::query_bonded_stake(&client, args).await;
}
Sub::QueryValidatorState(QueryValidatorState(mut args)) => {
let client = HttpClient::new(utils::take_config_address(
&mut args.query.ledger_address,
))
.unwrap();
wait_until_node_is_synched(&client)
.await
.proceed_or_else(error)?;
let args = args.to_sdk(&mut ctx);
rpc::query_and_print_validator_state(
&client,
&mut ctx.wallet,
args,
)
.await;
}
Sub::QueryCommissionRate(QueryCommissionRate(mut args)) => {
let client = HttpClient::new(utils::take_config_address(
&mut args.query.ledger_address,
Expand Down
109 changes: 96 additions & 13 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const WALLET_CMD: &str = "wallet";
const RELAYER_CMD: &str = "relayer";

pub mod cmds {

use super::utils::*;
use super::{
args, ArgMatches, CLIENT_CMD, NODE_CMD, RELAYER_CMD, WALLET_CMD,
Expand Down Expand Up @@ -216,6 +217,7 @@ pub mod cmds {
.subcommand(TxVoteProposal::def().display_order(1))
// PoS transactions
.subcommand(TxInitValidator::def().display_order(2))
.subcommand(TxUnjailValidator::def().display_order(2))
.subcommand(Bond::def().display_order(2))
.subcommand(Unbond::def().display_order(2))
.subcommand(Withdraw::def().display_order(2))
Expand All @@ -238,6 +240,7 @@ pub mod cmds {
.subcommand(QueryProposal::def().display_order(4))
.subcommand(QueryProposalResult::def().display_order(4))
.subcommand(QueryProtocolParameters::def().display_order(4))
.subcommand(QueryValidatorState::def().display_order(4))
// Utils
.subcommand(Utils::def().display_order(5))
}
Expand All @@ -251,6 +254,8 @@ pub mod cmds {
let tx_init_account = Self::parse_with_ctx(matches, TxInitAccount);
let tx_init_validator =
Self::parse_with_ctx(matches, TxInitValidator);
let tx_unjail_validator =
Self::parse_with_ctx(matches, TxUnjailValidator);
let tx_reveal_pk = Self::parse_with_ctx(matches, TxRevealPk);
let tx_init_proposal =
Self::parse_with_ctx(matches, TxInitProposal);
Expand Down Expand Up @@ -282,6 +287,8 @@ pub mod cmds {
Self::parse_with_ctx(matches, QueryProposalResult);
let query_protocol_parameters =
Self::parse_with_ctx(matches, QueryProtocolParameters);
let query_validator_state =
Self::parse_with_ctx(matches, QueryValidatorState);
let add_to_eth_bridge_pool =
Self::parse_with_ctx(matches, AddToEthBridgePool);
let utils = SubCmd::parse(matches).map(Self::WithoutContext);
Expand All @@ -295,6 +302,7 @@ pub mod cmds {
.or(tx_vote_proposal)
.or(tx_init_validator)
.or(tx_commission_rate_change)
.or(tx_unjail_validator)
.or(bond)
.or(unbond)
.or(withdraw)
Expand All @@ -314,6 +322,7 @@ pub mod cmds {
.or(query_proposal)
.or(query_proposal_result)
.or(query_protocol_parameters)
.or(query_validator_state)
.or(utils)
}
}
Expand Down Expand Up @@ -359,6 +368,7 @@ pub mod cmds {
TxInitAccount(TxInitAccount),
TxInitValidator(TxInitValidator),
TxCommissionRateChange(TxCommissionRateChange),
TxUnjailValidator(TxUnjailValidator),
TxInitProposal(TxInitProposal),
TxVoteProposal(TxVoteProposal),
TxRevealPk(TxRevealPk),
Expand All @@ -381,6 +391,7 @@ pub mod cmds {
QueryProposal(QueryProposal),
QueryProposalResult(QueryProposalResult),
QueryProtocolParameters(QueryProtocolParameters),
QueryValidatorState(QueryValidatorState),
}

#[allow(clippy::large_enum_variant)]
Expand Down Expand Up @@ -1282,6 +1293,27 @@ pub mod cmds {
}
}

#[derive(Clone, Debug)]
pub struct TxUnjailValidator(pub args::TxUnjailValidator<args::CliTypes>);

impl SubCmd for TxUnjailValidator {
const CMD: &'static str = "unjail-validator";

fn parse(matches: &ArgMatches) -> Option<Self> {
matches.subcommand_matches(Self::CMD).map(|matches| {
TxUnjailValidator(args::TxUnjailValidator::parse(matches))
})
}

fn def() -> App {
App::new(Self::CMD)
.about(
"Send a signed transaction to unjail a jailed validator.",
)
.add_args::<args::TxUnjailValidator<args::CliTypes>>()
}
}

#[derive(Clone, Debug)]
pub struct Bond(pub args::Bond<args::CliTypes>);

Expand Down Expand Up @@ -1453,6 +1485,27 @@ pub mod cmds {
}
}

#[derive(Clone, Debug)]
pub struct QueryValidatorState(
pub args::QueryValidatorState<args::CliTypes>,
);

impl SubCmd for QueryValidatorState {
const CMD: &'static str = "validator-state";

fn parse(matches: &ArgMatches) -> Option<Self> {
matches.subcommand_matches(Self::CMD).map(|matches| {
QueryValidatorState(args::QueryValidatorState::parse(matches))
})
}

fn def() -> App {
App::new(Self::CMD)
.about("Query the state of a PoS validator.")
.add_args::<args::QueryValidatorState<args::CliTypes>>()
}
}

#[derive(Clone, Debug)]
pub struct QueryTransfers(pub args::QueryTransfers<args::CliTypes>);

Expand Down Expand Up @@ -1488,7 +1541,7 @@ pub mod cmds {

fn def() -> App {
App::new(Self::CMD)
.about("Query commission rate.")
.about("Query a validator's commission rate.")
.add_args::<args::QueryCommissionRate<args::CliTypes>>()
}
}
Expand Down Expand Up @@ -4016,8 +4069,44 @@ pub mod args {
"The validator's address whose bonded stake to query.",
))
.arg(EPOCH.def().help(
"The epoch at which to query (last committed, if not \
specified).",
"The epoch at which to query (corresponding to the last \
committed block, if not specified).",
))
}
}

impl CliToSdk<QueryValidatorState<SdkTypes>> for QueryValidatorState<CliTypes> {
fn to_sdk(self, ctx: &mut Context) -> QueryValidatorState<SdkTypes> {
QueryValidatorState::<SdkTypes> {
query: self.query.to_sdk(ctx),
validator: ctx.get(&self.validator),
epoch: self.epoch,
}
}
}

impl Args for QueryValidatorState<CliTypes> {
fn parse(matches: &ArgMatches) -> Self {
let query = Query::parse(matches);
let validator = VALIDATOR.parse(matches);
let epoch = EPOCH.parse(matches);
Self {
query,
validator,
epoch,
}
}

fn def(app: App) -> App {
app.add_args::<Query<CliTypes>>()
.arg(
VALIDATOR.def().help(
"The validator's address whose state is queried.",
),
)
.arg(EPOCH.def().help(
"The epoch at which to query (corresponding to the last \
committed block, if not specified).",
))
}
}
Expand Down Expand Up @@ -4064,16 +4153,10 @@ pub mod args {

impl CliToSdk<TxUnjailValidator<SdkTypes>> for TxUnjailValidator<CliTypes> {
fn to_sdk(self, ctx: &mut Context) -> TxUnjailValidator<SdkTypes> {
TxUnjailValidator {
TxUnjailValidator::<SdkTypes> {
tx: self.tx.to_sdk(ctx),
validator: ctx.get(&self.validator),
tx_code_path: self
.tx_code_path
.as_path()
.to_str()
.unwrap()
.to_string()
.into_bytes(),
tx_code_path: self.tx_code_path.to_path_buf(),
}
}
}
Expand Down Expand Up @@ -4127,8 +4210,8 @@ pub mod args {
"The validator's address whose commission rate to query.",
))
.arg(EPOCH.def().help(
"The epoch at which to query (last committed, if not \
specified).",
"The epoch at which to query (corresponding to the last \
committed block, if not specified).",
))
}
}
Expand Down
Loading