Skip to content
Snippets Groups Projects
  1. Mar 13, 2025
  2. Mar 11, 2025
    • Alexandru Vasile's avatar
      network: Make litep2p the default backend in Kusama (#7866) · bcc272a1
      Alexandru Vasile authored
      This PR makes the litep2p backend the default network backend in Kusama.
      
      We performed a gradual rollout in Kusama by asking validators to
      manually switch to litep2p. The rollout went smoothly, with 250
      validators running litep2p without issues. This PR represents the next
      step in testing the backend at scale.
      
      Thanks to everyone who contributed to making this happen! A special
      shoutout to the validators for their prompt support and cooperation :pray:
      
      While at it, the litep2p release is bumped to the latest 0.9.2, which
      downgrades a spamming log to debug.
      
      
      ### CLI Testing Done
      
      
      ```
      ### Kusama without network backend specified
      RUST_LOG=info ./target/release/polkadot --chain kusama --pruning=1000 --in-peers 50 --out-peers 50 --sync=warp --detailed-log-output
      2025-03-10 14:24:18.503  INFO main sub-libp2p: Running litep2p network backend
      
      ### Kusama with libp2p
      RUST_LOG=info ./target/release/polkadot --chain kusama --pruning=1000 --in-peers 50 --out...
      bcc272a1
    • Sebastian Kunert's avatar
      slot-based-collator: Allow multiple blocks per slot (#7569) · 8ddb0714
      Sebastian Kunert authored
      **Summary:** This PR enables authoring of multiple blocks in one AURA
      slot in the slot-based collator and stabilizes the slot-based collator.
      
      ## CLI Changes
      The flag `--experimental-use-slot-based` is now marked as deprecated. I
      opted to introduce `--authoring slot-based` instead of just removing the
      `experimental` prefix. By introducing the `authoring` variant, we get
      some future-proofing in case we want to introduce further options.
      
      ## Change Description
      With elastic-scaling, we are able to author multiple blocks with a
      single relay-chain parent. In the initial iteration, the interval
      between two blocks was determined by the `slot_duration` of the
      parachain. This PR introduces a more flexible model, where we try to
      author multiple blocks in a single slot if the runtime allows it.
      
      The block authoring loop is largely the same. The
      [`SlotTimer`](https://github.com/paritytech/polkadot-sdk/blob/f1935bd9/cumulus/cli...
      8ddb0714
  3. Mar 06, 2025
  4. Feb 27, 2025
  5. Feb 24, 2025
    • CrabGopher's avatar
      optional rocksdb for frame-benchmarking-cli (#7649) · 2edabef4
      CrabGopher authored
      `sc-cli` brings rocksdb dependency into frame-benchmarking-cli when used
      with `default-features = false`.
      This PR makes rocksdb deps optional that sc-cli brings in some of the
      crates. I think I covered all the crates that depend on sc-cli but
      please let me know if I missed any.
      
      Fixes: https://github.com/paritytech/polkadot-sdk/issues/3793
      2edabef4
  6. Feb 14, 2025
    • Florian Franzen's avatar
      cumulus-client: use only valid syntax in Cargo.toml (#7455) · 9117f70f
      Florian Franzen authored
      # Description
      
      This PR ensure that only valid syntax is uses inside the `Cargo.toml`. 
      
      ## Integration
      
      Not sure if worth backporting. Came across this when trying to package
      `try-runtime-cli`.
      
      ## Review Notes
      
      It should be obvious that this is not valid syntax. I am not able to add
      labels and doubt this requires a prdoc.
      9117f70f
  7. Feb 13, 2025
  8. Feb 07, 2025
    • Przemek Rzad's avatar
      Ensure license headers match the Cargo manifest licenses (#5776) · 3726493d
      Przemek Rzad authored
      
      - Closes https://github.com/paritytech/license-scanner/issues/44
      - Silent because only comments are changed in the crates.
      
      ## What's inside
      
      First, we change the file traversal mechanism from shell globbing to
      walking through files which happens inside the `license-scanner` - so it
      has knowledge about directory structure and can correlate files with
      corresponding Cargo manifest.
      
      Next, added `MIT-0` and `Unlicense` to the allowed list of licenses.
      `Unlicense` appears only once across {Substrate,Cumulus,Polkadot} - in
      `penpal-runtime`.
      
      Finally, updated headers in files that do not match the corresponding
      manifest license.
      
      ---------
      
      Co-authored-by: Yuri Volkov's avatarcornholio <0@mcornholio.ru>
      3726493d
  9. Feb 03, 2025
    • Alin Dima's avatar
      deprecate AsyncBackingParams (#7254) · 4cd07c56
      Alin Dima authored
      
      Part of https://github.com/paritytech/polkadot-sdk/issues/5079.
      
      Removes all usage of the static async backing params, replacing them
      with dynamically computed equivalent values (based on the claim queue
      and scheduling lookahead).
      
      Adds a new runtime API for querying the scheduling lookahead value. If
      not present, falls back to 3 (the default value that is backwards
      compatible with values we have on production networks for
      allowed_ancestry_len)
      
      Also resolves most of
      https://github.com/paritytech/polkadot-sdk/issues/4447, removing code
      that handles async backing not yet being enabled.
      While doing this, I removed the support for collation protocol version 1
      on collators, as it only worked for leaves not supporting async backing
      (which are none).
      I also unhooked the legacy v1 statement-distribution (for the same
      reason as above). That subsystem is basically dead code now, so I had to
      remove some of its tests as they would no longer pass (since the
      subsystem no longer sends messages to the legacy variant). I did not
      remove the entire legacy subsystem yet, as that would pollute this PR
      too much. We can remove the entire v1 and v2 validation protocols in a
      follow up PR.
      
      In another PR: remove test files with names `prospective_parachains`
      (it'd pollute this PR if we do now)
      
      TODO:
      - [x] add deprecation warnings
      - [x] prdoc
      
      ---------
      
      Co-authored-by: default avatarcmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
      4cd07c56
  10. Jan 28, 2025
    • Alin Dima's avatar
      cumulus: bump PARENT_SEARCH_DEPTH and add test for 12-core elastic scaling (#6983) · e6aad5b0
      Alin Dima authored
      On top of https://github.com/paritytech/polkadot-sdk/pull/6757
      
      Fixes https://github.com/paritytech/polkadot-sdk/issues/6858 by bumping
      the `PARENT_SEARCH_DEPTH` constant to a larger value (30) and adds a
      zombienet-sdk test that exercises the 12-core scenario.
      
      This is a node-side limit that restricts the number of allowed pending
      availability candidates when choosing the parent parablock during
      authoring.
      This limit is rather redundant, as the parachain runtime already
      restricts the unincluded segment length to the configured value in the
      [FixedVelocityConsensusHook](https://github.com/paritytech/polkadot-sdk/blob/88d900af
      
      /cumulus/pallets/aura-ext/src/consensus_hook.rs#L35)
      (which ideally should be equal to this `PARENT_SEARCH_DEPTH`).
      
      For 12 cores, a value of 24 should be enough, but I bumped it to 30 to
      have some extra buffer.
      
      There are two other potential ways of fixing this:
      - remove this constant altogether, as the parachain runtime already
      makes those guarantees. Chose not to do this, as it can't hurt to have
      an extra safeguard
      - set this value to be equal to the uninlcuded segment size. This value
      however is not exposed to the node-side and would require a new runtime
      API, which seems overkill for a redundant check.
      
      ---------
      
      Co-authored-by: default avatarJavier Viola <javier@parity.io>
      e6aad5b0
  11. Jan 26, 2025
  12. Jan 23, 2025
    • Andrei Sandu's avatar
      Deprecate ParaBackingState API (#6867) · e9393a9a
      Andrei Sandu authored
      
      Currently the `para_backing_state` API is used only by the prospective
      parachains subsystems and returns 2 things: the constraints for
      parachain blocks and the candidates pending availability.
      
      This PR deprecates `para_backing_state` and introduces a new
      `backing_constraints` API that can be used together with
      `candidates_pending_availability` to get the same information provided
      by `para_backing_state`.
      
      TODO:
      - [x] PRDoc
      
      ---------
      
      Signed-off-by: default avatarAndrei Sandu <andrei-mihail@parity.io>
      Co-authored-by: command-bot <>
      e9393a9a
  13. Jan 22, 2025
  14. Jan 20, 2025
    • Sebastian Kunert's avatar
      Collator: Fix `can_build_upon` by always allowing to build on included block (#7205) · 06f5d486
      Sebastian Kunert authored
      Follow-up to #6825, which introduced this bug.
      
      We use the `can_build_upon` method to ask the runtime if it is fine to
      build another block. The runtime checks this based on the
      [`ConsensusHook`](https://github.com/paritytech/polkadot-sdk/blob/c1b7c302/cumulus/pallets/aura-ext/src/consensus_hook.rs#L110-L110)
      implementation, the most popular one being the `FixedConsensusHook`.
      
      In #6825 I removed a check that would always allow us to build when we
      are building on an included block. Turns out this check is still
      required when:
      1. The [`UnincludedSegment`
      ](https://github.com/paritytech/polkadot-sdk/blob/c1b7c302
      
      /cumulus/pallets/parachain-system/src/lib.rs#L758-L758)
      storage item in pallet-parachain-system is equal or larger than the
      unincluded segment.
      2. We are calling the `can_build_upon` runtime API where the included
      block has progressed offchain to the current parent block (so last entry
      in the `UnincludedSegment` storage item).
      
      In this scenario the last entry in `UnincludedSegment` does not have a
      hash assigned yet (because it was not available in `on_finalize` of the
      previous block). So the unincluded segment will be reported at its
      maximum length which will forbid building another block.
      
      Ideally we would have a more elegant solution than to rely on the
      node-side here. But for now the check is reintroduced and a test is
      added to not break it again by accident.
      
      ---------
      
      Co-authored-by: command-bot <>
      Co-authored-by: default avatarMichal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com>
      06f5d486
  15. Jan 14, 2025
    • Sebastian Kunert's avatar
      Parachains: Use relay chain slot for velocity measurement (#6825) · d5539aa6
      Sebastian Kunert authored
      
      closes #3967 
      
      ## Changes
      We now use relay chain slots to measure velocity on chain. Previously we
      were storing the current parachain slot. Then in `on_state_proof` of the
      `ConsensusHook` we were checking how many blocks were athored in the
      current parachain slot. This works well when the parachain slot time and
      relay chain slot time is the same. With elastic scaling, we can have
      parachain slot times lower than that of the relay chain. In these cases
      we want to measure velocity in relation to the relay chain. This PR
      adjusts that.
      
      
      ##  Migration
      This PR includes a migration. Storage item `SlotInfo` of pallet
      `aura-ext` is renamed to `RelaySlotInfo` to better reflect its new
      content. A migration has been added that just kills the old storage
      item. `RelaySlotInfo` will be `None` initially but its value will be
      adjusted after one new relay chain slot arrives.
      
      ---------
      
      Co-authored-by: command-bot <>
      Co-authored-by: default avatarBastian Köcher <git@kchr.de>
      d5539aa6
  16. Jan 06, 2025
    • Sebastian Kunert's avatar
      Avoid incomplete block import pipeline with full verifying import queue (#7050) · 1dcff3df
      Sebastian Kunert authored
      ## Problem
      In the parachain template we use the [fully verifying import queue
      
      ](https://github.com/paritytech/polkadot-sdk/blob/3d9eddbe/cumulus/client/consensus/aura/src/equivocation_import_queue.rs#L224-L224)
      which does extra equivocation checks.
      
      However, when we import a warp synced block with state, we don't set a
      fork choice, leading to an incomplete block import pipeline and error
      here:
      https://github.com/paritytech/polkadot-sdk/blob/3d9eddbe/substrate/client/service/src/client/client.rs#L488-L488
      
      This renders warp sync useless for chains using this import queue.
      
      ## Fix
      The fix is to always import a block with state as best block, as we
      already do in the normal Aura Verifier.
      In a follow up we should also take another look into unifying the usage
      of the different import queues.
      
      fixes https://github.com/paritytech/project-mythical/issues/256
      
      ---------
      
      Co-authored-by: command-bot <>
      1dcff3df
  17. Dec 20, 2024
    • Xavier Lau's avatar
      Reorder dependencies' keys (#6967) · a843d15e
      Xavier Lau authored
      
      It doesn't make sense to only reorder the features array.
      
      For example:
      
      This makes it hard for me to compare the dependencies and features,
      especially some crates have a really really long dependencies list.
      ```toml​
      [dependencies]
      c = "*"
      a = "*"
      b = "*"
      
      [features]
      std = [
        "a",
        "b",
        "c",
      ]
      ```
      
      This makes my life easier.
      ```toml​
      [dependencies]
      a = "*"
      b = "*"
      c = "*"
      
      [features]
      std = [
        "a",
        "b",
        "c",
      ]
      ```
      
      ---------
      
      Co-authored-by: default avatarBastian Köcher <git@kchr.de>
      Co-authored-by: command-bot <>
      a843d15e
  18. Dec 18, 2024
  19. Dec 16, 2024
  20. Dec 13, 2024
  21. Dec 03, 2024
  22. Nov 24, 2024
  23. Nov 21, 2024
  24. Nov 11, 2024
    • Nazar Mokrynskyi's avatar
      Remove network starter that is no longer needed (#6400) · b601d57a
      Nazar Mokrynskyi authored
      
      # Description
      
      This seems to be an old artifact of the long closed
      https://github.com/paritytech/substrate/issues/6827 that I noticed when
      working on related code earlier.
      
      ## Integration
      
      `NetworkStarter` was removed, simply remove its usage:
      ```diff
      -let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) =
      +let (network, system_rpc_tx, tx_handler_controller, sync_service) =
          build_network(BuildNetworkParams {
      ...
      -start_network.start_network();
      ```
      
      ## Review Notes
      
      Changes are trivial, the only reason for this to not be accepted is if
      it is desired to not start network automatically for whatever reason, in
      which case the description of network starter needs to change.
      
      # Checklist
      
      * [x] My PR includes a detailed description as outlined in the
      "Description" and its two subsections above.
      * [ ] My PR follows the [labeling requirements](
      
      https://github.com/paritytech/polkadot-sdk/blob/master/docs/contributor/CONTRIBUTING.md#Process
      ) of this project (at minimum one label for `T` required)
      * External contributors: ask maintainers to put the right label on your
      PR.
      
      ---------
      
      Co-authored-by: default avatarGitHub Action <action@github.com>
      Co-authored-by: default avatarBastian Köcher <git@kchr.de>
      b601d57a
  25. Nov 07, 2024
    • Nazar Mokrynskyi's avatar
      Syncing strategy refactoring (part 3) (#5737) · 12d90524
      Nazar Mokrynskyi authored
      # Description
      
      This is a continuation of
      https://github.com/paritytech/polkadot-sdk/pull/5666 that finally fixes
      https://github.com/paritytech/polkadot-sdk/issues/5333.
      
      This should allow developers to create custom syncing strategies or even
      the whole syncing engine if they so desire. It also moved syncing engine
      creation and addition of corresponding protocol outside
      `build_network_advanced` method, which is something Bastian expressed as
      desired in
      https://github.com/paritytech/polkadot-sdk/issues/5#issuecomment-1700816458
      
      Here I replaced strategy-specific types and methods in `SyncingStrategy`
      trait with generic ones. Specifically `SyncingAction` is now used by all
      strategies instead of strategy-specific types with conversions.
      `StrategyKey` was an enum with a fixed set of options and now replaced
      with an opaque type that strategies create privately and send to upper
      layers as an opaque type. Requests and responses are now handled in a
      generic way regardl...
      12d90524
  26. Nov 05, 2024
    • Nazar Mokrynskyi's avatar
      Remove `sp_runtime::RuntimeString` and replace with `Cow<'static, str>` or... · c5444f38
      Nazar Mokrynskyi authored
      Remove `sp_runtime::RuntimeString` and replace with `Cow<'static, str>` or `String` depending on use case (#5693)
      
      # Description
      
      As described in https://github.com/paritytech/polkadot-sdk/issues/4001
      `RuntimeVersion` was not encoded consistently using serde. Turned out it
      was a remnant of old times and no longer actually needed. As such I
      removed it completely in this PR and replaced with `Cow<'static, str>`
      for spec/impl names and `String` for error cases.
      
      Fixes https://github.com/paritytech/polkadot-sdk/issues/4001.
      
      ## Integration
      
      For downstream projects the upgrade will primarily consist of following
      two changes:
      ```diff
      #[sp_version::runtime_version]
      pub const VERSION: RuntimeVersion = RuntimeVersion {
      -	spec_name: create_runtime_str!("statemine"),
      -	impl_name: create_runtime_str!("statemine"),
      +	spec_name: alloc::borrow::Cow::Borrowed("statemine"),
      +	impl_name: alloc::borrow::Cow::Borrowed("statemine"),
      ```
      ```diff
      		fn dispatch_benchmark(
      			config: frame_benchmarking::BenchmarkConfig
      -		) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
      +		) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, alloc::string::String> {
      ```
      
      SCALE encoding/decoding remains the same as before, but serde encoding
      in runtime has changed from bytes to string (it was like this in `std`
      environment already), which most projects shouldn't have issues with. I
      consider the impact of serde encoding here low due to the type only
      being used in runtime version struct and mostly limited to runtime
      internals, where serde encoding/decoding of this data structure is quite
      unlikely (though we did hit exactly this edge-case ourselves
      :sweat_smile:
      
      ).
      
      ## Review Notes
      
      Most of the changes are trivial and mechanical, the only non-trivial
      change is in
      `substrate/primitives/version/proc-macro/src/decl_runtime_version.rs`
      where macro call expectation in `sp_version::runtime_version`
      implementation was replaced with function call expectation.
      
      # Checklist
      
      * [x] My PR includes a detailed description as outlined in the
      "Description" and its two subsections above.
      * [ ] My PR follows the [labeling requirements](
      
      https://github.com/paritytech/polkadot-sdk/blob/master/docs/contributor/CONTRIBUTING.md#Process
      ) of this project (at minimum one label for `T` required)
      * External contributors: ask maintainers to put the right label on your
      PR.
      * [ ] I have made corresponding changes to the documentation (if
      applicable)
      
      ---------
      
      Co-authored-by: default avatarGitHub Action <action@github.com>
      Co-authored-by: default avatarGuillaume Thiolliere <guillaume.thiolliere@parity.io>
      Co-authored-by: default avatarBastian Köcher <info@kchr.de>
      c5444f38
    • Alin Dima's avatar
      refactor and harden check_core_index (#6217) · 74ec1ee2
      Alin Dima authored
      Resolves https://github.com/paritytech/polkadot-sdk/issues/6179
      74ec1ee2
  27. Oct 30, 2024
    • Sebastian Kunert's avatar
      Add overhead benchmark to frame-omni-bencher (#5891) · 40547f9f
      Sebastian Kunert authored
      
      # Benchmark Overhead Command for Parachains
      
      This implements the `benchmark overhead` command for parachains. Full
      context is available at:
      https://github.com/paritytech/polkadot-sdk/issues/5303. Previous attempt
      was this https://github.com/paritytech/polkadot-sdk/pull/5283, but here
      we have integration into frame-omni-bencher and improved tooling.
      
      ## Changes Overview
      
      Users are now able to use `frame-omni-bencher` to generate
      `extrinsic_weight.rs` and `block_weight.rs` files for their runtime. The
      core logic for generating these remains untouched; this PR provides
      mostly machinery to make it work for parachains at all.
      
      Similar to the pallet benchmarks, we gain the option to benchmark based
      on just a runtime:
      
      ```
      frame-omni-bencher v1 benchmark overhead --runtime {{runtime}}
      ```
      
      or with a spec:
      
      ```
      frame-omni-bencher v1 benchmark overhead --chain {{spec}} --genesis-builder spec
      ```
      
      In this case, the genesis state is generated from the runtime presets.
      However, it is also possible to use `--chain` and genesis builder `spec`
      to generate the genesis state from the chain spec.
      
      Additionally, we use metadata to perform some checks based on the
      pallets the runtime exposes:
      
      - If we see the `ParaInherent` pallet, we assume that we are dealing
      with a relay chain. This means that we don't need proof recording during
      import (since there is no storage weight).
      - If we detect the `ParachainSystem` pallet, we assume that we are
      dealing with a parachain and take corresponding actions like patching a
      para id into the genesis state.
      
      On the inherent side, I am currently supplying the standard inherents
      every parachain needs.
      
      In the current state, `frame-omni-bencher` supports all system chains.
      In follow-up PRs, we could add additional inherents to increase
      compatibility.
      
      Since we are building a block during the benchmark, we also need to
      build an extrinsic. By default, I am leveraging subxt to build the xt
      dynamically. If a chain is not compatible with the `SubstrateConfig`
      that comes with `subxt`, it can provide a custom extrinsic builder to
      benchmarking-cli. This requires either a custom bencher implementation
      or an integration into the parachains node.
      
      Also cumulus-test-runtime has been migrated to provide genesis configs.
      
      ## Chain Compatibility
      The current version here is compatible with the system chains and common
      substrate chains. The way to go for others would be to customize the
      frame-omni-bencher by providing a custom extrinsicbuilder. I did an
      example implementation that works for mythical:
      https://github.com/skunert/mythical-bencher
      
      ## Follow-Ups
      - After #6040 is finished, we should integrate this here to make the
      tooling truly useful. In the current form, the state is fairly small and
      not representative.
      
      ## How to Review
      I recommend starting from
      [here](https://github.com/paritytech/polkadot-sdk/pull/5891/files#diff-50830ff756b3ac3403b7739d66c9e3a5185dbea550669ca71b28d19c7a2a54ecR264),
      this method is the main entry point for omni-bencher and `polkadot`
      binary.
      
      TBD:
      - [x] PRDoc
      
      ---------
      
      Co-authored-by: default avatarMichal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com>
      40547f9f
  28. Oct 25, 2024
  29. Oct 15, 2024
    • Michal Kucharczyk's avatar
      fork-aware transaction pool added (#4639) · 26c11fc5
      Michal Kucharczyk authored
      ### Fork-Aware Transaction Pool Implementation
      
      This PR introduces a fork-aware transaction pool (fatxpool) enhancing
      transaction management by maintaining the valid state of txpool for
      different forks.
      
      ### High-level overview
      The high level overview was added to
      [`sc_transaction_pool::fork_aware_txpool`](https://github.com/paritytech/polkadot-sdk/blob/3ad0a1b7/substrate/client/transaction-pool/src/fork_aware_txpool/mod.rs#L21)
      module. Use:
      ```
      cargo  doc --document-private-items -p sc-transaction-pool --open
      ```
      to build the doc. It should give a good overview and nice entry point
      into the new pool's mechanics.
      
      <details>
        <summary>Quick overview (documentation excerpt)</summary>
      
      #### View
      For every fork, a view is created. The view is a persisted state of the
      transaction pool computed and updated at the tip of the fork. The view
      is built around the existing `ValidatedPool` structure.
      
      A view is created on every new best block notification. To create a
      view, one of the existing views is chosen and cloned.
      
      When the chain progresses, the view is kept in the cache
      (`retracted_views`) to allow building blocks upon intermediary blocks in
      the fork.
      
      The views are deleted on finalization: views lower than the finalized
      block are removed.
      
      The views are updated with the transactions from the mempool—all
      transactions are sent to the newly created views.
      A maintain process is also executed for the newly created
      views—basically resubmitting and pruning transactions from the
      appropriate tree route.
      
      ##### View store
      View store is the helper structure that acts as a container for all the
      views. It provides some convenient methods.
      
      ##### Submitting transactions
      Every transaction is submitted to every view at the tips of the forks.
      Retracted views are not updated.
      Every transaction also goes into the mempool.
      
      ##### Internal mempool
      Shortly, the main purpose of an internal mempool is to prevent a
      transaction from being lost. That could happen when a transaction is
      invalid on one fork and could be valid on another. It also allows the
      txpool to accept transactions when no blocks have been reported yet.
      
      The mempool removes its transactions when they get finalized.
      Transactions are also periodically verified on every finalized event and
      removed from the mempool if no longer valid.
      
      #### Events
      Transaction events from multiple views are merged and filtered to avoid
      duplicated events.
      `Ready` / `Future` / `Inblock` events are originated in the Views and
      are de-duplicated and forwarded to external listeners.
      `Finalized` events are originated in fork-aware-txpool logic.
      `Invalid` events requires special care and can be originated in both
      view and fork-aware-txpool logic.
      
      #### Light maintain
      Sometime transaction pool does not have enough time to prepare fully
      maintained view with all retracted transactions being revalidated. To
      avoid providing empty ready transaction set to block builder (what would
      result in empty block) the light maintain was implemented. It simply
      removes the imported transactions from ready iterator.
      
      #### Revalidation
      Revalidation is performed for every view. The revalidation process is
      started after a trigger is executed. The revalidation work is terminated
      just after a new best block / finalized event is notified to the
      transaction pool.
      The revalidation result is applied to the newly created view which is
      built upon the revalidated view.
      
      Additionally, parts of the mempool are also revalidated to make sure
      that no transactions are stuck in the mempool.
      
      
      #### Logs
      The most important log allowing to understand the state of the txpool
      is:
      ```
                    maintain: txs:(0, 92) views:[2;[(327, 76, 0), (326, 68, 0)]] event:Finalized { hash: 0x8...f, tree_route: [] }  took:3.463522ms
                                   ^   ^         ^     ^   ^  ^      ^   ^  ^        ^                                                   ^
      unwatched txs in mempool ────┘   │         │     │   │  │      │   │  │        │                                                   │
         watched txs in mempool ───────┘         │     │   │  │      │   │  │        │                                                   │
                           views  ───────────────┘     │   │  │      │   │  │        │                                                   │
                            1st view block # ──────────┘   │  │      │   │  │        │                                                   │
                                 number of ready tx ───────┘  │      │   │  │        │                                                   │
                                      numer of future tx ─────┘      │   │  │        │                                                   │
                                              2nd view block # ──────┘   │  │        │                                                   │
                                            number of ready tx ──────────┘  │        │                                                   │
                                                 number of future tx ───────┘        │                                                   │
                                                                       event ────────┘                                                   │
                                                                             duration  ──────────────────────────────────────────────────┘
      ```
      It is logged after the maintenance is done.
      
      The `debug` level enables per-transaction logging, allowing to keep
      track of all transaction-related actions that happened in txpool.
      </details>
      
      
      ### Integration notes
      
      For teams having a custom node, the new txpool needs to be instantiated,
      typically in `service.rs` file, here is an example:
      
      https://github.com/paritytech/polkadot-sdk/blob/9c547ff3
      
      /cumulus/polkadot-omni-node/lib/src/common/spec.rs#L152-L161
      
      To enable new transaction pool the following cli arg shall be specified:
      `--pool-type=fork-aware`. If it works, there shall be information
      printed in the log:
      ```
      2024-09-20 21:28:17.528  INFO main txpool: [Parachain]  creating ForkAware txpool.
      ````
      
      For debugging the following debugs shall be enabled:
      ```
            "-lbasic-authorship=debug",
            "-ltxpool=debug",
      ```
      *note:* trace for txpool enables per-transaction logging.
      
      ### Future work
      The current implementation seems to be stable, however further
      improvements are required.
      Here is the umbrella issue for future work:
      - https://github.com/paritytech/polkadot-sdk/issues/5472
      
      
      Partially fixes: #1202
      
      ---------
      
      Co-authored-by: default avatarBastian Köcher <git@kchr.de>
      Co-authored-by: default avatarSebastian Kunert <skunert49@gmail.com>
      Co-authored-by: default avatarIulian Barbu <14218860+iulianbarbu@users.noreply.github.com>
      26c11fc5
  30. Oct 07, 2024
  31. Oct 04, 2024
  32. Sep 26, 2024
    • Alexandru Gheorghe's avatar
      [5 / 5] Introduce approval-voting-parallel (#4849) · b16237ad
      Alexandru Gheorghe authored
      This is the implementation of the approach described here:
      https://github.com/paritytech/polkadot-sdk/issues/1617#issuecomment-2150321612
      &
      https://github.com/paritytech/polkadot-sdk/issues/1617#issuecomment-2154357547
      &
      https://github.com/paritytech/polkadot-sdk/issues/1617#issuecomment-2154721395.
      
      ## Description of changes
      
      The end goal is to have an architecture where we have single
      subsystem(`approval-voting-parallel`) and multiple worker types that
      would full-fill the work that currently is fulfilled by the
      `approval-distribution` and `approval-voting` subsystems. The main loop
      of the new subsystem would do just the distribution of work to the
      workers.
      
      The new subsystem will have:
      - N approval-distribution workers: This would do the work that is
      currently being done by the approval-distribution subsystem and in
      addition to that will also perform the crypto-checks that an assignment
      is valid and that a vote is correctly signed. Work is assigned via the
      following formula: `worker_index = msg.validator % WORKER_COUNT`, this
      guarantees that all assignments and approvals from the same validator
      reach the same worker.
      - 1 approval-voting worker: This would receive an already valid message
      and do everything the approval-voting currently does, except the
      crypto-checking that has been moved already to the approval-distribution
      worker.
      
      On the hot path of processing messages **no** synchronisation and
      waiting is needed between approval-distribution and approval-voting
      workers.
      
      <img width="1431" alt="Screenshot 2024-06-07 at 11 28 08"
      src="https://github.com/paritytech/polkadot-sdk/assets/49718502/a196199b-b705-4140-87d4-c6900ba8595e">
      
      
      
      ## Guidelines for reading
      
      The full implementation is broken in 5 PRs and all of them are
      self-contained and improve things incrementally even without the
      parallelisation being implemented/enabled, the reason this approach was
      taken instead of a big-bang PR, is to make things easier to review and
      reduced the risk of breaking this critical subsystems.
      
      After reading the full description of this PR, the changes should be
      read in the following order:
      1. https://github.com/paritytech/polkadot-sdk/pull/4848, some other
      micro-optimizations for networks with a high number of validators. This
      change gives us a speed up by itself without any other changes.
      2. https://github.com/paritytech/polkadot-sdk/pull/4845 , this contains
      only interface changes to decouple the subsystem from the `Context` and
      be able to run multiple instances of the subsystem on different threads.
      **No functional changes**
      3. https://github.com/paritytech/polkadot-sdk/pull/4928, moving of the
      crypto checks from approval-voting in approval-distribution, so that the
      approval-distribution has no reason to wait after approval-voting
      anymore. This change gives us a speed up by itself without any other
      changes.
      4. https://github.com/paritytech/polkadot-sdk/pull/4846, interface
      changes to make approval-voting runnable on a separate thread. **No
      functional changes**
      5. This PR, where we instantiate an `approval-voting-parallel` subsystem
      that runs on different workers the logic currently in
      `approval-distribution` and `approval-voting`.
      6. The next step after this changes get merged and deploy would be to
      bring all the files from approval-distribution, approval-voting,
      approval-voting-parallel into a single rust crate, to make it easier to
      maintain and understand the structure.
      
      ## Results
      Running subsystem-benchmarks with 1000 validators 100 fully ocuppied
      cores and triggering all assignments and approvals for all tranches
      
      #### Approval does not lags behind. 
       Master
      ```
      Chain selection approved  after 72500 ms hash=0x0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a
      ```
      With this PoC
      ```
      Chain selection approved  after 3500 ms hash=0x0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a
      ```
      
      #### Gathering enough assignments
       
      Enough assignments are gathered in less than 500ms, so that gives un a
      guarantee that un-necessary work does not get triggered, on master on
      the same benchmark because the subsystems fall behind on work, that
      number goes above 32 seconds on master.
       
      <img width="2240" alt="Screenshot 2024-06-20 at 15 48 22"
      src="https://github.com/paritytech/polkadot-sdk/assets/49718502/d2f2b29c-5ff6-44b4-a245-5b37ab8e58bc">
      
      
      #### Cpu usage:
      Master
      ```
      CPU usage, seconds                     total   per block
      approval-distribution                96.9436      9.6944
      approval-voting                     117.4676     11.7468
      test-environment                     44.0092      4.4009
      ```
      With this PoC
      ```
      CPU usage, seconds                     total   per block
      approval-distribution                 0.0014      0.0001 --- unused
      approval-voting                       0.0437      0.0044.  --- unused
      approval-voting-parallel              5.9560      0.5956
      approval-voting-parallel-0           22.9073      2.2907
      approval-voting-parallel-1           23.0417      2.3042
      approval-voting-parallel-2           22.0445      2.2045
      approval-voting-parallel-3           22.7234      2.2723
      approval-voting-parallel-4           21.9788      2.1979
      approval-voting-parallel-5           23.0601      2.3060
      approval-voting-parallel-6           22.4805      2.2481
      approval-voting-parallel-7           21.8330      2.1833
      approval-voting-parallel-db          37.1954      3.7195.  --- the approval-voting thread.
      ```
      
      # Enablement strategy
      
      Because just some trivial plumbing is needed in approval-distribution
      and approval-voting to be able to run things in parallel and because
      this subsystems plays a critical part in the system this PR proposes
      that we keep both ways of running the approval work, as separated
      subsystems and just a single subsystem(`approval-voting-parallel`) which
      has multiple workers for the distribution work and one worker for the
      approval-voting work and switch between them with a comandline flag.
      
      The benefits for this is twofold.
      1. With the same polkadot binary we can easily switch just a few
      validators to use the parallel approach and gradually make this the
      default way of running, if now issues arise.
      2. In the worst case scenario were it becomes the default way of running
      things, but we discover there are critical issues with it we have the
      path to quickly disable it by asking validators to adjust their command
      line flags.
      
      
      # Next steps
      - [x] Make sure through various testing we are not missing anything 
      - [x] Polish the implementations to make them production ready
      - [x] Add Unittest Tests for approval-voting-parallel.
      - [x] Define and implement the strategy for rolling this change, so that
      the blast radius is minimal(single validator) in case there are problems
      with the implementation.
      - [x]  Versi long running tests.
      - [x] Add relevant metrics.
      
      @ordian @eskimor @sandreim @AndreiEres
      
      , let me know what you think.
      
      ---------
      
      Signed-off-by: default avatarAlexandru Gheorghe <alexandru.gheorghe@parity.io>
      b16237ad
  33. Sep 23, 2024
    • Alin Dima's avatar
      elastic scaling: add core selector to cumulus (#5372) · b9eb68bc
      Alin Dima authored
      Partially implements
      https://github.com/paritytech/polkadot-sdk/issues/5048
      
      - adds a core selection runtime API to cumulus and a generic way of
      configuring it for a parachain
      - modifies the slot based collator to utilise the claim queue and the
      generic core selection
      
      What's left to be implemented (in a follow-up PR):
      - add the UMP signal for core selection into the parachain-system pallet
      
      View the RFC for more context:
      https://github.com/polkadot-fellows/RFCs/pull/103
      
      ---------
      
      Co-authored-by: command-bot <>
      b9eb68bc
  34. Sep 22, 2024
  35. Sep 20, 2024
    • tmpolaczyk's avatar
      Allow to call arbitrary runtime apis using RelayChainInterface (#5521) · 5a431470
      tmpolaczyk authored
      
      When using the relay chain though a `Arc<dyn RelayChainInterface>` there
      is no way to call arbitrary runtime apis. Both implementations of that
      trait allow this, so it feels natural to expose this functionality in
      the trait.
      
      This PR adds a `call_runtime_api` method to RelayChainInterface trait,
      and a separate function also named `call_runtime_api` which allows the
      caller to specify the input and output types, as opposed to having to
      encode them. This generic function cannot be part of the trait because a
      `dyn Trait` object cannot have generic methods.
      
      ---------
      
      Co-authored-by: default avatarBastian Köcher <git@kchr.de>
      5a431470
  36. Sep 19, 2024
    • Iulian Barbu's avatar
      cumulus/minimal-node: added prometheus metrics for the RPC client (#5572) · c8d5e5a3
      Iulian Barbu authored
      
      # Description
      
      When we start a node with connections to external RPC servers (as a
      minimal node), we lack metrics around how many individual calls we're
      doing to the remote RPC servers and their duration. This PR adds metrics
      that measure durations of each RPC call made by the minimal nodes, and
      implicitly how many calls there are.
      
      Closes #5409 
      Closes #5689
      
      ## Integration
      
      Node operators should be able to track minimal node metrics and decide
      appropriate actions according to how the metrics are interpreted/felt.
      The added metrics can be observed by curl'ing the prometheus metrics
      endpoint for the ~relaychain~ parachain (it was changed based on the
      review). The metrics are represented by
      ~`polkadot_parachain_relay_chain_rpc_interface`~
      `relay_chain_rpc_interface` namespace (I realized lining up
      `parachain_relay_chain` in the same metric might be confusing :).
      Excerpt from the curl:
      
      ```
      relay_chain_rpc_interface_bucket{method="chain_getBlockHash",chain="rococo_local_testnet",le="0.001"} 15
      relay_chain_rpc_interface_bucket{method="chain_getBlockHash",chain="rococo_local_testnet",le="0.004"} 23
      relay_chain_rpc_interface_bucket{method="chain_getBlockHash",chain="rococo_local_testnet",le="0.016"} 23
      relay_chain_rpc_interface_bucket{method="chain_getBlockHash",chain="rococo_local_testnet",le="0.064"} 23
      relay_chain_rpc_interface_bucket{method="chain_getBlockHash",chain="rococo_local_testnet",le="0.256"} 24
      relay_chain_rpc_interface_bucket{method="chain_getBlockHash",chain="rococo_local_testnet",le="1.024"} 24
      relay_chain_rpc_interface_bucket{method="chain_getBlockHash",chain="rococo_local_testnet",le="4.096"} 24
      relay_chain_rpc_interface_bucket{method="chain_getBlockHash",chain="rococo_local_testnet",le="16.384"} 24
      relay_chain_rpc_interface_bucket{method="chain_getBlockHash",chain="rococo_local_testnet",le="65.536"} 24
      relay_chain_rpc_interface_bucket{method="chain_getBlockHash",chain="rococo_local_testnet",le="+Inf"} 24
      relay_chain_rpc_interface_sum{method="chain_getBlockHash",chain="rococo_local_testnet"} 0.11719075
      relay_chain_rpc_interface_count{method="chain_getBlockHash",chain="rococo_local_testnet"} 24
      ```
      
      ## Review Notes
      
      The way we measure durations/hits is based on `HistogramVec` struct
      which allows us to collect timings for each RPC client method called
      from the minimal node., It can be extended to measure the RPCs against
      other dimensions too (status codes, response sizes, etc). The timing
      measuring is done at the level of the `relay-chain-rpc-interface`, in
      the `RelayChainRpcClient` struct's method 'request_tracing'. A single
      entry point for all RPC requests done through the
      relay-chain-rpc-interface. The requests durations will fall under
      exponential buckets described by start `0.001`, factor `4` and count
      `9`.
      
      ---------
      
      Signed-off-by: default avatarIulian Barbu <iulian.barbu@parity.io>
      c8d5e5a3
  37. Sep 17, 2024
    • Nazar Mokrynskyi's avatar
      Syncing strategy refactoring (part 2) (#5666) · 43cd6fd4
      Nazar Mokrynskyi authored
      # Description
      
      Follow-up to https://github.com/paritytech/polkadot-sdk/pull/5469 and
      mostly covering https://github.com/paritytech/polkadot-sdk/issues/5333.
      
      The primary change here is that syncing strategy is no longer created
      inside of syncing engine, instead syncing strategy is an argument of
      syncing engine, more specifically it is an argument to `build_network`
      that most downstream users will use. This also extracts addition of
      request-response protocols outside of network construction, making sure
      they are physically not present when they don't need to be (imagine
      syncing strategy that uses none of Substrate's protocols in its
      implementation for example).
      
      This technically allows to completely replace syncing strategy with
      whatever strategy chain might need.
      
      There will be at least one follow-up PR that will simplify
      `SyncingStrategy` trait and other public interfaces to remove mentions
      of block/state/warp sync requests, replacing them with generic APIs,
      such that strategies where warp sync is not applicable don't have to
      provide dummy method implementations, etc.
      
      ## Integration
      
      Downstream projects will have to write a bit of boilerplate calling
      `build_polkadot_syncing_strategy` function to create previously default
      syncing strategy.
      
      ## Review Notes
      
      Please review PR through individual commits rather than the final diff,
      it will be easier that way. The changes are mostly just moving code
      around one step at a time.
      
      # Checklist
      
      * [x] My PR includes a detailed description as outlined in the
      "Description" and its two subsections above.
      * [x] My PR follows the [labeling requirements](
      
      https://github.com/paritytech/polkadot-sdk/blob/master/docs/contributor/CONTRIBUTING.md#Process
      ) of this project (at minimum one label for `T` required)
      * External contributors: ask maintainers to put the right label on your
      PR.
      * [x] I have made corresponding changes to the documentation (if
      applicable)
      43cd6fd4
  38. Sep 16, 2024