Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

WIP safe mode and tx pause {continued} #12371

Merged
merged 28 commits into from
Oct 12, 2022
Merged

WIP safe mode and tx pause {continued} #12371

merged 28 commits into from
Oct 12, 2022

Conversation

nuke-web3
Copy link
Contributor

@nuke-web3 nuke-web3 commented Sep 28, 2022

Targets #12092

  • Changes the tx pause pallet to accept input as RuntimeCalls, instead of stringy names. This was decided to be a bad idea, based on feedback.

    • The storage is still stringy names, as it allows for less headache on migration and safety
    • The UI can now help you as in the Proxy pallet have dropdown selections for the possible calls, and there should be no possibility of user error, or inserting calls that do not explicitly exist in the runtime. Example:
      image
    • The above likely means we have to over specify calls with "real" values, but all we really want here is the call without dummy data. TBD on behavior and if a fix is possible
  • tests for tx pause and safe mode working as written 🎉

    • ensuring indirect calls from pallets, like batching via util pallet (and perhaps proxy) {tested manually to work as expected in the kitchensink via polkadot.js apps UI}
  • benchmarks configured and dummy files genereated 🎉

  • naming tweaks for intuitive understanding and common terms between pallets.

Considerations (for abandoned RuntimeCall variation on these pallets)

One issue with tx pause pallet to accept input as RuntimeCalls: on runtime upgrades changing names or removing pallets that are paused will be inaccessible to remove from tx pause storage, as the runtime metadata won't include the matching stringy names from before.

Possible solution: a "raw" call in this pallet to insert or drop pauses by stringy names explicitly as a privileged call for the unpause origin. Alternatively, just a note on how to remove a raw storage key if you missed it in a migration (likely not possible from the unpause origin!)

Its more of a corner case IMHO, and a very simple migration would be needed if you wanted to keep a modified call paused. No issue leaving an irrelevant call name in storage either. Not an DOS attachable thing or something likely to case any issue if forgotten

TODO

  • Update kitchen sink runtime config for the safe mode origins needed (not correct or working as it stands now)
  • ~Add preset call filter for the tx pause pallet such that what amounts to a "batch" of items will be placed into storage for tx pause in a single call. There should be no need to analyze and form a manual pause_call batch. ~ in a folllowup PR
    • Can this be derived from a match statement ergonomically, so you can specify pallets inclusive of all calls without explicitly naming each?
    • Desired behavior is being able to selectively unpause calls that are placed in this preset batch of calls to add to the vec of paused calls.

