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

PoS rewards #1992

Merged
merged 19 commits into from
Nov 11, 2023
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
2 changes: 2 additions & 0 deletions .changelog/unreleased/features/1992-pos-rewards.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Implements a claim-based rewards system for PoS inflation.
([\#1992](https://github.com/anoma/namada/pull/1992))
1 change: 1 addition & 0 deletions .github/workflows/scripts/e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"e2e::ledger_tests::test_node_connectivity_and_consensus": 28,
"e2e::ledger_tests::test_epoch_sleep": 12,
"e2e::ledger_tests::wrapper_disposable_signer": 28,
"e2e::ledger_tests::pos_rewards": 44,
"e2e::wallet_tests::wallet_address_cmds": 1,
"e2e::wallet_tests::wallet_encrypted_key_cmds": 1,
"e2e::wallet_tests::wallet_encrypted_key_cmds_env_var": 1,
Expand Down
1 change: 1 addition & 0 deletions apps/src/lib/bench_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ pub const TX_CHANGE_VALIDATOR_COMMISSION_WASM: &str =
pub const TX_IBC_WASM: &str = "tx_ibc.wasm";
pub const TX_UNJAIL_VALIDATOR_WASM: &str = "tx_unjail_validator.wasm";
pub const TX_WITHDRAW_WASM: &str = "tx_withdraw.wasm";
pub const TX_CLAIM_REWARDS_WASM: &str = "tx_claim_rewards.wasm";
pub const TX_INIT_ACCOUNT_WASM: &str = "tx_init_account.wasm";
pub const TX_INIT_VALIDATOR_WASM: &str = "tx_init_validator.wasm";

Expand Down
64 changes: 64 additions & 0 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ pub mod cmds {
.subcommand(Unbond::def().display_order(2))
.subcommand(Withdraw::def().display_order(2))
.subcommand(Redelegate::def().display_order(2))
.subcommand(ClaimRewards::def().display_order(2))
.subcommand(TxCommissionRateChange::def().display_order(2))
// Ethereum bridge transactions
.subcommand(AddToEthBridgePool::def().display_order(3))
Expand Down Expand Up @@ -288,6 +289,7 @@ pub mod cmds {
let unbond = Self::parse_with_ctx(matches, Unbond);
let withdraw = Self::parse_with_ctx(matches, Withdraw);
let redelegate = Self::parse_with_ctx(matches, Redelegate);
let claim_rewards = Self::parse_with_ctx(matches, ClaimRewards);
let query_epoch = Self::parse_with_ctx(matches, QueryEpoch);
let query_account = Self::parse_with_ctx(matches, QueryAccount);
let query_transfers = Self::parse_with_ctx(matches, QueryTransfers);
Expand Down Expand Up @@ -334,6 +336,7 @@ pub mod cmds {
.or(unbond)
.or(withdraw)
.or(redelegate)
.or(claim_rewards)
.or(add_to_eth_bridge_pool)
.or(tx_update_steward_commission)
.or(tx_resign_steward)
Expand Down Expand Up @@ -409,6 +412,7 @@ pub mod cmds {
Bond(Bond),
Unbond(Unbond),
Withdraw(Withdraw),
ClaimRewards(ClaimRewards),
Redelegate(Redelegate),
AddToEthBridgePool(AddToEthBridgePool),
TxUpdateStewardCommission(TxUpdateStewardCommission),
Expand Down Expand Up @@ -1437,6 +1441,28 @@ pub mod cmds {
}
}

#[derive(Clone, Debug)]
pub struct ClaimRewards(pub args::ClaimRewards<args::CliTypes>);

impl SubCmd for ClaimRewards {
const CMD: &'static str = "claim-rewards";

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

fn def() -> App {
App::new(Self::CMD)
.about(
"Claim available rewards tokens from bonds that \
contributed in consensus.",
)
.add_args::<args::ClaimRewards<args::CliTypes>>()
}
}

#[derive(Clone, Debug)]
pub struct Redelegate(pub args::Redelegate<args::CliTypes>);

Expand Down Expand Up @@ -2663,6 +2689,7 @@ pub mod args {
"tx_update_steward_commission.wasm";
pub const TX_VOTE_PROPOSAL: &str = "tx_vote_proposal.wasm";
pub const TX_WITHDRAW_WASM: &str = "tx_withdraw.wasm";
pub const TX_CLAIM_REWARDS_WASM: &str = "tx_claim_rewards.wasm";
pub const TX_RESIGN_STEWARD: &str = "tx_resign_steward.wasm";

pub const VP_USER_WASM: &str = "vp_user.wasm";
Expand Down Expand Up @@ -4594,6 +4621,43 @@ pub mod args {
}
}

impl CliToSdk<ClaimRewards<SdkTypes>> for ClaimRewards<CliTypes> {
fn to_sdk(self, ctx: &mut Context) -> ClaimRewards<SdkTypes> {
let tx = self.tx.to_sdk(ctx);
let chain_ctx = ctx.borrow_chain_or_exit();
ClaimRewards::<SdkTypes> {
tx,
validator: chain_ctx.get(&self.validator),
source: self.source.map(|x| chain_ctx.get(&x)),
tx_code_path: self.tx_code_path.to_path_buf(),
}
}
}

impl Args for ClaimRewards<CliTypes> {
fn parse(matches: &ArgMatches) -> Self {
let tx = Tx::parse(matches);
let validator = VALIDATOR.parse(matches);
let source = SOURCE_OPT.parse(matches);
let tx_code_path = PathBuf::from(TX_CLAIM_REWARDS_WASM);
Self {
tx,
validator,
source,
tx_code_path,
}
}

fn def(app: App) -> App {
app.add_args::<Tx<CliTypes>>()
.arg(VALIDATOR.def().help("Validator address."))
.arg(SOURCE_OPT.def().help(
"Source address for claiming rewards for a bond. For \
self-bonds, the validator is also the source.",
))
}
}

impl CliToSdk<QueryConversions<SdkTypes>> for QueryConversions<CliTypes> {
fn to_sdk(self, ctx: &mut Context) -> QueryConversions<SdkTypes> {
QueryConversions::<SdkTypes> {
Expand Down
11 changes: 11 additions & 0 deletions apps/src/lib/cli/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,17 @@ impl CliApi {
let namada = ctx.to_sdk(&client, io);
tx::submit_withdraw(&namada, args).await?;
}
Sub::ClaimRewards(ClaimRewards(mut args)) => {
let client = client.unwrap_or_else(|| {
C::from_tendermint_address(
&mut args.tx.ledger_address,
)
});
client.wait_until_node_is_synced(io).await?;
let args = args.to_sdk(&mut ctx);
let namada = ctx.to_sdk(&client, io);
tx::submit_claim_rewards(&namada, args).await?;
}
Sub::Redelegate(Redelegate(mut args)) => {
let client = client.unwrap_or_else(|| {
C::from_tendermint_address(
Expand Down
22 changes: 22 additions & 0 deletions apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,28 @@ where
Ok(())
}

pub async fn submit_claim_rewards<'a, N: Namada<'a>>(
namada: &N,
args: args::ClaimRewards,
) -> Result<(), error::Error>
where
<N::Client as namada::ledger::queries::Client>::Error: std::fmt::Display,
{
let (mut tx, signing_data, _fee_unshield_epoch) =
args.build(namada).await?;
signing::generate_test_vector(namada, &tx).await?;

if args.tx.dump_tx {
tx::dump_tx(namada.io(), &args.tx, tx);
} else {
namada.sign(&mut tx, &args.tx, signing_data).await?;

namada.submit(tx, &args.tx).await?;
}

Ok(())
}

pub async fn submit_redelegate<'a, N: Namada<'a>>(
namada: &N,
args: args::Redelegate,
Expand Down
Loading
Loading