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

add notes and warnings to ProvideInherent docs #9730

Merged
merged 9 commits into from
Mar 27, 2022

Conversation

apopiak
Copy link
Contributor

@apopiak apopiak commented Sep 8, 2021

This PR makes some changes to the inherents docs to avoid misunderstandings.

@apopiak apopiak added the A3-in_progress Pull request is in progress. No review needed at this stage. label Sep 8, 2021
@apopiak apopiak requested review from bkchr and gui1117 September 8, 2021 10:12
Comment on lines 79 to 80
/// This check is not guaranteed to be run as part of consensus and cannot be relied upon for
/// security. Run security relevant checks in [`Self::create_inherent`].
Copy link
Contributor

@gui1117 gui1117 Sep 8, 2021

Choose a reason for hiding this comment

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

security checks cannot be put in create_inherent AFAIK.
I don't really know the nature of the check that check_inherent provide, but it is important for security reason otherwise there is no point to it, no ?
Some check for the validity of the timestamp is done in check_inherent.

As far as I understand this: It is what other validator will use the check the validity of the inherents provided in comparison to some inherent data that the validator will provide.
For instance, a validator will check that the timestamp is not too much in the future compared to what he considers to be the present. (I.e. compared to the time he provided in his inherent data)

@apopiak apopiak 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. D2-notlive 💤 PR contains changes in a runtime directory that is not deployed to a chain that requires an audit. labels Sep 8, 2021
@stale
Copy link

stale bot commented Oct 23, 2021

Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Oct 23, 2021
@stale stale bot closed this Nov 6, 2021
@apopiak apopiak reopened this Nov 26, 2021
@stale stale bot removed the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Nov 26, 2021
@apopiak
Copy link
Contributor Author

apopiak commented Nov 26, 2021

@bkchr @thiolliere What do you think of the rewording?

/// NOTE: All checks necessary to ensure that the inherent is correct and that can be done in
/// the runtime should happen in the returned `Call`.
/// E.g. if this provides a block producer, check in the returned extrinsic that the producer is
/// eligible to create the block.
Copy link
Contributor

@gui1117 gui1117 Nov 29, 2021

Choose a reason for hiding this comment

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

I don't very like this example, probably for the same reason as said above by Basti.

Like currently the block producer is passed by using digest, but I guess we could use an inherent.
Then the inherent could just write the author into a storage (which can be removed in on_finalize in order not to get into the block).
Later other pallets could check that the author is able to produce a block, and just panic in case he is not able to produce a block.

Thus the check whether the producer is eligible to create the block will not happen in the call, but later in the block production.

I think that this part:

/// NOTE: All checks necessary to ensure that the inherent is correct and that can be done in
/// the runtime should happen in the returned Call.

is good, but maybe as an example I would write:

E.g. if this provide the timestamp, the call will check that the given timestamp is increasing the old timestamp by more than a minimum and it will also check that the timestamp hasn't already been set.
Later in the on_finalize hook, the pallet could also ensure that the timestamp is set.

Copy link
Contributor

@gui1117 gui1117 left a comment

Choose a reason for hiding this comment

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

all good to me, except the example which I would prefer to be different https://github.com/paritytech/substrate/pull/9730/files#r758115926

/// If the inherent is not present, it will return `e`.
///
/// - `Err(_)` indicates that this function failed and further operations should be aborted.
///
/// NOTE: If inherent is required then the runtime asserts that the block contains at least
/// NOTE: If the inherent is required then the runtime asserts that the block contains at least
/// one inherent for which:
/// * type is [`Self::Call`],
/// * [`Self::is_inherent`] returns true.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure how to write it but this is_inherent_required is currently only checked by other block producer same as check_inherent, maybe we can change it to make it part of the execute_block. But it is not the case currently.

@stale
Copy link

stale bot commented Dec 29, 2021

Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Dec 29, 2021
@apopiak apopiak removed the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Jan 4, 2022
@apopiak apopiak 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 Jan 12, 2022
@apopiak apopiak marked this pull request as ready for review January 12, 2022 16:07
@stale stale bot added the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Feb 13, 2022
@paritytech paritytech deleted a comment from stale bot Feb 14, 2022
@stale stale bot removed the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Feb 14, 2022
@apopiak apopiak requested a review from gui1117 February 23, 2022 11:25
@stale
Copy link

stale bot commented Mar 25, 2022

Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Mar 25, 2022
@bkchr bkchr added the D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit label Mar 27, 2022
@stale stale bot removed the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Mar 27, 2022
@bkchr bkchr merged commit 65b44e9 into master Mar 27, 2022
@bkchr bkchr deleted the apopiak/provide-inherent-docs branch March 27, 2022 21:35
grishasobol pushed a commit to gear-tech/substrate that referenced this pull request Mar 28, 2022
* add notes and warnings to ProvideInherent docs

* rephrase ProvideInherent doc comments

* more comment refinement

* remove multiple inherents note

* remove repetition

Co-authored-by: Bastian Köcher <[email protected]>

* replace inherent example in docs

* add note about who checks is_inherent_required

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <[email protected]>

Co-authored-by: Bastian Köcher <[email protected]>
grishasobol pushed a commit to gear-tech/substrate that referenced this pull request Mar 28, 2022
* add notes and warnings to ProvideInherent docs

* rephrase ProvideInherent doc comments

* more comment refinement

* remove multiple inherents note

* remove repetition

Co-authored-by: Bastian Köcher <[email protected]>

* replace inherent example in docs

* add note about who checks is_inherent_required

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <[email protected]>

Co-authored-by: Bastian Köcher <[email protected]>
grishasobol pushed a commit to gear-tech/substrate that referenced this pull request Mar 28, 2022
* add notes and warnings to ProvideInherent docs

* rephrase ProvideInherent doc comments

* more comment refinement

* remove multiple inherents note

* remove repetition

Co-authored-by: Bastian Köcher <[email protected]>

* replace inherent example in docs

* add note about who checks is_inherent_required

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <[email protected]>

Co-authored-by: Bastian Köcher <[email protected]>
DaviRain-Su pushed a commit to octopus-network/substrate that referenced this pull request Aug 23, 2022
* add notes and warnings to ProvideInherent docs

* rephrase ProvideInherent doc comments

* more comment refinement

* remove multiple inherents note

* remove repetition

Co-authored-by: Bastian Köcher <[email protected]>

* replace inherent example in docs

* add note about who checks is_inherent_required

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <[email protected]>

Co-authored-by: Bastian Köcher <[email protected]>
ark0f pushed a commit to gear-tech/substrate that referenced this pull request Feb 27, 2023
* add notes and warnings to ProvideInherent docs

* rephrase ProvideInherent doc comments

* more comment refinement

* remove multiple inherents note

* remove repetition

Co-authored-by: Bastian Köcher <[email protected]>

* replace inherent example in docs

* add note about who checks is_inherent_required

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <[email protected]>

Co-authored-by: Bastian Köcher <[email protected]>
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. D2-notlive 💤 PR contains changes in a runtime directory that is not deployed to a chain that requires an audit. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants