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

stakingv3: rank dapps in-between tiers #1240

Merged
merged 24 commits into from
Jun 18, 2024
Merged

stakingv3: rank dapps in-between tiers #1240

merged 24 commits into from
Jun 18, 2024

Conversation

ermalkaleci
Copy link
Contributor

@ermalkaleci ermalkaleci commented May 8, 2024

In order to preserve u8 for DAppTierRewards we can use each byte of u8 for tier and rank. This way there's no need for migration and it's backward compatible.

Since u8 has 2 bytes 0xff 0b1111_1111 we can use the 1st byte for tier and 2nd byte for rank. Rank goes from 0..10 (higher is better). Meaning if you just enter a tier your rank is 0 and more staking will increase your ranking as you become close to next tier.

// RankedTier { tier: 1, rank: 10 } is represented as 0xa1
let tier: u8 = 0xa1 & 0x0f; // tier  1
let rank: u8 = 0xa1 >> 4;   // rank 10

Currently all values will be from 0..3 so rank will be zero. Rank will take place once we deploy it.

The simplest solution for reward distribution between ranks will be to define an additional reward per rank. Let’s say Tier 2 reward portion is 50K ASTR and slot capacity is 5 then reward per slot will be 10K ASTR, therefor rank reward will be rank_reward = max(slot_reward, tier_remaining_reward) / 10 = 1K . If you classify for rank 0 then you get 10K (slot reward), if you classify rank 3 you get 10K + 3 * rank_reward = 13K. All the reward to support ranked tier comes from tier reward portion itself. If tier has 5 slots with 3 occupied then reward of 2 slots will be used for ranking. e.i. slots occupied[rank_0, rank_3, rank_10] then calculated reward will be [10k, 13K, 20K] . In cases when there’s not enough remaining reward to satisfy full reward per rank then it will be adjust based on remaining reward, so rank reward will be less than 1K. If all slots are occupied then all dapps will make equal 10K each (slot reward).

  • benchmarking
  • docs

@ermalkaleci ermalkaleci added the dapps-staking Dapps Staking label May 8, 2024
@ermalkaleci ermalkaleci added enhancement New feature or request other PR/issue is related to third-party, scripts or other things which don't have definite label. labels May 8, 2024
@ermalkaleci
Copy link
Contributor Author

/bench shibuya pallet-dapp-staking-v3

Copy link

Benchmarks job is scheduled at https://github.com/AstarNetwork/Astar/actions/runs/9051969615.
Please wait for a while.
Branch: feat/rank-dapps
SHA: c15d44c

Copy link

Benchmark job failed.
Please check https://github.com/AstarNetwork/Astar/actions/runs/9051969615.

@ermalkaleci
Copy link
Contributor Author

/bench shibuya-dev pallet-dapp-staking-v3

Copy link

Benchmarks job is scheduled at https://github.com/AstarNetwork/Astar/actions/runs/9052059142.
Please wait for a while.
Branch: feat/rank-dapps
SHA: c15d44c

Copy link

Benchmarks have been finished.
You can download artifacts if exists https://github.com/AstarNetwork/Astar/actions/runs/9052059142.

@ermalkaleci
Copy link
Contributor Author

/bench shibuya-dev pallet-dapp-staking-v3

Copy link

Benchmarks job is scheduled at https://github.com/AstarNetwork/Astar/actions/runs/9052156819.
Please wait for a while.
Branch: feat/rank-dapps
SHA: c42ffba

Copy link

Benchmarks have been finished.
You can download artifacts if exists https://github.com/AstarNetwork/Astar/actions/runs/9052156819.

@ermalkaleci ermalkaleci requested a review from Dinonard May 13, 2024 08:25
@ermalkaleci ermalkaleci marked this pull request as ready for review May 13, 2024 09:13
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.

Sorry for the delay!

Left some comments we can discuss, didn't check tests yet.

pallets/dapp-staking-v3/src/lib.rs Show resolved Hide resolved
pallets/dapp-staking-v3/src/lib.rs Show resolved Hide resolved
primitives/src/dapp_staking.rs Show resolved Hide resolved
primitives/src/dapp_staking.rs Show resolved Hide resolved
pallets/dapp-staking-v3/src/lib.rs Outdated Show resolved Hide resolved
pallets/dapp-staking-v3/src/lib.rs Show resolved Hide resolved
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.

Went over the tests this time as well, so this is full review from me.

