Skip to content
This repository has been archived by the owner on Sep 28, 2023. It is now read-only.

Beneficiary #113

Closed
wants to merge 3 commits into from
Closed

Beneficiary #113

wants to merge 3 commits into from

Conversation

kaichaosun
Copy link

Pull Request Summary

Check list

  • added unit tests
  • updated documentation

Copy link
Member

@Dinonard Dinonard left a comment

Choose a reason for hiding this comment

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

Great work, that was super fast 😃

I've left some comments/questions and would like to hear your opinion.

///
/// The dispatch origin is the current beneficiary.
#[pallet::weight(10_000)]
pub fn update_rewards_beneficiary(
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps delegate_rewards_beneficiary?
Since this cannot be used by the staker, so it's more clear.

T::WeightInfo::claim_staker_without_restake()
})
.into())
Ok(Some(weight_info).into())
Copy link
Member

Choose a reason for hiding this comment

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

Is this a personal preference or was the approach before incorrect?

Copy link
Author

Choose a reason for hiding this comment

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

It's a personal preference, trying to make return logic simple and default based.

}

T::Currency::resolve_creating(&staker, reward_imbalance);
// Withdraw reward funds from the dapps staking pot
let reward_imbalance = T::Currency::withdraw(
Copy link
Member

Choose a reason for hiding this comment

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

What if this fails at this point?
What state do we leave the chain in?

Copy link
Author

Choose a reason for hiding this comment

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

The failed call will not affect the chain state, since the call by default is transactional.

Copy link
Member

Choose a reason for hiding this comment

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

You're right, after paritytech/substrate#11431.

let beneficiary = RewardsBeneficiary::<T>::get(&staker, &contract_id);
let mut weight_info = T::WeightInfo::claim_staker_without_restake();

if beneficiary.is_none() && should_restake_reward {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not fond of argument bloat, but perhaps the added check would be better suited inside fn should_restake_reward?

Copy link
Author

Choose a reason for hiding this comment

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

Sounds good!

Self::update_staker_info(&staker, &contract_id, staker_info);
Self::deposit_event(Event::<T>::Reward(staker, contract_id, era, staker_reward));
Self::deposit_event(Event::<T>::Reward(reward_account, contract_id, era, staker_reward));
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps this is confusing a bit - Reward event would be read as X staked on Y and received Z amount of reward for era N.

Right now, beneficiary could be an account that's not even part of dapps-staking, so it'd be even more confusing.

Could you share your opinion on this?
Is there an alternative solution you could propose?

Copy link
Author

Choose a reason for hiding this comment

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

Current Reward event reads as someone staked on Y and its beneficiary is X, X received Z amount of reward for era N.
Adding an extract field called staker makes sense for easily index on staker for reward events.

For UX, most users don't need to bother this beneficiary settings, by default the restake should just works fine. User only need to care about beneficiary if they are making a staking pool for others, delegate and beneficiary will make it clear in this case.

Instead of adding an extra storage, make the reward destination to include beneficiary seems more straight forward, but require more thorough design and changes.

Copy link
Member

Choose a reason for hiding this comment

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

Sure, I like the scenarios, even though this is just a dummy-pre-screening-task feature :)

Differentiating when stakers receive rewards and when it's just via a reward beneficiary is important if we want to be aware how much someone earned as a staker. With the modified event, we cannot tell whether the user received rewards as a beneficiary or as a nomination reward.

And love the proposal about reward destination 👍 😄 , was hoping for it!

@@ -1782,6 +1782,58 @@ fn claim_only_payout_is_ok() {
})
}

#[test]
Copy link
Member

Choose a reason for hiding this comment

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

Nice UT coverage! 👍

@Dinonard Dinonard closed this Dec 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants