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

Ensure inherent are first #8173

Merged
26 commits merged into from
Apr 13, 2021
Merged

Ensure inherent are first #8173

26 commits merged into from
Apr 13, 2021

Conversation

gui1117
Copy link
Contributor

@gui1117 gui1117 commented Feb 22, 2021

fix #6243
fix #8144

polkadot companion: paritytech/polkadot#2560

Breaking change:

  • execute_block now checks that inherents are first.
  • inherent is any extrinsics, not signed and accepted by one module as inherent (ProvideInherent::is_inherent(call) == true)
  • module only check inherent for which <$module as ProvideInherent>::is_inherent(call) == true
  • any validate unsigned implementation which accept an inherent call is invalid as block producer could include them after some non inherents.

Description:

We basically introduce ProvideInherent::is_inherent(call) function and make use of it in impl_outer_inherent.

The implementation consider a signed extrinsic to be not an inherent.
So we can accept calls where ProvideInherent::is_inherent(call) == true and are signed. Those are not inherent and can be valid calls.
(note: we could refuse those, by adding some checker in extra_signed)

We also don't ensure that inherent call are successful.
And we don't ensure that inherent call are unique.

All we do is:

  • we consider unsigned extrinsic with call where ProvideInherent::is_inherent(call) == true to be inherent
  • inherent are first
  • module which requires inherent have at least one inherent (thus unsigned) for which <$module as ProvideInherent>::is_inherent(call) is true.

@github-actions github-actions bot added the A0-please_review Pull request needs code review. label Feb 22, 2021
@gui1117 gui1117 added B3-apinoteworthy C1-low PR touches the given topic and has a low impact on builders. labels Feb 22, 2021
@gui1117 gui1117 added A3-in_progress Pull request is in progress. No review needed at this stage. and removed A0-please_review Pull request needs code review. labels Feb 22, 2021
@gui1117 gui1117 added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Feb 23, 2021
@gui1117 gui1117 added A3-in_progress Pull request is in progress. No review needed at this stage. and removed A0-please_review Pull request needs code review. labels Feb 23, 2021
@gui1117 gui1117 added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Feb 23, 2021
frame/executive/src/lib.rs Show resolved Hide resolved
primitives/runtime/src/testing.rs Outdated Show resolved Hide resolved
@gui1117 gui1117 added A3-in_progress Pull request is in progress. No review needed at this stage. and removed A0-please_review Pull request needs code review. labels Feb 23, 2021
}

/// An extrinsic on which we can get access to call.
pub trait ExtrinsicCall: sp_runtime::traits::Extrinsic {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this cannot be added inside Extrinsic easily (because OpaqueExtrinsic for instance implements it), thus I extracted it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks sensible to me. Maybe I would call it ExtractCall or CallOfExtrinsic, but looks okay.

@gui1117 gui1117 removed the A3-in_progress Pull request is in progress. No review needed at this stage. label Feb 23, 2021
Copy link
Member

@shawntabrizi shawntabrizi left a comment

Choose a reason for hiding this comment

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

My general comment is that the inherent / unsigned story I think is not super clean.

It seems that the difference between an inherent tx and an unsigned tx now is whether the module remembers to write the function is_inherent.

Maybe this is as good as it gets, but i would actually expect something a little more clean, and without chance of forgetting to implement such a fine detail.

@bkchr
Copy link
Member

bkchr commented Mar 16, 2021

My general comment is that the inherent / unsigned story I think is not super clean.

It seems that the difference between an inherent tx and an unsigned tx now is whether the module remembers to write the function is_inherent.

Maybe this is as good as it gets, but i would actually expect something a little more clean, and without chance of forgetting to implement such a fine detail.

The compiler forces you to implement is_inherent, as the trait ProvideInherent requires this :P

@paritytech paritytech deleted a comment from smisty Mar 16, 2021
@paritytech paritytech deleted a comment from smisty Mar 16, 2021
@gui1117
Copy link
Contributor Author

gui1117 commented Mar 16, 2021

My general comment is that the inherent / unsigned story I think is not super clean.

It seems that the difference between an inherent tx and an unsigned tx now is whether the module remembers to write the function is_inherent.

Maybe this is as good as it gets, but i would actually expect something a little more clean, and without chance of forgetting to implement such a fine detail.

Yes, I also think it needs some documentation somewhere but this is the summary:

  • an inherent is an unsigned extrinsic, whose call is marked as inherent by one pallet.
  • non-inherent unsigned extrinsics are unsigned transactions.
  • signed extrinsic are signed transactions and not inherent.

No inherent should be accepted in ValidateUnsigned::validate_unsigned, offchain worker must not send inherent too. Otherwise the block producer can include these extrinsics after some non-inherent and the block is invalid.
Though inherent must be accepted in ValidateUnsigned::pre_dispatch.

Maybe we can improve on this with some macro attributes on calls themself so that ppl can't mess themself.

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.

audit? burnin? anything :P

@gui1117
Copy link
Contributor Author

gui1117 commented Mar 18, 2021

there is no client change, so no burnin.
I guess audit is required considering it is not trivial.

@gui1117 gui1117 added the D9-needsaudit 👮 PR contains changes to fund-managing logic that should be properly reviewed and externally audited label Mar 18, 2021
@kianenigma kianenigma added D1-audited 👍 PR contains changes to fund-managing logic that has been properly reviewed and externally audited and removed A7-needspolkadotpr D9-needsaudit 👮 PR contains changes to fund-managing logic that should be properly reviewed and externally audited labels Apr 7, 2021
@shawntabrizi
Copy link
Member

shawntabrizi commented Apr 8, 2021

@thiolliere Can you get merge-able, and then it seems we are good to go

@gui1117
Copy link
Contributor Author

gui1117 commented Apr 13, 2021

bot merge

@ghost
Copy link

ghost commented Apr 13, 2021

Trying merge.

@ghost ghost merged commit c80cc4e into master Apr 13, 2021
@ghost ghost deleted the gui-inherent-forced-at-first branch April 13, 2021 09:30
hirschenberger pushed a commit to hirschenberger/substrate that referenced this pull request Apr 14, 2021
* impl

* fix tests

* impl in execute_block

* fix tests

* add a test in frame-executive

* fix some panic warning

* use trait to get call from extrinsic

* remove unused

* fix test

* fix testing

* fix tests

* return index of extrinsic on error

* fix test

* Update primitives/inherents/src/lib.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* address comments

rename trait, and refactor

* refactor + doc improvment

* fix tests

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
@tdelabro
Copy link

Hey,
I would like to have internals executed after transactions. Around block finalization. How can I achieve this?

This pull request was closed.
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. C1-low PR touches the given topic and has a low impact on builders. D1-audited 👍 PR contains changes to fund-managing logic that has been properly reviewed and externally audited
Projects
None yet
6 participants