1. Apr 15, 2024
    • 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
  2. Apr 14, 2024
  3. Apr 13, 2024
  4. Apr 12, 2024
  5. Apr 11, 2024
  6. Apr 10, 2024
    • PG Herveou's avatar
      Contracts: Remove ED from base deposit (#3536) · 643aa2be
      PG Herveou authored
      - Update internal logic so that the storage_base_deposit does not
      include ED
      - add v16 migration to update ContractInfo struct with this change
      
      Before:
      <img width="820" alt="Screenshot 2024-03-21 at 11 23 29"
      src="https://github.com/paritytech/polkadot-sdk/assets/521091/a0a8df0d-e743-42c5-9e16-cf2ec1aa949c">
      
      After:
      ![Screenshot 2024-03-21 at 11 23
      42](https://github.com/paritytech/polkadot-sdk/assets/521091/593235b0-b866-4915-b653-2071d793228b
      
      )
      
      ---------
      
      Co-authored-by: default avatarCyrill Leutwiler <[email protected]>
      Co-authored-by: command-bot <>
      643aa2be
    • Milos Kriz's avatar
      Amend chainspecs for `people-westend` and add IBP bootnodes (#4072) · d21a41f2
      Milos Kriz authored
      Dear team, dear @NachoPal @joepetrowski @bkchr @ggwpez
      
      ,
      
      This is a retry of #3957, after merging master as advised!,
      
      Many thanks!
      
      **_Milos_**
      
      ---------
      
      Signed-off-by: default avatarOliver Tale-Yazdi <[email protected]>
      Co-authored-by: default avatarOliver Tale-Yazdi <[email protected]>
      d21a41f2
    • PG Herveou's avatar
      Contracts: Reuse module when validating (#3789) · 1da8d12d
      PG Herveou authored
      Reuse wasmi Module when validating.
      Prepare the code for 0.32 and the addition of Module::new_unchecked
      1da8d12d
    • Alexandru Vasile's avatar
      net/strategy: Log bad peerId from on_validated_block_announce (#4051) · cd010925
      Alexandru Vasile authored
      This tiny PR extends the `on_validated_block_announce` log with the bad
      PeerID.
      Used to identify if the peerID is malicious by correlating with other
      logs (ie peer-set).
      
      While at it, have removed the `\n` from a multiline log, which did not
      play well with
      [sub-triage-logs](https://github.com/lexnv/sub-triage-logs/tree/master
      
      ).
      
      cc @paritytech/networking
      
      ---------
      
      Signed-off-by: default avatarAlexandru Vasile <[email protected]>
      Co-authored-by: default avatarBastian Köcher <[email protected]>
      cd010925
    • PG Herveou's avatar
      Contracts: Only exec parsed code in benchmarks (#3915) · 0d71753e
      PG Herveou authored
      [Weights
      compare](https://weights.tasty.limo/compare?unit=weight&ignore_errors=true&threshold=10&method=asymptotic&repo=polkadot-sdk&old=master&new=pg%2Fbench_tweaks&path_pattern=substrate%2Fframe%2F**%2Fsrc%2Fweights.rs%2Cpolkadot%2Fruntime%2F*%2Fsrc%2Fweights%2F**%2F*.rs%2Cpolkadot%2Fbridges%2Fmodules%2F*%2Fsrc%2Fweights.rs%2Ccumulus%2F**%2Fweights%2F*.rs%2Ccumulus%2F**%2Fweights%2Fxcm%2F*.rs%2Ccumulus%2F**%2Fsrc%2Fweights.rs)
      
      Note: Raw weights change does not mean much here, as this PR reduce the
      scope of what is benchmarked, they are therefore decreased by a good
      margin. One should instead print the Schedule using
      
      cargo test --features runtime-benchmarks bench_print_schedule --
      --nocapture
      or following the instructions from the
      [README](https://github.com/paritytech/polkadot-sdk/tree/pg/bench_tweaks/substrate/frame/contracts#schedule)
      for looking at the Schedule of a specific runtime
      
      ---------
      
      Co-authored-by: command-bot <>
      0d71753e
    • Matteo Muraca's avatar
      Removed `pallet::getter` usage from Polkadot Runtime pallets (#3660) · 92e14255
      Matteo Muraca authored
      Part of #3326 
      
      @Kianenigma @ggwpez
      
       
      
      polkadot address: 12poSUQPtcF1HUPQGY3zZu2P8emuW9YnsPduA4XG3oCEfJVp
      
      ---------
      
      Signed-off-by: default avatarMatteo Muraca <[email protected]>
      Co-authored-by: default avatarordian <[email protected]>
      92e14255
    • Bulat Saifullin's avatar
      Convert chainspec to raw (#4057) · d96a9752
      Bulat Saifullin authored
      The plain `people-kusama` and `coretime-kusama` chainspecs were uploaded
      at https://github.com/paritytech/polkadot-sdk/pull/3961. Only binaries
      with compatible runtime versions can run with plain chainspec. For
      example:
      
      One of the latest master builds fails:
      
      ```
      docker run paritypr/polkadot-parachain-debug:master-216509db --chain coretime-kusama
      ...
      Error: Service(Client(Storage("wasm call error Other: Exported method GenesisBuilder_get_preset is not found"))
      ```
      
      Master build from 5 days ago:
      
      ```
      docker run paritypr/polkadot-parachain-debug:master-68cdb126 --chain coretime-kusama
      ...
      2024-04-08 16:51:02 [Parachain] 🔨 Initializing Genesis block/state (state: 0xc418…889c, header-hash: 0x638c…d050)
      2024-04-08 16:51:03 [Relaychain] 🔨 Initializing Genesis block/state (state: 0xb000…ef6b, header-hash: 0xb0a8…dafe)
      2024-04-08 16:51:03 [Relaychain] 👴 Loading GRANDPA authority set from genesis on what appears to be first startup.
      2024-04-08 16:51:03 [Relaychain] 👶 Creating empty BABE epoch changes on what appears to be first startup.
      2024-04-08 16:51:03 [Relaychain] 🏷 Local node identity is: 12D3KooWQEp2uPow3FnngGmy9dYQ3qxY1GkmumS5MqBWEQscwTyy
      2024-04-08 16:51:03 [Relaychain] 📦 Highest known block at #0
      ...
      ```
      
      ## Changes:
      
      1. Rename:
      ```
      coretime-kusama.json -> coretime-kusama-genesis.json
      people-kusama.json -> people-kusama-genesis.json
      ```
      
      2. Generate raw chainspec:
      
      ```
      docker run --rm -v $(pwd):/dir paritypr/polkadot-parachain-debug:master-68cdb126 build-spec --raw --chain /dir/people-kusama-genesis.json > people-kusama.json 
      docker run --rm -v $(pwd):/dir paritypr/polkadot-parachain-debug:master-68cdb126 build-spec --raw --chain /dir/coretime-kusama-genesis.json > coretime-kusama.json
      ```
      
      ## Tests:
      
      New chainspec can run on the latest master build:
      
      ```
      docker run -it --rm -v $(pwd):/dir paritypr/polkadot-parachain-debug:master-216509db --chain /dir/coretime-kusama.json
      ...
      2024-04-09 16:44:39 [Relaychain] ️ Syncing, target=#22665488 (8 peers), best: #2371 (0x19f8…5f3a), finalized #2048 (0xede6…f879),  388.6kiB/s  87.0kiB/s
      2024-04-09 16:44:39 [Parachain] 💤 Idle (6 peers), best: #0 (0x638c…d050), finalized #0 (0x638c…d050),  6.3kiB/s  2.8kiB/s
      ```
      
      Plain chainspec will fail:
      
      ```
      docker run -it --rm -v $(pwd):/dir paritypr/polkadot-parachain-debug:master-216509db --chain /dir/coretime-kusama-genesis.json
      ... 
      Error: Service(Client(Storage("wasm call error Other: Exported method GenesisBuilder_get_preset is not found")))
      ```
      d96a9752
    • Serban Iorga's avatar
      Reapply lost changes · b8956fe1
      Serban Iorga authored and Bastian Köcher's avatar Bastian Köcher committed
      b8956fe1
    • Serban Iorga's avatar
      Fix chain_spec_as_json_fails_with_invalid_config · fb84c461
      Serban Iorga authored and Bastian Köcher's avatar Bastian Köcher committed
      fb84c461
    • Serban Iorga's avatar
      Leftovers · a230a377
      Serban Iorga authored and Bastian Köcher's avatar Bastian Köcher committed
      a230a377
    • Serban Iorga's avatar
      diener workspacify · 4ad46c81
      Serban Iorga authored and Bastian Köcher's avatar Bastian Köcher committed
      4ad46c81
    • Serban Iorga's avatar
      Backport changes from polakdot-sdk (#2920) · 6be88982
      Serban Iorga authored and Bastian Köcher's avatar Bastian Köcher committed
      * Migrate fee payment from `Currency` to `fungible` (#2292)
      
      Part of https://github.com/paritytech/polkadot-sdk/issues/226
      Related https://github.com/paritytech/polkadot-sdk/issues/1833
      
      - Deprecate `CurrencyAdapter` and introduce `FungibleAdapter`
      - Deprecate `ToStakingPot` and replace usage with `ResolveTo`
      - Required creating a new `StakingPotAccountId` struct that implements
      `TypedGet` for the staking pot account ID
      - Update parachain common utils `DealWithFees`, `ToAuthor` and
      `AssetsToBlockAuthor` implementations to use `fungible`
      - Update runtime XCM Weight Traders to use `ResolveTo` instead of
      `ToStakingPot`
      - Update runtime Transaction Payment pallets to use `FungibleAdapter`
      instead of `CurrencyAdapter`
      - [x] Blocked by https://github.com/paritytech/polkadot-sdk/pull/1296,
      needs the `Unbalanced::decrease_balance` fix
      
      (cherry picked from commit bda4e75a
      
      )
      
      * Upgrade `trie-db` from `0.28.0` to `0.29.0` (#3982)
      
      - What does this PR do?
      1. Upgrades `trie-db`'s version to the latest release. This release
      includes, among others, an implementation of `DoubleEndedIterator` for
      the `TrieDB` struct, allowing to iterate both backwards and forwards
      within the leaves of a trie.
      2. Upgrades `trie-bench` to `0.39.0` for compatibility.
      3. Upgrades `criterion` to `0.5.1` for compatibility.
      - Why are these changes needed?
      Besides keeping up with the upgrade of `trie-db`, this specifically adds
      the functionality of iterating back on the leafs of a trie, with
      `sp-trie`. In a project we're currently working on, this comes very
      handy to verify a Merkle proof that is the response to a challenge. The
      challenge is a random hash that (most likely) will not be an existing
      leaf in the trie. So the challenged user, has to provide a Merkle proof
      of the previous and next existing leafs in the trie, that surround the
      random challenged hash.
      
      Without having DoubleEnded iterators, we're forced to iterate until we
      find the first existing leaf, like so:
      ```rust
              // ************* VERIFIER (RUNTIME) *************
              // Verify proof. This generates a partial trie based on the proof and
              // checks that the root hash matches the `expected_root`.
              let (memdb, root) = proof.to_memory_db(Some(&root)).unwrap();
              let trie = TrieDBBuilder::<LayoutV1<RefHasher>>::new(&memdb, &root).build();
      
              // Print all leaf node keys and values.
              println!("\nPrinting leaf nodes of partial tree...");
              for key in trie.key_iter().unwrap() {
                  if key.is_ok() {
                      println!("Leaf node key: {:?}", key.clone().unwrap());
      
                      let val = trie.get(&key.unwrap());
      
                      if val.is_ok() {
                          println!("Leaf node value: {:?}", val.unwrap());
                      } else {
                          println!("Leaf node value: None");
                      }
                  }
              }
      
              println!("RECONSTRUCTED TRIE {:#?}", trie);
      
              // Create an iterator over the leaf nodes.
              let mut iter = trie.iter().unwrap();
      
              // First element with a value should be the previous existing leaf to the challenged hash.
              let mut prev_key = None;
              for element in &mut iter {
                  if element.is_ok() {
                      let (key, _) = element.unwrap();
                      prev_key = Some(key);
                      break;
                  }
              }
              assert!(prev_key.is_some());
      
              // Since hashes are `Vec<u8>` ordered in big-endian, we can compare them directly.
              assert!(prev_key.unwrap() <= challenge_hash.to_vec());
      
              // The next element should exist (meaning there is no other existing leaf between the
              // previous and next leaf) and it should be greater than the challenged hash.
              let next_key = iter.next().unwrap().unwrap().0;
              assert!(next_key >= challenge_hash.to_vec());
      ```
      
      With DoubleEnded iterators, we can avoid that, like this:
      ```rust
              // ************* VERIFIER (RUNTIME) *************
              // Verify proof. This generates a partial trie based on the proof and
              // checks that the root hash matches the `expected_root`.
              let (memdb, root) = proof.to_memory_db(Some(&root)).unwrap();
              let trie = TrieDBBuilder::<LayoutV1<RefHasher>>::new(&memdb, &root).build();
      
              // Print all leaf node keys and values.
              println!("\nPrinting leaf nodes of partial tree...");
              for key in trie.key_iter().unwrap() {
                  if key.is_ok() {
                      println!("Leaf node key: {:?}", key.clone().unwrap());
      
                      let val = trie.get(&key.unwrap());
      
                      if val.is_ok() {
                          println!("Leaf node value: {:?}", val.unwrap());
                      } else {
                          println!("Leaf node value: None");
                      }
                  }
              }
      
              // println!("RECONSTRUCTED TRIE {:#?}", trie);
              println!("\nChallenged key: {:?}", challenge_hash);
      
              // Create an iterator over the leaf nodes.
              let mut double_ended_iter = trie.into_double_ended_iter().unwrap();
      
              // First element with a value should be the previous existing leaf to the challenged hash.
              double_ended_iter.seek(&challenge_hash.to_vec()).unwrap();
              let next_key = double_ended_iter.next_back().unwrap().unwrap().0;
              let prev_key = double_ended_iter.next_back().unwrap().unwrap().0;
      
              // Since hashes are `Vec<u8>` ordered in big-endian, we can compare them directly.
              println!("Prev key: {:?}", prev_key);
              assert!(prev_key <= challenge_hash.to_vec());
      
              println!("Next key: {:?}", next_key);
              assert!(next_key >= challenge_hash.to_vec());
      ```
      - How were these changes implemented and what do they affect?
      All that is needed for this functionality to be exposed is changing the
      version number of `trie-db` in all the `Cargo.toml`s applicable, and
      re-exporting some additional structs from `trie-db` in `sp-trie`.
      
      ---------
      
      Co-authored-by: default avatarBastian Köcher <[email protected]>
      (cherry picked from commit 4e73c0fc
      
      )
      
      * Update polkadot-sdk refs
      
      * Fix Cargo.lock
      
      ---------
      
      Co-authored-by: default avatarLiam Aharon <[email protected]>
      Co-authored-by: default avatarFacundo Farall <[email protected]>
      6be88982
    • Serban Iorga's avatar
      ckb-merkle-mountain-range -> 0.5.2 (#2911) · 3f1a9279
      Serban Iorga authored and Bastian Köcher's avatar Bastian Köcher committed
      3f1a9279