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

rusk-wallet: Allow withdrawing of partial rewards #3041

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Daksh14
Copy link
Contributor

@Daksh14 Daksh14 commented Nov 22, 2024

Pass reward param to withdraw transaction function Add check for withdraw amount

Closes #2538

@Daksh14 Daksh14 requested review from welf, HDauven and moCello November 22, 2024 00:41
@Daksh14 Daksh14 force-pushed the withdraw_partial_rewards branch from 29acc9d to 407c04e Compare November 22, 2024 00:42
Copy link
Member

@moCello moCello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments, the biggest one being that I would have the stake-reward be an optional value. So that when the user doesn't specify anything, the entire reward is withdrawn.

@@ -194,6 +194,10 @@ pub(crate) enum Command {
#[arg(short, long)]
address: Option<Address>,

/// Amount of rewards to withdraw from the stake contract
#[arg(short, long)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not add short here as that option has caused clashes in the past and I see no problem with only allowing the stake-reward being passed as a long argument.

Copy link
Contributor Author

@Daksh14 Daksh14 Nov 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no problem in adding short. Those clashes happen if arguments have same starting alphabet, here -r or --reward shouldn't clash with anything. I'd like to keep it like all other arguments

Copy link
Member

@moCello moCello Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the default option should always only be long unless there is a good reason to add it as short as well.

@@ -194,6 +194,10 @@ pub(crate) enum Command {
#[arg(short, long)]
address: Option<Address>,

/// Amount of rewards to withdraw from the stake contract
#[arg(short, long)]
reward: Dusk,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to have the reward be an optional value. If None is given, we withdraw the entire reward.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree, if the person isnt aware they can specify the amount and they dont want to withdraw all of it then it will be a problem, will leave the user confused. Even if we document this behavior people arent gonna read it. I can add option to withdraw all but they will have to specify if they want to do so

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say that it's most likely that the user wants to withdraw all the funds so having this behavior activated by default makes sense to me.
And if not all funds should be withdrawn, then the user can specify so we don't sacrifice any functionality with my proposed solution.
We do however add friction with your suggestion since the user now needs to be aware and check the max funds available whenever she wants to retrieve the reward.

The case that the user is not aware of certain functionalities shouldn't guide our design decisions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Daksh14 I agree with Moana here. The approach she suggests would lead to the least amount of friction. Users will always have to end up requesting for their reward balance, even though the vast majority will want to withdraw their full reward balance anyway.

We should always design with Pareto principle in mind. Focus on the needs of the majority (80%), but make sure the minority (20%) can still achieve their goals

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amt is now optional and if its none then all the available rewards will be withdrawn @HDauven @moCello

@@ -628,6 +628,21 @@ impl<F: SecureWalletFile + Debug> Wallet<F> {

Ok(gas_prices)
}

/// Get the amount of stake rewards the user has
pub async fn get_stake_amount(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beware of the naming of functions. The stake-amount is not the same as the stake-reward.

I also don't think you really need this function, but that it makes more sense to use the get_stake_info method that is already implemented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need the helper function because get_stake_info is a method of the State which wallet keeps track off. I'll rename the function to get_stake_reward

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but get_stake_amount is also a method of the state. Indeed the first three lines of get_stake_amount can be replaces by self.stake_info(sender_index)

Mapping that output to one field of the stake-info doesn't justify an extra method to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and my appologies, I meant stake_info not get_stake_info in my first comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check the contents of get_stake_reward function. It requires a helper function because we need to access the state that means we have to be connected to the chain and be online which can be only accessed through the Wallet struct so it needs to be a method @moCello

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the function I'm referring to, in line 466 of the same file:

    /// Obtains stake information for a given address.
    pub async fn stake_info(
        &self,
        profile_idx: u8,
    ) -> Result<Option<StakeData>, Error> {
        self.state()?
            .fetch_stake(self.public_key(profile_idx)?)
            .await
    }

Afaics it does the same as the first lines of your proposed new function.

Accessing one field of the obtained stake-info, to me doesn't justify a new method on the wallet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the method to use the stake_info method now double check and let me know @moCello

rusk-wallet/src/wallet/transaction.rs Outdated Show resolved Hide resolved
welf
welf previously approved these changes Dec 2, 2024
Pass reward param to withdraw transaction function
Add check for withdraw amount
Rename helper method to be more correct
@Daksh14 Daksh14 force-pushed the withdraw_partial_rewards branch from 9de9242 to 42b32d6 Compare December 28, 2024 23:29
@Daksh14 Daksh14 force-pushed the withdraw_partial_rewards branch from 42b32d6 to d7770d7 Compare December 28, 2024 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rusk-wallet: Allow users to withdraw specific value from staking reward
4 participants