1. Apr 26, 2024
    • Oliver Tale-Yazdi's avatar
      [balances] Safeguard against consumer ref underflow (#3865) · e8f7c81d
      Oliver Tale-Yazdi authored
      
      
      There are some accounts that do not have a consumer ref while having a
      reserve.
      This adds a fail-safe mechanism to trigger in the case that
      `does_consume` is true, but the assumption of `consumer>0` is not.
      
      This should prevent those accounts from loosing balance and the TI from
      getting messed up even more, but is not an "ideal" fix. TBH an ideal fix
      is not possible, since on-chain data is in an invalid state.
      
      ---------
      
      Signed-off-by: default avatarOliver Tale-Yazdi <[email protected]>
      e8f7c81d
  2. Apr 04, 2024
  3. Mar 15, 2024
  4. Mar 13, 2024
  5. Mar 04, 2024
    • Gavin Wood's avatar
      FRAME: Create `TransactionExtension` as a replacement for `SignedExtension` (#2280) · fd5f9292
      Gavin Wood authored
      Closes #2160
      
      First part of [Extrinsic
      Horizon](https://github.com/paritytech/polkadot-sdk/issues/2415
      
      )
      
      Introduces a new trait `TransactionExtension` to replace
      `SignedExtension`. Introduce the idea of transactions which obey the
      runtime's extensions and have according Extension data (né Extra data)
      yet do not have hard-coded signatures.
      
      Deprecate the terminology of "Unsigned" when used for
      transactions/extrinsics owing to there now being "proper" unsigned
      transactions which obey the extension framework and "old-style" unsigned
      which do not. Instead we have __*General*__ for the former and
      __*Bare*__ for the latter. (Ultimately, the latter will be phased out as
      a type of transaction, and Bare will only be used for Inherents.)
      
      Types of extrinsic are now therefore:
      - Bare (no hardcoded signature, no Extra data; used to be known as
      "Unsigned")
      - Bare transactions (deprecated): Gossiped, validated with
      `ValidateUnsigned` (deprecated) and the `_bare_compat` bits of
      `TransactionExtension` (deprecated).
        - Inherents: Not gossiped, validated with `ProvideInherent`.
      - Extended (Extra data): Gossiped, validated via `TransactionExtension`.
        - Signed transactions (with a hardcoded signature).
        - General transactions (without a hardcoded signature).
      
      `TransactionExtension` differs from `SignedExtension` because:
      - A signature on the underlying transaction may validly not be present.
      - It may alter the origin during validation.
      - `pre_dispatch` is renamed to `prepare` and need not contain the checks
      present in `validate`.
      - `validate` and `prepare` is passed an `Origin` rather than a
      `AccountId`.
      - `validate` may pass arbitrary information into `prepare` via a new
      user-specifiable type `Val`.
      - `AdditionalSigned`/`additional_signed` is renamed to
      `Implicit`/`implicit`. It is encoded *for the entire transaction* and
      passed in to each extension as a new argument to `validate`. This
      facilitates the ability of extensions to acts as underlying crypto.
      
      There is a new `DispatchTransaction` trait which contains only default
      function impls and is impl'ed for any `TransactionExtension` impler. It
      provides several utility functions which reduce some of the tedium from
      using `TransactionExtension` (indeed, none of its regular functions
      should now need to be called directly).
      
      Three transaction version discriminator ("versions") are now
      permissible:
      - 0b000000100: Bare (used to be called "Unsigned"): contains Signature
      or Extra (extension data). After bare transactions are no longer
      supported, this will strictly identify an Inherents only.
      - 0b100000100: Old-school "Signed" Transaction: contains Signature and
      Extra (extension data).
      - 0b010000100: New-school "General" Transaction: contains Extra
      (extension data), but no Signature.
      
      For the New-school General Transaction, it becomes trivial for authors
      to publish extensions to the mechanism for authorizing an Origin, e.g.
      through new kinds of key-signing schemes, ZK proofs, pallet state,
      mutations over pre-authenticated origins or any combination of the
      above.
      
      ## Code Migration
      
      ### NOW: Getting it to build
      
      Wrap your `SignedExtension`s in `AsTransactionExtension`. This should be
      accompanied by renaming your aggregate type in line with the new
      terminology. E.g. Before:
      
      ```rust
      /// The SignedExtension to the basic transaction logic.
      pub type SignedExtra = (
      	/* snip */
      	MySpecialSignedExtension,
      );
      /// Unchecked extrinsic type as expected by this runtime.
      pub type UncheckedExtrinsic =
      	generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
      ```
      
      After:
      
      ```rust
      /// The extension to the basic transaction logic.
      pub type TxExtension = (
      	/* snip */
      	AsTransactionExtension<MySpecialSignedExtension>,
      );
      /// Unchecked extrinsic type as expected by this runtime.
      pub type UncheckedExtrinsic =
      	generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, TxExtension>;
      ```
      
      You'll also need to alter any transaction building logic to add a
      `.into()` to make the conversion happen. E.g. Before:
      
      ```rust
      fn construct_extrinsic(
      		/* snip */
      ) -> UncheckedExtrinsic {
      	let extra: SignedExtra = (
      		/* snip */
      		MySpecialSignedExtension::new(/* snip */),
      	);
      	let payload = SignedPayload::new(call.clone(), extra.clone()).unwrap();
      	let signature = payload.using_encoded(|e| sender.sign(e));
      	UncheckedExtrinsic::new_signed(
      		/* snip */
      		Signature::Sr25519(signature),
      		extra,
      	)
      }
      ```
      
      After:
      
      ```rust
      fn construct_extrinsic(
      		/* snip */
      ) -> UncheckedExtrinsic {
      	let tx_ext: TxExtension = (
      		/* snip */
      		MySpecialSignedExtension::new(/* snip */).into(),
      	);
      	let payload = SignedPayload::new(call.clone(), tx_ext.clone()).unwrap();
      	let signature = payload.using_encoded(|e| sender.sign(e));
      	UncheckedExtrinsic::new_signed(
      		/* snip */
      		Signature::Sr25519(signature),
      		tx_ext,
      	)
      }
      ```
      
      ### SOON: Migrating to `TransactionExtension`
      
      Most `SignedExtension`s can be trivially converted to become a
      `TransactionExtension`. There are a few things to know.
      
      - Instead of a single trait like `SignedExtension`, you should now
      implement two traits individually: `TransactionExtensionBase` and
      `TransactionExtension`.
      - Weights are now a thing and must be provided via the new function `fn
      weight`.
      
      #### `TransactionExtensionBase`
      
      This trait takes care of anything which is not dependent on types
      specific to your runtime, most notably `Call`.
      
      - `AdditionalSigned`/`additional_signed` is renamed to
      `Implicit`/`implicit`.
      - Weight must be returned by implementing the `weight` function. If your
      extension is associated with a pallet, you'll probably want to do this
      via the pallet's existing benchmarking infrastructure.
      
      #### `TransactionExtension`
      
      Generally:
      - `pre_dispatch` is now `prepare` and you *should not reexecute the
      `validate` functionality in there*!
      - You don't get an account ID any more; you get an origin instead. If
      you need to presume an account ID, then you can use the trait function
      `AsSystemOriginSigner::as_system_origin_signer`.
      - You get an additional ticket, similar to `Pre`, called `Val`. This
      defines data which is passed from `validate` into `prepare`. This is
      important since you should not be duplicating logic from `validate` to
      `prepare`, you need a way of passing your working from the former into
      the latter. This is it.
      - This trait takes two type parameters: `Call` and `Context`. `Call` is
      the runtime call type which used to be an associated type; you can just
      move it to become a type parameter for your trait impl. `Context` is not
      currently used and you can safely implement over it as an unbounded
      type.
      - There's no `AccountId` associated type any more. Just remove it.
      
      Regarding `validate`:
      - You get three new parameters in `validate`; all can be ignored when
      migrating from `SignedExtension`.
      - `validate` returns a tuple on success; the second item in the tuple is
      the new ticket type `Self::Val` which gets passed in to `prepare`. If
      you use any information extracted during `validate` (off-chain and
      on-chain, non-mutating) in `prepare` (on-chain, mutating) then you can
      pass it through with this. For the tuple's last item, just return the
      `origin` argument.
      
      Regarding `prepare`:
      - This is renamed from `pre_dispatch`, but there is one change:
      - FUNCTIONALITY TO VALIDATE THE TRANSACTION NEED NOT BE DUPLICATED FROM
      `validate`!!
      - (This is different to `SignedExtension` which was required to run the
      same checks in `pre_dispatch` as in `validate`.)
      
      Regarding `post_dispatch`:
      - Since there are no unsigned transactions handled by
      `TransactionExtension`, `Pre` is always defined, so the first parameter
      is `Self::Pre` rather than `Option<Self::Pre>`.
      
      If you make use of `SignedExtension::validate_unsigned` or
      `SignedExtension::pre_dispatch_unsigned`, then:
      - Just use the regular versions of these functions instead.
      - Have your logic execute in the case that the `origin` is `None`.
      - Ensure your transaction creation logic creates a General Transaction
      rather than a Bare Transaction; this means having to include all
      `TransactionExtension`s' data.
      - `ValidateUnsigned` can still be used (for now) if you need to be able
      to construct transactions which contain none of the extension data,
      however these will be phased out in stage 2 of the Transactions Horizon,
      so you should consider moving to an extension-centric design.
      
      ## TODO
      
      - [x] Introduce `CheckSignature` impl of `TransactionExtension` to
      ensure it's possible to have crypto be done wholly in a
      `TransactionExtension`.
      - [x] Deprecate `SignedExtension` and move all uses in codebase to
      `TransactionExtension`.
        - [x] `ChargeTransactionPayment`
        - [x] `DummyExtension`
        - [x] `ChargeAssetTxPayment` (asset-tx-payment)
        - [x] `ChargeAssetTxPayment` (asset-conversion-tx-payment)
        - [x] `CheckWeight`
        - [x] `CheckTxVersion`
        - [x] `CheckSpecVersion`
        - [x] `CheckNonce`
        - [x] `CheckNonZeroSender`
        - [x] `CheckMortality`
        - [x] `CheckGenesis`
        - [x] `CheckOnlySudoAccount`
        - [x] `WatchDummy`
        - [x] `PrevalidateAttests`
        - [x] `GenericSignedExtension`
        - [x] `SignedExtension` (chain-polkadot-bulletin)
        - [x] `RefundSignedExtensionAdapter`
      - [x] Implement `fn weight` across the board.
      - [ ] Go through all pre-existing extensions which assume an account
      signer and explicitly handle the possibility of another kind of origin.
      - [x] `CheckNonce` should probably succeed in the case of a non-account
      origin.
      - [x] `CheckNonZeroSender` should succeed in the case of a non-account
      origin.
      - [x] `ChargeTransactionPayment` and family should fail in the case of a
      non-account origin.
        - [ ] 
      - [x] Fix any broken tests.
      
      ---------
      
      Signed-off-by: default avatargeorgepisaltu <[email protected]>
      Signed-off-by: default avatarAlexandru Vasile <[email protected]>
      Signed-off-by: default avatardependabot[bot] <[email protected]>
      Signed-off-by: default avatarOliver Tale-Yazdi <[email protected]>
      Signed-off-by: default avatarAlexandru Gheorghe <[email protected]>
      Signed-off-by: default avatarAndrei Sandu <[email protected]>
      Co-authored-by: default avatarNikhil Gupta <[email protected]>
      Co-authored-by: default avatargeorgepisaltu <[email protected]>
      Co-authored-by: default avatarChevdor <[email protected]>
      Co-authored-by: default avatarBastian Köcher <[email protected]>
      Co-authored-by: default avatarMaciej <[email protected]>
      Co-authored-by: default avatarJavier Viola <[email protected]>
      Co-authored-by: default avatarMarcin S. <[email protected]>
      Co-authored-by: default avatarTsvetomir Dimitrov <[email protected]>
      Co-authored-by: default avatarJavier Bullrich <[email protected]>
      Co-authored-by: default avatarKoute <[email protected]>
      Co-authored-by: default avatarAdrian Catangiu <[email protected]>
      Co-authored-by: Vladimir Istyufeev's avatarVladimir Istyufeev <[email protected]>
      Co-authored-by: default avatarRoss Bulat <[email protected]>
      Co-authored-by: default avatarGonçalo Pestana <[email protected]>
      Co-authored-by: default avatarLiam Aharon <[email protected]>
      Co-authored-by: default avatarSvyatoslav Nikolsky <[email protected]>
      Co-authored-by: default avatarAndré Silva <[email protected]>
      Co-authored-by: default avatarOliver Tale-Yazdi <[email protected]>
      Co-authored-by: default avatars0me0ne-unkn0wn <[email protected]>
      Co-authored-by: default avatarordian <[email protected]>
      Co-authored-by: default avatarSebastian Kunert <[email protected]>
      Co-authored-by: default avatarAaro Altonen <[email protected]>
      Co-authored-by: default avatarDmitry Markin <[email protected]>
      Co-authored-by: default avatarAlexandru Vasile <[email protected]>
      Co-authored-by: default avatarAlexander Samusev <[email protected]>
      Co-authored-by: default avatarJulian Eager <[email protected]>
      Co-authored-by: default avatarMichal Kucharczyk <[email protected]>
      Co-authored-by: default avatarDavide Galassi <[email protected]>
      Co-authored-by: default avatarDónal Murray <[email protected]>
      Co-authored-by: default avataryjh <[email protected]>
      Co-authored-by: default avatarTom Mi <[email protected]>
      Co-authored-by: default avatardependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
      Co-authored-by: default avatarWill | Paradox | ParaNodes.io <[email protected]>
      Co-authored-by: default avatarBastian Köcher <[email protected]>
      Co-authored-by: default avatarJoshy Orndorff <[email protected]>
      Co-authored-by: default avatarJoshy Orndorff <[email protected]>
      Co-authored-by: default avatarPG Herveou <[email protected]>
      Co-authored-by: default avatarAlexander Theißen <[email protected]>
      Co-authored-by: default avatarKian Paimani <[email protected]>
      Co-authored-by: default avatarJuan Girini <[email protected]>
      Co-authored-by: default avatarbader y <[email protected]>
      Co-authored-by: default avatarJames Wilson <[email protected]>
      Co-authored-by: default avatarjoe petrowski <[email protected]>
      Co-authored-by: default avatarasynchronous rob <[email protected]>
      Co-authored-by: default avatarParth <[email protected]>
      Co-authored-by: default avatarAndrew Jones <[email protected]>
      Co-authored-by: default avatarJonathan Udd <[email protected]>
      Co-authored-by: default avatarSerban Iorga <[email protected]>
      Co-authored-by: default avatarEgor_P <[email protected]>
      Co-authored-by: default avatarBranislav Kontur <[email protected]>
      Co-authored-by: default avatarEvgeny Snitko <[email protected]>
      Co-authored-by: default avatarJust van Stam <[email protected]>
      Co-authored-by: default avatarFrancisco Aguirre <[email protected]>
      Co-authored-by: default avatargupnik <[email protected]>
      Co-authored-by: default avatardzmitry-lahoda <[email protected]>
      Co-authored-by: default avatarzhiqiangxu <[email protected]>
      Co-authored-by: default avatarNazar Mokrynskyi <[email protected]>
      Co-authored-by: default avatarAnwesh <[email protected]>
      Co-authored-by: default avatarcheme <[email protected]>
      Co-authored-by: default avatarSam Johnson <[email protected]>
      Co-authored-by: default avatarkianenigma <[email protected]>
      Co-authored-by: default avatarJegor Sidorenko <[email protected]>
      Co-authored-by: default avatarMuharem <[email protected]>
      Co-authored-by: default avatarjoepetrowski <[email protected]>
      Co-authored-by: default avatarAlexandru Gheorghe <[email protected]>
      Co-authored-by: default avatarGabriel Facco de Arruda <[email protected]>
      Co-authored-by: default avatarSquirrel <[email protected]>
      Co-authored-by: default avatarAndrei Sandu <[email protected]>
      Co-authored-by: default avatargeorgepisaltu <[email protected]>
      Co-authored-by: command-bot <>
      fd5f9292
  6. Feb 19, 2024
    • Gilt0's avatar
      [FRAME Core] remove unnecessary overrides while using derive_impl for frame_system (#3317) · b78c72cf
      Gilt0 authored
      
      
      # Description
      
      This PR removes redundant type definition from test definition config
      implementations like
      ```
      #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
      impl frame_system::Config for Test {
          type A = A;
          ...
      }
      ```
      
      This changes avoid redundancies in the code as the macro `derive_impl`
      defines the relevant types. To implement the changes, it was a simple
      fact of running tests and making sure that the tests would still run
      while the definition would be removed.
      
      Closes #3237
      
      As a note, here is a brief account of things done from the Issue's
      description statement
      ```
      alliance migrate alliance, fast-unstake and bags list to use derive-impl #1636
      asset-conversion                                                                                            DONE
      asset-rate                                                                                                  DONE
      assets                                                                                                      DONE
      atomic-swap                                                                                                 DONE
      aura                                                                                                        DONE
      authority-discovery                                                                                         DONE                                                                     
      authorship  migrate babe and authorship to use derive-impl #1790
      babe  migrate babe and authorship to use derive-impl #1790
      bags-list migrate alliance, fast-unstake and bags list to use derive-impl #1636
      balances                                                                                                    DONE
      beefy                                                                                                       NOTHING TO DO --- also noted this error without failing tests Feb 13 13:49:08.941 ERROR runtime::timestamp: `pallet_timestamp::UnixTime::now` is called at genesis, invalid value returned: 0
      beefy-mmr                                                                                                   NOTHING TO DO
      bounties                                                                                                    DONE
      child-bounties                                                                                              DONE
      collective                                                                                                  DONE
      contracts                                                                                                   DONE
      conviction-voting                                                                                           DONE
      core-fellowship                                                                                             NOTHING TO DO
      democracy                                                                                                   DONE
      election-provider-multi-phase                                                                               NOTHING TO DO
      elections-phragmen                                                                                          DONE
      executive                                                                                                   NOTHING TO DO
      fast-unstake migrate alliance, fast-unstake and bags list to use derive-impl #1636
      glutton                                                                                                     DONE
      grandpa                                                                                                     DONE
      identity                                                                                                    DONE
      im-online                                                                                                   NOTHING TO DO
      indices Refactor indices pallet #1789
      insecure-randomness-collective-flip                                                                         DONE
      lottery                                                                                                     DONE
      membership                                                                                                  DONE
      merkle-mountain-range                                                                                       NOTHING TO DO
      message-queue                                                                                               DONE
      multisig add frame_system::DefaultConfig to individual pallet DefaultConfigs substrate#14453
      nft-fractionalization                                                                                       DONE
      nfts                                                                                                        DONE
      nicks Refactor pallet-state-trie-migration to fungible::* traits #1801                                      NOT IN REPO
      nis                                                                                                         DONE
      node-authorization                                                                                          DONE
      nomination-pools                                                                                            NOTHING TO DO -- ONLY impl for Runtime
      offences                                                                                                    DELETED EVERYTHING -- IS THAT CORRECT??
      preimage                                                                                                    DONE
      proxy add frame_system::DefaultConfig to individual pallet DefaultConfigs substrate#14453
      ranked-collective                                                                                           NOTHING TO DO
      recovery                                                                                                    DONE
      referenda                                                                                                   DONE
      remark                                                                                                      DONE
      root-offences                                                                                               DONE
      root-testing                                                                                                NOTHING TO DO
      salary                                                                                                      NOTHING TO DO
      scheduler                                                                                                   DONE
      scored-pool                                                                                                 DONE
      session                                                                                                     DONE -- substrate/frame/session/benchmarking/src/mock.rs untouched
      society                                                                                                     NOTHING TO DO
      staking                                                                                                     DONE
      staking-bags-benchmarks                                                                                     NOT IN REPO
      state-trie-migration                                                                                        NOTHING TO DO
      statement                                                                                                   DONE
      sudo                                                                                                        DONE
      system                                                                                                      DONE
      timestamp                                                                                                   DONE
      tips                                                                                                        DONE
      transaction-payment                                                                                         NOTHING TO DO
      transaction-storage                                                                                         NOTHING TO DO
      treasury                                                                                                    DONE
      try-runtime                                                                                                 NOTHING TO DO -- no specific mention of 'for Test'
      uniques                                                                                                     DONE
      utility                                                                                                     DONE
      vesting                                                                                                     DONE
      whitelist                                                                                                   DONE
      ```
      
      ---------
      
      Co-authored-by: command-bot <>
      Co-authored-by: default avatargupnik <[email protected]>
      b78c72cf
  7. Jan 31, 2024
    • Branislav Kontur's avatar
      [frame] `#[pallet::composite_enum]` improved variant count handling + removed... · bb8ddc46
      Branislav Kontur authored
      [frame] `#[pallet::composite_enum]` improved variant count handling + removed `pallet_balances`'s `MaxHolds` config (#2657)
      
      I started this investigation/issue based on @liamaharon question
      [here](https://github.com/paritytech/polkadot-sdk/pull/1801#discussion_r1410452499).
      
      ## Problem
      
      The `pallet_balances` integrity test should correctly detect that the
      runtime has correct distinct `HoldReasons` variant count. I assume the
      same situation exists for RuntimeFreezeReason.
      
      It is not a critical problem, if we set `MaxHolds` with a sufficiently
      large value, everything should be ok. However, in this case, the
      integrity_test check becomes less useful.
      
      **Situation for "any" runtime:**
      - `HoldReason` enums from different pallets:
      ```rust
              /// from pallet_nis
              #[pallet::composite_enum]
      	pub enum HoldReason {
      		NftReceipt,
      	}
      
              /// from pallet_preimage
              #[pallet::composite_enum]
      	pub enum HoldReason {
      		Preimage,
      	}
      
              // from pallet_state-trie-migration
              #[pallet::composite_enum]
      	pub enum HoldReason {
      		SlashForContinueMigrate,
      		SlashForMigrateCustomTop,
      		SlashForMigrateCustomChild,
      	}
      ```
      
      - generated `RuntimeHoldReason` enum looks like:
      ```rust
      pub enum RuntimeHoldReason {
      
          #[codec(index = 32u8)]
          Preimage(pallet_preimage::HoldReason),
      
          #[codec(index = 38u8)]
          Nis(pallet_nis::HoldReason),
      
          #[codec(index = 42u8)]
          StateTrieMigration(pallet_state_trie_migration::HoldReason),
      }
      ```
      
      - composite enum `RuntimeHoldReason` variant count is detected as `3`
      - we set `type MaxHolds = ConstU32<3>`
      - `pallet_balances::integrity_test` is ok with `3`(at least 3)
      
      However, the real problem can occur in a live runtime where some
      functionality might stop working. This is due to a total of 5 distinct
      hold reasons (for pallets with multi-instance support, it is even more),
      and not all of them can be used because of an incorrect `MaxHolds`,
      which is deemed acceptable according to the `integrity_test`:
        ```
        // pseudo-code - if we try to call all of these:
      
      T::Currency::hold(&pallet_nis::HoldReason::NftReceipt.into(),
      &nft_owner, deposit)?;
      T::Currency::hold(&pallet_preimage::HoldReason::Preimage.into(),
      &nft_owner, deposit)?;
      
      T::Currency::hold(&pallet_state_trie_migration::HoldReason::SlashForContinueMigrate.into(),
      &nft_owner, deposit)?;
      
        // With `type MaxHolds = ConstU32<3>` these two will fail
      
      T::Currency::hold(&pallet_state_trie_migration::HoldReason::SlashForMigrateCustomTop.into(),
      &nft_owner, deposit)?;
      
      T::Currency::hold(&pallet_state_trie_migration::HoldReason::SlashForMigrateCustomChild.into(),
      &nft_owner, deposit)?;
        ```  
      
      
      ## Solutions
      
      A macro `#[pallet::*]` expansion is extended of `VariantCount`
      implementation for the `#[pallet::composite_enum]` enum type. This
      expansion generates the `VariantCount` implementation for pallets'
      `HoldReason`, `FreezeReason`, `LockId`, and `SlashReason`. Enum variants
      must be plain enum values without fields to ensure a deterministic
      count.
      
      The composite runtime enum, `RuntimeHoldReason` and
      `RuntimeFreezeReason`, now sets `VariantCount::VARIANT_COUNT` as the sum
      of pallets' enum `VariantCount::VARIANT_COUNT`:
      ```rust
      #[frame_support::pallet(dev_mode)]
      mod module_single_instance {
      
      	#[pallet::composite_enum]
      	pub enum HoldReason {
      		ModuleSingleInstanceReason1,
      		ModuleSingleInstanceReason2,
      	}
      ...
      }
      
      #[frame_support::pallet(dev_mode)]
      mod module_multi_instance {
      
      	#[pallet::composite_enum]
      	pub enum HoldReason<I: 'static = ()> {
      		ModuleMultiInstanceReason1,
      		ModuleMultiInstanceReason2,
      		ModuleMultiInstanceReason3,
      	}
      ...
      }
      
      
      impl self::sp_api_hidden_includes_construct_runtime::hidden_include::traits::VariantCount
          for RuntimeHoldReason
      {
          const VARIANT_COUNT: u32 = 0
              + module_single_instance::HoldReason::VARIANT_COUNT
              + module_multi_instance::HoldReason::<module_multi_instance::Instance1>::VARIANT_COUNT
              + module_multi_instance::HoldReason::<module_multi_instance::Instance2>::VARIANT_COUNT
              + module_multi_instance::HoldReason::<module_multi_instance::Instance3>::VARIANT_COUNT;
      }
      ```
      
      In addition, `MaxHolds` is removed (as suggested
      [here](https://github.com/paritytech/polkadot-sdk/pull/2657#discussion_r1443324573))
      from `pallet_balances`, and its `Holds` are now bounded to
      `RuntimeHoldReason::VARIANT_COUNT`. Therefore, there is no need to let
      the runtime specify `MaxHolds`.
      
      
      ## For reviewers
      
      Relevant changes can be found here:
      - `substrate/frame/support/procedural/src/lib.rs` 
      -  `substrate/frame/support/procedural/src/pallet/parse/composite.rs`
      -  `substrate/frame/support/procedural/src/pallet/expand/composite.rs`
      -
      `substrate/frame/support/procedural/src/construct_runtime/expand/composite_helper.rs`
      -
      `substrate/frame/support/procedural/src/construct_runtime/expand/hold_reason.rs`
      -
      `substrate/frame/support/procedural/src/construct_runtime/expand/freeze_reason.rs`
      - `substrate/frame/support/src/traits/misc.rs`
      
      And the rest of the files is just about removed `MaxHolds` from
      `pallet_balances`
      
      ## Next steps
      
      Do the same for `MaxFreezes`
      https://github.com/paritytech/polkadot-sdk/issues/2997
      
      .
      
      ---------
      
      Co-authored-by: command-bot <>
      Co-authored-by: default avatarBastian Köcher <[email protected]>
      Co-authored-by: default avatarDónal Murray <[email protected]>
      Co-authored-by: default avatargupnik <[email protected]>
      bb8ddc46
  8. Jan 30, 2024
  9. Jan 22, 2024
  10. Nov 28, 2023
  11. Oct 24, 2023
  12. Oct 17, 2023
  13. Aug 30, 2023
  14. Aug 23, 2023
    • juangirini's avatar
      Restructure `frame_support` macro related exports (#14745) · 878c562c
      juangirini authored
      
      
      * make reexports private
      
      * make reexports private 2
      
      * make reexports private for runtime-benchmarking
      
      * make reexports private for try-runtime
      
      * fix for try-runtime
      
      * make reexports private for tests
      
      * fmt
      
      * make reexports private for tests
      
      * make reexports private for experimental
      
      * fix beefy
      
      * fix ui test
      
      * fix ui test
      
      * fix benches
      
      * ".git/.scripts/commands/fmt/fmt.sh"
      
      * fix contracts use
      
      * wip
      
      * wip
      
      * do not reexport sp_api::metadata_ir
      
      * fix CI checks
      
      * fix support tests
      
      * ".git/.scripts/commands/fmt/fmt.sh"
      
      * Update frame/support/src/lib.rs
      
      Co-authored-by: default avatarBastian Köcher <[email protected]>
      
      * import codec directly
      
      * fmt
      
      * fix node-cli tests
      
      ---------
      
      Co-authored-by: command-bot <>
      Co-authored-by: default avatarBastian Köcher <[email protected]>
      878c562c
  15. Jul 14, 2023
    • juangirini's avatar
      Replace system config `Index` for `Nonce` (#14290) · 6a29a70a
      juangirini authored
      * replace Index by Nonce
      
      * replace Index by Nonce
      
      * replace Index by Nonce
      
      * replace Index by Nonce
      
      * replace Index by Nonce
      
      * wip
      
      * remove index in lieu of nonce
      
      * wip
      
      * remove accountnonce in lieu of nonce
      
      * add minor improvement
      
      * rebase and merge conflicts
      6a29a70a
  16. Jul 13, 2023
    • gupnik's avatar
      Moves `Block` to `frame_system` instead of `construct_runtime` and removes... · 5e7b27e9
      gupnik authored
      
      Moves `Block` to `frame_system` instead of `construct_runtime` and removes `Header` and `BlockNumber` (#14437)
      
      * Initial setup
      
      * Adds node block
      
      * Uses UncheckedExtrinsic and removes Where section
      
      * Updates frame_system to use Block
      
      * Adds deprecation warning
      
      * Fixes pallet-timestamp
      
      * Removes Header and BlockNumber
      
      * Addresses review comments
      
      * Addresses review comments
      
      * Adds comment about compiler bug
      
      * Removes where clause
      
      * Refactors code
      
      * Fixes errors in cargo check
      
      * Fixes errors in cargo check
      
      * Fixes warnings in cargo check
      
      * Formatting
      
      * Fixes construct_runtime tests
      
      * Uses import instead of full path for BlockNumber
      
      * Uses import instead of full path for Header
      
      * Formatting
      
      * Fixes construct_runtime tests
      
      * Fixes imports in benchmarks
      
      * Formatting
      
      * Fixes construct_runtime tests
      
      * Formatting
      
      * Minor updates
      
      * Fixes construct_runtime ui tests
      
      * Fixes construct_runtime ui tests with 1.70
      
      * Fixes docs
      
      * Fixes docs
      
      * Adds u128 mock block type
      
      * Fixes split example
      
      * fixes for cumulus
      
      * ".git/.scripts/commands/fmt/fmt.sh"
      
      * Updates new tests
      
      * Fixes fully-qualified path in few places
      
      * Formatting
      
      * Update frame/examples/default-config/src/lib.rs
      
      Co-authored-by: default avatarJuan <[email protected]>
      
      * Update frame/support/procedural/src/construct_runtime/mod.rs
      
      Co-authored-by: default avatarJuan <[email protected]>
      
      * ".git/.scripts/commands/fmt/fmt.sh"
      
      * Addresses some review comments
      
      * Fixes build
      
      * ".git/.scripts/commands/fmt/fmt.sh"
      
      * Update frame/democracy/src/lib.rs
      
      Co-authored-by: default avatarOliver Tale-Yazdi <[email protected]>
      
      * Update frame/democracy/src/lib.rs
      
      Co-authored-by: default avatarOliver Tale-Yazdi <[email protected]>
      
      * Update frame/support/procedural/src/construct_runtime/mod.rs
      
      Co-authored-by: default avatarOliver Tale-Yazdi <[email protected]>
      
      * Update frame/support/procedural/src/construct_runtime/mod.rs
      
      Co-authored-by: default avatarOliver Tale-Yazdi <[email protected]>
      
      * Addresses review comments
      
      * Updates trait bounds
      
      * Minor fix
      
      * ".git/.scripts/commands/fmt/fmt.sh"
      
      * Removes unnecessary bound
      
      * ".git/.scripts/commands/fmt/fmt.sh"
      
      * Updates test
      
      * Fixes build
      
      * Adds a bound for header
      
      * ".git/.scripts/commands/fmt/fmt.sh"
      
      * Removes where block
      
      * Minor fix
      
      * Minor fix
      
      * Fixes tests
      
      * ".git/.scripts/commands/update-ui/update-ui.sh" 1.70
      
      * Updates test
      
      * Update primitives/runtime/src/traits.rs
      
      Co-authored-by: default avatarBastian Köcher <[email protected]>
      
      * Update primitives/runtime/src/traits.rs
      
      Co-authored-by: default avatarBastian Köcher <[email protected]>
      
      * Updates doc
      
      * Updates doc
      
      ---------
      
      Co-authored-by: command-bot <>
      Co-authored-by: default avatarJuan <[email protected]>
      Co-authored-by: default avatarOliver Tale-Yazdi <[email protected]>
      Co-authored-by: default avatarBastian Köcher <[email protected]>
      5e7b27e9
  17. Jul 12, 2023
    • Michal Kucharczyk's avatar
      `GenesisBuild<T,I>` deprecated. `BuildGenesisConfig` added. (#14306) · 87d41d0a
      Michal Kucharczyk authored
      
      
      * frame::support: GenesisConfig types for Runtime enabled
      
      * frame::support: macro generating GenesisBuild::build for RuntimeGenesisConfig
      
      * frame: ambiguity BuildStorage vs GenesisBuild fixed
      
      * fix
      
      * RuntimeGenesisBuild added
      
      * Revert "frame: ambiguity BuildStorage vs GenesisBuild fixed"
      
      This reverts commit 950f3d019d0e21c55a739c44cc19cdabd3ff0293.
      
      * Revert "fix"
      
      This reverts commit a2f76dd24e9a16cf9230d45825ed28787211118b.
      
      * Revert "RuntimeGenesisBuild added"
      
      This reverts commit 3c131b618138ced29c01ab8d15d8c6410c9e128b.
      
      * Revert "Revert "frame: ambiguity BuildStorage vs GenesisBuild fixed""
      
      This reverts commit 2b1ecd467231eddec69f8d328039ba48a380da3d.
      
      * Revert "Revert "fix""
      
      This reverts commit fd7fa629adf579d83e30e6ae9fd162637fc45e30.
      
      * Code review suggestions
      
      * frame: BuildGenesisConfig added, BuildGenesis deprecated
      
      * frame: some pallets updated with BuildGenesisConfig
      
      * constuct_runtime: support for BuildGenesisConfig
      
      * frame::support: genesis_build macro supports BuildGenesisConfig
      
      * frame: BuildGenesisConfig added, BuildGenesis deprecated
      
      * Cargo.lock update
      
      * test-runtime: fixes
      
      * Revert "fix"
      
      This reverts commit a2f76dd24e9a16cf9230d45825ed28787211118b.
      
      * Revert "frame: ambiguity BuildStorage vs GenesisBuild fixed"
      
      This reverts commit 950f3d019d0e21c55a739c44cc19cdabd3ff0293.
      
      * self review
      
      * doc fixed
      
      * ui tests fixed
      
      * fmt
      
      * tests fixed
      
      * genesis_build macrto fixed for non-generic GenesisConfig
      
      * BuildGenesisConfig constraints added
      
      * warning fixed
      
      * some duplication removed
      
      * fmt
      
      * fix
      
      * doc tests fix
      
      * doc fix
      
      * cleanup: remove BuildModuleGenesisStorage
      
      * self review comments
      
      * fix
      
      * Update frame/treasury/src/tests.rs
      
      Co-authored-by: default avatarSebastian Kunert <[email protected]>
      
      * Update frame/support/src/traits/hooks.rs
      
      Co-authored-by: default avatarSebastian Kunert <[email protected]>
      
      * doc fix: GenesisBuild exposed
      
      * ".git/.scripts/commands/fmt/fmt.sh"
      
      * frame: more serde(skip) + cleanup
      
      * Update frame/support/src/traits/hooks.rs
      
      Co-authored-by: default avatarDavide Galassi <[email protected]>
      
      * frame: phantom fields moved to the end of structs
      
      * chain-spec: Default::default cleanup
      
      * test-runtime: phantom at the end
      
      * merge master fixes
      
      * fix
      
      * fix
      
      * fix
      
      * fix
      
      * fix (facepalm)
      
      * Update frame/support/procedural/src/pallet/expand/genesis_build.rs
      
      Co-authored-by: default avatarBastian Köcher <[email protected]>
      
      * fmt
      
      * fix
      
      * fix
      
      ---------
      
      Co-authored-by: parity-processbot <>
      Co-authored-by: default avatarSebastian Kunert <[email protected]>
      Co-authored-by: default avatarDavide Galassi <[email protected]>
      Co-authored-by: default avatarBastian Köcher <[email protected]>
      87d41d0a
  18. May 24, 2023
    • Bastian Köcher's avatar
      HoldReason: Improve usage (#13869) · 05da6d8e
      Bastian Köcher authored
      
      
      * HoldReason: Improve usage
      
      `HoldReason` was switched recently to use the `composite_enum` attribute that will merge the enums
      from all pallets in the runtime to `RuntimeHoldReason`. `pallet-nis` was still requiring that the
      variant was passed as constant to call `hold`. The proper implementation is to use the `HoldReason`
      from inside the pallet directly when calling `hold`. This is done by adding a `RuntimeHoldReason` as
      type to the `Config` trait and requiring that `Currency` is using the same reason. Besides that the
      pr changes the name `HoldIdentifier` in `pallet_balances::Config` to `RuntimeHoldReason`.
      
      * Update frame/nis/src/lib.rs
      
      Co-authored-by: default avatarOliver Tale-Yazdi <[email protected]>
      
      * Review comment
      
      * Fixes
      
      ---------
      
      Co-authored-by: default avatarOliver Tale-Yazdi <[email protected]>
      05da6d8e
  19. May 17, 2023
  20. May 04, 2023
    • Liam Aharon's avatar
      fungible conformance tests: Inspect and Mutate (#13852) · 9c53fd72
      Liam Aharon authored
      
      
      * typo
      
      * - create test files for each fungile trait
      - begin implementing tests for the Inspect trait
      
      * wrap inspect tests in a macro
      
      * first run of mutate tests
      
      * move test implementation out of ballances
      
      * make tests more generic
      
      * transfer tests
      
      * combine inspect and mutate tests
      
      * set balance failing tests
      
      * can_deposit tests
      
      * can_withdraw tests
      
      * test reducible_balance
      
      * remove balanced stub
      
      * revert set_balance return val fix
      
      * typo
      
      * macro and dust trap tests
      
      * disable test when it doesn't make sense
      
      * remove debug comment
      
      * reduce macro boilerplate
      
      * improved var naming
      
      * improve variable naming
      
      * remove redundant comment
      
      * remove placeholder tests
      
      * remove placeholder tests
      
      * simplify macro
      
      * Update frame/balances/src/tests/fungible_conformance_tests.rs
      
      Co-authored-by: default avatarKian Paimani <[email protected]>
      
      * use Balance from T
      
      * fix copyright
      
      * add test doc comments
      
      * improve test naming
      
      * clippy
      
      * fix rustdoc errors
      
      * fix rustdoc
      
      * improve macro
      
      * improve variable naming
      
      * remove redundant comment
      
      * use path
      
      ---------
      
      Co-authored-by: default avatarKian Paimani <[email protected]>
      9c53fd72
  21. Apr 27, 2023
  22. Mar 24, 2023
  23. Mar 18, 2023
    • Gavin Wood's avatar
      Deprecate `Currency`; introduce holds and freezing into `fungible` traits (#12951) · 5d81f23f
      Gavin Wood authored
      
      
      * First reworking of fungibles API
      
      * New API and docs
      
      * More fungible::* API improvements
      
      * New ref-counting logic for old API
      
      * Missing files
      
      * Fixes
      
      * Use the new transfer logic
      
      * Use fungibles for the dispatchables
      
      * Use shelve/restore names
      
      * Locking works with total balance.
      
      * repotting and removal
      
      * Separate Holds from Reserves
      
      * Introduce freezes
      
      * Missing files
      
      * Tests for freezing
      
      * Fix hold+freeze combo
      
      * More tests
      
      * Fee-free dispatchable for upgrading accounts
      
      * Benchmarks and a few fixes
      
      * Another test
      
      * Docs and refactor to avoid blanket impls
      
      * Repot
      
      * Fit out ItemOf fully
      
      * Add events to Balanced traits
      
      * Introduced events into Hold traits
      
      * Fix Assets pallet tests
      
      * Assets benchmarks pass
      
      * Missing files and fixes
      
      * Fixes
      
      * Fixes
      
      * Benchmarks fixes
      
      * Fix balance benchmarks
      
      * Formatting
      
      * Expose fungible sub modules
      
      * Move NIS to fungible API
      
      * Fix broken impl and add test
      
      * Fix tests
      
      * API for `transfer_and_hold`
      
      * Use composite APIs
      
      * Formatting
      
      * Upgraded event
      
      * Fixes
      
      * Fixes
      
      * Fixes
      
      * Fixes
      
      * Repot tests and some fixed
      
      * Fix some bits
      
      * Fix dust tests
      
      * Rename `set_balance`
      
      - `Balances::set_balance` becomes `Balances::force_set_balance`
      - `Unbalanced::set_balance` becomes `Unbalances::write_balance`
      
      * becomes
      
      * Move dust handling to fungibles API
      
      * Formatting
      
      * Fixes and more refactoring
      
      * Fixes
      
      * Fixes
      
      * Fixes
      
      * Fixes
      
      * Fixes
      
      * Fixes
      
      * Fixes
      
      * Fixes
      
      * Fixes
      
      * Use reducible_balance for better correctness on fees
      
      * Reducing hold to zero should remove entry.
      
      * Add test
      
      * Docs
      
      * Update frame/support/src/traits/tokens/fungibles/hold.rs
      
      Co-authored-by: default avatarMuharem Ismailov <[email protected]>
      
      * Update frame/support/src/traits/tokens/fungibles/regular.rs
      
      Co-authored-by: default avatarMuharem Ismailov <[email protected]>
      
      * Update frame/support/src/traits/tokens/fungible/hold.rs
      
      Co-authored-by: default avatarMuharem Ismailov <[email protected]>
      
      * Update frame/support/src/traits/tokens/fungible/regular.rs
      
      Co-authored-by: default avatarMuharem Ismailov <[email protected]>
      
      * Docs
      
      * Docs
      
      * Docs
      
      * Fix NIS benchmarks
      
      * Doc comment
      
      * Remove post_mutation
      
      * Fix some tests
      
      * Fix some grumbles
      
      * Enumify bool args to fungible(s) functions
      
      * Fix up assets and balances
      
      * Formatting
      
      * Fix contracts
      
      * Fix tests & benchmarks build
      
      * Typify minted boolean arg
      
      * Typify on_hold boolean arg; renames
      
      * Fix numerous tests
      
      * Fix dependency issue
      
      * Privatize dangerous API mutate_account
      
      * Fix contracts (@alext - please check this commit)
      
      * Remove println
      
      * Fix tests for contracts
      
      * Fix broken rename
      
      * Fix broken rename
      
      * Fix broken rename
      
      * Docs
      
      * Update frame/support/src/traits/tokens/fungible/hold.rs
      
      Co-authored-by: default avatarAnthony Alaribe <[email protected]>
      
      * remove from_ref_time
      
      * Update frame/executive/src/lib.rs
      
      Co-authored-by: default avatarAnthony Alaribe <[email protected]>
      
      * Update frame/executive/src/lib.rs
      
      Co-authored-by: default avatarAnthony Alaribe <[email protected]>
      
      * Reenable test
      
      * Update frame/support/src/traits/tokens/fungibles/hold.rs
      
      Co-authored-by: default avatarAnthony Alaribe <[email protected]>
      
      * Update frame/support/src/traits/tokens/fungible/hold.rs
      
      Co-authored-by: default avatarAnthony Alaribe <[email protected]>
      
      * Update frame/support/src/traits/tokens/fungible/hold.rs
      
      Co-authored-by: default avatarAnthony Alaribe <[email protected]>
      
      * Update frame/support/src/traits/tokens/fungible/hold.rs
      
      Co-authored-by: default avatarAnthony Alaribe <[email protected]>
      
      * Update frame/support/src/traits/tokens/currency.rs
      
      Co-authored-by: default avatarAnthony Alaribe <[email protected]>
      
      * Update frame/lottery/src/tests.rs
      
      Co-authored-by: default avatarAnthony Alaribe <[email protected]>
      
      * Update frame/support/src/traits/tokens/fungible/mod.rs
      
      Co-authored-by: default avatarAnthony Alaribe <[email protected]>
      
      * Update frame/support/src/traits/tokens/fungible/regular.rs
      
      Co-authored-by: default avatarAnthony Alaribe <[email protected]>
      
      * Update frame/support/src/traits/tokens/fungibles/freeze.rs
      
      Co-authored-by: default avatarAnthony Alaribe <[email protected]>
      
      * Update frame/support/src/traits/tokens/fungible/regular.rs
      
      Co-authored-by: default avatarAnthony Alaribe <[email protected]>
      
      * Update frame/support/src/traits/tokens/fungibles/hold.rs
      
      Co-authored-by: default avatarAnthony Alaribe <[email protected]>
      
      * Update frame/support/src/traits/tokens/fungibles/hold.rs
      
      Co-authored-by: default avatarAnthony Alaribe <[email protected]>
      
      * Update frame/support/src/traits/tokens/fungibles/hold.rs
      
      Co-authored-by: default avatarAnthony Alaribe <[email protected]>
      
      * Rename UnwantedRemoval to UnwantedAccountRemoval
      
      * Docs
      
      * Formatting
      
      * Update frame/balances/src/lib.rs
      
      Co-authored-by: default avatarOliver Tale-Yazdi <[email protected]>
      
      * Update primitives/runtime/src/lib.rs
      
      Co-authored-by: default avatarKeith Yeung <[email protected]>
      
      * handle_raw_dust oes nothing
      
      * Formatting
      
      * Fixes
      
      * Grumble
      
      * Fixes
      
      * Add test
      
      * Add test
      
      * Tests for reducible_balance
      
      * Fixes
      
      * Fix Salary
      
      * Fixes
      
      * Disable broken test
      
      * Disable nicely
      
      * Fixes
      
      * Fixes
      
      * Fixes
      
      * Rename some events
      
      * Fix nomination pools breakage
      
      * Add compatibility stub for transfer tx
      
      * Reinstate a safely compatible version of Balances set_balance
      
      * Fixes
      
      * Grumble
      
      * Update frame/nis/src/lib.rs
      
      Co-authored-by: default avatarKian Paimani <[email protected]>
      
      * ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_balances
      
      * disable flakey tests
      
      * Update frame/balances/src/lib.rs
      
      Co-authored-by: default avatarKian Paimani <[email protected]>
      
      * Grumbles
      
      * Grumble
      
      ---------
      
      Co-authored-by: default avatarMuharem Ismailov <[email protected]>
      Co-authored-by: default avatarAlexander Theißen <[email protected]>
      Co-authored-by: default avatarAnthony Alaribe <[email protected]>
      Co-authored-by: default avatarOliver Tale-Yazdi <[email protected]>
      Co-authored-by: default avatarKeith Yeung <[email protected]>
      Co-authored-by: default avatarKian Paimani <[email protected]>
      Co-authored-by: command-bot <>
      5d81f23f