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(dAppStaking): Move actions for bonus rewards #1418

Merged
merged 36 commits into from
Feb 18, 2025

Conversation

Dinonard
Copy link
Member

@Dinonard Dinonard commented Feb 2, 2025

Pull Request Summary

Closes #1379

This PR introduces enhancements to the bonus reward eligibility mechanism and implements robust handling for stake movement, particularly during the build&earn subperiod.

The approach aims to first adapt existing pallet to easily support move functionality.
Pallet has a lot of tests covering stake & unstake functioality, and in case MAX_BONUS_MOVES = 1, every legacy test must work same as before.

Changes

  • logic from stake, unstake and unstake_from_unregistered is moved to separate functions, with minimal modifications
  • it's important for unstake to return more comprehensive information of what was unstaked
  • types are modified to return necessary information for the higher level functionality
  • test files are adapted to ensure that high level (extrinsic) tests are passing
  • move extrinsic, using inner_unstake and inner_stake functions (or unstake_from_unregistered) as the building blocks

Bonus Reward Eligibility

The previously used loyal_staker flag is replaced with a bonus_status u8 type.
The number of allowed move actions is defined by a config parameter (MaxBonusSafeMovesPerPeriod); bonus is forfeited if move actions exceed this value.

Move action

A move action is defined as either:

  • Partial unstaking that reduces the 'voting stake'.
  • Transfers of 'voting stake' between contracts.

If a move action is performed during the build&earn subperiod, the bonus_status attached to the relevant singular staking info is reduced until it is forfeited.

Stake Movement Enhancements

A new move_stake extrinsic is implemented. It is similar to an 'unstake' followed by a 'stake'. Existing safeguards are extended additional checks to:

  • Ensure the source and destination contracts are different.
  • Validate the amount to be moved.

When moving stake from unregistered contracts, the bonus status is always preserved.

Migration

This PR introduces the update_bonus extrinsic, which updates loyal_staker flags from the previous 0 move actions limit to the new value set by MaxBonusSafeMovesPerPeriod. The change will take effect in a future runtime upgrade when the config parameters are updated.

Check list

  • added or updated unit tests
  • updated Astar official documentation
  • update dAppStaking precompile
  • added benchmarks & weights for any modified runtime logics.
  • add E2E tests
  • prepare follow-up issue for Astar Portal frontend & forum post

@Dinonard
Copy link
Member Author

Dinonard commented Feb 2, 2025

@ipapandinas please check the concept.

@Dinonard Dinonard added shiden related to shiden runtime astar Related to Astar shibuya related to shibuya runtime This PR/Issue is related to the topic “runtime”. labels Feb 6, 2025
Copy link
Member Author

@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 👏
The types tests look like it was hellish to update 🙈

Copy link
Member Author

@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.

Haven't checked testing_utils in detail.

Copy link
Member Author

@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.

Few additional comments, hope to discuss it more since I might not be aware of some issues.

ermalkaleci
ermalkaleci previously approved these changes Feb 14, 2025
Copy link
Contributor

@ermalkaleci ermalkaleci 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 Author

@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.

@ipapandinas checked the delta since last review - LGTM!
(cannot approve since I made the PR 🙈 )

ipapandinas
ipapandinas previously approved these changes Feb 18, 2025
// Enable maintenance mode on the first run
// Likely to be already set in the runtime upgrade migration
ActiveProtocolState::<T>::mutate(|state| {
state.maintenance = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

does this mean anyone can put protocol in maintenance mode?

Copy link
Contributor

Choose a reason for hiding this comment

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

True, in a sense yes, anyone can trigger do_update, this is not the best. Maintenance mode is supposed to be entered with the on_runtime_upgrade here, but during chopstick testing it was not the case, so that's why I've put it also here too. I can remove it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I haven't noticed this before tbh - but does this mean that even after the migration finishes, this code can still be entered, and maintenance mode re-enabled?

Copy link
Member Author

Choose a reason for hiding this comment

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

Btw, it's fine if anyone can trigger do_update, as long as it's protected properly.

  • weight is limited
  • once migration is finished, call has no effect

Copy link
Contributor

Choose a reason for hiding this comment

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

You can test migration with chopsticks as well. Don't override wasm but instead do system::set_code and then build a block to trigger runtime upgrade then build enough blocks to run all the migrations

Copy link
Contributor

Choose a reason for hiding this comment

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

I was testing it by overriding wasm, now I've followed your advice by manually building blocks, much better, thanks!

Comment on lines 519 to 523
/// Temporary cursor to persist latest BonusStatus item updated.
/// TODO: remove it once all BonusStatus are updated and this storage value is cleanup.
#[pallet::storage]
pub type ActiveBonusUpdateCursor<T: Config> =
StorageValue<_, (T::AccountId, T::SmartContract), OptionQuery>;
Copy link
Member Author

Choose a reason for hiding this comment

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

With respect to the comment about enabling maintenance mode in the migration - keep it only in the OnRuntimeUpgradeHook.

As for this particular storage, I can suggest two approaches:

  • OnRuntimeUpgrade sets this to Some, and None means it's finished. The migration extrinsic should immediately fail if this is None
  • A more clear approach would be to replace this value with:
enum MigrationState {
  NotStarted,
  InProgress(T::AccountId, T::SmartContract),
  Finished,
}

failing the migration extrinsic if state is set to Finished

Copy link
Contributor

Choose a reason for hiding this comment

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

what if we set this cursor and enable maintenance on_runtime_upgrade? It will require to trigger updates immediately after migration though

Copy link
Member Author

Choose a reason for hiding this comment

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

My comments assume this is all setup in the on_runtime_upgrade.

In previous review I completely missed that it's not, my bad. I assumed it was 🤦.

Copy link
Contributor

Choose a reason for hiding this comment

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

I've used a proper BonusUpdateState in this commit 03df158

It should solved the issue

Copy link
Member Author

Choose a reason for hiding this comment

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

What about V8ToV9?
Shouldn't it be added to parachain runtimes?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was planing to do it in the release prep PR, but it makes more sense to do it here. It's done now ✅

Copy link
Member Author

@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

ipapandinas
ipapandinas previously approved these changes Feb 18, 2025
Copy link

Code Coverage

Package Line Rate Branch Rate Health
pallets/collective-proxy/src 94% 0%
pallets/price-aggregator/src 76% 0%
pallets/static-price-provider/src 91% 0%
primitives/src/xcm 62% 0%
pallets/vesting-mbm/src 87% 0%
precompiles/xcm/src 69% 0%
pallets/dapp-staking/src/benchmarking 95% 0%
pallets/astar-xcm-benchmarks/src/generic 100% 0%
chain-extensions/types/assets/src 0% 0%
pallets/dapp-staking/src/test 0% 0%
pallets/astar-xcm-benchmarks/src/fungible 100% 0%
precompiles/dapp-staking/src 89% 0%
chain-extensions/unified-accounts/src 0% 0%
chain-extensions/pallet-assets/src 54% 0%
pallets/dynamic-evm-base-fee/src 82% 0%
pallets/unified-accounts/src 81% 0%
pallets/dapp-staking/src 78% 0%
precompiles/sr25519/src 56% 0%
precompiles/substrate-ecdsa/src 67% 0%
precompiles/dapp-staking/src/test 0% 0%
pallets/inflation/src 90% 0%
chain-extensions/types/unified-accounts/src 0% 0%
primitives/src 54% 0%
pallets/dapp-staking/rpc/runtime-api/src 0% 0%
pallets/ethereum-checked/src 76% 0%
precompiles/dispatch-lockdrop/src 83% 0%
precompiles/assets-erc20/src 78% 0%
pallets/xc-asset-config/src 48% 0%
pallets/astar-xcm-benchmarks/src 86% 0%
pallets/collator-selection/src 87% 0%
precompiles/unified-accounts/src 100% 0%
Summary 75% (3691 / 4894) 0% (0 / 0)

Minimum allowed line rate is 50%

@ipapandinas ipapandinas merged commit ff28544 into master Feb 18, 2025
8 checks passed
@ipapandinas ipapandinas deleted the feat/ds-move-concept branch February 18, 2025 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astar Related to Astar enhancement New feature or request runtime This PR/Issue is related to the topic “runtime”. shibuya related to shibuya shiden related to shiden runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dAppStaking - Bonus rewards mechanism rework
3 participants