1. Apr 24, 2024
  2. 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 (`--out-peers 200`), networking CPU
      usage goes down from ~110% to ~30% (80 pp) and for normal load
      (`--out-peers 40`), the usage goes down from ~55% to ~18% (37 pp).
      
      These should not be taken as final numbers because:
      
      a) there are still some low-hanging optimization fruits, such as
      enabling [receive window
      auto-tuning](https://github.com/libp2p/rust-yamux/pull/176
      
      ), integrating
      `Peerset` more closely with `litep2p` or improving memory usage of the
      WebSocket transport
      b) fixing bugs/instabilities that incorrectly cause `litep2p` to do less
      work will increase the networking CPU usage
      c) verification in a more diverse set of tests/conditions is needed
      
      Nevertheless, these numbers should give an early estimate for CPU usage
      of the new networking backend.
      
      This PR consists of three separate changes:
      * introduce a generic `PeerId` (wrapper around `Multihash`) so that we
      don't have use `NetworkService::PeerId` in every part of the code that
      uses a `PeerId`
      * introduce `NetworkBackend` trait, implement it for the libp2p network
      stack and make Polkadot SDK generic over `NetworkBackend`
        * implement `NetworkBackend` for litep2p
      
      The new library should be considered experimental which is why
      `rust-libp2p` will remain as the default option for the time being. This
      PR currently depends on the master branch of `litep2p` but I'll cut a
      new release for the library once all review comments have been
      addresses.
      
      ---------
      
      Signed-off-by: default avatarAlexandru Vasile <[email protected]>
      Co-authored-by: default avatarDmitry Markin <[email protected]>
      Co-authored-by: default avatarAlexandru Vasile <[email protected]>
      Co-authored-by: default avatarAlexandru Vasile <[email protected]>
      80616f6d
    • Bastian Köcher's avatar
      sc-beefy-consensus: Remove unneeded stream. (#4015) · c1063a53
      Bastian Köcher authored
      The stream was just used to communicate from the validator the peer
      reports back to the gossip engine. Internally the gossip engine just
      forwards these reports to the networking engine. So, we can just do this
      directly.
      
      The reporting stream was also pumped [in the worker behind the
      engine](https://github.com/paritytech/polkadot-sdk/blob/9d6261892814fa27c97881c0321c008d7340b54b/substrate/client/consensus/beefy/src/worker.rs#L939).
      This means if there was a lot of data incoming over the engine, the
      reporting stream was almost never processed and thus, it could have
      started to grow and we have seen issues around this.
      
      Partly Closes: https://github.com/paritytech/polkadot-sdk/issues/3945
      c1063a53
  3. Apr 02, 2024
  4. Mar 26, 2024
    • Dcompoze's avatar
      Fix spelling mistakes across the whole repository (#3808) · 002d9260
      Dcompoze authored
      **Update:** Pushed additional changes based on the review comments.
      
      **This pull request fixes various spelling mistakes in this
      repository.**
      
      Most of the changes are contained in the first **3** commits:
      
      - `Fix spelling mistakes in comments and docs`
      
      - `Fix spelling mistakes in test names`
      
      - `Fix spelling mistakes in error messages, panic messages, logs and
      tracing`
      
      Other source code spelling mistakes are separated into individual
      commits for easier reviewing:
      
      - `Fix the spelling of 'authority'`
      
      - `Fix the spelling of 'REASONABLE_HEADERS_IN_JUSTIFICATION_ANCESTRY'`
      
      - `Fix the spelling of 'prev_enqueud_messages'`
      
      - `Fix the spelling of 'endpoint'`
      
      - `Fix the spelling of 'children'`
      
      - `Fix the spelling of 'PenpalSiblingSovereignAccount'`
      
      - `Fix the spelling of 'PenpalSudoAccount'`
      
      - `Fix the spelling of 'insufficient'`
      
      - `Fix the spelling of 'PalletXcmExtrinsicsBenchmark'`
      
      - `Fix the spelling of 'subtracted'`
      
      - `Fix the spelling of 'CandidatePendingAvailability'`
      
      - `Fix the spelling of 'exclusive'`
      
      - `Fix the spelling of 'until'`
      
      - `Fix the spelling of 'discriminator'`
      
      - `Fix the spelling of 'nonexistent'`
      
      - `Fix the spelling of 'subsystem'`
      
      - `Fix the spelling of 'indices'`
      
      - `Fix the spelling of 'committed'`
      
      - `Fix the spelling of 'topology'`
      
      - `Fix the spelling of 'response'`
      
      - `Fix the spelling of 'beneficiary'`
      
      - `Fix the spelling of 'formatted'`
      
      - `Fix the spelling of 'UNKNOWN_PROOF_REQUEST'`
      
      - `Fix the spelling of 'succeeded'`
      
      - `Fix the spelling of 'reopened'`
      
      - `Fix the spelling of 'proposer'`
      
      - `Fix the spelling of 'InstantiationNonce'`
      
      - `Fix the spelling of 'depositor'`
      
      - `Fix the spelling of 'expiration'`
      
      - `Fix the spelling of 'phantom'`
      
      - `Fix the spelling of 'AggregatedKeyValue'`
      
      - `Fix the spelling of 'randomness'`
      
      - `Fix the spelling of 'defendant'`
      
      - `Fix the spelling of 'AquaticMammal'`
      
      - `Fix the spelling of 'transactions'`
      
      - `Fix the spelling of 'PassingTracingSubscriber'`
      
      - `Fix the spelling of 'TxSignaturePayload'`
      
      - `Fix the spelling of 'versioning'`
      
      - `Fix the spelling of 'descendant'`
      
      - `Fix the spelling of 'overridden'`
      
      - `Fix the spelling of 'network'`
      
      Let me know if this structure is adequate.
      
      **Note:** The usage of the words `Merkle`, `Merkelize`, `Merklization`,
      `Merkelization`, `Merkleization`, is somewhat inconsistent but I left it
      as it is.
      
      ~~**Note:** In some places the term `Receival` is used to refer to
      message reception, IMO `Reception` is the correct word here, but I left
      it as it is.~~
      
      ~~**Note:** In some places the term `Overlayed` is used instead of the
      more acceptable version `Overlaid` but I also left it as it is.~~
      
      ~~**Note:** In some places the term `Applyable` is used instead of the
      correct version `Applicable` but I also left it as it is.~~
      
      **Note:** Some usage of British vs American english e.g. `judgement` vs
      `judgment`, `initialise` vs `initialize`, `optimise` vs `optimize` etc.
      are both present in different places, but I suppose that's
      understandable given the number of contributors.
      
      ~~**Note:** There is a spelling mistake in `.github/CODEOWNERS` but it
      triggers errors in CI when I make changes to it, so I left it as it
      is.~~
      002d9260
  5. Feb 22, 2024
    • Adrian Catangiu's avatar
      sc-consensus-beefy: pump gossip engine while waiting for initialization conditions (#3435) · 31546c8d
      Adrian Catangiu authored
      As part of BEEFY worker/voter initialization the task waits for certain
      chain and backend conditions to be fulfilled:
      - BEEFY consensus enabled on-chain & GRANDPA best finalized higher than
      on-chain BEEFY genesis block,
      - backend has synced headers for BEEFY mandatory blocks between best
      BEEFY and best GRANDPA.
      
      During this waiting time, any messages gossiped on the BEEFY topic for
      current chain get enqueued in the gossip engine, leading to RAM bloating
      and output warning/error messages when the wait time is non-negligible
      (like during a clean sync).
      
      This PR adds logic to pump the gossip engine while waiting for other
      things to make sure gossiped messages get consumed (practically
      discarded until worker is fully initialized).
      
      Also raises the warning threshold for enqueued messages from 10k to
      100k. This is in line with the other gossip protocols on the node.
      
      Fixes https://github.com/paritytech/polkadot-sdk/issues/3390
      
      
      
      ---------
      
      Signed-off-by: default avatarAdrian Catangiu <[email protected]>
      31546c8d
  6. Feb 21, 2024
  7. Feb 20, 2024
    • Oliver Tale-Yazdi's avatar
      Lift dependencies to the workspace (Part 2/x) (#3366) · e89d0fca
      Oliver Tale-Yazdi authored
      
      
      Lifting some more dependencies to the workspace. Just using the
      most-often updated ones for now.
      It can be reproduced locally.
      
      ```sh
      # First you can check if there would be semver incompatible bumps (looks good in this case):
      $ zepter transpose dependency lift-to-workspace --ignore-errors syn quote thiserror "regex:^serde.*"
      
      # Then apply the changes:
      $ zepter transpose dependency lift-to-workspace --version-resolver=highest syn quote thiserror "regex:^serde.*" --fix
      
      # And format the changes:
      $ taplo format --config .config/taplo.toml
      ```
      
      ---------
      
      Signed-off-by: default avatarOliver Tale-Yazdi <[email protected]>
      e89d0fca
  8. Feb 16, 2024
  9. 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
  10. Feb 12, 2024
  11. Feb 08, 2024
  12. Feb 01, 2024
  13. Jan 26, 2024
  14. 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
  15. Jan 22, 2024
  16. Jan 10, 2024
    • Alin Dima's avatar
      add fallback request for req-response protocols (#2771) · f2a750ee
      Alin Dima authored
      Previously, it was only possible to retry the same request on a
      different protocol name that had the exact same binary payloads.
      
      Introduce a way of trying a different request on a different protocol if
      the first one fails with Unsupported protocol.
      
      This helps with adding new req-response versions in polkadot while
      preserving compatibility with unupgraded nodes.
      
      The way req-response protocols were bumped previously was that they were
      bundled with some other notifications protocol upgrade, like for async
      backing (but that is more complicated, especially if the feature does
      not require any changes to a notifications protocol). Will be needed for
      implementing https://github.com/polkadot-fellows/RFCs/pull/47
      
      TODO:
      - [x]  add tests
      - [x] add guidance docs in polkadot about req-response protocol
      versioning
      f2a750ee
  17. Jan 08, 2024
  18. Jan 07, 2024
  19. Jan 04, 2024
  20. Dec 27, 2023
  21. Dec 18, 2023
  22. Dec 15, 2023
  23. Dec 14, 2023
  24. Dec 13, 2023
  25. Dec 01, 2023
  26. Nov 30, 2023
  27. Nov 28, 2023
    • Aaro Altonen's avatar
      Rework the event system of `sc-network` (#1370) · e71c484d
      Aaro Altonen authored
      This commit introduces a new concept called `NotificationService` which
      allows Polkadot protocols to communicate with the underlying
      notification protocol implementation directly, without routing events
      through `NetworkWorker`. This implies that each protocol has its own
      service which it uses to communicate with remote peers and that each
      `NotificationService` is unique with respect to the underlying
      notification protocol, meaning `NotificationService` for the transaction
      protocol can only be used to send and receive transaction-related
      notifications.
      
      The `NotificationService` concept introduces two additional benefits:
        * allow protocols to start using custom handshakes
        * allow protocols to accept/reject inbound peers
      
      Previously the validation of inbound connections was solely the
      responsibility of `ProtocolController`. This caused issues with light
      peers and `SyncingEngine` as `ProtocolController` would accept more
      peers than `SyncingEngine` could accept which caused peers to have
      differing views of their own states. `SyncingEngine` would reject excess
      peers but these rejections were not properly communicated to those peers
      causing them to assume that they were accepted.
      
      With `NotificationService`, the local handshake is not sent to remote
      peer if peer is rejected which allows it to detect that it was rejected.
      
      This commit also deprecates the use of `NetworkEventStream` for all
      notification-related events and going forward only DHT events are
      provided through `NetworkEventStream`. If protocols wish to follow each
      other's events, they must introduce additional abtractions, as is done
      for GRANDPA and transactions protocols by following the syncing protocol
      through `SyncEventStream`.
      
      Fixes https://github.com/paritytech/polkadot-sdk/issues/512
      Fixes https://github.com/paritytech/polkadot-sdk/issues/514
      Fixes https://github.com/paritytech/polkadot-sdk/issues/515
      Fixes https://github.com/paritytech/polkadot-sdk/issues/554
      Fixes https://github.com/paritytech/polkadot-sdk/issues/556
      
      ---
      These changes are transferred from
      https://github.com/paritytech/substrate/pull/14197
      
       but there are no
      functional changes compared to that PR
      
      ---------
      
      Co-authored-by: default avatarDmitry Markin <[email protected]>
      Co-authored-by: default avatarAlexandru Vasile <[email protected]>
      e71c484d
  28. Nov 23, 2023
  29. Nov 17, 2023
    • Serban Iorga's avatar
      Beefy: small fixes (#2378) · 3ab2bc9f
      Serban Iorga authored
      Related to #2285
      
      - save the state of the BEEFY gadget after processing a finality proof.
      We need this in order to avoid skipping blocks.
      - avoid reprocessing the old state when not necessary
      3ab2bc9f
  30. Nov 07, 2023
  31. Nov 06, 2023
  32. Nov 03, 2023
    • Bastian Köcher's avatar
      `sc-block-builder`: Remove `BlockBuilderProvider` (#2099) · ca5f1056
      Bastian Köcher authored
      The `BlockBuilderProvider` was a trait that was defined in
      `sc-block-builder`. The trait was implemented for `Client`. This
      basically meant that you needed to import `sc-block-builder` any way to
      have access to the block builder. So, this trait was not providing any
      real value. This pull request is removing the said trait. Instead of the
      trait it introduces a builder for creating a `BlockBuilder`. The builder
      currently has the quite fabulous name `BlockBuilderBuilder` (I'm open to
      any better name 😅
      
      ). The rest of the pull request is about
      replacing the old trait with the new builder.
      
      # Downstream code changes
      
      If you used `new_block` or `new_block_at` before you now need to switch
      it over to the new `BlockBuilderBuilder` pattern:
      
      ```rust
      // `new` requires a type that implements `CallApiAt`. 
      let mut block_builder = BlockBuilderBuilder::new(client)
                      // Then you need to specify the hash of the parent block the block will be build on top of
      		.on_parent_block(at)
                      // The block builder also needs the block number of the parent block. 
                      // Here it is fetched from the given `client` using the `HeaderBackend`
                      // However, there also exists `with_parent_block_number` for directly passing the number
      		.fetch_parent_block_number(client)
      		.unwrap()
                      // Enable proof recording if required. This call is optional.
      		.enable_proof_recording()
                      // Pass the digests. This call is optional.
                      .with_inherent_digests(digests)
      		.build()
      		.expect("Creates new block builder");
      ```
      
      ---------
      
      Co-authored-by: default avatarSebastian Kunert <[email protected]>
      Co-authored-by: command-bot <>
      ca5f1056
  33. Oct 16, 2023
    • Adrian Catangiu's avatar
      sc-consensus-beefy: fix initialization when state is unavailable (#1888) · 646ecd0e
      Adrian Catangiu authored
      Fix situation where BEEFY initial validator set could not be determined.
      
      If state is unavailable at BEEFY genesis block to get initial validator
      set, get the info from header digests. For this, we need to walk back
      the chain starting from BEEFY genesis looking for the BEEFY digest
      announcing the active validator set for that respective session.
      
      This commit fixes a silly bug where walking back the chain was stopped
      when reaching BEEFY genesis block, which is incorrect when BEEFY genesis
      is not session boundary block. When BEEFY genesis is set to some random
      block within a session, we need to walk back to the start of the session
      to see the validator set announcement.
      
      Added regression test for this fix.
      
      Fixes https://github.com/paritytech/polkadot-sdk/issues/1885
      
      
      
      Signed-off-by: default avatarAdrian Catangiu <[email protected]>
      646ecd0e
  34. Oct 13, 2023
    • Adrian Catangiu's avatar
      sc-consensus-beefy: improve gossip logic (#1852) · 83206000
      Adrian Catangiu authored
      - Remove cached messages used for deduplication in `GossipValidator`
      since they're already deduplicated in upper layer `NetworkGossip`.
      - Add cache for "justified rounds" to quickly discard any further (even
      if potentially different) justifications at the gossip level, once a
      valid one (for a respective round) is submitted to the worker.
      - Add short-circuit in worker `finalize()` method to not attempt to
      finalize same block multiple times (for example when we get
      justifications for same block from multiple components like
      block-import, gossip or on-demand).
      - Change a test which had A LOT of latency in syncing blocks for some
      weird reason and would only run after ~150seconds. It now runs
      instantly.
      
      Fixes https://github.com/paritytech/polkadot-sdk/issues/1728
      83206000
  35. Sep 29, 2023
  36. Sep 15, 2023
  37. Sep 11, 2023