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

Feat/dyn tier thresholds #1306

Merged
merged 23 commits into from
Aug 6, 2024
Merged

Feat/dyn tier thresholds #1306

merged 23 commits into from
Aug 6, 2024

Conversation

ipapandinas
Copy link
Contributor

@ipapandinas ipapandinas commented Jul 24, 2024

Pull Request Summary

New tier thresholds as percentage of the total issuance. Should be merged after v5.42.2 is deployed to Astar/Shiden.
Closes #1295

Types: TierThreshold enum updated

For TierThreshold enum: previous DynamicTvlAmount & FixedTvlAmount variants were deleted and new ones are added instead: DynamicPercentage & FixedPercentage. They support Perbill percentages and are intended to be used in the same way as the previous ones for TVL amounts. Genesis configurations, mocks and tests were updated accordingly.

Migrations

Two migrations are introduced:

  1. In TierConfig: TiersConfiguration type is refactored - number_of_slots is removed and tier_thresholds is translated from BoundedVec<TierThreshold, NT> to BoundedVec<Balance, NT>.
  2. In StaticTierParams: tier_thresholds is updated for each runtime with calculated percentage based on the the total issuance when dApp staking v3 was launched.

try-runtime results

shibuya

[2024-07-29T14:37:26Z INFO  remote-ext] scraping key-pairs from remote at block height 0xea0d18ef4a469c8a83285c6b0f2721953aa7a0baa749068b0aafe3cb976f9277
...
[2024-07-29T14:38:08Z INFO  shibuya_runtime] try-runtime::on_runtime_upgrade
[2024-07-29T14:38:08Z WARN  frame_support::migrations] 🚚 Pallet "XcmpQueue" VersionedMigration migration 3->4 can be removed; on-chain is already at StorageVersion(4).
[2024-07-29T14:38:08Z WARN  frame_support::migrations] 🚚 Pallet "DappStaking" VersionedMigration migration 7->8 can be removed; on-chain is already at StorageVersion(8).
[2024-07-29T14:38:08Z INFO  runtime::frame-support] ⚠️ Ethereum declares internal migrations (which *might* execute). On-chain `StorageVersion(0)` vs in-code storage version `NoStorageVersionSet`
[2024-07-29T14:38:08Z INFO  runtime::executive] ✅ Entire runtime state decodes without error. 373904 bytes total.
[2024-07-29T14:38:08Z INFO  try-runtime::cli] PoV size (zstd-compressed compact proof): 1.3 KB. For parachains, it's your responsibility to verify that a PoV of this size fits within any relaychain constraints.
[2024-07-29T14:38:08Z INFO  try-runtime::cli] Consumed ref_time: 0.006775s (1.36% of max 0.5s)
[2024-07-29T14:38:08Z INFO  try-runtime::cli] ✅ No weight safety issues detected.

Check list

  • added or updated unit tests
  • updated Astar official documentation
  • added OnRuntimeUpgrade hook for precompile revert code registration
  • added benchmarks & weights for any modified runtime logics.

@ipapandinas ipapandinas added enhancement New feature or request dapps-staking Dapps Staking runtime This PR/Issue is related to the topic “runtime”. labels Jul 25, 2024
@ipapandinas
Copy link
Contributor Author

/runtime-upgrade-test runtime=shibuya

Copy link

Runtime upgrade test is scheduled at https://github.com/AstarNetwork/Astar/actions/runs/10108041768.
Please wait for a while.
Runtime: shibuya
Branch: feat/dyn-tier-thresholds
SHA: 68887d7

@ipapandinas ipapandinas marked this pull request as ready for review July 29, 2024 15:02
@AstarNetwork AstarNetwork deleted a comment from github-actions bot Jul 29, 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.

Nice, well done!

Did a quick review and left some comments.
Will do a more detailed review tomorrow.

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

2 more comments, otherwise LGTM.

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

Did a thorough review now - just a few small comments. 🙈

pallets/dapp-staking-v3/src/types.rs Outdated Show resolved Hide resolved
pallets/dapp-staking-v3/src/types.rs Outdated Show resolved Hide resolved
pallets/dapp-staking-v3/src/benchmarking/utils.rs Outdated Show resolved Hide resolved
pallets/dapp-staking-v3/src/lib.rs Show resolved Hide resolved
pallets/dapp-staking-v3/src/migration.rs Outdated 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.

LGTM

@@ -1258,6 +1258,7 @@ pub type Executive = frame_executive::Executive<
>;

parameter_types! {
// percentages below are calulated based on total issuance at the time when dApp staking v3 was launched (8.4B)
Copy link
Member

Choose a reason for hiding this comment

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

Might be worth considering adding more checks for this into the try-runtime check 🙂

For another PR though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you thinking of sanity checks in pre_upgrade, like:

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
    let tier_thresholds: Result<BoundedVec<TierThreshold, T::NumberOfTiers>, _> =
        BoundedVec::try_from(TierThresholds::get().to_vec());
    assert!(tier_thresholds.is_ok());

    ...
}

Copy link
Member

Choose a reason for hiding this comment

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

Both pre & post.

E.g. take current thresholds (active ones) in pre-upgrade, send them to post upgrade.

In post-upgrade, after you derive the new thresholds, ensure they are e.g. within 10% of the old ones.

Copy link

github-actions bot commented Aug 6, 2024

Code Coverage

Package Line Rate Branch Rate Health
primitives/src/xcm 65% 0%
primitives/src 60% 0%
pallets/astar-xcm-benchmarks/src 86% 0%
pallets/collator-selection/src 92% 0%
pallets/xc-asset-config/src 50% 0%
pallets/dapp-staking-v3/src/test 0% 0%
chain-extensions/unified-accounts/src 0% 0%
pallets/dapp-staking-v3/rpc/runtime-api/src 0% 0%
chain-extensions/pallet-assets/src 56% 0%
pallets/astar-xcm-benchmarks/src/generic 100% 0%
pallets/unified-accounts/src 77% 0%
precompiles/dapp-staking-v3/src/test 0% 0%
precompiles/sr25519/src 64% 0%
pallets/price-aggregator/src 75% 0%
pallets/dapp-staking-v3/src/benchmarking 98% 0%
pallets/collective-proxy/src 86% 0%
pallets/dapp-staking-migration/src 0% 0%
pallets/ethereum-checked/src 74% 0%
precompiles/substrate-ecdsa/src 74% 0%
precompiles/xcm/src 71% 0%
chain-extensions/types/unified-accounts/src 0% 0%
pallets/astar-xcm-benchmarks/src/fungible 100% 0%
pallets/dynamic-evm-base-fee/src 89% 0%
precompiles/dapp-staking-v3/src 90% 0%
chain-extensions/types/assets/src 0% 0%
precompiles/unified-accounts/src 100% 0%
precompiles/dispatch-lockdrop/src 86% 0%
precompiles/assets-erc20/src 78% 0%
pallets/dapp-staking-v3/src 86% 0%
pallets/inflation/src 86% 0%
pallets/static-price-provider/src 52% 0%
Summary 77% (3576 / 4647) 0% (0 / 0)

Minimum allowed line rate is 50%

@Dinonard
Copy link
Member

Dinonard commented Aug 6, 2024

@ermalkaleci any more comments here?

@ermalkaleci
Copy link
Contributor

@ermalkaleci any more comments here?

I'm reviewing now. The only concern is to double check percentage

@ipapandinas ipapandinas merged commit 6f34256 into master Aug 6, 2024
8 checks passed
@ipapandinas ipapandinas deleted the feat/dyn-tier-thresholds branch August 6, 2024 15:12
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 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 - Improved Tier Threshold Derivation
3 participants