@nuke-web3 nuke-web3 requested a review from ggwpez September 28, 2022 00:25
@nuke-web3 nuke-web3 changed the title WIP safe mode and tx pause {continued WIP safe mode and tx pause {continued} Sep 28, 2022
@github-actions github-actions bot added the A0-please_review Pull request needs code review. label Sep 28, 2022
@nuke-web3 nuke-web3 marked this pull request as draft September 28, 2022 00:41
@nuke-web3 nuke-web3 self-assigned this Sep 28, 2022
ggwpez and others added 3 commits September 28, 2022 20:41
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
@nuke-web3 nuke-web3 added B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. labels Oct 3, 2022
nuke-web3 and others added 4 commits October 3, 2022 11:25
benchmarking getting call stack exhausted
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
@nuke-web3
Copy link
Contributor Author

nuke-web3 commented Oct 5, 2022

To ensure that the RuntimeCall type used as a field needed to be set by end users, I wanted to make sure it wasn't too difficult and that it would prevent "footguns" using 917961b I have made an MVP demo of using the tx-pause with subxt: https://github.com/NukeManDan/pause-subxt

As the OP hoped, the behavior using the apps ui is the same as proxy: you have drop downs on the only selections you can make. The only grip is that you are forced to used correct values here generally in the "call" you supply (like an account and value for a balance transfer) to make the UI and subxt happy.

@ggwpez wdyt? Not too bad for the extra safety and less need to lookup the correct string to place into storage for the pallet and the function/call as it was previously?

@Polkadot-Forum
Copy link

This pull request has been mentioned on Polkadot Forum. There might be relevant details there:

https://forum.polkadot.network/t/safe-mode-and-transaction-pause-pallets/636/1

@ggwpez
Copy link
Member

ggwpez commented Oct 6, 2022

@ggwpez wdyt? Not too bad for the extra safety and less need to lookup the correct string to place into storage for the pallet and the function/call as it was previously?

We could already safe-guard against wrong pallet names by going through all available pallets. This is maybe also possible for calls. I think requiring additional argument data which we will then ignore is not good.
It also gives off the impression that we could filter a complete by arguments, since they are provided. But we ignore them later on.
I will ask @shawntabrizi today in a meeting what he thinks.

PS: A front-end UI could also real all Pallet and Call names from metadata, so we should be good with just strings.

@nuke-web3
Copy link
Contributor Author

nuke-web3 commented Oct 6, 2022

Agreed that extraneous call data is not ideal. Dumb question: is it possible to specify a type that is inclusive of only the call without values? Perhaps its somewhere in the macro logic to generate the RuntimeCall enum or maybe a way to cheaply impl a type that does this from the fully generated RuntimeCall enum...?

Perhaps yes: https://stackoverflow.com/questions/32554285/compare-enums-only-by-variant-not-value
Will look into this

@nuke-web3
Copy link
Contributor Author

nuke-web3 commented Oct 6, 2022

Not having to create a custom ui just to handle this pallet was my goal in using the Call variants though (in part) although I agree its an option.

I want to test behavior of sending a raw encoded call with incorrect call data specified to pause, as at least to me it's unclear if that extrinsic would be rejected. I do think so though, as we need to be able to read the pallet name and call name, and dummy call data set in the pause extrinsics should fail to extract this (i hope). Stingy names can be set without a check and succeed (as it is now) to set an arbitrary, possibly meaningless via typo, filter.

Perhaps it is possible to use stringy names that are checked at execution time to be correct? Static at compile time imho is still preferred.

@Polkadot-Forum
Copy link

This pull request has been mentioned on Polkadot Forum. There might be relevant details there:

https://forum.polkadot.network/t/safe-mode-and-transaction-pause-pallets/636/4


impl ForceActivateOrigin {
/// The duration of how long the safe-mode will be activated.
pub fn duration(&self) -> u32 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I will prefer to make it

/// An origin that can enable the safe-mode by force.
 pub enum ForceActivateOrigin {
 	Weak = 5,
 	Medium = 7,
 	Strong = 11,
 }

so that frontend doesn't need to hardcod those number once more

Copy link
Contributor Author

@nuke-web3 nuke-web3 Oct 8, 2022

Choose a reason for hiding this comment

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

Cool - TIL https://doc.rust-lang.org/reference/items/enumerations.html#custom-discriminant-values-for-fieldless-enumerations is a thing

So this example diff works to yield an integer castable item, so BlockNumber works fine.

But you cannot assign the same value for any origin this way as it would conflict:

enum SharedDiscriminantError {
    SharedA = 1,
    SharedB = 1
}

I think this restriction would be OK, but hope there is a better method to get there... Open to ideas.

@Polkadot-Forum
Copy link

This pull request has been mentioned on Polkadot Forum. There might be relevant details there:

https://forum.polkadot.network/t/safe-mode-and-transaction-pause-pallets/636/6

@nuke-web3
Copy link
Contributor Author

nuke-web3 commented Oct 11, 2022

Removed RuntimeCall call values per feedback.

Introduced FullNameOf makes a handy Contains impl for calls and/or pallets to be filtered:

use pallet_tx_pause::FullNameOf;
pub struct UnfilterableCallNames;
/// Make Balances::transfer_keep_alive unfilterable, accept all others.
impl Contains<FullNameOf<Runtime>> for UnfilterableCallNames {
fn contains(full_name: &FullNameOf<Runtime>) -> bool {
let unpausables: Vec<FullNameOf<Runtime>> = vec![
(
b"Balances".to_vec().try_into().unwrap(),
Some(b"transfer_keep_alive".to_vec().try_into().unwrap()),
),
];
for unpausable_call in unpausables {
let (pallet_name, maybe_call_name) = full_name;
if pallet_name == &unpausable_call.0 {
if unpausable_call.1.is_none() {
return true
}
return maybe_call_name == &unpausable_call.1
}
}
false
}
}

@nuke-web3 nuke-web3 marked this pull request as ready for review October 12, 2022 00:38
@nuke-web3 nuke-web3 merged commit 1983a4d into oty-safe-mode Oct 12, 2022
@nuke-web3 nuke-web3 deleted the ds/tmp-sm-txp branch October 12, 2022 00:40
paritytech-processbot bot pushed a commit that referenced this pull request Aug 25, 2023
* Add safe-mode

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update pallet

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add to kitchensink-runtime

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Spelling

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Rename to tx-pause

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add SafeMode pallet

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Automatically disable safe-mode in on_init…

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add permissionless enable+extend

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add repay+slash stake methods

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add docs

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix stakes storage

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Genesis config for safe-mode pallet

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Genesis config for safe-mode pallet

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Rename ExtrinsicName to FunctionName

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Origin variable duration

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Rename FunctionName -> CallName

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Rename and docs

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Pallet safe mode tests (#12148)

* Add safe-mode mock runtime
* Add safe-mode tests
* Add ForceEnable- and ForceExtendOrigin
* Start dummy benchmarks
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Tests for `pallet-tx-pause` (#12259)

* mock added
* tests added
* dummy benchmarks started

* rename to active/inactive
tests broken, in progress

* Runtime types, fix tests

* WIP safe mode and tx pause {continued} (#12371)

* test coverage on safe mode and tx pause
* benchmarks & tests
* tests passing, use FullNameOf to check tx-pause unfilterables
* naming updates

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Set block number

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* dummy weights generated, safe mode

* add repay_reservation call with RepaymentDelay per #10033 feature requirements

* make call name optional to allow pausing pallets, handle `Contains` correctly for this throughout, doc comments started

* move to full_name notation for all interfaces, last commit introduced 1 more storage read.

* refactor is_paused

* safe math on safe mode

* Make stuff compile

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Compile

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Cleanup & renames

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Cleanup TxPause pallet

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix benches

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Refactor to fungibles::* and rename stuf

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Make compile

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix node config

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Typos

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove CausalHoldReason

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Refactor benchmarks and runtime configs

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add traits

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove old code

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Cleanup safe-mode benches

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/safe-mode/Cargo.toml

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>

* Update frame/safe-mode/Cargo.toml

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>

* Docs

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove getters

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update Cargo.lock

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove phantom

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix test

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove phantom

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Apply suggestions from code review

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>

* Use new as Origin benchmarking syntax

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Docs

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix node

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix tx-pause benches

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Renames

* Remove duplicate test

* Add docs

* docs

* Apply suggestions from code review

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com>
Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com>

* Cleanup tests

* docs

* Cleanup GenesisConfigs

* Doc traits

* Remove PauseTooLongNames

* docs

* Use V2 benchmarking

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use RuntimeHoldReason

* Fix kitchensink runtime

* Fix CI

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix CI

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Review

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Rename Stake to Deposit

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add docs

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add Notify and test it

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix kitchensink

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/safe-mode/src/tests.rs

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>

* Update frame/safe-mode/src/tests.rs

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>

* Update frame/support/src/traits/safe_mode.rs

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>

* Update frame/support/src/traits/safe_mode.rs

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>

* Update frame/support/src/traits/safe_mode.rs

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>

* Update frame/support/src/traits/tx_pause.rs

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>

* Update frame/tx-pause/src/lib.rs

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>

* Update frame/tx-pause/src/lib.rs

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>

* Update frame/tx-pause/src/mock.rs

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>

* Update frame/support/src/traits/safe_mode.rs

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>

* Simplify code

* Update frame/support/src/traits/safe_mode.rs

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>

* Update frame/support/src/traits/safe_mode.rs

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>

* Update frame/support/src/traits/safe_mode.rs

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>

* Fixup merge

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Make stuff compile

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Make tx-pause compile again

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix features

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix more features

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* ".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime=dev --target_dir=substrate --pallet=pallet_safe_mode

* Update weights

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Dan Shields <35669742+NukeManDan@users.noreply.github.com>
Co-authored-by: Dan Shields <nukemandan@protonmail.com>
Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com>
Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com>
Co-authored-by: command-bot <>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants