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

Validator commission rates #695

Merged
merged 38 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
22d845b
replace floating point arithm from token module with rust_decimal
brentstone Aug 30, 2022
97523f4
[ci] wasm checksums update
github-actions[bot] Oct 26, 2022
d08da6e
changelog: #436
tzemanovic Oct 26, 2022
29eb68f
remove staking reward address from all code
brentstone Oct 25, 2022
020f6bf
remove staking reward address from genesis toml files
brentstone Oct 26, 2022
3eb21f7
client: remove staking rewards address from init-validator result
tzemanovic Oct 26, 2022
b54b5c0
wallet: remove validator rewards key
tzemanovic Oct 26, 2022
9852d28
remove staking rewards address from cli strings and docs strings
tzemanovic Oct 26, 2022
70fa58b
changelog: #687
tzemanovic Oct 26, 2022
da7bffc
introduce validator commission rate and changes
brentstone Sep 21, 2022
3fbc30e
require commission rate input data for new validators
brentstone Sep 23, 2022
4b88573
epoched commission rate and tx for validator to change their rate
brentstone Sep 27, 2022
4ff76d8
commission rate: query + refactor validator change tx
brentstone Sep 28, 2022
77dfff4
add missing commission rate-related instances
brentstone Oct 26, 2022
5b6565e
include and update `rust_decimal`
brentstone Oct 26, 2022
288bf33
bug fix from splitting this PR off of #388
brentstone Oct 26, 2022
3704ef6
cleaning: incl fmt + clippy
brentstone Oct 26, 2022
0e097d8
init validator: add commission rate required args for tests
brentstone Oct 26, 2022
80283b2
fix commission rate validation on validator initialization
brentstone Oct 28, 2022
9d8a0d0
improve docs
brentstone Oct 28, 2022
629e1c5
[ci] wasm checksums update
github-actions[bot] Oct 31, 2022
258b910
wasm tx test for changing validator commission rate
brentstone Nov 4, 2022
6610a65
fix error convention
brentstone Nov 4, 2022
563d218
commission change wasm tx test: fix and update validation
brentstone Nov 4, 2022
7d652e3
bug fix: consensus key validation error
brentstone Nov 4, 2022
9b4f2be
fix get of epoched commission rate before pipeline
brentstone Nov 4, 2022
6778fd0
add max change info to query of validator commission rate
brentstone Nov 4, 2022
b900354
fix pos state machine test
brentstone Nov 7, 2022
7b6de40
[ci] wasm checksums update
github-actions[bot] Nov 7, 2022
302a08c
changes in response to review comments
brentstone Nov 8, 2022
dcfd6af
validator VP that checks source and signature for a commission rate c…
brentstone Nov 9, 2022
9068938
add max commission rate info to validation and pos state machine test
brentstone Nov 9, 2022
9b175c4
fix: critical flaw in pos VP that was prematurely returning true
brentstone Nov 9, 2022
fea59bd
add vp validator to wasms
brentstone Nov 9, 2022
757ba1d
async tx to change validator commission rate
brentstone Nov 9, 2022
42b0bfa
addressing 2nd round of review comments
brentstone Nov 10, 2022
476877e
[ci] wasm checksums update
github-actions[bot] Nov 10, 2022
6b92f2c
changelog: add #695
tzemanovic Nov 10, 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/687-remove-staking-address.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- PoS: Removed staking reward addresses in preparation of auto-staked rewards
system. ([#687](https://github.com/anoma/namada/pull/687))
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/436-remove-f64.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Refactored token decimal formatting.
([#436](https://github.com/anoma/namada/pull/436))
17 changes: 17 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
3 changes: 3 additions & 0 deletions apps/src/bin/anoma-client/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,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
156 changes: 134 additions & 22 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ pub mod cmds {
QueryBalance(QueryBalance),
QueryBonds(QueryBonds),
QueryVotingPower(QueryVotingPower),
QueryCommissionRate(QueryCommissionRate),
QuerySlashes(QuerySlashes),
QueryRawBytes(QueryRawBytes),
QueryProposal(QueryProposal),
Expand Down Expand Up @@ -840,8 +841,8 @@ pub mod cmds {
fn def() -> App {
App::new(Self::CMD)
.about(
"Send a signed transaction to create a new validator and \
its staking reward account.",
"Send a signed transaction to create a new validator \
account.",
)
.add_args::<args::TxInitValidator>()
}
Expand Down Expand Up @@ -999,6 +1000,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 @@ -1194,9 +1214,9 @@ pub mod cmds {
fn def() -> App {
App::new(Self::CMD)
.about(
"Initialize genesis validator's address, staking reward \
address, consensus key, validator account key and \
staking rewards key and use it in the ledger's node.",
"Initialize genesis validator's address, consensus key \
and validator account key and use it in the ledger's \
node.",
)
.add_args::<args::InitGenesisValidator>()
}
Expand All @@ -1217,6 +1237,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 @@ -1245,6 +1266,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 @@ -1276,6 +1298,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 OWNER: ArgOpt<WalletAddress> = arg_opt("owner");
Expand All @@ -1289,8 +1313,6 @@ pub mod args {
const RAW_ADDRESS: Arg<Address> = arg("address");
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 @@ -1528,10 +1550,10 @@ 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 @@ -1542,21 +1564,22 @@ 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);
Self {
tx,
source,
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 @@ -1578,24 +1601,26 @@ 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. Expressed as a decimal between 0 and \
1. 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. \
Expressed as a decimal between 0 and 1. 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 \
if none specified.",
))
.arg(REWARDS_CODE_PATH.def().about(
"The path to the validity predicate WASM code to be used \
for the staking reward account. Uses the default staking \
reward VP if none specified.",
))
.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 Expand Up @@ -2070,6 +2095,77 @@ pub mod args {
}
}

#[derive(Clone, Debug)]
/// Commission rate change args
pub struct TxCommissionRateChange {
/// Common tx arguments
pub tx: Tx,
/// Validator address (should be self)
pub validator: WalletAddress,
/// Value to which the tx changes the commission rate
pub rate: Decimal,
}

impl Args for TxCommissionRateChange {
fn parse(matches: &ArgMatches) -> Self {
let tx = Tx::parse(matches);
let validator = VALIDATOR.parse(matches);
let rate = COMMISSION_RATE.parse(matches);
Self {
tx,
validator,
rate,
}
}

fn def(app: App) -> App {
app.add_args::<Query>()
.arg(VALIDATOR.def().about(
"The validator's address whose commission rate to change.",
))
.arg(
COMMISSION_RATE
.def()
.about("The desired new commission rate."),
)
}
}

/// Query PoS commission rate
#[derive(Clone, Debug)]
pub struct QueryCommissionRate {
/// Common query args
pub query: Query,
/// Address of a validator
pub validator: 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.parse(matches);
let epoch = EPOCH.parse(matches);
Self {
query,
validator,
epoch,
}
}

fn def(app: App) -> App {
app.add_args::<Query>()
.arg(VALIDATOR.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 @@ -2569,6 +2665,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 @@ -2577,6 +2675,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 @@ -2585,6 +2686,8 @@ pub mod args {
net_address,
unsafe_dont_encrypt,
key_scheme,
commission_rate,
max_commission_rate_change,
}
}

Expand All @@ -2595,6 +2698,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