Commit Graph

8833 Commits

Author SHA1 Message Date
gupnik 82f3c3e2e8 Construct Runtime v2 (#1378)
Moved from https://github.com/paritytech/substrate/pull/14788

----

Fixes https://github.com/paritytech/polkadot-sdk/issues/232

This PR introduces outer-macro approach for `construct_runtime` as
discussed in the linked issue. It looks like the following:
```rust
#[frame_support::runtime]
mod runtime {
	#[runtime::runtime]
        #[runtime::derive(
		RuntimeCall,
		RuntimeEvent,
		RuntimeError,
		RuntimeOrigin,
		RuntimeFreezeReason,
		RuntimeHoldReason,
		RuntimeSlashReason,
		RuntimeLockId,
                RuntimeTask,
	)]
	pub struct Runtime;

	#[runtime::pallet_index(0)]
	pub type System = frame_system;

	#[runtime::pallet_index(1)]
	pub type Timestamp = pallet_timestamp;

	#[runtime::pallet_index(2)]
	pub type Aura = pallet_aura;

	#[runtime::pallet_index(3)]
	pub type Grandpa = pallet_grandpa;

	#[runtime::pallet_index(4)]
	pub type Balances = pallet_balances;

	#[runtime::pallet_index(5)]
	pub type TransactionPayment = pallet_transaction_payment;

	#[runtime::pallet_index(6)]
	pub type Sudo = pallet_sudo;

	// Include the custom logic from the pallet-template in the runtime.
	#[runtime::pallet_index(7)]
	pub type TemplateModule = pallet_template;
}
```

## Features
- `#[runtime::runtime]` attached to a struct defines the main runtime
- `#[runtime::derive]` attached to this struct defines the types
generated by runtime
- `#[runtime::pallet_index]` must be attached to a pallet to define its
index
- `#[runtime::disable_call]` can be optionally attached to a pallet to
disable its calls
- `#[runtime::disable_unsigned]` can be optionally attached to a pallet
to disable unsigned calls
- A pallet instance can be defined as `TemplateModule:
pallet_template<Instance>`
- An optional attribute can be defined as
`#[frame_support::runtime(legacy_ordering)]` to ensure that the order of
hooks is same as the order of pallets (and not based on the
pallet_index). This is to support legacy runtimes and should be avoided
for new ones.

## Todo
- [x] Update the latest syntax in kitchensink and tests
- [x] Update UI tests
- [x] Docs

## Extension
- Abstract away the Executive similar to
https://github.com/paritytech/substrate/pull/14742
- Optionally avoid the need to specify all runtime types (TBD)

---------

Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>
Co-authored-by: Nikhil Gupta <>
2024-03-13 07:01:01 +00:00
Michal Kucharczyk a756baf3b2 Support for keyring in runtimes (#2044)
This functionality is required for #1984.

This PR enables
[`sp-keyring`](https://github.com/paritytech/polkadot-sdk/blob/21d36b7b4229c4d5225944f197918cde23fda4ea/substrate/primitives/keyring/src/sr25519.rs#L31-L40)
in `no-std` environments, allowing to generate the public key (e.g.
`AccountKeyring::Alice.public().to_ss58check()`), which can be later
used in the any of built-in [_runtime-genesis-config_
variant](https://github.com/paritytech/polkadot-sdk/blob/21d36b7b4229c4d5225944f197918cde23fda4ea/polkadot/node/service/src/chain_spec.rs#L1066-L1073).


The proposal is as follows:
- expose [`core::Pair`
trait](https://github.com/paritytech/polkadot-sdk/blob/d6f15306282e3de848a09c9aa9cba6f95a7811f0/substrate/primitives/core/src/crypto.rs#L832)
in `no-std`,
- `full_crypto` feature enables `sign` method,
- `std` feature enables `generate_with_phrase` and `generate` methods
(randomness is required),
- All other functionality, currently gated by `full_crypto` will be
available unconditionally (`no-std`):
-- `from_string`
-- `from_string_with_seed`
-- `from seed`
-- `from_seed_slice`
-- `from_phrase`
-- `derive`
-- `verify`

---

Depends on https://github.com/rust-bitcoin/rust-bip39/pull/57

---------

Co-authored-by: command-bot <>
Co-authored-by: Davide Galassi <davxy@datawok.net>
2024-03-12 11:43:31 +00:00
Koute b0f34e4b29 Add a PolkaVM-based executor (#3458)
This PR adds a new PolkaVM-based executor to Substrate.

- The executor can now be used to actually run a PolkaVM-based runtime,
and successfully produces blocks.
- The executor is always compiled-in, but is disabled by default.
- The `SUBSTRATE_ENABLE_POLKAVM` environment variable must be set to `1`
to enable the executor, in which case the node will accept both WASM and
PolkaVM program blobs (otherwise it'll default to WASM-only). This is
deliberately undocumented and not explicitly exposed anywhere (e.g. in
the command line arguments, or in the API) to disincentivize anyone from
enabling it in production. If/when we'll move this into production usage
I'll remove the environment variable and do it "properly".
- I did not use our legacy runtime allocator for the PolkaVM executor,
so currently every allocation inside of the runtime will leak guest
memory until that particular instance is destroyed. The idea here is
that I will work on the https://github.com/polkadot-fellows/RFCs/pull/4
which will remove the need for the legacy allocator under WASM, and that
will also allow us to use a proper non-leaking allocator under PolkaVM.
- I also did some minor cleanups of the WASM executor and deleted some
dead code.

No prdocs included since this is not intended to be an end-user feature,
but an unofficial experiment, and shouldn't affect any current
production user. Once this is production-ready a full Polkadot
Fellowship RFC will be necessary anyway.
2024-03-12 05:23:06 +00:00
gupnik 7315a9b8fd Adds default config for assets pallet (#3637)
Step in https://github.com/paritytech/polkadot-sdk/issues/171
2024-03-12 04:42:58 +00:00
dependabot[bot] 7a644fa082 Bump handlebars from 4.3.7 to 5.1.0 (#3248)
Bumps [handlebars](https://github.com/sunng87/handlebars-rust) from
4.3.7 to 5.1.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/sunng87/handlebars-rust/releases">handlebars's
releases</a>.</em></p>
<blockquote>
<h2>v5.1.0</h2>
<h2>What's Changed</h2>
<ul>
<li>chore(deps-dev): bump follow-redirects from 1.15.2 to 1.15.4 in
/playground/www by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/sunng87/handlebars-rust/pull/628">sunng87/handlebars-rust#628</a></li>
<li>Add chained else expression support by <a
href="https://github.com/progmboy"><code>@​progmboy</code></a> in <a
href="https://redirect.github.com/sunng87/handlebars-rust/pull/629">sunng87/handlebars-rust#629</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a href="https://github.com/progmboy"><code>@​progmboy</code></a>
made their first contribution in <a
href="https://redirect.github.com/sunng87/handlebars-rust/pull/629">sunng87/handlebars-rust#629</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/sunng87/handlebars-rust/compare/v5.0.0...v5.1.0">https://github.com/sunng87/handlebars-rust/compare/v5.0.0...v5.1.0</a></p>
<h2>v5.0.0</h2>
<h2>5.0.0</h2>
<p>A semver major release that introduces some API breaking changes.</p>
<h3>Highlights</h3>
<ul>
<li><code>RenderError</code> has been rewritten for typed error reason.
In previous versions we use string message for <code>RenderError</code>
which is impossible to handle with code. This version introduces
<code>RenderErrorReason</code> so you can use <code>match</code> to deal
various error reasons.</li>
<li>Lifetime in <code>Helper</code> trait has been simplified.</li>
</ul>
<h3>Changes compared to 4.3</h3>
<ul>
<li>[Added] public mutable access to local variables in
<code>BlockContext</code> <a
href="https://redirect.github.com/sunng87/handlebars-rust/issues/533">#533</a></li>
<li>[Changed] Simplified lifetime specifiers for <code>Helper</code>,
<code>ScopedJson</code> and some
other related types and functions. <a
href="https://redirect.github.com/sunng87/handlebars-rust/issues/532">#532</a></li>
<li>[Changed] Updated <code>TemplateError</code> to reduce its size.
Direct field access is
removed in favor of access methods</li>
<li>[Changed] Introducing <code>RenderErrorReason</code> for typed
render error</li>
<li>[Changed] Changed <code>register_template_directory</code> api for
more customizations
#[610]</li>
<li>[Changed] Updated rust-embed to 8.0</li>
</ul>
<h2>Collaboration Wanted</h2>
<p>I'm looking for collaborations to join the development with me on
this project. Contact via email if your are interested in.</p>
<h2>Auto-generated changelog</h2>
<ul>
<li>chore(deps): update criterion requirement from 0.3 to 0.4 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/sunng87/handlebars-rust/pull/530">sunng87/handlebars-rust#530</a></li>
<li>issue 529: simplify lifetime requirements by <a
href="https://github.com/lovasoa"><code>@​lovasoa</code></a> in <a
href="https://redirect.github.com/sunng87/handlebars-rust/pull/532">sunng87/handlebars-rust#532</a></li>
<li>Allow public access to local variables by <a
href="https://github.com/lovasoa"><code>@​lovasoa</code></a> in <a
href="https://redirect.github.com/sunng87/handlebars-rust/pull/533">sunng87/handlebars-rust#533</a></li>
<li>Fix issue when using partial context within each block by <a
href="https://github.com/sunng87"><code>@​sunng87</code></a> in <a
href="https://redirect.github.com/sunng87/handlebars-rust/pull/536">sunng87/handlebars-rust#536</a></li>
<li>chore(deps): update tiny_http requirement from 0.11 to 0.12 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/sunng87/handlebars-rust/pull/538">sunng87/handlebars-rust#538</a></li>
<li>fix: enable include-exclude feature for rust-embed by <a
href="https://github.com/sunng87"><code>@​sunng87</code></a> in <a
href="https://redirect.github.com/sunng87/handlebars-rust/pull/542">sunng87/handlebars-rust#542</a></li>
<li>Fix looking up provided null value in strict mode by <a
href="https://github.com/sunng87"><code>@​sunng87</code></a> in <a
href="https://redirect.github.com/sunng87/handlebars-rust/pull/543">sunng87/handlebars-rust#543</a></li>
<li>chore(deps): update pprof requirement from 0.10 to 0.11 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/sunng87/handlebars-rust/pull/544">sunng87/handlebars-rust#544</a></li>
<li>Able to get the missing variable path from error by <a
href="https://github.com/linw1995"><code>@​linw1995</code></a> in <a
href="https://redirect.github.com/sunng87/handlebars-rust/pull/546">sunng87/handlebars-rust#546</a></li>
<li>chore(deps): update env_logger requirement from 0.9 to 0.10 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/sunng87/handlebars-rust/pull/547">sunng87/handlebars-rust#547</a></li>
<li>fix: loading templates which has multiple extensions by <a
href="https://github.com/sunng87"><code>@​sunng87</code></a> in <a
href="https://redirect.github.com/sunng87/handlebars-rust/pull/551">sunng87/handlebars-rust#551</a></li>
<li>Web playground by <a
href="https://github.com/sunng87"><code>@​sunng87</code></a> in <a
href="https://redirect.github.com/sunng87/handlebars-rust/pull/548">sunng87/handlebars-rust#548</a></li>
<li>chore(deps): bump loader-utils from 1.2.3 to 1.4.2 in
/playground/www by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/sunng87/handlebars-rust/pull/553">sunng87/handlebars-rust#553</a></li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/sunng87/handlebars-rust/blob/master/CHANGELOG.md">handlebars's
changelog</a>.</em></p>
<blockquote>
<h2><a
href="https://github.com/sunng87/handlebars-rust/compare/5.0.0...5.1.0">5.1.0</a>
- 2024-01-17</h2>
<ul>
<li>[Added] Chained <code>else if</code> block support <a
href="https://redirect.github.com/sunng87/handlebars-rust/issues/629">#629</a></li>
</ul>
<h2><a
href="https://github.com/sunng87/handlebars-rust/compare/4.3.4...5.0.0">5.0.0</a>
- 2023-12-31</h2>
<ul>
<li>[Added] public mutable access to local variables in
<code>BlockContext</code> <a
href="https://redirect.github.com/sunng87/handlebars-rust/issues/533">#533</a></li>
<li>[Changed] Simplified lifetime specifiers for <code>Helper</code>,
<code>ScopedJson</code> and some
other related types and functions. <a
href="https://redirect.github.com/sunng87/handlebars-rust/issues/532">#532</a></li>
<li>[Changed] Updated <code>TemplateError</code> to reduce its size.
Direct field access is
removed in favor of access methods</li>
<li>[Changed] Introducing <code>RenderErrorReason</code> for typed
render error</li>
<li>[Changed] Changed <code>register_template_directory</code> api for
more customizations
#[610]</li>
<li>[Changed] Updated rust-embed to 8.0</li>
</ul>
<h2><a
href="https://github.com/sunng87/handlebars-rust/compare/4.3.3...4.3.4">4.3.4</a>
- 2022-09-11</h2>
<ul>
<li>[Added] New <code>write_fmt</code> function for <code>Output</code>
<a
href="https://redirect.github.com/sunng87/handlebars-rust/issues/522">#522</a></li>
<li>[Added] <code>reason()</code> method for <code>TemplateError</code>
to access underlying reason,
this replaces original direct <code>.reason</code> access.</li>
<li>[Changed] Direct access to <code>TemplateError</code>'s
<code>reason</code> field is depreacted will
be removed in future.</li>
</ul>
<h2><a
href="https://github.com/sunng87/handlebars-rust/compare/4.3.2...4.3.3">4.3.3</a>
- 2022-07-20</h2>
<ul>
<li>[Fixed] Disable partial expression indentation with <code>{{~&gt;
partial}}</code> to
bring behavior closer in line with original javascript version. <a
href="https://redirect.github.com/sunng87/handlebars-rust/issues/518">#518</a></li>
<li>[Fixed] Support for using partial context together with partial
parameters
<a
href="https://redirect.github.com/sunng87/handlebars-rust/issues/520">#520</a></li>
</ul>
<h2><a
href="https://github.com/sunng87/handlebars-rust/compare/4.3.1...4.3.2">4.3.2</a>
- 2022-07-14</h2>
<ul>
<li>[Added] Render functions that reuse <code>Context</code> for custom
<code>std::io::Write</code>:
<code>render_with_context_to_write</code> and
<code>render_template_with_context_to_write</code></li>
</ul>
<h2><a
href="https://github.com/sunng87/handlebars-rust/compare/4.3.0...4.3.1">4.3.1</a>
- 2022-06-09</h2>
<ul>
<li>[Added] Added support for <code>{{~{variable}~}}</code> syntax <a
href="https://redirect.github.com/sunng87/handlebars-rust/issues/509">#509</a></li>
</ul>
<h2><a
href="https://github.com/sunng87/handlebars-rust/compare/4.2.2...4.3.0">4.3.0</a>
- 2022-05-18</h2>
<ul>
<li>[Changed] update MSRV to 1.57 as rhai requires</li>
<li>[Fixed] Reimplemented indent support for partial expression
<code>{{&gt; partial}}</code>, which is introduced in 4.2.0. The new
implementation is
aligned with original javascript version, that every text line
generated from partial are indented as <code>{{&gt; partial}}</code>
does. <code>prevent_indent</code> will turn-off this feature. <a
href="https://redirect.github.com/sunng87/handlebars-rust/issues/505">#505</a></li>
<li>[Changed] changed error support library from quick_error to
thiserror</li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/sunng87/handlebars-rust/commit/d8d9a78f4a11d1a5e2ad82cd5277a6edb24d3751"><code>d8d9a78</code></a>
chore: Release handlebars version 5.1.0</li>
<li><a
href="https://github.com/sunng87/handlebars-rust/commit/137bce5863b6782252b966480c497246e904e008"><code>137bce5</code></a>
chore: minor cleanup for chained else support in <a
href="https://redirect.github.com/sunng87/handlebars-rust/issues/629">#629</a></li>
<li><a
href="https://github.com/sunng87/handlebars-rust/commit/e30d8abfa391b643aa93b0e8d5f424f5a436a8c6"><code>e30d8ab</code></a>
Merge pull request <a
href="https://redirect.github.com/sunng87/handlebars-rust/issues/629">#629</a>
from progmboy/else_chain</li>
<li><a
href="https://github.com/sunng87/handlebars-rust/commit/8f16353281b565007ffccddcb8178389aa3bcdc1"><code>8f16353</code></a>
format code</li>
<li><a
href="https://github.com/sunng87/handlebars-rust/commit/786d132c1deb295b1fc77441d85201b556685b82"><code>786d132</code></a>
add else chain support</li>
<li><a
href="https://github.com/sunng87/handlebars-rust/commit/23672e837bf731a609080366450e587960d39b69"><code>23672e8</code></a>
Merge pull request <a
href="https://redirect.github.com/sunng87/handlebars-rust/issues/628">#628</a>
from sunng87/dependabot/npm_and_yarn/playground/www/f...</li>
<li><a
href="https://github.com/sunng87/handlebars-rust/commit/b849efd171e2ec598383605349f4ef8bcd6b8631"><code>b849efd</code></a>
chore(deps-dev): bump follow-redirects in /playground/www</li>
<li><a
href="https://github.com/sunng87/handlebars-rust/commit/7071c9d3ba572b7ac7f29bee43b2f4501652de83"><code>7071c9d</code></a>
test: add test for error reason</li>
<li><a
href="https://github.com/sunng87/handlebars-rust/commit/4664a345f373eb9a96b1281640396d098221a28c"><code>4664a34</code></a>
(cargo-release) version 5.0.0</li>
<li><a
href="https://github.com/sunng87/handlebars-rust/commit/ca277489dc80d2392c0029994e59ed26beb64636"><code>ca27748</code></a>
Merge pull request <a
href="https://redirect.github.com/sunng87/handlebars-rust/issues/625">#625</a>
from sunng87/refactor/render-error-reason-2</li>
<li>Additional commits viewable in <a
href="https://github.com/sunng87/handlebars-rust/compare/v4.3.7...v5.1.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=handlebars&package-manager=cargo&previous-version=4.3.7&new-version=5.1.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

You can trigger a rebase of this PR by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore <dependency name> major version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's major version (unless you unignore this specific
dependency's major version or upgrade to it yourself)
- `@dependabot ignore <dependency name> minor version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's minor version (unless you unignore this specific
dependency's minor version or upgrade to it yourself)
- `@dependabot ignore <dependency name>` will close this group update PR
and stop Dependabot creating any more for the specific dependency
(unless you unignore this specific dependency or upgrade to it yourself)
- `@dependabot unignore <dependency name>` will remove all of the ignore
conditions of the specified dependency
- `@dependabot unignore <dependency name> <ignore condition>` will
remove the ignore condition of the specified dependency and ignore
conditions


</details>

> **Note**
> Automatic rebases have been disabled on this pull request as it has
been open for over 30 days.

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
2024-03-11 22:20:48 +00:00
philoniare d3f81056ad [Deprecation] Remove the deprecated Store trait (#3532)
# Description

*Removes the deprecated `trait Store` feature from the code base*

Fixes #222

---------

Co-authored-by: Dónal Murray <donalm@seadanda.dev>
2024-03-11 20:39:21 +00:00
s0me0ne-unkn0wn 4249a3d6cb Remove getters from im-online pallet (#3589)
As I've been dancing around this pallet for quite some time anyway, I
decided to remove getters at once. There were only a few leftovers in
tests.

Related: #3326 
CC @muraca
2024-03-11 14:38:44 +00:00
Dónal Murray aa35328371 [pallet_broker] Fix adapt_price behaviour at zero (#3636)
This fixes the behaviour of `Linear` which is the default implementation
of the `AdaptPrice` trait in the broker pallet. Previously if cores were
offered but not sold in only one sale, the price would be set to zero
and due to the logic being purely multiplicative, the price would stay
at 0 indefinitely.

This could be further paired with a configurable minimum in the broker
pallet itself, which will be a future PR.

This affects the Rococo and Westend Coretime chains, but Kusama has a
different implementation so this isn't required for the Kusama launch. I
actually thought I opened this a while ago.

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
2024-03-11 14:12:27 +00:00
Muharem bbaa5a3bb5 Asset Conversion: doc guide to address incorrect exchange rate for non-withdrawable pool (#3275)
This documentation guide to address an incorrect exchange rate for a
non-withdrawable pool.
2024-03-10 21:24:41 +00:00
Viki Val 1c435e91c1 🐛 Depositing PalletAttributeSet on incorrect nft (#2740)
## Context

Implementing `HolderOf(collection_id)` we have observed a fancy glitch
where pallet deposits event with incorrect values

### Test case 

[Observe following
extrinsic](https://assethub-polkadot.subscan.io/extrinsic/0xdc72321b7674aa209c2f194ed49bd6bd12708af103f98b5b9196e0132dcba777)

To mint in collection `51` user needs to be `HolderOf(50)`.
Therefore current user is owner of item `394` `witness_data {
owned_item: 394 }`

All checking is done correctly, storage is updated correctly

 
![photo_2023-12-18 16 07
11](https://github.com/paritytech/polkadot-sdk/assets/22471030/ca991272-156d-4db1-97b2-1a2873fc5d3f)

However the event which is emitted does not make semantic sense as we
updated storage for `50-394` not for `51-114`

![photo_2023-12-18 16 07
17](https://github.com/paritytech/polkadot-sdk/assets/22471030/c998a92c-e306-4433-aad8-103078140e23)

## The fix 

This PR fixes that depositing `PalletAttributeSet` emits correct values.

---------

Co-authored-by: Jegor Sidorenko <jegor@parity.io>
Co-authored-by: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com>
2024-03-09 15:32:53 +00:00
Michal Kucharczyk 9f5d9fa96f core: replace secp256k with k256 in crypto::ecdsa (#3525)
This PR replaces the usage of
[secp256k](https://crates.io/crates/secp256k1) crate with
[k256](https://crates.io/crates/k256) in `core::crypto::ecdsa` for
`non-std` environments as outcome of discussion in #3448.

`secp256k1` is used in `std`, meaning that we should not affect host
performance with this PR.
`k256` is enabled in runtimes (`no-std`), and is required to proceed
with #2044.

If desirable, in future we can switch to `k256` also for `std`. That
would require some performance evaluation (e.g. for EVM chains as per
https://github.com/paritytech/polkadot-sdk/issues/3448#issuecomment-1976780391).

Closes https://github.com/paritytech/polkadot-sdk/issues/3448

---------

Co-authored-by: command-bot <>
Co-authored-by: Davide Galassi <davxy@datawok.net>
2024-03-09 10:14:06 +00:00
cuinix ea458d0b95 fix some typos (#3587)
Signed-off-by: cuinix <915115094@qq.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
2024-03-08 21:28:04 +00:00
PG Herveou 1fe3c5f23b Contracts: Fix terminate benchmark (#3558)
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: command-bot <>
2024-03-08 18:13:31 +00:00
PG Herveou a0c9a3d65a benchmark: allow range trailing comma in RangeArgs (#3598)
Rustfmt will add a trailing comma for longer expression, this change
will make sure that the Range parameters can still be parsed.

---------

Co-authored-by: command-bot <>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
2024-03-08 16:36:09 +00:00
PG Herveou f977c21157 Contracts Bump ApiVersion and add test (#3619)
ApiVersion should have been bumped with
https://github.com/paritytech/polkadot-sdk/pull/3606
this does that and add a test so we don't forget to do that everytime
2024-03-08 09:48:55 +00:00
Pablo Andrés Dorado Suárez f4fbddec42 fix(pallet-benchmarking): split test functions in v2 (#3574)
Closes #376

---------

Co-authored-by: command-bot <>
2024-03-07 23:19:52 +00:00
PG Herveou de9411aa4c Contracts: Remove unstable on lock/unlock_delegate_dependency host fns (#3606)
Oversight from PR https://github.com/paritytech/polkadot-sdk/pull/3384.
These 2 functions should have been tagged as stable
2024-03-07 12:39:39 +00:00
Alexander Theißen 6792d4b5b8 Disable flaky test (#3602)
Unfortunately, the flakiness wasn't fixed by
https://github.com/paritytech/polkadot-sdk/pull/3595. Let's disable the
test in the meanwhile since it is hanging on the CI a lot.

---------

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
2024-03-07 12:10:12 +00:00
PG Herveou c89b3997df Contracts: Remove changelog (#3605)
This is not maintained, and we should be able to get information
from the release changelog
2024-03-07 11:47:30 +00:00
Kian Paimani 50cc1c2f7e Add documentation around pallet coupling (#3542)
substrate.io deprecation companion:
https://github.com/substrate-developer-hub/substrate-docs/pull/2139
pba-content companion:
https://github.com/Polkadot-Blockchain-Academy/pba-content/pull/978

partially inspired by:
https://github.com/paritytech/polkadot-sdk/issues/3535

---------

Co-authored-by: Ankan <10196091+Ank4n@users.noreply.github.com>
2024-03-07 11:40:30 +00:00
André Silva 30c32e3d84 move substrate-bip39 into polkadot-sdk (#3579)
Moves [substrate-bip39](https://github.com/paritytech/substrate-bip39)
into substrate. All git history is preserved. Dependencies have been
updated to use the same version as the rest of the repo.

Fixes https://github.com/paritytech/polkadot-sdk/issues/1934.

---------

Co-authored-by: Maciej Hirsz <maciej.hirsz@gmail.com>
Co-authored-by: Maciej Hirsz <1096222+maciejhirsz@users.noreply.github.com>
Co-authored-by: Gav Wood <i@gavwood.com>
Co-authored-by: Stanislav Tkach <stanislav.tkach@gmail.com>
Co-authored-by: Robert Habermeier <rphmeier@gmail.com>
Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
Co-authored-by: Demi M. Obenour <demi@parity.io>
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: NikVolf <nikvolf@gmail.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Benjamin Kampmann <ben@gnunicorn.org>
Co-authored-by: Maciej Hirsz <hello@maciej.codes>
Co-authored-by: cheme <emericchevalier.pro@gmail.com>
Co-authored-by: adoerr <0xad@gmx.net>
Co-authored-by: Jun Jiang <jasl9187@hotmail.com>
Co-authored-by: Dan Shields <35669742+NukeManDan@users.noreply.github.com>
Co-authored-by: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com>
2024-03-07 10:45:56 +00:00
Dastan 11831df8e7 nomination-pools: add permissionless condition to chill (#3453)
Currently, pool member funds cannot be unbonded if the depositor's stake
is less than `MinNominatorBond`. This usually happens after
`T::MinNominatorBond` is increased.

To fix this, the above mentioned condition is added as a case for
permissionless dispatch of `chill`. After pool is chilled, pool members
can unbond their funds since pool won't be nominating anymore.

Consequently, same check is added to `nominate` call, i.e pool can not
start nominating if it's depositor does not have `MinNominatorBond`

cc @Ank4n @kianenigma 

closes #2350

Polkadot address: 16FqwPZ8GRC5U5D4Fu7W33nA55ZXzXGWHwmbnE1eT6pxuqcT

---------

Co-authored-by: Ankan <10196091+Ank4n@users.noreply.github.com>
Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com>
Co-authored-by: command-bot <>
2024-03-07 10:36:30 +00:00
Alexander Theißen 4ae7398818 contracts: Remove wat support from test fixtures (#3588)
In order to prepare for PolkaVM support I removed the wat support from
our test fixture crate.

- Removed redundant tests (invalid module checks are already inside the
prepare module where they belong
- Converted the gas_sync tests to Rust
- Moved the start function test to the `wasm` module
2024-03-07 01:05:04 +00:00
PG Herveou 9952786e1b Contracts upload with Determinism::Enforced when possible (#3540)
Co-authored-by: Cyrill Leutwiler <cyrill@parity.io>
Co-authored-by: command-bot <>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
2024-03-06 16:35:55 +00:00
Alexandru Vasile f2f4b154d7 chainHead/follow: Provide multiple block hashes to the initialized event (#3445)
This PR extends the Initialized event of the chainHead_follow
subscription.

Now, the event provides multiple finalized block hashes. This
information allows clients that are disconnected, and that want to
reconnect, to not lose information about the state of the chain.

At the moment, the spec encourages servers to provide at least 1 minute
of finalized blocks (~10 blocks). The users are responsible for
unpinning these blocks at a later time. This PR tries to report at least
1 finalized block and at most 16 blocks, if they are available.


Closes: https://github.com/paritytech/polkadot-sdk/issues/3432
cc @paritytech/subxt-team

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
2024-03-06 15:52:30 +00:00
André Silva adce09057d sc-manual-seal: don't spawn threads in tests (#3595)
Hopefully helps with test flakiness.
2024-03-06 14:54:36 +00:00
Usama Ali f5bf4654e0 FIX: Make sc-network-sync types Public (#3586)
This PR makes `sc-network-sync` types public following
[this](https://github.com/paritytech/polkadot-sdk/issues/3556) issue.

Fixes #3556
2024-03-06 13:18:56 +00:00
PG Herveou 475e7a1476 Contracts: Charge min amount when processing deletion queue (#2934)
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
2024-03-06 06:47:33 +00:00
Sergej Sakac 8f8297e9de Permissioned contract deployment (#3377)
Closes: #3196

---------

Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: PG Herveou <pgherveou@parity.io>
2024-03-06 00:49:18 +00:00
Oliver Tale-Yazdi 329c077236 [FRAME] Use 'ready' pages in XCMP suspend logic (#2393)
Changes:
- `QueueFootprint` gets a new field; `ready_pages` that contains the
non-overweight and not yet processed pages.
- `XCMP` queue pallet is change to use the `ready_pages` instead of
`pages` to calculate the channel suspension thresholds.

This should give the XCMP queue pallet a more correct view of when to
suspend channels.

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
2024-03-05 17:16:24 +00:00
Rodrigo Quelhas c367ac2488 remove deprecated type 'GenesisConfig' (#3378)
# Description

Removed deprecated type `GenesisConfig` from the codebase.

Closes https://github.com/paritytech/polkadot-sdk/issues/175

# Checklist

- [x] My PR includes a detailed description as outlined in the
"Description" section above
- [x] My PR follows the [labeling requirements](CONTRIBUTING.md#Process)
of this project (at minimum one label for `T`
  required)
- [x] I have made corresponding changes to the documentation (if
applicable)

---------

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
Co-authored-by: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com>
2024-03-05 14:05:04 +00:00
Kian Paimani 4c810609d6 Repot all templates into a single directory (#3460)
The first step towards
https://github.com/paritytech/polkadot-sdk/issues/3155

Brings all templates under the following structure

```
templates
|   parachain
|   |   polkadot-launch
|   |   runtime              --> parachain-template-runtime
|   |   pallets              --> pallet-parachain-template
|   |   node                 --> parachain-template-node
|   minimal
|   |   runtime              --> minimal-template-runtime
|   |   pallets              --> pallet-minimal-template
|   |   node                 --> minimal-template-node
|   solochain
|   |   runtime              --> solochain-template-runtime
|   |   pallets              --> pallet-template (the naming is not consistent here)
|   |   node                 --> solochain-template-node
```

The only note-worthy changes in this PR are: 

- More `Cargo.toml` fields are forwarded to use the one from the
workspace.
- parachain template now has weights and benchmarks
- adds a shell pallet to the minimal template
- remove a few unused deps 


A list of possible follow-ups: 

- [ ] Unify READMEs, create a parent README for all
- [ ] remove references to `docs.substrate.io` in templates
- [ ] make all templates use `#[derive_impl]`
- [ ] update and unify all licenses
- [ ] Remove polkadot launch, use
https://github.com/paritytech/polkadot-sdk/blob/35349df993ea2e7c4769914ef5d199e787b23d4c/cumulus/zombienet/examples/small_network.toml
instead.
2024-03-05 11:40:37 +00:00
Matteo Muraca a71f018c7a Removed pallet::getter usage from pallet-collective (#3456)
Part of #3326 
This one is easier as all the storage items are public. 

@ggwpez @kianenigma @shawntabrizi

---------

Signed-off-by: Matteo Muraca <mmuraca247@gmail.com>
Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
Co-authored-by: command-bot <>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
2024-03-05 11:04:11 +00:00
Serban Iorga 3ff78a7888 Increase 0002-validators-warp-sync timeout (#3575)
Fixes failures like:
https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/5436619#L3319
2024-03-05 11:04:05 +00:00
Niklas Adolfsson efcea0edab rpc server: add prometheus label is_rate_limited (#3504)
After some discussion with @kogeler after the we added the rate-limit
middleware it may slow down
the rpc call timings metrics significantly because it works as follows:

1. The rate limit guard is checked when the call comes and if a slot is
available -> process the call
2. If no free spot is available then the call will be sleeping
`jitter_delay + min_time_rate_guard` then woken up and checked at most
ten times
3. If no spot is available after 10 iterations -> the call is rejected
(this may take tens of seconds)

Thus, this PR adds a label "is_rate_limited" to filter those out on the
metrics "substrate_rpc_calls_time" and "substrate_rpc_calls_finished".

I had to merge two middleware layers Metrics and RateLimit to avoid
shared state in a hacky way.

---------

Co-authored-by: James Wilson <james@jsdw.me>
2024-03-05 09:50:57 +00:00
PG Herveou 0eda0b3f17 Contracts call extract_from_slice in macro (#3566) 2024-03-05 09:47:42 +00:00
Nazar Mokrynskyi c34ad77d05 Remove useless Result import (#3534)
Latest Rust nightly complains with `the item `Result` is imported
redundantly`

Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
2024-03-05 07:47:10 +00:00
PG Herveou 0708cf382d Contracts: Fix typo (#3563) 2024-03-04 20:32:03 +00:00
Gavin Wood fd5f9292f5 FRAME: Create TransactionExtension as a replacement for SignedExtension (#2280)
Closes #2160

First part of [Extrinsic
Horizon](https://github.com/paritytech/polkadot-sdk/issues/2415)

Introduces a new trait `TransactionExtension` to replace
`SignedExtension`. Introduce the idea of transactions which obey the
runtime's extensions and have according Extension data (né Extra data)
yet do not have hard-coded signatures.

Deprecate the terminology of "Unsigned" when used for
transactions/extrinsics owing to there now being "proper" unsigned
transactions which obey the extension framework and "old-style" unsigned
which do not. Instead we have __*General*__ for the former and
__*Bare*__ for the latter. (Ultimately, the latter will be phased out as
a type of transaction, and Bare will only be used for Inherents.)

Types of extrinsic are now therefore:
- Bare (no hardcoded signature, no Extra data; used to be known as
"Unsigned")
- Bare transactions (deprecated): Gossiped, validated with
`ValidateUnsigned` (deprecated) and the `_bare_compat` bits of
`TransactionExtension` (deprecated).
  - Inherents: Not gossiped, validated with `ProvideInherent`.
- Extended (Extra data): Gossiped, validated via `TransactionExtension`.
  - Signed transactions (with a hardcoded signature).
  - General transactions (without a hardcoded signature).

`TransactionExtension` differs from `SignedExtension` because:
- A signature on the underlying transaction may validly not be present.
- It may alter the origin during validation.
- `pre_dispatch` is renamed to `prepare` and need not contain the checks
present in `validate`.
- `validate` and `prepare` is passed an `Origin` rather than a
`AccountId`.
- `validate` may pass arbitrary information into `prepare` via a new
user-specifiable type `Val`.
- `AdditionalSigned`/`additional_signed` is renamed to
`Implicit`/`implicit`. It is encoded *for the entire transaction* and
passed in to each extension as a new argument to `validate`. This
facilitates the ability of extensions to acts as underlying crypto.

There is a new `DispatchTransaction` trait which contains only default
function impls and is impl'ed for any `TransactionExtension` impler. It
provides several utility functions which reduce some of the tedium from
using `TransactionExtension` (indeed, none of its regular functions
should now need to be called directly).

Three transaction version discriminator ("versions") are now
permissible:
- 0b000000100: Bare (used to be called "Unsigned"): contains Signature
or Extra (extension data). After bare transactions are no longer
supported, this will strictly identify an Inherents only.
- 0b100000100: Old-school "Signed" Transaction: contains Signature and
Extra (extension data).
- 0b010000100: New-school "General" Transaction: contains Extra
(extension data), but no Signature.

For the New-school General Transaction, it becomes trivial for authors
to publish extensions to the mechanism for authorizing an Origin, e.g.
through new kinds of key-signing schemes, ZK proofs, pallet state,
mutations over pre-authenticated origins or any combination of the
above.

## Code Migration

### NOW: Getting it to build

Wrap your `SignedExtension`s in `AsTransactionExtension`. This should be
accompanied by renaming your aggregate type in line with the new
terminology. E.g. Before:

```rust
/// The SignedExtension to the basic transaction logic.
pub type SignedExtra = (
	/* snip */
	MySpecialSignedExtension,
);
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic =
	generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
```

After:

```rust
/// The extension to the basic transaction logic.
pub type TxExtension = (
	/* snip */
	AsTransactionExtension<MySpecialSignedExtension>,
);
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic =
	generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, TxExtension>;
```

You'll also need to alter any transaction building logic to add a
`.into()` to make the conversion happen. E.g. Before:

```rust
fn construct_extrinsic(
		/* snip */
) -> UncheckedExtrinsic {
	let extra: SignedExtra = (
		/* snip */
		MySpecialSignedExtension::new(/* snip */),
	);
	let payload = SignedPayload::new(call.clone(), extra.clone()).unwrap();
	let signature = payload.using_encoded(|e| sender.sign(e));
	UncheckedExtrinsic::new_signed(
		/* snip */
		Signature::Sr25519(signature),
		extra,
	)
}
```

After:

```rust
fn construct_extrinsic(
		/* snip */
) -> UncheckedExtrinsic {
	let tx_ext: TxExtension = (
		/* snip */
		MySpecialSignedExtension::new(/* snip */).into(),
	);
	let payload = SignedPayload::new(call.clone(), tx_ext.clone()).unwrap();
	let signature = payload.using_encoded(|e| sender.sign(e));
	UncheckedExtrinsic::new_signed(
		/* snip */
		Signature::Sr25519(signature),
		tx_ext,
	)
}
```

### SOON: Migrating to `TransactionExtension`

Most `SignedExtension`s can be trivially converted to become a
`TransactionExtension`. There are a few things to know.

- Instead of a single trait like `SignedExtension`, you should now
implement two traits individually: `TransactionExtensionBase` and
`TransactionExtension`.
- Weights are now a thing and must be provided via the new function `fn
weight`.

#### `TransactionExtensionBase`

This trait takes care of anything which is not dependent on types
specific to your runtime, most notably `Call`.

- `AdditionalSigned`/`additional_signed` is renamed to
`Implicit`/`implicit`.
- Weight must be returned by implementing the `weight` function. If your
extension is associated with a pallet, you'll probably want to do this
via the pallet's existing benchmarking infrastructure.

#### `TransactionExtension`

Generally:
- `pre_dispatch` is now `prepare` and you *should not reexecute the
`validate` functionality in there*!
- You don't get an account ID any more; you get an origin instead. If
you need to presume an account ID, then you can use the trait function
`AsSystemOriginSigner::as_system_origin_signer`.
- You get an additional ticket, similar to `Pre`, called `Val`. This
defines data which is passed from `validate` into `prepare`. This is
important since you should not be duplicating logic from `validate` to
`prepare`, you need a way of passing your working from the former into
the latter. This is it.
- This trait takes two type parameters: `Call` and `Context`. `Call` is
the runtime call type which used to be an associated type; you can just
move it to become a type parameter for your trait impl. `Context` is not
currently used and you can safely implement over it as an unbounded
type.
- There's no `AccountId` associated type any more. Just remove it.

Regarding `validate`:
- You get three new parameters in `validate`; all can be ignored when
migrating from `SignedExtension`.
- `validate` returns a tuple on success; the second item in the tuple is
the new ticket type `Self::Val` which gets passed in to `prepare`. If
you use any information extracted during `validate` (off-chain and
on-chain, non-mutating) in `prepare` (on-chain, mutating) then you can
pass it through with this. For the tuple's last item, just return the
`origin` argument.

Regarding `prepare`:
- This is renamed from `pre_dispatch`, but there is one change:
- FUNCTIONALITY TO VALIDATE THE TRANSACTION NEED NOT BE DUPLICATED FROM
`validate`!!
- (This is different to `SignedExtension` which was required to run the
same checks in `pre_dispatch` as in `validate`.)

Regarding `post_dispatch`:
- Since there are no unsigned transactions handled by
`TransactionExtension`, `Pre` is always defined, so the first parameter
is `Self::Pre` rather than `Option<Self::Pre>`.

If you make use of `SignedExtension::validate_unsigned` or
`SignedExtension::pre_dispatch_unsigned`, then:
- Just use the regular versions of these functions instead.
- Have your logic execute in the case that the `origin` is `None`.
- Ensure your transaction creation logic creates a General Transaction
rather than a Bare Transaction; this means having to include all
`TransactionExtension`s' data.
- `ValidateUnsigned` can still be used (for now) if you need to be able
to construct transactions which contain none of the extension data,
however these will be phased out in stage 2 of the Transactions Horizon,
so you should consider moving to an extension-centric design.

## TODO

- [x] Introduce `CheckSignature` impl of `TransactionExtension` to
ensure it's possible to have crypto be done wholly in a
`TransactionExtension`.
- [x] Deprecate `SignedExtension` and move all uses in codebase to
`TransactionExtension`.
  - [x] `ChargeTransactionPayment`
  - [x] `DummyExtension`
  - [x] `ChargeAssetTxPayment` (asset-tx-payment)
  - [x] `ChargeAssetTxPayment` (asset-conversion-tx-payment)
  - [x] `CheckWeight`
  - [x] `CheckTxVersion`
  - [x] `CheckSpecVersion`
  - [x] `CheckNonce`
  - [x] `CheckNonZeroSender`
  - [x] `CheckMortality`
  - [x] `CheckGenesis`
  - [x] `CheckOnlySudoAccount`
  - [x] `WatchDummy`
  - [x] `PrevalidateAttests`
  - [x] `GenericSignedExtension`
  - [x] `SignedExtension` (chain-polkadot-bulletin)
  - [x] `RefundSignedExtensionAdapter`
- [x] Implement `fn weight` across the board.
- [ ] Go through all pre-existing extensions which assume an account
signer and explicitly handle the possibility of another kind of origin.
- [x] `CheckNonce` should probably succeed in the case of a non-account
origin.
- [x] `CheckNonZeroSender` should succeed in the case of a non-account
origin.
- [x] `ChargeTransactionPayment` and family should fail in the case of a
non-account origin.
  - [ ] 
- [x] Fix any broken tests.

---------

Signed-off-by: georgepisaltu <george.pisaltu@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
Co-authored-by: Nikhil Gupta <17176722+gupnik@users.noreply.github.com>
Co-authored-by: georgepisaltu <52418509+georgepisaltu@users.noreply.github.com>
Co-authored-by: Chevdor <chevdor@users.noreply.github.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Maciej <maciej.zyszkiewicz@parity.io>
Co-authored-by: Javier Viola <javier@parity.io>
Co-authored-by: Marcin S. <marcin@realemail.net>
Co-authored-by: Tsvetomir Dimitrov <tsvetomir@parity.io>
Co-authored-by: Javier Bullrich <javier@bullrich.dev>
Co-authored-by: Koute <koute@users.noreply.github.com>
Co-authored-by: Adrian Catangiu <adrian@parity.io>
Co-authored-by: Vladimir Istyufeev <vladimir@parity.io>
Co-authored-by: Ross Bulat <ross@parity.io>
Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com>
Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
Co-authored-by: Svyatoslav Nikolsky <svyatonik@gmail.com>
Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: s0me0ne-unkn0wn <48632512+s0me0ne-unkn0wn@users.noreply.github.com>
Co-authored-by: ordian <write@reusable.software>
Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
Co-authored-by: Aaro Altonen <48052676+altonen@users.noreply.github.com>
Co-authored-by: Dmitry Markin <dmitry@markin.tech>
Co-authored-by: Alexandru Vasile <60601340+lexnv@users.noreply.github.com>
Co-authored-by: Alexander Samusev <41779041+alvicsam@users.noreply.github.com>
Co-authored-by: Julian Eager <eagr@tutanota.com>
Co-authored-by: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com>
Co-authored-by: Davide Galassi <davxy@datawok.net>
Co-authored-by: Dónal Murray <donal.murray@parity.io>
Co-authored-by: yjh <yjh465402634@gmail.com>
Co-authored-by: Tom Mi <tommi@niemi.lol>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Will | Paradox | ParaNodes.io <79228812+paradox-tt@users.noreply.github.com>
Co-authored-by: Bastian Köcher <info@kchr.de>
Co-authored-by: Joshy Orndorff <JoshOrndorff@users.noreply.github.com>
Co-authored-by: Joshy Orndorff <git-user-email.h0ly5@simplelogin.com>
Co-authored-by: PG Herveou <pgherveou@gmail.com>
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Juan Girini <juangirini@gmail.com>
Co-authored-by: bader y <ibnbassem@gmail.com>
Co-authored-by: James Wilson <james@jsdw.me>
Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
Co-authored-by: asynchronous rob <rphmeier@gmail.com>
Co-authored-by: Parth <desaiparth08@gmail.com>
Co-authored-by: Andrew Jones <ascjones@gmail.com>
Co-authored-by: Jonathan Udd <jonathan@dwellir.com>
Co-authored-by: Serban Iorga <serban@parity.io>
Co-authored-by: Egor_P <egor@parity.io>
Co-authored-by: Branislav Kontur <bkontur@gmail.com>
Co-authored-by: Evgeny Snitko <evgeny@parity.io>
Co-authored-by: Just van Stam <vstam1@users.noreply.github.com>
Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>
Co-authored-by: gupnik <nikhilgupta.iitk@gmail.com>
Co-authored-by: dzmitry-lahoda <dzmitry@lahoda.pro>
Co-authored-by: zhiqiangxu <652732310@qq.com>
Co-authored-by: Nazar Mokrynskyi <nazar@mokrynskyi.com>
Co-authored-by: Anwesh <anweshknayak@gmail.com>
Co-authored-by: cheme <emericchevalier.pro@gmail.com>
Co-authored-by: Sam Johnson <sam@durosoft.com>
Co-authored-by: kianenigma <kian@parity.io>
Co-authored-by: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com>
Co-authored-by: Muharem <ismailov.m.h@gmail.com>
Co-authored-by: joepetrowski <joe@parity.io>
Co-authored-by: Alexandru Gheorghe <49718502+alexggh@users.noreply.github.com>
Co-authored-by: Gabriel Facco de Arruda <arrudagates@gmail.com>
Co-authored-by: Squirrel <gilescope@gmail.com>
Co-authored-by: Andrei Sandu <54316454+sandreim@users.noreply.github.com>
Co-authored-by: georgepisaltu <george.pisaltu@parity.io>
Co-authored-by: command-bot <>
2024-03-04 19:12:43 +00:00
Liam Aharon b0741d4f78 Finish documenting #[pallet::xxx] macros (#2638)
Closes https://github.com/paritytech/polkadot-sdk-docs/issues/35

- Moves pallet proc macro docs to `frame_support`
- Adds missing docs
- Revise revise existing docs, adding compiling doctests where
appropriate

---------

Co-authored-by: command-bot <>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
2024-03-03 08:37:41 +00:00
gupnik cdc8d197e6 Remove as frame_system::DefaultConfig from the required syntax in derive_impl (#3505)
Step in https://github.com/paritytech/polkadot-sdk/issues/171

This PR removes the need to specify `as [disambiguation_path]` for cases
where the trait definition resides within the same scope as default impl
path.

For example, in the following macro invocation
```rust
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
impl frame_system::Config for Runtime {
   ...
}
```
the trait `DefaultConfig` lies within the `frame_system` scope and
`TestDefaultConfig` impls the `DefaultConfig` trait. Using this
information, we can compute the disambiguation path internally, thus
removing the need of an explicit specification.

In cases where the trait lies outside this scope, we would still need to
specify it explicitly, but this should take care of most (if not all)
uses of `derive_impl` within FRAME's context.
2024-03-02 12:49:12 +00:00
Dmitry Markin a1b57a8c18 Fix crash of synced parachain node run with --sync=warp (#3523)
Fixes https://github.com/paritytech/polkadot-sdk/issues/3496.
2024-03-01 11:19:17 +00:00
Kian Paimani c0e52a9ed6 Fix call enum's metadata regression (#3513)
This fixes an issue introduced in
https://github.com/paritytech/substrate/pull/14101, in which I removed
the `Call` enum's documentation and replaced it with a link to the
`Pallet` struct, but this also removed any docs related to call from the
metadata.

I tried to add a regression test for this, but it seems to me that this
is not possible, given that using `type-info` we only assert in type-ids
for `Call`, `Event` and `Error`. I removed some doc comments from a test
setup in `frame-support-test` to demonstrate the issue there. @jsdw do
you have any comments on this?

I also fixed a small issue in the custom html/css of `polkadot-sdk-doc`
crate, making sure it does not affect the rust-doc page of all other
crates.

- [x] Investigate a regression test
- [x] prdoc
2024-02-29 19:08:08 +00:00
philoniare a22319cdd5 [Deprecation] Remove sp_weights::OldWeight (#3491)
# Description

*Removes `sp_weights::OldWeight` and its usage*

Fixes #144

---------

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
2024-02-29 05:17:24 +00:00
Alexandru Gheorghe 833bafdbf7 Fixup multi-collator parachain transition to async backing (#3510)
Fixing: 
```
Verification failed for block 0x07bbf1e04121d70a4bdb21cc055132b53ac2390fa95c4d05497fc91b1e8bf7f5 received from (12D3KooWJzLd8skcAgA24EcJey7aJAhYctfUxWGjSP5Usk9wbpPZ): "Header 0x07bbf1e04121d70a4bdb21cc055132b53ac2390fa95c4d05497fc91b1e8bf7f5 rejected: too far in the future"   
```

---------

Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Co-authored-by: Dmitry Sinyavin <dmitry.sinyavin@parity.io>
Co-authored-by: s0me0ne-unkn0wn <48632512+s0me0ne-unkn0wn@users.noreply.github.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
2024-02-28 23:43:53 +00:00
Oliver Tale-Yazdi eefd5fe449 Multi-Block-Migrations, poll hook and new System callbacks (#1781)
This MR is the merge of
https://github.com/paritytech/substrate/pull/14414 and
https://github.com/paritytech/substrate/pull/14275. It implements
[RFC#13](https://github.com/polkadot-fellows/RFCs/pull/13), closes
https://github.com/paritytech/polkadot-sdk/issues/198.

----- 

This Merge request introduces three major topicals:

1. Multi-Block-Migrations
1. New pallet `poll` hook for periodic service work
1. Replacement hooks for `on_initialize` and `on_finalize` in cases
where `poll` cannot be used

and some more general changes to FRAME.  
The changes for each topical span over multiple crates. They are listed
in topical order below.

# 1.) Multi-Block-Migrations

Multi-Block-Migrations are facilitated by creating `pallet_migrations`
and configuring `System::Config::MultiBlockMigrator` to point to it.
Executive picks this up and triggers one step of the migrations pallet
per block.
The chain is in lockdown mode for as long as an MBM is ongoing.
Executive does this by polling `MultiBlockMigrator::ongoing` and not
allowing any transaction in a block, if true.

A MBM is defined through trait `SteppedMigration`. A condensed version
looks like this:
```rust
/// A migration that can proceed in multiple steps.
pub trait SteppedMigration {
	type Cursor: FullCodec + MaxEncodedLen;
	type Identifier: FullCodec + MaxEncodedLen;

	fn id() -> Self::Identifier;

	fn max_steps() -> Option<u32>;

	fn step(
		cursor: Option<Self::Cursor>,
		meter: &mut WeightMeter,
	) -> Result<Option<Self::Cursor>, SteppedMigrationError>;
}
```

`pallet_migrations` can be configured with an aggregated tuple of these
migrations. It then starts to migrate them one-by-one on the next
runtime upgrade.
Two things are important here:
- 1. Doing another runtime upgrade while MBMs are ongoing is not a good
idea and can lead to messed up state.
- 2. **Pallet Migrations MUST BE CONFIGURED IN `System::Config`,
otherwise it is not used.**

The pallet supports an `UpgradeStatusHandler` that can be used to notify
external logic of upgrade start/finish (for example to pause XCM
dispatch).

Error recovery is very limited in the case that a migration errors or
times out (exceeds its `max_steps`). Currently the runtime dev can
decide in `FailedMigrationHandler::failed` how to handle this. One
follow-up would be to pair this with the `SafeMode` pallet and enact
safe mode when an upgrade fails, to allow governance to rescue the
chain. This is currently not possible, since governance is not
`Mandatory`.

## Runtime API

- `Core`: `initialize_block` now returns `ExtrinsicInclusionMode` to
inform the Block Author whether they can push transactions.

### Integration

Add it to your runtime implementation of `Core` and `BlockBuilder`:
```patch
diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs
@@ impl_runtime_apis! {
	impl sp_block_builder::Core<Block> for Runtime {
-		fn initialize_block(header: &<Block as BlockT>::Header) {
+		fn initialize_block(header: &<Block as BlockT>::Header) -> RuntimeExecutiveMode {
			Executive::initialize_block(header)
		}

		...
	}
```

# 2.) `poll` hook

A new pallet hook is introduced: `poll`. `Poll` is intended to replace
mostly all usage of `on_initialize`.
The reason for this is that any code that can be called from
`on_initialize` cannot be migrated through an MBM. Currently there is no
way to statically check this; the implication is to use `on_initialize`
as rarely as possible.
Failing to do so can result in broken storage invariants.

The implementation of the poll hook depends on the `Runtime API` changes
that are explained above.

# 3.) Hard-Deadline callbacks

Three new callbacks are introduced and configured on `System::Config`:
`PreInherents`, `PostInherents` and `PostTransactions`.
These hooks are meant as replacement for `on_initialize` and
`on_finalize` in cases where the code that runs cannot be moved to
`poll`.
The reason for this is to make the usage of HD-code (hard deadline) more
explicit - again to prevent broken invariants by MBMs.

# 4.) FRAME (general changes)

## `frame_system` pallet

A new memorize storage item `InherentsApplied` is added. It is used by
executive to track whether inherents have already been applied.
Executive and can then execute the MBMs directly between inherents and
transactions.

The `Config` gets five new items:
- `SingleBlockMigrations` this is the new way of configuring migrations
that run in a single block. Previously they were defined as last generic
argument of `Executive`. This shift is brings all central configuration
about migrations closer into view of the developer (migrations that are
configured in `Executive` will still work for now but is deprecated).
- `MultiBlockMigrator` this can be configured to an engine that drives
MBMs. One example would be the `pallet_migrations`. Note that this is
only the engine; the exact MBMs are injected into the engine.
- `PreInherents` a callback that executes after `on_initialize` but
before inherents.
- `PostInherents` a callback that executes after all inherents ran
(including MBMs and `poll`).
- `PostTransactions` in symmetry to `PreInherents`, this one is called
before `on_finalize` but after all transactions.

A sane default is to set all of these to `()`. Example diff suitable for
any chain:
```patch
@@ impl frame_system::Config for Test {
 	type MaxConsumers = ConstU32<16>;
+	type SingleBlockMigrations = ();
+	type MultiBlockMigrator = ();
+	type PreInherents = ();
+	type PostInherents = ();
+	type PostTransactions = ();
 }
```

An overview of how the block execution now looks like is here. The same
graph is also in the rust doc.

<details><summary>Block Execution Flow</summary>
<p>

![Screenshot 2023-12-04 at 19 11
29](https://github.com/paritytech/polkadot-sdk/assets/10380170/e88a80c4-ef11-4faa-8df5-8b33a724c054)

</p>
</details> 

## Inherent Order

Moved to https://github.com/paritytech/polkadot-sdk/pull/2154

---------------


## TODO

- [ ] Check that `try-runtime` still works
- [ ] Ensure backwards compatibility with old Runtime APIs
- [x] Consume weight correctly
- [x] Cleanup

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
Co-authored-by: Juan Girini <juangirini@gmail.com>
Co-authored-by: command-bot <>
Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com>
Co-authored-by: Gavin Wood <gavin@parity.io>
Co-authored-by: Bastian Köcher <git@kchr.de>
2024-02-28 19:49:00 +00:00
Kian Paimani 14530269b7 Add documentation around FRAME Offchain workers (#3463)
- deprecation companion:
https://github.com/substrate-developer-hub/substrate-docs/pull/2136
- inspired by
https://substrate.stackexchange.com/questions/11058/how-can-i-create-ocw-that-wont-activates-every-block-but-will-activates-only-w/11060#11060

---------

Co-authored-by: Sergej Sakac <73715684+Szegoo@users.noreply.github.com>
2024-02-28 13:07:14 +00:00
Alexandru Vasile f1b2189e83 rpc-v2/tx/tests: Add transaction broadcast tests and check propagated tx status (#3193)
This PR adds tests for the `transaction_broadcast` method.


The testing needs to coordinate the following components:
- The `TestApi` marks transactions as invalid and implements
`ChainApi::validate_transaction`
- this is what dictates if a transaction is valid or not and is called
from within the `BasicPool`
- The `BasicPool` which maintains the transactions and implements
`submit_and_watch` needed by the tx broadcast to submit the transaction
- The status of the transaction pool is exposed by mocking the BasicPool
- The `ChainHeadMockClient` which mocks the
`BlockchainEvents::import_notification_stream` needed by the tx
broadcast to know to which blocks the transaction is submitted

The following changes have been added to the substrate testing to
accommodate this:
- `TestApi` gets ` remove_invalid`, counterpart to `add_invalid` to
ensure an invalid transaction can become valid again; as well as a
priority setter for extrinsics
- `BasicPool` test constructor is extended with options for the
`PoolRotator`
- this mechanism is needed because transactions are banned for 30mins
(default) after they are declared invalid
  - testing bypasses this by providing a `Duration::ZERO`

### Testing Scenarios

- Capture the status of the transaction as it is normally broadcasted
- `transaction_stop` is valid while the transaction is in progress
- A future transaction is handled when the dependencies are completed
- Try to resubmit the transaction at a later block (currently invalid)
- An invalid transaction status is propagated; the transaction is marked
as temporarily banned; then the ban expires and transaction is
resubmitted
  
This builds on top of:
https://github.com/paritytech/polkadot-sdk/pull/3079
Part of: https://github.com/paritytech/polkadot-sdk/issues/3084

cc @paritytech/subxt-team

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: James Wilson <james@jsdw.me>
2024-02-28 09:43:58 +00:00
Liam Aharon 12ce4f7d04 Runtime Upgrade ref docs and Single Block Migration example pallet (#1554)
Closes https://github.com/paritytech/polkadot-sdk-docs/issues/55

- Changes 'current storage version' terminology to less ambiguous
'in-code storage version' (suggestion by @ggwpez)
- Adds a new example pallet `pallet-example-single-block-migrations`
- Adds a new reference doc to replace
https://docs.substrate.io/maintain/runtime-upgrades/ (temporarily living
in the pallet while we wait for developer hub PR to merge)
- Adds documentation for the `storage_alias` macro
- Improves `trait Hooks` docs 
- Improves `trait GetStorageVersion` docs
- Update the suggested patterns for using `VersionedMigration`, so that
version unchecked migrations are never exported
- Prevents accidental usage of version unchecked migrations in runtimes

https://github.com/paritytech/substrate/pull/14421#discussion_r1255467895
- Unversioned migration code is kept inside `mod version_unchecked`,
versioned code is kept in `pub mod versioned`
- It is necessary to use modules to limit visibility because the inner
migration must be `pub`. See
https://github.com/rust-lang/rust/issues/30905 and

https://internals.rust-lang.org/t/lang-team-minutes-private-in-public-rules/4504/40
for more.

### todo

- [x] move to reference docs to proper place within sdk-docs (now that
https://github.com/paritytech/polkadot-sdk/pull/2102 is merged)
- [x] prdoc

---------

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Juan <juangirini@gmail.com>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: command-bot <>
Co-authored-by: gupnik <nikhilgupta.iitk@gmail.com>
2024-02-28 07:32:02 +00:00
maksimryndin 7ec0b8741b Collator overseer builder unification (#3335)
resolve https://github.com/paritytech/polkadot-sdk/issues/3116

a follow-up on
https://github.com/paritytech/polkadot-sdk/pull/3061#pullrequestreview-1847530265:

- [x] reuse collator overseer builder for polkadot-node and collator
- [x] run zombienet test (0001-parachains-smoke-test.toml)
- [x] make wasm build errors more user-friendly for an easier problem
detection when using different toolchains in Rust

---------

Co-authored-by: ordian <write@reusable.software>
Co-authored-by: s0me0ne-unkn0wn <48632512+s0me0ne-unkn0wn@users.noreply.github.com>
2024-02-28 04:05:54 +00:00