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

Refactor SignedExtension #5540

Merged
merged 8 commits into from
Apr 8, 2020
Merged

Refactor SignedExtension #5540

merged 8 commits into from
Apr 8, 2020

Conversation

athei
Copy link
Member

@athei athei commented Apr 6, 2020

polkadot companion: paritytech/polkadot#979

This PR refactors the trait SignedExtension. The following changes where applied:

Move the DispatchInfo associated type to Dispatchable::Info

This information logically belongs to the Dispatchable. Not having it there requires consuming types to duplicate this as an associated type (SignedExtension, Applyable).

Bound Call: Dispatchable

This is a requirement for the first change. Because the DispatchInfo type is now an associated type on Dispatchable.

Pass Dispatchable::PostInfo to SignedExtension::post_dispatch

This is a followup of #5458 that passes this new information to the SignedExtension where it can then be used to accomplish weight refund (in a followup PR).

Pass Dispatchable::Info by reference

There was no apparent reason (or is there one?) for having DispatchInfo to be cloned into every SignedExtension.

@athei athei added the A0-please_review Pull request needs code review. label Apr 6, 2020
@athei athei requested review from tomusdrw and kianenigma April 6, 2020 10:46
@athei athei requested review from pepyakin and gui1117 as code owners April 6, 2020 10:46
@parity-cla-bot
Copy link

It looks like @athei signed our Contributor License Agreement. 👍

Many thanks,

Parity Technologies CLA Bot

Copy link
Contributor

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

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

on the right track, but we need to reduce boilerplate

frame/balances/src/tests.rs Outdated Show resolved Hide resolved
frame/balances/src/tests_composite.rs Outdated Show resolved Hide resolved
frame/balances/src/tests_local.rs Outdated Show resolved Hide resolved
frame/executive/src/lib.rs Outdated Show resolved Hide resolved
frame/executive/src/lib.rs Show resolved Hide resolved
frame/staking/src/lib.rs Outdated Show resolved Hide resolved
frame/transaction-payment/src/lib.rs Show resolved Hide resolved
primitives/runtime/src/generic/checked_extrinsic.rs Outdated Show resolved Hide resolved
primitives/runtime/src/traits.rs Show resolved Hide resolved
frame/balances/src/tests.rs Outdated Show resolved Hide resolved
frame/balances/src/tests_composite.rs Outdated Show resolved Hide resolved
frame/balances/src/tests_local.rs Outdated Show resolved Hide resolved
frame/example/src/lib.rs Outdated Show resolved Hide resolved
frame/example/src/lib.rs Outdated Show resolved Hide resolved
frame/executive/src/lib.rs Show resolved Hide resolved
frame/staking/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

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

I realised something:

I don't think it actually makes sense for dispatchInfo to be generic at the moment. Maybe we can make it generic, but currently it isn't.
otherwise, it doesn't even make sense for it to be generic as it is since it is kinda hard-coded in frame-support::dispatch. Your weight annotation must return weight + pays_fee + class and then they get bundled into this type DispatchInfo.

Yes, you can use any type to compute these 3, but they are fixed themselves. From this PoV I think this work needs to be refactored again.

I recommend merging this PR leniently just to unblock weight refund and I can make a follow up asap and my goal would be actually to either rethink the whole process or make it un-generic, as it used to be.

@athei
Copy link
Member Author

athei commented Apr 6, 2020

An alternative approach would be that I pass the Dispatchable::PostInfo as an additional associated type of SignedExtension. Then the refactor can happen after getting the refund merged. However, this would clash with how we want to do it eventually (move associated types way from SignedExtension. @tomusdrw what do you think?

@tomusdrw
Copy link
Contributor

tomusdrw commented Apr 6, 2020

I don't think it actually makes sense for dispatchInfo to be generic at the moment. Maybe we can make it generic, but currently it isn't.

Yes, I think @athei is fully aware of that, but it making it a fixed type would require moving Dispatchable to sp_runtime (which might be another big task).

An alternative approach would be that I pass the Dispatchable::PostInfo as an additional associated type of SignedExtension. Then the refactor can happen after getting the refund merged. However, this would clash with how we want to do it eventually (move associated types way from SignedExtension. @tomusdrw what do you think?

I think this PR looks good and is a bit nicer than current approach, so I think we should merge it as is (especially that it unlocks stuff). We can further change it in the future if needed.

@athei
Copy link
Member Author

athei commented Apr 6, 2020

Yes, I think @athei is fully aware of that, but it making it a fixed type would require moving Dispatchable to sp_runtime (which might be another big task).

Dispatchableis in sp_runtime. Do you mean FRAME?

@tomusdrw
Copy link
Contributor

tomusdrw commented Apr 6, 2020

Dispatchableis in sp_runtime. Do you mean FRAME?

Ugh, yes. So it's now generic, since weight is frame-specific, right?

@athei
Copy link
Member Author

athei commented Apr 6, 2020

Yes Dispatchable is generic since #5458.

athei and others added 7 commits April 7, 2020 09:50
* Move DispatchInfo Associated type to Dispatchable
* Bound Call: Dispatchable
* Pass PostDispatchInfo to post_dispatch
* Pass DispatchInfo by reference to avoid clones
Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
@athei athei force-pushed the at-refactor-signed-extension branch from dabb4d3 to 211334a Compare April 7, 2020 07:51
@athei
Copy link
Member Author

athei commented Apr 7, 2020

I think this PR looks good and is a bit nicer than current approach, so I think we should merge it as is (especially that it unlocks stuff). We can further change it in the future if needed.

That would be nice. I think I addressed all raised concerns now. Praying to CI gods.

frame/balances/src/tests_composite.rs Outdated Show resolved Hide resolved
primitives/runtime/src/traits.rs Show resolved Hide resolved
Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>
@athei
Copy link
Member Author

athei commented Apr 7, 2020

I added the Polkadot companion and tested it against this PR locally.

@gavofyork gavofyork merged commit 78cb165 into master Apr 8, 2020
@gavofyork gavofyork deleted the at-refactor-signed-extension branch April 8, 2020 09:12
@athei athei mentioned this pull request Apr 8, 2020
lamafab pushed a commit to lamafab/substrate that referenced this pull request Jun 16, 2020
…adot#986 (paritytech#982)

* Companion PR to paritytech#5560

* Set priorities.

* Update substrate.

* Fix tests.

* Update Substrate

* Companion of SignedExtension refactor (paritytech#5540)

Co-authored-by: Tomasz Drwięga <tomasz@parity.io>
Co-authored-by: Alexander Theißen <alexander.theissen@parity.io>
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants