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

Break StakingInterface into smaller traits #3888

Open
Ank4n opened this issue Mar 29, 2024 · 0 comments
Open

Break StakingInterface into smaller traits #3888

Ank4n opened this issue Mar 29, 2024 · 0 comments
Labels
I4-refactor Code needs refactoring.

Comments

@Ank4n
Copy link
Contributor

Ank4n commented Mar 29, 2024

StakingInterface is too big and bloated.

It could be broken down into something like this

  • trait StakingConfig {} // can be merged with StakingInspect
  • trait StakingInspect {}
  • trait StakingMutate: StakingInspect {}
  • trait StakingUnsafe: StakingMutate {}

Other pallets that only need to query Staking configuration or data about a nominator/validator can use the right level of traits.

StakingMutate allows all the ways to mutate the staking ledger.

StakingUnsafe gives access to low level apis that allow other pallets to manipulate ledger overriding some general integrity checks. These are to be used by DelegationStakingPallet that is being worked on #2680.

@Ank4n Ank4n added the I4-refactor Code needs refactoring. label Mar 29, 2024
github-merge-queue bot pushed a commit that referenced this issue Apr 20, 2024
This is the first PR in preparation for
#454.

## Follow ups:
- #3904.
- #3905.

Overall changes are documented here (lot more visual 😍):
https://hackmd.io/@ak0n/454-np-governance

[Maybe followup](#4217)
with migration of storage item `VirtualStakers` as a bool or enum in
`Ledger`.

## Context
We want to achieve a way for a user (`Delegator`) to delegate their
funds to another account (`Agent`). Delegate implies the funds are
locked in delegator account itself. Agent can act on behalf of delegator
to stake directly on Staking pallet.

The delegation feature is added to Staking via another pallet
`delegated-staking` worked on
[here](#3904).

## Introduces:
### StakingUnchecked Trait
As the name implies, this trait allows unchecked (non-locked) mutation
of staking ledger. These apis are only meant to be used by other pallets
in the runtime and should not be exposed directly to user code path.
Also related: #3888.

### Virtual Bond
Allows other pallets to stake via staking pallet while managing the
locks on these accounts themselves. Introduces another storage
`VirtualStakers` that whitelist these accounts.

We also restrict virtual stakers to set reward account as themselves.
Since the account has no locks, we cannot support compounding of
rewards. Conservatively, we require them to set a separate account
different from the staker. Since these are code managed, it should be
easy for another pallet to redistribute reward and rebond them.

### Slashes
Since there is no actual lock maintained by staking-pallet for virtual
stakers, this pallet does not apply any slashes. It is then important
for pallets managing virtual stakers to listen to slashing events and
apply necessary slashes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I4-refactor Code needs refactoring.
Projects
Status: 📕 Backlog
Development

No branches or pull requests

1 participant