Skip to content

Commit

Permalink
Merge pull request #3940 from anoma/brent/small-tings
Browse files Browse the repository at this point in the history
Small misc fixes
  • Loading branch information
mergify[bot] authored Oct 24, 2024
2 parents f722c1c + 99a4dc9 commit 2107072
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .changelog/unreleased/improvements/3940-small-tings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Fixes display of tx allowlist in query-protocol-parameters.
Improves some error messages. Improves two standard client queries.
([\#3940](https://github.com/anoma/namada/pull/3940))
26 changes: 19 additions & 7 deletions crates/apps_lib/src/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use namada_sdk::address::{Address, InternalAddress, MASP};
use namada_sdk::chain::{BlockHeight, Epoch};
use namada_sdk::collections::{HashMap, HashSet};
use namada_sdk::control_flow::time::{Duration, Instant};
use namada_sdk::dec::Dec;
use namada_sdk::events::Event;
use namada_sdk::governance::parameters::GovernanceParameters;
use namada_sdk::governance::pgf::parameters::PgfParameters;
Expand All @@ -34,6 +33,7 @@ use namada_sdk::masp::MaspTokenRewardData;
use namada_sdk::parameters::{
storage as param_storage, EpochDuration, ProposalBytes,
};
use namada_sdk::proof_of_stake::rewards::PosRewardsRates;
use namada_sdk::proof_of_stake::types::{
CommissionPair, Slash, ValidatorMetaData, ValidatorState,
ValidatorStateInfo, WeightedValidator,
Expand Down Expand Up @@ -85,12 +85,17 @@ pub async fn query_and_print_masp_epoch(context: &impl Namada) -> MaspEpoch {
/// Query and print some information to help discern when the next epoch will
/// begin.
pub async fn query_and_print_next_epoch_info(context: &impl Namada) {
query_block(context).await;

let current_epoch = query_epoch(context.client()).await.unwrap();
let (this_epoch_first_height, epoch_duration) =
rpc::query_next_epoch_info(context.client()).await.unwrap();

display_line!(context.io(), "Current epoch: {current_epoch}.\n");
display_line!(
context.io(),
"First block height of this current epoch: {this_epoch_first_height}."
"First block height of this epoch {current_epoch}: \
{this_epoch_first_height}."
);
display_line!(
context.io(),
Expand All @@ -104,7 +109,8 @@ pub async fn query_and_print_next_epoch_info(context: &impl Namada) {
);
display_line!(
context.io(),
"\nEarliest height at which the next epoch can begin is block {}.",
"\nEarliest height at which epoch {} can begin is block {}.",
current_epoch.next(),
this_epoch_first_height.0 + epoch_duration.min_num_of_blocks
);
}
Expand Down Expand Up @@ -726,7 +732,7 @@ pub async fn query_protocol_parameters(
masp_epoch_multiplier
);

let key = param_storage::get_tx_allowlist_storage_key();
let key = param_storage::get_vp_allowlist_storage_key();
let vp_allowlist: Vec<String> = query_storage_value(context.client(), &key)
.await
.expect("Parameter should be defined.");
Expand Down Expand Up @@ -1367,16 +1373,22 @@ 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) {
let rewards_rate = unwrap_client_response::<N::Client, Dec>(
display_line!(context.io(), "Querying staking rewards rates...");
let PosRewardsRates {
staking_rewards_rate,
inflation_rate,
} = unwrap_client_response::<N::Client, PosRewardsRates>(
RPC.vp()
.token()
.staking_rewards_rate(context.client())
.await,
);
display_line!(
context.io(),
"Current annual staking rewards rate: {}",
rewards_rate
"Current annual staking rewards rate: {}\nCurrent PoS inflation rate: \
{}",
staking_rewards_rate,
inflation_rate
);
}

Expand Down
3 changes: 2 additions & 1 deletion crates/governance/src/cli/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ pub enum ProposalValidation {
/// The proposal difference between end and activation epoch is invalid
#[error(
"Invalid proposal activation epoch: difference between proposal \
activation and end epoch must be at least {0}, but found {1}"
activation and end epoch must be at least {0}, but found {1}. The \
difference must also be greater than 0."
)]
InvalidEndActivationDifference(u64, u64),
/// The proposal difference between end and activation epoch is invalid
Expand Down
2 changes: 1 addition & 1 deletion crates/proof_of_stake/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub enum UnbondError {
#[error("No bond could be found")]
NoBondFound,
#[error(
"Trying to withdraw more tokens ({0}) than the amount bonded ({0})"
"Trying to withdraw more tokens ({0}) than the amount bonded ({1})"
)]
UnbondAmountGreaterThanBond(String, String),
#[error("No bonds found for the validator {0}")]
Expand Down
21 changes: 18 additions & 3 deletions crates/proof_of_stake/src/rewards.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! PoS rewards distribution.

use borsh::{BorshDeserialize, BorshSerialize};
use namada_controller::PDController;
use namada_core::address::{self, Address};
use namada_core::arith::{self, checked};
Expand Down Expand Up @@ -98,6 +99,14 @@ pub struct PosRewards {
pub active_val_coeff: Dec,
}

/// Return values of the inflation asnd staking rewards rates
#[derive(Debug, Copy, Clone, BorshSerialize, BorshDeserialize)]
#[allow(missing_docs)]
pub struct PosRewardsRates {
pub staking_rewards_rate: Dec,
pub inflation_rate: Dec,
}

/// Holds relevant PoS parameters and is used to calculate the coefficients for
/// the rewards
#[derive(Debug, Copy, Clone)]
Expand Down Expand Up @@ -661,7 +670,7 @@ where
/// Compute an estimation of the most recent staking rewards rate.
pub fn estimate_staking_reward_rate<S, Token, Parameters>(
storage: &S,
) -> Result<Dec>
) -> Result<PosRewardsRates>
where
S: StorageRead,
Parameters: parameters::Read<S>,
Expand Down Expand Up @@ -690,7 +699,10 @@ where
let est_staking_reward_rate =
checked!(est_inflation_rate / last_staked_ratio)?;

Ok(est_staking_reward_rate)
Ok(PosRewardsRates {
staking_rewards_rate: est_staking_reward_rate,
inflation_rate: est_inflation_rate,
})
}

#[cfg(test)]
Expand Down Expand Up @@ -961,7 +973,10 @@ mod tests {
total_native_tokens,
);

let query_staking_rate = estimate_staking_reward_rate::<
let PosRewardsRates {
staking_rewards_rate: query_staking_rate,
inflation_rate: _query_inflation_rate,
} = estimate_staking_reward_rate::<
_,
namada_trans_token::Store<_>,
namada_parameters::Store<_>,
Expand Down
10 changes: 6 additions & 4 deletions crates/sdk/src/queries/vp/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

use namada_core::address::Address;
use namada_core::token;
use namada_proof_of_stake::rewards::estimate_staking_reward_rate;
use namada_proof_of_stake::rewards::{
estimate_staking_reward_rate, PosRewardsRates,
};
use namada_state::{DBIter, StorageHasher, DB};
use namada_token::{
get_effective_total_native_supply, read_denom, read_total_supply, Dec,
get_effective_total_native_supply, read_denom, read_total_supply,
};

use crate::queries::RequestCtx;
Expand All @@ -14,7 +16,7 @@ router! {TOKEN,
( "denomination" / [token: Address] ) -> Option<token::Denomination> = denomination,
( "total_supply" / [token: Address] ) -> token::Amount = total_supply,
( "effective_native_supply" ) -> token::Amount = effective_native_supply,
( "staking_rewards_rate" ) -> Dec = staking_rewards_rate,
( "staking_rewards_rate" ) -> PosRewardsRates = staking_rewards_rate,
}

/// Get the number of decimal places (in base 10) for a
Expand Down Expand Up @@ -56,7 +58,7 @@ where
/// Get the effective total supply of the native token
fn staking_rewards_rate<D, H, V, T>(
ctx: RequestCtx<'_, D, H, V, T>,
) -> namada_storage::Result<Dec>
) -> namada_storage::Result<PosRewardsRates>
where
D: 'static + DB + for<'iter> DBIter<'iter> + Sync,
H: 'static + StorageHasher + Sync,
Expand Down
4 changes: 2 additions & 2 deletions crates/sdk/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ use namada_ibc::storage::{
use namada_io::{display_line, edisplay_line, Client, Io};
use namada_parameters::{storage as params_storage, EpochDuration};
use namada_proof_of_stake::parameters::PosParams;
use namada_proof_of_stake::rewards::PosRewardsRates;
use namada_proof_of_stake::types::{
BondsAndUnbondsDetails, CommissionPair, LivenessInfo, ValidatorMetaData,
WeightedValidator,
};
use namada_state::LastBlock;
use namada_token::masp::MaspTokenRewardData;
use namada_token::Dec;
use namada_tx::data::{BatchedTxResult, DryRunResult, ResultCode, TxResult};
use namada_tx::event::{Batch as BatchAttr, Code as CodeAttr};
use serde::Serialize;
Expand Down Expand Up @@ -241,7 +241,7 @@ pub async fn get_effective_native_supply<C: Client + Sync>(
/// Query the effective total supply of the native token
pub async fn get_staking_rewards_rate<C: Client + Sync>(
client: &C,
) -> Result<Dec, error::Error> {
) -> Result<PosRewardsRates, error::Error> {
convert_response::<C, _>(
RPC.vp().token().staking_rewards_rate(client).await,
)
Expand Down
3 changes: 3 additions & 0 deletions crates/tests/src/integration/ledger_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,9 @@ fn pos_rewards() -> Result<()> {
let _res = captured
.matches(r"Current annual staking rewards rate: 63.483")
.expect("Test failed");
let _res = captured
.matches(r"PoS inflation rate: 0.066")
.expect("Test failed");

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion genesis/hardware/parameters.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ epochs_per_year = 31_536_000
# The multiplier for masp epochs
masp_epoch_multiplier = 2
# Max gas for block
max_block_gas = 25_000_000
max_block_gas = 15_000_000
# Masp fee payment gas limit
masp_fee_payment_gas_limit = 250_000
# Gas scale
Expand Down
2 changes: 1 addition & 1 deletion genesis/localnet/parameters.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ epochs_per_year = 31_536_000
# The multiplier for masp epochs
masp_epoch_multiplier = 2
# Max gas for block
max_block_gas = 25_000_000
max_block_gas = 15_000_000
# Masp fee payment gas limit
masp_fee_payment_gas_limit = 250_000
# Gas scale
Expand Down
2 changes: 1 addition & 1 deletion genesis/starter/parameters.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ epochs_per_year = 31_536_000
# The multiplier for masp epochs
masp_epoch_multiplier = 2
# Max gas for block
max_block_gas = 25_000_000
max_block_gas = 15_000_000
# Masp fee payment gas limit
masp_fee_payment_gas_limit = 250_000
# Gas scale
Expand Down

0 comments on commit 2107072

Please sign in to comment.