pallets/dapp-staking-v3/src/test/tests.rs Outdated Show resolved Hide resolved
pallets/dapp-staking-v3/src/test/tests.rs Show resolved Hide resolved
pallets/dapp-staking-v3/src/test/tests.rs Outdated Show resolved Hide resolved
pallets/dapp-staking-v3/src/migration.rs Outdated Show resolved Hide resolved
runtime/shibuya/src/lib.rs Show resolved Hide resolved
@Dinonard Dinonard added the runtime This PR/Issue is related to the topic “runtime”. label Jun 4, 2024
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.

LGTM!

I guess benchmarks still need to be run.

It'd be good to get another review from @ashutoshvarma or @PierreOssun .

@Dinonard
Copy link
Member

Dinonard commented Jun 5, 2024

@ermalkaleci could you please open up an issue here, and explain how the existing struct has changed, how to know which struct to use (storage version), and how to calculate the new reward?

@ermalkaleci
Copy link
Contributor Author

/bench astar-dev,shibuya-dev,shiden-dev pallet_dapp_staking_v3

Copy link

github-actions bot commented Jun 5, 2024

Benchmarks job is scheduled at https://github.com/AstarNetwork/Astar/actions/runs/9387947006.
Please wait for a while.
Branch: feat/rank-dapps
SHA: 59a6d7e

Copy link

github-actions bot commented Jun 5, 2024

Benchmarks have been finished.
You can download artifacts if exists https://github.com/AstarNetwork/Astar/actions/runs/9387947006.

Copy link

github-actions bot commented Jun 5, 2024

Code Coverage

Package Line Rate Branch Rate Health
pallets/ethereum-checked/src 79% 0%
precompiles/dapp-staking-v3/src/test 0% 0%
chain-extensions/types/unified-accounts/src 0% 0%
precompiles/dispatch-lockdrop/src 86% 0%
pallets/inflation/src 83% 0%
pallets/xvm/src 54% 0%
pallets/dapp-staking-v3/rpc/runtime-api/src 0% 0%
pallets/dapp-staking-v3/src 90% 0%
pallets/price-aggregator/src 72% 0%
pallets/static-price-provider/src 52% 0%
pallets/collator-selection/src 92% 0%
chain-extensions/xvm/src 0% 0%
pallets/dapp-staking-v3/src/test 0% 0%
precompiles/unified-accounts/src 100% 0%
primitives/src 62% 0%
primitives/src/xcm 64% 0%
chain-extensions/unified-accounts/src 0% 0%
chain-extensions/types/assets/src 0% 0%
pallets/xc-asset-config/src 64% 0%
precompiles/substrate-ecdsa/src 74% 0%
precompiles/sr25519/src 64% 0%
pallets/astar-xcm-benchmarks/src 88% 0%
precompiles/xcm/src 73% 0%
chain-extensions/pallet-assets/src 56% 0%
pallets/dapp-staking-v3/src/benchmarking 98% 0%
chain-extensions/types/xvm/src 0% 0%
pallets/astar-xcm-benchmarks/src/generic 100% 0%
pallets/dapp-staking-migration/src 0% 0%
pallets/oracle-benchmarks/src 0% 0%
precompiles/dapp-staking-v3/src 90% 0%
pallets/unified-accounts/src 86% 0%
pallets/astar-xcm-benchmarks/src/fungible 100% 0%
precompiles/assets-erc20/src 81% 0%
pallets/dynamic-evm-base-fee/src 92% 0%
precompiles/xvm/src 75% 0%
Summary 77% (3644 / 4714) 0% (0 / 0)

Minimum allowed line rate is 50%

Copy link
Member

@ashutoshvarma ashutoshvarma left a comment

Choose a reason for hiding this comment

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

LGTM!

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.

LGTM

@ermalkaleci ermalkaleci merged commit 3e87609 into master Jun 18, 2024
9 checks passed
@ermalkaleci ermalkaleci deleted the feat/rank-dapps branch June 18, 2024 07:56
@@ -289,6 +296,7 @@ pub mod pallet {
beneficiary: T::AccountId,
smart_contract: T::SmartContract,
tier_id: TierId,
rank: Rank,
Copy link

@GuiGou12358 GuiGou12358 Jun 26, 2024

Choose a reason for hiding this comment

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

Hi,
IMHO, it was better to add the new field at the end to be backwards compatible with existing clients listening to your events.
Changing the order of fields introduces a breaking change for events consumers.
Adding a new field at the end doesn't necessarily break the consumer: the new field is ignored but it still work.
Hoping this comment can be helpful for the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You should be able to query by key. Any reason why you are querying by index?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dapps-staking Dapps Staking enhancement New feature or request other PR/issue is related to third-party, scripts or other things which don't have definite label. runtime This PR/Issue is related to the topic “runtime”.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dApp Staking v3 - Tier Assignemt & Reward Distribution Algorithm Assignment Proposal
4 participants