diff --git a/.changelog/unreleased/improvements/3940-small-tings.md b/.changelog/unreleased/improvements/3940-small-tings.md new file mode 100644 index 0000000000..9fc72d6634 --- /dev/null +++ b/.changelog/unreleased/improvements/3940-small-tings.md @@ -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)) \ No newline at end of file diff --git a/crates/apps_lib/src/client/rpc.rs b/crates/apps_lib/src/client/rpc.rs index ab8d0b2285..7814c2db31 100644 --- a/crates/apps_lib/src/client/rpc.rs +++ b/crates/apps_lib/src/client/rpc.rs @@ -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; @@ -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, @@ -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(), @@ -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 ); } @@ -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 = query_storage_value(context.client(), &key) .await .expect("Parameter should be defined."); @@ -1367,7 +1373,11 @@ pub async fn query_effective_native_supply(context: &N) { /// Query the staking rewards rate estimate pub async fn query_staking_rewards_rate(context: &N) { - let rewards_rate = unwrap_client_response::( + display_line!(context.io(), "Querying staking rewards rates..."); + let PosRewardsRates { + staking_rewards_rate, + inflation_rate, + } = unwrap_client_response::( RPC.vp() .token() .staking_rewards_rate(context.client()) @@ -1375,8 +1385,10 @@ pub async fn query_staking_rewards_rate(context: &N) { ); 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 ); } diff --git a/crates/governance/src/cli/validation.rs b/crates/governance/src/cli/validation.rs index c904cbfeca..44719d2654 100644 --- a/crates/governance/src/cli/validation.rs +++ b/crates/governance/src/cli/validation.rs @@ -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 diff --git a/crates/proof_of_stake/src/error.rs b/crates/proof_of_stake/src/error.rs index 40b1b46592..165cec9b7a 100644 --- a/crates/proof_of_stake/src/error.rs +++ b/crates/proof_of_stake/src/error.rs @@ -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}")] diff --git a/crates/proof_of_stake/src/rewards.rs b/crates/proof_of_stake/src/rewards.rs index 441a73d6d4..f43756a857 100644 --- a/crates/proof_of_stake/src/rewards.rs +++ b/crates/proof_of_stake/src/rewards.rs @@ -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}; @@ -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)] @@ -661,7 +670,7 @@ where /// Compute an estimation of the most recent staking rewards rate. pub fn estimate_staking_reward_rate( storage: &S, -) -> Result +) -> Result where S: StorageRead, Parameters: parameters::Read, @@ -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)] @@ -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<_>, diff --git a/crates/sdk/src/queries/vp/token.rs b/crates/sdk/src/queries/vp/token.rs index 9d232696cb..7b90ea5ee9 100644 --- a/crates/sdk/src/queries/vp/token.rs +++ b/crates/sdk/src/queries/vp/token.rs @@ -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; @@ -14,7 +16,7 @@ router! {TOKEN, ( "denomination" / [token: Address] ) -> Option = 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 @@ -56,7 +58,7 @@ where /// Get the effective total supply of the native token fn staking_rewards_rate( ctx: RequestCtx<'_, D, H, V, T>, -) -> namada_storage::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, diff --git a/crates/sdk/src/rpc.rs b/crates/sdk/src/rpc.rs index 001cc7a716..52dbf06bf3 100644 --- a/crates/sdk/src/rpc.rs +++ b/crates/sdk/src/rpc.rs @@ -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; @@ -241,7 +241,7 @@ pub async fn get_effective_native_supply( /// Query the effective total supply of the native token pub async fn get_staking_rewards_rate( client: &C, -) -> Result { +) -> Result { convert_response::( RPC.vp().token().staking_rewards_rate(client).await, ) diff --git a/crates/tests/src/integration/ledger_tests.rs b/crates/tests/src/integration/ledger_tests.rs index 06df6dd049..e8eb72fdab 100644 --- a/crates/tests/src/integration/ledger_tests.rs +++ b/crates/tests/src/integration/ledger_tests.rs @@ -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(()) } diff --git a/genesis/hardware/parameters.toml b/genesis/hardware/parameters.toml index cda15160aa..4052dc2e2a 100644 --- a/genesis/hardware/parameters.toml +++ b/genesis/hardware/parameters.toml @@ -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 diff --git a/genesis/localnet/parameters.toml b/genesis/localnet/parameters.toml index 161e4da0ab..f17e55268f 100644 --- a/genesis/localnet/parameters.toml +++ b/genesis/localnet/parameters.toml @@ -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 diff --git a/genesis/starter/parameters.toml b/genesis/starter/parameters.toml index 79b53b6b1c..7877e723a3 100644 --- a/genesis/starter/parameters.toml +++ b/genesis/starter/parameters.toml @@ -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