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

✨ Slashing behavior for pallet vesting #396

Merged
merged 3 commits into from
Sep 12, 2024

Conversation

JuaniRios
Copy link
Contributor

@JuaniRios JuaniRios commented Sep 4, 2024

What?

  • Reduce vesting schedules of pallet-vesting after a slash is made when an evaluation is settled

Why?

  • A user could have negative transferable balance if they had some tokens locked for vesting and then got slashed.

How?

  • Semi-generic solution which should be easily adapted to the Polkadot SDK. PR is here.
  • pallet-funding (in the future pallet-balances) accepts a tuple of items that implement a trait called on_slash.
  • pallet funding calls this after slashing the evaluator (we don't use the slash interface so we call the trait directly. In the future this trait should also be called when using the slash function)
  • We implement on pallet vesting the trait where we see how many tokens should be released at the moment of slashing, and then apply the slash on the remaining frozen amount. We recalculate the per_block amount to keep the same end block

Testing?

  • 2 tests in the new crate on-slash-vesting
  • 1 integration test

Anything Else?

  • For now the trait for slashing needs to be in the same crate we implement it since we can't impl a foreign trait on a foreign crate.
  • Soon we should submit a PR to polkadot-sdk where we submit this new slash interface on the tokens::fungible trait, and also add our vesting impl directly inside pallet-vesting.

@JuaniRios JuaniRios changed the title slash behavior on pallet vesting ✨ Slashing behavior for pallet vesting Sep 4, 2024
@JuaniRios JuaniRios force-pushed the 09-04-slash_behavior_on_pallet_vesting branch from a77032a to 6217f26 Compare September 4, 2024 13:34
@JuaniRios JuaniRios force-pushed the 09-03-schedule_merge_runtime_api branch from bc33597 to 1b9300f Compare September 4, 2024 14:03
@JuaniRios JuaniRios force-pushed the 09-04-slash_behavior_on_pallet_vesting branch 3 times, most recently from ff81701 to b56ce16 Compare September 5, 2024 14:00
@JuaniRios JuaniRios self-assigned this Sep 5, 2024
@JuaniRios JuaniRios marked this pull request as ready for review September 5, 2024 14:07
@JuaniRios JuaniRios force-pushed the 09-03-schedule_merge_runtime_api branch from 1b9300f to f7a5360 Compare September 9, 2024 11:11
@JuaniRios JuaniRios force-pushed the 09-04-slash_behavior_on_pallet_vesting branch from b56ce16 to a6828af Compare September 9, 2024 11:11
@JuaniRios JuaniRios mentioned this pull request Sep 9, 2024
@JuaniRios JuaniRios force-pushed the 09-03-schedule_merge_runtime_api branch from f7a5360 to 61185bf Compare September 10, 2024 08:34
@JuaniRios JuaniRios force-pushed the 09-04-slash_behavior_on_pallet_vesting branch from a6828af to 5e2c3a4 Compare September 10, 2024 08:35
@JuaniRios JuaniRios force-pushed the 09-03-schedule_merge_runtime_api branch from 61185bf to e3c6894 Compare September 10, 2024 08:43
@JuaniRios JuaniRios force-pushed the 09-04-slash_behavior_on_pallet_vesting branch from 5e2c3a4 to fdf5426 Compare September 10, 2024 08:43
@lrazovic lrazovic force-pushed the 09-03-schedule_merge_runtime_api branch from e3c6894 to 9d2a29d Compare September 10, 2024 13:45
@lrazovic lrazovic force-pushed the 09-04-slash_behavior_on_pallet_vesting branch from fdf5426 to 74624f3 Compare September 10, 2024 13:45
Copy link
Member

@lrazovic lrazovic left a comment

Choose a reason for hiding this comment

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

I like it! In this round of review I mainly focused on the logic and not on the tests, I will review the tests as soon the comments are addressed.

pallets/on-slash-vesting/src/lib.rs Outdated Show resolved Hide resolved
pallets/on-slash-vesting/src/lib.rs Outdated Show resolved Hide resolved
pallets/on-slash-vesting/src/mock.rs Show resolved Hide resolved
@JuaniRios JuaniRios force-pushed the 09-03-schedule_merge_runtime_api branch from 9d2a29d to 5a07a33 Compare September 11, 2024 11:15
@JuaniRios JuaniRios force-pushed the 09-04-slash_behavior_on_pallet_vesting branch 2 times, most recently from bade02e to d9ac4a4 Compare September 11, 2024 11:23
@JuaniRios JuaniRios force-pushed the 09-04-slash_behavior_on_pallet_vesting branch from d9ac4a4 to b86d878 Compare September 11, 2024 11:31
@JuaniRios JuaniRios force-pushed the 09-03-schedule_merge_runtime_api branch from 5a07a33 to f93fc74 Compare September 12, 2024 08:35
@JuaniRios JuaniRios force-pushed the 09-04-slash_behavior_on_pallet_vesting branch from b86d878 to 4674903 Compare September 12, 2024 08:35
Copy link
Collaborator

@vstam1 vstam1 left a comment

Choose a reason for hiding this comment

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

Couple of dbg statements left, but think logic looks good as is

pallets/on-slash-vesting/src/lib.rs Show resolved Hide resolved
pallets/on-slash-vesting/src/test.rs Outdated Show resolved Hide resolved
pallets/on-slash-vesting/src/test.rs Outdated Show resolved Hide resolved
@JuaniRios JuaniRios force-pushed the 09-04-slash_behavior_on_pallet_vesting branch from 4674903 to 20bda10 Compare September 12, 2024 11:02
Copy link
Contributor Author

JuaniRios commented Sep 12, 2024

Merge activity

  • Sep 12, 9:39 AM EDT: @JuaniRios started a stack merge that includes this pull request via Graphite.
  • Sep 12, 9:54 AM EDT: Graphite rebased this pull request as part of a merge.
  • Sep 12, 9:55 AM EDT: @JuaniRios merged this pull request with Graphite.

@JuaniRios JuaniRios changed the base branch from 09-03-schedule_merge_runtime_api to graphite-base/396 September 12, 2024 13:50
@JuaniRios JuaniRios changed the base branch from graphite-base/396 to main September 12, 2024 13:52
@JuaniRios JuaniRios force-pushed the 09-04-slash_behavior_on_pallet_vesting branch from 20bda10 to cd5caa4 Compare September 12, 2024 13:53
@JuaniRios JuaniRios merged commit b0681c3 into main Sep 12, 2024
1 check passed
@JuaniRios JuaniRios deleted the 09-04-slash_behavior_on_pallet_vesting branch September 12, 2024 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants