Skip to content

Conversation

@gui1117
Copy link
Contributor

@gui1117 gui1117 commented Feb 18, 2025

Rename CreateInherent to CreateBare, add method create_bare and deprecate create_inherent.

Both unsigned transaction and inherent use the extrinsic type Bare.
Before this PR CreateInherent trait was use to generate unsigned transaction, now unsigned transaction can be generated using a proper trait CreateBare.

How to upgrade:

  • Change usage of CreateInherent to CreateBare and create_inherent to create_bare.
  • Implement CreateBare for the runtime, the method create_bare is usually implemented using Extrinsic::new_bare.

@gui1117 gui1117 requested a review from a team as a code owner February 18, 2025 05:13
@gui1117 gui1117 added the R0-no-crate-publish-required The change does not require any crates to be re-published. label Feb 18, 2025
///
/// It can also be used to create an unsigned transaction as they are both the same extrinsic
/// variant: `Bare`. Unsigned transaction are deprecated in favor of general transaction.
pub trait CreateInherent<LocalCall>: CreateTransactionBase<LocalCall> {
Copy link
Member

Choose a reason for hiding this comment

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

The naming is still just wrong and trying to fix this via docs is not making it better. As I already said in the original pr, the name of the trait is wrong.

I would propose we introduce a new CreateBare with proper docs and tag this trait deprecated.

Copy link
Contributor Author

@gui1117 gui1117 Feb 19, 2025

Choose a reason for hiding this comment

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

I updated the PR: deprecate CreateInherent, introduce CreateBare and replace all usage in polkadot-sdk.

It is a breaking change so I am not sure I can backport anything to 2412, but I will backport it to 2503.

I acknowledge my mistake in transaction extension review, also overall I underestimated the stability and the pace of new feature in polkadot-sdk in 2024.

As a side note I think offchain traits could be improved as well:

  • we could remove LocalCall everywhere, people can bound RuntimeCall: From<Call> in their config
  • CreateTransactionBase could simply bound frame_system::Config as supertrait instead of having a duplicated associated type RuntimeCall that bring name conflict. (We do bound Config as supertrait for SigningTypes).
    But better not to break them.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with the offchain trait refactor, but it's probably best to do it after phase 2 of Extrinsic Horizon is done.

@gui1117 gui1117 requested a review from acatangiu as a code owner February 19, 2025 01:38
@gui1117 gui1117 changed the title Improve doc for unsigned transaction WIP: Introduce CreateBare, deprecated CreateInherent Feb 19, 2025
@paritytech-review-bot paritytech-review-bot bot requested a review from a team February 19, 2025 01:39
@gui1117 gui1117 added T1-FRAME This PR/Issue is related to core FRAME, the framework. and removed R0-no-crate-publish-required The change does not require any crates to be re-published. labels Feb 19, 2025
@gui1117 gui1117 changed the title WIP: Introduce CreateBare, deprecated CreateInherent Introduce CreateBare, deprecated CreateInherent Feb 19, 2025

/// Submit an unsigned transaction onchain with a signed payload
pub trait SendUnsignedTransaction<T: SigningTypes + CreateInherent<LocalCall>, LocalCall> {
pub trait SendUnsignedTransaction<T: SigningTypes + CreateBare<LocalCall>, LocalCall> {
Copy link
Member

Choose a reason for hiding this comment

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

If you change this, it basically means that people may have CreateInherent implemented, but it will not be used by anything.

Copy link
Member

Choose a reason for hiding this comment

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

Basically also resulting in compile errors.

Copy link
Contributor Author

@gui1117 gui1117 Feb 20, 2025

Choose a reason for hiding this comment

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

If we do this, runtime will have to implement CreateInherent with the intention of creating a bare extrinsic.

It is ok to me, and the least breaking change, but it keeps the faulty trait usage: CreateInherent, I will also add in the doc of CreateInherent the intention.

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 updated the code:

  • CreateInherent has a new method create_bare with default implementation. User can override it to specify the behavior. (not ideal but not a breaking change.)
  • CreateBare is introduced, automatically implemented for CreateInherent using CreateInherent::create_bare.
  • CreateBare is used instead of CreateInherent for SendUnsignedTransaction and it implementation for Signer.
  • pallets such as beefy are not using CreateBare in their trait bound to avoid any breaking change.
  • User are expected to implement CreateInherent for their runtime in order to keep pallet's usage.
  • User are expected to use CreateBare in their pallet, the idiomatic trait to create a bare extrinsic.

Possible alternative design: slightly more breaking, but provides a path forward:

  • I considered deprecated CreateInherent and use CreateBare in polkadot-sdk pallets. That would be a breaking change: e.g. if a pallets bounds beefy config and use T::create_inherent method then their code then it won't compile. They have to use create_bare and import CreateBase trait in scope. (note: we could introduce CreateBare::create_inherent so that rustc give some hint to import the trait in scope.)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's ok as it is right now, fixes the name and helps the dev a bit with the default impl.

@paritytech-review-bot paritytech-review-bot bot requested a review from a team February 24, 2025 01:07
@gui1117
Copy link
Contributor Author

gui1117 commented Feb 24, 2025

/cmd fmt

@gui1117
Copy link
Contributor Author

gui1117 commented Mar 3, 2025

It doesn't work either, because CreateBare takes a generic so we can't implement it directly when it is derived automatically for CreateInherent:

error[E0119]: conflicting implementations of trait `frame_system::offchain::CreateBare<_>` for type `mock::Test`
  --> substrate/frame/sassafras/src/mock.rs:59:1
   |
59 | / impl<C> frame_system::offchain::CreateBare<C> for Test
60 | | where
61 | |     RuntimeCall: From<C>,
   | |_________________________^
   |
   = note: conflicting implementation in crate `frame_system`:
           - impl<LocalCall, T> frame_system::offchain::CreateBare<LocalCall> for T
             where T: CreateInherent<LocalCall>;
   = note: downstream crates may implement trait `frame_system::offchain::CreateInherent<_>` for type `mock::Test`

For more information about this error, try `rustc --explain E0119`.
error: could not compile `pallet-sassafras` (lib test) due to 1 previous error

So instead I just renamed the trait CreateInherent to CreateBare, deprecated the method create_inherent and added the method create_bare, people updating their code will have a compile error saying create_bare is not implemented, I think it is fine because it is very easy to implement. Other than that there is no breaking change.

The deprecation of a reexport doesn't work in rust, but the doc show the rename so if people use an IDE they will see the trait is renamed.

image

@paritytech paritytech deleted a comment from github-actions bot Mar 4, 2025
@paritytech paritytech deleted a comment from github-actions bot Mar 4, 2025
@gui1117
Copy link
Contributor Author

gui1117 commented Mar 5, 2025

Considering approvals here for the PR when it was in a different state, I am not sure I should consider this PR approved.

But IMO it looks good.

@gui1117
Copy link
Contributor Author

gui1117 commented Mar 13, 2025

Having CreateBare as a trait automatically implemented for implementations CreateInherent is not doable because the trait is generic and it will fail with:

error[E0119]: conflicting implementations of trait `Bare<_>` for type `Runtime`
 --> src/lib.rs:3:1
  |
3 | impl<Call> major::Bare<Call> for Runtime {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: conflicting implementation in crate `major`:
          - impl<Call, T> Bare<Call> for T
            where T: Inherent<Call>;
  = note: downstream crates may implement trait `major::Inherent<_>` for type `Runtime`

For more information about this error, try `rustc --explain E0119`.

Having CreateInherent automatically implemented for CreateBare is doable but it is a breaking change, user will have to remove their implementation of CreateInherent and instead implement CreateBare.

In this PR, I choose a rename of the trait, I know renames are not very good but the documentation CreateInherent will show that it is renamed to CreateBare and "deprecated".

Another solution would simply to mark the trait as deprecated and create a new trait, and update all our usage for the new trait CreateBare. This will give a good deprecated warning message but also some compile error because CreateBare is not implemented.

If you have some opinion @bkchr

@gui1117
Copy link
Contributor Author

gui1117 commented May 5, 2025

@bkchr because you approve a different version that I had to change because it didn't work at the end.

This final version is:
A new trait CreateBare with 2 methods create_bare and deprecated create_inherent that default implementation is create_bare.
CreateInherent is rewrote as a type alias to CreateBare with a documentation saying it is deprecated.

User using CreateInherent will just have a warning create_inherent is deprecated in favor of create_bare.
Implementer of CreateInherent will have a compile error saying create_bare is not implemented.

I think it is good.

@gui1117 gui1117 enabled auto-merge May 26, 2025 04:25
@gui1117 gui1117 added this pull request to the merge queue May 26, 2025
Merged via the queue into master with commit 2d1883f May 26, 2025
181 of 182 checks passed
@gui1117 gui1117 deleted the gui-improve-doc branch May 26, 2025 05:47
ordian added a commit that referenced this pull request May 27, 2025
* master: (99 commits)
  Snowbridge: Remove asset location check for compatibility (#8473)
  add poke_deposit extrinsic to pallet-bounties (#8382)
  litep2p/peerset: Reject non-reserved peers in the reserved-only mode (#8650)
  Charge deposit based on key length (#8648)
  [pallet-revive] make subscription task panic on error (#8587)
  tx/metrics: Add metrics for the RPC v2 `transactionWatch_v1_submitAndWatch` (#8345)
  Bridges: Fix - Improve try-state for pallet-xcm-bridge-hub (#8615)
  Introduce CreateBare, deprecated CreateInherent (#7597)
  Use hashbrown hashmap/hashset in validation context (#8606)
  ci: rm gitlab config (#8622)
  🔪 flaky and Zombienet tests (#8600)
  cumulus: adjust unincluded segment size metric buckets (#8617)
  Benchmark storage access on block validation (#8069)
  Revert 7934 es/remove tj changes (#8611)
  collator-protocol: add more collation observability (#8230)
  `fatxpool`: add fallback for ready at light (#8533)
  txpool: fix tx removal from unlocks set (#8500)
  XCMP weight metering: account for the MQ page position (#8344)
  fix epmb solution duplicate issue + add remote mining apparatus to epm (#8585)
  Fix generated address returned by Substrate RPC runtime call (#8504)
  ...
pgherveou pushed a commit that referenced this pull request Jun 11, 2025
Rename `CreateInherent` to `CreateBare`, add method `create_bare` and
deprecate `create_inherent`.
Both unsigned transaction and inherent use the extrinsic type `Bare`.
Before this PR `CreateInherent` trait was use to generate unsigned
transaction, now unsigned transaction can be generated using a proper
trait `CreateBare`.
How to upgrade:
* Change usage of `CreateInherent` to `CreateBare` and `create_inherent`
to `create_bare`.
* Implement `CreateBare` for the runtime, the method `create_bare` is
usually implemented using `Extrinsic::new_bare`.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
fellowship-merge-bot bot pushed a commit to polkadot-fellows/runtimes that referenced this pull request Aug 7, 2025
This brings in `stable2506` Polkadot SDK, and integrates many new
features.

Integrated breaking changes to be verified by the original authors:

- [x] ~paritytech/polkadot-sdk#8127 @kianenigma
@Ank4n~
     This will come in with AHM, and not before.
- [x] paritytech/polkadot-sdk#7597 @gui1117 
- [x] paritytech/polkadot-sdk#8254 @bkchr 
- [x] paritytech/polkadot-sdk#7592 @bkontur 
- [x] paritytech/polkadot-sdk#8382
@UtkarshBhardwaj007
- [x] paritytech/polkadot-sdk#8021 @serban300 
- [x] paritytech/polkadot-sdk#8344 @serban300 
- [x] paritytech/polkadot-sdk#8262 @athei 
- [x] paritytech/polkadot-sdk#8584 @athei 
- [x] paritytech/polkadot-sdk#8299 @skunert
- [x] paritytech/polkadot-sdk#8652 @pgherveou 
- [x] paritytech/polkadot-sdk#8554 @pgherveou 
- [x] paritytech/polkadot-sdk#8281 @mrshiposha 
- [x] paritytech/polkadot-sdk#7730
@franciscoaguirre
- [x] paritytech/polkadot-sdk#8599 @yrong
@claravanstaden
- [x] paritytech/polkadot-sdk#8531 @bkontur 
- [x] paritytech/polkadot-sdk#8409 @kianenigma 
- [x] paritytech/polkadot-sdk#9137
@franciscoaguirre
- [x] paritytech/polkadot-sdk#7944 @bkontur 
- [x] paritytech/polkadot-sdk#8179 @bkontur 
- [x] paritytech/polkadot-sdk#8037 @yrong

---------

Co-authored-by: GitHub Action <[email protected]>
Co-authored-by: claravanstaden <[email protected]>
Co-authored-by: Branislav Kontur <[email protected]>
Co-authored-by: Bastian Köcher <[email protected]>
Co-authored-by: Alain Brenzikofer <[email protected]>
Co-authored-by: kianenigma <[email protected]>
Co-authored-by: Francisco Aguirre <[email protected]>
Co-authored-by: ron <[email protected]>
Co-authored-by: joe petrowski <[email protected]>
Co-authored-by: Overkillus <[email protected]>
alvicsam pushed a commit that referenced this pull request Oct 17, 2025
Rename `CreateInherent` to `CreateBare`, add method `create_bare` and
deprecate `create_inherent`.
Both unsigned transaction and inherent use the extrinsic type `Bare`.
Before this PR `CreateInherent` trait was use to generate unsigned
transaction, now unsigned transaction can be generated using a proper
trait `CreateBare`.
How to upgrade:
* Change usage of `CreateInherent` to `CreateBare` and `create_inherent`
to `create_bare`.
* Implement `CreateBare` for the runtime, the method `create_bare` is
usually implemented using `Extrinsic::new_bare`.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T1-FRAME This PR/Issue is related to core FRAME, the framework.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants