1. Apr 26, 2024
  2. Apr 24, 2024
  3. Apr 19, 2024
  4. Apr 18, 2024
  5. Apr 17, 2024
  6. Apr 15, 2024
    • Alexandru Vasile's avatar
      logging(fix): Use the proper log target for logging (#4124) · d1f9fe0a
      Alexandru Vasile authored
      This PR ensures the proper logging target (ie `libp2p_tcp` or `beefy`)
      is displayed.
      
      The issue has been introduced in:
      https://github.com/paritytech/polkadot-sdk/pull/4059, which removes the
      normalized metadata of logs.
      
      From
      [documentation](https://docs.rs/tracing-log/latest/tracing_log/trait.NormalizeEvent.html#tymethod.normalized_metadata):
      
      > In tracing-log, an Event produced by a log (through
      [AsTrace](https://docs.rs/tracing-log/latest/tracing_log/trait.AsTrace.html))
      has an hard coded “log” target
      
      >
      [normalized_metadata](https://docs.rs/tracing-log/latest/tracing_log/trait.NormalizeEvent.html#tymethod.normalized_metadata):
      If this Event comes from a log, this method provides a new normalized
      Metadata which has all available attributes from the original log,
      including file, line, module_path and target
      
      This has low implications if a version was deployed containing the
      mentioned pull request, as we'll lose the ability to distinguish between
      log targets.
      
      ### Before this PR
      
      ```
      2024-04-15 12:45:40.327  INFO main log: Parity Polkadot
      2024-04-15 12:45:40.328  INFO main log: ️  version 1.10.0-d1b0ef76
      2024-04-15 12:45:40.328  INFO main log: ️  by Parity Technologies <[email protected]>, 2017-2024
      2024-04-15 12:45:40.328  INFO main log: 📋 Chain specification: Development
      2024-04-15 12:45:40.328  INFO main log: 🏷  Node name: yellow-eyes-2963
      2024-04-15 12:45:40.328  INFO main log: 👤 Role: AUTHORITY
      2024-04-15 12:45:40.328  INFO main log: 💾 Database: RocksDb at /tmp/substrated39i9J/chains/rococo_dev/db/full
      2024-04-15 12:45:44.508  WARN main log: Took active validators from set with wrong size
      ...
      
      2024-04-15 12:45:45.805  INFO                 main log: 👶 Starting BABE Authorship worker
      2024-04-15 12:45:45.806  INFO tokio-runtime-worker log: 🥩 BEEFY gadget waiting for BEEFY pallet to become available...
      2024-04-15 12:45:45.806 DEBUG tokio-runtime-worker log: New listen address: /ip6/::1/tcp/30333
      2024-04-15 12:45:45.806 DEBUG tokio-runtime-worker log: New listen address: /ip4/127.0.0.1/tcp/30333
      ```
      
      ### After this PR
      
      ```
      2024-04-15 12:59:45.623  INFO main sc_cli::runner: Parity Polkadot
      2024-04-15 12:59:45.623  INFO main sc_cli::runner: ️  version 1.10.0-d1b0ef76
      2024-04-15 12:59:45.623  INFO main sc_cli::runner: ️  by Parity Technologies <[email protected]>, 2017-2024
      2024-04-15 12:59:45.623  INFO main sc_cli::runner: 📋 Chain specification: Development
      2024-04-15 12:59:45.623  INFO main sc_cli::runner: 🏷  Node name: helpless-lizards-0550
      2024-04-15 12:59:45.623  INFO main sc_cli::runner: 👤
      
       Role: AUTHORITY
      ...
      2024-04-15 12:59:50.204  INFO tokio-runtime-worker beefy: 🥩 BEEFY gadget waiting for BEEFY pallet to become available...
      2024-04-15 12:59:50.204 DEBUG tokio-runtime-worker libp2p_tcp: New listen address: /ip6/::1/tcp/30333
      2024-04-15 12:59:50.204 DEBUG tokio-runtime-worker libp2p_tcp: New listen address: /ip4/127.0.0.1/tcp/30333
      ```
      
      Signed-off-by: default avatarAlexandru Vasile <[email protected]>
      d1f9fe0a
    • Alexandru Gheorghe's avatar
      Prevent accidental change of network-key for active authorities (#3852) · 2bc4ed11
      Alexandru Gheorghe authored
      As discovered during investigation of
      https://github.com/paritytech/polkadot-sdk/issues/3314 and
      https://github.com/paritytech/polkadot-sdk/issues/3673 there are active
      validators which accidentally might change their network key during
      restart, that's not a safe operation when you are in the active set
      because of distributed nature of DHT, so the old records would still
      exist in the network until they expire 36h, so unless they have a good
      reason validators should avoid changing their key when they restart
      their nodes.
      
      There is an effort in parallel to improve this situation
      https://github.com/paritytech/polkadot-sdk/pull/3786
      
      , but those changes
      are way more intrusive and will need more rigorous testing, additionally
      they will reduce the time to less than 36h, but the propagation won't be
      instant anyway, so not changing your network during restart should be
      the safest way to run your node, unless you have a really good reason to
      change it.
      
      ## Proposal
      1. Do not auto-generate the network if the network file does not exist
      in the provided path. Nodes where the key file does not exist will get
      the following error:
      ```
      Error: 
         0: Starting an authorithy without network key in /home/alexggh/.local/share/polkadot/chains/ksmcc3/network/secret_ed25519.
            
             This is not a safe operation because the old identity still lives in the dht for 36 hours.
            
             Because of it your node might suffer from not being properly connected to other nodes for validation purposes.
            
             If it is the first time running your node you could use one of the following methods.
            
             1. Pass --unsafe-force-node-key-generation and make sure you remove it for subsequent node restarts
            
             2. Separetly generate the key with: polkadot key generate-node-key --file <YOUR_PATH_TO_NODE_KEY>
      ```
      
      2. Add an explicit parameters for nodes that do want to change their
      network despite the warnings or if they run the node for the first time.
      `--unsafe-force-node-key-generation`
      
      3. For `polkadot key generate-node-key` add two new mutually exclusive
      parameters `base_path` and `default_base_path` to help with the key
      generation in the same path the polkadot main command would expect it.
       
      4. Modify the installation scripts to auto-generate a key in default
      path if one was not present already there, this should help with making
      the executable work out of the box after an instalation.
      
      ## Notes
      
      Nodes that do not have already the key persisted will fail to start
      after this change, however I do consider that better than the current
      situation where they start but they silently hide that they might not be
      properly connected to their peers.
      
      ## TODO
      - [x] Make sure only nodes that are authorities on producation chains
      will be affected by this restrictions.
      - [x] Proper PRDOC, to make sure node operators are aware this is
      coming.
      
      ---------
      
      Signed-off-by: default avatarAlexandru Gheorghe <[email protected]>
      Co-authored-by: default avatarDmitry Markin <[email protected]>
      Co-authored-by: default avatars0me0ne-unkn0wn <[email protected]>
      Co-authored-by: default avatarBastian Köcher <[email protected]>
      2bc4ed11
  7. Apr 13, 2024
  8. Apr 12, 2024
    • Squirrel's avatar
      Remove redundent logging code (#4059) · b28ba4ae
      Squirrel authored
      
      
      1. The `CustomFmtContext::ContextWithFormatFields` enum arm isn't
      actually used and thus we don't need the enum anymore.
      
      2. We don't do anything with most of the normalized metadata that's
      created by calling `event.normalized_metadata();` - the `target` we can
      get from `event.metadata.target()` and level we can get from
      `event.metadata.level()` - let's just call them direct to simplify
      things. (`event.metadata()` is just a field call under the hood)
      
      Changelog: No functional changes, might run a tad faster with lots of
      logging turned on.
      
      ---------
      
      Co-authored-by: default avatarBastian Köcher <[email protected]>
      b28ba4ae
  9. Apr 11, 2024
  10. Apr 10, 2024
  11. Apr 09, 2024
  12. 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
    • Sebastian Kunert's avatar
      Add best block indicator to informant message + print parent block on import message (#4021) · fdb1dba2
      Sebastian Kunert authored
      Sometimes you need to debug some issues just by the logs and reconstruct
      what happened.
      In these scenarios it would be nice to know if a block was imported as
      best block, and what it parent was.
      So here I propose to change the output of the informant to this:
      
      ```
      2024-04-05 20:38:22.004  INFO ⋮substrate: [Parachain]  Imported #18 (0xe7b3…4555 -> 0xbd6f…ced7)    
      2024-04-05 20:38:24.005  INFO ⋮substrate: [Parachain]  Imported #19 (0xbd6f…ced7 -> 0x4dd0…d81f)    
      2024-04-05 20:38:24.011  INFO ⋮substrate: [jobless-children-5352] 🌟 Imported #42 (0xed2e…27fc -> 0x718f…f30e)    
      2024-04-05 20:38:26.005  INFO ⋮substrate: [Parachain]  Imported #20 (0x4dd0…d81f -> 0x6e85…e2b8)    
      2024-04-05 20:38:28.004  INFO ⋮substrate: [Parachain] 🌟 Imported #21 (0x6e85…e2b8 -> 0xad53…2a97)    
      2024-04-05 20:38:30.004  INFO ⋮substrate: [Parachain] 🌟
      
       Imported #22 (0xad53…2a97 -> 0xa874…890f)    
      ```
      
      ---------
      
      Co-authored-by: default avatarBastian Köcher <[email protected]>
      fdb1dba2
    • 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
  13. Apr 06, 2024
    • Squirrel's avatar
      Major bump of tracing-subscriber version (#3891) · 99400385
      Squirrel authored
      
      
      I don't think there are any more releases to the 0.2.x versions, so best
      we're on the 0.3.x release.
      
      No change on the benchmarks, fast local time is still just as fast as
      before:
      
      new version bench:
      ```
      fast_local_time         time:   [30.551 ns 30.595 ns 30.668 ns]
      ```
      
      old version bench:
      ```
      fast_local_time         time:   [30.598 ns 30.646 ns 30.723 ns]
      ```
      
      ---------
      
      Co-authored-by: default avatarBastian Köcher <[email protected]>
      99400385
  14. Apr 04, 2024
  15. Apr 03, 2024
    • Alexandru Vasile's avatar
      chainHead: Ensure reasonable distance between leaf and finalized block (#3562) · 287b116c
      Alexandru Vasile authored
      This PR ensure that the distance between any leaf and the finalized
      block is within a reasonable distance.
      
      For a new subscription, the chainHead has to provide all blocks between
      the leaves of the chain and the finalized block.
       When the distance between a leaf and the finalized block is large:
       - The tree route is costly to compute
       - We could deliver an unbounded number of blocks (potentially millions)
      (For more details see
      https://github.com/paritytech/polkadot-sdk/pull/3445#discussion_r1507210283
      
      )
      
      The configuration of the ChainHead is extended with:
      - suspend on lagging distance: When the distance between any leaf and
      the finalized block is greater than this number, the subscriptions are
      suspended for a given duration.
      - All active subscriptions are terminated with the `Stop` event, all
      blocks are unpinned and data discarded.
      - For incoming subscriptions, until the suspended period expires the
      subscriptions will immediately receive the `Stop` event.
          - Defaults to 128 blocks
      - suspended duration: The amount of time for which subscriptions are
      suspended
          - Defaults to 30 seconds
       
       
       cc @paritytech/subxt-team
      
      ---------
      
      Signed-off-by: default avatarAlexandru Vasile <[email protected]>
      Co-authored-by: default avatarSebastian Kunert <[email protected]>
      287b116c
  16. Apr 02, 2024
  17. Mar 29, 2024
  18. Mar 27, 2024
    • Alexandru Vasile's avatar
      authority-discovery: Set intervals to start when authority keys changes (#3764) · 5ac32ee2
      Alexandru Vasile authored
      The authority-discovery mechanism has implemented a few exponential
      timers for:
      - publishing the authority records
      - goes from 2 seconds (when freshly booted) to 1 hour if the node is
      long-running
        - set to 1 hour after successfully publishing the authority record
      - discovering other authority records
      - goes from 2 seconds (when freshly booted) to 10 minutes if the node is
      long-running
      
      This PR resets the exponential publishing and discovery interval to
      defaults ensuring that long-running nodes:
      - will retry publishing the authority records as aggressively as freshly
      booted nodes
      - Currently, if a long-running node fails to publish the DHT record when
      the keys change (ie DhtEvent::ValuePutFailed), it will only retry after
      1 hour
      - will rediscover other authorities faster (since there is a chance that
      other authority keys changed)
      
      The subp2p-explorer has difficulties discovering the authorities when
      the authority set changes in the first few hours. This might be entirely
      due to the recursive nature of the DHT and the needed time to propagate
      the records. However, there is a small chance that the authority
      publishing failed and is only retried in 1h.
      
      Let me know if this makes sense 🙏
      
       
      
      cc @paritytech/networking
      
      ---------
      
      Signed-off-by: default avatarAlexandru Vasile <[email protected]>
      Co-authored-by: default avatarDmitry Markin <[email protected]>
      5ac32ee2
  19. 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
  20. Mar 22, 2024
  21. Mar 20, 2024
  22. Mar 19, 2024
    • Davide Galassi's avatar
      Implement crypto byte array newtypes in term of a shared type (#3684) · 1e9fd237
      Davide Galassi authored
      Introduces `CryptoBytes` type defined as:
      
      ```rust
      pub struct CryptoBytes<const N: usize, Tag = ()>(pub [u8; N], PhantomData<fn() -> Tag>);
      ```
      
      The type implements a bunch of methods and traits which are typically
      expected from a byte array newtype
      (NOTE: some of the methods and trait implementations IMO are a bit
      redundant, but I decided to maintain them all to not change too much
      stuff in this PR)
      
      It also introduces two (generic) typical consumers of `CryptoBytes`:
      `PublicBytes` and `SignatureBytes`.
      
      ```rust
      pub struct PublicTag;
      pub PublicBytes<const N: usize, CryptoTag> = CryptoBytes<N, (PublicTag, CryptoTag)>;
      
      pub struct SignatureTag;
      pub SignatureBytes<const N: usize, CryptoTag> = CryptoBytes<N, (SignatureTag, CryptoTag)>;
      ```
      
      Both of them use a tag to differentiate the two types at a higher level.
      Downstream specializations will further specialize using a dedicated
      crypto tag. For example in ECDSA:
      
      
      ```rust
      pub struct EcdsaTag;
      
      pub type Public = PublicBytes<PUBLIC_KEY_SERIALIZED_SIZE, EcdsaTag>;
      pub type Signature = PublicBytes<PUBLIC_KEY_SERIALIZED_SIZE, EcdsaTag>;
      ```
      
      Overall we have a cleaner and most importantly **consistent** code for
      all the types involved
      
      All these details are opaque to the end user which can use `Public` and
      `Signature` for the cryptos as before
      1e9fd237
    • Alexandru Vasile's avatar
      rpc: Enable `transaction_unstable_broadcast` RPC V2 API (#3713) · 923f27cc
      Alexandru Vasile authored
      This PR enables the `transaction_unstable_broadcast ` and
      `transaction_unstable_stop` RPC API.
      
      Since the API is unstable, we don't need to expose this in the release
      notes.
      
      After merging this, we could validate the API in subxt and stabilize it.
      
      Spec PR that stabilizes the API:
      https://github.com/paritytech/json-rpc-interface-spec/pull/139
      
      
      
      cc @paritytech/subxt-team
      
      Signed-off-by: default avatarAlexandru Vasile <[email protected]>
      923f27cc
  23. Mar 17, 2024