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

added counter for individual rewards #450

Merged

Conversation

Maar-io
Copy link
Member

@Maar-io Maar-io commented Sep 30, 2021

Adding new storage double map to use as counter for accrued rewards per (contract, staker)

  • add storage
  • increase it after claim() for stakers and the developer
  • delete after total unbonding
  • update check for all UTs

Add reward counter per contract

  • Add new element in EraStakingPoints struct and use as counter

@Maar-io Maar-io marked this pull request as draft September 30, 2021 16:50
@Maar-io Maar-io requested a review from Dinonard October 1, 2021 09:03
@Maar-io Maar-io marked this pull request as ready for review October 1, 2021 11:08
@Maar-io Maar-io requested a review from bobo-k2 October 1, 2021 11:09
@Maar-io Maar-io added this to In Progress in dApps staking Oct 1, 2021
@@ -86,12 +87,7 @@ pub enum SmartContract<AccountId> {
/// The ledger of a (bonded) stash.
#[derive(PartialEq, Eq, Clone, Encode, Decode, Default, RuntimeDebug)]
pub struct StakingLedger<Balance: HasCompact + Default> {
/// The total amount of the stash's balance that we are currently accounting for.
/// It's just `active` plus all the `unlocking` balances.
/// The total amount of the staker's balance that we are currently accounting for.
Copy link
Member

Choose a reason for hiding this comment

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

It no longer makes sense to keep this as struct.

Copy link
Member Author

Choose a reason for hiding this comment

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

removed struct

#[pallet::getter(fn reward_counter)]
pub(crate) type IndividualRewardCounter<T: Config> = StorageDoubleMap<
_,
Twox64Concat,
Copy link
Member

Choose a reason for hiding this comment

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

Since both key types are supplied from the outside, shouldn't we use secure hashing?

Also applies to the rest of the maps in dapps staking pallet.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's take this out of the scope of this PR.
I have created new todo for this
https://github.com/PlasmNetwork/Astar/projects/5#card-69947102

@@ -811,10 +826,19 @@ pub mod pallet {
}

/// Execute payout for stakers
Copy link
Member

Choose a reason for hiding this comment

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

Now it does more than that.

payout_stakers_and_return_total_reward?

Doc should also be updated.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

eras: EraIndex,
expected_era_reward: mock::Balance,
) {
println!("check_rewards_and_counter {:?}, user={:?}", contract, &user);
Copy link
Member

Choose a reason for hiding this comment

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

This should be removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

removed

@@ -72,6 +72,7 @@ pub struct EraStakingPoints<AccountId: Ord, Balance: HasCompact> {
/// Era when this contract was staked last time before this one.
/// In case only a single staking era exists, it will be set to that one. This indicates the final element in the chain.
former_staked_era: EraIndex,
paidout_rewards: Balance,
Copy link
Member

Choose a reason for hiding this comment

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

paid_out_rewards?

Or just 'claimed_rewards'?

Also add documentation.

Copy link
Member Author

Choose a reason for hiding this comment

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

renamed.
Added doc.

Comment on lines 130 to 131
#[pallet::getter(fn reward_counter)]
pub(crate) type IndividualRewardCounter<T: Config> = StorageDoubleMap<
Copy link
Member

Choose a reason for hiding this comment

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

Just a suggestion, but I'd replace the name. You're not 'counting' rewards, e.g. how many times rewards were given.
The name is just misleading, at least to me.

I'd suggest something like 'TotalRewardsEarned' (or claimed).

Copy link
Member Author

Choose a reason for hiding this comment

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

it is actually not total since one staker can stake on several contracts.
It is renamed to RewardsClaimed

&contract,
&staker1,
free_balance_staker1,
eras_eligible_for_reward as u32,
Copy link
Member

Choose a reason for hiding this comment

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

'as EraIndex' ?

Copy link
Member Author

Choose a reason for hiding this comment

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

replaced all instances

@Maar-io Maar-io merged commit 0fceb9e into feature/dapp-staking-pallet Oct 2, 2021
@Maar-io Maar-io deleted the feature/dapp-staker-total-reward branch October 2, 2021 08:45
dApps staking automation moved this from In Progress to Done Oct 2, 2021
Dinonard pushed a commit that referenced this pull request Oct 4, 2021
* added counter for individual rewards

* update claim UT

* added counter for rewards paid out to contract

* review rework

* review rework2
hoonsubin added a commit that referenced this pull request Oct 4, 2021
* re fork

* remove recursive limit

* add bond() bond_extra() set_controller()

* formatting fix

* Feature/dapp step1 (#407)

* dapps-staking step1. (#405)

* added unbond() withraw_unbonded()

* dapp_staking_bond_test_wip

* add EraFinder mock and test bonding not_ok

Co-authored-by: Dinonard <dino.pacandi@gmail.com>

* Expanded UT for bond()
Added UT for bond_extra() and set_controller()
Left some TODOs to discuss in review

* add unbond() UT

* withdraw_unbonded() UT

* UT granularization, various improvements

Co-authored-by: Mar.io <34627453+Maar-io@users.noreply.github.com>

* Feature/dapp step2 (#409)

* dapps-staking step1. (#405)

* added unbond() withraw_unbonded()

* dapp_staking_bond_test_wip

* add EraFinder mock and test bonding not_ok

Co-authored-by: Dinonard <dino.pacandi@gmail.com>

* Expanded UT for bond()
Added UT for bond_extra() and set_controller()
Left some TODOs to discuss in review

* add unbond() UT

* withdraw_unbonded() UT

* UT granularization, various improvements

* resolving some merge issues

* Feature/dapps register (#408)

* register + test

* added SmartContract struct

* removed ContractFinder trait

* Feature/dapp step1 (#407)

* dapps-staking step1. (#405)

* added unbond() withraw_unbonded()

* dapp_staking_bond_test_wip

* add EraFinder mock and test bonding not_ok

Co-authored-by: Dinonard <dino.pacandi@gmail.com>

* Expanded UT for bond()
Added UT for bond_extra() and set_controller()
Left some TODOs to discuss in review

* add unbond() UT

* withdraw_unbonded() UT

* UT granularization, various improvements

Co-authored-by: Mar.io <34627453+Maar-io@users.noreply.github.com>

* register + test

* added SmartContract struct

* removed ContractFinder trait

* add to runtime

* resolvimg merge issues

* fmt fix

Co-authored-by: Dinonard <3002868+Dinonard@users.noreply.github.com>

* review fixes. Added support for AlreadyUsedDeveloperAccount

* fmt fix

* moved helper register() on top

* fmt test file

* fmt fix after merge

Co-authored-by: Dinonard <dino.pacandi@gmail.com>
Co-authored-by: Dinonard <3002868+Dinonard@users.noreply.github.com>

* dapps-staking Era handling (#410)

* era handling and ForceEra

* remove reward distribution from on_initialize

* added new storage maps (#413)

* added new storage maps

* added comment for PalletEraRewards

* Dapps-staking register() refactoring (#414)

* register() refactoring

* updateds after review
register() updated with initial:
  ContractLastClaimed
  ContractLastStaked

* not needed empty insert for ContractLastClaimed and Staked

* Update Cargo.toml (#420) with license

* Feature/bond and stake (#415)

* Initial stake and unbond

* Initial implementation of bond and stake

* Finished bond_and_stake, start with UT

* UT update & staked era bug fix

* Added era reward struct

* Pallet constants for staking, bug fixes, new UTs

* Finalized unit test, ready for review

* fix compilation error for runtime

* documentation fixes

* addressing review comments

Weight calculation will be implemented in a follow-up PR.

* License move to dapps (#421)

* Feature/unbond unstake and withdraw (#424)

* unbond,unstake&withdraw initial commit

* additional UTs for unbond_and_withdraw

* more UTs and bug fixes

* added test utils, minor modifications

* dapps staking claim (#422)

* initial claim() function

* fmt fix and license info

* added clearing of storage until claim era

* UT with several staking for a contract

* sceleton for payour_stakers()

* more checks on claim()

* fixes after running UT

* review fixes

* more review fixesž

* optimize storage use during payout

* minor comment fix

* added UT for 2 contracts

* minor merge fix

* claim() review updates

* use map instead of vec of vec, plus fmt

* renaming and adding comments to claim algorithm

* remove unnecessary cloning

* implemented accumulator for era rewards

* Feature/dapp shiden15 (#429)

* Added DealWithFees handler for tx fees (#391)

* Temporary disable custom signatures pallet (#401)

* Temporary disable custom signatures pallet

* Bump version

* Fix custom signatures pallet (#402)

* Added stale transaction traction
* Added constant transaction fee

* EVM contracts integration (#397)

* Added EVM into runtime

* Added EVM support into collator

* Enabled Ethereum-compatible RPC
* Added Frontier consensus middleware

* Fix frontier consensus

* Fix frontier invalid transaction bug

* Added Shibuya testnet

* Fix EVM gas fee charge (#411)

* Fix pallet custom signatures issues (#412)

* Fix pallet custom signatures issues

* Update Cargo.lock

* Development chain with EVM and Ink contracts (#423)

* Development chain with EVM and Ink contracts

* Fix code formatting

* Added local chain properties

* Enable EVM withdraws & customsig fixes (#419)

* Enable EVM withdraws & customsig fixes

* Enable customsig pallet for shiden

* Fix EVM native tx conversion (#426)

* Fix EVM native tx conversion

* Increase Alice development endowment

* Update Cargo.lock

* Added staking EVM precompiles (#425)

* re fork

* remove recursive limit

* add bond() bond_extra() set_controller()

* formatting fix

* Feature/dapp step1 (#407)

* dapps-staking step1. (#405)

* added unbond() withraw_unbonded()

* dapp_staking_bond_test_wip

* add EraFinder mock and test bonding not_ok

Co-authored-by: Dinonard <dino.pacandi@gmail.com>

* Expanded UT for bond()
Added UT for bond_extra() and set_controller()
Left some TODOs to discuss in review

* add unbond() UT

* withdraw_unbonded() UT

* UT granularization, various improvements

Co-authored-by: Mar.io <34627453+Maar-io@users.noreply.github.com>

* Feature/dapp step2 (#409)

* dapps-staking step1. (#405)

* added unbond() withraw_unbonded()

* dapp_staking_bond_test_wip

* add EraFinder mock and test bonding not_ok

Co-authored-by: Dinonard <dino.pacandi@gmail.com>

* Expanded UT for bond()
Added UT for bond_extra() and set_controller()
Left some TODOs to discuss in review

* add unbond() UT

* withdraw_unbonded() UT

* UT granularization, various improvements

* resolving some merge issues

* Feature/dapps register (#408)

* register + test

* added SmartContract struct

* removed ContractFinder trait

* Feature/dapp step1 (#407)

* dapps-staking step1. (#405)

* added unbond() withraw_unbonded()

* dapp_staking_bond_test_wip

* add EraFinder mock and test bonding not_ok

Co-authored-by: Dinonard <dino.pacandi@gmail.com>

* Expanded UT for bond()
Added UT for bond_extra() and set_controller()
Left some TODOs to discuss in review

* add unbond() UT

* withdraw_unbonded() UT

* UT granularization, various improvements

Co-authored-by: Mar.io <34627453+Maar-io@users.noreply.github.com>

* register + test

* added SmartContract struct

* removed ContractFinder trait

* add to runtime

* resolvimg merge issues

* fmt fix

Co-authored-by: Dinonard <3002868+Dinonard@users.noreply.github.com>

* review fixes. Added support for AlreadyUsedDeveloperAccount

* fmt fix

* moved helper register() on top

* fmt test file

* fmt fix after merge

Co-authored-by: Dinonard <dino.pacandi@gmail.com>
Co-authored-by: Dinonard <3002868+Dinonard@users.noreply.github.com>

* dapps-staking Era handling (#410)

* era handling and ForceEra

* remove reward distribution from on_initialize

* added new storage maps (#413)

* added new storage maps

* added comment for PalletEraRewards

* Dapps-staking register() refactoring (#414)

* register() refactoring

* updateds after review
register() updated with initial:
  ContractLastClaimed
  ContractLastStaked

* not needed empty insert for ContractLastClaimed and Staked

* Update Cargo.toml (#420) with license

* Feature/bond and stake (#415)

* Initial stake and unbond

* Initial implementation of bond and stake

* Finished bond_and_stake, start with UT

* UT update & staked era bug fix

* Added era reward struct

* Pallet constants for staking, bug fixes, new UTs

* Finalized unit test, ready for review

* fix compilation error for runtime

* documentation fixes

* addressing review comments

Weight calculation will be implemented in a follow-up PR.

* License move to dapps (#421)

* Feature/unbond unstake and withdraw (#424)

* unbond,unstake&withdraw initial commit

* additional UTs for unbond_and_withdraw

* more UTs and bug fixes

* added test utils, minor modifications

* dapps staking claim (#422)

* initial claim() function

* fmt fix and license info

* added clearing of storage until claim era

* UT with several staking for a contract

* sceleton for payour_stakers()

* more checks on claim()

* fixes after running UT

* review fixes

* more review fixesž

* optimize storage use during payout

* minor comment fix

* added UT for 2 contracts

* minor merge fix

* claim() review updates

* use map instead of vec of vec, plus fmt

* renaming and adding comments to claim algorithm

* remove unnecessary cloning

* implemented accumulator for era rewards

* moved pallet-dapps-staking to local runtime

* megre conflict and fmt

Co-authored-by: Aleksandr Krupenkin <mail@akru.me>
Co-authored-by: satellitex <s.a.t.e.3.ths@gmail.com>
Co-authored-by: Dinonard <3002868+Dinonard@users.noreply.github.com>
Co-authored-by: Dinonard <dino.pacandi@gmail.com>
Co-authored-by: Sota Watanabe <w.souta.s.life@gmail.com>

* test failing due to wrong name (#430)

* wrong era to read EraRewardsAndStakes (#431)

Co-authored-by: Dinonard <3002868+Dinonard@users.noreply.github.com>

* Feature/dapps staking cleanup (#437)

* Initial dapps staking cleanup

* Dapps staking cleanup 2nd part

* Dapps staking cleanup part3

* Improved empty current era handling

* Era reward bug fix

* Revert some fixes

* Addressed comments

* Fixed issue with era staking and reward. 3 more UTs need to be changed

* Claim UTs few fixes, more remains to be done

* refactoring claim UTs (#438)

* Feature/dapps staking claim refactor (#439)

* Refactored claim method to handle eras beyond history depth. Added unclaimed reward accumulation

* Rebase and some improvements

* Comment update

* registration with pre-approved list of contracts (#442)

* registration with preapproved list of contracts

* format fix

* renaming and using append

* Inject rewards into dapps staking pallet (#448)

* Inject rewards into dapps staking pallet

* local-runtime uses OnTimestamp

* Use of OnUnbalanced trait

* Aura and BLockReward tuple

* added counter for individual rewards (#450)

* added counter for individual rewards

* update claim UT

* added counter for rewards paid out to contract

* review rework

* review rework2

* Added register deposit function (#451)

* Added register deposit function

* Fix code formatting

* rebase updates

Co-authored-by: Dinonard <dino.pacandi@gmail.com>

* SmartContract as trait (#446)

* SmartContract as trait

* contract_id.is_contract() changes

* changed SmartContract to trait

* more rebase fixes

* runtime updates for shibuya and local

* changing Shibuya parameters, delete unused code

* default HistoryDepth set to 30

* fixing reserved amount for registration

* minor comment fix

* enable developer as the key for preapproval (#455)

* enable developer as the key for preapproval

* use StorageMap instead of Vec for preapproved devs

* adding Vesting pallet (#459)

* Feature/dapps staking unregister (#458)

* use secure hasher

* Unregister implementation

* Unregister unit tests

* Addressed review comments

* Use safe hasher

* Rebase to latest

* Adding README.md for pallet-dapps-staking (#460)

* added README.md

* Some updates, added unregister documentation

Co-authored-by: Dinonard <3002868+Dinonard@users.noreply.github.com>

Co-authored-by: satellitex <s.a.t.e.3.ths@gmail.com>
Co-authored-by: Mar.io <mario@stake.co.jp>
Co-authored-by: Dinonard <3002868+Dinonard@users.noreply.github.com>
Co-authored-by: Mar.io <34627453+Maar-io@users.noreply.github.com>
Co-authored-by: Dinonard <dino.pacandi@gmail.com>
Co-authored-by: Sota Watanabe <w.souta.s.life@gmail.com>
Co-authored-by: Aleksandr Krupenkin <mail@akru.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
dApps staking
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants