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

Add BondingRestriction config trait for staking pallet #8

Conversation

mnaamani
Copy link
Member

BondingRestriction configuration trait on staking pallet to provide a means to add an external check before bonding a stash account, if other parts of the runtime might have an opinion about whether to allow it or not.

Main usecase would be if there are other pallets that lock funds and we wish to avoid any conflicting locks.

@mnaamani mnaamani requested a review from Lezek123 August 31, 2022 05:07
Copy link

@Lezek123 Lezek123 left a comment

Choose a reason for hiding this comment

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

When trying to run tests (cargo test) I'm getting:

error[E0046]: not all trait items implemented, missing: `BondingRestriction`
   --> frame/offences/benchmarking/src/mock.rs:159:1
    |
159 | impl pallet_staking::Config for Test {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `BondingRestriction` in implementation
    |
    = help: implement the missing item: `type BondingRestriction = Type;`

frame/staking/src/lib.rs Outdated Show resolved Hide resolved
frame/staking/src/lib.rs Outdated Show resolved Hide resolved
/// Allows for parts of the runtime that might implement other forms fund locking to prevent
/// incompatible locking on accounts which could lead to unsafe state.
pub trait BondingRestriction<AccountId> {
/// Determine if bonding is allowed with stash and controller combination

Choose a reason for hiding this comment

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

I'm wondering whether it's a good idea to include controller here, since the controller account can also be changed via set_controller, in which case some controller-specific restrictions may be bypassed.

Copy link
Member Author

Choose a reason for hiding this comment

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

We are of course mainly concerned with the stash account, I added controller to give ability to prevent bond in-case the controller had some other lock on it which would prevent user from unbonding or doing other actions with their controller account. Obviously I didn't see the set_controller. (And coming to think of it, even if we detected it earlier, nothing would prevent user from using their controller account to stake so it would not have really prevented that anyway) I will drop controller as suggested.

@mnaamani mnaamani requested a review from Lezek123 August 31, 2022 16:48
@mnaamani
Copy link
Member Author

Applied suggestion and fixed mocks.

cargo test --release --features runtime-benchmarks now builds and runs.
The only failing test, which also happens on polkadot-v0.9.23 without our modifications is:

test test::metadata ... FAILED

failures:

---- test::metadata stdout ----
thread 'test::metadata' panicked at 'assertion failed: `(left == right)`

Diff < left / right > :
 Some(
     Variant(
         TypeDefVariant {
             variants: [
                 Variant {
                     name: "set_dummy",
                     fields: [
                         Field {
                             name: Some(
                                 "new_value",
                             ),
                             ty: UntrackedSymbol {
                                 id: 38,
                                 marker: PhantomData,
                             },
                             type_name: Some(
<                                "T::Balance",
>                                "/*«*/ T::Balance /*»*/",
                             ),
                             docs: [],
                         },
                     ],
                     index: 0,
                     docs: [],
                 },
             ],
         },
     ),
 )

', frame/support/test/tests/pallet_compatibility.rs:299:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    test::metadata

test result: FAILED. 2 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

error: test failed, to rerun pass '-p frame-support-test --test pallet_compatibility'

Copy link

@Lezek123 Lezek123 left a comment

Choose a reason for hiding this comment

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

LGTM

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.

2 participants