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

Renaming and documentation for ApplyResult, ApplyOutcome and et al #4134

Merged
merged 15 commits into from
Nov 22, 2019

Conversation

pepyakin
Copy link
Contributor

@pepyakin pepyakin commented Nov 18, 2019

This PR features:

  • Removing unused variants from ApplyError, preserving the enumeration (not sure about that, should we just use TransactionValidity directly?),
  • Renaming the ApplyResult and ApplyOutcome to (hopefully) less confusing ones.
  • Adding documentation that (again hopefuly) further reduces confusion.

This change doesn't require version bump, although it changes the external API. Therefore here is the accompanying Polkadot PR.

@bkchr
Copy link
Member

bkchr commented Nov 18, 2019

(This breaks the block authoring of Kusama)

@pepyakin
Copy link
Contributor Author

Can you shed some light on why is that?

@bkchr
Copy link
Member

bkchr commented Nov 19, 2019

We can not decode ApplyResult/InclusionOutput anymore. It is solvable, but will require a little bit more effort.
We need to add a compatibility layer as shown here: #3585. This would require that all validators update before we send out the runtime update to the network. (we should increment the authoring version as well)

Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

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

In general looking good.

primitives/block-builder/runtime-api/src/lib.rs Outdated Show resolved Hide resolved
primitives/sr-primitives/src/lib.rs Outdated Show resolved Hide resolved
/// supplies the result of the extrinsic dispatch.
///
/// Examples of reasons preventing inclusion in a block:
/// - More block weight is required to process the extrinsic than is left in the block being built.
Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't name weight here and just say block resources. Weight is Palette specific while I suppose these error types are.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahhh, that's a good point. I am mistakingly assumed that we are in the pallete context.

/// included in the next block if it has enough spare weight available.
/// - The sender doesn't have enough funds to pay the transaction inclusion fee. Including such
/// a transaction in the block doesn't make sense.
/// - The extrinsic supplied a bad signature. This transaction won't become valid ever.
Copy link
Contributor

@kianenigma kianenigma Nov 19, 2019

Choose a reason for hiding this comment

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

I would make it very clear that a dispatch has two phases 1- pre-dispatch stuff and 2- the dispatch itself.

A signature check, and any other code that we might put in Executive::apply_extrinsic_xxx is in the first group (.check). For instance a signature check gives you Err(InclusionError)

A weight check, nonce and other things that happen either in signedExtensions or dispatch code itself are in the second group. I think a wrong nonce gives you Ok(DispatchError) (while an all okay dispatch gives Ok(())).

So I would make this distinction very clear in the docs.

(take the above with a grain of slat and double check, I didn't look super deep into the code.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Based on this, without any explanation, I find it confusing that signature check and weight check are enumerated next to each other, as it seems that they are natively different types of checks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I would redirect the reader from this documentation to how apply/dispatch + SignedExtensions work in general to get more details into the lifecycle of 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.

Yeah, they are different checks in practice, but we are dealing with the non-pallete context, from the block builder API perspective, from that PoV they are essentially the same, isn't it This also relates to referencing the user to the documentation of SignedExtensions and co.

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.

Strictly better than what we have now, but still a lot of room for improvement imho. But I'm happy to merge asap, cause otherwise we may end up with never ending story of doc improvements through the entire codebase.

@@ -43,7 +43,7 @@ use sr_api::{Core, ApiExt, ApiErrorFor};
pub use runtime_api::BlockBuilder as BlockBuilderApi;

/// Error when the runtime failed to apply an extrinsic.
pub struct ApplyExtrinsicFailed(pub sr_primitives::ApplyError);
pub struct ApplyExtrinsicFailed(pub sr_primitives::InclusionError);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be renamed as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My logic was that I'd leave this as is to denote that apply_extrinsic failed because of the following reason which is represented by InclusionError.

I thought maybe it would be better to name apply_extrinsic as include_extrinsic, but that is getting out of hand...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That said, I am not strong on it. Give me a sign (thumbs up will do) and I will make the change

paint/executive/src/lib.rs Outdated Show resolved Hide resolved
primitives/block-builder/runtime-api/src/lib.rs Outdated Show resolved Hide resolved
primitives/sr-primitives/src/lib.rs Outdated Show resolved Hide resolved
primitives/sr-primitives/src/lib.rs Show resolved Hide resolved
primitives/sr-primitives/src/lib.rs Outdated Show resolved Hide resolved
/// included in the next block if it has enough spare weight available.
/// - The sender doesn't have enough funds to pay the transaction inclusion fee. Including such
/// a transaction in the block doesn't make sense.
/// - The extrinsic supplied a bad signature. This transaction won't become valid ever.
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I would redirect the reader from this documentation to how apply/dispatch + SignedExtensions work in general to get more details into the lifecycle of extrinsic.

primitives/sr-primitives/src/lib.rs Outdated Show resolved Hide resolved
Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
@pepyakin pepyakin 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 Nov 19, 2019
@pepyakin
Copy link
Contributor Author

pepyakin commented Nov 19, 2019

So I guess if we are more or less happy with this refactoring, as the next step I'd like to get some directions on how to cleanly integrate this PR into polkadot/kusama.

Apart from updating the accompanying PR with updating the authoring version there, what else should we do here? Can you guide me on this one, @bkchr ?

@pepyakin pepyakin 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 Nov 19, 2019
@gavofyork
Copy link
Member

@pepyakin re: compatibility with kusama, it's more about just ensuring that UI people are given appropriate warning.

conflicts need sorting, but otherwise should be good.

@gavofyork gavofyork added A8-looksgood and removed A0-please_review Pull request needs code review. labels Nov 22, 2019
# Conflicts:
#	bin/node/executor/src/lib.rs
#	palette/executive/src/lib.rs
#	palette/system/src/lib.rs
#	primitives/sr-primitives/src/testing.rs
#	primitives/sr-primitives/src/traits.rs
Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

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

Besides the whitespaces, it looks good.

@pepyakin pepyakin merged commit d88fff5 into master Nov 22, 2019
@pepyakin pepyakin deleted the ser-apply-clean branch November 22, 2019 16:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants