-
Notifications
You must be signed in to change notification settings - Fork 414
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
Conversation
@ipapandinas please check the concept. |
There was a problem hiding this 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 🙈
There was a problem hiding this 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.
There was a problem hiding this 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this 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 🙈 )
pallets/dapp-staking/src/lib.rs
Outdated
// Enable maintenance mode on the first run | ||
// Likely to be already set in the runtime upgrade migration | ||
ActiveProtocolState::<T>::mutate(|state| { | ||
state.maintenance = true; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
pallets/dapp-staking/src/lib.rs
Outdated
/// 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>; |
There was a problem hiding this comment.
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 toSome
, andNone
means it's finished. Themigration
extrinsic should immediately fail if this isNone
- 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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 🤦.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ✅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Minimum allowed line rate is |
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
stake
,unstake
andunstake_from_unregistered
is moved to separate functions, with minimal modificationsunstake
to return more comprehensive information of what was unstakedmove
extrinsic, usinginner_unstake
andinner_stake
functions (orunstake_from_unregistered
) as the building blocksBonus Reward Eligibility
The previously used
loyal_staker
flag is replaced with abonus_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:
If a move action is performed during the
build&earn
subperiod, thebonus_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:When moving stake from unregistered contracts, the bonus status is always preserved.
Migration
This PR introduces the
update_bonus
extrinsic, which updatesloyal_staker
flags from the previous 0 move actions limit to the new value set byMaxBonusSafeMovesPerPeriod
. The change will take effect in a future runtime upgrade when the config parameters are updated.Check list