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

dApp staking - try-state checks implemented #1331

Merged
merged 6 commits into from
Aug 27, 2024

Conversation

ipapandinas
Copy link
Contributor

Pull Request Summary

This pull request enforces tests with try-state checks to ensure storage invariants are maintained.
Closes #1294

Invariants

Below are all the invariants checked, grouped by storage items.

Invariants of active protocol storage items

  1. [PeriodInfo] number in [ActiveProtocolState] must always be greater than the number of elements in [PeriodEnd].
  2. Ensures the era number and next_era_start block number are valid.

Invariants of NextDAppId

  1. [NextDAppId] must always be greater than or equal to the number of dapps in [IntegratedDApps].
  2. [NextDAppId] must always be greater than or equal to the number of contracts in [ContractStake].

Invariants of IntegratedDApps

  1. The number of entries in [IntegratedDApps] should not exceed the [T::MaxNumberOfContracts] constant.

Invariants of StaticTierParams and TierConfig

  1. The [T::NumberOfTiers] constant must always be equal to the number of slot_distribution, reward_portion, tier_thresholds in [StaticTierParams].
  2. The [T::NumberOfTiers] constant must always be equal to the number of slots_per_tier, reward_portion, tier_thresholds in [TierConfig].

Invariants of Ledger

  1. Iterating over all [Ledger] accounts should yield the correct locked and stakes amounts compared to current era in [CurrentEraInfo].
  2. The number of unlocking chunks in [Ledger] for any account should not exceed the [T::MaxUnlockingChunks] constant.
  3. Each staking entry in [Ledger] should be greater than or equal to the [T::MinimumStakeAmount] constant.
  4. Each locking entry in [Ledger] should be greater than or equal to the [T::MinimumLockedAmount] constant.
  5. The number of staking entries per account in [Ledger] should not exceed the [T::MaxNumberOfStakedContracts] constant.

Invariants of ContractStake

  1. Iterating over all contracts in [ContractStake] should yield the correct staked amounts compared to current era in [CurrentEraInfo]
  2. Each staking entry in [ContractStake] should be greater than or equal to the [T::MinimumStakeAmount] constant.

Invariants of EraRewards

  1. Era number in [DAppTiers] must also be stored in one of the span of [EraRewards].
  2. Each span lenght entry in [EraRewards] should be lower than or equal to the [T::EraRewardSpanLength] constant.

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 dapps-staking Dapps Staking tests If the PR/issue is related to tests, like xcm-simulator tests, rpc-tests etc. labels Aug 20, 2024
ermalkaleci
ermalkaleci previously approved these changes Aug 22, 2024
Copy link

Code Coverage

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

Minimum allowed line rate is 50%

@ipapandinas
Copy link
Contributor Author

@ermalkaleci I removed an invariant check, can you re approve it?

@ipapandinas ipapandinas merged commit 89ae18f into master Aug 27, 2024
8 checks passed
@ipapandinas ipapandinas deleted the feat/dapp-staking-try-state branch August 27, 2024 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dapps-staking Dapps Staking tests If the PR/issue is related to tests, like xcm-simulator tests, rpc-tests etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dApp staking - introduce try-state checks
2 participants