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

Inflation system and PoS rewards #388

Closed
wants to merge 105 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
f787667
client: add a block query to print hash, height and time of a block
tzemanovic Oct 20, 2022
ca3608d
changelog: add #658
tzemanovic Oct 20, 2022
ea2d533
test/e2e/helpers: add a helper to query and parse block height
tzemanovic Oct 20, 2022
8c3ec0e
Change fundamental unit of native stoken token from micro to nano units
brentstone Aug 30, 2022
c8b621f
change `votes_per_token` to 1/100 per fundamental token unit (namnam)
brentstone Aug 30, 2022
2a14756
replace f64 with Decimal in token conversions
brentstone Sep 5, 2022
1853ffc
change back to 10^6 namnam = 1 nam, votes_per_token = 1 namnam
brentstone Sep 8, 2022
5e52372
add PD controller used to determine inflation per epoch
brentstone Aug 26, 2022
02967bd
add objects for PoS rewards
brentstone Aug 26, 2022
52a6ad0
add some TODOs and use inflation module
brentstone Aug 28, 2022
4d51f33
clarify+rename 'epoch_storage_key' as 'epoch_duration_storage_key'
brentstone Aug 29, 2022
86d4786
mint_tokens function for inflation
brentstone Aug 29, 2022
0ae9c2e
use rust_decimal for inflation calculations
brentstone Aug 29, 2022
d10db6b
add max_staking_reward_rate to PosParams
brentstone Aug 29, 2022
42c8f21
apply inflation starting from within finalize_block() when a new epoc…
brentstone Aug 29, 2022
f02e1ae
Distribute rewards from PoS address
brentstone Aug 29, 2022
beba5c1
fix RewardsError
brentstone Aug 29, 2022
8044eb5
fmt
brentstone Aug 29, 2022
d4ad5b3
add missing use statements + fmt
brentstone Aug 29, 2022
0e55a73
read PoS address
brentstone Aug 29, 2022
f7c0f21
code documentation cleaning
brentstone Aug 29, 2022
e7a8b5a
add total supply key for native staking token (NAM)
brentstone Aug 31, 2022
1d32075
Write total supply of native staking token (NAM) to storage at genesi…
brentstone Aug 31, 2022
b875e92
more for writing total staking token supply to storage
brentstone Sep 1, 2022
33816b7
get block proposer and validator voting info from tendermint
brentstone Sep 1, 2022
89e700a
Refactor storage of total token supply
brentstone Sep 2, 2022
e97eb1d
Refactor VoteInfo struct to be defined in PoS rather than apps
brentstone Sep 2, 2022
55d4033
Get block proposer and signers to use in rewards distribution
brentstone Sep 2, 2022
4207c9e
update Cargo.lock and Cargo.toml files
brentstone Sep 2, 2022
f35ce18
remove BasisPoints and change relevant parameters to Decimal type
brentstone Sep 8, 2022
4bd313a
upgrade rust_decimal to latest version
brentstone Sep 8, 2022
1af54e0
add fns to multiply Decimal and integer type, return truncated integer
brentstone Sep 8, 2022
8311fb0
add new parameters needed for rewards PD controller to the Parameters…
brentstone Sep 8, 2022
1fb41ce
more decimal_mult function uses
brentstone Sep 8, 2022
ba1a955
update rust_decimal in wasms
brentstone Sep 8, 2022
47e85e9
rename `votes_per_token` to `tm_votes_per_token` since this will only…
brentstone Sep 9, 2022
f9820a7
update max inflation rate in params (formerly max_staking_rewards_rate)
brentstone Sep 9, 2022
6aee580
add target_staked_ratio to PoS params
brentstone Sep 9, 2022
89483df
add storage key for total staked tokens, write at genesis (still need…
brentstone Sep 9, 2022
1846f8a
refactor and upgrade apply_inflation and rewards controller, includin…
brentstone Sep 10, 2022
d6a615d
cleanup documentation, var names, make fmt
brentstone Sep 10, 2022
61e5f86
clean up distribute_rewards, remove VotingPower within
brentstone Sep 10, 2022
6c3bec6
specify read or write intentions for parameters storage keys
brentstone Sep 12, 2022
9f8af8f
fix correct inner type of ValidationError::TotalVotingPowerTooLarge
brentstone Sep 12, 2022
b2c4c9c
refactor out VotingPower(Delta) in pos crate, distinguish total and v…
brentstone Sep 14, 2022
36d2196
fix bug from rebase: make fundamental unit of whole token to be micro
brentstone Sep 16, 2022
b5c4aa7
continue refactoring away VotingPower
brentstone Sep 16, 2022
d91d28d
refactor VotingPower out of PoS VP
brentstone Sep 16, 2022
8982bba
various small changes + fmt
brentstone Sep 16, 2022
452289a
rename reward_rate -> inflation_rate for pos
brentstone Sep 18, 2022
34d2b68
Update wasm tx_(un)bond with VotingPower removal
brentstone Sep 20, 2022
be9f147
change `validator_total_deltas` -> `validator_deltas`
brentstone Sep 20, 2022
edbe2ad
keep voting_power as a possible client query
brentstone Sep 20, 2022
12b438f
more voting_power removal and accurate variable renaming
brentstone Sep 20, 2022
d6c2c20
documentation updates + unused imports removal
brentstone Sep 20, 2022
c269828
make fmt
brentstone Sep 20, 2022
c848a3b
add `min_validator_stake` to `PosParams` with arbitrary default value
brentstone Sep 20, 2022
b45ea1f
fix default value of epochs_per_year
brentstone Sep 20, 2022
dec0ba7
Update rewards parameters and distribution
brentstone Sep 20, 2022
ef7def6
Cargo.lock files
brentstone Sep 20, 2022
69ab0f1
update docs, error handling, storage reading in finalize_block
brentstone Sep 21, 2022
de92acf
introduce validator commission rate and changes
brentstone Sep 21, 2022
a9b8f35
remove `total_staked_tokens` as a storage value
brentstone Sep 21, 2022
759db5c
storage keys for new validator sets (consensus, below_(capacity|thres…
brentstone Sep 21, 2022
b2bf704
fmt, doc cleanup, renaming, better errors
brentstone Sep 21, 2022
2b47eb7
update toml files with latest parameters and values
brentstone Sep 21, 2022
2b941b6
introduce validator rewards products into storage
brentstone Sep 22, 2022
efe25df
refactor reward distribution using block reward accumulators and rewa…
brentstone Sep 22, 2022
86783c7
get number of blocks in the epoch at the end of the epoch
brentstone Sep 22, 2022
1fd3f87
update `current_epoch` usage and fix accumulator bug
brentstone Sep 22, 2022
c2ac11c
cleaner use statements
brentstone Sep 22, 2022
32a495a
require commission rate input data for new validators
brentstone Sep 23, 2022
2e08fe3
storage: last known rewards product for validators that leave the con…
brentstone Sep 23, 2022
f89b15f
update use of reward accumulator and delegation rewards products
brentstone Sep 23, 2022
273637b
remove validator staking rewards address
brentstone Sep 24, 2022
76807cd
make fmt
brentstone Sep 25, 2022
3d38030
epoched commission rate and tx for validator to change their rate
brentstone Sep 27, 2022
78cc6f7
fix documentation
brentstone Sep 27, 2022
7bb4530
small updates after rebase
brentstone Sep 27, 2022
756fc57
commission rate: query + refactor validator change tx
brentstone Sep 28, 2022
633737f
remove remaining staking_reward account and key items
brentstone Sep 30, 2022
c285dfe
fix: write all fields in Parameters storage in `init_storage`
brentstone Sep 30, 2022
5612313
fmt, clean up documentation, debugging statements
brentstone Oct 3, 2022
31d46a9
initialize staked_ratio as 0.0 in storage
brentstone Oct 11, 2022
c5a9195
better errors
brentstone Oct 11, 2022
b2ef1a2
consensus voting information in storage for the previous block
brentstone Oct 11, 2022
0f4c106
fix calculation and writing of staked NAM ratio at genesis
brentstone Oct 11, 2022
4996559
refactor read+write of some Rewards objects
brentstone Oct 12, 2022
402d2d7
refactor rewards, store last block proposer instead of votes
brentstone Oct 12, 2022
9458c66
storage change: last inflation rate -> last inflation token amount
brentstone Oct 18, 2022
e61e775
make inflation gain parameters only mutable by gov and not written to…
brentstone Oct 18, 2022
ff491d0
align inflation mechanism with latest spec
brentstone Oct 18, 2022
cea2b56
update rewards/inflation execution and docs
brentstone Oct 18, 2022
808f668
remove old debug statements, commented code
brentstone Oct 21, 2022
4cac0e3
fix initial staked ratio parameter at genesis
brentstone Oct 21, 2022
8d28564
get bonded stake of a block's signing validators from namada rather t…
brentstone Oct 21, 2022
3d4fbbd
cleaning after rebasing off of v0.8.1
brentstone Oct 24, 2022
838f29d
change how we import tendermint block vote info into namada
brentstone Oct 24, 2022
284cb49
store proposer address of both current and last block (needed for ABCI+)
brentstone Oct 24, 2022
a313170
conditional compile for tracking block voting info depending on tende…
brentstone Oct 24, 2022
49f0ab6
wasm checksums
brentstone Oct 24, 2022
5549411
fmt and Cargo.lock files
brentstone Oct 24, 2022
1cad325
add rust_decimal to wasms toml
brentstone Oct 24, 2022
b13f685
clippy fixes
brentstone Oct 24, 2022
c9cfe14
wasm: fix tx_unbond bug + misc small updates
brentstone Oct 25, 2022
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/features/658-add-client-block-query.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Client: Add a command to query the last committed block's hash, height and
timestamp. ([#658](https://github.com/anoma/namada/issues/658))
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions apps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ tracing-subscriber = {version = "0.3.7", features = ["env-filter"]}
websocket = "0.26.2"
winapi = "0.3.9"
bimap = {version = "0.6.2", features = ["serde"]}
rust_decimal = "1.26.1"
rust_decimal_macros = "1.26.1"

[dev-dependencies]
namada = {path = "../shared", features = ["testing", "wasm-runtime"]}
Expand Down
6 changes: 6 additions & 0 deletions apps/src/bin/anoma-client/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ pub async fn main() -> Result<()> {
Sub::QueryEpoch(QueryEpoch(args)) => {
rpc::query_epoch(args).await;
}
Sub::QueryBlock(QueryBlock(args)) => {
rpc::query_block(args).await;
}
Sub::QueryBalance(QueryBalance(args)) => {
rpc::query_balance(ctx, args).await;
}
Expand All @@ -61,6 +64,9 @@ pub async fn main() -> Result<()> {
Sub::QueryVotingPower(QueryVotingPower(args)) => {
rpc::query_voting_power(ctx, args).await;
}
Sub::QueryCommissionRate(QueryCommissionRate(args)) => {
rpc::query_commission_rate(ctx, args).await;
}
Sub::QuerySlashes(QuerySlashes(args)) => {
rpc::query_slashes(ctx, args).await;
}
Expand Down
122 changes: 114 additions & 8 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ pub mod cmds {
.subcommand(Withdraw::def().display_order(2))
// Queries
.subcommand(QueryEpoch::def().display_order(3))
.subcommand(QueryBlock::def().display_order(3))
.subcommand(QueryBalance::def().display_order(3))
.subcommand(QueryBonds::def().display_order(3))
.subcommand(QueryVotingPower::def().display_order(3))
Expand Down Expand Up @@ -198,6 +199,7 @@ pub mod cmds {
let unbond = Self::parse_with_ctx(matches, Unbond);
let withdraw = Self::parse_with_ctx(matches, Withdraw);
let query_epoch = Self::parse_with_ctx(matches, QueryEpoch);
let query_block = Self::parse_with_ctx(matches, QueryBlock);
let query_balance = Self::parse_with_ctx(matches, QueryBalance);
let query_bonds = Self::parse_with_ctx(matches, QueryBonds);
let query_voting_power =
Expand All @@ -224,6 +226,7 @@ pub mod cmds {
.or(unbond)
.or(withdraw)
.or(query_epoch)
.or(query_block)
.or(query_balance)
.or(query_bonds)
.or(query_voting_power)
Expand Down Expand Up @@ -283,9 +286,11 @@ pub mod cmds {
Unbond(Unbond),
Withdraw(Withdraw),
QueryEpoch(QueryEpoch),
QueryBlock(QueryBlock),
QueryBalance(QueryBalance),
QueryBonds(QueryBonds),
QueryVotingPower(QueryVotingPower),
QueryCommissionRate(QueryCommissionRate),
QuerySlashes(QuerySlashes),
QueryRawBytes(QueryRawBytes),
QueryProposal(QueryProposal),
Expand Down Expand Up @@ -936,6 +941,25 @@ pub mod cmds {
}
}

#[derive(Clone, Debug)]
pub struct QueryBlock(pub args::Query);

impl SubCmd for QueryBlock {
const CMD: &'static str = "block";

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

fn def() -> App {
App::new(Self::CMD)
.about("Query the last committed block.")
.add_args::<args::Query>()
}
}

#[derive(Clone, Debug)]
pub struct QueryBalance(pub args::QueryBalance);

Expand Down Expand Up @@ -993,6 +1017,25 @@ pub mod cmds {
}
}

#[derive(Clone, Debug)]
pub struct QueryCommissionRate(pub args::QueryCommissionRate);

impl SubCmd for QueryCommissionRate {
const CMD: &'static str = "commission-rate";

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

fn def() -> App {
App::new(Self::CMD)
.about("Query commission rate.")
.add_args::<args::QueryCommissionRate>()
}
}

#[derive(Clone, Debug)]
pub struct QuerySlashes(pub args::QuerySlashes);

Expand Down Expand Up @@ -1255,6 +1298,7 @@ pub mod args {
use namada::types::storage::{self, Epoch};
use namada::types::token;
use namada::types::transaction::GasLimit;
use rust_decimal::Decimal;

use super::context::{WalletAddress, WalletKeypair, WalletPublicKey};
use super::utils::*;
Expand Down Expand Up @@ -1283,6 +1327,7 @@ pub mod args {
const CHAIN_ID_PREFIX: Arg<ChainIdPrefix> = arg("chain-prefix");
const CODE_PATH: Arg<PathBuf> = arg("code-path");
const CODE_PATH_OPT: ArgOpt<PathBuf> = CODE_PATH.opt();
const COMMISSION_RATE: Arg<Decimal> = arg("commission-rate");
const CONSENSUS_TIMEOUT_COMMIT: ArgDefault<Timeout> = arg_default(
"consensus-timeout-commit",
DefaultFn(|| Timeout::from_str("1s").unwrap()),
Expand Down Expand Up @@ -1314,6 +1359,8 @@ pub mod args {

const LEDGER_ADDRESS: Arg<TendermintAddress> = arg("ledger-address");
const LOCALHOST: ArgFlag = flag("localhost");
const MAX_COMMISSION_RATE_CHANGE: Arg<Decimal> =
arg("max-commission-rate-change");
const MODE: ArgOpt<String> = arg_opt("mode");
const NET_ADDRESS: Arg<SocketAddr> = arg("net-address");
const NFT_ADDRESS: Arg<Address> = arg("nft-address");
Expand All @@ -1329,7 +1376,6 @@ pub mod args {
const RAW_ADDRESS_OPT: ArgOpt<Address> = RAW_ADDRESS.opt();
const RAW_PUBLIC_KEY_OPT: ArgOpt<common::PublicKey> = arg_opt("public-key");
const REWARDS_CODE_PATH: ArgOpt<PathBuf> = arg_opt("rewards-code-path");
const REWARDS_KEY: ArgOpt<WalletPublicKey> = arg_opt("rewards-key");
const SCHEME: ArgDefault<SchemeType> =
arg_default("scheme", DefaultFn(|| SchemeType::Ed25519));
const SIGNER: ArgOpt<WalletAddress> = arg_opt("signer");
Expand Down Expand Up @@ -1567,8 +1613,9 @@ pub mod args {
pub scheme: SchemeType,
pub account_key: Option<WalletPublicKey>,
pub consensus_key: Option<WalletKeypair>,
pub rewards_account_key: Option<WalletPublicKey>,
pub protocol_key: Option<WalletPublicKey>,
pub commission_rate: Decimal,
pub max_commission_rate_change: Decimal,
pub validator_vp_code_path: Option<PathBuf>,
pub rewards_vp_code_path: Option<PathBuf>,
pub unsafe_dont_encrypt: bool,
Expand All @@ -1581,8 +1628,10 @@ pub mod args {
let scheme = SCHEME.parse(matches);
let account_key = VALIDATOR_ACCOUNT_KEY.parse(matches);
let consensus_key = VALIDATOR_CONSENSUS_KEY.parse(matches);
let rewards_account_key = REWARDS_KEY.parse(matches);
let protocol_key = PROTOCOL_KEY.parse(matches);
let commission_rate = COMMISSION_RATE.parse(matches);
let max_commission_rate_change =
MAX_COMMISSION_RATE_CHANGE.parse(matches);
let validator_vp_code_path = VALIDATOR_CODE_PATH.parse(matches);
let rewards_vp_code_path = REWARDS_CODE_PATH.parse(matches);
let unsafe_dont_encrypt = UNSAFE_DONT_ENCRYPT.parse(matches);
Expand All @@ -1592,8 +1641,9 @@ pub mod args {
scheme,
account_key,
consensus_key,
rewards_account_key,
protocol_key,
commission_rate,
max_commission_rate_change,
validator_vp_code_path,
rewards_vp_code_path,
unsafe_dont_encrypt,
Expand All @@ -1617,14 +1667,19 @@ pub mod args {
"A consensus key for the validator account. A new one \
will be generated if none given.",
))
.arg(REWARDS_KEY.def().about(
"A public key for the staking reward account. A new one \
will be generated if none given.",
))
.arg(PROTOCOL_KEY.def().about(
"A public key for signing protocol transactions. A new \
one will be generated if none given.",
))
.arg(COMMISSION_RATE.def().about(
"The commission rate charged by the validator for \
delegation rewards. This is a required parameter.",
))
.arg(MAX_COMMISSION_RATE_CHANGE.def().about(
"The maximum change per epoch in the commission rate \
charged by the validator for delegation rewards. This is \
a required parameter.",
))
.arg(VALIDATOR_CODE_PATH.def().about(
"The path to the validity predicate WASM code to be used \
for the validator account. Uses the default validator VP \
Expand Down Expand Up @@ -2169,6 +2224,41 @@ pub mod args {
}
}

/// Query PoS commission rate
#[derive(Clone, Debug)]
pub struct QueryCommissionRate {
/// Common query args
pub query: Query,
/// Address of a validator
pub validator: Option<WalletAddress>,
/// Epoch in which to find commission rate
pub epoch: Option<Epoch>,
}

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

fn def(app: App) -> App {
app.add_args::<Query>()
.arg(VALIDATOR_OPT.def().about(
"The validator's address whose commission rate to query.",
))
.arg(EPOCH.def().about(
"The epoch at which to query (last committed, if not \
specified).",
))
}
}

/// Query PoS slashes
#[derive(Clone, Debug)]
pub struct QuerySlashes {
Expand Down Expand Up @@ -2668,6 +2758,8 @@ pub mod args {
#[derive(Clone, Debug)]
pub struct InitGenesisValidator {
pub alias: String,
pub commission_rate: Decimal,
pub max_commission_rate_change: Decimal,
pub net_address: SocketAddr,
pub unsafe_dont_encrypt: bool,
pub key_scheme: SchemeType,
Expand All @@ -2676,6 +2768,9 @@ pub mod args {
impl Args for InitGenesisValidator {
fn parse(matches: &ArgMatches) -> Self {
let alias = ALIAS.parse(matches);
let commission_rate = COMMISSION_RATE.parse(matches);
let max_commission_rate_change =
MAX_COMMISSION_RATE_CHANGE.parse(matches);
let net_address = NET_ADDRESS.parse(matches);
let unsafe_dont_encrypt = UNSAFE_DONT_ENCRYPT.parse(matches);
let key_scheme = SCHEME.parse(matches);
Expand All @@ -2684,6 +2779,8 @@ pub mod args {
net_address,
unsafe_dont_encrypt,
key_scheme,
commission_rate,
max_commission_rate_change,
}
}

Expand All @@ -2694,6 +2791,15 @@ pub mod args {
Anoma uses port `26656` for P2P connections by default, \
but you can configure a different value.",
))
.arg(COMMISSION_RATE.def().about(
"The commission rate charged by the validator for \
delegation rewards. This is a required parameter.",
))
.arg(MAX_COMMISSION_RATE_CHANGE.def().about(
"The maximum change per epoch in the commission rate \
charged by the validator for delegation rewards. This is \
a required parameter.",
))
.arg(UNSAFE_DONT_ENCRYPT.def().about(
"UNSAFE: Do not encrypt the generated keypairs. Do not \
use this for keys used in a live network.",
Expand Down
Loading