Skip to content
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
3 changes: 3 additions & 0 deletions .changelog/unreleased/improvements/4021-dryrun-fixups.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Some small fixups learned from the dry-run: namadac
staking-rewards-rate, namadac query-proposal, log.
([\#4021](https://github.com/anoma/namada/pull/4021))
11 changes: 6 additions & 5 deletions crates/apps_lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5993,11 +5993,12 @@ pub mod args {
}

fn def(app: App) -> App {
app.add_args::<Query<CliTypes>>().arg(
PROPOSAL_ID_OPT
.def()
.help(wrap!("The proposal identifier.")),
)
app.add_args::<Query<CliTypes>>()
.arg(PROPOSAL_ID_OPT.def().help(wrap!(
"The ID number of the proposal. This argument is \
optional. If not provided, then the most recent 10 \
proposals will be displayed."
)))
}
}

Expand Down
38 changes: 24 additions & 14 deletions crates/apps_lib/src/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,21 +330,25 @@ pub async fn query_proposal(context: &impl Namada, args: args::QueryProposal) {
edisplay_line!(context.io(), "No proposal found with id: {}", id);
}
} else {
let last_proposal_id_key = governance_storage::get_counter_key();
let last_proposal_id: u64 =
query_storage_value(context.client(), &last_proposal_id_key)
let counter_key = governance_storage::get_counter_key();
let next_proposal_id: u64 =
query_storage_value(context.client(), &counter_key)
.await
.unwrap();

if next_proposal_id == 0 {
display_line!(context.io(), "No proposals found.");
return;
}
let last_proposal_id = next_proposal_id.checked_sub(1).unwrap();

let from_id = if last_proposal_id > 10 {
last_proposal_id - 10
} else {
0
};

display_line!(context.io(), "id: {}", last_proposal_id);

for id in from_id..last_proposal_id {
for id in from_id..=last_proposal_id {
let proposal = query_proposal_by_id(context.client(), id)
.await
.unwrap()
Expand Down Expand Up @@ -1399,7 +1403,6 @@ pub async fn query_effective_native_supply<N: Namada>(context: &N) {

/// Query the staking rewards rate estimate
pub async fn query_staking_rewards_rate<N: Namada>(context: &N) {
display_line!(context.io(), "Querying staking rewards rates...");
let PosRewardsRates {
staking_rewards_rate,
inflation_rate,
Expand All @@ -1409,13 +1412,20 @@ pub async fn query_staking_rewards_rate<N: Namada>(context: &N) {
.staking_rewards_rate(context.client())
.await,
);
display_line!(
context.io(),
"Current annual staking rewards rate: {}\nCurrent PoS inflation rate: \
{}",
staking_rewards_rate,
inflation_rate
);
if staking_rewards_rate.is_zero() && inflation_rate.is_zero() {
display_line!(
context.io(),
"PoS inflation and rewards are not currently enabled."
);
} else {
display_line!(
context.io(),
"Current annual staking rewards rate: {}\nCurrent PoS inflation \
rate: {}",
staking_rewards_rate,
inflation_rate
);
}
}

/// Query a validator's state information
Expand Down
16 changes: 13 additions & 3 deletions crates/proof_of_stake/src/rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ use thiserror::Error;
use crate::lazy_map::NestedSubKey;
use crate::storage::{
consensus_validator_set_handle, get_last_reward_claim_epoch,
read_last_pos_inflation_amount, read_last_staked_ratio, read_pos_params,
read_total_stake, read_validator_stake, rewards_accumulator_handle,
read_last_pos_inflation_amount, read_last_staked_ratio,
read_owned_pos_params, read_pos_params, read_total_stake,
read_validator_stake, rewards_accumulator_handle,
validator_commission_rate_handle, validator_rewards_products_handle,
validator_state_handle, write_last_pos_inflation_amount,
write_last_staked_ratio,
Expand Down Expand Up @@ -690,14 +691,23 @@ where
let last_inflation_amount =
Dec::try_from(last_inflation_amount).into_storage_result()?;

// Check if inflation is on
let params = read_owned_pos_params(storage)?;
if params.max_inflation_rate == Dec::zero() {
return Ok(PosRewardsRates {
staking_rewards_rate: Dec::zero(),
inflation_rate: Dec::zero(),
});
}

// Estimate annual inflation rate
let est_inflation_rate = checked!(
last_inflation_amount * epochs_per_year / total_native_tokens
)?;

// Estimate annual staking rewards rate
let est_staking_reward_rate =
checked!(est_inflation_rate / last_staked_ratio)?;
checked!(est_inflation_rate / last_staked_ratio).unwrap_or(Dec::zero());

Ok(PosRewardsRates {
staking_rewards_rate: est_staking_reward_rate,
Expand Down
3 changes: 2 additions & 1 deletion crates/sdk/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2142,7 +2142,8 @@ pub async fn build_vote_proposal(
context.io(),
"NB: voter address {} is a validator, and validators can only \
vote on proposals within the first 2/3 of the voting period. \
The voting period specifically for validators has ended.",
Either the voting period has not started, or the voting \
period specifically for validators has ended.",
voter_address
);
}
Expand Down