Skip to content
Snippets Groups Projects
  1. Jan 27, 2025
  2. Jan 25, 2025
  3. Jan 04, 2025
  4. Dec 10, 2024
  5. Nov 29, 2024
    • Rodrigo Quelhas's avatar
      Expose types from `sc-service` (#5855) · 72fb8bd3
      Rodrigo Quelhas authored
      # Description
      
      At moonbeam we have worked on a `lazy-loading` feature which is a client
      mode that forks a live parachain and fetches its state on-demand, we
      have been able to do this by duplicating some code from
      `sc_service::client`. The objective of this PR is to simplify the
      implementation by making public some types in polkadot-sdk.
      
      - Modules:
      - `sc_service::client` **I do not see a point to only expose this type
      when `test-helpers` feature is enabled**
      
      ## Integration
      
      Not applicable, the PR just makes some types public.
      
      ## Review Notes
      
      The changes included in this PR give more flexibility for client
      developers by exposing important types.
      72fb8bd3
  6. Nov 19, 2024
  7. 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
  8. 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 regardless of the strategy, which reduced and simplified
      strategy API.
      
      `PolkadotSyncingStrategy` now lives in its dedicated module (had to edit
      .gitignore for this) like other strategies.
      
      `build_network_advanced` takes generic `SyncingService` as an argument
      alongside with a few other low-level types (that can probably be
      extracted in the future as well) without any notion of specifics of the
      way syncing is actually done. All the protocol and tasks are created
      outside and not a part of the network anymore. It still adds a bunch of
      protocols like for light client and some others that should eventually
      be restructured making `build_network_advanced` just building generic
      network and not application-specific protocols handling.
      
      ## Integration
      
      Just like https://github.com/paritytech/polkadot-sdk/pull/5666
      introduced `build_polkadot_syncing_strategy`, this PR introduces
      `build_default_block_downloader`, but for convenience and to avoid
      typical boilerplate a simpler high-level function
      `build_default_syncing_engine` is added that will take care of creating
      typical block downloader, syncing strategy and syncing engine, which is
      what most users will be using going forward. `build_network` towards the
      end of the PR was renamed to `build_network_advanced` and
      `build_network`'s API was reverted to
      pre-https://github.com/paritytech/polkadot-sdk/pull/5666, so most users
      will not see much of a difference during upgrade unless they opt-in to
      use new API.
      
      ## Review Notes
      
      For `StrategyKey` I was thinking about using something like private type
      and then storing `TypeId` inside instead of a static string in it, let
      me know if that would preferred.
      
      The biggest change happened to requests that different strategies make
      and how their responses are handled. The most annoying thing here is
      that block response decoding, in contrast to all other responses, is
      dependent on request. This meant request had to be sent throughout the
      system. While originally `Response` was `Vec<u8>`, I didn't want to
      re-encode/decode request and response just to fit into that API, so I
      ended up with `Box<dyn Any + Send>`. This allows responses to be truly
      generic and each strategy will know how to downcast it back to the
      concrete type when handling the response.
      
      Import queue refactoring was needed to move `SyncingEngine` construction
      out of `build_network` that awkwardly implemented for `SyncingService`,
      but due to `&mut self` wasn't usable on `Arc<SyncingService>` for no
      good reason. `Arc<SyncingService>` itself is of course useless, but
      refactoring to replace it with just `SyncingService` was unfortunately
      rejected in https://github.com/paritytech/polkadot-sdk/pull/5454
      
      As usual I recommend to review this PR as a series of commits instead of
      as the final diff, it'll make more sense that way.
      
      # 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)
      12d90524
  9. Nov 04, 2024
    • PG Herveou's avatar
      [eth-rpc] Fixes (#6317) · 7f80f452
      PG Herveou authored
      
      Various fixes for the release of eth-rpc & ah-westend-runtime
      
      - Bump asset-hub westend spec version
      - Fix the status of the Receipt to properly report failed transactions
      - Fix value conversion between native and eth decimal representation
      
      ---------
      
      Co-authored-by: default avatarGitHub Action <action@github.com>
      7f80f452
  10. 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
  11. 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
  12. Sep 09, 2024
    • Nick Vikeras's avatar
      Plumb RPC listener up to caller (#5038) · c72f9ab5
      Nick Vikeras authored
      
      # Description
      
      This PR allows the RPC server's socket address to be returned when
      initializing the server. This allows the library consumer to easily
      programmatically determine which port the RPC server is listening on. My
      use case for this is automated testing. I'd like to be able to simply
      specify that the server bind to port '0' and then test against whatever
      port the OS assigns dynamically. I will have many RPC servers running in
      parallel across many tests within a single process, and I don't want to
      have to deal with port conflicts.
      
      ## Integration
      
      Integration is straightforward. My main concern is that I am making
      non-backwards-compatible changes to public library functions. Let me
      know if I should leave backwards-compatible wrappers in place for
      any/all of the public functions that were modified.
      
      ## Review Notes
      The rationale for making the new listen_addresses field on the
      RpcHandlers struct a ```[MultiAddr]``` rather than ```SocketAddr``` is
      because I wanted it to be transport-agnostic as well as capable of
      supporting multiple listening addresses in case that is ever required by
      the RPC server in the future.
      
      # Checklist
      
      * [x] My PR includes a detailed description as outlined in the
      "Description" and its two subsections above.
      * [ ] My PR follows the [labeling requirements](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)
      * [ ] I have added tests that prove my fix is effective or that my
      feature works (if applicable)
      
      1. I didn't understand what the 'T' label meant. Am I supposed to open a
      github Issue for my PR?
      2. I didn't see an easy way to add tests since the functions I am
      modifying are not directly called by any tests.
      
      ---------
      
      Co-authored-by: default avatarNiklas Adolfsson <niklasadolfsson1@gmail.com>
      c72f9ab5
  13. Sep 02, 2024
    • Nazar Mokrynskyi's avatar
      Improve `sc-service` API (#5364) · da654103
      Nazar Mokrynskyi authored
      
      This improves `sc-service` API by not requiring the whole
      `&Configuration`, using specific configuration options instead.
      `RpcConfiguration` was also extracted from `Configuration` to group all
      RPC options together.
      
      We don't use Substrate's CLI and would rather not use `Configuration`
      either, but some key public functions require it even though they
      ignored most of the fields anyway.
      
      `RpcConfiguration` is very helpful not just for consolidation of the
      fields, but also to finally make RPC optional for our use case, while
      Substrate still runs RPC server on localhost even if listening address
      is explicitly set to `None`, which is annoying (and I suspect there is a
      reason for it, so didn't want to change the default just yet).
      
      While this is a breaking change, most developers will not notice it if
      they use higher-level APIs.
      
      Fixes https://github.com/paritytech/polkadot-sdk/issues/2897
      
      ---------
      
      Co-authored-by: default avatarNiklas Adolfsson <niklasadolfsson1@gmail.com>
      da654103
  14. Aug 28, 2024
    • Niklas Adolfsson's avatar
      rpc server: listen to `ipv6 socket` if available and... · 09254eb9
      Niklas Adolfsson authored
      rpc server: listen to `ipv6 socket` if available and `--experimental-rpc-endpoint` CLI option (#4792)
      
      Close https://github.com/paritytech/polkadot-sdk/issues/3488,
      https://github.com/paritytech/polkadot-sdk/issues/4331
      
      This changes/adds the following:
      
      1. The default setting is that substrate starts a rpc server that
      listens to localhost both Ipv4 and Ipv6 on the same port. Ipv6 is
      allowed to fail because some platforms may not support it
      2. A new RPC CLI option `--experimental-rpc-endpoint` which allow to
      configure arbitrary listen addresses including the port, if this is
      enabled no other interfaces are enabled.
      3. If the local addr is not found for any of the sockets the server is
      not started throws an error.
      4. Remove the deny_unsafe from the RPC implementations instead this is
      an extension to allow different polices for different interfaces/sockets
      such one may enable unsafe on local interface and safe on only the
      external interface.
      
      So for instance in this PR it's now possible to start up three RPC...
      09254eb9
  15. Aug 26, 2024
    • Nazar Mokrynskyi's avatar
      Sync status refactoring (#5450) · dd1aaa47
      Nazar Mokrynskyi authored
      As I was looking at the coupling between `SyncingEngine`,
      `SyncingStrategy` and individual strategies I noticed a few things that
      were unused, redundant or awkward.
      
      The awkward change comes from
      https://github.com/paritytech/substrate/pull/13700 where
      `num_connected_peers` property was added to `SyncStatus` struct just so
      it can be rendered in the informer. While convenient, the property
      didn't really belong there and was annoyingly set to `0` in some
      strategies and to `num_peers` in others. I have replaced that with a
      property on `SyncingService` that already stored necessary information
      internally.
      
      Also `ExtendedPeerInfo` didn't have a working `Clone` implementation due
      to lack of perfect derive in Rust and while I ended up not using it in
      the refactoring, I included fixed implementation for it in this PR
      anyway.
      
      While these changes are not strictly necessary for
      https://github.com/paritytech/polkadot-sdk/issues/5333, they do reduce
      coupling of syncing engine with sync...
      dd1aaa47
  16. Aug 23, 2024
    • Nazar Mokrynskyi's avatar
      Remove the need to wait for target block header in warp sync implementation (#5431) · 6d819a61
      Nazar Mokrynskyi authored
      I'm not sure if this is exactly what
      https://github.com/paritytech/polkadot-sdk/issues/3537 meant, but I
      think it should be fine to wait for relay chain before initializing
      parachain node fully, which removed the need for background task and
      extra hacks throughout the stack just to know where warp sync should
      start.
      
      Previously there were both `WarpSyncParams` and `WarpSyncConfig`, but
      there was no longer any point in having two data structures, so I
      simplified it to just `WarpSyncConfig`.
      
      Fixes https://github.com/paritytech/polkadot-sdk/issues/3537
      6d819a61
  17. Aug 07, 2024
  18. Jul 09, 2024
    • Serban Iorga's avatar
      `polkadot-parachain` simplifications and deduplications (#4916) · 01e0fc23
      Serban Iorga authored
      `polkadot-parachain` simplifications and deduplications
      
      Details in the commit messages. Just copy-pasting the last commit
      description since it introduces the biggest changes:
      
      ```
          Implement a more structured way to define a node spec
          
          - use traits instead of bounds for `rpc_ext_builder()`,
            `build_import_queue()`, `start_consensus()`
          - add a `NodeSpec` trait for defining the specifications of a node
          - deduplicate the code related to building a node's components /
            starting a node
      ```
      
      The other changes are much smaller, most of them trivial and are
      isolated in separate commits.
      01e0fc23
  19. May 27, 2024
    • Michal Kucharczyk's avatar
      `sc-chain-spec`: deprecated code removed (#4410) · 2d3a6932
      Michal Kucharczyk authored
      This PR removes deprecated code:
      - The `RuntimeGenesisConfig` generic type parameter in
      `GenericChainSpec` struct.
      - `ChainSpec::from_genesis` method allowing to create chain-spec using
      closure providing runtime genesis struct
      - `GenesisSource::Factory` variant together with no longer needed
      `GenesisSource`'s generic parameter `G` (which was intended to be a
      runtime genesis struct).
      
      
      https://github.com/paritytech/polkadot-sdk/blob/17b56fae/substrate/client/chain-spec/src/chain_spec.rs#L559-L563
      2d3a6932
  20. May 15, 2024
  21. May 09, 2024
    • Niklas Adolfsson's avatar
      rpc: add option to `whitelist ips` in rate limiting (#3701) · d37719da
      Niklas Adolfsson authored
      This PR adds two new CLI options to disable rate limiting for certain ip
      addresses and whether to trust "proxy header".
      After going back in forth I decided to use ip addr instead host because
      we don't want rely on the host header which can be spoofed but another
      solution is to resolve the ip addr from the socket to host name.
      
      Example:
      
      ```bash
      $ polkadot --rpc-rate-limit 10 --rpc-rate-limit-whitelisted-ips 127.0.0.1/8 --rpc-rate-limit-trust-proxy-headers
      ```
      
      The ip addr is read from the HTTP proxy headers `Forwarded`,
      `X-Forwarded-For` `X-Real-IP` if `--rpc-rate-limit-trust-proxy-headers`
      is enabled if that is not enabled or the headers are not found then the
      ip address is read from the socket.
      
      //cc @BulatSaif can you test this and give some feedback on it?
      d37719da
  22. May 02, 2024
  23. Apr 08, 2024
    • Aaro Altonen's avatar
      Integrate litep2p into Polkadot SDK (#2944) · 80616f6d
      Aaro Altonen authored
      [litep2p](https://github.com/altonen/litep2p) is a libp2p-compatible P2P
      networking library. It supports all of the features of `rust-libp2p`
      that are currently being utilized by Polkadot SDK.
      
      Compared to `rust-libp2p`, `litep2p` has a quite different architecture
      which is why the new `litep2p` network backend is only able to use a
      little of the existing code in `sc-network`. The design has been mainly
      influenced by how we'd wish to structure our networking-related code in
      Polkadot SDK: independent higher-levels protocols directly communicating
      with the network over links that support bidirectional backpressure. A
      good example would be `NotificationHandle`/`RequestResponseHandle`
      abstractions which allow, e.g., `SyncingEngine` to directly communicate
      with peers to announce/request blocks.
      
      I've tried running `polkadot --network-backend litep2p` with a few
      different peer configurations and there is a noticeable reduction in
      networking CPU usage. For high load (`...
      80616f6d
  24. Feb 20, 2024
    • Niklas Adolfsson's avatar
      rpc server: make possible to disable/enable batch requests (#3364) · fee810a5
      Niklas Adolfsson authored
      The rationale behind this, is that it may be useful for some users
      actually disable RPC batch requests or limit them by length instead of
      the total size bytes of the batch.
      
      This PR adds two new CLI options:
      
      ```
      --rpc-disable-batch-requests - disable batch requests on the server
      --rpc-max-batch-request-len <LEN> - limit batches to LEN on the server.
      ```
      fee810a5
  25. Feb 17, 2024
  26. Feb 14, 2024
    • Niklas Adolfsson's avatar
      rpc: bump jsonrpsee v0.22 and fix race in `rpc v2 chain_head` (#3230) · c7c4fe01
      Niklas Adolfsson authored
      Close #2992 
      
      Breaking changes:
      - rpc server grafana metric `substrate_rpc_requests_started` is removed
      (not possible to implement anymore)
      - rpc server grafana metric `substrate_rpc_requests_finished` is removed
      (not possible to implement anymore)
      - rpc server ws ping/pong not ACK:ed within 30 seconds more than three
      times then the connection will be closed
      
      Added
      - rpc server grafana metric `substrate_rpc_sessions_time` is added to
      get the duration for each websocket session
      c7c4fe01
  27. Feb 03, 2024
  28. Jan 23, 2024
    • Niklas Adolfsson's avatar
      rpc: backpressured RPC server (bump jsonrpsee 0.20) (#1313) · e16ef086
      Niklas Adolfsson authored
      This is a rather big change in jsonrpsee, the major things in this bump
      are:
      - Server backpressure (the subscription impls are modified to deal with
      that)
      - Allow custom error types / return types (remove jsonrpsee::core::Error
      and jsonrpee::core::CallError)
      - Bug fixes (graceful shutdown in particular not used by substrate
      anyway)
         - Less dependencies for the clients in particular
         - Return type requires Clone in method call responses
         - Moved to tokio channels
         - Async subscription API (not used in this PR)
      
      Major changes in this PR:
      - The subscriptions are now bounded and if subscription can't keep up
      with the server it is dropped
      - CLI: add parameter to configure the jsonrpc server bounded message
      buffer (default is 64)
      - Add our own subscription helper to deal with the unbounded streams in
      substrate
      
      The most important things in this PR to review is the added helpers
      functions in `substrate/client/rpc/src/utils.rs` and the rest is pretty
      much chore.
      
      Regarding the "bounded buffer limit" it may cause the server to handle
      the JSON-RPC calls
      slower than before.
      
      The message size limit is bounded by "--rpc-response-size" thus "by
      default 10MB * 64 = 640MB"
      but the subscription message size is not covered by this limit and could
      be capped as well.
      
      Hopefully the last release prior to 1.0, sorry in advance for a big PR
      
      Previous attempt: https://github.com/paritytech/substrate/pull/13992
      
      Resolves https://github.com/paritytech/polkadot-sdk/issues/748, resolves
      https://github.com/paritytech/polkadot-sdk/issues/627
      e16ef086
  29. Jan 12, 2024
    • Dmitry Markin's avatar
      Extract warp sync strategy from `ChainSync` (#2467) · 5208bed7
      Dmitry Markin authored
      
      Extract `WarpSync` (and `StateSync` as part of warp sync) from
      `ChainSync` as independent syncing strategy called by `SyncingEngine`.
      Introduce `SyncingStrategy` enum as a proxy between `SyncingEngine` and
      specific syncing strategies.
      
      ## Limitations
      Gap sync is kept in `ChainSync` for now because it shares the same set
      of peers as block syncing implementation in `ChainSync`. Extraction of a
      common context responsible for peer management in syncing strategies
      able to run in parallel is planned for a follow-up PR.
      
      ## Further improvements
      A possibility of conversion of `SyncingStartegy` into a trait should be
      evaluated. The main stopper for this is that different strategies need
      to communicate different actions to `SyncingEngine` and respond to
      different events / provide different APIs (e.g., requesting
      justifications is only possible via `ChainSync` and not through
      `WarpSync`; `SendWarpProofRequest` action is only relevant to
      `WarpSync`, etc.)
      
      ---------
      
      Co-authored-by: default avatarAaro Altonen <48052676+altonen@users.noreply.github.com>
      5208bed7
  30. Nov 30, 2023
    • Sebastian Kunert's avatar
      PoV Reclaim (Clawback) Node Side (#1462) · 9a650c46
      Sebastian Kunert authored
      This PR provides the infrastructure for the pov-reclaim mechanism
      discussed in #209. The goal is to provide the current proof size to the
      runtime so it can be used to reclaim storage weight.
      
      ## New Host Function
      - A new host function is provided
      [here](https://github.com/skunert/polkadot-sdk/blob/5b317fda
      
      /cumulus/primitives/pov-reclaim/src/lib.rs#L23).
      It returns the size of the current proof size to the runtime. If
      recording is not enabled, it returns 0.
      
      ## Implementation Overview
      - Implement option to enable proof recording during import in the
      client. This is currently enabled for `polkadot-parachain`,
      `parachain-template` and the cumulus test node.
      - Make the proof recorder ready for no-std. It was previously only
      enabled for std environments, but we need to record the proof size in
      `validate_block` too.
      - Provide a recorder implementation that only the records the size of
      incoming nodes and does not store the nodes itself.
      - Fix benchmarks that were broken by async backing changes
      - Provide new externalities extension that is registered by default if
      proof recording is enabled.
      - I think we should discuss the naming, pov-reclaim was more intuitive
      to me, but we could also go with clawback like in the issue.
      
      ## Impact of proof recording during import
      With proof recording: 6.3058 Kelem/s
      Without proof recording: 6.3427 Kelem/s
      
      The measured impact on the importing performance is quite low on my
      machine using the block import benchmark. With proof recording I am
      seeing a performance hit of 0.585%.
      
      ---------
      
      Co-authored-by: command-bot <>
      Co-authored-by: default avatarDavide Galassi <davxy@datawok.net>
      Co-authored-by: default avatarBastian Köcher <git@kchr.de>
      9a650c46
  31. Sep 27, 2023
    • Michal Kucharczyk's avatar
      `BlockId` removal: `tx-pool` refactor (#1678) · ab3a3bc2
      Michal Kucharczyk authored
      
      It changes following APIs:
      - trait `ChainApi`
      -- `validate_transaction`
      
      - trait `TransactionPool` 
      --`submit_at`
      --`submit_one`
      --`submit_and_watch`
      
      and some implementation details, in particular:
      - impl `Pool` 
      --`submit_at`
      --`resubmit_at`
      --`submit_one`
      --`submit_and_watch`
      --`prune_known`
      --`prune`
      --`prune_tags`
      --`resolve_block_number`
      --`verify`
      --`verify_one`
      
      - revalidation queue
      
      All tests are also adjusted.
      
      ---------
      
      Co-authored-by: command-bot <>
      Co-authored-by: default avatarBastian Köcher <git@kchr.de>
      ab3a3bc2
  32. Sep 05, 2023
  33. Aug 16, 2023
  34. Jul 25, 2023
    • Anton's avatar
      chore: update libp2p to 0.52.1 (#14429) · 59d8b864
      Anton authored
      * update libp2p to 0.52.0
      
      * proto name now must implement `AsRef<str>`
      
      * update libp2p version everywhere
      
      * ToSwarm, FromBehaviour, ToBehaviour
      
      also LocalProtocolsChange and RemoteProtocolsChange
      
      * new NetworkBehaviour invariants
      
      * replace `Vec<u8>` with `StreamProtocol`
      
      * rename ConnectionHandlerEvent::Custom to NotifyBehaviour
      
      * remove DialError & ListenError invariants
      
      also fix pending_events
      
      * use connection_limits::Behaviour
      
      See https://github.com/libp2p/rust-libp2p/pull/3885
      
      * impl `void::Void` for `BehaviourOut`
      
      also use `Behaviour::with_codec`
      
      * KademliaHandler no longer public
      
      * fix StreamProtocol construction
      
      * update libp2p-identify to 0.2.0
      
      * remove non-existing methods from PollParameters
      
      rename ConnectionHandlerUpgrErr to StreamUpgradeError
      
      * `P2p` now contains `PeerId`, not `Multihash`
      
      * use multihash-codetable crate
      
      * update Cargo.lock
      
      * reformat text
      
      * comment out tests for now
      
      * remove `.into()` from P2p
      
      * confirm observed addr manually
      
      See https://github.com/libp2p/rust-libp2p/blob/master/protocols/identify/CHANGELOG.md#0430
      
      * remove SwarmEvent::Banned
      
      since we're not using `ban_peer_id`, this can be safely removed.
      we may want to introduce `libp2p::allow_block_list` module in the future.
      
      * fix imports
      
      * replace `libp2p` with smaller deps in network-gossip
      
      * bring back tests
      
      * finish rewriting tests
      
      * uncomment handler tests
      
      * Revert "uncomment handler tests"
      
      This reverts commit 720a06815887f4e10767c62b58864a7ec3a48e50.
      
      * add a fixme
      
      * update Cargo.lock
      
      * remove extra From
      
      * make void uninhabited
      
      * fix discovery test
      
      * use autonat protocols
      
      confirming external addresses manually is unsafe in open networks
      
      * fix SyncNotificationsClogged invariant
      
      * only set server mode manually in tests
      
      doubt that we need to set it on node since we're adding public addresses
      
      * address @dmitry-markin comments
      
      * remove autonat
      
      * removed unused var
      
      * fix EOL
      
      * update smallvec and sha2
      
      in attempt to compile polkadot
      
      * bump k256
      
      in attempt to build cumulus
      
      ---------
      
      Co-authored-by: parity-processbot <>
      59d8b864
  35. Jul 17, 2023
  36. Jul 11, 2023
    • Bastian Köcher's avatar
      Removal of execution strategies (#14387) · 5eb816d7
      Bastian Köcher authored
      
      * Start
      
      * More work!
      
      * Moar
      
      * More changes
      
      * More fixes
      
      * More worrk
      
      * More fixes
      
      * More fixes to make it compile
      
      * Adds `NoOffchainStorage`
      
      * Pass the extensions
      
      * Small basti making small progress
      
      * Fix merge errors and remove `ExecutionContext`
      
      * Move registration of `ReadRuntimeVersionExt` to `ExecutionExtension`
      
      Instead of registering `ReadRuntimeVersionExt` in `sp-state-machine` it is moved to
      `ExecutionExtension` which provides the default extensions.
      
      * Fix compilation
      
      * Register the global extensions inside runtime api instance
      
      * Fixes
      
      * Fix `generate_initial_session_keys` by passing the keystore extension
      
      * Fix the grandpa tests
      
      * Fix more tests
      
      * Fix more tests
      
      * Don't set any heap pages if there isn't an override
      
      * Fix small fallout
      
      * FMT
      
      * Fix tests
      
      * More tests
      
      * Offchain worker custom extensions
      
      * More fixes
      
      * Make offchain tx pool creation reusable
      
      Introduces an `OffchainTransactionPoolFactory` for creating offchain transactions pools that can be
      registered in the runtime externalities context. This factory will be required for a later pr to
      make the creation of offchain transaction pools easier.
      
      * Fixes
      
      * Fixes
      
      * Set offchain transaction pool in BABE before using it in the runtime
      
      * Add the `offchain_tx_pool` to Grandpa as well
      
      * Fix the nodes
      
      * Print some error when using the old warnings
      
      * Fix merge issues
      
      * Fix compilation
      
      * Rename `babe_link`
      
      * Rename to `offchain_tx_pool_factory`
      
      * Cleanup
      
      * FMT
      
      * Fix benchmark name
      
      * Fix `try-runtime`
      
      * Remove `--execution` CLI args
      
      * Make clippy happy
      
      * Forward bls functions
      
      * Fix docs
      
      * Update UI tests
      
      * Update client/api/src/execution_extensions.rs
      
      Co-authored-by: default avatarMichal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com>
      
      * Apply suggestions from code review
      
      Co-authored-by: default avatarKoute <koute@users.noreply.github.com>
      
      * Update client/cli/src/params/import_params.rs
      
      Co-authored-by: default avatarKoute <koute@users.noreply.github.com>
      
      * Update client/api/src/execution_extensions.rs
      
      Co-authored-by: default avatarKoute <koute@users.noreply.github.com>
      
      * Pass the offchain storage to the MMR RPC
      
      * Update client/api/src/execution_extensions.rs
      
      Co-authored-by: default avatarSebastian Kunert <skunert49@gmail.com>
      
      * Review comments
      
      * Fixes
      
      ---------
      
      Co-authored-by: default avatarMichal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com>
      Co-authored-by: default avatarKoute <koute@users.noreply.github.com>
      Co-authored-by: default avatarSebastian Kunert <skunert49@gmail.com>
      5eb816d7
  37. May 31, 2023
  38. May 07, 2023
  39. May 04, 2023
    • Michal Kucharczyk's avatar
      substrate-test-runtime migrated to "pure" frame runtime (#13737) · 6a295e7c
      Michal Kucharczyk authored
      * substrate-test-runtime migrated to pure-frame based
      
      * test block builder: helpers added
      
      * simple renaming
      
      * basic_authorship test adjusted
      
      * block_building storage_proof test adjusted
      
      * babe: tests: should_panic expected added
      
      * babe: tests adjusted
      
      ConsensusLog::NextEpochData is now added by pallet_babe as
      pallet_babe::SameAuthoritiesForever trigger is used in runtime config.
      
      * beefy: tests adjusted
      
      test-substrate-runtime is now using frame::executive to finalize the
      block. during finalization the digests stored during block execution are
      checked against header digests:
      https://github.com/paritytech/substrate/blob/91bb2d29/frame/executive/src/lib.rs#L585-L591
      
      It makes impossible to directly manipulate header's digets, w/o
      depositing logs into system pallet storage `Digest<T: Config>`.
      
      Instead of this dedicated extrinsic allowing to store logs items
      (MmrRoot / AuthoritiesChange) is used.
      
      * grandpa: tests adjusted
      
      test-substrate-runtime is now using frame::executive to finalize the
      block. during finalization the digest logs stored during block execution are
      checked against header digest logs:
      https://github.com/paritytech/substrate/blob/91bb2d29
      
      /frame/executive/src/lib.rs#L585-L591
      
      It makes impossible to directly manipulate header's digets, w/o
      depositing logs into system pallet storage `Digest<T: Config>`.
      
      Instead of this dedicated extrinsic allowing to store logs items
      (ScheduledChange / ForcedChange and DigestItem::Other) is used.
      
      * network:bitswap: test adjusted
      
      The size of unchecked extrinsic was increased. The pattern used in test will
      be placed at the end of scale-encoded buffer.
      
      * runtime apis versions adjusted
      
      * storage keys used in runtime adjusted
      
      * wasm vs native tests removed
      
      * rpc tests: adjusted
      
      Transfer transaction processing was slightly improved, test was
      adjusted.
      
      * tests: sizes adjusted
      
      Runtime extrinsic size was increased. Size of data read during block
      execution was also increased due to usage of new pallets in runtime.
      
      Sizes were adjusted in tests.
      
      * cargo.lock update
      
      cargo update -p substrate-test-runtime -p substrate-test-runtime-client
      
      * warnings fixed
      
      * builders cleanup: includes / std
      
      * extrinsic validation cleanup
      
      * txpool: benches performance fixed
      
      * fmt
      
      * spelling
      
      * Apply suggestions from code review
      
      Co-authored-by: default avatarDavide Galassi <davxy@datawok.net>
      
      * Apply code review suggestions
      
      * Apply code review suggestions
      
      * get rid of 1063 const
      
      * renaming: UncheckedExtrinsic -> Extrinsic
      
      * test-utils-runtime: further step to pure-frame
      
      * basic-authorship: tests OK
      
      * CheckSubstrateCall added + tests fixes
      
      * test::Transfer call removed
      
      * priority / propagate / no sudo+root-testing
      
      * fixing warnings + format
      
      * cleanup: build2/nonce + format
      
      * final tests fixes
      
      all tests are passing
      
      * logs/comments removal
      
      * should_not_accept_old_signatures test removed
      
      * make txpool benches work again
      
      * Cargo.lock reset
      
      * format
      
      * sudo hack removed
      
      * txpool benches fix+cleanup
      
      * .gitignore reverted
      
      * rebase fixing + unsigned cleanup
      
      * Cargo.toml/Cargo.lock cleanup
      
      * force-debug feature removed
      
      * mmr tests fixed
      
      * make cargo-clippy happy
      
      * network sync test uses unsigned extrinsic
      
      * cleanup
      
      * ".git/.scripts/commands/fmt/fmt.sh"
      
      * push_storage_change signed call remove
      
      * GenesisConfig cleanup
      
      * fix
      
      * fix
      
      * GenesisConfig simplified
      
      * storage_keys_works: reworked
      
      * storage_keys_works: expected keys in vec
      
      * storage keys list moved to substrate-test-runtime
      
      * substrate-test: some sanity tests + GenesisConfigBuilder rework
      
      * Apply suggestions from code review
      
      Co-authored-by: default avatarBastian Köcher <git@kchr.de>
      
      * Apply suggestions from code review
      
      * Review suggestions
      
      * fix
      
      * fix
      
      * beefy: generate_blocks_and_sync block_num sync with actaul value
      
      * Apply suggestions from code review
      
      Co-authored-by: default avatarDavide Galassi <davxy@datawok.net>
      
      * Update test-utils/runtime/src/genesismap.rs
      
      Co-authored-by: default avatarDavide Galassi <davxy@datawok.net>
      
      * cargo update -p sc-rpc -p sc-transaction-pool
      
      * Review suggestions
      
      * fix
      
      * doc added
      
      * slot_duration adjusted for Babe::slot_duration
      
      * small doc fixes
      
      * array_bytes::hex used instead of hex
      
      * tiny -> medium name fix
      
      * Apply suggestions from code review
      
      Co-authored-by: default avatarSebastian Kunert <skunert49@gmail.com>
      
      * TransferData::try_from_unchecked_extrinsic -> try_from
      
      * Update Cargo.lock
      
      ---------
      
      Co-authored-by: parity-processbot <>
      Co-authored-by: default avatarDavide Galassi <davxy@datawok.net>
      Co-authored-by: default avatarBastian Köcher <git@kchr.de>
      Co-authored-by: default avatarSebastian Kunert <skunert49@gmail.com>
      6a295e7c
  40. May 03, 2023