Files
pezkuwi-fellows/print.html
T
2024-09-11 01:01:48 +00:00

9391 lines
803 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE HTML>
<html lang="en" class="polkadot" dir="ltr">
<head>
<!-- Book generated using mdBook -->
<meta charset="UTF-8">
<title>Polkadot Fellowship RFCs</title>
<meta name="robots" content="noindex">
<!-- Custom HTML head -->
<meta name="description" content="An online book of RFCs approved or proposed within the Polkadot Fellowship.">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#ffffff">
<link rel="icon" href="favicon.svg">
<link rel="shortcut icon" href="favicon.png">
<link rel="stylesheet" href="css/variables.css">
<link rel="stylesheet" href="css/general.css">
<link rel="stylesheet" href="css/chrome.css">
<link rel="stylesheet" href="css/print.css" media="print">
<!-- Fonts -->
<link rel="stylesheet" href="FontAwesome/css/font-awesome.css">
<link rel="stylesheet" href="fonts/fonts.css">
<!-- Highlight.js Stylesheets -->
<link rel="stylesheet" href="highlight.css">
<link rel="stylesheet" href="tomorrow-night.css">
<link rel="stylesheet" href="ayu-highlight.css">
<!-- Custom theme stylesheets -->
<link rel="stylesheet" href="theme/polkadot.css">
</head>
<body class="sidebar-visible no-js">
<div id="body-container">
<!-- Provide site root to javascript -->
<script>
var path_to_root = "";
var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "polkadot" : "polkadot";
</script>
<!-- Work around some values being stored in localStorage wrapped in quotes -->
<script>
try {
var theme = localStorage.getItem('mdbook-theme');
var sidebar = localStorage.getItem('mdbook-sidebar');
if (theme.startsWith('"') && theme.endsWith('"')) {
localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
}
if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
}
} catch (e) { }
</script>
<!-- Set the theme before any content is loaded, prevents flash -->
<script>
var theme;
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
if (theme === null || theme === undefined) { theme = default_theme; }
var html = document.querySelector('html');
html.classList.remove('polkadot')
html.classList.add(theme);
var body = document.querySelector('body');
body.classList.remove('no-js')
body.classList.add('js');
</script>
<input type="checkbox" id="sidebar-toggle-anchor" class="hidden">
<!-- Hide / unhide sidebar before it is displayed -->
<script>
var body = document.querySelector('body');
var sidebar = null;
var sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
if (document.body.clientWidth >= 1080) {
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
sidebar = sidebar || 'visible';
} else {
sidebar = 'hidden';
}
sidebar_toggle.checked = sidebar === 'visible';
body.classList.remove('sidebar-visible');
body.classList.add("sidebar-" + sidebar);
</script>
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
<div class="sidebar-scrollbox">
<ol class="chapter"><li class="chapter-item expanded affix "><a href="introduction.html">Introduction</a></li><li class="spacer"></li><li class="chapter-item expanded affix "><li class="part-title">Newly Proposed</li><li class="spacer"></li><li class="chapter-item expanded affix "><li class="part-title">Proposed</li><li class="chapter-item expanded "><a href="proposed/0004-remove-unnecessary-allocator-usage.html">RFC-0004: Remove the host-side runtime memory allocator</a></li><li class="chapter-item expanded "><a href="proposed/0006-dynamic-pricing-for-bulk-coretime-sales.html">RFC-0006: Dynamic Pricing for Bulk Coretime Sales</a></li><li class="chapter-item expanded "><a href="proposed/0009-improved-net-light-client-requests.html">RFC-0009: Improved light client requests networking protocol</a></li><li class="chapter-item expanded "><a href="proposed/0015-market-design-revisit.html">RFC-0015: Market Design Revisit</a></li><li class="chapter-item expanded "><a href="proposed/0034-xcm-absolute-location-account-derivation.html">RFC-34: XCM Absolute Location Account Derivation</a></li><li class="chapter-item expanded "><a href="proposed/0035-conviction-voting-delegation-modifications.html"> RFC-0035: Conviction Voting Delegation Modifications</a></li><li class="chapter-item expanded "><a href="proposed/0044-rent-based-registration.html">RFC-0044: Rent based registration model</a></li><li class="chapter-item expanded "><a href="proposed/0054-remove-heap-pages.html">RFC-0054: Remove the concept of "heap pages" from the client</a></li><li class="chapter-item expanded "><a href="proposed/0070-x-track-kusamanetwork.html">RFC-0070: X Track for @kusamanetwork</a></li><li class="chapter-item expanded "><a href="proposed/0073-referedum-deposit-track.html">RFC-0073: Decision Deposit Referendum Track</a></li><li class="chapter-item expanded "><a href="proposed/0074-stateful-multisig-pallet.html">RFC-0074: Stateful Multisig Pallet</a></li><li class="chapter-item expanded "><a href="proposed/0077-increase-max-length-of-identity-pgp-fingerprint-value.html">RFC-0077: Increase maximum length of identity PGP fingerprint values from 20 bytes</a></li><li class="chapter-item expanded "><a href="proposed/0088-broker-pallet-slashable-deposit-purchaser-reputation-reserved-cores.html">RFC-0088: Add slashable locked deposit, purchaser reputation, and reserved cores for on-chain identities to broker pallet</a></li><li class="chapter-item expanded "><a href="proposed/0089-flexible-inflation.html">RFC-0089: Flexible Inflation</a></li><li class="chapter-item expanded "><a href="proposed/00xx-secondary-marketplace-for-regions.html">RFC-0001: Secondary Market for Regions</a></li><li class="chapter-item expanded "><a href="proposed/00xx-smart-contracts-coretime-chain.html">RFC-0002: Smart Contracts on the Coretime Chain</a></li><li class="chapter-item expanded "><a href="proposed/0111-pure-proxy-replication.html">RFC-0111: Pure Proxy Replication</a></li><li class="chapter-item expanded "><a href="proposed/0112-compress-state-response-message-in-state-sync.html">RFC-0112: Compress the State Response Message in State Sync</a></li><li class="chapter-item expanded "><a href="proposed/0114-secp256r1-hostfunction.html">RFC-0114: Introduce secp256r1_ecdsa_verify_prehashed Host Function to verify NIST-P256 elliptic curve signatures</a></li><li class="chapter-item expanded "><a href="proposed/0117-unbrick-collective.html">RFC-0117: The Unbrick Collective</a></li><li class="chapter-item expanded "><a href="proposed/RFC-114 Adjust Tipper Track Confirmation Periods.html">RFC-114: Adjust Tipper Track Confirmation Periods</a></li><li class="spacer"></li><li class="chapter-item expanded affix "><li class="part-title">Approved</li><li class="chapter-item expanded "><a href="approved/0001-agile-coretime.html">RFC-1: Agile Coretime</a></li><li class="chapter-item expanded "><a href="approved/0005-coretime-interface.html">RFC-5: Coretime Interface</a></li><li class="chapter-item expanded "><a href="approved/0007-system-collator-selection.html">RFC-0007: System Collator Selection</a></li><li class="chapter-item expanded "><a href="approved/0008-parachain-bootnodes-dht.html">RFC-0008: Store parachain bootnodes in relay chain DHT</a></li><li class="chapter-item expanded "><a href="approved/0010-burn-coretime-revenue.html">RFC-0010: Burn Coretime Revenue</a></li><li class="chapter-item expanded "><a href="approved/0012-process-for-adding-new-collectives.html">RFC-0012: Process for Adding New System Collectives</a></li><li class="chapter-item expanded "><a href="approved/0013-prepare-blockbuilder-and-core-runtime-apis-for-mbms.html">RFC-0013: Prepare Core runtime API for MBMs</a></li><li class="chapter-item expanded "><a href="approved/0014-improve-locking-mechanism-for-parachains.html">RFC-0014: Improve locking mechanism for parachains</a></li><li class="chapter-item expanded "><a href="approved/0022-adopt-encointer-runtime.html">RFC-0022: Adopt Encointer Runtime</a></li><li class="chapter-item expanded "><a href="approved/0026-sassafras-consensus.html">RFC-0026: Sassafras Consensus Protocol</a></li><li class="chapter-item expanded "><a href="approved/0032-minimal-relay.html">RFC-0032: Minimal Relay</a></li><li class="chapter-item expanded "><a href="approved/0042-extrinsics-state-version.html">RFC-0042: Add System version that replaces StateVersion on RuntimeVersion</a></li><li class="chapter-item expanded "><a href="approved/0043-storage-proof-size-hostfunction.html">RFC-0043: Introduce storage_proof_size Host Function for Improved Parachain Block Utilization</a></li><li class="chapter-item expanded "><a href="approved/0045-nft-deposits-asset-hub.html">RFC-0045: Lowering NFT Deposits on Asset Hub</a></li><li class="chapter-item expanded "><a href="approved/0047-assignment-of-availability-chunks.html">RFC-0047: Assignment of availability chunks to validators</a></li><li class="chapter-item expanded "><a href="approved/0048-session-keys-runtime-api.html">RFC-0048: Generate ownership proof for SessionKeys</a></li><li class="chapter-item expanded "><a href="approved/0050-fellowship-salaries.html">RFC-0050: Fellowship Salaries</a></li><li class="chapter-item expanded "><a href="approved/0056-one-transaction-per-notification.html">RFC-0056: Enforce only one transaction per notification</a></li><li class="chapter-item expanded "><a href="approved/0059-nodes-capabilities-discovery.html">RFC-0059: Add a discovery mechanism for nodes based on their capabilities</a></li><li class="chapter-item expanded "><a href="approved/0078-merkleized-metadata.html">RFC-0078: Merkleized Metadata</a></li><li class="chapter-item expanded "><a href="approved/0084-general-transaction-extrinsic-format.html">RFC-0084: General transactions in extrinsic format</a></li><li class="chapter-item expanded "><a href="approved/0091-dht-record-creation-time.html">RFC-0091: DHT Authority discovery record creation time</a></li><li class="chapter-item expanded "><a href="approved/0097-unbonding_queue.html">RFC-0097: Unbonding Queue</a></li><li class="chapter-item expanded "><a href="approved/0099-transaction-extension-version.html">RFC-0099: Introduce a transaction extension version</a></li><li class="chapter-item expanded "><a href="approved/0100-xcm-multi-type-asset-transfer.html">RFC-0100: New XCM instruction: InitiateAssetsTransfer</a></li><li class="chapter-item expanded "><a href="approved/0101-xcm-transact-remove-max-weight-param.html">RFC-0101: XCM Transact remove require_weight_at_most parameter</a></li><li class="chapter-item expanded "><a href="approved/0103-introduce-core-index-commitment.html">RFC-0103: Introduce a CoreIndex commitment and a SessionIndex field in candidate receipts</a></li><li class="chapter-item expanded "><a href="approved/0105-xcm-improved-fee-mechanism.html">RFC-0105: XCM improved fee mechanism</a></li><li class="chapter-item expanded "><a href="approved/0107-xcm-execution-hints.html">RFC-0107: XCM Execution hints</a></li><li class="chapter-item expanded "><a href="approved/0108-xcm-remove-testnet-ids.html">RFC-0108: Remove XCM testnet NetworkIds</a></li><li class="spacer"></li><li class="chapter-item expanded affix "><li class="part-title">Stale</li><li class="chapter-item expanded "><a href="stale/0102-offchain-parachain-runtime-upgrades.html">RFC-0000: Feature Name Here</a></li><li class="chapter-item expanded "><a href="stale/0106-xcm-remove-fees-mode.html">RFC-0106: Remove XCM fees mode</a></li><li class="chapter-item expanded "><a href="stale/0109-xcm-descend-instead-of-clear-origin.html">RFC-0109: Descend XCM origin instead of clearing it where possible</a></li><li class="chapter-item expanded "><a href="stale/TODO-stale-nomination-reward-curve.html">RFC-TODO: Stale Nomination Reward Curve</a></li></ol>
</div>
<div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
</nav>
<!-- Track and set sidebar scroll position -->
<script>
var sidebarScrollbox = document.querySelector('#sidebar .sidebar-scrollbox');
sidebarScrollbox.addEventListener('click', function(e) {
if (e.target.tagName === 'A') {
sessionStorage.setItem('sidebar-scroll', sidebarScrollbox.scrollTop);
}
}, { passive: true });
var sidebarScrollTop = sessionStorage.getItem('sidebar-scroll');
sessionStorage.removeItem('sidebar-scroll');
if (sidebarScrollTop) {
// preserve sidebar scroll position when navigating via links within sidebar
sidebarScrollbox.scrollTop = sidebarScrollTop;
} else {
// scroll sidebar to current active section when navigating via "next/previous chapter" buttons
var activeSection = document.querySelector('#sidebar .active');
if (activeSection) {
activeSection.scrollIntoView({ block: 'center' });
}
}
</script>
<div id="page-wrapper" class="page-wrapper">
<div class="page">
<div id="menu-bar-hover-placeholder"></div>
<div id="menu-bar" class="menu-bar sticky">
<div class="left-buttons">
<label id="sidebar-toggle" class="icon-button" for="sidebar-toggle-anchor" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
<i class="fa fa-bars"></i>
</label>
<button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
<i class="fa fa-paint-brush"></i>
</button>
<ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
<li role="none"><button role="menuitem" class="theme" id="polkadot">Polkadot</button></li>
<li role="none"><button role="menuitem" class="theme" id="light">Light</button></li>
<li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
<li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
<li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
<li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
</ul>
<button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
<i class="fa fa-search"></i>
</button>
</div>
<h1 class="menu-title">Polkadot Fellowship RFCs</h1>
<div class="right-buttons">
<a href="print.html" title="Print this book" aria-label="Print this book">
<i id="print-button" class="fa fa-print"></i>
</a>
</div>
</div>
<div id="search-wrapper" class="hidden">
<form id="searchbar-outer" class="searchbar-outer">
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
</form>
<div id="searchresults-outer" class="searchresults-outer hidden">
<div id="searchresults-header" class="searchresults-header"></div>
<ul id="searchresults">
</ul>
</div>
</div>
<!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
<script>
document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
});
</script>
<div id="content" class="content">
<main>
<p><img width="30%" src="images/Polkadot_Logo_Horizontal_Pink_Black.svg" alt="Polkadot logo" /></p>
<h1 id="introduction"><a class="header" href="#introduction">Introduction</a></h1>
<p>This book contains the Polkadot Fellowship Requests for Comments (RFCs)
detailing proposed changes to the technical implementation of the Polkadot network.</p>
<p><img width="2%" src="images/github-mark.svg" alt="GitHub logo" />&nbsp;<a href="https://github.com/polkadot-fellows/RFCs/">polkadot-fellows/RFCs</a></p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/pull/4">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="proposed/0004-remove-unnecessary-allocator-usage.html#rfc-0004-remove-the-host-side-runtime-memory-allocator">RFC-0004: Remove the host-side runtime memory allocator</a>
<ul>
<li><a href="proposed/0004-remove-unnecessary-allocator-usage.html#summary">Summary</a></li>
<li><a href="proposed/0004-remove-unnecessary-allocator-usage.html#motivation">Motivation</a></li>
<li><a href="proposed/0004-remove-unnecessary-allocator-usage.html#stakeholders">Stakeholders</a></li>
<li><a href="proposed/0004-remove-unnecessary-allocator-usage.html#explanation">Explanation</a>
<ul>
<li><a href="proposed/0004-remove-unnecessary-allocator-usage.html#new-host-functions">New host functions</a></li>
<li><a href="proposed/0004-remove-unnecessary-allocator-usage.html#other-changes">Other changes</a></li>
</ul>
</li>
<li><a href="proposed/0004-remove-unnecessary-allocator-usage.html#drawbacks">Drawbacks</a></li>
<li><a href="proposed/0004-remove-unnecessary-allocator-usage.html#prior-art">Prior Art</a></li>
<li><a href="proposed/0004-remove-unnecessary-allocator-usage.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="proposed/0004-remove-unnecessary-allocator-usage.html#future-possibilities">Future Possibilities</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0004-remove-the-host-side-runtime-memory-allocator"><a class="header" href="#rfc-0004-remove-the-host-side-runtime-memory-allocator">RFC-0004: Remove the host-side runtime memory allocator</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>2023-07-04</td></tr>
<tr><td><strong>Description</strong></td><td>Update the runtime-host interface to no longer make use of a host-side allocator</td></tr>
<tr><td><strong>Authors</strong></td><td>Pierre Krieger</td></tr>
</tbody></table>
</div>
<h2 id="summary"><a class="header" href="#summary">Summary</a></h2>
<p>Update the runtime-host interface to no longer make use of a host-side allocator.</p>
<h2 id="motivation"><a class="header" href="#motivation">Motivation</a></h2>
<p>The heap allocation of the runtime is currently controlled by the host using a memory allocator on the host side.</p>
<p>The API of many host functions consists in allocating a buffer. For example, when calling <code>ext_hashing_twox_256_version_1</code>, the host allocates a 32 bytes buffer using the host allocator, and returns a pointer to this buffer to the runtime. The runtime later has to call <code>ext_allocator_free_version_1</code> on this pointer in order to free the buffer.</p>
<p>Even though no benchmark has been done, it is pretty obvious that this design is very inefficient. To continue with the example of <code>ext_hashing_twox_256_version_1</code>, it would be more efficient to instead write the output hash to a buffer that was allocated by the runtime on its stack and passed by pointer to the function. Allocating a buffer on the stack in the worst case scenario simply consists in decreasing a number, and in the best case scenario is free. Doing so would save many Wasm memory reads and writes by the allocator, and would save a function call to <code>ext_allocator_free_version_1</code>.</p>
<p>Furthermore, the existence of the host-side allocator has become questionable over time. It is implemented in a very naive way, and for determinism and backwards compatibility reasons it needs to be implemented exactly identically in every client implementation. Runtimes make substantial use of heap memory allocations, and each allocation needs to go twice through the runtime &lt;-&gt; host boundary (once for allocating and once for freeing). Moving the allocator to the runtime side, while it would increase the size of the runtime, would be a good idea. But before the host-side allocator can be deprecated, all the host functions that make use of it need to be updated to not use it.</p>
<h2 id="stakeholders"><a class="header" href="#stakeholders">Stakeholders</a></h2>
<p>No attempt was made at convincing stakeholders.</p>
<h2 id="explanation"><a class="header" href="#explanation">Explanation</a></h2>
<h3 id="new-host-functions"><a class="header" href="#new-host-functions">New host functions</a></h3>
<p>This section contains a list of new host functions to introduce.</p>
<pre><code class="language-wat">(func $ext_storage_read_version_2
(param $key i64) (param $value_out i64) (param $offset i32) (result i64))
(func $ext_default_child_storage_read_version_2
(param $child_storage_key i64) (param $key i64) (param $value_out i64)
(param $offset i32) (result i64))
</code></pre>
<p>The signature and behaviour of <code>ext_storage_read_version_2</code> and <code>ext_default_child_storage_read_version_2</code> is identical to their version 1 counterparts, but the return value has a different meaning.
The new functions directly return the number of bytes that were written in the <code>value_out</code> buffer. If the entry doesn't exist, a value of <code>-1</code> is returned. Given that the host must never write more bytes than the size of the buffer in <code>value_out</code>, and that the size of this buffer is expressed as a 32 bits number, a 64bits value of <code>-1</code> is not ambiguous.</p>
<p>The runtime execution stops with an error if <code>value_out</code> is outside of the range of the memory of the virtual machine, even if the size of the buffer is 0 or if the amount of data to write would be 0 bytes.</p>
<pre><code class="language-wat">(func $ext_storage_next_key_version_2
(param $key i64) (param $out i64) (return i32))
(func $ext_default_child_storage_next_key_version_2
(param $child_storage_key i64) (param $key i64) (param $out i64) (return i32))
</code></pre>
<p>The behaviour of these functions is identical to their version 1 counterparts.
Instead of allocating a buffer, writing the next key to it, and returning a pointer to it, the new version of these functions accepts an <code>out</code> parameter containing <a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">a pointer-size</a> to the memory location where the host writes the output. The runtime execution stops with an error if <code>out</code> is outside of the range of the memory of the virtual machine, even if the function wouldn't write anything to <code>out</code>.
These functions return the size, in bytes, of the next key, or <code>0</code> if there is no next key. If the size of the next key is larger than the buffer in <code>out</code>, the bytes of the key that fit the buffer are written to <code>out</code> and any extra byte that doesn't fit is discarded.</p>
<p>Some notes:</p>
<ul>
<li>It is never possible for the next key to be an empty buffer, because an empty key has no preceding key. For this reason, a return value of <code>0</code> can unambiguously be used to indicate the lack of next key.</li>
<li>The <code>ext_storage_next_key_version_2</code> and <code>ext_default_child_storage_next_key_version_2</code> are typically used in order to enumerate keys that starts with a certain prefix. Given that storage keys are constructed by concatenating hashes, the runtime is expected to know the size of the next key and can allocate a buffer that can fit said key. When the next key doesn't belong to the desired prefix, it might not fit the buffer, but given that the start of the key is written to the buffer anyway this can be detected in order to avoid calling the function a second time with a larger buffer.</li>
</ul>
<pre><code class="language-wat">(func $ext_hashing_keccak_256_version_2
(param $data i64) (param $out i32))
(func $ext_hashing_keccak_512_version_2
(param $data i64) (param $out i32))
(func $ext_hashing_sha2_256_version_2
(param $data i64) (param $out i32))
(func $ext_hashing_blake2_128_version_2
(param $data i64) (param $out i32))
(func $ext_hashing_blake2_256_version_2
(param $data i64) (param $out i32))
(func $ext_hashing_twox_64_version_2
(param $data i64) (param $out i32))
(func $ext_hashing_twox_128_version_2
(param $data i64) (param $out i32))
(func $ext_hashing_twox_256_version_2
(param $data i64) (param $out i32))
(func $ext_trie_blake2_256_root_version_3
(param $data i64) (param $version i32) (param $out i32))
(func $ext_trie_blake2_256_ordered_root_version_3
(param $data i64) (param $version i32) (param $out i32))
(func $ext_trie_keccak_256_root_version_3
(param $data i64) (param $version i32) (param $out i32))
(func $ext_trie_keccak_256_ordered_root_version_3
(param $data i64) (param $version i32) (param $out i32))
(func $ext_default_child_storage_root_version_3
(param $child_storage_key i64) (param $out i32))
(func $ext_crypto_ed25519_generate_version_2
(param $key_type_id i32) (param $seed i64) (param $out i32))
(func $ext_crypto_sr25519_generate_version_2
(param $key_type_id i32) (param $seed i64) (param $out i32) (return i32))
(func $ext_crypto_ecdsa_generate_version_2
(param $key_type_id i32) (param $seed i64) (param $out i32) (return i32))
</code></pre>
<p>The behaviour of these functions is identical to their version 1 or version 2 counterparts. Instead of allocating a buffer, writing the output to it, and returning a pointer to it, the new version of these functions accepts an <code>out</code> parameter containing the memory location where the host writes the output. The output is always of a size known at compilation time. The runtime execution stops with an error if <code>out</code> is outside of the range of the memory of the virtual machine.</p>
<pre><code class="language-wat">(func $ext_default_child_storage_root_version_3
(param $child_storage_key i64) (param $out i32))
(func $ext_storage_root_version_3
(param $out i32))
</code></pre>
<p>The behaviour of these functions is identical to their version 1 and version 2 counterparts. Instead of allocating a buffer, writing the output to it, and returning a pointer to it, the new versions of these functions accepts an <code>out</code> parameter containing the memory location where the host writes the output. The output is always of a size known at compilation time. The runtime execution stops with an error if <code>out</code> is outside of the range of the memory of the virtual machine.</p>
<p>I have taken the liberty to take the version 1 of these functions as a base rather than the version 2, as a PPP deprecating the version 2 of these functions has previously been accepted: <a href="https://github.com/w3f/PPPs/pull/6">https://github.com/w3f/PPPs/pull/6</a>.</p>
<pre><code class="language-wat">(func $ext_storage_clear_prefix_version_3
(param $prefix i64) (param $limit i64) (param $removed_count_out i32)
(return i32))
(func $ext_default_child_storage_clear_prefix_version_3
(param $child_storage_key i64) (param $prefix i64)
(param $limit i64) (param $removed_count_out i32) (return i32))
(func $ext_default_child_storage_kill_version_4
(param $child_storage_key i64) (param $limit i64)
(param $removed_count_out i32) (return i32))
</code></pre>
<p>The behaviour of these functions is identical to their version 2 and 3 counterparts. Instead of allocating a buffer, writing the output to it, and returning a pointer to it, the version 3 and 4 of these functions accepts a <code>removed_count_out</code> parameter containing the memory location to a 8 bytes buffer where the host writes the number of keys that were removed in little endian. The runtime execution stops with an error if <code>removed_count_out</code> is outside of the range of the memory of the virtual machine. The functions return 1 to indicate that there are keys remaining, and 0 to indicate that all keys have been removed.</p>
<p>Note that there is an alternative proposal to add new host functions with the same names: <a href="https://github.com/w3f/PPPs/pull/7">https://github.com/w3f/PPPs/pull/7</a>. This alternative doesn't conflict with this one except for the version number. One proposal or the other will have to use versions 4 and 5 rather than 3 and 4.</p>
<pre><code class="language-wat">(func $ext_crypto_ed25519_sign_version_2
(param $key_type_id i32) (param $key i32) (param $msg i64) (param $out i32) (return i32))
(func $ext_crypto_sr25519_sign_version_2
(param $key_type_id i32) (param $key i32) (param $msg i64) (param $out i32) (return i32))
func $ext_crypto_ecdsa_sign_version_2
(param $key_type_id i32) (param $key i32) (param $msg i64) (param $out i32) (return i32))
(func $ext_crypto_ecdsa_sign_prehashed_version_2
(param $key_type_id i32) (param $key i32) (param $msg i64) (param $out i32) (return i64))
</code></pre>
<p>The behaviour of these functions is identical to their version 1 counterparts. The new versions of these functions accept an <code>out</code> parameter containing the memory location where the host writes the signature. The runtime execution stops with an error if <code>out</code> is outside of the range of the memory of the virtual machine, even if the function wouldn't write anything to <code>out</code>. The signatures are always of a size known at compilation time. On success, these functions return <code>0</code>. If the public key can't be found in the keystore, these functions return <code>1</code> and do not write anything to <code>out</code>.</p>
<p>Note that the return value is 0 on success and 1 on failure, while the previous version of these functions write 1 on success (as it represents a SCALE-encoded <code>Some</code>) and 0 on failure (as it represents a SCALE-encoded <code>None</code>). Returning 0 on success and non-zero on failure is consistent with common practices in the C programming language and is less surprising than the opposite.</p>
<pre><code class="language-wat">(func $ext_crypto_secp256k1_ecdsa_recover_version_3
(param $sig i32) (param $msg i32) (param $out i32) (return i64))
(func $ext_crypto_secp256k1_ecdsa_recover_compressed_version_3
(param $sig i32) (param $msg i32) (param $out i32) (return i64))
</code></pre>
<p>The behaviour of these functions is identical to their version 2 counterparts. The new versions of these functions accept an <code>out</code> parameter containing the memory location where the host writes the signature. The runtime execution stops with an error if <code>out</code> is outside of the range of the memory of the virtual machine, even if the function wouldn't write anything to <code>out</code>. The signatures are always of a size known at compilation time. On success, these functions return <code>0</code>. On failure, these functions return a non-zero value and do not write anything to <code>out</code>.</p>
<p>The non-zero value written on failure is:</p>
<ul>
<li>1: incorrect value of R or S</li>
<li>2: incorrect value of V</li>
<li>3: invalid signature</li>
</ul>
<p>These values are equal to the values returned on error by the version 2 (see <a href="https://spec.polkadot.network/chap-host-api#defn-ecdsa-verify-error">https://spec.polkadot.network/chap-host-api#defn-ecdsa-verify-error</a>), but incremented by 1 in order to reserve 0 for success.</p>
<pre><code class="language-wat">(func $ext_crypto_ed25519_num_public_keys_version_1
(param $key_type_id i32) (return i32))
(func $ext_crypto_ed25519_public_key_version_2
(param $key_type_id i32) (param $key_index i32) (param $out i32))
(func $ext_crypto_sr25519_num_public_keys_version_1
(param $key_type_id i32) (return i32))
(func $ext_crypto_sr25519_public_key_version_2
(param $key_type_id i32) (param $key_index i32) (param $out i32))
(func $ext_crypto_ecdsa_num_public_keys_version_1
(param $key_type_id i32) (return i32))
(func $ext_crypto_ecdsa_public_key_version_2
(param $key_type_id i32) (param $key_index i32) (param $out i32))
</code></pre>
<p>The functions superceded the <code>ext_crypto_ed25519_public_key_version_1</code>, <code>ext_crypto_sr25519_public_key_version_1</code>, and <code>ext_crypto_ecdsa_public_key_version_1</code> host functions.</p>
<p>Instead of calling <code>ext_crypto_ed25519_public_key_version_1</code> in order to obtain the list of all keys at once, the runtime should instead call <code>ext_crypto_ed25519_num_public_keys_version_1</code> in order to obtain the number of public keys available, then <code>ext_crypto_ed25519_public_key_version_2</code> repeatedly.
The <code>ext_crypto_ed25519_public_key_version_2</code> function writes the public key of the given <code>key_index</code> to the memory location designated by <code>out</code>. The <code>key_index</code> must be between 0 (included) and <code>n</code> (excluded), where <code>n</code> is the value returned by <code>ext_crypto_ed25519_num_public_keys_version_1</code>. Execution must trap if <code>n</code> is out of range.</p>
<p>The same explanations apply for <code>ext_crypto_sr25519_public_key_version_1</code> and <code>ext_crypto_ecdsa_public_key_version_1</code>.</p>
<p>Host implementers should be aware that the list of public keys (including their ordering) must not change while the runtime is running. This is most likely done by copying the list of all available keys either at the start of the execution or the first time the list is accessed.</p>
<pre><code class="language-wat">(func $ext_offchain_http_request_start_version_2
(param $method i64) (param $uri i64) (param $meta i64) (result i32))
</code></pre>
<p>The behaviour of this function is identical to its version 1 counterpart. Instead of allocating a buffer, writing the request identifier in it, and returning a pointer to it, the version 2 of this function simply returns the newly-assigned identifier to the HTTP request. On failure, this function returns <code>-1</code>. An identifier of <code>-1</code> is invalid and is reserved to indicate failure.</p>
<pre><code class="language-wat">(func $ext_offchain_http_request_write_body_version_2
(param $method i64) (param $uri i64) (param $meta i64) (result i32))
(func $ext_offchain_http_response_read_body_version_2
(param $request_id i32) (param $buffer i64) (param $deadline i64) (result i64))
</code></pre>
<p>The behaviour of these functions is identical to their version 1 counterpart. Instead of allocating a buffer, writing two bytes in it, and returning a pointer to it, the new version of these functions simply indicates what happened:</p>
<ul>
<li>For <code>ext_offchain_http_request_write_body_version_2</code>, 0 on success.</li>
<li>For <code>ext_offchain_http_response_read_body_version_2</code>, 0 or a non-zero number of bytes on success.</li>
<li>-1 if the deadline was reached.</li>
<li>-2 if there was an I/O error while processing the request.</li>
<li>-3 if the identifier of the request is invalid.</li>
</ul>
<p>These values are equal to the values returned on error by the version 1 (see <a href="https://spec.polkadot.network/chap-host-api#defn-http-error">https://spec.polkadot.network/chap-host-api#defn-http-error</a>), but tweaked in order to reserve positive numbers for success.</p>
<p>When it comes to <code>ext_offchain_http_response_read_body_version_2</code>, the host implementers must not read too much data at once in order to not create ambiguity in the returned value. Given that the size of the <code>buffer</code> is always inferior or equal to 4 GiB, this is not a problem.</p>
<pre><code class="language-wat">(func $ext_offchain_http_response_wait_version_2
(param $ids i64) (param $deadline i64) (param $out i32))
</code></pre>
<p>The behaviour of this function is identical to its version 1 counterpart. Instead of allocating a buffer, writing the output to it, and returning a pointer to it, the new version of this function accepts an <code>out</code> parameter containing the memory location where the host writes the output. The runtime execution stops with an error if <code>out</code> is outside of the range of the memory of the virtual machine.</p>
<p>The encoding of the response code is also modified compared to its version 1 counterpart and each response code now encodes to 4 little endian bytes as described below:</p>
<ul>
<li>100-999: the request has finished with the given HTTP status code.</li>
<li>-1 if the deadline was reached.</li>
<li>-2 if there was an I/O error while processing the request.</li>
<li>-3 if the identifier of the request is invalid.</li>
</ul>
<p>The buffer passed to <code>out</code> must always have a size of <code>4 * n</code> where <code>n</code> is the number of elements in the <code>ids</code>.</p>
<pre><code class="language-wat">(func $ext_offchain_http_response_header_name_version_1
(param $request_id i32) (param $header_index i32) (param $out i64) (result i64))
(func $ext_offchain_http_response_header_value_version_1
(param $request_id i32) (param $header_index i32) (param $out i64) (result i64))
</code></pre>
<p>These functions supercede the <code>ext_offchain_http_response_headers_version_1</code> host function.</p>
<p>Contrary to <code>ext_offchain_http_response_headers_version_1</code>, only one header indicated by <code>header_index</code> can be read at a time. Instead of calling <code>ext_offchain_http_response_headers_version_1</code> once, the runtime should call <code>ext_offchain_http_response_header_name_version_1</code> and <code>ext_offchain_http_response_header_value_version_1</code> multiple times with an increasing <code>header_index</code>, until a value of <code>-1</code> is returned.</p>
<p>These functions accept an <code>out</code> parameter containing <a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">a pointer-size</a> to the memory location where the header name or value should be written. The runtime execution stops with an error if <code>out</code> is outside of the range of the memory of the virtual machine, even if the function wouldn't write anything to <code>out</code>.</p>
<p>These functions return the size, in bytes, of the header name or header value. If request doesn't exist or is in an invalid state (as documented for <code>ext_offchain_http_response_headers_version_1</code>) or the <code>header_index</code> is out of range, a value of <code>-1</code> is returned. Given that the host must never write more bytes than the size of the buffer in <code>out</code>, and that the size of this buffer is expressed as a 32 bits number, a 64bits value of <code>-1</code> is not ambiguous.</p>
<p>If the buffer in <code>out</code> is too small to fit the entire header name of value, only the bytes that fit are written and the rest are discarded.</p>
<pre><code class="language-wat">(func $ext_offchain_submit_transaction_version_2
(param $data i64) (return i32))
(func $ext_offchain_http_request_add_header_version_2
(param $request_id i32) (param $name i64) (param $value i64) (result i32))
</code></pre>
<p>Instead of allocating a buffer, writing <code>1</code> or <code>0</code> in it, and returning a pointer to it, the version 2 of these functions return <code>0</code> or <code>1</code>, where <code>0</code> indicates success and <code>1</code> indicates failure. The runtime must interpret any non-<code>0</code> value as failure, but the client must always return <code>1</code> in case of failure.</p>
<pre><code class="language-wat">(func $ext_offchain_local_storage_read_version_1
(param $kind i32) (param $key i64) (param $value_out i64) (param $offset i32) (result i64))
</code></pre>
<p>This function supercedes the <code>ext_offchain_local_storage_get_version_1</code> host function, and uses an API and logic similar to <code>ext_storage_read_version_2</code>.</p>
<p>It reads the offchain local storage key indicated by <code>kind</code> and <code>key</code> starting at the byte indicated by <code>offset</code>, and writes the value to the <a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">pointer-size</a> indicated by <code>value_out</code>.</p>
<p>The function returns the number of bytes that were written in the <code>value_out</code> buffer. If the entry doesn't exist, a value of <code>-1</code> is returned. Given that the host must never write more bytes than the size of the buffer in <code>value_out</code>, and that the size of this buffer is expressed as a 32 bits number, a 64bits value of <code>-1</code> is not ambiguous.</p>
<p>The runtime execution stops with an error if <code>value_out</code> is outside of the range of the memory of the virtual machine, even if the size of the buffer is 0 or if the amount of data to write would be 0 bytes.</p>
<pre><code class="language-wat">(func $ext_offchain_network_peer_id_version_1
(param $out i64))
</code></pre>
<p>This function writes <a href="https://spec.polkadot.network/chap-networking#id-node-identities">the <code>PeerId</code> of the local node</a> to the memory location indicated by <code>out</code>. A <code>PeerId</code> is always 38 bytes long.
The runtime execution stops with an error if <code>out</code> is outside of the range of the memory of the virtual machine.</p>
<pre><code class="language-wat">(func $ext_input_size_version_1
(return i64))
(func $ext_input_read_version_1
(param $offset i64) (param $out i64))
</code></pre>
<p>When a runtime function is called, the host uses the allocator to allocate memory within the runtime where to write some input data. These two new host functions provide an alternative way to access the input that doesn't make use of the allocator.</p>
<p>The <code>ext_input_size_version_1</code> host function returns the size in bytes of the input data.</p>
<p>The <code>ext_input_read_version_1</code> host function copies some data from the input data to the memory of the runtime. The <code>offset</code> parameter indicates the offset within the input data where to start copying, and must be inferior or equal to the value returned by <code>ext_input_size_version_1</code>. The <code>out</code> parameter is <a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">a pointer-size</a> containing the buffer where to write to.
The runtime execution stops with an error if <code>offset</code> is strictly superior to the size of the input data, or if <code>out</code> is outside of the range of the memory of the virtual machine, even if the amount of data to copy would be 0 bytes.</p>
<h3 id="other-changes"><a class="header" href="#other-changes">Other changes</a></h3>
<p>In addition to the new host functions, this RFC proposes two changes to the runtime-host interface:</p>
<ul>
<li>The following function signature is now also accepted for runtime entry points: <code>(func (result i64))</code>.</li>
<li>Runtimes no longer need to expose a constant named <code>__heap_base</code>.</li>
</ul>
<p>All the host functions that are being superceded by new host functions are now considered deprecated and should no longer be used.
The following other host functions are similarly also considered deprecated:</p>
<ul>
<li><code>ext_storage_get_version_1</code></li>
<li><code>ext_default_child_storage_get_version_1</code></li>
<li><code>ext_allocator_malloc_version_1</code></li>
<li><code>ext_allocator_free_version_1</code></li>
<li><code>ext_offchain_network_state_version_1</code></li>
</ul>
<h2 id="drawbacks"><a class="header" href="#drawbacks">Drawbacks</a></h2>
<p>This RFC might be difficult to implement in Substrate due to the internal code design. It is not clear to the author of this RFC how difficult it would be.</p>
<h2 id="prior-art"><a class="header" href="#prior-art">Prior Art</a></h2>
<p>The API of these new functions was heavily inspired by API used by the C programming language.</p>
<h2 id="unresolved-questions"><a class="header" href="#unresolved-questions">Unresolved Questions</a></h2>
<p>The changes in this RFC would need to be benchmarked. This involves implementing the RFC and measuring the speed difference.</p>
<p>It is expected that most host functions are faster or equal speed to their deprecated counterparts, with the following exceptions:</p>
<ul>
<li>
<p><code>ext_input_size_version_1</code>/<code>ext_input_read_version_1</code> is inherently slower than obtaining a buffer with the entire data due to the two extra function calls and the extra copying. However, given that this only happens once per runtime call, the cost is expected to be negligible.</p>
</li>
<li>
<p>The <code>ext_crypto_*_public_keys</code>, <code>ext_offchain_network_state</code>, and <code>ext_offchain_http_*</code> host functions are likely slightly slower than their deprecated counterparts, but given that they are used only in offchain workers this is acceptable.</p>
</li>
<li>
<p>It is unclear how replacing <code>ext_storage_get</code> with <code>ext_storage_read</code> and <code>ext_default_child_storage_get</code> with <code>ext_default_child_storage_read</code> will impact performances.</p>
</li>
<li>
<p>It is unclear how the changes to <code>ext_storage_next_key</code> and <code>ext_default_child_storage_next_key</code> will impact performances.</p>
</li>
</ul>
<h2 id="future-possibilities"><a class="header" href="#future-possibilities">Future Possibilities</a></h2>
<p>After this RFC, we can remove from the source code of the host the allocator altogether in a future version, by removing support for all the deprecated host functions.
This would remove the possibility to synchronize older blocks, which is probably controversial and requires a some preparations that are out of scope of this RFC.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/pull/6">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="proposed/0006-dynamic-pricing-for-bulk-coretime-sales.html#rfc-0006-dynamic-pricing-for-bulk-coretime-sales">RFC-0006: Dynamic Pricing for Bulk Coretime Sales</a>
<ul>
<li><a href="proposed/0006-dynamic-pricing-for-bulk-coretime-sales.html#summary">Summary</a></li>
<li><a href="proposed/0006-dynamic-pricing-for-bulk-coretime-sales.html#motivation">Motivation</a>
<ul>
<li><a href="proposed/0006-dynamic-pricing-for-bulk-coretime-sales.html#requirements">Requirements</a></li>
</ul>
</li>
<li><a href="proposed/0006-dynamic-pricing-for-bulk-coretime-sales.html#stakeholders">Stakeholders</a></li>
<li><a href="proposed/0006-dynamic-pricing-for-bulk-coretime-sales.html#explanation">Explanation</a>
<ul>
<li><a href="proposed/0006-dynamic-pricing-for-bulk-coretime-sales.html#overview">Overview</a></li>
<li><a href="proposed/0006-dynamic-pricing-for-bulk-coretime-sales.html#parameters">Parameters</a></li>
<li><a href="proposed/0006-dynamic-pricing-for-bulk-coretime-sales.html#function">Function</a></li>
<li><a href="proposed/0006-dynamic-pricing-for-bulk-coretime-sales.html#pseudo-code">Pseudo-code</a></li>
<li><a href="proposed/0006-dynamic-pricing-for-bulk-coretime-sales.html#properties-of-the-curve">Properties of the Curve</a></li>
<li><a href="proposed/0006-dynamic-pricing-for-bulk-coretime-sales.html#example-configurations">Example Configurations</a></li>
</ul>
</li>
<li><a href="proposed/0006-dynamic-pricing-for-bulk-coretime-sales.html#drawbacks">Drawbacks</a></li>
<li><a href="proposed/0006-dynamic-pricing-for-bulk-coretime-sales.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="proposed/0006-dynamic-pricing-for-bulk-coretime-sales.html#future-possibilities">Future Possibilities</a></li>
<li><a href="proposed/0006-dynamic-pricing-for-bulk-coretime-sales.html#references">References</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0006-dynamic-pricing-for-bulk-coretime-sales"><a class="header" href="#rfc-0006-dynamic-pricing-for-bulk-coretime-sales">RFC-0006: Dynamic Pricing for Bulk Coretime Sales</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>July 09, 2023</td></tr>
<tr><td><strong>Description</strong></td><td>A dynamic pricing model to adapt the regular price for bulk coretime sales</td></tr>
<tr><td><strong>Authors</strong></td><td>Tommi Enenkel (Alice und Bob)</td></tr>
<tr><td><strong>License</strong></td><td>MIT</td></tr>
</tbody></table>
</div>
<h2 id="summary-1"><a class="header" href="#summary-1">Summary</a></h2>
<p>This RFC proposes a dynamic pricing model for the sale of Bulk Coretime on the Polkadot UC. The proposed model updates the regular price of cores for each sale period, by taking into account the number of cores sold in the previous sale, as well as a limit of cores and a target number of cores sold. It ensures a minimum price and limits price growth to a maximum price increase factor, while also giving govenance control over the steepness of the price change curve. It allows governance to address challenges arising from changing market conditions and should offer predictable and controlled price adjustments.</p>
<p>Accompanying visualizations are provided at [1].</p>
<h2 id="motivation-1"><a class="header" href="#motivation-1">Motivation</a></h2>
<p>RFC-1 proposes periodic Bulk Coretime Sales as a mechanism to sell continouos regions of blockspace (suggested to be 4 weeks in length). A number of Blockspace Regions (compare RFC-1 &amp; RFC-3) are provided for sale to the Broker-Chain each period and shall be sold in a way that provides value-capture for the Polkadot network. The exact pricing mechanism is out of scope for RFC-1 and shall be provided by this RFC. </p>
<p>A dynamic pricing model is needed. A limited number of Regions are offered for sale each period. The model needs to find the price for a period based on supply and demand of the previous period.</p>
<p>The model shall give Coretime consumers predictability about upcoming price developments and confidence that Polkadot governance can adapt the pricing model to changing market conditions.</p>
<h3 id="requirements"><a class="header" href="#requirements">Requirements</a></h3>
<ol>
<li>The solution SHOULD provide a dynamic pricing model that increases price with growing demand and reduces price with shrinking demand.</li>
<li>The solution SHOULD have a slow rate of change for price if the number of Regions sold is close to a given sales target and increase the rate of change as the number of sales deviates from the target.</li>
<li>The solution SHOULD provide the possibility to always have a minimum price per Region.</li>
<li>The solution SHOULD provide a maximum factor of price increase should the limit of Regions sold per period be reached.</li>
<li>The solution should allow governance to control the steepness of the price function</li>
</ol>
<h2 id="stakeholders-1"><a class="header" href="#stakeholders-1">Stakeholders</a></h2>
<p>The primary stakeholders of this RFC are:</p>
<ul>
<li>Protocol researchers and evelopers</li>
<li>Polkadot DOT token holders</li>
<li>Polkadot parachains teams</li>
<li>Brokers involved in the trade of Bulk Coretime</li>
</ul>
<h2 id="explanation-1"><a class="header" href="#explanation-1">Explanation</a></h2>
<h3 id="overview"><a class="header" href="#overview">Overview</a></h3>
<p>The dynamic pricing model sets the new price based on supply and demand in the previous period. The model is a function of the number of Regions sold, piecewise-defined by two power functions.</p>
<ul>
<li>The left side ranges from 0 to the target. It represents situations where demand was lower than the target.</li>
<li>The right side ranges from the target to limit. It represents situations where demand was higher than the target.</li>
</ul>
<p>The curve of the function forms a plateau around the target and then falls off to the left and rises up to the right. The shape of the plateau can be controlled via a scale factor for the left side and right side of the function respectively.</p>
<h3 id="parameters"><a class="header" href="#parameters">Parameters</a></h3>
<p>From here on, we will also refer to Regions sold as 'cores' to stay congruent with RFC-1.</p>
<div class="table-wrapper"><table><thead><tr><th>Name</th><th>Suggested Value</th><th>Description</th><th>Constraints</th></tr></thead><tbody>
<tr><td><code>BULK_LIMIT</code></td><td>45</td><td>The maximum number of cores being sold</td><td><code>0 &lt; BULK_LIMIT</code></td></tr>
<tr><td><code>BULK_TARGET</code></td><td>30</td><td>The target number of cores being sold</td><td><code>0 &lt; BULK_TARGET &lt;= BULK_LIMIT</code></td></tr>
<tr><td><code>MIN_PRICE</code></td><td>1</td><td>The minimum price a core will always cost.</td><td><code>0 &lt; MIN_PRICE</code></td></tr>
<tr><td><code>MAX_PRICE_INCREASE_FACTOR</code></td><td>2</td><td>The maximum factor by which the price can change.</td><td><code>1 &lt; MAX_PRICE_INCREASE_FACTOR</code></td></tr>
<tr><td><code>SCALE_DOWN</code></td><td>2</td><td>The steepness of the left side of the function.</td><td><code>0 &lt; SCALE_DOWN</code></td></tr>
<tr><td><code>SCALE_UP</code></td><td>2</td><td>The steepness of the right side of the function.</td><td><code>0 &lt; SCALE_UP</code></td></tr>
</tbody></table>
</div>
<h3 id="function"><a class="header" href="#function">Function</a></h3>
<pre><code class="language-math">P(n) = \begin{cases}
(P_{\text{old}} - P_{\text{min}}) \left(1 - \left(\frac{T - n}{T}\right)^d\right) + P_{\text{min}} &amp; \text{if } n \leq T \\
((F - 1) \cdot P_{\text{old}} \cdot \left(\frac{n - T}{L - T}\right)^u) + P_{\text{old}} &amp; \text{if } n &gt; T
\end{cases}
</code></pre>
<ul>
<li>$P_{\text{old}}$ is the <code>old_price</code>, the price of a core in the previous period.</li>
<li>$P_{\text{min}}$ is the <code>MIN_PRICE</code>, the minimum price a core will always cost.</li>
<li>$F$ is the <code>MAX_PRICE_INCREASE_FACTOR</code>, the factor by which the price maximally can change from one period to another.</li>
<li>$d$ is the <code>SCALE_DOWN</code>, the steepness of the left side of the function.</li>
<li>$u$ is the <code>SCALE_UP</code>, the steepness of the right side of the function.</li>
<li>$T$ is the <code>BULK_TARGET</code>, the target number of cores being sold.</li>
<li>$L$ is the <code>BULK_LIMIT</code>, the maximum number of cores being sold.</li>
<li>$n$ is <code>cores_sold</code>, the number of cores being sold.</li>
</ul>
<h4 id="left-side"><a class="header" href="#left-side">Left side</a></h4>
<p>The left side is a power function that describes an increasing concave downward curvature that approaches <code>old_price</code>. We realize this by using the form $y = a(1 - x^d)$, usually used as a downward sloping curve, but in our case flipped horizontally by letting the argument $x = \frac{T-n}{T}$ decrease with $n$, doubly inversing the curve.</p>
<p>This approach is chosen over a decaying exponential because it let's us a better control the shape of the plateau, especially allowing us to get a straight line by setting <code>SCALE_DOWN</code> to $1$.</p>
<h4 id="ride-side"><a class="header" href="#ride-side">Ride side</a></h4>
<p>The right side is a power function of the form $y = a(x^u)$.</p>
<h3 id="pseudo-code"><a class="header" href="#pseudo-code">Pseudo-code</a></h3>
<pre><code>NEW_PRICE := IF CORES_SOLD &lt;= BULK_TARGET THEN
(OLD_PRICE - MIN_PRICE) * (1 - ((BULK_TARGET - CORES_SOLD)^SCALE_DOWN / BULK_TARGET^SCALE_DOWN)) + MIN_PRICE
ELSE
((MAX_PRICE_INCREASE_FACTOR - 1) * OLD_PRICE * ((CORES_SOLD - BULK_TARGET)^SCALE_UP / (BULK_LIMIT - BULK_TARGET)^SCALE_UP)) + OLD_PRICE
END IF
</code></pre>
<h3 id="properties-of-the-curve"><a class="header" href="#properties-of-the-curve">Properties of the Curve</a></h3>
<h4 id="minimum-price"><a class="header" href="#minimum-price">Minimum Price</a></h4>
<p>We introduce <code>MIN_PRICE</code> to control the minimum price.</p>
<p>The left side of the function shall be allowed to come close to 0 if cores sold approaches 0. The rationale is that if there are actually 0 cores sold, the previous sale price was too high and the price needs to adapt quickly.</p>
<h4 id="price-forms-a-plateau-around-the-target"><a class="header" href="#price-forms-a-plateau-around-the-target">Price forms a plateau around the target</a></h4>
<p>If the number of cores is close to <code>BULK_TARGET</code>, less extreme price changes might be sensible. This ensures that a drop in sold cores or an increase doesnt lead to immediate price changes, but rather slowly adapts. Only if more extreme changes in the number of sold cores occur, does the price slope increase.</p>
<p>We introduce <code>SCALE_DOWN</code> and <code>SCALE_UP</code> to control for the steepness of the left and the right side of the function respectively.</p>
<h4 id="max-price-increase-factor"><a class="header" href="#max-price-increase-factor">Max price increase factor</a></h4>
<p>We introduce <code>MAX_PRICE_INCREASE_FACTOR</code> as the factor that controls how much the price may increase from one period to another.</p>
<p>Introducing this variable gives governance an additional control lever and avoids the necessity for a future runtime upgrade.</p>
<h3 id="example-configurations"><a class="header" href="#example-configurations">Example Configurations</a></h3>
<h4 id="baseline"><a class="header" href="#baseline">Baseline</a></h4>
<p>This example proposes the baseline parameters. If not mentioned otherwise, other examples use these values. </p>
<p>The minimum price of a core is 1 DOT, the price can double every 4 weeks. Price change around <code>BULK_TARGET</code> is dampened slightly.</p>
<pre><code>BULK_TARGET = 30
BULK_LIMIT = 45
MIN_PRICE = 1
MAX_PRICE_INCREASE_FACTOR = 2
SCALE_DOWN = 2
SCALE_UP = 2
OLD_PRICE = 1000
</code></pre>
<h4 id="more-aggressive-pricing"><a class="header" href="#more-aggressive-pricing">More aggressive pricing</a></h4>
<p>We might want to have a more aggressive price growth, allowing the price to triple every 4 weeks and have a linear increase in price on the right side.</p>
<pre><code>BULK_TARGET = 30
BULK_LIMIT = 45
MIN_PRICE = 1
MAX_PRICE_INCREASE_FACTOR = 3
SCALE_DOWN = 2
SCALE_UP = 1
OLD_PRICE = 1000
</code></pre>
<h4 id="conservative-pricing-to-ensure-quick-corrections-in-an-affluent-market"><a class="header" href="#conservative-pricing-to-ensure-quick-corrections-in-an-affluent-market">Conservative pricing to ensure quick corrections in an affluent market</a></h4>
<p>If governance considers the risk that a sudden surge in DOT price might price chains out from bulk coretime markets, it can ensure the model quickly reacts to a quick drop in demand, by setting 0 &lt; SCALE_DOWN &lt; 1 and setting the max price increase factor more conservatively.</p>
<pre><code>BULK_TARGET = 30
BULK_LIMIT = 45
MIN_PRICE = 1
MAX_PRICE_INCREASE_FACTOR = 1.5
SCALE_DOWN = 0.5
SCALE_UP = 2
OLD_PRICE = 1000
</code></pre>
<h4 id="linear-pricing"><a class="header" href="#linear-pricing">Linear pricing</a></h4>
<p>By setting the scaling factors to 1 and potentially adapting the max price increase, we can achieve a linear function</p>
<pre><code>BULK_TARGET = 30
BULK_LIMIT = 45
MIN_PRICE = 1
MAX_PRICE_INCREASE_FACTOR = 1.5
SCALE_DOWN = 1
SCALE_UP = 1
OLD_PRICE = 1000
</code></pre>
<h2 id="drawbacks-1"><a class="header" href="#drawbacks-1">Drawbacks</a></h2>
<p>None at present.</p>
<h2 id="prior-art-and-references"><a class="header" href="#prior-art-and-references">Prior Art and References</a></h2>
<p>This pricing model is based on the requirements from the basic linear solution proposed in RFC-1, which is a simple dynamic pricing model and only used as proof. The present model adds additional considerations to make the model more adaptable under real conditions. </p>
<h2 id="future-possibilities-1"><a class="header" href="#future-possibilities-1">Future Possibilities</a></h2>
<p>This RFC, if accepted, shall be implemented in conjunction with RFC-1.</p>
<h2 id="references"><a class="header" href="#references">References</a></h2>
<ul>
<li>[1] Polkadot forum post with visualizations: <a href="https://forum.polkadot.network/t/dynamic-pricing-for-bulk-coretime-sales/3359">Dynamic Pricing for Bulk Coretime Sales</a></li>
</ul>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/pull/9">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="proposed/0009-improved-net-light-client-requests.html#rfc-0009-improved-light-client-requests-networking-protocol">RFC-0009: Improved light client requests networking protocol</a>
<ul>
<li><a href="proposed/0009-improved-net-light-client-requests.html#summary">Summary</a></li>
<li><a href="proposed/0009-improved-net-light-client-requests.html#motivation">Motivation</a></li>
<li><a href="proposed/0009-improved-net-light-client-requests.html#stakeholders">Stakeholders</a></li>
<li><a href="proposed/0009-improved-net-light-client-requests.html#explanation">Explanation</a></li>
<li><a href="proposed/0009-improved-net-light-client-requests.html#drawbacks">Drawbacks</a></li>
<li><a href="proposed/0009-improved-net-light-client-requests.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="proposed/0009-improved-net-light-client-requests.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="proposed/0009-improved-net-light-client-requests.html#performance">Performance</a></li>
<li><a href="proposed/0009-improved-net-light-client-requests.html#ergonomics">Ergonomics</a></li>
<li><a href="proposed/0009-improved-net-light-client-requests.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="proposed/0009-improved-net-light-client-requests.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="proposed/0009-improved-net-light-client-requests.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="proposed/0009-improved-net-light-client-requests.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0009-improved-light-client-requests-networking-protocol"><a class="header" href="#rfc-0009-improved-light-client-requests-networking-protocol">RFC-0009: Improved light client requests networking protocol</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>2023-07-19</td></tr>
<tr><td><strong>Description</strong></td><td>Modify the networking storage read requests to solve some problems with the existing one</td></tr>
<tr><td><strong>Authors</strong></td><td>Pierre Krieger</td></tr>
</tbody></table>
</div>
<h2 id="summary-2"><a class="header" href="#summary-2">Summary</a></h2>
<p>Improve the networking messages that query storage items from the remote, in order to reduce the bandwidth usage and number of round trips of light clients.</p>
<h2 id="motivation-2"><a class="header" href="#motivation-2">Motivation</a></h2>
<p>Clients on the Polkadot peer-to-peer network can be divided into two categories: full nodes and light clients. So-called full nodes are nodes that store the content of the chain locally on their disk, while light clients are nodes that don't. In order to access for example the balance of an account, a full node can do a disk read, while a light client needs to send a network message to a full node and wait for the full node to reply with the desired value. This reply is in the form of a Merkle proof, which makes it possible for the light client to verify the exactness of the value.</p>
<p>Unfortunately, this network protocol is suffering from some issues:</p>
<ul>
<li>It is not possible for the querier to check whether a key exists in the storage of the chain except by querying the value of that key. The reply will thus include the value of the key, only for that value to be discarded by the querier that isn't interested by it. This is a waste of bandwidth.</li>
<li>It is not possible for the querier to know whether a value in the storage of the chain has been modified between two blocks except by querying this value for both blocks and comparing them. Only a few storage values get modified in a block, and thus most of the time the comparison will be equal. This leads to a waste of bandwidth as the values have to be transferred.</li>
<li>While it is possible to ask for multiple specific storage keys at the same time, it is not possible to ask for a list of keys that start with a certain prefix. Due to the way FRAME works, storage keys are grouped by &quot;prefix&quot;, for example all account balances start with the same prefix. It is thus a common necessity for a light client to obtain the list of all keys (and possibly their values) that start with a specific prefix. This is currently not possible except by performing multiple queries serially that &quot;walk down&quot; the trie.</li>
</ul>
<p>Once Polkadot and Kusama will have transitioned to <code>state_version = 1</code>, which modifies the format of the trie entries, it will be possible to generate Merkle proofs that contain only the hashes of values in the storage. Thanks to this, it is already possible to prove the existence of a key without sending its entire value (only its hash), or to prove that a value has changed or not between two blocks (by sending just their hashes).
Thus, the only reason why aforementioned issues exist is because the existing networking messages don't give the possibility for the querier to query this. This is what this proposal aims at fixing.</p>
<h2 id="stakeholders-2"><a class="header" href="#stakeholders-2">Stakeholders</a></h2>
<p>This is the continuation of https://github.com/w3f/PPPs/pull/10, which itself is the continuation of https://github.com/w3f/PPPs/pull/5.</p>
<h2 id="explanation-2"><a class="header" href="#explanation-2">Explanation</a></h2>
<p>The protobuf schema of the networking protocol can be found here: https://github.com/paritytech/substrate/blob/5b6519a7ff4a2d3cc424d78bc4830688f3b184c0/client/network/light/src/schema/light.v1.proto</p>
<p>The proposal is to modify this protocol in this way:</p>
<pre><code class="language-diff">@@ -11,6 +11,7 @@ message Request {
RemoteReadRequest remote_read_request = 2;
RemoteReadChildRequest remote_read_child_request = 4;
// Note: ids 3 and 5 were used in the past. It would be preferable to not re-use them.
+ RemoteReadRequestV2 remote_read_request_v2 = 6;
}
}
@@ -48,6 +49,21 @@ message RemoteReadRequest {
repeated bytes keys = 3;
}
+message RemoteReadRequestV2 {
+ required bytes block = 1;
+ optional ChildTrieInfo child_trie_info = 2; // Read from the main trie if missing.
+ repeated Key keys = 3;
+ optional bytes onlyKeysAfter = 4;
+ optional bool onlyKeysAfterIgnoreLastNibble = 5;
+}
+
+message ChildTrieInfo {
+ enum ChildTrieNamespace {
+ DEFAULT = 1;
+ }
+
+ required bytes hash = 1;
+ required ChildTrieNamespace namespace = 2;
+}
+
// Remote read response.
message RemoteReadResponse {
// Read proof. If missing, indicates that the remote couldn't answer, for example because
@@ -65,3 +81,8 @@ message RemoteReadChildRequest {
// Storage keys.
repeated bytes keys = 6;
}
+
+message Key {
+ required bytes key = 1;
+ optional bool skipValue = 2; // Defaults to `false` if missing
+ optional bool includeDescendants = 3; // Defaults to `false` if missing
+}
</code></pre>
<p>Note that the field names aren't very important as they are not sent over the wire. They can be changed at any time without any consequence. I would invite people to not discuss these field names as they are implementation details.</p>
<p>This diff adds a new type of request (<code>RemoteReadRequestV2</code>).</p>
<p>The new <code>child_trie_info</code> field in the request makes it possible to specify which trie is concerned by the request. The current networking protocol uses two different structs (<code>RemoteReadRequest</code> and <code>RemoteReadChildRequest</code>) for main trie and child trie queries, while this new request would make it possible to query either. This change doesn't fix any of the issues mentioned in the previous section, but is a side change that has been done for simplicity.
An alternative could have been to specify the <code>child_trie_info</code> for each individual <code>Key</code>. However this would make it necessary to send the child trie hash many times over the network, which leads to a waste of bandwidth, and in my opinion makes things more complicated for no actual gain. If a querier would like to access more than one trie at the same time, it is always possible to send one query per trie.</p>
<p>If <code>skipValue</code> is <code>true</code> for a <code>Key</code>, then the value associated with this key isn't important to the querier, and the replier is encouraged to replace the value with its hash provided that the storage item has a <code>state_version</code> equal to 1. If the storage value has a <code>state_version</code> equal to 0, then the optimization isn't possible and the replier should behave as if <code>skipValue</code> was <code>false</code>.</p>
<p>If <code>includeDescendants</code> is <code>true</code> for a <code>Key</code>, then the replier must also include in the proof all keys that are descendant of the given key (in other words, its children, children of children, children of children of children, etc.). It must do so even if <code>key</code> itself doesn't have any storage value associated to it. The values of all of these descendants are replaced with their hashes if <code>skipValue</code> is <code>true</code>, similarly to <code>key</code> itself.</p>
<p>The optional <code>onlyKeysAfter</code> and <code>onlyKeysAfterIgnoreLastNibble</code> fields can provide a lower bound for the keys contained in the proof. The responder must not include in its proof any node whose key is strictly inferior to the value in <code>onlyKeysAfter</code>. If <code>onlyKeysAfterIgnoreLastNibble</code> is provided, then the last 4 bits for <code>onlyKeysAfter</code> must be ignored. This makes it possible to represent a trie branch node that doesn't have an even number of nibbles. If no <code>onlyKeysAfter</code> is provided, it is equivalent to being empty, meaning that the response must start with the root node of the trie.</p>
<p>If <code>onlyKeysAfterIgnoreLastNibble</code> is missing, it is equivalent to <code>false</code>. If <code>onlyKeysAfterIgnoreLastNibble</code> is <code>true</code> and <code>onlyKeysAfter</code> is missing or empty, then the request is invalid.</p>
<p>For the purpose of this networking protocol, it should be considered as if the main trie contained an entry for each default child trie whose key is <code>concat(&quot;:child_storage:default:&quot;, child_trie_hash)</code> and whose value is equal to the trie root hash of that default child trie. This behavior is consistent with what the host functions observe when querying the storage. This behavior is present in the existing networking protocol, in other words this proposal doesn't change anything to the situation, but it is worth mentioning.
Also note that child tries aren't considered as descendants of the main trie when it comes to the <code>includeDescendants</code> flag. In other words, if the request concerns the main trie, no content coming from child tries is ever sent back.</p>
<p>This protocol keeps the same maximum response size limit as currently exists (16 MiB). It is not possible for the querier to know in advance whether its query will lead to a reply that exceeds the maximum size. If the reply is too large, the replier should send back only a limited number (but at least one) of requested items in the proof. The querier should then send additional requests for the rest of the items. A response containing none of the requested items is invalid.</p>
<p>The server is allowed to silently discard some keys of the request if it judges that the number of requested keys is too high. This is in line with the fact that the server might truncate the response.</p>
<h2 id="drawbacks-2"><a class="header" href="#drawbacks-2">Drawbacks</a></h2>
<p>This proposal doesn't handle one specific situation: what if a proof containing a single specific item would exceed the response size limit? For example, if the response size limit was 1 MiB, querying the runtime code (which is typically 1.0 to 1.5 MiB) would be impossible as it's impossible to generate a proof less than 1 MiB. The response size limit is currently 16 MiB, meaning that no single storage item must exceed 16 MiB.</p>
<p>Unfortunately, because it's impossible to verify a Merkle proof before having received it entirely, parsing the proof in a streaming way is also not possible.</p>
<p>A way to solve this issue would be to Merkle-ize large storage items, so that a proof could include only a portion of a large storage item. Since this would require a change to the trie format, it is not realistically feasible in a short time frame.</p>
<h2 id="testing-security-and-privacy"><a class="header" href="#testing-security-and-privacy">Testing, Security, and Privacy</a></h2>
<p>The main security consideration concerns the size of replies and the resources necessary to generate them. It is for example easily possible to ask for all keys and values of the chain, which would take a very long time to generate. Since responses to this networking protocol have a maximum size, the replier should truncate proofs that would lead to the response being too large. Note that it is already possible to send a query that would lead to a very large reply with the existing network protocol. The only thing that this proposal changes is that it would make it less complicated to perform such an attack.</p>
<p>Implementers of the replier side should be careful to detect early on when a reply would exceed the maximum reply size, rather than inconditionally generate a reply, as this could take a very large amount of CPU, disk I/O, and memory. Existing implementations might currently be accidentally protected from such an attack thanks to the fact that requests have a maximum size, and thus that the list of keys in the query was bounded. After this proposal, this accidental protection would no longer exist.</p>
<p>Malicious server nodes might truncate Merkle proofs even when they don't strictly need to, and it is not possible for the client to (easily) detect this situation. However, malicious server nodes can already do undesirable things such as throttle down their upload bandwidth or simply not respond. There is no need to handle unnecessarily truncated Merkle proofs any differently than a server simply not answering the request.</p>
<h2 id="performance-ergonomics-and-compatibility"><a class="header" href="#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance"><a class="header" href="#performance">Performance</a></h3>
<p>It is unclear to the author of the RFC what the performance implications are. Servers are supposed to have limits to the amount of resources they use to respond to requests, and as such the worst that can happen is that light client requests become a bit slower than they currently are.</p>
<h3 id="ergonomics"><a class="header" href="#ergonomics">Ergonomics</a></h3>
<p>Irrelevant.</p>
<h3 id="compatibility"><a class="header" href="#compatibility">Compatibility</a></h3>
<p>The prior networking protocol is maintained for now. The older version of this protocol could get removed in a long time.</p>
<h2 id="prior-art-and-references-1"><a class="header" href="#prior-art-and-references-1">Prior Art and References</a></h2>
<p>None. This RFC is a clean-up of an existing mechanism.</p>
<h2 id="unresolved-questions-1"><a class="header" href="#unresolved-questions-1">Unresolved Questions</a></h2>
<p>None</p>
<h2 id="future-directions-and-related-material"><a class="header" href="#future-directions-and-related-material">Future Directions and Related Material</a></h2>
<p>The current networking protocol could be deprecated in a long time. Additionally, the current &quot;state requests&quot; protocol (used for warp syncing) could also be deprecated in favor of this one.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/pull/17">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="proposed/0015-market-design-revisit.html#rfc-0015-market-design-revisit">RFC-0015: Market Design Revisit</a>
<ul>
<li><a href="proposed/0015-market-design-revisit.html#summary">Summary</a></li>
<li><a href="proposed/0015-market-design-revisit.html#motivation">Motivation</a></li>
<li><a href="proposed/0015-market-design-revisit.html#stakeholders">Stakeholders</a></li>
<li><a href="proposed/0015-market-design-revisit.html#explanation">Explanation</a>
<ul>
<li><a href="proposed/0015-market-design-revisit.html#bulk-markets">Bulk Markets</a></li>
<li><a href="proposed/0015-market-design-revisit.html#benefits-of-this-system">Benefits of this system</a></li>
<li><a href="proposed/0015-market-design-revisit.html#further-discussion-points">Further Discussion Points</a></li>
</ul>
</li>
<li><a href="proposed/0015-market-design-revisit.html#drawbacks">Drawbacks</a></li>
<li><a href="proposed/0015-market-design-revisit.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="proposed/0015-market-design-revisit.html#unresolved-questions">Unresolved Questions</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0015-market-design-revisit"><a class="header" href="#rfc-0015-market-design-revisit">RFC-0015: Market Design Revisit</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>05.08.2023</td></tr>
<tr><td><strong>Description</strong></td><td>This RFC refines the previously proposed mechanisms involving the various Coretime markets and presents an integrated framework for harmonious interaction between all markets.</td></tr>
<tr><td><strong>Authors</strong></td><td>Jonas Gehrlein</td></tr>
</tbody></table>
</div>
<h2 id="summary-3"><a class="header" href="#summary-3">Summary</a></h2>
<p>This document is a proposal for restructuring the bulk markets in the Polkadot UC's coretime allocation system to improve efficiency and fairness. The proposal suggests separating the <code>BULK_PERIOD</code> into <code>MARKET_PERIOD</code> and <code>RENEWAL_PERIOD</code>, allowing for a market-driven price discovery through a clearing price Dutch auction during the <code>MARKET_PERIOD</code> followed by renewal offers at the <code>MARKET_PRICE</code> during the <code>RENEWAL_PERIOD</code>. The new system ensures synchronicity between renewal and market prices, fairness among all current tenants, and efficient price discovery, while preserving price caps to provide security for current tenants. It seeks to start a discussion about the possibility of long-term leases.</p>
<h2 id="motivation-3"><a class="header" href="#motivation-3">Motivation</a></h2>
<p>While the initial <a href="https://github.com/polkadot-fellows/RFCs/blob/6f29561a4747bbfd95307ce75cd949dfff359e39/text/0001-agile-coretime.md">RFC-1</a> has provided a robust framework for Coretime allocation within the Polkadot UC, this proposal builds upon its strengths and uses many provided building blocks to address some areas that could be further improved. </p>
<p>In particular, this proposal introduces the following changes:</p>
<ul>
<li>It introduces a <code>RESERVE_PRICE</code> that anchors all markets, promoting price synchronicity within the Bulk markets (flexible + renewals).
<ul>
<li>This reduces complexity.</li>
<li>This makes sure all consumers pay a closely correlated price for coretime within a <code>BULK_PERIOD</code>.</li>
</ul>
</li>
<li>It reverses the order of the market and renewal phase.
<ul>
<li>This allows to fine-tune the price through market forces.</li>
</ul>
</li>
<li>It exposes the renewal prices, while still being beneficial for longterm tenants, more to market forces. </li>
<li>It removes the LeadIn period and introduces a (from the perspective of the coretime systemchain) passive Settlement Phase, that allows the secondary market to exert it's force.</li>
</ul>
<p>The premise of this proposal is to reduce complexity by introducing a common price (that develops releative to capacity consumption of Polkadot UC), while still allowing for market forces to add efficiency. Longterm lease owners still receive priority <strong>IF</strong> they can pay (close to) the market price. This prevents a situation where the renewal price significantly diverges from renewal prices which allows for core captures. While maximum price increase certainty might seem contradictory to efficient price discovery, the proposed model aims to balance these elements, utilizing market forces to determine the price and allocate cores effectively within certain bounds. It must be stated, that potential price increases remain predictable (in the worst-case) but could be higher than in the originally proposed design. The argument remains, however, that we need to allow market forces to affect all prices for an efficient Coretime pricing and allocation.</p>
<p>Ultimately, this the framework proposed here adheres to all requirements stated in RFC-1.</p>
<h2 id="stakeholders-3"><a class="header" href="#stakeholders-3">Stakeholders</a></h2>
<p>Primary stakeholder sets are:</p>
<ul>
<li>Protocol researchers and developers, largely represented by the Polkadot Fellowship and Parity Technologies' Engineering division.</li>
<li>Polkadot Parachain teams both present and future, and their users.</li>
<li>Polkadot DOT token holders.</li>
</ul>
<h2 id="explanation-3"><a class="header" href="#explanation-3">Explanation</a></h2>
<h3 id="bulk-markets"><a class="header" href="#bulk-markets">Bulk Markets</a></h3>
<p>The <code>BULK_PERIOD</code> has been restructured into two primary segments: the <code>MARKET_PERIOD</code> and <code>RENEWAL_PERIOD</code>, along with an auxiliary <code>SETTLEMENT_PERIOD</code>. This latter period doesn't necessitate any actions from the coretime system chain, but it facilitates a more efficient allocation of coretime in secondary markets. A significant departure from the original proposal lies in the timing of renewals, which now occur post-market phase. This adjustment aims to harmonize renewal prices with their market counterparts, ensuring a more consistent and equitable pricing model.</p>
<h4 id="market-period-14-days"><a class="header" href="#market-period-14-days">Market Period (14 days)</a></h4>
<p>During the market period, core sales are conducted through a well-established <strong>clearing price Dutch auction</strong> that features a <code>RESERVE_PRICE</code>. The price initiates at a premium, designated as <code>PRICE_PREMIUM</code> (for instance, 30%) and descends linearly to the <code>RESERVE_PRICE</code> throughout the duration of the <code>MARKET_PERIOD</code>. Each bidder is expected to submit both their desired price and the quantity (that is, the amount of Coretime) they wish to purchase. To secure these acquisitions, bidders must make a deposit equivalent to their bid multiplied by the chosen quantity, in DOT. </p>
<p>The market achieves resolution once all quantities have been sold, or the <code>RESERVE_PRICE</code> has been reached. This situation leads to determining the <code>MARKET_PRICE</code> either by the lowest bid that was successful in clearing the entire market or by the <code>RESERVE_PRICE</code>. This mechanism yields a uniform price, shaped by market forces (refer to the following discussion for an explanation of its benefits). In other words, all buyers pay the same price (per unit of Coretime). Further down the benefits of this variant of a Dutch auction is discussed.</p>
<p><strong>Note:</strong> In cases where some cores remain unsold in the market, all buyers are obligated to pay the <code>RESERVE_PRICE</code>.</p>
<h4 id="renewal-period-7-days"><a class="header" href="#renewal-period-7-days">Renewal Period (7 days)</a></h4>
<p>As the <code>RENEWAL_PERIOD</code> commences, all current tenants are granted the opportunity to renew their cores at a slight discount of <code>MARKET_PRICE * RENEWAL_DISCOUNT</code> (for instance, 10%). This provision affords marginal benefits to existing tenants, balancing out the non-transferability aspect of renewals.</p>
<p>At the end of the period, all available cores are allocated to the current tenants who have opted for renewal and the participants who placed bids during the market period. If the demand for cores exceeds supply, the cores left unclaimed from renewals may be awarded to bidders who placed their bids early in the auction, thereby subtly incentivizing early participation. If the supply exceeds the demand, all unsold cores are transferred to the Instantanous Market.</p>
<h4 id="reserve-price-adjustment"><a class="header" href="#reserve-price-adjustment">Reserve Price Adjustment</a></h4>
<p>After all cores are allocated, the <code>RESERVE_PRICE</code> is adjusted following the process described in RFC-1 and serves as baseline price in the next <code>BULK_PERIOD</code>. </p>
<p><strong>Note:</strong> The particular price curve is outside the scope of the proposal. The <code>MARKET_PRICE</code> (as a function of <code>RESERVE_PRICE</code>), however, is able to capture higher demand very well while being capped downwards. That means, the curve that adjusts the <code>RESERVE_PRICE</code> should be more sensitive to undercapacity.</p>
<h4 id="price-predictability"><a class="header" href="#price-predictability">Price Predictability</a></h4>
<p>Tasks that are in the &quot;renewal-pipeline&quot; can determine the upper bound for the price they will pay in any future period. The main driver of any price increase over time is the adjustment of the <code>RESERVE_PRICE</code>, that occurs at the end of each <code>BULK_PERIOD</code> after determining the capacity fillment of Polkadot UC. To calculate the maximum price in some future period, a task could assume maximum capacity in all upcoming periods and track the resulting price increase of <code>RESERVE_PRICE</code>. In the final period, that price can get a maximum premium of <code>PRICE_PREMIUM</code> and after deducting a potential <code>RENEWAL_DISCOUNT</code>, the maximum price can be determined.</p>
<h4 id="settlement-period-7-days"><a class="header" href="#settlement-period-7-days">Settlement Period (7 days)</a></h4>
<p>During the settlement period, participants have ample time to trade Coretime on secondary markets before the onset of the next <code>BULK_PERIOD</code>. This allows for trading with full Coretime availability. Trading transferrable Coretime naturally continues during each <code>BULK_PERIOD</code>, albeit with cores already in use.</p>
<h3 id="benefits-of-this-system"><a class="header" href="#benefits-of-this-system">Benefits of this system</a></h3>
<ul>
<li>The introduction of a single price, the <code>RESERVE_PRICE</code>, provides an anchor for all Coretime markets. This is a preventative measure against the possible divergence and mismatch of prices, which could inadvertently lead to a situation where existing tenants secure cores at significantly below-market rates.</li>
<li>With a more market-responsive pricing system, we can achieve a more efficient price discovery process. Any price increases will be less arbitrary and more dynamic.</li>
<li>The ideal strategy for existing tenants is to maintain passivity, i.e., refrain from active market participation and simply accept the offer presented to them during the renewal phase. This approach lessens the organizational overhead for long-term projects.</li>
<li>In the two-week market phase, the maximum price increase is known well in advance, providing ample time for tenants to secure necessary funds to meet the potential price escalation.</li>
<li>All existing tenants pay an equal amount for Coretime, reflecting our intent to price the Coretime itself and not the relative timing of individual projects.</li>
</ul>
<h4 id="discussion-clearing-price-dutch-auctions"><a class="header" href="#discussion-clearing-price-dutch-auctions">Discussion: Clearing Price Dutch Auctions</a></h4>
<p>Having all bidders pay the market clearing price offers some benefits and disadvantages.</p>
<ul>
<li>Advantages:
<ul>
<li><strong>Fairness</strong>: All bidders pay the same price.</li>
<li><strong>Active participation</strong>: Because bidders are protected from overbidding (winner's curse), they are more likely to engage and reveal their true valuations.</li>
<li><strong>Simplicity</strong>: A single price is easier to work with for pricing renewals later.</li>
<li><strong>Truthfulness</strong>: There is no need to try to game the market by waiting with bidding. Bidders can just bid their valuations.</li>
</ul>
</li>
<li>Disadvantages:
<ul>
<li><strong>(Potentially) Lower Revenue</strong>: While the theory predicts revenue-equivalence between a uniform price and pay-as-bid type of auction, slightly lower revenue for the former type is observed empirically. Arguably, revenue maximization (i.e., squeezing out the maximum willingness to pay from bidders) is not the priority for Polkadot UC. Instead, it is interested in efficient allocation and the other benefits illustrated above.</li>
<li><strong>(Technical) Complexity</strong>: Instead of making a final purchase within the auction, the bid is only a deposit. Some refunds might happen after the auction is finished. This might pose additional challenges from the technical side (e.g., storage requirements).</li>
</ul>
</li>
</ul>
<h3 id="further-discussion-points"><a class="header" href="#further-discussion-points">Further Discussion Points</a></h3>
<ul>
<li><strong>Long-term Coretime</strong>: The Polkadot UC is undergoing a transition from two-year leases without an instantaneous market to a model encompassing instantaneous and one-month leases. This shift seems to pivot from one extreme to another. While the introduction of short-term leases, both instantaneous and for one month, is a constructive move to lower barriers to entry and promote experimentation, it seems to be the case that established projects might benefit from more extended lease options. We could consider offering another product, such as a six-month Coretime lease, using the same mechanism described herein. Although the majority of leases would still be sold on a one-month basis, the addition of this option would enhance market efficiency as it would <strong>strengthen the impact of a secondary market</strong>.</li>
</ul>
<h2 id="drawbacks-3"><a class="header" href="#drawbacks-3">Drawbacks</a></h2>
<p>There are trade-offs that arise from this proposal, compared to the initial model. The most notable one is that here, I prioritize requirement 6 over requirement 2. The price, in the very &quot;worst-case&quot; (meaning a huge explosion in demand for coretime) could lead to a much larger increase of prices in Coretime. From an economic perspective, this (rare edgecase) would also mean that we'd vastly underprice Coretime in the original model, leading to highly inefficient allocations.</p>
<h2 id="prior-art-and-references-2"><a class="header" href="#prior-art-and-references-2">Prior Art and References</a></h2>
<p>This RFC builds extensively on the available ideas put forward in <a href="https://github.com/polkadot-fellows/RFCs/blob/6f29561a4747bbfd95307ce75cd949dfff359e39/text/0001-agile-coretime.md">RFC-1</a>. </p>
<p>Additionally, I want to express a special thanks to <a href="https://samuelhaefner.github.io/">Samuel Haefner</a> and <a href="https://sites.google.com/site/dobzin/">Shahar Dobzinski</a> for fruitful discussions and helping me structure my thoughts. </p>
<h2 id="unresolved-questions-2"><a class="header" href="#unresolved-questions-2">Unresolved Questions</a></h2>
<p>The technical feasability needs to be assessed.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/pull/34">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="proposed/0034-xcm-absolute-location-account-derivation.html#rfc-34-xcm-absolute-location-account-derivation">RFC-34: XCM Absolute Location Account Derivation</a>
<ul>
<li><a href="proposed/0034-xcm-absolute-location-account-derivation.html#summary">Summary</a></li>
<li><a href="proposed/0034-xcm-absolute-location-account-derivation.html#motivation">Motivation</a></li>
<li><a href="proposed/0034-xcm-absolute-location-account-derivation.html#stakeholders">Stakeholders</a></li>
<li><a href="proposed/0034-xcm-absolute-location-account-derivation.html#explanation">Explanation</a></li>
<li><a href="proposed/0034-xcm-absolute-location-account-derivation.html#drawbacks">Drawbacks</a></li>
<li><a href="proposed/0034-xcm-absolute-location-account-derivation.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="proposed/0034-xcm-absolute-location-account-derivation.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="proposed/0034-xcm-absolute-location-account-derivation.html#performance">Performance</a></li>
<li><a href="proposed/0034-xcm-absolute-location-account-derivation.html#ergonomics">Ergonomics</a></li>
<li><a href="proposed/0034-xcm-absolute-location-account-derivation.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="proposed/0034-xcm-absolute-location-account-derivation.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="proposed/0034-xcm-absolute-location-account-derivation.html#unresolved-questions">Unresolved Questions</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-34-xcm-absolute-location-account-derivation"><a class="header" href="#rfc-34-xcm-absolute-location-account-derivation">RFC-34: XCM Absolute Location Account Derivation</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>05 October 2023</td></tr>
<tr><td><strong>Description</strong></td><td>XCM Absolute Location Account Derivation</td></tr>
<tr><td><strong>Authors</strong></td><td>Gabriel Facco de Arruda</td></tr>
</tbody></table>
</div>
<h2 id="summary-4"><a class="header" href="#summary-4">Summary</a></h2>
<p>This RFC proposes changes that enable the use of absolute locations in AccountId derivations, which allows protocols built using XCM to have static account derivations in any runtime, regardless of its position in the family hierarchy.</p>
<h2 id="motivation-4"><a class="header" href="#motivation-4">Motivation</a></h2>
<p>These changes would allow protocol builders to leverage absolute locations to maintain the exact same derived account address across all networks in the ecosystem, thus enhancing user experience.</p>
<p>One such protocol, that is the original motivation for this proposal, is InvArch's Saturn Multisig, which gives users a unifying multisig and DAO experience across all XCM connected chains.</p>
<h2 id="stakeholders-4"><a class="header" href="#stakeholders-4">Stakeholders</a></h2>
<ul>
<li>Ecosystem developers</li>
</ul>
<h2 id="explanation-4"><a class="header" href="#explanation-4">Explanation</a></h2>
<p>This proposal aims to make it possible to derive accounts for absolute locations, enabling protocols that require the ability to maintain the same derived account in any runtime. This is done by deriving accounts from the hash of described absolute locations, which are static across different destinations.</p>
<p>The same location can be represented in relative form and absolute form like so:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>// Relative location (from own perspective)
{
parents: 0,
interior: Here
}
// Relative location (from perspective of parent)
{
parents: 0,
interior: [Parachain(1000)]
}
// Relative location (from perspective of sibling)
{
parents: 1,
interior: [Parachain(1000)]
}
// Absolute location
[GlobalConsensus(Kusama), Parachain(1000)]
<span class="boring">}</span></code></pre></pre>
<p>Using <code>DescribeFamily</code>, the above relative locations would be described like so:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>// Relative location (from own perspective)
// Not possible.
// Relative location (from perspective of parent)
(b&quot;ChildChain&quot;, Compact::&lt;u32&gt;::from(*index)).encode()
// Relative location (from perspective of sibling)
(b&quot;SiblingChain&quot;, Compact::&lt;u32&gt;::from(*index)).encode()
<span class="boring">}</span></code></pre></pre>
<p>The proposed description for absolute location would follow the same pattern, like so:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>(
b&quot;GlobalConsensus&quot;,
network_id,
b&quot;Parachain&quot;,
Compact::&lt;u32&gt;::from(para_id),
tail
).encode()
<span class="boring">}</span></code></pre></pre>
<p>This proposal requires the modification of two XCM types defined in the <code>xcm-builder</code> crate: The <code>WithComputedOrigin</code> barrier and the <code>DescribeFamily</code> MultiLocation descriptor.</p>
<h4 id="withcomputedorigin"><a class="header" href="#withcomputedorigin">WithComputedOrigin</a></h4>
<p>The <code>WtihComputedOrigin</code> barrier serves as a wrapper around other barriers, consuming origin modification instructions and applying them to the message origin before passing to the inner barriers. One of the origin modifying instructions is <code>UniversalOrigin</code>, which serves the purpose of signaling that the origin should be a Universal Origin that represents the location as an absolute path prefixed by the <code>GlobalConsensus</code> junction.</p>
<p>In it's current state the barrier transforms locations with the <code>UniversalOrigin</code> instruction into relative locations, so the proposed changes aim to make it return absolute locations instead.</p>
<h4 id="describefamily"><a class="header" href="#describefamily">DescribeFamily</a></h4>
<p>The <code>DescribeFamily</code> location descriptor is part of the <code>HashedDescription</code> MultiLocation hashing system and exists to describe locations in an easy format for encoding and hashing, so that an AccountId can be derived from this MultiLocation.</p>
<p>This implementation contains a match statement that does not match against absolute locations, so changes to it involve matching against absolute locations and providing appropriate descriptions for hashing.</p>
<h2 id="drawbacks-4"><a class="header" href="#drawbacks-4">Drawbacks</a></h2>
<p>No drawbacks have been identified with this proposal.</p>
<h2 id="testing-security-and-privacy-1"><a class="header" href="#testing-security-and-privacy-1">Testing, Security, and Privacy</a></h2>
<p>Tests can be done using simple unit tests, as this is not a change to XCM itself but rather to types defined in <code>xcm-builder</code>.</p>
<p>Security considerations should be taken with the implementation to make sure no unwanted behavior is introduced.</p>
<p>This proposal does not introduce any privacy considerations.</p>
<h2 id="performance-ergonomics-and-compatibility-1"><a class="header" href="#performance-ergonomics-and-compatibility-1">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-1"><a class="header" href="#performance-1">Performance</a></h3>
<p>Depending on the final implementation, this proposal should not introduce much overhead to performance.</p>
<h3 id="ergonomics-1"><a class="header" href="#ergonomics-1">Ergonomics</a></h3>
<p>The ergonomics of this proposal depend on the final implementation details.</p>
<h3 id="compatibility-1"><a class="header" href="#compatibility-1">Compatibility</a></h3>
<p>Backwards compatibility should remain unchanged, although that depend on the final implementation.</p>
<h2 id="prior-art-and-references-3"><a class="header" href="#prior-art-and-references-3">Prior Art and References</a></h2>
<ul>
<li><code>DescirbeFamily</code> type: https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/xcm/xcm-builder/src/location_conversion.rs#L122</li>
<li><code>WithComputedOrigin</code> type: https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/xcm/xcm-builder/src/barriers.rs#L153</li>
</ul>
<h2 id="unresolved-questions-3"><a class="header" href="#unresolved-questions-3">Unresolved Questions</a></h2>
<p>Implementation details and overall code is still up to discussion.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/pull/35">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="proposed/0035-conviction-voting-delegation-modifications.html#rfc-0035-conviction-voting-delegation-modifications">RFC-0035: Conviction Voting Delegation Modifications</a>
<ul>
<li><a href="proposed/0035-conviction-voting-delegation-modifications.html#summary">Summary</a></li>
<li><a href="proposed/0035-conviction-voting-delegation-modifications.html#motivation">Motivation</a></li>
<li><a href="proposed/0035-conviction-voting-delegation-modifications.html#stakeholders">Stakeholders</a></li>
<li><a href="proposed/0035-conviction-voting-delegation-modifications.html#explanation">Explanation</a></li>
<li><a href="proposed/0035-conviction-voting-delegation-modifications.html#drawbacks">Drawbacks</a></li>
<li><a href="proposed/0035-conviction-voting-delegation-modifications.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="proposed/0035-conviction-voting-delegation-modifications.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="proposed/0035-conviction-voting-delegation-modifications.html#performance">Performance</a></li>
<li><a href="proposed/0035-conviction-voting-delegation-modifications.html#ergonomics--compatibility">Ergonomics &amp; Compatibility</a></li>
</ul>
</li>
<li><a href="proposed/0035-conviction-voting-delegation-modifications.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="proposed/0035-conviction-voting-delegation-modifications.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="proposed/0035-conviction-voting-delegation-modifications.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0035-conviction-voting-delegation-modifications"><a class="header" href="#rfc-0035-conviction-voting-delegation-modifications">RFC-0035: Conviction Voting Delegation Modifications</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>October 10, 2023</strong></td><td></td></tr>
<tr><td><strong>Conviction Voting Delegation Modifications</strong></td><td></td></tr>
<tr><td><strong>ChaosDAO</strong></td><td></td></tr>
</tbody></table>
</div>
<h2 id="summary-5"><a class="header" href="#summary-5">Summary</a></h2>
<p>This RFC proposes to make modifications to voting power delegations as part of the Conviction Voting pallet. The changes being proposed include:</p>
<ol>
<li>Allow a Delegator to vote independently of their Delegate if they so desire.</li>
<li>Allow nested delegations for example Charlie delegates to Bob who delegates to Alice when Alice votes then both Bob and Charlie vote alongside Alice (in the current implementation Charlie will not vote when Alice votes).</li>
<li>Make a change so that when a delegate votes abstain their delegated votes also vote abstain.</li>
<li>Allow a Delegator to delegate/ undelegate their votes for all tracks with a single call. </li>
</ol>
<h2 id="motivation-5"><a class="header" href="#motivation-5">Motivation</a></h2>
<p>It has become clear since the launch of OpenGov that there are a few common tropes which pop up time and time again:</p>
<ol>
<li>The frequency of referenda is often too high for network participants to have sufficient time to review, comprehend, and ultimately vote on each individual referendum. This means that these network participants end up being inactive in on-chain governance.</li>
<li>There are active network participants who are reviewing every referendum and are providing feedback in an attempt to help make the network thrive but often time these participants do not control enough voting power to influence the network with their positive efforts.</li>
<li>Delegating votes for all tracks currently requires long batched calls which result in high fees for the Delegator - resulting in a reluctance from many to delegate their votes.</li>
</ol>
<p>We believe (based on feedback from token holders with a larger stake in the network) that if there were some changes made to delegation mechanics, these larger stake holders would be more likely to delegate their voting power to active network participants thus greatly increasing the support turnout.</p>
<h2 id="stakeholders-5"><a class="header" href="#stakeholders-5">Stakeholders</a></h2>
<p>The primary stakeholders of this RFC are:</p>
<ul>
<li>The Polkadot Technical Fellowship who will have to research and implement the technical aspects of this RFC</li>
<li>DOT token holders in general </li>
</ul>
<h2 id="explanation-5"><a class="header" href="#explanation-5">Explanation</a></h2>
<p>This RFC proposes to make 4 changes to the convictionVoting pallet logic in order to improve the user experience of those delegating their voting power to another account. </p>
<ol>
<li>
<p><strong>Allow a Delegator to vote independently of their Delegate if they so desire</strong> this would empower network participants to more actively delegate their voting power to active voters, removing the tedious steps of having to undelegate across an entire track every time they do not agree with their delegate's voting direction for a particular referendum.</p>
</li>
<li>
<p><strong>Allow nested delegations for example Charlie delegates to Bob who delegates to Alice when Alice votes then both Bob and Charlie vote alongside Alice (in the current runtime Charlie will not vote when Alice votes)</strong> This would allow network participants who control multiple (possibly derived) accounts to be able to delegate all of their voting power to a single account under their control, which would in turn delegate to a more active voting participant. Then if the delegator wishes to vote independently of their delegate they can control all of their voting power from a single account, which again removes the pain point of having to issue multiple undelegate extrinsics in the event that they disagree with their delegate.</p>
</li>
<li>
<p><strong>Have delegated votes follow their delegates abstain votes</strong> there are times where delegates may vote abstain on a particular referendum and adding this functionality will increase the support of a particular referendum. It has a secondary benefit of meaning that Validators who are delegating their voting power do not lose points in the 1KV program in the event that their delegate votes abstain (another pain point which may be preventing those network participants from delegating).</p>
</li>
<li>
<p><strong>Allow a Delegator to delegate/ undelegate their votes for all tracks with a single call</strong> - in order to delegate votes across all tracks, a user must batch 15 calls - resulting in high costs for delegation. A single call for <code>delegate_all</code>/ <code>undelegate_all</code> would reduce the complexity and therefore costs of delegations considerably for prospective Delegators.</p>
</li>
</ol>
<h2 id="drawbacks-5"><a class="header" href="#drawbacks-5">Drawbacks</a></h2>
<p>We do not foresee any drawbacks by implementing these changes. If anything we believe that this should help to increase overall voter turnout (via the means of delegation) which we see as a net positive.</p>
<h2 id="testing-security-and-privacy-2"><a class="header" href="#testing-security-and-privacy-2">Testing, Security, and Privacy</a></h2>
<p>We feel that the Polkadot Technical Fellowship would be the most competent collective to identify the testing requirements for the ideas presented in this RFC.</p>
<h2 id="performance-ergonomics-and-compatibility-2"><a class="header" href="#performance-ergonomics-and-compatibility-2">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-2"><a class="header" href="#performance-2">Performance</a></h3>
<p>This change may add extra chain storage requirements on Polkadot, especially with respect to nested delegations. </p>
<h3 id="ergonomics--compatibility"><a class="header" href="#ergonomics--compatibility">Ergonomics &amp; Compatibility</a></h3>
<p>The change to add nested delegations may affect governance interfaces such as Nova Wallet who will have to apply changes to their indexers to support nested delegations. It may also affect the Polkadot Delegation Dashboard as well as Polkassembly &amp; SubSquare.</p>
<p>We want to highlight the importance for ecosystem builders to create a mechanism for indexers and wallets to be able to understand that changes have occurred such as increasing the pallet version, etc.</p>
<h2 id="prior-art-and-references-4"><a class="header" href="#prior-art-and-references-4">Prior Art and References</a></h2>
<p>N/A</p>
<h2 id="unresolved-questions-4"><a class="header" href="#unresolved-questions-4">Unresolved Questions</a></h2>
<p>N/A</p>
<h2 id="future-directions-and-related-material-1"><a class="header" href="#future-directions-and-related-material-1">Future Directions and Related Material</a></h2>
<p>Additionally we would like to re-open the conversation about the potential for there to be free delegations. This was discussed by Dr Gavin Wood at Sub0 2022 and we feel like this would go a great way towards increasing the amount of network participants that are delegating: https://youtu.be/hSoSA6laK3Q?t=526</p>
<p>Overall, we strongly feel that delegations are a great way to increase voter turnout, and the ideas presented in this RFC would hopefully help in that aspect.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/pull/44">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="proposed/0044-rent-based-registration.html#rfc-0044-rent-based-registration-model">RFC-0044: Rent based registration model</a>
<ul>
<li><a href="proposed/0044-rent-based-registration.html#summary">Summary</a></li>
<li><a href="proposed/0044-rent-based-registration.html#motivation">Motivation</a></li>
<li><a href="proposed/0044-rent-based-registration.html#requirements">Requirements</a></li>
<li><a href="proposed/0044-rent-based-registration.html#stakeholders">Stakeholders</a></li>
<li><a href="proposed/0044-rent-based-registration.html#explanation">Explanation</a>
<ul>
<li><a href="proposed/0044-rent-based-registration.html#registering-an-on-demand-parachain">Registering an on-demand parachain</a></li>
<li><a href="proposed/0044-rent-based-registration.html#on-demand-parachain-pruning">On-demand parachain pruning</a></li>
<li><a href="proposed/0044-rent-based-registration.html#ensuring-rent-is-paid">Ensuring rent is paid</a></li>
<li><a href="proposed/0044-rent-based-registration.html#on-demand-para-re-registration">On-demand para re-registration</a></li>
</ul>
</li>
<li><a href="proposed/0044-rent-based-registration.html#drawbacks">Drawbacks</a></li>
<li><a href="proposed/0044-rent-based-registration.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="proposed/0044-rent-based-registration.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="proposed/0044-rent-based-registration.html#performance">Performance</a></li>
<li><a href="proposed/0044-rent-based-registration.html#ergonomics">Ergonomics</a></li>
<li><a href="proposed/0044-rent-based-registration.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="proposed/0044-rent-based-registration.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="proposed/0044-rent-based-registration.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="proposed/0044-rent-based-registration.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0044-rent-based-registration-model"><a class="header" href="#rfc-0044-rent-based-registration-model">RFC-0044: Rent based registration model</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>6 November 2023</td></tr>
<tr><td><strong>Description</strong></td><td>A new rent based parachain registration model</td></tr>
<tr><td><strong>Authors</strong></td><td>Sergej Sakac</td></tr>
</tbody></table>
</div>
<h2 id="summary-6"><a class="header" href="#summary-6">Summary</a></h2>
<p>This RFC proposes a new model for a sustainable on-demand parachain registration, involving a smaller initial deposit and periodic rent payments. The new model considers that on-demand chains may be unregistered and later re-registered. The proposed solution also ensures a quick startup for on-demand chains on Polkadot in such cases.</p>
<h2 id="motivation-6"><a class="header" href="#motivation-6">Motivation</a></h2>
<p>With the support of on-demand parachains on Polkadot, there is a need to explore a new, more cost-effective model for registering validation code. In the current model, the parachain manager is responsible for reserving a unique <code>ParaId</code> and covering the cost of storing the validation code of the parachain. These costs can escalate, particularly if the validation code is large. We need a better, sustainable model for registering on-demand parachains on Polkadot to help smaller teams deploy more easily.</p>
<p>This RFC suggests a new payment model to create a more financially viable approach to on-demand parachain registration. In this model, a lower initial deposit is required, followed by recurring payments upon parachain registration.</p>
<p>This new model will coexist with the existing one-time deposit payment model, offering teams seeking to deploy on-demand parachains on Polkadot a more cost-effective alternative.</p>
<h2 id="requirements-1"><a class="header" href="#requirements-1">Requirements</a></h2>
<ol>
<li>The solution SHOULD NOT affect the current model for registering validation code.</li>
<li>The solution SHOULD offer an easily configurable way for governance to adjust the initial deposit and recurring rent cost.</li>
<li>The solution SHOULD provide an incentive to prune validation code for which rent is not paid.</li>
<li>The solution SHOULD allow anyone to re-register validation code under the same <code>ParaId</code> without the need for redundant pre-checking if it was already verified before.</li>
<li>The solution MUST be compatible with the Agile Coretime model, as described in RFC#0001</li>
<li>The solution MUST allow anyone to pay the rent.</li>
<li>The solution MUST prevent the removal of validation code if it could still be required for disputes or approval checking.</li>
</ol>
<h2 id="stakeholders-6"><a class="header" href="#stakeholders-6">Stakeholders</a></h2>
<ul>
<li>Future Polkadot on-demand Parachains</li>
</ul>
<h2 id="explanation-6"><a class="header" href="#explanation-6">Explanation</a></h2>
<p>This RFC proposes a set of changes that will enable the new rent based approach to registering and storing validation code on-chain.
The new model, compared to the current one, will require periodic rent payments. The parachain won't be pruned automatically if the rent is not paid, but by permitting anyone to prune the parachain and rewarding the caller, there will be an incentive for the removal of the validation code.</p>
<p>On-demand parachains should still be able to utilize the current one-time payment model. However, given the size of the deposit required, it's highly likely that most on-demand parachains will opt for the new rent-based model.</p>
<p>Importantly, this solution doesn't require any storage migrations in the current system nor does it introduce any breaking changes. The following provides a detailed description of this solution.</p>
<h3 id="registering-an-on-demand-parachain"><a class="header" href="#registering-an-on-demand-parachain">Registering an on-demand parachain</a></h3>
<p>In the current implementation of the registrar pallet, there are two constants that specify the necessary deposit for parachains to register and store their validation code:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>trait Config {
// -- snip --
/// The deposit required for reserving a `ParaId`.
#[pallet::constant]
type ParaDeposit: Get&lt;BalanceOf&lt;Self&gt;&gt;;
/// The deposit to be paid per byte stored on chain.
#[pallet::constant]
type DataDepositPerByte: Get&lt;BalanceOf&lt;Self&gt;&gt;;
}
<span class="boring">}</span></code></pre></pre>
<p>This RFC proposes the addition of three new constants that will determine the payment amount and the frequency of the recurring rent payment:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>trait Config {
// -- snip --
/// Defines how frequently the rent needs to be paid.
///
/// The duration is set in sessions instead of block numbers.
#[pallet::constant]
type RentDuration: Get&lt;SessionIndex&gt;;
/// The initial deposit amount for registering validation code.
///
/// This is defined as a proportion of the deposit that would be required in the regular
/// model.
#[pallet::constant]
type RentalDepositProportion: Get&lt;Perbill&gt;;
/// The recurring rental cost defined as a proportion of the initial rental registration deposit.
#[pallet::constant]
type RentalRecurringProportion: Get&lt;Perbill&gt;;
}
<span class="boring">}</span></code></pre></pre>
<p>Users will be able to reserve a <code>ParaId</code> and register their validation code for a proportion of the regular deposit required. However, they must also make additional rent payments at intervals of <code>T::RentDuration</code>.</p>
<p>For registering using the new rental system we will have to make modifications to the <code>paras-registrar</code> pallet. We should expose two new extrinsics for this:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>mod pallet {
// -- snip --
pub fn register_rental(
origin: OriginFor&lt;T&gt;,
id: ParaId,
genesis_head: HeadData,
validation_code: ValidationCode,
) -&gt; DispatchResult { /* ... */ }
pub fn pay_rent(origin: OriginFor&lt;T&gt;, id: ParaId) -&gt; DispatchResult {
/* ... */
}
}
<span class="boring">}</span></code></pre></pre>
<p>A call to <code>register_rental</code> will require the reservation of only a percentage of the deposit that would otherwise be required to register the validation code when using the regular model.
As described later in the <em>Quick para re-registering</em> section below, we will also store the code hash of each parachain to enable faster re-registration after a parachain has been pruned. For this reason the total initial deposit amount is increased to account for that.</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>// The logic for calculating the initial deposit for parachain registered with the
// new rent-based model:
let validation_code_deposit = per_byte_fee.saturating_mul((validation_code.0.len() as u32).into());
let head_deposit = per_byte_fee.saturating_mul((genesis_head.0.len() as u32).into())
let hash_deposit = per_byte_fee.saturating_mul(HASH_SIZE);
let deposit = T::RentalDepositProportion::get().mul_ceil(validation_code_deposit)
.saturating_add(T::ParaDeposit::get())
.saturating_add(head_deposit)
.saturating_add(hash_deposit)
<span class="boring">}</span></code></pre></pre>
<p>Once the <code>ParaId</code> is reserved and the validation code is registered the rent must be periodically paid to ensure the on-demand parachain doesn't get removed from the state. The <code>pay_rent</code> extrinsic should be callable by anyone, removing the need for the parachain to depend on the parachain manager for rent payments.</p>
<h3 id="on-demand-parachain-pruning"><a class="header" href="#on-demand-parachain-pruning">On-demand parachain pruning</a></h3>
<p>If the rent is not paid, anyone has the option to prune the on-demand parachain and claim a portion of the initial deposit reserved for storing the validation code. This type of 'light' pruning only removes the validation code, while the head data and validation code hash are retained. The validation code hash is stored to allow anyone to register it again as well as to enable quicker re-registration by skipping the pre-checking process.</p>
<p>The moment the rent is no longer paid, the parachain won't be able to purchase on-demand access, meaning no new blocks are allowed. This stage is called the &quot;hibernation&quot; stage, during which all the parachain-related data is still stored on-chain, but new blocks are not permitted. The reason for this is to ensure that the validation code is available in case it is needed in the dispute or approval checking subsystems. Waiting for one entire session will be enough to ensure it is safe to deregister the parachain.</p>
<p>This means that anyone can prune the parachain only once the &quot;hibernation&quot; stage is over, which lasts for an entire session after the moment that the rent is not paid.</p>
<p>The pruning described here is a light form of pruning, since it only removes the validation code. As with all parachains, the parachain or para manager can use the <code>deregister</code> extrinsic to remove all associated state.</p>
<h3 id="ensuring-rent-is-paid"><a class="header" href="#ensuring-rent-is-paid">Ensuring rent is paid</a></h3>
<p>The <code>paras</code> pallet will be loosely coupled with the <code>para-registrar</code> pallet. This approach enables all the pallets tightly coupled with the <code>paras</code> pallet to have access to the rent status information.</p>
<p>Once the validation code is stored without having its rent paid the <code>assigner_on_demand</code> pallet will ensure that an order for that parachain cannot be placed. This is easily achievable given that the <code>assigner_on_demand</code> pallet is tightly coupled with the <code>paras</code> pallet.</p>
<h3 id="on-demand-para-re-registration"><a class="header" href="#on-demand-para-re-registration">On-demand para re-registration</a></h3>
<p>If the rent isn't paid on time, and the parachain gets pruned, the new model should provide a quick way to re-register the same validation code under the same <code>ParaId</code>. This can be achieved by skipping the pre-checking process, as the validation code hash will be stored on-chain, allowing us to easily verify that the uploaded code remains unchanged.</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>/// Stores the validation code hash for parachains that successfully completed the
/// pre-checking process.
///
/// This is stored to enable faster on-demand para re-registration in case its pvf has been earlier
/// registered and checked.
///
/// NOTE: During a runtime upgrade where the pre-checking rules change this storage map should be
/// cleared appropriately.
#[pallet::storage]
pub(super) type CheckedCodeHash&lt;T: Config&gt; =
StorageMap&lt;_, Twox64Concat, ParaId, ValidationCodeHash&gt;;
<span class="boring">}</span></code></pre></pre>
<p>To enable parachain re-registration, we should introduce a new extrinsic in the <code>paras-registrar</code> pallet that allows this. The logic of this extrinsic will be same as regular registration, with the distinction that it can be called by anyone, and the required deposit will be smaller since it only has to cover for the storage of the validation code.</p>
<h2 id="drawbacks-6"><a class="header" href="#drawbacks-6">Drawbacks</a></h2>
<p>This RFC does not alter the process of reserving a <code>ParaId</code>, and therefore, it does not propose reducing it, even though such a reduction could be beneficial.</p>
<p>Even though this RFC doesn't delve into the specifics of the configuration values for parachain registration but rather focuses on the mechanism, configuring it carelessly could lead to potential problems.</p>
<p>Since the validation code hash and head data are not removed when the parachain is pruned but only when the <code>deregister</code> extrinsic is called, the <code>T::DataDepositPerByte</code> must be set to a higher value to create a strong enough incentive for removing it from the state.</p>
<h2 id="testing-security-and-privacy-3"><a class="header" href="#testing-security-and-privacy-3">Testing, Security, and Privacy</a></h2>
<p>The implementation of this RFC will be tested on Rococo first.</p>
<p>Proper research should be conducted on setting the configuration values of the new system since these values can have great impact on the network.</p>
<p>An audit is required to ensure the implementation's correctness.</p>
<p>The proposal introduces no new privacy concerns.</p>
<h2 id="performance-ergonomics-and-compatibility-3"><a class="header" href="#performance-ergonomics-and-compatibility-3">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-3"><a class="header" href="#performance-3">Performance</a></h3>
<p>This RFC should not introduce any performance impact.</p>
<h3 id="ergonomics-2"><a class="header" href="#ergonomics-2">Ergonomics</a></h3>
<p>This RFC does not affect the current parachains, nor the parachains that intend to use the one-time payment model for parachain registration.</p>
<h3 id="compatibility-2"><a class="header" href="#compatibility-2">Compatibility</a></h3>
<p>This RFC does not break compatibility.</p>
<h2 id="prior-art-and-references-5"><a class="header" href="#prior-art-and-references-5">Prior Art and References</a></h2>
<p>Prior discussion on this topic: https://github.com/paritytech/polkadot-sdk/issues/1796</p>
<h2 id="unresolved-questions-5"><a class="header" href="#unresolved-questions-5">Unresolved Questions</a></h2>
<p>None at this time.</p>
<h2 id="future-directions-and-related-material-2"><a class="header" href="#future-directions-and-related-material-2">Future Directions and Related Material</a></h2>
<p>As noted in <a href="https://github.com/paritytech/polkadot-sdk/issues/1796">this GitHub issue</a>, we want to raise the per-byte cost of on-chain data storage. However, a substantial increase in this cost would make it highly impractical for on-demand parachains to register on Polkadot.
This RFC offers an alternative solution for on-demand parachains, ensuring that the per-byte cost increase doesn't overly burden the registration process.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/pull/54">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="proposed/0054-remove-heap-pages.html#rfc-0054-remove-the-concept-of-heap-pages-from-the-client">RFC-0054: Remove the concept of &quot;heap pages&quot; from the client</a>
<ul>
<li><a href="proposed/0054-remove-heap-pages.html#summary">Summary</a></li>
<li><a href="proposed/0054-remove-heap-pages.html#motivation">Motivation</a></li>
<li><a href="proposed/0054-remove-heap-pages.html#stakeholders">Stakeholders</a></li>
<li><a href="proposed/0054-remove-heap-pages.html#explanation">Explanation</a></li>
<li><a href="proposed/0054-remove-heap-pages.html#drawbacks">Drawbacks</a></li>
<li><a href="proposed/0054-remove-heap-pages.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="proposed/0054-remove-heap-pages.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="proposed/0054-remove-heap-pages.html#performance">Performance</a></li>
<li><a href="proposed/0054-remove-heap-pages.html#ergonomics">Ergonomics</a></li>
<li><a href="proposed/0054-remove-heap-pages.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="proposed/0054-remove-heap-pages.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="proposed/0054-remove-heap-pages.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="proposed/0054-remove-heap-pages.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0054-remove-the-concept-of-heap-pages-from-the-client"><a class="header" href="#rfc-0054-remove-the-concept-of-heap-pages-from-the-client">RFC-0054: Remove the concept of &quot;heap pages&quot; from the client</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>2023-11-24</td></tr>
<tr><td><strong>Description</strong></td><td>Remove the concept of heap pages from the client and move it to the runtime.</td></tr>
<tr><td><strong>Authors</strong></td><td>Pierre Krieger</td></tr>
</tbody></table>
</div>
<h2 id="summary-7"><a class="header" href="#summary-7">Summary</a></h2>
<p>Rather than enforce a limit to the total memory consumption on the client side by loading the value at <code>:heappages</code>, enforce that limit on the runtime side.</p>
<h2 id="motivation-7"><a class="header" href="#motivation-7">Motivation</a></h2>
<p>From the early days of Substrate up until recently, the runtime was present in two forms: the wasm runtime (wasm bytecode passed through an interpreter) and the native runtime (native code directly run by the client).</p>
<p>Since the wasm runtime has a lower amount of available memory (4 GiB maximum) compared to the native runtime, and in order to ensure sure that the wasm and native runtimes always produce the same outcome, it was necessary to clamp the amount of memory available to both runtimes to the same value.</p>
<p>In order to achieve this, a special storage key (a &quot;well-known&quot; key) <code>:heappages</code> was introduced and represents the number of &quot;wasm pages&quot; (one page equals 64kiB) of memory that are available to the memory allocator of the runtimes. If this storage key is absent, it defaults to 2048, which is 128 MiB.</p>
<p>The native runtime has since then been disappeared, but the concept of &quot;heap pages&quot; still exists. This RFC proposes a simplification to the design of Polkadot by removing the concept of &quot;heap pages&quot; as is currently known, and proposes alternative ways to achieve the goal of limiting the amount of memory available.</p>
<h2 id="stakeholders-7"><a class="header" href="#stakeholders-7">Stakeholders</a></h2>
<p>Client implementers and low-level runtime developers.</p>
<h2 id="explanation-7"><a class="header" href="#explanation-7">Explanation</a></h2>
<p>This RFC proposes the following changes to the client:</p>
<ul>
<li>The client no longer considers <code>:heappages</code> as special.</li>
<li>The memory allocator of the runtime is no longer bounded by the value of <code>:heappages</code>.</li>
</ul>
<p>With these changes, the memory available to the runtime is now only bounded by the available memory space (4 GiB), and optionally by the maximum amount of memory specified in the Wasm binary (see https://webassembly.github.io/spec/core/bikeshed/#memories%E2%91%A0). In Rust, the latter can be controlled during compilation with the flag <code>-Clink-arg=--max-memory=...</code>.</p>
<p>Since the client-side change is strictly more tolerant than before, we can perform the change immediately after the runtime has been updated, and without having to worry about backwards compatibility.</p>
<p>This RFC proposes three alternative paths (different chains might choose to follow different paths):</p>
<ul>
<li>
<p>Path A: add back the same memory limit to the runtime, like so:</p>
<ul>
<li>At initialization, the runtime loads the value of <code>:heappages</code> from the storage (using <code>ext_storage_get</code> or similar), and sets a global variable to the decoded value.</li>
<li>The runtime tracks the total amount of memory that it has allocated using its instance of <code>#[global_allocator]</code> (https://github.com/paritytech/polkadot-sdk/blob/e3242d2c1e2018395c218357046cc88caaed78f3/substrate/primitives/io/src/lib.rs#L1748-L1762). This tracking should also be added around the host functions that perform allocations.</li>
<li>If an allocation is attempted that would go over the value in the global variable, the memory allocation fails.</li>
</ul>
</li>
<li>
<p>Path B: define the memory limit using the <code>-Clink-arg=--max-memory=...</code> flag.</p>
</li>
<li>
<p>Path C: don't add anything to the runtime. This is effectively the same as setting the memory limit to ~4 GiB (compared to the current default limit of 128 MiB). This solution is viable only because we're compiling for 32bits wasm rather than for example 64bits wasm. If we ever compile for 64bits wasm, this would need to be revisited.</p>
</li>
</ul>
<p>Each parachain can choose the option that they prefer, but the author of this RFC strongly suggests either option C or B.</p>
<h2 id="drawbacks-7"><a class="header" href="#drawbacks-7">Drawbacks</a></h2>
<p>In case of path A, there is one situation where the behaviour pre-RFC is not equivalent to the one post-RFC: when a host function that performs an allocation (for example <code>ext_storage_get</code>) is called, without this RFC this allocation might fail due to reaching the maximum heap pages, while after this RFC this will always succeed.
This is most likely not a problem, as storage values aren't supposed to be larger than a few megabytes at the very maximum.</p>
<p>In the unfortunate event where the runtime runs out of memory, path B would make it more difficult to relax the memory limit, as we would need to re-upload the entire Wasm, compared to updating only <code>:heappages</code> in path A or before this RFC.
In the case where the runtime runs out of memory only in the specific event where the Wasm runtime is modified, this could brick the chain. However, this situation is no different than the thousands of other ways that a bug in the runtime can brick a chain, and there's no reason to be particularily worried about this situation in particular.</p>
<h2 id="testing-security-and-privacy-4"><a class="header" href="#testing-security-and-privacy-4">Testing, Security, and Privacy</a></h2>
<p>This RFC would reduce the chance of a consensus issue between clients.
The <code>:heappages</code> are a rather obscure feature, and it is not clear what happens in some corner cases such as the value being too large (error? clamp?) or malformed. This RFC would completely erase these questions.</p>
<h2 id="performance-ergonomics-and-compatibility-4"><a class="header" href="#performance-ergonomics-and-compatibility-4">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-4"><a class="header" href="#performance-4">Performance</a></h3>
<p>In case of path A, it is unclear how performances would be affected. Path A consists in moving client-side operations to the runtime without changing these operations, and as such performance differences are expected to be minimal. Overall, we're talking about one addition/subtraction per malloc and per free, so this is more than likely completely negligible.</p>
<p>In case of path B and C, the performance gain would be a net positive, as this RFC strictly removes things.</p>
<h3 id="ergonomics-3"><a class="header" href="#ergonomics-3">Ergonomics</a></h3>
<p>This RFC would isolate the client and runtime more from each other, making it a bit easier to reason about the client or the runtime in isolation.</p>
<h3 id="compatibility-3"><a class="header" href="#compatibility-3">Compatibility</a></h3>
<p>Not a breaking change. The runtime-side changes can be applied immediately (without even having to wait for changes in the client), then as soon as the runtime is updated, the client can be updated without any transition period. One can even consider updating the client before the runtime, as it corresponds to path C.</p>
<h2 id="prior-art-and-references-6"><a class="header" href="#prior-art-and-references-6">Prior Art and References</a></h2>
<p>None.</p>
<h2 id="unresolved-questions-6"><a class="header" href="#unresolved-questions-6">Unresolved Questions</a></h2>
<p>None.</p>
<h2 id="future-directions-and-related-material-3"><a class="header" href="#future-directions-and-related-material-3">Future Directions and Related Material</a></h2>
<p>This RFC follows the same path as https://github.com/polkadot-fellows/RFCs/pull/4 by scoping everything related to memory allocations to the runtime.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/pull/70">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="proposed/0070-x-track-kusamanetwork.html#rfc-0070-x-track-for-kusamanetwork">RFC-0070: X Track for @kusamanetwork</a>
<ul>
<li><a href="proposed/0070-x-track-kusamanetwork.html#summary">Summary</a></li>
<li><a href="proposed/0070-x-track-kusamanetwork.html#motivation">Motivation</a></li>
<li><a href="proposed/0070-x-track-kusamanetwork.html#stakeholders">Stakeholders</a></li>
<li><a href="proposed/0070-x-track-kusamanetwork.html#explanation">Explanation</a>
<ul>
<li><a href="proposed/0070-x-track-kusamanetwork.html#phase-1---track-configurations">Phase 1 - Track configurations</a></li>
<li><a href="proposed/0070-x-track-kusamanetwork.html#phase-2---establish-specs-for-x-post-track-referenda">Phase 2 - Establish Specs for X Post Track Referenda</a></li>
<li><a href="proposed/0070-x-track-kusamanetwork.html#phase-3---release-tooling--documentation">Phase 3 - Release, Tooling, &amp; Documentation</a></li>
</ul>
</li>
<li><a href="proposed/0070-x-track-kusamanetwork.html#drawbacks">Drawbacks</a></li>
<li><a href="proposed/0070-x-track-kusamanetwork.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="proposed/0070-x-track-kusamanetwork.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="proposed/0070-x-track-kusamanetwork.html#performance">Performance</a></li>
<li><a href="proposed/0070-x-track-kusamanetwork.html#ergonomics">Ergonomics</a></li>
<li><a href="proposed/0070-x-track-kusamanetwork.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="proposed/0070-x-track-kusamanetwork.html#references">References</a></li>
<li><a href="proposed/0070-x-track-kusamanetwork.html#unresolved-questions">Unresolved Questions</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0070-x-track-for-kusamanetwork"><a class="header" href="#rfc-0070-x-track-for-kusamanetwork">RFC-0070: X Track for <a href="https://x.com/kusamanetwork">@kusamanetwork</a></a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>January 29, 2024</td></tr>
<tr><td><strong>Description</strong></td><td>Add a governance track to facilitate posts on the @kusamanetwork's X account</td></tr>
<tr><td><strong>Author</strong></td><td>Adam Clay Steeber</td></tr>
</tbody></table>
</div>
<h2 id="summary-8"><a class="header" href="#summary-8">Summary</a></h2>
<p>This RFC proposes adding a trivial governance track on Kusama to facilitate X (formerly known as Twitter) posts on the <a href="https://x.com/kusamanetwork">@kusamanetwork</a> account. The technical aspect
of implementing this in the runtime is very inconsequential and straight-forward, though it might get more technical if the Fellowship wants to regulate this track
with a non-existent permission set. If this is implemented it would need to be followed up with:</p>
<ol>
<li>the establishment of specifications for proposing X posts via this track, and</li>
<li>the development of tools/processes to ensure that the content contained in referenda enacted in this track would be automatically posted on X.</li>
</ol>
<h2 id="motivation-8"><a class="header" href="#motivation-8">Motivation</a></h2>
<p>The overall motivation for this RFC is to decentralize the management of the Kusama brand/communication channel to KSM holders. This is necessary in my opinion primarily
because of the inactivity of the account in recent history, with posts spanning weeks or months apart. I am currently unaware of who/what entity manages the Kusama
X account, but if they are affiliated with Parity or W3F this proposed solution could also offload some of the legal ramifications of making (or not making)
announcements to the public regarding Kusama. While centralized control of the X account would still be present, it could become totally moot if this RFC is implemented
and the community becomes totally autonomous in the management of Kusama's X posts.</p>
<p>This solution does not cover every single communication front for Kusama, but it does cover one of the largest. It also establishes a precedent for other communication channels
that could be offloaded to openGov, provided this proof-of-concept is successful.</p>
<p>Finally, this RFC is the epitome of experimentation that Kusama is ideal for. This proposal may spark newfound excitement for Kusama and help us realize Kusama's potential
for pushing boundaries and trying new unconventional ideas.</p>
<h2 id="stakeholders-8"><a class="header" href="#stakeholders-8">Stakeholders</a></h2>
<p>This idea has not been formalized by any individual (or group of) KSM holder(s). To my knowledge the socialization of this idea is contained
entirely in <a href="https://twitter.com/AdamSteeber1/status/1750541362498302230">my recent X post here</a>, but it is possible that an idea like this one has been discussed in
other places. It appears to me that the ecosystem would welcome a change like this which is why I am taking action to formalize the discussion.</p>
<h2 id="explanation-8"><a class="header" href="#explanation-8">Explanation</a></h2>
<p>The implementation of this idea can be broken down into 3 primary phases:</p>
<h3 id="phase-1---track-configurations"><a class="header" href="#phase-1---track-configurations">Phase 1 - Track configurations</a></h3>
<p>First, we begin with this RFC to ensure all feedback can be discussed and implemented in the proposal. After the Fellowship and the community come to a reasonable
agreement on the changes necessary to make this happen, the Fellowship can merge changes into Kusama's runtime to include this new track with appropriate track configurations.
As a starting point, I recommend the following track configurations:</p>
<pre><code>const APP_X_POST: Curve = Curve::make_linear(7, 28, percent(50), percent(100));
const SUP_X_POST: Curve = Curve::make_reciprocal(?, ?, percent(?), percent(?), percent(?));
// I don't know how to configure the make_reciprocal variables to get what I imagine for support,
// but I recommend starting at 50% support and sharply decreasing such that 1% is sufficient quarterway
// through the decision period and hitting 0% at the end of the decision period, or something like that.
(
69,
pallet_referenda::TrackInfo {
name: &quot;x_post&quot;,
max_deciding: 50,
decision_deposit: 1 * UNIT,
prepare_period: 10 * MINUTES,
decision_period: 4 * DAYS,
confirm_period: 10 * MINUTES,
min_enactment_period: 1 * MINUTES,
min_approval: APP_X_POST,
min_support: SUP_X_POST,
},
),
</code></pre>
<p>I also recommend restricting permissions of this track to only submitting remarks or batches of remarks - that's all we'll need for its purpose. I'm not sure how
easy that is to configure, but it is important since we don't want such an agile track to be able to make highly consequential calls.</p>
<h3 id="phase-2---establish-specs-for-x-post-track-referenda"><a class="header" href="#phase-2---establish-specs-for-x-post-track-referenda">Phase 2 - Establish Specs for X Post Track Referenda</a></h3>
<p>It is important that we establish the specifications of referenda that will be submitted in this track to ensure that whatever automation tool is built can easily
make posts once a referendum is enacted. As stated above, we really only need a system.remark (or batch of remarks) to indicate the contents of a proposed X post.
The most straight-forward way to do this is to require remarks to adhere to X's requirements for making <a href="https://developer.twitter.com/en/docs/twitter-api/tweets/manage-tweets/api-reference/post-tweets">posts via their API</a>.</p>
<p>For example, if I wanted to propose a post that contained the text &quot;Hello World!&quot; I would propose a referendum in the X post track that contains the following call data:
<code>0x0000607b2274657874223a202248656c6c6f20576f726c6421227d</code> (i.e. <code>system.remark('{&quot;text&quot;: &quot;Hello World!&quot;}')</code>).</p>
<p>At first, we could support text posts only to prove the concept. Later on we could expand this spec to add support for media, likes, retweets, replies, polls, and
whatever other X features we want.</p>
<h3 id="phase-3---release-tooling--documentation"><a class="header" href="#phase-3---release-tooling--documentation">Phase 3 - Release, Tooling, &amp; Documentation</a></h3>
<p>Once we agree on track configurations and specs for referenda in this track, the Fellowship can move forward with merging these changes into Kusama's runtime and
include them in its next release. We could also move forward with developing the necessary tools that would listen for enacted referenda to post automatically on X.
This would require coordination with whoever controls the X account; they would either need to run the tools themselves or add a third party as an authorized user to
run the tools to make posts on the account's behalf. This is a bottleneck for decentralization, but as long as the tools are run by the X account manager or by a trusted third party
it should be fine. I'm open to more decentralized solutions, but those always come at a cost of complexity.</p>
<p>For the tools themselves, we could open a bounty on Kusama for developers/teams to bid on. We could also just ask the community to step up with a Treasury proposal
to have anyone fund the build. Or, the Fellowship could make the release of these changes contingent on their endorsement of developers/teams to build these tools. Lots of options!
For the record, me and my team could develop all the necessary tools, but all because I'm proposing these changes doesn't entitle me to funds to build the tools needed
to implement them. Here's what would be needed:</p>
<ul>
<li>a listener tool that would listen for enacted referenda in this track, verify the format of the remark(s), and submit to X's API with authenticating credentials</li>
<li>a UI to allow layman users to propose referenda on this track</li>
</ul>
<p>After everything is complete, we can update the Kusama wiki to include documentation on the X post specifications and include links to the tools/UI.</p>
<h2 id="drawbacks-8"><a class="header" href="#drawbacks-8">Drawbacks</a></h2>
<p>The main drawback to this change is that it requires a lot of off-chain coordination. It's easy enough to include the track on Kusama but it's a totally different
challenge to make it function as intended. The tools need to be built and the auth tokens need to be managed. It would certainly add an administrative burden to whoever
manages the X account since they would either need to run the tools themselves or manage auth tokens.</p>
<p>This change also introduces on-going costs to the Treasury since it would need to compensate people to support the tools necessary to facilitate this idea. The ultimate
question is whether these on-going costs would be worth the ability for KSM holders to make posts on Kusama's X account.</p>
<p>There's also the risk of misconfiguring the track to make referenda too easy to pass, potentially allowing a malicious actor to get content posted on X that violates X's ToS.
If that happens, we risk getting Kusama banned on X!</p>
<p>This change might also be outside the scope of the Fellowship/openGov. Perhaps the best solution for the X account is to have the Treasury pay for a professional
agency to manage posts. It wouldn't be decentralized but it would probably be more effective in terms of creating good content.</p>
<p>Finally, this solution is merely pseudo-decentralization since the X account manager would still have ultimate control of the account. It's decentralized insofar as
the auth tokens are given to people actually running the tools; a house of cards is required to facilitate X posts via this track. Not ideal.</p>
<h2 id="testing-security-and-privacy-5"><a class="header" href="#testing-security-and-privacy-5">Testing, Security, and Privacy</a></h2>
<p>There's major precedent for configuring tracks on openGov given the amount of power tracks have, so it shouldn't be hard to come up with a sound configuration.
That's why I recommend restricting permissions of this track to remarks and batches of remarks, or something equally inconsequential.</p>
<p>Building the tools for this implementation is really straight-forward and could be audited by Fellowship members, and the community at large, on Github.</p>
<p>The largest security concern would be the management of Kusama's X account's auth tokens. We would need to ensure that they aren't compromised.</p>
<h2 id="performance-ergonomics-and-compatibility-5"><a class="header" href="#performance-ergonomics-and-compatibility-5">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-5"><a class="header" href="#performance-5">Performance</a></h3>
<p>If a track on Kusama promises users that compliant referenda enacted therein would be posted on Kusama's X account, users would expect that track to perform as promised.
If the house of cards tumbles down and a compliant referendum doesn't actually get anything posted, users might think that Kusama is broken or unreliable. This
could be damaging to Kusama's image and cause people to question the soundness of other features on Kusama.</p>
<p>As mentioned in the drawbacks, the performance of this feature would depend on off-chain coordinations. We can reduce the administrative burden of these coordinations
by funding third parties with the Treasury to deal with it, but then we're relying on trusting these parties.</p>
<h3 id="ergonomics-4"><a class="header" href="#ergonomics-4">Ergonomics</a></h3>
<p>By adding a new track to Kusama, governance platforms like Polkassembly or Nova Wallet would need to include it on their applications. This shouldn't be too
much of a burden or overhead since they've already built the infrastructure for other openGov tracks.</p>
<h3 id="compatibility-4"><a class="header" href="#compatibility-4">Compatibility</a></h3>
<p>This change wouldn't break any compatibility as far as I know.</p>
<h2 id="references-1"><a class="header" href="#references-1">References</a></h2>
<p>One reference to a similar feature requiring on-chain/off-chain coordination would be the Kappa-Sigma-Mu Society. Nothing on-chain necessarily enforces the rules
or facilitates bids, challenges, defenses, etc. However, the Society has managed to maintain itself with integrity to its rules. So I don't think this is totally
out of Kusama's scope. But it will require some off-chain effort to maintain.</p>
<h2 id="unresolved-questions-7"><a class="header" href="#unresolved-questions-7">Unresolved Questions</a></h2>
<ul>
<li>Who will develop the tools necessary to implement this feature? How do we select them?</li>
<li>How can this idea be better implemented with on-chain/substrate features?</li>
</ul>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/pull/73">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="proposed/0073-referedum-deposit-track.html#rfc-0073-decision-deposit-referendum-track">RFC-0073: Decision Deposit Referendum Track</a>
<ul>
<li><a href="proposed/0073-referedum-deposit-track.html#summary">Summary</a></li>
<li><a href="proposed/0073-referedum-deposit-track.html#motivation">Motivation</a></li>
<li><a href="proposed/0073-referedum-deposit-track.html#explanation">Explanation</a>
<ul>
<li><a href="proposed/0073-referedum-deposit-track.html#referendum-track-parameters---polkadot">Referendum track parameters - Polkadot</a></li>
<li><a href="proposed/0073-referedum-deposit-track.html#referendum-track-parameters---kusama">Referendum track parameters - Kusama</a></li>
</ul>
</li>
<li><a href="proposed/0073-referedum-deposit-track.html#drawbacks">Drawbacks</a></li>
<li><a href="proposed/0073-referedum-deposit-track.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="proposed/0073-referedum-deposit-track.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="proposed/0073-referedum-deposit-track.html#performance">Performance</a></li>
<li><a href="proposed/0073-referedum-deposit-track.html#ergonomics">Ergonomics</a></li>
<li><a href="proposed/0073-referedum-deposit-track.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="proposed/0073-referedum-deposit-track.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="proposed/0073-referedum-deposit-track.html#unresolved-questions">Unresolved Questions</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0073-decision-deposit-referendum-track"><a class="header" href="#rfc-0073-decision-deposit-referendum-track">RFC-0073: Decision Deposit Referendum Track</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>12 February 2024</td></tr>
<tr><td><strong>Description</strong></td><td>Add a referendum track which can place the decision deposit on any other track</td></tr>
<tr><td><strong>Authors</strong></td><td>JelliedOwl</td></tr>
</tbody></table>
</div>
<h2 id="summary-9"><a class="header" href="#summary-9">Summary</a></h2>
<p>The current size of the decision deposit on some tracks is too high for many proposers. As a result, those needing to use it have to find someone else willing to put up the deposit for them - and a number of legitimate attempts to use the root track have timed out. This track would provide a more affordable (though slower) route for these holders to use the root track.</p>
<h2 id="motivation-9"><a class="header" href="#motivation-9">Motivation</a></h2>
<p>There have been recent attempts to use the Kusama root track which have timed out with no decision deposit placed. Usually, these referenda have been related to parachain registration related issues. </p>
<h2 id="explanation-9"><a class="header" href="#explanation-9">Explanation</a></h2>
<p>Propose to address this by adding a new referendum track <em><strong>[22] Referendum Deposit</strong></em> which can place the decision deposit on another referendum. This would require the following changes:</p>
<ul>
<li>[Referenda Pallet] Modify the <code>placeDecisionDesposit</code> function to additionally allow it to be called by root, with root call bypassing the requirements for a deposit payment.</li>
<li>[Runtime] Add a new referendum track which can only call <code>referenda-&gt;placeDecisionDeposit</code> and the utility functions.</li>
</ul>
<h3 id="referendum-track-parameters---polkadot"><a class="header" href="#referendum-track-parameters---polkadot">Referendum track parameters - Polkadot</a></h3>
<ul>
<li><strong>Decision deposit</strong>: 1000 DOT</li>
<li><strong>Decision period</strong>: 14 days</li>
<li><strong>Confirmation period</strong>: 12 hours</li>
<li><strong>Enactment period</strong>: 2 hour</li>
<li><strong>Approval &amp; Support curves</strong>: As per the root track, timed to match the decision period</li>
<li><strong>Maximum deciding</strong>: 10</li>
</ul>
<h3 id="referendum-track-parameters---kusama"><a class="header" href="#referendum-track-parameters---kusama">Referendum track parameters - Kusama</a></h3>
<ul>
<li><strong>Decision deposit</strong>: 33.333333 KSM</li>
<li><strong>Decision period</strong>: 7 days</li>
<li><strong>Confirmation period</strong>: 6 hours</li>
<li><strong>Enactment period</strong>: 1 hour</li>
<li><strong>Approval &amp; Support curves</strong>: As per the root track, timed to match the decision period</li>
<li><strong>Maximum deciding</strong>: 10</li>
</ul>
<h2 id="drawbacks-9"><a class="header" href="#drawbacks-9">Drawbacks</a></h2>
<p>This track would provide a route to starting a root referendum with a much-reduced slashable deposit. This might be undesirable but, assuming the decision deposit cost for this track is still high enough, slashing would still act as a disincentive.</p>
<p>An alternative to this might be to reduce the decision deposit size some of the more expensive tracks. However, part of the purpose of the high deposit - at least on the root track - is to prevent spamming the limited queue with junk referenda.</p>
<h2 id="testing-security-and-privacy-6"><a class="header" href="#testing-security-and-privacy-6">Testing, Security, and Privacy</a></h2>
<p>Will need additional tests case for the modified pallet and runtime. No security or privacy issues.</p>
<h2 id="performance-ergonomics-and-compatibility-6"><a class="header" href="#performance-ergonomics-and-compatibility-6">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-6"><a class="header" href="#performance-6">Performance</a></h3>
<p>No significant performance impact.</p>
<h3 id="ergonomics-5"><a class="header" href="#ergonomics-5">Ergonomics</a></h3>
<p>Only changes related to adding the track. Existing functionality is unchanged.</p>
<h3 id="compatibility-5"><a class="header" href="#compatibility-5">Compatibility</a></h3>
<p>No compatibility issues.</p>
<h2 id="prior-art-and-references-7"><a class="header" href="#prior-art-and-references-7">Prior Art and References</a></h2>
<ul>
<li>Recent discussion / referendum for an alternative way to address this issue: <a href="https://kusama.polkassembly.io/referenda/340">Kusama Referendum 340 - Funding a Decision Deposit Sponsor</a></li>
</ul>
<h2 id="unresolved-questions-8"><a class="header" href="#unresolved-questions-8">Unresolved Questions</a></h2>
<p>Feedback on whether my proposed implementation of this is the best way to address the issue - including which calls the track should be allowed to make. Are the track parameters correct or should be use something different? Alternative would be welcome.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/pull/74">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="proposed/0074-stateful-multisig-pallet.html#rfc-0074-stateful-multisig-pallet">RFC-0074: Stateful Multisig Pallet</a>
<ul>
<li><a href="proposed/0074-stateful-multisig-pallet.html#summary">Summary</a></li>
<li><a href="proposed/0074-stateful-multisig-pallet.html#motivation">Motivation</a>
<ul>
<li><a href="proposed/0074-stateful-multisig-pallet.html#problem">Problem</a></li>
<li><a href="proposed/0074-stateful-multisig-pallet.html#requirements">Requirements</a></li>
<li><a href="proposed/0074-stateful-multisig-pallet.html#use-cases">Use Cases</a></li>
</ul>
</li>
<li><a href="proposed/0074-stateful-multisig-pallet.html#stakeholders">Stakeholders</a></li>
<li><a href="proposed/0074-stateful-multisig-pallet.html#explanation">Explanation</a>
<ul>
<li><a href="proposed/0074-stateful-multisig-pallet.html#state-transition-functions">State Transition Functions</a></li>
<li><a href="proposed/0074-stateful-multisig-pallet.html#storagestate">Storage/State</a></li>
<li><a href="proposed/0074-stateful-multisig-pallet.html#considerations--edge-cases">Considerations &amp; Edge cases</a></li>
</ul>
</li>
<li><a href="proposed/0074-stateful-multisig-pallet.html#drawbacks">Drawbacks</a></li>
<li><a href="proposed/0074-stateful-multisig-pallet.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="proposed/0074-stateful-multisig-pallet.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="proposed/0074-stateful-multisig-pallet.html#performance">Performance</a></li>
<li><a href="proposed/0074-stateful-multisig-pallet.html#ergonomics">Ergonomics</a></li>
<li><a href="proposed/0074-stateful-multisig-pallet.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="proposed/0074-stateful-multisig-pallet.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="proposed/0074-stateful-multisig-pallet.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="proposed/0074-stateful-multisig-pallet.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0074-stateful-multisig-pallet"><a class="header" href="#rfc-0074-stateful-multisig-pallet">RFC-0074: Stateful Multisig Pallet</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>15 February 2024</td></tr>
<tr><td><strong>Description</strong></td><td>Add Enhanced Multisig Pallet to System chains</td></tr>
<tr><td><strong>Authors</strong></td><td>Abdelrahman Soliman (Boda)</td></tr>
</tbody></table>
</div>
<h2 id="summary-10"><a class="header" href="#summary-10">Summary</a></h2>
<p>A pallet to facilitate enhanced multisig accounts. The main enhancement is that we store a multisig account in the state with related info (signers, threshold,..etc). The module affords enhanced control over administrative operations such as adding/removing signers, changing the threshold, account deletion, canceling an existing proposal. Each signer can approve/reject a proposal while still exists. The proposal is <strong>not</strong> intended for migrating or getting rid of existing multisig. It's to allow both options to coexist.</p>
<p>For the rest of the RFC We use the following terms:</p>
<ul>
<li><code>proposal</code> to refer to an extrinsic that is to be dispatched from a multisig account after getting enough approvals.</li>
<li><code>Stateful Multisig</code> to refer to the proposed pallet.</li>
<li><code>Stateless Multisig</code> to refer to the current multisig pallet in polkadot-sdk.</li>
</ul>
<h2 id="motivation-10"><a class="header" href="#motivation-10">Motivation</a></h2>
<h3 id="problem"><a class="header" href="#problem">Problem</a></h3>
<p>Entities in the Polkadot ecosystem need to have a way to manage their funds and other operations in a secure and efficient way. Multisig accounts are a common way to achieve this. Entities by definition change over time, members of the entity may change, threshold requirements may change, and the multisig account may need to be deleted. For even more enhanced hierarchical control, the multisig account may need to be controlled by other multisig accounts.</p>
<p>Current native solutions for multisig operations are less optimal, performance-wise (as we'll explain later in the RFC), and lack fine-grained control over the multisig account.</p>
<h4 id="stateless-multisig"><a class="header" href="#stateless-multisig">Stateless Multisig</a></h4>
<p>We refer to current <a href="https://github.com/paritytech/polkadot-sdk/tree/master/substrate/frame/multisig">multisig pallet in polkadot-sdk</a> because the multisig account is only derived and not stored in the state. Although deriving the account is determinsitc as it relies on exact users (sorted) and thershold to derive it. This does not allow for control over the multisig account. It's also tightly coupled to exact users and threshold. This makes it hard for an organization to manage existing accounts and to change the threshold or add/remove signers.</p>
<p>We believe as well that the stateless multisig is not efficient in terms of block footprint as we'll show in the performance section.</p>
<h4 id="pure-proxy"><a class="header" href="#pure-proxy">Pure Proxy</a></h4>
<p>Pure proxy can achieve having a stored and determinstic multisig account from different users but it's unneeded complexity as a way around the limitations of the current multisig pallet. It doesn't also have the same fine grained control over the multisig account.</p>
<p>Other points mentioned by @tbaut</p>
<ul>
<li>pure proxies aren't (yet) a thing cross chain</li>
<li>the end user complexity is much much higher with pure proxies, also for new users smart contract multisig are widely known while pure proxies are obscure.</li>
<li>you can shoot yourself in the foot by deleting the proxy, and effectively loosing access to funds with pure proxies.</li>
</ul>
<h3 id="requirements-2"><a class="header" href="#requirements-2">Requirements</a></h3>
<p>Basic requirements for the Stateful Multisig are:</p>
<ul>
<li>The ability to have concrete and permanent (unless deleted) multisig accounts in the state.</li>
<li>The ability to add/remove signers from an existing multisig account by the multisig itself.</li>
<li>The ability to change the threshold of an existing multisig account by the multisig itself.</li>
<li>The ability to delete an existing multisig account by the multisig itself.</li>
<li>The ability to cancel an existing proposal by the multisig itself.</li>
<li>Signers of multisig account can start a proposal on behalf of the multisig account which will be dispatched after getting enough approvals.</li>
<li>Signers of multisig account can approve/reject a proposal while still exists.</li>
</ul>
<h3 id="use-cases"><a class="header" href="#use-cases">Use Cases</a></h3>
<ul>
<li>
<p>Corporate Governance:
In a corporate setting, multisig accounts can be employed for decision-making processes. For example, a company may require the approval of multiple executives to initiate significant financial transactions.</p>
</li>
<li>
<p>Joint Accounts:
Multisig accounts can be used for joint accounts where multiple individuals need to authorize transactions. This is particularly useful in family finances or shared business accounts.</p>
</li>
<li>
<p>Decentralized Autonomous Organizations (DAOs):
DAOs can utilize multisig accounts to ensure that decisions are made collectively. Multiple key holders can be required to approve changes to the organization's rules or the allocation of funds.</p>
</li>
</ul>
<p>and much more...</p>
<h2 id="stakeholders-9"><a class="header" href="#stakeholders-9">Stakeholders</a></h2>
<ul>
<li>Polkadot holders</li>
<li>Polkadot developers</li>
</ul>
<h2 id="explanation-10"><a class="header" href="#explanation-10">Explanation</a></h2>
<p>I've created the stateful multisig pallet during my studies in Polkadot Blockchain Academy under supervision from @shawntabrizi and @ank4n. After that, I've enhanced it to be fully functional and this is a draft <a href="https://github.com/paritytech/polkadot-sdk/pull/3300">PR#3300</a> in polkadot-sdk. I'll list all the details and design decisions in the following sections. Note that the PR is not 1-1 exactly to the current RFC as the RFC is a more polished version of the PR after updating based on the feedback and discussions.</p>
<p>Let's start with a sequence diagram to illustrate the main operations of the Stateful Multisig.</p>
<p><img src="https://github.com/asoliman92/RFCs/assets/2677789/4f2e8972-f3b8-4250-b75f-1e4788b35752" alt="multisig operations" /></p>
<p>Notes on above diagram:</p>
<ul>
<li>It's a 3 step process to execute a proposal. (Start Proposal --&gt; Approvals --&gt; Execute Proposal)</li>
<li><code>Execute</code> is an explicit extrinsic for a simpler API. It can be optimized to be executed automatically after getting enough approvals.</li>
<li>Any user can create a multisig account and they don't need to be part of it. (Alice in the diagram)</li>
<li>A proposal is any extrinsic including control extrinsics (e.g. add/remove signer, change threshold,..etc).</li>
<li>Any multisig account signer can start a proposal on behalf of the multisig account. (Bob in the diagram)</li>
<li>Any multisig account owener can execute proposal if it's approved by enough signers. (Dave in the diagram)</li>
</ul>
<h3 id="state-transition-functions"><a class="header" href="#state-transition-functions">State Transition Functions</a></h3>
<p>having the following enum to store the call or the hash:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>enum CallOrHash&lt;T: Config&gt; {
Call(&lt;T as Config&gt;::RuntimeCall),
Hash(T::Hash),
}
<span class="boring">}</span></code></pre></pre>
<ul>
<li><code>create_multisig</code> - Create a multisig account with a given threshold and initial signers. (Needs Deposit)</li>
</ul>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> /// Creates a new multisig account and attach signers with a threshold to it.
///
/// The dispatch origin for this call must be _Signed_. It is expected to be a nomral AccountId and not a
/// Multisig AccountId.
///
/// T::BaseCreationDeposit + T::PerSignerDeposit * signers.len() will be held from the caller's account.
///
/// # Arguments
///
/// - `signers`: Initial set of accounts to add to the multisig. These may be updated later via `add_signer`
/// and `remove_signer`.
/// - `threshold`: The threshold number of accounts required to approve an action. Must be greater than 0 and
/// less than or equal to the total number of signers.
///
/// # Errors
///
/// * `TooManySignatories` - The number of signatories exceeds the maximum allowed.
/// * `InvalidThreshold` - The threshold is greater than the total number of signers.
pub fn create_multisig(
origin: OriginFor&lt;T&gt;,
signers: BoundedBTreeSet&lt;T::AccountId, T::MaxSignatories&gt;,
threshold: u32,
) -&gt; DispatchResult
<span class="boring">}</span></code></pre></pre>
<ul>
<li><code>start_proposal</code> - Start a multisig proposal. (Needs Deposit)</li>
</ul>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> /// Starts a new proposal for a dispatchable call for a multisig account.
/// The caller must be one of the signers of the multisig account.
/// T::ProposalDeposit will be held from the caller's account.
///
/// # Arguments
///
/// * `multisig_account` - The multisig account ID.
/// * `call_or_hash` - The enum having the call or the hash of the call to be approved and executed later.
///
/// # Errors
///
/// * `MultisigNotFound` - The multisig account does not exist.
/// * `UnAuthorizedSigner` - The caller is not an signer of the multisig account.
/// * `TooManySignatories` - The number of signatories exceeds the maximum allowed. (shouldn't really happen as it's the first approval)
pub fn start_proposal(
origin: OriginFor&lt;T&gt;,
multisig_account: T::AccountId,
call_or_hash: CallOrHash,
) -&gt; DispatchResult
<span class="boring">}</span></code></pre></pre>
<ul>
<li><code>approve</code> - Approve a multisig proposal.</li>
</ul>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> /// Approves a proposal for a dispatchable call for a multisig account.
/// The caller must be one of the signers of the multisig account.
///
/// If a signer did approve -&gt; reject -&gt; approve, the proposal will be approved.
/// If a signer did approve -&gt; reject, the proposal will be rejected.
///
/// # Arguments
///
/// * `multisig_account` - The multisig account ID.
/// * `call_or_hash` - The enum having the call or the hash of the call to be approved.
///
/// # Errors
///
/// * `MultisigNotFound` - The multisig account does not exist.
/// * `UnAuthorizedSigner` - The caller is not an signer of the multisig account.
/// * `TooManySignatories` - The number of signatories exceeds the maximum allowed.
/// This shouldn't really happen as it's an approval, not an addition of a new signer.
pub fn approve(
origin: OriginFor&lt;T&gt;,
multisig_account: T::AccountId,
call_or_hash: CallOrHash,
) -&gt; DispatchResult
<span class="boring">}</span></code></pre></pre>
<ul>
<li><code>reject</code> - Reject a multisig proposal.</li>
</ul>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> /// Rejects a proposal for a multisig account.
/// The caller must be one of the signers of the multisig account.
///
/// Between approving and rejecting, last call wins.
/// If a signer did approve -&gt; reject -&gt; approve, the proposal will be approved.
/// If a signer did approve -&gt; reject, the proposal will be rejected.
///
/// # Arguments
///
/// * `multisig_account` - The multisig account ID.
/// * `call_or_hash` - The enum having the call or the hash of the call to be rejected.
///
/// # Errors
///
/// * `MultisigNotFound` - The multisig account does not exist.
/// * `UnAuthorizedSigner` - The caller is not an signer of the multisig account.
/// * `SignerNotFound` - The caller has not approved the proposal.
#[pallet::call_index(3)]
#[pallet::weight(Weight::default())]
pub fn reject(
origin: OriginFor&lt;T&gt;,
multisig_account: T::AccountId,
call_or_hash: CallOrHash,
) -&gt; DispatchResult
<span class="boring">}</span></code></pre></pre>
<ul>
<li><code>execute_proposal</code> - Execute a multisig proposal. (Releases Deposit)</li>
</ul>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> /// Executes a proposal for a dispatchable call for a multisig account.
/// Poropsal needs to be approved by enough signers (exceeds or equal multisig threshold) before it can be executed.
/// The caller must be one of the signers of the multisig account.
///
/// This function does an extra check to make sure that all approvers still exist in the multisig account.
/// That is to make sure that the multisig account is not compromised by removing an signer during an active proposal.
///
/// Once finished, the withheld deposit will be returned to the proposal creator.
///
/// # Arguments
///
/// * `multisig_account` - The multisig account ID.
/// * `call_or_hash` - We should have gotten the RuntimeCall (preimage) and stored it in the proposal by the time the extrinsic is called.
///
/// # Errors
///
/// * `MultisigNotFound` - The multisig account does not exist.
/// * `UnAuthorizedSigner` - The caller is not an signer of the multisig account.
/// * `NotEnoughApprovers` - approvers don't exceed the threshold.
/// * `ProposalNotFound` - The proposal does not exist.
/// * `CallPreImageNotFound` - The proposal doesn't have the preimage of the call in the state.
pub fn execute_proposal(
origin: OriginFor&lt;T&gt;,
multisig_account: T::AccountId,
call_or_hash: CallOrHash,
) -&gt; DispatchResult
<span class="boring">}</span></code></pre></pre>
<ul>
<li><code>cancel_proposal</code> - Cancel a multisig proposal. (Releases Deposit)</li>
</ul>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> /// Cancels an existing proposal for a multisig account.
/// Poropsal needs to be rejected by enough signers (exceeds or equal multisig threshold) before it can be executed.
/// The caller must be one of the signers of the multisig account.
///
/// This function does an extra check to make sure that all rejectors still exist in the multisig account.
/// That is to make sure that the multisig account is not compromised by removing an signer during an active proposal.
///
/// Once finished, the withheld deposit will be returned to the proposal creator./
///
/// # Arguments
///
/// * `origin` - The origin multisig account who wants to cancel the proposal.
/// * `call_or_hash` - The call or hash of the call to be canceled.
///
/// # Errors
///
/// * `MultisigNotFound` - The multisig account does not exist.
/// * `ProposalNotFound` - The proposal does not exist.
pub fn cancel_proposal(
origin: OriginFor&lt;T&gt;,
multisig_account: T::AccountId,
call_or_hash: CallOrHash) -&gt; DispatchResult
<span class="boring">}</span></code></pre></pre>
<ul>
<li><code>cancel_own_proposal</code> - Cancel a multisig proposal started by the caller in case no other signers approved it yet. (Releases Deposit)</li>
</ul>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> /// Cancels an existing proposal for a multisig account Only if the proposal doesn't have approvers other than
/// the proposer.
///
/// This function needs to be called from a the proposer of the proposal as the origin.
///
/// The withheld deposit will be returned to the proposal creator.
///
/// # Arguments
///
/// * `multisig_account` - The multisig account ID.
/// * `call_or_hash` - The hash of the call to be canceled.
///
/// # Errors
///
/// * `MultisigNotFound` - The multisig account does not exist.
/// * `ProposalNotFound` - The proposal does not exist.
pub fn cancel_own_proposal(
origin: OriginFor&lt;T&gt;,
multisig_account: T::AccountId,
call_or_hash: CallOrHash,
) -&gt; DispatchResult
<span class="boring">}</span></code></pre></pre>
<ul>
<li><code>cleanup_proposals</code> - Cleanup proposals of a multisig account. (Releases Deposit)</li>
</ul>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> /// Cleanup proposals of a multisig account. This function will iterate over a max limit per extrinsic to ensure
/// we don't have unbounded iteration over the proposals.
///
/// The withheld deposit will be returned to the proposal creator.
///
/// # Arguments
///
/// * `multisig_account` - The multisig account ID.
///
/// # Errors
///
/// * `MultisigNotFound` - The multisig account does not exist.
/// * `ProposalNotFound` - The proposal does not exist.
pub fn cleanup_proposals(
origin: OriginFor&lt;T&gt;,
multisig_account: T::AccountId,
) -&gt; DispatchResult
<span class="boring">}</span></code></pre></pre>
<p>Note: Next functions need to be called from the multisig account itself. Deposits are reserved from the multisig account as well.</p>
<ul>
<li><code>add_signer</code> - Add a new signer to a multisig account. (Needs Deposit)</li>
</ul>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> /// Adds a new signer to the multisig account.
/// This function needs to be called from a Multisig account as the origin.
/// Otherwise it will fail with MultisigNotFound error.
///
/// T::PerSignerDeposit will be held from the multisig account.
///
/// # Arguments
///
/// * `origin` - The origin multisig account who wants to add a new signer to the multisig account.
/// * `new_signer` - The AccountId of the new signer to be added.
/// * `new_threshold` - The new threshold for the multisig account after adding the new signer.
///
/// # Errors
/// * `MultisigNotFound` - The multisig account does not exist.
/// * `InvalidThreshold` - The threshold is greater than the total number of signers or is zero.
/// * `TooManySignatories` - The number of signatories exceeds the maximum allowed.
pub fn add_signer(
origin: OriginFor&lt;T&gt;,
new_signer: T::AccountId,
new_threshold: u32,
) -&gt; DispatchResult
<span class="boring">}</span></code></pre></pre>
<ul>
<li><code>remove_signer</code> - Remove an signer from a multisig account. (Releases Deposit)</li>
</ul>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> /// Removes an signer from the multisig account.
/// This function needs to be called from a Multisig account as the origin.
/// Otherwise it will fail with MultisigNotFound error.
/// If only one signer exists and is removed, the multisig account and any pending proposals for this account will be deleted from the state.
///
/// # Arguments
///
/// * `origin` - The origin multisig account who wants to remove an signer from the multisig account.
/// * `signer_to_remove` - The AccountId of the signer to be removed.
/// * `new_threshold` - The new threshold for the multisig account after removing the signer. Accepts zero if
/// the signer is the only one left.kkk
///
/// # Errors
///
/// This function can return the following errors:
///
/// * `MultisigNotFound` - The multisig account does not exist.
/// * `InvalidThreshold` - The new threshold is greater than the total number of signers or is zero.
/// * `UnAuthorizedSigner` - The caller is not an signer of the multisig account.
pub fn remove_signer(
origin: OriginFor&lt;T&gt;,
signer_to_remove: T::AccountId,
new_threshold: u32,
) -&gt; DispatchResult
<span class="boring">}</span></code></pre></pre>
<ul>
<li><code>set_threshold</code> - Change the threshold of a multisig account.</li>
</ul>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> /// Sets a new threshold for a multisig account.
/// This function needs to be called from a Multisig account as the origin.
/// Otherwise it will fail with MultisigNotFound error.
///
/// # Arguments
///
/// * `origin` - The origin multisig account who wants to set the new threshold.
/// * `new_threshold` - The new threshold to be set.
/// # Errors
///
/// * `MultisigNotFound` - The multisig account does not exist.
/// * `InvalidThreshold` - The new threshold is greater than the total number of signers or is zero.
set_threshold(origin: OriginFor&lt;T&gt;, new_threshold: u32) -&gt; DispatchResult
<span class="boring">}</span></code></pre></pre>
<ul>
<li><code>delete_multisig</code> - Delete a multisig account. (Releases Deposit)</li>
</ul>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> /// Deletes a multisig account and all related proposals.
///
/// This function needs to be called from a Multisig account as the origin.
/// Otherwise it will fail with MultisigNotFound error.
///
/// # Arguments
///
/// * `origin` - The origin multisig account who wants to cancel the proposal.
///
/// # Errors
///
/// * `MultisigNotFound` - The multisig account does not exist.
pub fn delete_account(origin: OriginFor&lt;T&gt;) -&gt; DispatchResult
<span class="boring">}</span></code></pre></pre>
<h3 id="storagestate"><a class="header" href="#storagestate">Storage/State</a></h3>
<ul>
<li>Use 2 main storage maps to store mutlisig accounts and proposals.</li>
</ul>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>#[pallet::storage]
pub type MultisigAccount&lt;T: Config&gt; = StorageMap&lt;_, Twox64Concat, T::AccountId, MultisigAccountDetails&lt;T&gt;&gt;;
/// The set of open multisig proposals. A proposal is uniquely identified by the multisig account and the call hash.
/// (maybe a nonce as well in the future)
#[pallet::storage]
pub type PendingProposals&lt;T: Config&gt; = StorageDoubleMap&lt;
_,
Twox64Concat,
T::AccountId, // Multisig Account
Blake2_128Concat,
T::Hash, // Call Hash
MultisigProposal&lt;T&gt;,
&gt;;
<span class="boring">}</span></code></pre></pre>
<p>As for the values:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>pub struct MultisigAccountDetails&lt;T: Config&gt; {
/// The signers of the multisig account. This is a BoundedBTreeSet to ensure faster operations (add, remove).
/// As well as lookups and faster set operations to ensure approvers is always a subset from signers. (e.g. in case of removal of an signer during an active proposal)
pub signers: BoundedBTreeSet&lt;T::AccountId, T::MaxSignatories&gt;,
/// The threshold of approvers required for the multisig account to be able to execute a call.
pub threshold: u32,
pub deposit: BalanceOf&lt;T&gt;,
}
<span class="boring">}</span></code></pre></pre>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>pub struct MultisigProposal&lt;T: Config&gt; {
/// Proposal creator.
pub creator: T::AccountId,
pub creation_deposit: BalanceOf&lt;T&gt;,
/// The extrinsic when the multisig operation was opened.
pub when: Timepoint&lt;BlockNumberFor&lt;T&gt;&gt;,
/// The approvers achieved so far, including the depositor.
/// The approvers are stored in a BoundedBTreeSet to ensure faster lookup and operations (approve, reject).
/// It's also bounded to ensure that the size don't go over the required limit by the Runtime.
pub approvers: BoundedBTreeSet&lt;T::AccountId, T::MaxSignatories&gt;,
/// The rejectors for the proposal so far.
/// The rejectors are stored in a BoundedBTreeSet to ensure faster lookup and operations (approve, reject).
/// It's also bounded to ensure that the size don't go over the required limit by the Runtime.
pub rejectors: BoundedBTreeSet&lt;T::AccountId, T::MaxSignatories&gt;,
/// The block number until which this multisig operation is valid. None means no expiry.
pub expire_after: Option&lt;BlockNumberFor&lt;T&gt;&gt;,
}
<span class="boring">}</span></code></pre></pre>
<p>For optimization we're using BoundedBTreeSet to allow for efficient lookups and removals. Especially in the case of approvers, we need to be able to remove an approver from the list when they reject their approval. (which we do lazily when <code>execute_proposal</code> is called).</p>
<p>There's an extra storage map for the deposits of the multisig accounts per signer added. This is to ensure that we can release the deposits when the multisig removes them even if the constant deposit per signer changed in the runtime later on.</p>
<h3 id="considerations--edge-cases"><a class="header" href="#considerations--edge-cases">Considerations &amp; Edge cases</a></h3>
<h4 id="removing-an-signer-from-the-multisig-account-during-an-active-proposal"><a class="header" href="#removing-an-signer-from-the-multisig-account-during-an-active-proposal">Removing an signer from the multisig account during an active proposal</a></h4>
<p>We need to ensure that the approvers are always a subset from signers. This is also partially why we're using BoundedBTreeSet for signers and approvers. Once execute proposal is called we ensure that the proposal is still valid and the approvers are still a subset from current signers.</p>
<h4 id="multisig-account-deletion-and-cleaning-up-existing-proposals"><a class="header" href="#multisig-account-deletion-and-cleaning-up-existing-proposals">Multisig account deletion and cleaning up existing proposals</a></h4>
<p>Once the last signer of a multisig account is removed or the multisig approved the account deletion we delete the multisig accound from the state and keep the proposals until someone calls <code>cleanup_proposals</code> multiple times which iterates over a max limit per extrinsic. This is to ensure we don't have unbounded iteration over the proposals. Users are already incentivized to call <code>cleanup_proposals</code> to get their deposits back.</p>
<h4 id="multisig-account-deletion-and-existing-deposits"><a class="header" href="#multisig-account-deletion-and-existing-deposits">Multisig account deletion and existing deposits</a></h4>
<p>We currently just delete the account without checking for deposits (Would like to hear your thoughts here). We can either</p>
<ul>
<li>Don't make deposits to begin with and make it a fee.</li>
<li>Transfer to treasury.</li>
<li>Error on deletion. (don't like this)</li>
</ul>
<h4 id="approving-a-proposal-after-the-threshold-is-changed"><a class="header" href="#approving-a-proposal-after-the-threshold-is-changed">Approving a proposal after the threshold is changed</a></h4>
<p>We always use latest threshold and don't store each proposal with different threshold. This allows the following:</p>
<ul>
<li>In case threshold is lower than the number of approvers then the proposal is still valid.</li>
<li>In case threshold is higher than the number of approvers then we catch it during execute proposal and error.</li>
</ul>
<h2 id="drawbacks-10"><a class="header" href="#drawbacks-10">Drawbacks</a></h2>
<ul>
<li>New pallet to maintain.</li>
</ul>
<h2 id="testing-security-and-privacy-7"><a class="header" href="#testing-security-and-privacy-7">Testing, Security, and Privacy</a></h2>
<p>Standard audit/review requirements apply.</p>
<h2 id="performance-ergonomics-and-compatibility-7"><a class="header" href="#performance-ergonomics-and-compatibility-7">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-7"><a class="header" href="#performance-7">Performance</a></h3>
<p>Doing back of the envelop calculation to proof that the stateful multisig is more efficient than the stateless multisig given it's smaller footprint size on blocks.</p>
<p>Quick review over the extrinsics for both as it affects the block size:</p>
<p>Stateless Multisig:
Both <code>as_multi</code> and <code>approve_as_multi</code> has a similar parameters:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>origin: OriginFor&lt;T&gt;,
threshold: u16,
other_signatories: Vec&lt;T::AccountId&gt;,
maybe_timepoint: Option&lt;Timepoint&lt;BlockNumberFor&lt;T&gt;&gt;&gt;,
call_hash: [u8; 32],
max_weight: Weight,
<span class="boring">}</span></code></pre></pre>
<p>Stateful Multisig:
We have the following extrinsics:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>pub fn start_proposal(
origin: OriginFor&lt;T&gt;,
multisig_account: T::AccountId,
call_or_hash: CallOrHash,
)
<span class="boring">}</span></code></pre></pre>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>pub fn approve(
origin: OriginFor&lt;T&gt;,
multisig_account: T::AccountId,
call_or_hash: CallOrHash,
)
<span class="boring">}</span></code></pre></pre>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>pub fn execute_proposal(
origin: OriginFor&lt;T&gt;,
multisig_account: T::AccountId,
call_or_hash: CallOrHash,
)
<span class="boring">}</span></code></pre></pre>
<p>The main takeway is that we don't need to pass the threshold and other signatories in the extrinsics. This is because we already have the threshold and signatories in the state (only once).</p>
<p>So now for the caclulations, given the following:</p>
<ul>
<li>K is the number of multisig accounts.</li>
<li>N is number of signers in each multisig account.</li>
<li>For each proposal we need to have 2N/3 approvals.</li>
</ul>
<p>The table calculates if each of the K multisig accounts has one proposal and it gets approved by the 2N/3 and then executed. How much did the total Blocks and States sizes increased by the end of the day.</p>
<p>Note: We're not calculating the cost of proposal as both in statefull and stateless multisig they're almost the same and gets cleaned up from the state once the proposal is executed or canceled.</p>
<p>Stateless effect on blocksizes = 2/3<em>K</em>N^2 (as each user of the 2/3 users will need to call approve_as_multi with all the other signatories(N) in extrinsic body)</p>
<p>Stateful effect on blocksizes = K * N (as each user will need to call approve with the multisig account only in extrinsic body)</p>
<p>Stateless effect on statesizes = Nil (as the multisig account is not stored in the state)</p>
<p>Stateful effect on statesizes = K*N (as each multisig account (K) will be stored with all the signers (K) in the state)</p>
<div class="table-wrapper"><table><thead><tr><th>Pallet</th><th style="text-align: center">Block Size</th><th style="text-align: right">State Size</th></tr></thead><tbody>
<tr><td>Stateless</td><td style="text-align: center">2/3<em>K</em>N^2</td><td style="text-align: right">Nil</td></tr>
<tr><td>Stateful</td><td style="text-align: center">K*N</td><td style="text-align: right">K*N</td></tr>
</tbody></table>
</div>
<p>Simplified table removing K from the equation:
| Pallet | Block Size | State Size |
|----------------|:-------------:|-----------:|
| Stateless | N^2 | Nil |
| Stateful | N | N |</p>
<p>So even though the stateful multisig has a larger state size, it's still more efficient in terms of block size and total footprint on the blockchain.</p>
<h3 id="ergonomics-6"><a class="header" href="#ergonomics-6">Ergonomics</a></h3>
<p>The Stateful Multisig will have better ergonomics for managing multisig accounts for both developers and end-users.</p>
<h3 id="compatibility-6"><a class="header" href="#compatibility-6">Compatibility</a></h3>
<p>This RFC is compatible with the existing implementation and can be handled via upgrades and migration. It's not intended to replace the existing multisig pallet.</p>
<h2 id="prior-art-and-references-8"><a class="header" href="#prior-art-and-references-8">Prior Art and References</a></h2>
<p><a href="https://github.com/paritytech/polkadot-sdk/tree/master/substrate/frame/multisig">multisig pallet in polkadot-sdk</a></p>
<h2 id="unresolved-questions-9"><a class="header" href="#unresolved-questions-9">Unresolved Questions</a></h2>
<ul>
<li>On account deletion, should we transfer remaining deposits to treasury or remove signers' addition deposits completely and consider it as fees to start with?</li>
</ul>
<h2 id="future-directions-and-related-material-4"><a class="header" href="#future-directions-and-related-material-4">Future Directions and Related Material</a></h2>
<ul>
<li><input disabled="" type="checkbox"/>
Batch addition/removal of signers.</li>
<li><input disabled="" type="checkbox"/>
Add expiry to proposals. After a certain time, proposals will not accept any more approvals or executions and will be deleted.</li>
<li><input disabled="" type="checkbox"/>
Implement call filters. This will allow multisig accounts to only accept certain calls.</li>
</ul>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/pull/77">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="proposed/0077-increase-max-length-of-identity-pgp-fingerprint-value.html#rfc-0077-increase-maximum-length-of-identity-pgp-fingerprint-values-from-20-bytes">RFC-0077: Increase maximum length of identity PGP fingerprint values from 20 bytes</a>
<ul>
<li><a href="proposed/0077-increase-max-length-of-identity-pgp-fingerprint-value.html#summary">Summary</a></li>
<li><a href="proposed/0077-increase-max-length-of-identity-pgp-fingerprint-value.html#motivation">Motivation</a>
<ul>
<li><a href="proposed/0077-increase-max-length-of-identity-pgp-fingerprint-value.html#background">Background</a></li>
<li><a href="proposed/0077-increase-max-length-of-identity-pgp-fingerprint-value.html#problem">Problem</a></li>
<li><a href="proposed/0077-increase-max-length-of-identity-pgp-fingerprint-value.html#solution-requirements">Solution Requirements</a></li>
</ul>
</li>
<li><a href="proposed/0077-increase-max-length-of-identity-pgp-fingerprint-value.html#stakeholders">Stakeholders</a></li>
<li><a href="proposed/0077-increase-max-length-of-identity-pgp-fingerprint-value.html#explanation">Explanation</a></li>
<li><a href="proposed/0077-increase-max-length-of-identity-pgp-fingerprint-value.html#drawbacks">Drawbacks</a></li>
<li><a href="proposed/0077-increase-max-length-of-identity-pgp-fingerprint-value.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="proposed/0077-increase-max-length-of-identity-pgp-fingerprint-value.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="proposed/0077-increase-max-length-of-identity-pgp-fingerprint-value.html#performance">Performance</a></li>
<li><a href="proposed/0077-increase-max-length-of-identity-pgp-fingerprint-value.html#ergonomics">Ergonomics</a></li>
<li><a href="proposed/0077-increase-max-length-of-identity-pgp-fingerprint-value.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="proposed/0077-increase-max-length-of-identity-pgp-fingerprint-value.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="proposed/0077-increase-max-length-of-identity-pgp-fingerprint-value.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="proposed/0077-increase-max-length-of-identity-pgp-fingerprint-value.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0077-increase-maximum-length-of-identity-pgp-fingerprint-values-from-20-bytes"><a class="header" href="#rfc-0077-increase-maximum-length-of-identity-pgp-fingerprint-values-from-20-bytes">RFC-0077: Increase maximum length of identity PGP fingerprint values from 20 bytes</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>20 Feb 2024</td></tr>
<tr><td><strong>Description</strong></td><td>Increase the maximum length of identity PGP fingerprint values from 20 bytes</td></tr>
<tr><td><strong>Authors</strong></td><td>Luke Schoen</td></tr>
</tbody></table>
</div>
<h2 id="summary-11"><a class="header" href="#summary-11">Summary</a></h2>
<p>This proposes to increase the maximum length of PGP Fingerprint values from a 20 bytes/chars limit to a 40 bytes/chars limit.</p>
<h2 id="motivation-11"><a class="header" href="#motivation-11">Motivation</a></h2>
<h3 id="background"><a class="header" href="#background">Background</a></h3>
<p>Pretty Good Privacy (PGP) Fingerprints are shorter versions of their corresponding Public Key that may be printed on a business card.</p>
<p>They may be used by someone to validate the correct corresponding Public Key.</p>
<p>It should be possible to add PGP Fingerprints to Polkadot on-chain identities.</p>
<p>GNU Privacy Guard (GPG) is compliant with PGP and the two acronyms are used interchangeably.</p>
<h3 id="problem-1"><a class="header" href="#problem-1">Problem</a></h3>
<p>If you want to set a Polkadot on-chain identity, users may provide a PGP Fingerprint value in the &quot;pgpFingerprint&quot; field, which may be longer than 20 bytes/chars (e.g. PGP Fingerprints are 40 bytes/chars long), however that field can only store a maximum length of 20 bytes/chars of information.</p>
<p>Possible disadvantages of the current 20 bytes/chars limitation:</p>
<ul>
<li>Discourages users from using the &quot;pgpFingerprint&quot; field.</li>
<li>Discourages users from using Polkadot on-chain identities for Web2 and Web3 dApp software releases where the latest &quot;pgpFingerprint&quot; field could be used to verify the correct PGP Fingerprint that has been used to sign the software releases so users that download the software know that it was from a trusted source.</li>
<li>Encourages dApps to link to Web2 sources to allow their users verify the correct fingerprint associated with software releases, rather than to use the Web3 Polkadot on-chain identity &quot;pgpFingerprint&quot; field of the releaser of the software, since it may be the case that the &quot;pgpFingerprint&quot; field of most on-chain identities is not widely used due to the maximum length of 20 bytes/chars restriction.</li>
<li>Discourages users from setting an on-chain identity by creating an extrinsic using Polkadot.js with <code>identity</code> &gt; <code>setIdentity(info)</code>, since if they try to provide their 40 character long PGP Fingerprint or GPG Fingerprint, which is longer than the maximum length of 20 bytes/chars, they will encounter an error.</li>
<li>Discourages users from using on-chain Web3 registrars to judge on-chain identity fields, where the shortest value they are able to generate for a &quot;pgpFingerprint&quot; is not less than or equal to the maximum length of 20 bytes.</li>
</ul>
<h3 id="solution-requirements"><a class="header" href="#solution-requirements">Solution Requirements</a></h3>
<p>The maximum length of identity PGP Fingerprint values should be increased from the current 20 bytes/chars limit at least a 40 bytes/chars limit to support PGP Fingerprints and GPG Fingerprints.</p>
<h2 id="stakeholders-10"><a class="header" href="#stakeholders-10">Stakeholders</a></h2>
<ul>
<li>Any Polkadot account holder wishing to use a Polkadot on-chain identity for their:
<ul>
<li>PGP Fingerprints that are longer than 32 characters</li>
<li>GPG Fingerprints that are longer than 32 characters</li>
</ul>
</li>
</ul>
<h2 id="explanation-11"><a class="header" href="#explanation-11">Explanation</a></h2>
<p>If a user tries to setting an on-chain identity by creating an extrinsic using Polkadot.js with <code>identity</code> &gt; <code>setIdentity(info)</code>, then if they try to provide their 40 character long PGP Fingerprint or GPG Fingerprint, which is longer than the maximum length of 20 bytes/chars <code>[u8;20]</code>, then they will encounter this error:</p>
<pre><code>createType(Call):: Call: failed decoding identity.setIdentity:: Struct: failed on args: {...}:: Struct: failed on pgpFingerprint: Option&lt;[u8;20]&gt;:: Expected input with 20 bytes (160 bits), found 40 bytes
</code></pre>
<p>Increasing maximum length of identity PGP Fingerprint values from the current 20 bytes/chars limit to at least a 40 bytes/chars limit would overcome these errors and support PGP Fingerprints and GPG Fingerprints, satisfying the solution requirements.</p>
<h2 id="drawbacks-11"><a class="header" href="#drawbacks-11">Drawbacks</a></h2>
<p>No drawbacks have been identified.</p>
<h2 id="testing-security-and-privacy-8"><a class="header" href="#testing-security-and-privacy-8">Testing, Security, and Privacy</a></h2>
<p>Implementations would be tested for adherance by checking that 40 bytes/chars PGP Fingerprints are supported.</p>
<p>No effect on security or privacy has been identified than already exists.</p>
<p>No implementation pitfalls have been identified.</p>
<h2 id="performance-ergonomics-and-compatibility-8"><a class="header" href="#performance-ergonomics-and-compatibility-8">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-8"><a class="header" href="#performance-8">Performance</a></h3>
<p>It would be an optimization, since the associated exposed interfaces to developers and end-users could start being used.</p>
<p>To minimize additional overhead the proposal suggests a 40 bytes/chars limit since that would at least provide support for PGP Fingerprints, satisfying the solution requirements.</p>
<h3 id="ergonomics-7"><a class="header" href="#ergonomics-7">Ergonomics</a></h3>
<p>No potential ergonomic optimizations have been identified. </p>
<h3 id="compatibility-7"><a class="header" href="#compatibility-7">Compatibility</a></h3>
<p>Updates to Polkadot.js Apps, API and its documentation and those referring to it may be required.</p>
<h2 id="prior-art-and-references-9"><a class="header" href="#prior-art-and-references-9">Prior Art and References</a></h2>
<p>No prior articles or references.</p>
<h2 id="unresolved-questions-10"><a class="header" href="#unresolved-questions-10">Unresolved Questions</a></h2>
<p>No further questions at this stage.</p>
<h2 id="future-directions-and-related-material-5"><a class="header" href="#future-directions-and-related-material-5">Future Directions and Related Material</a></h2>
<p>Relates to RFC entitled &quot;Increase maximum length of identity raw data values from 32 bytes&quot;.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/pull/88">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="proposed/0088-broker-pallet-slashable-deposit-purchaser-reputation-reserved-cores.html#rfc-0088-add-slashable-locked-deposit-purchaser-reputation-and-reserved-cores-for-on-chain-identities-to-broker-pallet">RFC-0088: Add slashable locked deposit, purchaser reputation, and reserved cores for on-chain identities to broker pallet</a>
<ul>
<li><a href="proposed/0088-broker-pallet-slashable-deposit-purchaser-reputation-reserved-cores.html#summary">Summary</a></li>
<li><a href="proposed/0088-broker-pallet-slashable-deposit-purchaser-reputation-reserved-cores.html#motivation">Motivation</a>
<ul>
<li><a href="proposed/0088-broker-pallet-slashable-deposit-purchaser-reputation-reserved-cores.html#background">Background</a></li>
<li><a href="proposed/0088-broker-pallet-slashable-deposit-purchaser-reputation-reserved-cores.html#problem">Problem</a></li>
<li><a href="proposed/0088-broker-pallet-slashable-deposit-purchaser-reputation-reserved-cores.html#solution-requirements">Solution Requirements</a></li>
</ul>
</li>
<li><a href="proposed/0088-broker-pallet-slashable-deposit-purchaser-reputation-reserved-cores.html#stakeholders">Stakeholders</a></li>
<li><a href="proposed/0088-broker-pallet-slashable-deposit-purchaser-reputation-reserved-cores.html#drawbacks">Drawbacks</a>
<ul>
<li><a href="proposed/0088-broker-pallet-slashable-deposit-purchaser-reputation-reserved-cores.html#performance">Performance</a></li>
</ul>
</li>
<li><a href="proposed/0088-broker-pallet-slashable-deposit-purchaser-reputation-reserved-cores.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="proposed/0088-broker-pallet-slashable-deposit-purchaser-reputation-reserved-cores.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="proposed/0088-broker-pallet-slashable-deposit-purchaser-reputation-reserved-cores.html#performance-1">Performance</a></li>
<li><a href="proposed/0088-broker-pallet-slashable-deposit-purchaser-reputation-reserved-cores.html#ergonomics">Ergonomics</a></li>
<li><a href="proposed/0088-broker-pallet-slashable-deposit-purchaser-reputation-reserved-cores.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="proposed/0088-broker-pallet-slashable-deposit-purchaser-reputation-reserved-cores.html#prior-art-and-references">Prior Art and References</a>
<ul>
<li><a href="proposed/0088-broker-pallet-slashable-deposit-purchaser-reputation-reserved-cores.html#prior-art">Prior Art</a></li>
</ul>
</li>
<li><a href="proposed/0088-broker-pallet-slashable-deposit-purchaser-reputation-reserved-cores.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="proposed/0088-broker-pallet-slashable-deposit-purchaser-reputation-reserved-cores.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0088-add-slashable-locked-deposit-purchaser-reputation-and-reserved-cores-for-on-chain-identities-to-broker-pallet"><a class="header" href="#rfc-0088-add-slashable-locked-deposit-purchaser-reputation-and-reserved-cores-for-on-chain-identities-to-broker-pallet">RFC-0088: Add slashable locked deposit, purchaser reputation, and reserved cores for on-chain identities to broker pallet</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>25 Apr 2024</td></tr>
<tr><td><strong>Description</strong></td><td>Add slashable locked deposit, purchaser reputation, and reserved cores for on-chain identities to broker pallet</td></tr>
<tr><td><strong>Authors</strong></td><td>Luke Schoen</td></tr>
</tbody></table>
</div>
<h2 id="summary-12"><a class="header" href="#summary-12">Summary</a></h2>
<p>This proposes to require a slashable deposit in the <a href="https://github.com/paritytech/polkadot-sdk/tree/master/substrate/frame/broker">broker pallet</a> when initially purchasing or renewing Bulk Coretime or Instantaneous Coretime cores.</p>
<p>Additionally, it proposes to record a reputational status based on the behavior of the purchaser, as it relates to their use of Kusama Coretime cores that they purchase, and to possibly reserve a proportion of the cores for prospective purchasers that have an on-chain identity.</p>
<h2 id="motivation-12"><a class="header" href="#motivation-12">Motivation</a></h2>
<h3 id="background-1"><a class="header" href="#background-1">Background</a></h3>
<p>There are sales of Kusama Coretime cores that are scheduled to occur later this month by Coretime Marketplace <a href="https://www.lastic.xyz/kusama/bulkcore1">Lastic.xyz</a> initially in limited quantities, and potentially also by <a href="https://regionx.tech/">RegionX</a> in future that is subject to their <a href="https://polkadot.polkassembly.io/referenda/582">Polkadot referendum #582</a>. This poses a risk in that some Kusama Coretime core purchasers may buy Kusama Coretime cores when they have no intention of actually placing a workload on them or leasing them out, which would prevent those that wish to purchase and actually use Kusama Coretime cores from being able to use any at cores at all.</p>
<h3 id="problem-2"><a class="header" href="#problem-2">Problem</a></h3>
<p>The types of purchasers may include:</p>
<ul>
<li>Collectors (e.g. purchase a significant core such as the first core that is sold just to increase their likelihood of receiving an NFT airdrop for being one of the first purchasers).</li>
<li>Resellers (e.g. purchase a core that may be used at a popular period of time to resell closer to the date to realise a profit)</li>
<li>Market makers (e.g. buy cores just to change the floor price or volume).</li>
<li>Anti-competitive (e.g. competitor to Polkadot ecosystem purchases cores possibly in violation of anti-trust laws just to restrict access to prospective Kusama Coretime sales cores by the Kusama community that wish to do business in the Polkadot ecosystem).</li>
</ul>
<p>Chaoatic repurcussions could include the following:</p>
<ul>
<li>Generation of &quot;white elephant&quot; Kusama Coretime cores, similar to &quot;white elephant&quot; properties in the real-estate industry that never actually get used, leased or tenanted.</li>
<li>Kusama Coretime core resellers scalping the core time faster than the average core time consumer, and then choosing to use dynamic pricing that causes prices to fluctuate based on demand.</li>
<li>Resellers that own the Kusama Coretime scalping organisations may actually turn out to be the Official Kusama Coretime sellers.</li>
<li>Official Kusama Coretime sellers may establish a monopoly on the market and abuse that power by charging exhorbitant additional charge fees for each purchase, since they could then increase their floor prices even more, pretending that there are fewer cores available and more demand to make extra profits from their scalping organisations, similar to how it occurred in these <a href="https://www.rollingstone.com/pro/news/ticketmaster-cheating-scalpers-726353/">concert ticket sales</a>. This could caused Kusama Coretime costs to be no longer be affordable to the Kusama community.</li>
<li>Official Kusama Coretime sellers may run pre-sale events, but their websites may not be able to unable to handle the traffic and crash multiple times, causing them to end up cancelling those pre-sales and the pre-sale registrants missing out on getting a core that way, which would then cause available Kusama Coretime cores to be bought and resold at a higher price on third-party sites.</li>
<li>The scalping activity may be illegal in some jurisdictions and raise anti-trust issues similar to the Taylor Swift debacle over concert tickets.</li>
</ul>
<h3 id="solution-requirements-1"><a class="header" href="#solution-requirements-1">Solution Requirements</a></h3>
<ol>
<li>
<p><strong>On-chain identity</strong>. It may be possible to circumvent bots and scalpers to an extent by requiring a proportion of Kusama Coretime purchasers to have an on-chain identity. As such, a possible solution could be to allow the configuration of a threshold in the Broker pallet that reserves a proportion of the cores for accounts that have an on-chain identity, that reverts to a waiting list of anonymous account purchasers if the reserved proportion of cores remain unsold.</p>
</li>
<li>
<p><strong>Slashable deposit</strong>. A viable solution could be to require a slashable deposit to be locked prior to the purchase or renewal of a core, similar to how decision deposits are used in OpenGov to prevent spam, but where if you buy a Kusama Coretime core you could be challenged by one of more collectives of fishermen to provide proof against certain criteria of how you used it, and if you fail to provide adequate evidence in response to that scrutiny, then you would lose a proportion of that deposit and face restrictions on purchasing or renewing cores in future that may also be configured on-chain.</p>
</li>
<li>
<p><strong>Reputation</strong>. To disincentivise certain behaviours, a reputational status indicator could be used to record the historic behavior of the purchaser and whether on-chain judgement has determined they have adequately rectified that behaviour, as it relates to their usage of Kusama Coretime cores that they purchase.</p>
</li>
</ol>
<h2 id="stakeholders-11"><a class="header" href="#stakeholders-11">Stakeholders</a></h2>
<ul>
<li>Any Kusama account holder wishing to use the Broker pallet in any upcoming Kusama Coretime sales.</li>
<li>Any prospective Kusama Coretime purchaser, developer, and user.</li>
<li>KSM holders.</li>
</ul>
<h2 id="drawbacks-12"><a class="header" href="#drawbacks-12">Drawbacks</a></h2>
<h3 id="performance-9"><a class="header" href="#performance-9">Performance</a></h3>
<p>The slashable deposit if set too high, may result in an economic impact, where less Kusama Coretime core sales are purchased.</p>
<h2 id="testing-security-and-privacy-9"><a class="header" href="#testing-security-and-privacy-9">Testing, Security, and Privacy</a></h2>
<p>Lack of a slashable deposit in the Broker pallet is a security concern, since it exposes Kusama Coretime sales to potential abuse.</p>
<p>Reserving a proportion of Kusama Coretime sales cores for those with on-chain identities should not be to the exclusion of accounts that wish to remain anonymous or cause cores to be wasted unnecessarily. As such, if cores that are reserved for on-chain identities remain unsold then they should be released to anonymous accounts that are on a waiting list.</p>
<p>No implementation pitfalls have been identified.</p>
<h2 id="performance-ergonomics-and-compatibility-9"><a class="header" href="#performance-ergonomics-and-compatibility-9">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-10"><a class="header" href="#performance-10">Performance</a></h3>
<p>It should improve performance as it reduces the potential for state bloat since there is less risk of undesirable Kusama Coretime sales activity that would be apparent with no requirement for a slashable deposit or there being no reputational risk to purchasers that waste or misuse Kusama Coretime cores.</p>
<p>The solution proposes to minimize the risk of some Kusama Coretime cores not even being used or leased to perform any tasks at all.</p>
<p>It will be important to monitor and manage the slashable deposits, purchaser reputations, and utilization of the proportion of cores that are reserved for accounts with an on-chain identity.</p>
<h3 id="ergonomics-8"><a class="header" href="#ergonomics-8">Ergonomics</a></h3>
<p>The mechanism for setting a slashable deposit amount, should avoid undue complexity for users.</p>
<h3 id="compatibility-8"><a class="header" href="#compatibility-8">Compatibility</a></h3>
<p>Updates to Polkadot.js Apps, API and its documentation and those referring to it may be required.</p>
<h2 id="prior-art-and-references-10"><a class="header" href="#prior-art-and-references-10">Prior Art and References</a></h2>
<h3 id="prior-art-1"><a class="header" href="#prior-art-1">Prior Art</a></h3>
<p>No prior articles.</p>
<h2 id="unresolved-questions-11"><a class="header" href="#unresolved-questions-11">Unresolved Questions</a></h2>
<p>None</p>
<h2 id="future-directions-and-related-material-6"><a class="header" href="#future-directions-and-related-material-6">Future Directions and Related Material</a></h2>
<p>None</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/pull/89">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="proposed/0089-flexible-inflation.html#rfc-0089-flexible-inflation">RFC-0089: Flexible Inflation</a>
<ul>
<li><a href="proposed/0089-flexible-inflation.html#summary">Summary</a></li>
<li><a href="proposed/0089-flexible-inflation.html#motivation">Motivation</a></li>
<li><a href="proposed/0089-flexible-inflation.html#stakeholders">Stakeholders</a></li>
<li><a href="proposed/0089-flexible-inflation.html#explanation">Explanation</a>
<ul>
<li><a href="proposed/0089-flexible-inflation.html#existing-order">Existing Order</a></li>
<li><a href="proposed/0089-flexible-inflation.html#new-order">New Order</a></li>
<li><a href="proposed/0089-flexible-inflation.html#proposed-implementation">Proposed Implementation</a></li>
</ul>
</li>
<li><a href="proposed/0089-flexible-inflation.html#drawbacks">Drawbacks</a></li>
<li><a href="proposed/0089-flexible-inflation.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="proposed/0089-flexible-inflation.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a></li>
<li><a href="proposed/0089-flexible-inflation.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="proposed/0089-flexible-inflation.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="proposed/0089-flexible-inflation.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0089-flexible-inflation"><a class="header" href="#rfc-0089-flexible-inflation">RFC-0089: Flexible Inflation</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>May 6 2024</td></tr>
<tr><td><strong>Description</strong></td><td>Revise the inflation logic in the runtime such that it can be parameterized and tweaked in an easier and more transparent way.</td></tr>
<tr><td><strong>Authors</strong></td><td>Kian Paimani</td></tr>
</tbody></table>
</div>
<h2 id="summary-13"><a class="header" href="#summary-13">Summary</a></h2>
<p>This RFC proposes a new <code>pallet_inflation</code> to be added to the Polkadot runtime, which improves
inflation machinery of the Polkadot relay chain in a number of ways:</p>
<ol>
<li>More transparent and easier to understand inflation logic</li>
<li>Easier parameterization through governance</li>
<li>Decoupled from the staking logic, should inflation and staking happen in two disjoint consensus
systems, as proposed
<a href="https://polkadot-fellows.github.io/RFCs/approved/0032-minimal-relay.html">RFC32</a>.</li>
</ol>
<h2 id="motivation-13"><a class="header" href="#motivation-13">Motivation</a></h2>
<p>The existing inflation logic in the relay chain suffers from a number of drawbacks:</p>
<ul>
<li>It is dated, as the number of parachain slots (and consequently auctions) will soon no longer be a
factor in determining the inflation rate.</li>
<li>Is hard to parameterize through on-chain governance, as the only way to tweak the inflation amount
is through changing a particular function directly in the source code (<a href="https://github.com/polkadot-fellows/runtimes/blob/cc3beb8b2337a65e879e1d739c33e30230888267/relay/polkadot/src/lib.rs#L743-L769">example in Polkadot
runtime</a>).</li>
<li>Is deeply intertwined with the staking system, which is not an ideal design. For example, if one
wishes to know the inflation amount, an <a href="https://polkadot.subscan.io/event?page=1&amp;time_dimension=date&amp;module=staking&amp;event_id=erapaid"><code>Event</code> from the staking
system</a>
has to be interpreted, which is counter-intuitive.</li>
<li>Given all of this complexity, implementing an alteration which suggested a fixed percentage of the
inflation to go to the treasury was also <a href="https://github.com/paritytech/polkadot-sdk/pull/1660">not possible in an ergonomic
way</a>.</li>
</ul>
<p>This RFC, as iterated above, proposes a new <code>pallet_inflation</code> that addresses all of the named
problems. However, <strong>this RFC does not propose any changes to the actual inflation rate</strong>, but
rather provide a new technical substrate (pun intended), upon which token holders can decide on the
future of the DOT token's inflation in a more clear and transparent way.</p>
<p>We argue that one reason why the inflation rate of Polkadot has not significantly change in ~4 years
has been the complicated process of updating it. We hope that with the tools provided in this RFC,
stakeholders can experiment with the inflation rate in a more ergonomic way. Finally, this
experimentation can be considered useful as a final step toward fixing the economics of DOT in JAM,
as proposed in the JAM graypaper.</p>
<p>Within the scope of this RFC, we suggest deploying the new inflation pallet in a backwards
compatible way, such that the inflation model does not change in practice, and leave the actual
changes to the token holders and researchers and further governance proposals.</p>
<blockquote>
<p>While mainly intended for Polkadot, the system proposed in this RFC is general enough such that it
can be interpreted as a &quot;general inflation system pallet&quot;, and can be used in newly onboarding
parachain.</p>
</blockquote>
<h2 id="stakeholders-12"><a class="header" href="#stakeholders-12">Stakeholders</a></h2>
<p>This RFC is relevant to the following stakeholders, listed from high to low impact:</p>
<ul>
<li>All token holders who participate in governance, as they can possibly now propose (some degree of)
changes to the inflation model without any coding required. Depending on the parameters, these
changes may or may not require a particular governance track.</li>
<li>Validators and all other stakers, as the staking rate of the chain might possibly change through
the means that this pallet provides.</li>
<li>All other token holders.</li>
</ul>
<h2 id="explanation-12"><a class="header" href="#explanation-12">Explanation</a></h2>
<h3 id="existing-order"><a class="header" href="#existing-order">Existing Order</a></h3>
<p>First, let's further elaborate on the existing order. The current inflation logic is deeply nested
in <code>pallet_staking</code>, and <code>pallet_staking::Config::EraPayout</code> interface. Through this trait, the
staking pallet is informed how many new tokens should possibly be minted. This amount is divided
into two parts:</p>
<ul>
<li>an amount allocated to staking. This amount is not minted right away, and is instead minted when
the staking rewards are paid out.</li>
<li>an amount allocated to <code>pallet_staking::Config::RewardRemainder</code>, which is configured to forward
the amount to the treasury.</li>
</ul>
<p>As it stands now the implementation of <code>EraPayout</code> which specifies the two amounts above lives in
the respective runtime, and uses the original proposed inflation rate proposed by W3F for Polkadot.
Read more about this model <a href="https://wiki.polkadot.network/docs/learn-inflation">here</a>.</p>
<p>At present, the inflation always happens at the end of an <em>era</em>, which is a concept know by the
staking system. The duration of an era is recorded in <code>pallet_staking</code> as milliseconds (as recorded
by the standard <code>pallet_timestamp</code>), is passed to <code>EraPayout</code> as an input, as is measured against
the full year to determine how much should be inflated.</p>
<h3 id="new-order"><a class="header" href="#new-order">New Order</a></h3>
<blockquote>
<p>The naming used in this section is tentative, based on a WIP implementation, and subject to change
before finalization of this RFC.</p>
</blockquote>
<p>The new order splits the process for inflation into two steps:</p>
<ol>
<li><strong>Sourcing</strong> the inflation amount: This step merely specifies by how much the chain intends to
inflate its token. This amount is not minted right away, and is instead passed over to the next
step for <em>distribution</em>.</li>
<li><strong>Distributing</strong> the aforementioned amount: A sequence of functions that decide what needs to be
done with the sourced inflation amount. This process is expected to <em>transfer</em> the inflation
amount to any account that should receive it. This implies that the staking system should,
similar to treasury, have a key-less account that will act as a temporary pot for the inflation
amount.</li>
</ol>
<p>In very abstract terms, an example of the above process can be:</p>
<ul>
<li>The chain inflates its token by a fixed 10% per year, an amount called <code>i</code>.</li>
<li>Pay out 20% of <code>i</code> to the treasury account.</li>
<li>Pay out 10% of what is left of <code>i</code> to the fellowship account.</li>
<li>Pay out up to 70% of what is left of <code>i</code> to staking, depending on the staking rate.</li>
<li>Burn anything that is left.</li>
</ul>
<p>A proper configuration of this pallet should use <code>pallet_parameters</code> where possible to allow for any
of the actual values used to specify <code>Sourcing</code> and <code>Distribution</code> to be changed via on-chain
governance. Please see the <a href="proposed/0089-flexible-inflation.html#example-configurations">example configurations</a> section for more
details.</p>
<p>In the new model, inflation can happen at any point in time. Since now a new pallet is dedicated to
inflation, and it can internally store the timestamp of the last inflation point, and always inflate
the correct amount. This means that while the duration of a staking era is 1 day, the inflation
process can happen eg. every hour. The opposite is also possible, although more complicated: The
staking/treasury system can possibly receive their corresponding income on a weekly basis, while the
era duration is still 1 day. That being said, we don't recommend using this flexibility as it brings
no clear advantage, and is only extra complexity. We recommend the inflation to still happen shortly
before the end of the staking era. This means that if the inflation <code>sourcing</code> or <code>distribution</code> is
a function of the staking rate, it can reliably use the staking rate of the last era.</p>
<p>Finally, as noted above, this RFC implies a new accounting system for staking to keep track of its
staking reward. In short, the new process is as follows: <code>pallet_inflation</code> will mint the staking
portion of inflation directly into a key-less account controlled by <code>pallet_staking</code>. At the end of
each era, <code>pallet_staking</code> will inspect this account, and move whatever amount is paid out into it
to another key-less account associated with the era number. The actual payouts, initiated by stakers,
will transfer from this era account into the corresponding stakers' account.</p>
<blockquote>
<p>Interestingly, this means that any account can possibly contribute to staking rewards by
transferring DOTs to the key-less parent account controlled by the staking system.</p>
</blockquote>
<h3 id="proposed-implementation"><a class="header" href="#proposed-implementation">Proposed Implementation</a></h3>
<p>A candidate implementation of this RFC can be found in
<a href="https://github.com/paritytech/polkadot-sdk/compare/kiz-new-staking-inflation-system?expand=1">this</a>
branch of the <code>polkadot-sdk</code> repository. Please note the changes to:</p>
<ol>
<li><code>substrate/frame/inflation</code> to see the new pallet.</li>
<li><code>substrate/frame/staking</code> to see the integration with the staking pallet.</li>
<li><code>substrate/bin/runtime</code> to see how the pallet can be configured into a runtime.</li>
</ol>
<h4 id="example-configurations-1"><a class="header" href="#example-configurations-1">Example Configurations</a></h4>
<p>The following are working examples from the above implementation candidate, highlighting some of the
outcomes that can be achieved.</p>
<p>First, to parameterize the existing proposed implementation to replicate what Polkadot does today,
assuming we incorporate the fixed 2% treasury income, the outcome would be:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>parameter_types! {
pub Distribution: Vec&lt;pallet_inflation::DistributionStep&lt;Runtime&gt;&gt; = vec![
// 2% goes to treasury, no questions asked.
Box::new(pay::&lt;Runtime, TreasuryAccount, dynamic_params::staking::FixedTreasuryIncome&gt;),
// from whatever is left, staking gets all the rest, based on the staking rate.
Box::new(polkadot_staking_income::&lt;
Runtime,
dynamic_params::staking::IdealStakingRate,
dynamic_params::staking::Falloff,
StakingIncomeAccount
&gt;),
// Burn anything that is left.
Box::new(burn::&lt;Runtime, All&gt;),
];
}
impl pallet_inflation::Config for Runtime {
/// Fixed 10% annual inflation.
type InflationSource =
pallet_inflation::FixedRatioAnnualInflation&lt;Runtime, dynamic_params::staking::MaxInflation&gt;;
type Distribution = Distribution;
}
<span class="boring">}</span></code></pre></pre>
<p>In this snippet, we use a number of components provided by <code>pallet_inflation</code>, namely <code>pay</code>,
<code>polkadot_staking_income</code>, <code>burn</code> and <code>FixedRatioAnnualInflation</code>. Yet, crucially, these components
are fed parameters that are all backed by an instance of the <code>pallet_parameters</code>, namely everything
prefixed by <code>dynamic_params</code>.</p>
<p>The above is a purely inflationary system. If one wants to change the inflation to
<em>dis-inflationary</em>, another pre-made component of <code>pallet_inflation</code> can be used:</p>
<pre><code class="language-diff">impl pallet_inflation::Config for Runtime {
- /// Fixed 10% annual inflation.
- type InflationSource =
- pallet_inflation::FixedRatioAnnualInflation&lt;Runtime, dynamic_params::staking::MaxInflation&gt;;
+ type InflationSource = pallet_inflation::FixedAnnualInflation&lt;
+ Runtime,
+ dynamic_params::staking::FixedAnnualInflationAmount,
+ &gt;;
}
</code></pre>
<p>Whereby <code>FixedAnnualInflationAmount</code> is the <em>fixed</em> absolute <em>value</em> (as opposed to <em>ratio</em>) by
which the chain inflates annually, for example 100m DOTs.</p>
<h2 id="drawbacks-13"><a class="header" href="#drawbacks-13">Drawbacks</a></h2>
<p>The following drawbacks are noted:</p>
<ol>
<li>The solution provided here is possibly an over-engineering, if we want to achieve the goal of
making the existing formula parameterize-able. In that case, we can merely add an instance of the
<code>pallet_parameters</code> to the runtime and make the existing formula's ratios be provided by
governance-controlled parameters. Although, this shortsighted but simpler solution fails to
decouple the staking and inflation logic. This will be an issue depending on whether staking
lives in AssetHub, or its independent parachain.</li>
<li>Some of the interfaces proposed in the draft implementation still leak the implementation detail
of the inflation amount being reliant on eg. the staking-rate. We acknowledge this as a drawback,
but given that many PoS inflationary systems rely on the staking rate, we believe it is a
reasonable compromise. Such parameters can be ignored if the implementation does not need them.</li>
</ol>
<h2 id="testing-security-and-privacy-10"><a class="header" href="#testing-security-and-privacy-10">Testing, Security, and Privacy</a></h2>
<p>The new <code>pallet_inflation</code>, among its integration into <code>pallet_staking</code> must be thoroughly audited
and reviewed by fellows. We also emphasize on simulating the actual inflation logic using the real
polkadot state with Chopsticks and try-runtime.</p>
<h2 id="performance-ergonomics-and-compatibility-10"><a class="header" href="#performance-ergonomics-and-compatibility-10">Performance, Ergonomics, and Compatibility</a></h2>
<p>The proposed system in this RFC implies a handful of extra storage reads and writes &quot;per inflation
cycle&quot;, but given that a reasonable instance of this pallet would probably decide to inflation eg.
once per day, the performance impact is negligible.</p>
<p>The <a href="proposed/0089-flexible-inflation.html#drawbacks">drawback</a> section above noted some ergonomic concerns.</p>
<p>The <a href="proposed/0089-flexible-inflation.html#new-order">&quot;New Order&quot;</a> section above notes the compatibility notes with the existing staking
and inflation system.</p>
<h2 id="prior-art-and-references-11"><a class="header" href="#prior-art-and-references-11">Prior Art and References</a></h2>
<ul>
<li>Previous updates to the inflation system:</li>
<li><a href="https://paritytech.github.io/polkadot-sdk/master/pallet_parameters/index.html"><code>pallet_parameters</code></a></li>
<li>https://forum.polkadot.network/t/adjusting-the-current-inflation-model-to-sustain-treasury-inflow/3301</li>
</ul>
<h2 id="unresolved-questions-12"><a class="header" href="#unresolved-questions-12">Unresolved Questions</a></h2>
<ul>
<li>Whether the design proposed in this RFC is worthy of the complexity implementing and integrating
it? Note that a draft implementation already exists, yet the amount of further work needed to
integrate it is non-negligible.</li>
<li>Given that this pallet is general enough to also be used by parachain, the usage of timestamp
poses risks with regard to agile-coretime, and parachains that only use on-demand cores. Accurate
timestamps must be provided to the pallet in order to function, possibly being sourced from the
relay-chain. @ggwpez has explored issues related to on-demand core-time and time-based systems
<a href="https://github.com/paritytech/polkadot-sdk/issues/3268">here</a>.</li>
</ul>
<h2 id="future-directions-and-related-material-7"><a class="header" href="#future-directions-and-related-material-7">Future Directions and Related Material</a></h2>
<ul>
<li>If initial reaction is positive researchers and economic experts should formulate their desired
inflation parameters and systems, such that we can be sure the pallet is flexible enough in
possibly fulfilling them without an extensive amount of work needed. Given the high flexibility of
the pallet design as it stands, this is very unlikely.</li>
</ul>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/pull/94">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="proposed/00xx-secondary-marketplace-for-regions.html#rfc-0001-secondary-market-for-regions">RFC-0001: Secondary Market for Regions</a>
<ul>
<li><a href="proposed/00xx-secondary-marketplace-for-regions.html#summary">Summary</a></li>
<li><a href="proposed/00xx-secondary-marketplace-for-regions.html#motivation">Motivation</a></li>
<li><a href="proposed/00xx-secondary-marketplace-for-regions.html#stakeholders">Stakeholders</a></li>
<li><a href="proposed/00xx-secondary-marketplace-for-regions.html#explanation">Explanation</a></li>
<li><a href="proposed/00xx-secondary-marketplace-for-regions.html#drawbacks">Drawbacks</a></li>
<li><a href="proposed/00xx-secondary-marketplace-for-regions.html#testing-security-and-privacy">Testing, Security, and Privacy</a>
<ul>
<li><a href="proposed/00xx-secondary-marketplace-for-regions.html#testing">Testing</a></li>
<li><a href="proposed/00xx-secondary-marketplace-for-regions.html#security">Security</a></li>
<li><a href="proposed/00xx-secondary-marketplace-for-regions.html#privacy">Privacy</a></li>
</ul>
</li>
<li><a href="proposed/00xx-secondary-marketplace-for-regions.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="proposed/00xx-secondary-marketplace-for-regions.html#performance">Performance</a></li>
<li><a href="proposed/00xx-secondary-marketplace-for-regions.html#ergonomics">Ergonomics</a></li>
<li><a href="proposed/00xx-secondary-marketplace-for-regions.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="proposed/00xx-secondary-marketplace-for-regions.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="proposed/00xx-secondary-marketplace-for-regions.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="proposed/00xx-secondary-marketplace-for-regions.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0001-secondary-market-for-regions"><a class="header" href="#rfc-0001-secondary-market-for-regions">RFC-0001: Secondary Market for Regions</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>2024-06-09</td></tr>
<tr><td><strong>Description</strong></td><td>Implement a secondary market for region listings and sales</td></tr>
<tr><td><strong>Authors</strong></td><td><a href="https://github.com/poppyseedDev/">Aurora Poppyseed</a>, <a href="https://github.com/phillux">Philip Lucsok</a></td></tr>
</tbody></table>
</div>
<h2 id="summary-14"><a class="header" href="#summary-14">Summary</a></h2>
<p>This RFC proposes the addition of a secondary market feature to either the broker pallet or as a separate pallet maintained by Lastic, enabling users to list and purchase regions. This includes creating, purchasing, and removing listings, as well as emitting relevant events and handling associated errors.</p>
<h2 id="motivation-14"><a class="header" href="#motivation-14">Motivation</a></h2>
<p>Currently, the broker pallet lacks functionality for a secondary market, which limits users' ability to freely trade regions. This RFC aims to introduce a secure and straightforward mechanism for users to list regions they own for sale and allow other users to purchase these regions.</p>
<p>While integrating this functionality directly into the broker pallet is one option, another viable approach is to implement it as a separate pallet maintained by Lastic. This separate pallet would have access to the broker pallet and add minimal functionality necessary to support the secondary market.</p>
<p>Adding smart contracts to the Coretime chain could also address this need; however, this process is expected to be lengthy and complex. We cannot afford to wait for this extended timeline to enable basic secondary market functionality. By proposing either integration into the broker pallet or the creation of a dedicated pallet, we can quickly enhance the flexibility and utility of the broker pallet, making it more user-friendly and valuable.</p>
<h2 id="stakeholders-13"><a class="header" href="#stakeholders-13">Stakeholders</a></h2>
<p>Primary stakeholders include:</p>
<ul>
<li>Developers working on the broker pallet.</li>
<li>Secondary Coretime marketplaces.</li>
<li>Users who own regions and wish to trade them.</li>
<li>Community members interested in enhancing the broker pallets capabilities.</li>
</ul>
<h2 id="explanation-13"><a class="header" href="#explanation-13">Explanation</a></h2>
<p>This RFC introduces the following key features:</p>
<ol>
<li>
<p><strong>Storage Changes</strong>:</p>
<ul>
<li>Addition of <code>Listings</code> storage map to keep track of regions listed for sale and their prices.</li>
</ul>
</li>
<li>
<p><strong>New Dispatchable Functions</strong>:</p>
<ul>
<li><code>create_listing</code>: Allows a region owner to list a region for sale.</li>
<li><code>purchase_listing</code>: Allows a user to purchase a listed region.</li>
<li><code>remove_listing</code>: Allows a region owner to remove their listing.</li>
</ul>
</li>
<li>
<p><strong>Events</strong>:</p>
<ul>
<li><code>ListingCreated</code>: Emitted when a new listing is created.</li>
<li><code>RegionSold</code>: Emitted when a region is sold.</li>
<li><code>ListingRemoved</code>: Emitted when a listing is removed.</li>
</ul>
</li>
<li>
<p><strong>Error Handling</strong>:</p>
<ul>
<li><code>ExpiredRegion</code>: The region has expired and cannot be listed or sold.</li>
<li><code>UnknownListing</code>: The listing does not exist.</li>
<li><code>InvalidPrice</code>: The listing price is invalid.</li>
<li><code>NotOwner</code>: The caller is not the owner of the region.</li>
</ul>
</li>
<li>
<p><strong>Testing</strong>:</p>
<ul>
<li>Comprehensive tests to verify the correct functionality of the new features, including listing creation, purchase, removal, and handling of edge cases such as expired regions and unauthorized actions.</li>
</ul>
</li>
</ol>
<h2 id="drawbacks-14"><a class="header" href="#drawbacks-14">Drawbacks</a></h2>
<p>The main drawback of adding the additional complexity directly to the broker pallet is the potential increase in maintenance overhead. Therefore, we propose adding additional functionality as a separate pallet on the Coretime chain. To take the pressure off from implementing these features, implementation along with unit tests would be taken care of by Lastic (Aurora Makovac, Philip Lucsok).</p>
<p>There are potential risks of security vulnerabilities in the new market functionalities, such as unauthorized region transfers or incorrect balance adjustments. Therefore, extensive security measures would have to be implemented.</p>
<h2 id="testing-security-and-privacy-11"><a class="header" href="#testing-security-and-privacy-11">Testing, Security, and Privacy</a></h2>
<h3 id="testing"><a class="header" href="#testing">Testing</a></h3>
<ul>
<li>Comprehensive unit tests need to be provided to ensure the correctness of the new functionalities.</li>
<li>Scenarios tested should include successful and failed listing creation, purchases, and removals, as well as edge cases like expired regions and non-owner actions.</li>
</ul>
<h3 id="security"><a class="header" href="#security">Security</a></h3>
<ul>
<li>Security audits should be performed to identify any vulnerabilities.</li>
<li>Ensure that only region owners can create or remove listings.</li>
<li>Validate all inputs to prevent invalid operations.</li>
</ul>
<h3 id="privacy"><a class="header" href="#privacy">Privacy</a></h3>
<ul>
<li>The proposal does not introduce new privacy concerns as it only affects region trading functionality within the existing framework.</li>
</ul>
<h2 id="performance-ergonomics-and-compatibility-11"><a class="header" href="#performance-ergonomics-and-compatibility-11">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-11"><a class="header" href="#performance-11">Performance</a></h3>
<ul>
<li>This feature is expected to introduce minimal overhead since it primarily involves read and write operations to storage maps.</li>
<li>Efforts will be made to optimize the code to prevent unnecessary computational costs.</li>
</ul>
<h3 id="ergonomics-9"><a class="header" href="#ergonomics-9">Ergonomics</a></h3>
<ul>
<li>The new functions are designed to be intuitive and easy to use, providing clear feedback through events and errors.</li>
<li>Documentation and examples will be provided to assist developers and users.</li>
</ul>
<h3 id="compatibility-9"><a class="header" href="#compatibility-9">Compatibility</a></h3>
<ul>
<li>This proposal does not break compatibility with existing interfaces or previous versions.</li>
<li>No migrations are necessary as it introduces new functionality without altering existing features.</li>
</ul>
<h2 id="prior-art-and-references-12"><a class="header" href="#prior-art-and-references-12">Prior Art and References</a></h2>
<ul>
<li>All related discussions are going to be under this PR.</li>
</ul>
<h2 id="unresolved-questions-13"><a class="header" href="#unresolved-questions-13">Unresolved Questions</a></h2>
<ul>
<li>Are there additional security measures needed to prevent potential abuses of the new functionalities?</li>
</ul>
<h2 id="future-directions-and-related-material-8"><a class="header" href="#future-directions-and-related-material-8">Future Directions and Related Material</a></h2>
<ul>
<li>Integration with external NFT marketplaces for more robust trading options.</li>
<li>Development of user interfaces to interact with the new marketplace features seamlessly.</li>
<li>Exploration of adding smart contracts to the Coretime chain, which would provide greater flexibility and functionality for the secondary market and other decentralized applications. This would require a longer time for implementation, so this proposes an intermediary solution.</li>
</ul>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/pull/96">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="proposed/00xx-smart-contracts-coretime-chain.html#rfc-0002-smart-contracts-on-the-coretime-chain">RFC-0002: Smart Contracts on the Coretime Chain</a>
<ul>
<li><a href="proposed/00xx-smart-contracts-coretime-chain.html#summary">Summary</a></li>
<li><a href="proposed/00xx-smart-contracts-coretime-chain.html#motivation">Motivation</a></li>
<li><a href="proposed/00xx-smart-contracts-coretime-chain.html#stakeholders">Stakeholders</a></li>
<li><a href="proposed/00xx-smart-contracts-coretime-chain.html#explanation">Explanation</a></li>
<li><a href="proposed/00xx-smart-contracts-coretime-chain.html#drawbacks">Drawbacks</a></li>
<li><a href="proposed/00xx-smart-contracts-coretime-chain.html#testing-security-and-privacy">Testing, Security, and Privacy</a>
<ul>
<li><a href="proposed/00xx-smart-contracts-coretime-chain.html#testing">Testing</a></li>
<li><a href="proposed/00xx-smart-contracts-coretime-chain.html#security">Security</a></li>
<li><a href="proposed/00xx-smart-contracts-coretime-chain.html#privacy">Privacy</a></li>
</ul>
</li>
<li><a href="proposed/00xx-smart-contracts-coretime-chain.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="proposed/00xx-smart-contracts-coretime-chain.html#performance">Performance</a></li>
<li><a href="proposed/00xx-smart-contracts-coretime-chain.html#ergonomics">Ergonomics</a></li>
<li><a href="proposed/00xx-smart-contracts-coretime-chain.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="proposed/00xx-smart-contracts-coretime-chain.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="proposed/00xx-smart-contracts-coretime-chain.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="proposed/00xx-smart-contracts-coretime-chain.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0002-smart-contracts-on-the-coretime-chain"><a class="header" href="#rfc-0002-smart-contracts-on-the-coretime-chain">RFC-0002: Smart Contracts on the Coretime Chain</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>2024-06-09</td></tr>
<tr><td><strong>Description</strong></td><td>Implement smart contracts on the Coretime chain</td></tr>
<tr><td><strong>Authors</strong></td><td><a href="https://github.com/poppyseedDev/">Aurora Poppyseed</a>, <a href="https://github.com/phillux">Phil Lucksok</a></td></tr>
</tbody></table>
</div>
<h2 id="summary-15"><a class="header" href="#summary-15">Summary</a></h2>
<p>This RFC proposes the integration of smart contracts on the Coretime chain to enhance flexibility and enable complex decentralized applications, including secondary market functionalities.</p>
<h2 id="motivation-15"><a class="header" href="#motivation-15">Motivation</a></h2>
<p>Currently, the Coretime chain lacks the capability to support smart contracts, which limits the range of decentralized applications that can be developed and deployed. By enabling smart contracts, the Coretime chain can facilitate more sophisticated functionalities such as automated region trading, dynamic pricing mechanisms, and other decentralized applications that require programmable logic. This will enhance the utility of the Coretime chain, attract more developers, and create more opportunities for innovation.</p>
<p>Additionally, while there is a proposal (#885) to allow EVM-compatible contracts on Polkadots Asset Hub, the implementation of smart contracts directly on the Coretime chain will provide synchronous interactions and avoid the complexities of asynchronous operations via XCM. </p>
<h2 id="stakeholders-14"><a class="header" href="#stakeholders-14">Stakeholders</a></h2>
<p>Primary stakeholders include:</p>
<ul>
<li>Developers working on the Coretime chain.</li>
<li>Users who want to deploy decentralized applications on the Coretime chain.</li>
<li>Community members interested in expanding the capabilities of the Coretime chain.</li>
<li>Secondary Coretime marketplaces.</li>
</ul>
<h2 id="explanation-14"><a class="header" href="#explanation-14">Explanation</a></h2>
<p>This RFC introduces the following key components:</p>
<ol>
<li>
<p><strong>Smart Contract Support</strong>:</p>
<ul>
<li>Integrate support for deploying and executing smart contracts on the Coretime chain.</li>
<li>Use a well-established smart contract platform, such as Ethereums Solidity or Polkadot's Ink!, to ensure compatibility and ease of use.</li>
</ul>
</li>
<li>
<p><strong>Storage and Execution</strong>:</p>
<ul>
<li>Define a storage structure for smart contracts and their associated data.</li>
<li>Ensure efficient and secure execution of smart contracts, with proper resource management and gas fee mechanisms.</li>
</ul>
</li>
<li>
<p><strong>Integration with Existing Pallets</strong>:</p>
<ul>
<li>Ensure that smart contracts can interact with existing pallets on the Coretime chain, such as the broker pallet.</li>
<li>Provide APIs and interfaces for seamless integration and interaction.</li>
</ul>
</li>
<li>
<p><strong>Security and Auditing</strong>:</p>
<ul>
<li>Implement robust security measures to prevent vulnerabilities and exploits in smart contracts.</li>
<li>Conduct thorough security audits and testing before deployment.</li>
</ul>
</li>
</ol>
<h2 id="drawbacks-15"><a class="header" href="#drawbacks-15">Drawbacks</a></h2>
<p>There are several drawbacks to consider:</p>
<ul>
<li><strong>Complexity</strong>: Adding smart contracts introduces significant complexity to the Coretime chain, which may increase maintenance overhead and the potential for bugs.</li>
<li><strong>Performance</strong>: The execution of smart contracts can be resource-intensive, potentially affecting the performance of the Coretime chain.</li>
<li><strong>Security</strong>: Smart contracts are prone to vulnerabilities and exploits, necessitating rigorous security measures and continuous monitoring.</li>
</ul>
<h2 id="testing-security-and-privacy-12"><a class="header" href="#testing-security-and-privacy-12">Testing, Security, and Privacy</a></h2>
<h3 id="testing-1"><a class="header" href="#testing-1">Testing</a></h3>
<ul>
<li>Comprehensive unit tests and integration tests should be developed to ensure the correct functionality of smart contracts.</li>
<li>Test scenarios should include various use cases and edge cases to validate the robustness of the implementation.</li>
</ul>
<h3 id="security-1"><a class="header" href="#security-1">Security</a></h3>
<ul>
<li>Security audits should be performed to identify and mitigate vulnerabilities.</li>
<li>Implement best practices for smart contract development to minimize the risk of exploits.</li>
<li>Continuous monitoring and updates will be necessary to address new security threats.</li>
</ul>
<h3 id="privacy-1"><a class="header" href="#privacy-1">Privacy</a></h3>
<ul>
<li>The proposal does not introduce new privacy concerns as it extends existing functionalities with programmable logic.</li>
</ul>
<h2 id="performance-ergonomics-and-compatibility-12"><a class="header" href="#performance-ergonomics-and-compatibility-12">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-12"><a class="header" href="#performance-12">Performance</a></h3>
<ul>
<li>The introduction of smart contracts may impact performance due to the additional computational overhead.</li>
<li>Optimization techniques, such as efficient gas fee mechanisms and resource management, should be employed to minimize performance degradation.</li>
</ul>
<h3 id="ergonomics-10"><a class="header" href="#ergonomics-10">Ergonomics</a></h3>
<ul>
<li>The new functionality should be designed to be intuitive and easy to use for developers, with comprehensive documentation and examples.</li>
<li>Provide developer tools and SDKs to facilitate the creation and deployment of smart contracts.</li>
</ul>
<h3 id="compatibility-10"><a class="header" href="#compatibility-10">Compatibility</a></h3>
<ul>
<li>This proposal should maintain compatibility with existing interfaces and functionalities of the Coretime chain.</li>
<li>Ensure backward compatibility and provide migration paths if necessary.</li>
</ul>
<h2 id="prior-art-and-references-13"><a class="header" href="#prior-art-and-references-13">Prior Art and References</a></h2>
<ul>
<li>Ethereums implementation of smart contracts using Solidity.</li>
<li>Polkadots Ink! smart contract platform.</li>
<li>Existing decentralized applications and use cases on other blockchain platforms.</li>
<li>Proposal #885: EVM-compatible contracts on Asset Hub, which highlights the community's interest in integrating smart contracts within the Polkadot ecosystem.</li>
</ul>
<h2 id="unresolved-questions-14"><a class="header" href="#unresolved-questions-14">Unresolved Questions</a></h2>
<ul>
<li>What specific security measures should be implemented to prevent smart contract vulnerabilities?</li>
<li>How can we ensure optimal performance while supporting complex smart contracts?</li>
<li>What are the best practices for integrating smart contracts with existing pallets on the Coretime chain?</li>
</ul>
<h2 id="future-directions-and-related-material-9"><a class="header" href="#future-directions-and-related-material-9">Future Directions and Related Material</a></h2>
<ul>
<li>Further enhancements could include advanced developer tools and SDKs for smart contract development.</li>
<li>Integration with external decentralized applications and platforms to expand the ecosystem.</li>
<li>Continuous updates and improvements to the smart contract platform based on community feedback and emerging best practices.</li>
<li>Exploration of additional use cases for smart contracts on the Coretime chain, such as decentralized finance (DeFi) applications, voting systems, and more.</li>
</ul>
<p>By enabling smart contracts on the Coretime chain, we can significantly expand its capabilities and attract a wider range of developers and users, fostering innovation and growth in the ecosystem.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/pull/111">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="proposed/0111-pure-proxy-replication.html#rfc-0111-pure-proxy-replication">RFC-0111: Pure Proxy Replication</a>
<ul>
<li><a href="proposed/0111-pure-proxy-replication.html#summary">Summary</a></li>
<li><a href="proposed/0111-pure-proxy-replication.html#motivation">Motivation</a></li>
<li><a href="proposed/0111-pure-proxy-replication.html#stakeholders">Stakeholders</a></li>
<li><a href="proposed/0111-pure-proxy-replication.html#explanation">Explanation</a></li>
<li><a href="proposed/0111-pure-proxy-replication.html#drawbacks">Drawbacks</a></li>
<li><a href="proposed/0111-pure-proxy-replication.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="proposed/0111-pure-proxy-replication.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="proposed/0111-pure-proxy-replication.html#performance">Performance</a></li>
<li><a href="proposed/0111-pure-proxy-replication.html#ergonomics">Ergonomics</a></li>
<li><a href="proposed/0111-pure-proxy-replication.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="proposed/0111-pure-proxy-replication.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="proposed/0111-pure-proxy-replication.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="proposed/0111-pure-proxy-replication.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0111-pure-proxy-replication"><a class="header" href="#rfc-0111-pure-proxy-replication">RFC-0111: Pure Proxy Replication</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>12 Aug 2024.</td></tr>
<tr><td><strong>Description</strong></td><td>Replication of pure proxy account ownership to a remote chain</td></tr>
<tr><td><strong>Authors</strong></td><td>@muharem @xlc</td></tr>
</tbody></table>
</div>
<h2 id="summary-16"><a class="header" href="#summary-16">Summary</a></h2>
<p>This RFC proposes a solution to replicate an existing pure proxy from one chain to others. The aim is to address the current limitations where pure proxy accounts, which are keyless, cannot have their proxy relationships recreated on different chains. This leads to issues where funds or permissions transferred to the same keyless account address on chains other than its origin chain become inaccessible.</p>
<h2 id="motivation-16"><a class="header" href="#motivation-16">Motivation</a></h2>
<p>A pure proxy is a new account created by a primary account. The primary account is set as a proxy for the pure proxy account, managing it. Pure proxies are keyless and non-reproducible, meaning they lack a private key and have an address derived from a preimage determined by on-chain logic. More on pure proxies can be found <a href="https://wiki.polkadot.network/docs/learn-proxies-pure">here</a>.</p>
<p>For the purpose of this document, we define a keyless account as a &quot;pure account&quot;, the controlling account as a &quot;proxy account&quot;, and the entire relationship as a &quot;pure proxy&quot;.</p>
<p>The relationship between a pure account (e.g., account ID: <code>pure1</code>) and its proxy (e.g., account ID: <code>alice</code>) is stored on-chain (e.g., parachain <code>A</code>) and currently cannot be replicated to another chain (e.g., parachain <code>B</code>). Because the account <code>pure1</code> is keyless and its proxy relationship with <code>alice</code> is not replicable from the parachain <code>A</code> to the parachain <code>B</code>, <code>alice</code> does not control the <code>pure1</code> account on the parachain <code>B</code>.</p>
<p>Although this behaviour is not promised, users and clients often mistakenly expect <code>alice</code> to control the same <code>pure1</code> account on the parachain <code>B</code>. As a result, assets transferred to the account or permissions granted for it are inaccessible. Several factors contribute to this misuse:</p>
<ul>
<li>regular accounts on different parachains with the same account ID are typically accessible for the owner and controlled by the same private key (e.g., within System Parachains);</li>
<li>users and clients do not distinguish between keyless and regular accounts;</li>
<li>members using the multisig account ID across different chains, where a member of a multisig is a pure account;</li>
<li>users may prefer an account with a registered identity (e.g. for cross-chain treasury spend proposal), even if the account is keyless;</li>
</ul>
<p>Given that these mistakes are likely, it is necessary to provide a solution to either prevent them or enable access to a pure account on a target chain.</p>
<h2 id="stakeholders-15"><a class="header" href="#stakeholders-15">Stakeholders</a></h2>
<p>Runtime Users, Runtime Devs, wallets, cross-chain dApps.</p>
<h2 id="explanation-15"><a class="header" href="#explanation-15">Explanation</a></h2>
<p>One possible solution is to allow a proxy to create or replicate a pure proxy relationship for the same pure account on a target chain. For example, Alice, as the proxy of the <code>pure1</code> pure account on parachain <code>A</code>, should be able to set a proxy for the same <code>pure1</code> account on parachain <code>B</code>.</p>
<p>To minimise security risks, the parachain <code>B</code> should grant the parachain <code>A</code> the least amount of permission necessary for the replication. First, Parachain <code>A</code> claims to Parachain <code>B</code> that the operation is commanded by the pure account, and thus by its proxy, and second, provides proof that the account is keyless.</p>
<p>The replication process will be facilitated by XCM, with the first claim made using the <code>DescendOrigin</code> instruction. The replication call on parachain <code>A</code> would require a signed origin by the pure account and construct an XCM program for parachain <code>B</code>, where it first descends the origin, resulting in the <code>ParachainA/AccountId32(pure1)</code> origin location on the receiving side.</p>
<p>To prove that the pure account is keyless, the client must provide the initial preimage used by the chain to derive the pure account. Parachain <code>A</code> verifies it and sends it to parachain <code>B</code> with the replication request.</p>
<p>We can draft a pallet extension for the proxy pallet, which needs to be initialised on both sides to enable replication:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>// Simplified version to illustrate the concept.
mod pallet_proxy_replica {
/// The part of the pure account preimage that has to be provided by a client.
struct Witness {
/// Pure proxy swapner
spawner: AccountId,
/// Disambiguation index
index: u16,
/// The block height and extrinsic index of when the pure account was created.
block_number: BlockNumber,
/// The extrinsic index.
ext_index: u32,
// Part of the preimage, but constant.
// proxy_type: ProxyType::Any,
}
// ...
/// The replication call to be initiated on the source chain.
// Simplified version, the XCM part will be abstracted by the `Config` trait.
fn replicate(origin: SignedOrigin, witness: Witness, proxy: xcm::Location) -&gt; ... {
let pure = ensure_signed(origin);
ensure!(pure == proxy_pallet::derive_pure_account(witness), Error::NotPureAccount);
let xcm = vec![
DescendOrigin(who),
Transact(
// …
origin_kind: OriginKind::Xcm,
call: pallet_proxy_replica::create(witness, proxy).encode(),
)
];
xcmTransport::send(xcm)?;
}
// …
/// The call initiated by the source chain on the receiving chain.
// `Config::CreateOrigin` - generally open for whitelisted parachain IDs and
// converts `Origin::Xcm(ParachainA/AccountId32(pure1))` to `AccountID(pure1)`.
fn create(origin: Config::CreateOrigin, witness: Witness, proxy: xcm::Location) -&gt; ... {
let pure = T::CreateOrigin::ensure_origin(origin);
ensure!(pure == proxy_pallet::derive_pure_account(witness), Error::NotPureAccount);
proxy_pallet::create_pure_proxy(pure, proxy);
}
}
<span class="boring">}</span></code></pre></pre>
<h2 id="drawbacks-16"><a class="header" href="#drawbacks-16">Drawbacks</a></h2>
<p>There are two disadvantages to this approach:</p>
<ul>
<li>The receiving chain has to trust the sending chain's claim that the account controlling the pure account has commanded the replication.</li>
<li>Clients must obtain witness data.</li>
</ul>
<p>We could eliminate the first disadvantage by allowing only the spawner of the pure proxy to recreate the pure proxies, if they sign the transaction on a remote chain and supply the witness/preimage. Since the preimage of a pure account includes the account ID of the spawner, we can verify that the account signing the transaction is indeed the spawner of the given pure account. However, this approach would grant exclusive rights to the spawner over the pure account, which is not a property of pure proxies at present. This is why it's not an option for us.</p>
<p>As an alternative to requiring clients to provide a witness data, we could label pure accounts on the source chain and trust it on the receiving chain. However, this would require the receiving chain to place greater trust in the source chain. If the source chain is compromised, any type of account on the trusting chain could also be compromised.</p>
<p>A conceptually different solution would be to not implement replication of pure proxies and instead inform users that ownership of a pure proxy on one chain does not imply ownership of the same account on another chain. This solution seems complex, as it would require UIs and clients to adapt to this understanding. Moreover, mistakes would likely remain unavoidable.</p>
<h2 id="testing-security-and-privacy-13"><a class="header" href="#testing-security-and-privacy-13">Testing, Security, and Privacy</a></h2>
<p>Each chain expressly authorizes another chain to replicate its pure proxies, accepting the inherent risk of that chain potentially being compromised. This authorization allows a malicious actor from the compromised chain to take control of any pure proxy account on the chain that granted the authorization. However, this is limited to pure proxies that originated from the compromised chain if they have a chain-specific seed within the preimage.</p>
<p>There is a security issue, not introduced by the proposed solution but worth mentioning. The same spawner can create the pure accounts on different chains controlled by the different accounts. This is possible because the current preimage version of the proxy pallet does not include any non-reproducible, chain-specific data, and elements like block numbers and extrinsic indexes can be reproduced with some effort. This issue could be addressed by adding a chain-specific seed into the preimages of pure accounts.</p>
<h2 id="performance-ergonomics-and-compatibility-13"><a class="header" href="#performance-ergonomics-and-compatibility-13">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-13"><a class="header" href="#performance-13">Performance</a></h3>
<p>The replication is facilitated by XCM, which adds some additional load to the communication channel. However, since the number of replications is not expected to be large, the impact is minimal.</p>
<h3 id="ergonomics-11"><a class="header" href="#ergonomics-11">Ergonomics</a></h3>
<p>The proposed solution does not alter any existing interfaces. It does require clients to obtain the witness data which should not be an issue with support of an indexer. </p>
<h3 id="compatibility-11"><a class="header" href="#compatibility-11">Compatibility</a></h3>
<p>None.</p>
<h2 id="prior-art-and-references-14"><a class="header" href="#prior-art-and-references-14">Prior Art and References</a></h2>
<p>None.</p>
<h2 id="unresolved-questions-15"><a class="header" href="#unresolved-questions-15">Unresolved Questions</a></h2>
<p>None.</p>
<h2 id="future-directions-and-related-material-10"><a class="header" href="#future-directions-and-related-material-10">Future Directions and Related Material</a></h2>
<ul>
<li>Pure Proxy documentation - https://wiki.polkadot.network/docs/learn-proxies-pure</li>
</ul>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/pull/112">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="proposed/0112-compress-state-response-message-in-state-sync.html#rfc-0112-compress-the-state-response-message-in-state-sync">RFC-0112: Compress the State Response Message in State Sync</a>
<ul>
<li><a href="proposed/0112-compress-state-response-message-in-state-sync.html#summary">Summary</a></li>
<li><a href="proposed/0112-compress-state-response-message-in-state-sync.html#motivation">Motivation</a></li>
<li><a href="proposed/0112-compress-state-response-message-in-state-sync.html#stakeholders">Stakeholders</a></li>
<li><a href="proposed/0112-compress-state-response-message-in-state-sync.html#explanation">Explanation</a></li>
<li><a href="proposed/0112-compress-state-response-message-in-state-sync.html#drawbacks">Drawbacks</a></li>
<li><a href="proposed/0112-compress-state-response-message-in-state-sync.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="proposed/0112-compress-state-response-message-in-state-sync.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="proposed/0112-compress-state-response-message-in-state-sync.html#performance">Performance</a></li>
<li><a href="proposed/0112-compress-state-response-message-in-state-sync.html#ergonomics">Ergonomics</a></li>
<li><a href="proposed/0112-compress-state-response-message-in-state-sync.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="proposed/0112-compress-state-response-message-in-state-sync.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="proposed/0112-compress-state-response-message-in-state-sync.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="proposed/0112-compress-state-response-message-in-state-sync.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0112-compress-the-state-response-message-in-state-sync"><a class="header" href="#rfc-0112-compress-the-state-response-message-in-state-sync">RFC-0112: Compress the State Response Message in State Sync</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>14 August 2024</td></tr>
<tr><td><strong>Description</strong></td><td>Compress the state response message to reduce the data transfer during the state syncing</td></tr>
<tr><td><strong>Authors</strong></td><td>Liu-Cheng Xu</td></tr>
</tbody></table>
</div>
<h2 id="summary-17"><a class="header" href="#summary-17">Summary</a></h2>
<p>This RFC proposes compressing the state response message during the state syncing process to reduce the amount of data transferred.</p>
<h2 id="motivation-17"><a class="header" href="#motivation-17">Motivation</a></h2>
<p>State syncing can require downloading several gigabytes of data, particularly for blockchains with large state sizes, such as Astar, which
has a state size exceeding 5 GiB (https://github.com/AstarNetwork/Astar/issues/1110). This presents a significant
challenge for nodes with slower network connections. Additionally, the current state sync implementation lacks a persistence feature (https://github.com/paritytech/polkadot-sdk/issues/4),
meaning any network disruption forces the node to re-download the entire state, making the process even more difficult.</p>
<h2 id="stakeholders-16"><a class="header" href="#stakeholders-16">Stakeholders</a></h2>
<p>This RFC benefits all projects utilizing the Substrate framework, specifically in improving the efficiency of state syncing.</p>
<ul>
<li>Node Operators.</li>
<li>Substrate Users.</li>
</ul>
<h2 id="explanation-16"><a class="header" href="#explanation-16">Explanation</a></h2>
<p>The largest portion of the state response message consists of either <code>CompactProof</code> or <code>Vec&lt;KeyValueStateEntry&gt;</code>, depending on whether a proof is requested (<a href="https://github.com/paritytech/polkadot-sdk/blob/0cd577ba1c4995500eb3ed10330d93402177a53b/substrate/client/network/sync/src/state_request_handler.rs#L216-L241">source</a>):</p>
<ul>
<li><code>CompactProof</code>: When proof is requested, compression yields a lower ratio but remains beneficial, as shown in warp sync tests in the Performance section below.</li>
<li><code>Vec&lt;KeyValueStateEntry&gt;</code>: Without proof, this is theoretically compressible because the entries are generated by iterating the
storage sequentially starting from an empty storage key, which means many entries in the message share the same storage prefix, making it ideal
for compression.</li>
</ul>
<h2 id="drawbacks-17"><a class="header" href="#drawbacks-17">Drawbacks</a></h2>
<p>None identified.</p>
<h2 id="testing-security-and-privacy-14"><a class="header" href="#testing-security-and-privacy-14">Testing, Security, and Privacy</a></h2>
<p>The <a href="https://github.com/liuchengxu/polkadot-sdk/commit/2556fefacd2e817111d838af5f46d3dfa495852d">code changes</a> required for this RFC are straightforward: compress the state response on the sender side and decompress it on the receiver side. Existing sync tests should ensure functionality remains intact.</p>
<h2 id="performance-ergonomics-and-compatibility-14"><a class="header" href="#performance-ergonomics-and-compatibility-14">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-14"><a class="header" href="#performance-14">Performance</a></h3>
<p>This RFC optimizes network bandwidth usage during state syncing, particularly for blockchains with gigabyte-sized states, while introducing negligible CPU overhead for compression and decompression. For example, compressing the state response during a recent Polkadot warp sync (around height #22076653) reduces the data transferred from 530,310,121 bytes to 352,583,455 bytes — a 33% reduction, saving approximately 169 MiB of data.</p>
<p>Performance data is based on <a href="https://github.com/liuchengxu/polkadot-sdk/commit/da93360c9a59c29409061789c598d8f4e55d7856">this patch</a>, with logs available <a href="https://github.com/liuchengxu/polkadot-sdk/commit/9d98cefd5fac0a001d5910f7870ead05ab99eeba">here</a>.</p>
<h3 id="ergonomics-12"><a class="header" href="#ergonomics-12">Ergonomics</a></h3>
<p>None.</p>
<h3 id="compatibility-12"><a class="header" href="#compatibility-12">Compatibility</a></h3>
<p>No compatibility issues identified.</p>
<h2 id="prior-art-and-references-15"><a class="header" href="#prior-art-and-references-15">Prior Art and References</a></h2>
<p>None.</p>
<h2 id="unresolved-questions-16"><a class="header" href="#unresolved-questions-16">Unresolved Questions</a></h2>
<p>None.</p>
<h2 id="future-directions-and-related-material-11"><a class="header" href="#future-directions-and-related-material-11">Future Directions and Related Material</a></h2>
<p>None.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/pull/113">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="proposed/0114-secp256r1-hostfunction.html#rfc-0114-introduce-secp256r1_ecdsa_verify_prehashed-host-function-to-verify-nist-p256-elliptic-curve-signatures">RFC-0114: Introduce <code>secp256r1_ecdsa_verify_prehashed</code> Host Function to verify <code>NIST-P256</code> elliptic curve signatures</a>
<ul>
<li><a href="proposed/0114-secp256r1-hostfunction.html#summary">Summary</a></li>
<li><a href="proposed/0114-secp256r1-hostfunction.html#motivation">Motivation</a></li>
<li><a href="proposed/0114-secp256r1-hostfunction.html#stakeholders">Stakeholders</a></li>
<li><a href="proposed/0114-secp256r1-hostfunction.html#explanation">Explanation</a></li>
<li><a href="proposed/0114-secp256r1-hostfunction.html#drawbacks">Drawbacks</a></li>
<li><a href="proposed/0114-secp256r1-hostfunction.html#testing-security-and-privacy">Testing, Security, and Privacy</a>
<ul>
<li><a href="proposed/0114-secp256r1-hostfunction.html#security">Security</a></li>
</ul>
</li>
<li><a href="proposed/0114-secp256r1-hostfunction.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="proposed/0114-secp256r1-hostfunction.html#performance">Performance</a></li>
<li><a href="proposed/0114-secp256r1-hostfunction.html#ergonomics">Ergonomics</a></li>
<li><a href="proposed/0114-secp256r1-hostfunction.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="proposed/0114-secp256r1-hostfunction.html#prior-art-and-references">Prior Art and References</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0114-introduce-secp256r1_ecdsa_verify_prehashed-host-function-to-verify-nist-p256-elliptic-curve-signatures"><a class="header" href="#rfc-0114-introduce-secp256r1_ecdsa_verify_prehashed-host-function-to-verify-nist-p256-elliptic-curve-signatures">RFC-0114: Introduce <code>secp256r1_ecdsa_verify_prehashed</code> Host Function to verify <code>NIST-P256</code> elliptic curve signatures</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>16 August 2024</td></tr>
<tr><td><strong>Description</strong></td><td>Host function to verify <code>NIST-P256</code> elliptic curve signatures.</td></tr>
<tr><td><strong>Authors</strong></td><td>Rodrigo Quelhas</td></tr>
</tbody></table>
</div>
<h2 id="summary-18"><a class="header" href="#summary-18">Summary</a></h2>
<p>This RFC proposes a new host function, <code>secp256r1_ecdsa_verify_prehashed</code>, for verifying <code>NIST-P256</code> signatures. The function takes as input the message hash, <code>r</code> and <code>s</code> components of the signature, and the <code>x</code> and <code>y</code> coordinates of the public key. By providing this function, runtime authors can leverage a more efficient verification mechanism for &quot;secp256r1&quot; elliptic curve signatures, reducing computational costs and improving overall performance.</p>
<h2 id="motivation-18"><a class="header" href="#motivation-18">Motivation</a></h2>
<p>“secp256r1” elliptic curve is a standardized curve by NIST which has the same calculations by different input parameters with “secp256k1” elliptic curve. The cost of combined attacks and the security conditions are almost the same for both curves. Adding a host function can provide signature verifications using the “secp256r1” elliptic curve in the runtime and multi-faceted benefits can occur. One important factor is that this curve is widely used and supported in many modern devices such as Apples Secure Enclave, Webauthn, Android Keychain which proves the user adoption. Additionally, the introduction of this host function could enable valuable features in the account abstraction which allows more efficient and flexible management of accounts by transaction signs in mobile devices.
Most of the modern devices and applications rely on the “secp256r1” elliptic curve. The addition of this host function enables a more efficient verification of device native transaction signing mechanisms. For example:</p>
<ol>
<li><strong>Apple's Secure Enclave:</strong> There is a separate “Trusted Execution Environment” in Apple hardware which can sign arbitrary messages and can only be accessed by biometric identification.</li>
<li><strong>Webauthn:</strong> Web Authentication (WebAuthn) is a web standard published by the World Wide Web Consortium (W3C). WebAuthn aims to standardize an interface for authenticating users to web-based applications and services using public-key cryptography. It is being used by almost all of the modern web browsers.</li>
<li><strong>Android Keystore:</strong> Android Keystore is an API that manages the private keys and signing methods. The private keys are not processed while using Keystore as the applications signing method. Also, it can be done in the “Trusted Execution Environment” in the microchip.</li>
<li><strong>Passkeys:</strong> Passkeys is utilizing FIDO Alliance and W3C standards. It replaces passwords with cryptographic key-pairs which is also can be used for the elliptic curve cryptography.</li>
</ol>
<h2 id="stakeholders-17"><a class="header" href="#stakeholders-17">Stakeholders</a></h2>
<ul>
<li><strong>Runtime Authors</strong></li>
</ul>
<h2 id="explanation-17"><a class="header" href="#explanation-17">Explanation</a></h2>
<p>This RFC proposes a new host function for runtime authors to leverage a more efficient verification mechanism for &quot;secp256r1&quot; elliptic curve signatures.</p>
<p>Proposed host function signature:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>fn ext_secp256r1_ecdsa_verify_prehashed_version_1(
sig: &amp;[u8; 64],
msg: &amp;[u8; 32],
pub_key: &amp;[u8; 64],
) -&gt; bool;
<span class="boring">}</span></code></pre></pre>
<p>The host function MUST return <code>true</code> if the signature is valid or <code>false</code> otherwise.</p>
<h2 id="drawbacks-18"><a class="header" href="#drawbacks-18">Drawbacks</a></h2>
<p>N/A</p>
<h2 id="testing-security-and-privacy-15"><a class="header" href="#testing-security-and-privacy-15">Testing, Security, and Privacy</a></h2>
<h3 id="security-2"><a class="header" href="#security-2">Security</a></h3>
<p>The changes are not directly affecting the protocol security, parachains are not enforced to use the host function.</p>
<h2 id="performance-ergonomics-and-compatibility-15"><a class="header" href="#performance-ergonomics-and-compatibility-15">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-15"><a class="header" href="#performance-15">Performance</a></h3>
<p>N/A</p>
<h3 id="ergonomics-13"><a class="header" href="#ergonomics-13">Ergonomics</a></h3>
<p>The host function proposed in this RFC allows parachain runtime developers to use a more efficient verification mechanism for &quot;secp256r1&quot; elliptic curve signatures.</p>
<h3 id="compatibility-13"><a class="header" href="#compatibility-13">Compatibility</a></h3>
<p>Parachain teams will need to include this host function to upgrade.</p>
<h2 id="prior-art-and-references-16"><a class="header" href="#prior-art-and-references-16">Prior Art and References</a></h2>
<ul>
<li>Pull Request including <a href="https://github.com/ethereum/RIPs/blob/master/RIPS/rip-7212.md">RIP-7212</a> in Moonbeam: <a href="https://github.com/moonbeam-foundation/moonbeam/pull/2859">Add secp256r1 precompile</a>.</li>
<li>Pull Request including proposed host function: <a href="proposed/">IN PROGRESS</a>.</li>
</ul>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/pull/117">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="proposed/0117-unbrick-collective.html#rfc-0117-the-unbrick-collective">RFC-0117: The Unbrick Collective</a>
<ul>
<li><a href="proposed/0117-unbrick-collective.html#summary">Summary</a></li>
<li><a href="proposed/0117-unbrick-collective.html#motivation">Motivation</a></li>
<li><a href="proposed/0117-unbrick-collective.html#stakeholders">Stakeholders</a></li>
<li><a href="proposed/0117-unbrick-collective.html#explanation">Explanation</a>
<ul>
<li><a href="proposed/0117-unbrick-collective.html#the-collective">The Collective</a></li>
<li><a href="proposed/0117-unbrick-collective.html#the-unbrick-process">The Unbrick Process</a></li>
<li><a href="proposed/0117-unbrick-collective.html#belonging-to-the-collective">Belonging to the Collective</a></li>
</ul>
</li>
<li><a href="proposed/0117-unbrick-collective.html#drawbacks">Drawbacks</a></li>
<li><a href="proposed/0117-unbrick-collective.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="proposed/0117-unbrick-collective.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="proposed/0117-unbrick-collective.html#performance">Performance</a></li>
<li><a href="proposed/0117-unbrick-collective.html#ergonomics">Ergonomics</a></li>
<li><a href="proposed/0117-unbrick-collective.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="proposed/0117-unbrick-collective.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="proposed/0117-unbrick-collective.html#unresolved-questions">Unresolved Questions</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0117-the-unbrick-collective"><a class="header" href="#rfc-0117-the-unbrick-collective">RFC-0117: The Unbrick Collective</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>22 August 2024</td></tr>
<tr><td><strong>Description</strong></td><td>The Unbrick Collective aims to help teams rescuing a para once it stops producing blocks</td></tr>
<tr><td><strong>Authors</strong></td><td>Bryan Chen, Pablo Dorado</td></tr>
</tbody></table>
</div>
<h2 id="summary-19"><a class="header" href="#summary-19">Summary</a></h2>
<p>A followup of the <a href="proposed/./0014-improve-locking-mechanism-for-parachains">RFC-0014</a>. This RFC proposes adding a new collective to the Polkadot Collectives
Chain: The Unbrick Collective, as well as improvements in the mechanisms that will allow teams
operating paras that had stopped producing blocks to be assisted, in order to restore the production
of blocks of these paras.</p>
<h2 id="motivation-19"><a class="header" href="#motivation-19">Motivation</a></h2>
<p>Since the initial launch of Polkadot parachains, there has been many incidients causing parachains
to stop producing new blocks (therefore, being <em>bricked</em>) and many occurrences that requires
Polkadot governance to update the parachain head state/wasm. This can be due to many reasons range
from incorrectly registering the initial head state, inability to use sudo key, bad runtime
migration, bad weight configuration, and bugs in the development of the Polkadot SDK.</p>
<p>Currently, when the para is not unlocked in the <em>paras registrar</em><sup class="footnote-reference"><a href="#1">1</a></sup>, the <code>Root</code> origin is required to
perform such actions, involving the governance process to invoke this origin, which can be very
resource expensive for the teams. The long voting and enactment times also could result significant
damage to the parachain and users.</p>
<p>Finally, other instances of governance that might enact a call using the <code>Root</code> origin (like the
Polkadot Fellowship), due to the nature of their mission, are not fit to carry these kind of tasks.</p>
<p>In consequence, the idea of a Unbrick Collective that can provide assistance to para teams when
they brick and further protection against future halts is reasonable enough.</p>
<h2 id="stakeholders-18"><a class="header" href="#stakeholders-18">Stakeholders</a></h2>
<ul>
<li>Parachain teams</li>
<li>Parachain users</li>
<li>OpenGov users</li>
<li>Polkadot Fellowship</li>
</ul>
<h2 id="explanation-18"><a class="header" href="#explanation-18">Explanation</a></h2>
<h3 id="the-collective"><a class="header" href="#the-collective">The Collective</a></h3>
<p>The Unbrick Collective is defined as an unranked collective of members, not paid by the Polkadot
Treasury. Its main goal is to serve as a point of contact and assistance for enacting the actions
needed to unbrick a para. Such actions are:</p>
<ul>
<li>Updating the Parachain Verification Function (a.k.a. a new WASM) of a para.</li>
<li>Updating the head state of a para.</li>
<li>A combination of the above.</li>
</ul>
<p>In order to ensure these changes are safe enough for the network, actions enacted by the Unbrick
Collective must be whitelisted via similar mechanisms followed by collectives like the Polkadot
Fellowship. This will prevent unintended, not overseen changes on other paras to occur.</p>
<p>Also, teams might opt-in to delegate handling their para in the registry to the Collective. This
allows to perform similar actions using the <em>paras registrar</em>, allowing for a shorter path to unbrick a
para.</p>
<h3 id="the-unbrick-process"><a class="header" href="#the-unbrick-process">The Unbrick Process</a></h3>
<pre><code class="language-mermaid">flowchart TD
A[Start]
A -- Bricked --&gt; C[Request Unbrick «via governance»]
C --&gt; D[unbrick call proposal on WhitelistedUnbrickCaller]
C --&gt; E[whitelist call proposal on the Unbrick governance]
E -- call whitelisted --&gt; F[unbrick call enacted]
D -- unbrick called --&gt; F
F --&gt; Y
A -- Not bricked --&gt; O[Opt-in to the Collective]
O -- Bricked --&gt; P[Collective calls registrar]
P --&gt; Y
Y[update PVF / head state] -- Unbricked --&gt; Z[End]
</code></pre>
<p>Initially, a para team has two paths to handle a potential unbrick of their para in the case it
stops producing blocks.</p>
<ol>
<li><strong>Opt-in to the Unbrick Collective</strong>: This is done by delegating the handling of the para
in the <em>paras registrar</em> to the Collective. This doesn't require unlocking the para. This way,
the collective is enabled to perform changes in the <em>paras registrar</em> without the need for
whitelisting.</li>
<li><strong>Request an Unbrick Process</strong>: In case the para hasn't delegated its handling in the <em>paras
registrar</em>, it'll be still possible for the para team to submit a proposal to unbrick the para,
assisted by the Collective. This process is expected to be more expedite (and less expensive)
for a team to perform than submitting a proposal on the <code>Root</code> governance track.</li>
</ol>
<h3 id="belonging-to-the-collective"><a class="header" href="#belonging-to-the-collective">Belonging to the Collective</a></h3>
<p>The collective will be initially created without members (no seeding). There will be additional
governance proposals to setup the seed members.</p>
<p>The origins able to modify the members of the collective are:</p>
<ul>
<li>The <code>Fellows</code> track in the Polkadot Fellowship.</li>
<li><code>Root</code> track in the Relay.</li>
<li>More than two thrids of the existing Unbrick Collective.</li>
</ul>
<p>The members are responsible to verify the technical details of the unbrick requests (i.e. the hash
of the new PVF being set). Therefore, they must have the technical capacity to perform such tasks.</p>
<p>Suggested requirements to become a member are the following:</p>
<ul>
<li>Rank 3 or above in the Polkadot Fellowship.</li>
<li>Being a CTO or Technical Lead in a para team that has opted-in to delegate the Unbrick Collective
to manage the PVF/head state of the para.</li>
</ul>
<h2 id="drawbacks-19"><a class="header" href="#drawbacks-19">Drawbacks</a></h2>
<p>The ability to modify the Head State and/or the PVF of a para means a possibility to perform
arbitrary modifications of it (i.e. take control the native parachain token or any bridged assets
in the para).</p>
<p>This could introduce a new attack vectorm, and therefore, such great power needs to be handled
carefully.</p>
<h2 id="testing-security-and-privacy-16"><a class="header" href="#testing-security-and-privacy-16">Testing, Security, and Privacy</a></h2>
<p>The implementation of this RFC will be tested on testnets (Rococo and Westend) first.</p>
<p>An audit will be required to ensure the implementation doesn't introduce unwanted side effects.</p>
<p>There are no privacy related concerns.</p>
<h2 id="performance-ergonomics-and-compatibility-16"><a class="header" href="#performance-ergonomics-and-compatibility-16">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-16"><a class="header" href="#performance-16">Performance</a></h3>
<p>This RFC should not introduce any performance impact.</p>
<h3 id="ergonomics-14"><a class="header" href="#ergonomics-14">Ergonomics</a></h3>
<p>This RFC should improve the experience for new and existing parachain teams, lowering the barrier
to unbrick a stalled para.</p>
<h3 id="compatibility-14"><a class="header" href="#compatibility-14">Compatibility</a></h3>
<p>This RFC is fully compatible with existing interfaces.</p>
<h2 id="prior-art-and-references-17"><a class="header" href="#prior-art-and-references-17">Prior Art and References</a></h2>
<ul>
<li><a href="proposed/./0014-improve-locking-mechanism-for-parachains">RFC-0014: Improve Locking Mechanisms for Parachains</a></li>
<li><a href="https://forum.polkadot.network/t/how-to-recover-a-parachain/673">How to Recover a Parachain, Polkadot Forum</a></li>
<li><a href="https://forum.polkadot.network/t/unbrick-collective/6931">Unbrick Collective, Polkadot Forum</a></li>
</ul>
<h2 id="unresolved-questions-17"><a class="header" href="#unresolved-questions-17">Unresolved Questions</a></h2>
<ul>
<li>What are the parameters for the <code>WhitelistedUnbrickCaller</code> track?</li>
<li>Any other methods that shall be updated to accept <code>Unbrick</code> origin?</li>
<li>Any other requirements to become a member?</li>
<li>We would like to keep this simple, so no funding support from the Polkadot treasury. But do we
want to compensate the members somehow? i.e. Allow parachain teams to donate to the collective</li>
<li>Do we want to have this collective offer additional technical support to help bricked parachains?
i.e. help debug the code, create the rescue plan, create postmortem report, provide resources on
how to avoid getting bricked</li>
</ul>
<!-- Footnotes -->
<div class="footnote-definition" id="1"><sup class="footnote-definition-label">1</sup>
<p>The <em>paras registrar</em> refers to a pallet in the Relay, responsible to gather registration info
of the paras, the locked/unlocked state, and the manager info.</p>
</div>
<!-- Links -->
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/pull/114">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="proposed/RFC-114%20Adjust%20Tipper%20Track%20Confirmation%20Periods.html#rfc-114-adjust-tipper-track-confirmation-periods">RFC-114: Adjust Tipper Track Confirmation Periods</a>
<ul>
<li><a href="proposed/RFC-114%20Adjust%20Tipper%20Track%20Confirmation%20Periods.html#summary">Summary</a></li>
<li><a href="proposed/RFC-114%20Adjust%20Tipper%20Track%20Confirmation%20Periods.html#motivation">Motivation</a></li>
<li><a href="proposed/RFC-114%20Adjust%20Tipper%20Track%20Confirmation%20Periods.html#stakeholders">Stakeholders</a></li>
<li><a href="proposed/RFC-114%20Adjust%20Tipper%20Track%20Confirmation%20Periods.html#explanation">Explanation</a></li>
<li><a href="proposed/RFC-114%20Adjust%20Tipper%20Track%20Confirmation%20Periods.html#drawbacks">Drawbacks</a></li>
<li><a href="proposed/RFC-114%20Adjust%20Tipper%20Track%20Confirmation%20Periods.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="proposed/RFC-114%20Adjust%20Tipper%20Track%20Confirmation%20Periods.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="proposed/RFC-114%20Adjust%20Tipper%20Track%20Confirmation%20Periods.html#performance">Performance</a></li>
<li><a href="proposed/RFC-114%20Adjust%20Tipper%20Track%20Confirmation%20Periods.html#ergonomics--compatibility">Ergonomics &amp; Compatibility</a></li>
</ul>
</li>
<li><a href="proposed/RFC-114%20Adjust%20Tipper%20Track%20Confirmation%20Periods.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="proposed/RFC-114%20Adjust%20Tipper%20Track%20Confirmation%20Periods.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="proposed/RFC-114%20Adjust%20Tipper%20Track%20Confirmation%20Periods.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-114-adjust-tipper-track-confirmation-periods"><a class="header" href="#rfc-114-adjust-tipper-track-confirmation-periods">RFC-114: Adjust Tipper Track Confirmation Periods</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>17-Aug-24</td></tr>
<tr><td><strong>Description</strong></td><td>Big and Small Tipper Track Conformation Period Modification</td></tr>
<tr><td><strong>Authors</strong></td><td>Leemo / ChaosDAO</td></tr>
</tbody></table>
</div>
<h2 id="summary-20"><a class="header" href="#summary-20">Summary</a></h2>
<p>This RFC proposes to change the duration of the Confirmation Period for the Big Tipper and Small Tipper tracks in Polkadot OpenGov:</p>
<ul>
<li>
<p>Small Tipper: 10 Minutes -&gt; 12 Hours</p>
</li>
<li>
<p>Big Tipper: 1 Hour -&gt; 1 Day</p>
</li>
</ul>
<h2 id="motivation-20"><a class="header" href="#motivation-20">Motivation</a></h2>
<p>Currently, these are the durations of treasury tracks in Polkadot OpenGov. Confirmation periods for the Spender tracks were adjusted based on <a href="https://github.com/polkadot-fellows/RFCs/pull/20">RFC20</a> and its related conversation.</p>
<div class="table-wrapper"><table><thead><tr><th>Track Description</th><th>Confirmation Period Duration</th></tr></thead><tbody>
<tr><td>Treasurer</td><td>7 Days</td></tr>
<tr><td>Big Spender</td><td>7 Days</td></tr>
<tr><td>Medium Spender</td><td>4 Days</td></tr>
<tr><td>Small Spender</td><td>2 Days</td></tr>
<tr><td>Big Tipper</td><td><strong>1 Hour</strong></td></tr>
<tr><td>Small Tipper</td><td><strong>10 Minutes</strong></td></tr>
</tbody></table>
</div>
<p>You can see that there is a general trend on the Spender track that when the privilege level (the amount the track can spend) the confirmation period approximately doubles.</p>
<p>I believe that the Big Tipper and Small Tipper track's confirmation periods should be adjusted to match this trend.</p>
<p>In the current state it is possible to somewhat positively snipe these tracks, and whilst the power/privilege level of these tracks is very low (they cannot spend a large amount of funds), I believe we should increase the confirmation periods to something higher. This is backed up by the recent sentiment in the greater community regarding referendums submitted on these tracks. The parameters of Polkadot OpenGov can be adjusted based on the general sentiment of token holders when necessary. </p>
<h2 id="stakeholders-19"><a class="header" href="#stakeholders-19">Stakeholders</a></h2>
<p>The primary stakeholders of this RFC are:
DOT token holders as this affects the protocol's treasury
Entities wishing to submit a referendum on these tracks as this affects the referendum's timeline
Projects with governance app integrations see Performance, Ergonomics and Compatibility section below</p>
<h2 id="explanation-19"><a class="header" href="#explanation-19">Explanation</a></h2>
<p>This RFC proposes to change the duration of the confirmation period for both the Big Tipper and Small Tipper tracks. To achieve this the <code>confirm_period</code> parameter for those tracks should be changed.</p>
<p>You can see the lines of code that need to be adjusted here:</p>
<ul>
<li>
<p>Big Tipper: https://github.com/polkadot-fellows/runtimes/blob/f4c5d272d4672387771fb038ef52ca36f3429096/relay/polkadot/src/governance/tracks.rs#L245</p>
</li>
<li>
<p>Small Tipper: https://github.com/polkadot-fellows/runtimes/blob/f4c5d272d4672387771fb038ef52ca36f3429096/relay/polkadot/src/governance/tracks.rs#L231</p>
</li>
</ul>
<p>This RFC proposes to change the <code>confirm_period</code> for the Big Tipper track to <code>DAYS</code> (i.e. 1 Day) and the <code>confirm_period</code> for the Small Tipper track to <code>12 * HOURS</code> (i.e. 12 Hours).</p>
<h2 id="drawbacks-20"><a class="header" href="#drawbacks-20">Drawbacks</a></h2>
<p>The drawback of changing these confirmation periods is that the lifecycle of referenda submitted on those tracks would be ultimately longer, and it would add a greater potential to negatively &quot;snipe&quot; referenda on those tracks by knocking the referendum out of its confirmation period once the decision period has ended. This can be a good or a bad thing depending on your outlook of positive vs negative sniping.</p>
<h2 id="testing-security-and-privacy-17"><a class="header" href="#testing-security-and-privacy-17">Testing, Security, and Privacy</a></h2>
<p>This referendum will enhance the security of the protocol as it relates to its treasury. The confirmation period is one of the last lines of defense for the Polkadot token holder DAO to react to a potentially bad referendum and vote NAY in order for its confirmation period to be aborted.</p>
<h2 id="performance-ergonomics-and-compatibility-17"><a class="header" href="#performance-ergonomics-and-compatibility-17">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-17"><a class="header" href="#performance-17">Performance</a></h3>
<p>This is a simple change (code wise) that should not affect the performance of the Polkadot protocol, outside of increasing the duration of the confirmation periods for these 2 tracks.</p>
<h3 id="ergonomics--compatibility-1"><a class="header" href="#ergonomics--compatibility-1">Ergonomics &amp; Compatibility</a></h3>
<p>As per the implementation of changes described in RFC-20, it was identified that governance UIs automatically update to meet the new parameters:</p>
<ul>
<li>Nova Wallet - directly uses on-chain data, and change will be automatically reflected.</li>
<li>Polkassembly - directly uses on-chain data via rpc to fetch trackInfo so the change will be automatically reflected.</li>
<li>SubSquare - scan script will update their app to the latest parameters and it will be automatically reflected in their app.</li>
</ul>
<h2 id="prior-art-and-references-18"><a class="header" href="#prior-art-and-references-18">Prior Art and References</a></h2>
<p>N/A</p>
<h2 id="unresolved-questions-18"><a class="header" href="#unresolved-questions-18">Unresolved Questions</a></h2>
<p>Some token holders may want these confirmation periods to remain as they are currently and for them not to increase. If this is something that the Polkadot Technical Fellowship considers to be an issue to implement into a runtime upgrade then I can create a Wish For Change to obtain token holder approval.</p>
<h2 id="future-directions-and-related-material-12"><a class="header" href="#future-directions-and-related-material-12">Future Directions and Related Material</a></h2>
<p>The parameters of Polkadot OpenGov will likely continue to change over time, there are additional discussions in the community regarding adjusting the <code>min_support</code> for some tracks so that it does not trend towards 0%, similar to the current state of the Whitelisted Caller track. This is outside of the scope of this RFC and requires a lot more discussion.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0001-agile-coretime.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0001-agile-coretime.html#rfc-1-agile-coretime">RFC-1: Agile Coretime</a>
<ul>
<li><a href="approved/0001-agile-coretime.html#summary">Summary</a></li>
<li><a href="approved/0001-agile-coretime.html#motivation">Motivation</a>
<ul>
<li><a href="approved/0001-agile-coretime.html#present-system">Present System</a></li>
<li><a href="approved/0001-agile-coretime.html#problems">Problems</a></li>
</ul>
</li>
<li><a href="approved/0001-agile-coretime.html#requirements">Requirements</a></li>
<li><a href="approved/0001-agile-coretime.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0001-agile-coretime.html#explanation">Explanation</a>
<ul>
<li><a href="approved/0001-agile-coretime.html#overview">Overview</a></li>
<li><a href="approved/0001-agile-coretime.html#detail">Detail</a></li>
<li><a href="approved/0001-agile-coretime.html#specific-functions-of-the-coretime-chain">Specific functions of the Coretime-chain</a></li>
<li><a href="approved/0001-agile-coretime.html#notes-on-the-instantaneous-coretime-market">Notes on the Instantaneous Coretime Market</a></li>
<li><a href="approved/0001-agile-coretime.html#notes-on-economics">Notes on Economics</a></li>
<li><a href="approved/0001-agile-coretime.html#notes-on-types">Notes on Types</a></li>
<li><a href="approved/0001-agile-coretime.html#rollout">Rollout</a></li>
</ul>
</li>
<li><a href="approved/0001-agile-coretime.html#performance-ergonomics-and-compatibility">Performance, Ergonomics and Compatibility</a></li>
<li><a href="approved/0001-agile-coretime.html#testing-security-and-privacy">Testing, Security and Privacy</a></li>
<li><a href="approved/0001-agile-coretime.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
<li><a href="approved/0001-agile-coretime.html#drawbacks-alternatives-and-unknowns">Drawbacks, Alternatives and Unknowns</a></li>
<li><a href="approved/0001-agile-coretime.html#prior-art-and-references">Prior Art and References</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-1-agile-coretime"><a class="header" href="#rfc-1-agile-coretime">RFC-1: Agile Coretime</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>30 June 2023</td></tr>
<tr><td><strong>Description</strong></td><td>Agile periodic-sale-based model for assigning Coretime on the Polkadot Ubiquitous Computer.</td></tr>
<tr><td><strong>Authors</strong></td><td>Gavin Wood</td></tr>
</tbody></table>
</div>
<h2 id="summary-21"><a class="header" href="#summary-21">Summary</a></h2>
<p>This proposes a periodic, sale-based method for assigning Polkadot Coretime, the analogue of &quot;block space&quot; within the Polkadot Network. The method takes into account the need for long-term capital expenditure planning for teams building on Polkadot, yet also provides a means to allow Polkadot to capture long-term value in the resource which it sells. It supports the possibility of building rich and dynamic secondary markets to optimize resource allocation and largely avoids the need for parameterization.</p>
<h2 id="motivation-21"><a class="header" href="#motivation-21">Motivation</a></h2>
<h3 id="present-system"><a class="header" href="#present-system">Present System</a></h3>
<p>The <em>Polkadot Ubiquitous Computer</em>, or just <em>Polkadot UC</em>, represents the public service provided by the Polkadot Network. It is a trust-free, WebAssembly-based, multicore, internet-native omnipresent virtual machine which is highly resilient to interference and corruption.</p>
<p>The present system of allocating the limited resources of the Polkadot Ubiquitous Computer is through a process known as <em>parachain slot auctions</em>. This is a parachain-centric paradigm whereby a single core is long-term allocated to a single parachain which itself implies a Substrate/Cumulus-based chain secured and connected via the Relay-chain. Slot auctions are on-chain candle auctions which proceed for several days and result in the core being assigned to the parachain for six months at a time up to 24 months in advance. Practically speaking, we only see two year periods being bid upon and leased.</p>
<p>Funds behind the bids made in the slot auctions are merely locked, they are not consumed or paid and become unlocked and returned to the bidder on expiry of the lease period. A means of sharing the deposit trustlessly known as a <em>crowdloan</em> is available allowing token holders to contribute to the overall deposit of a chain without any counterparty risk.</p>
<h3 id="problems"><a class="header" href="#problems">Problems</a></h3>
<p>The present system is based on a model of one-core-per-parachain. This is a legacy interpretation of the Polkadot platform and is not a reflection of its present capabilities. By restricting ownership and usage to this model, more dynamic and resource-efficient means of utilizing the Polkadot Ubiquitous Computer are lost.</p>
<p>More specifically, it is impossible to lease out cores at anything less than six months, and apparently unrealistic to do so at anything less than two years. This removes the ability to dynamically manage the underlying resource, and generally experimentation, iteration and innovation suffer. It bakes into the platform an assumption of permanence for anything deployed into it and restricts the market's ability to find a more optimal allocation of the finite resource.</p>
<p>There is no ability to determine capital requirements for hosting a parachain beyond two years from the point of its initial deployment onto Polkadot. While it would be unreasonable to have perfect and indefinite cost predictions for any real-world platform, not having any clarity whatsoever beyond &quot;market rates&quot; two years hence can be a very off-putting prospect for teams to buy into.</p>
<p>However, quite possibly the most substantial problem is both a perceived and often real high barrier to entry of the Polkadot ecosystem. By forcing innovators to either raise seven-figure sums through investors or appeal to the wider token-holding community, Polkadot makes it difficult for a small band of innovators to deploy their technology into Polkadot. While not being actually permissioned, it is also far from the barrierless, permissionless ideal which an innovation platform such as Polkadot should be striving for.</p>
<h2 id="requirements-3"><a class="header" href="#requirements-3">Requirements</a></h2>
<ol>
<li>The solution SHOULD provide an acceptable value-capture mechanism for the Polkadot network.</li>
<li>The solution SHOULD allow parachains and other projects deployed on to the Polkadot UC to make long-term capital expenditure predictions for the cost of ongoing deployment.</li>
<li>The solution SHOULD minimize the barriers to entry in the ecosystem.</li>
<li>The solution SHOULD work well when the Polkadot UC has up to 1,000 cores.</li>
<li>The solution SHOULD work when the number of cores which the Polkadot UC can support changes over time.</li>
<li>The solution SHOULD facilitate the optimal allocation of work to cores of the Polkadot UC, including by facilitating the trade of regular core assignment at various intervals and for various spans.</li>
<li>The solution SHOULD avoid creating additional dependencies on functionality which the Relay-chain need not strictly provide for the delivery of the Polkadot UC.</li>
</ol>
<p>Furthermore, the design SHOULD be implementable and deployable in a timely fashion; three months from the acceptance of this RFC should not be unreasonable.</p>
<h2 id="stakeholders-20"><a class="header" href="#stakeholders-20">Stakeholders</a></h2>
<p>Primary stakeholder sets are:</p>
<ul>
<li>Protocol researchers and developers, largely represented by the Polkadot Fellowship and Parity Technologies' Engineering division.</li>
<li>Polkadot Parachain teams both present and future, and their users.</li>
<li>Polkadot DOT token holders.</li>
</ul>
<p><em>Socialization:</em></p>
<p>The essensials of this proposal were presented at Polkadot Decoded 2023 Copenhagen on the Main Stage. A small amount of socialization at the Parachain Summit preceeded it and some substantial discussion followed it. Parity Ecosystem team is currently soliciting views from ecosystem teams who would be key stakeholders.</p>
<h2 id="explanation-20"><a class="header" href="#explanation-20">Explanation</a></h2>
<h3 id="overview-1"><a class="header" href="#overview-1">Overview</a></h3>
<p>Upon implementation of this proposal, the parachain-centric slot auctions and associated crowdloans cease. Instead, Coretime on the Polkadot UC is sold by the Polkadot System in two separate formats: <em>Bulk Coretime</em> and <em>Instantaneous Coretime</em>.</p>
<p>When a Polkadot Core is utilized, we say it is dedicated to a <em>Task</em> rather than a &quot;parachain&quot;. The Task to which a Core is dedicated may change at every Relay-chain block and while one predominant type of Task is to secure a Cumulus-based blockchain (i.e. a parachain), other types of Tasks are envisioned.</p>
<p>Bulk Coretime is sold periodically on a specialised system chain known as the <em>Coretime-chain</em> and allocated in advance of its usage, whereas Instantaneous Coretime is sold on the Relay-chain immediately prior to usage on a block-by-block basis.</p>
<p>This proposal does not fix what should be done with revenue from sales of Coretime and leaves it for a further RFC process.</p>
<p>Owners of Bulk Coretime are tracked on the Coretime-chain and the ownership status and properties of the owned Coretime are exposed over XCM as a non-fungible asset.</p>
<p>At the request of the owner, the Coretime-chain allows a single Bulk Coretime asset, known as a <em>Region</em>, to be used in various ways including transferal to another owner, allocated to a particular task (e.g. a parachain) or placed in the Instantaneous Coretime Pool. Regions can also be split out, either into non-overlapping sub-spans or exactly-overlapping spans with less regularity.</p>
<p>The Coretime-Chain periodically instructs the Relay-chain to assign its cores to alternative tasks as and when Core allocations change due to new Regions coming into effect.</p>
<h4 id="renewal-and-migration"><a class="header" href="#renewal-and-migration">Renewal and Migration</a></h4>
<p>There is a renewal system which allows a Bulk Coretime assignment of a single core to be renewed unchanged with a known price increase from month to month. Renewals are processed in a period prior to regular purchases, effectively giving them precedence over a fixed number of cores available.</p>
<p>Renewals are only enabled when a core's assignment does not include an Instantaneous Coretime allocation and has not been split into shorter segments.</p>
<p>Thus, renewals are designed to ensure only that committed parachains get some guarantees about price for predicting future costs. This price-capped renewal system only allows cores to be reused for their same tasks from month to month. In any other context, Bulk Coretime would need to be purchased regularly.</p>
<p>As a migration mechanism, pre-existing leases (from the legacy lease/slots/crowdloan framework) are initialized into the Coretime-chain and cores assigned to them prior to Bulk Coretime sales. In the sale where the lease expires, the system offers a renewal, as above, to allow a priority sale of Bulk Coretime and ensure that the Parachain suffers no downtime when transitioning from the legacy framework.</p>
<h4 id="instantaneous-coretime"><a class="header" href="#instantaneous-coretime">Instantaneous Coretime</a></h4>
<p>Processing of Instantaneous Coretime happens in part on the Polkadot Relay-chain. Credit is purchased on the Coretime-chain for regular DOT tokens, and this results in a DOT-denominated Instantaneous Coretime Credit account on the Relay-chain being credited for the same amount.</p>
<p>Though the Instantaneous Coretime Credit account records a balance for an account identifier (very likely controlled by a collator), it is <em>non-transferable</em> and <em>non-refundable</em>. It can only be consumed in order to purchase some Instantaneous Coretime with immediate availability.</p>
<p>The Relay-chain reports this usage back to the Coretime-chain in order to allow it to reward the providers of the underlying Coretime, either the Polkadot System or owners of Bulk Coretime who contributed to the Instantaneous Coretime Pool.</p>
<p>Specifically the Relay-chain is expected to be responsible for:</p>
<ul>
<li>holding non-transferable, non-refundable DOT-denominated Instantaneous Coretime Credit balance information.</li>
<li>setting and adjusting the price of Instantaneous Coretime based on usage.</li>
<li>allowing collators to consume their Instantaneous Coretime Credit at the current pricing in exchange for the ability to schedule one PoV for near-immediate usage.</li>
<li>ensuring the Coretime-Chain has timely accounting information on Instantaneous Coretime Sales revenue.</li>
</ul>
<h4 id="coretime-chain"><a class="header" href="#coretime-chain">Coretime-chain</a></h4>
<p>The <em>Coretime-chain</em> is a new system parachain. It has the responsibility of providing the Relay-chain via UMP with information of:</p>
<ul>
<li>The number of cores which should be made available.</li>
<li>Which tasks should be running on which cores and in what ratios.</li>
<li>Accounting information for Instantaneous Coretime Credit.</li>
</ul>
<p>It also expects information from the Relay-chain via DMP:</p>
<ul>
<li>The number of cores available to be scheduled.</li>
<li>Account information on Instantaneous Coretime Sales.</li>
</ul>
<p>The specific interface is properly described in RFC-5.</p>
<h3 id="detail"><a class="header" href="#detail">Detail</a></h3>
<h4 id="parameters-1"><a class="header" href="#parameters-1">Parameters</a></h4>
<p>This proposal includes a number of parameters which need not necessarily be fixed. Their usage is explained below, but their values are suggested or specified in the later section <em>Parameter Values</em>.</p>
<h4 id="reservations-and-leases"><a class="header" href="#reservations-and-leases">Reservations and Leases</a></h4>
<p>The Coretime-chain includes some governance-set reservations of Coretime; these cover every System-chain. Additionally, governance is expected to initialize details of the pre-existing leased chains.</p>
<h4 id="regions"><a class="header" href="#regions">Regions</a></h4>
<p>A <em>Region</em> is an assignable period of Coretime with a known regularity.</p>
<p>All Regions are associated with a unique <em>Core Index</em>, to identify which core the assignment of which ownership of the Region controls.</p>
<p>All Regions are also associated with a <em>Core Mask</em>, an 80-bit bitmap, to denote the regularity at which it may be scheduled on the core. If all bits are set in the Core Mask value, it is said to be <em>Complete</em>. 80 is selected since this results in the size of the datatype used to identify any Region of Polkadot Coretime to be a very convenient 128-bit. Additionally, if <code>TIMESLICE</code> (the number of Relay-chain blocks in a Timeslice) is 80, then a single bit in the Core Mask bitmap represents exactly one Core for one Relay-chain block in one Timeslice.</p>
<p>All Regions have a span. Region spans are quantized into periods of <code>TIMESLICE</code> blocks; <code>BULK_PERIOD</code> divides into <code>TIMESLICE</code> a whole number of times.</p>
<p>The <code>Timeslice</code> type is a <code>u32</code> which can be multiplied by <code>TIMESLICE</code> to give a <code>BlockNumber</code> value representing the same quantity in terms of Relay-chain blocks.</p>
<p>Regions can be tasked to a <code>TaskId</code> (aka <code>ParaId</code>) or pooled into the Instantaneous Coretime Pool. This process can be <em>Provisional</em> or <em>Final</em>. If done only provisionally or not at all then they are fresh and have an <em>Owner</em> which is able to manipulate them further including reassignment. Once <em>Final</em>, then all ownership information is discarded and they cannot be manipulated further. Renewal is not possible when only provisionally tasked/pooled.</p>
<h4 id="bulk-sales"><a class="header" href="#bulk-sales">Bulk Sales</a></h4>
<p>A sale of Bulk Coretime occurs on the Coretime-chain every <code>BULK_PERIOD</code> blocks.</p>
<p>In every sale, a <code>BULK_LIMIT</code> of individual <em>Regions</em> are offered for sale.</p>
<p>Each Region offered for sale has a different Core Index, ensuring that they each represent an independently allocatable resource on the Polkadot UC.</p>
<p>The Regions offered for sale have the same span: they last exactly <code>BULK_PERIOD</code> blocks, and begin immediately following the span of the previous Sale's Regions. The Regions offered for sale also have the complete, non-interlaced, Core Mask.</p>
<p>The Sale Period ends immediately as soon as span of the Coretime Regions that are being sold begins. At this point, the next Sale Price is set according to the previous Sale Price together with the number of Regions sold compared to the desired and maximum amount of Regions to be sold. See Price Setting for additional detail on this point.</p>
<p>Following the end of the previous Sale Period, there is an <em>Interlude Period</em> lasting <code>INTERLUDE_PERIOD</code> of blocks. After this period is elapsed, regular purchasing begins with the <em>Purchasing Period</em>.</p>
<p>This is designed to give at least two weeks worth of time for the purchased regions to be partitioned, interlaced, traded and allocated.</p>
<h4 id="the-interlude"><a class="header" href="#the-interlude">The Interlude</a></h4>
<p>The Interlude period is a period prior to Regular Purchasing where renewals are allowed to happen. This has the effect of ensuring existing long-term tasks/parachains have a chance to secure their Bulk Coretime for a well-known price prior to general sales.</p>
<h4 id="regular-purchasing"><a class="header" href="#regular-purchasing">Regular Purchasing</a></h4>
<p>Any account may purchase Regions of Bulk Coretime if they have the appropriate funds in place during the Purchasing Period, which is from <code>INTERLUDE_PERIOD</code> blocks after the end of the previous sale until the beginning of the Region of the Bulk Coretime which is for sale as long as there are Regions of Bulk Coretime left for sale (i.e. no more than <code>BULK_LIMIT</code> have already been sold in the Bulk Coretime Sale). The Purchasing Period is thus roughly <code>BULK_PERIOD - INTERLUDE_PERIOD</code> blocks in length.</p>
<p>The Sale Price varies during an initial portion of the Purchasing Period called the <em>Leadin Period</em> and then stays stable for the remainder. This initial portion is <code>LEADIN_PERIOD</code> blocks in duration. During the Leadin Period the price decreases towards the Sale Price, which it lands at by the end of the Leadin Period. The actual curve by which the price starts and descends to the Sale Price is outside the scope of this RFC, though a basic suggestion is provided in the Price Setting Notes, below.</p>
<h4 id="renewals"><a class="header" href="#renewals">Renewals</a></h4>
<p>At any time when there are remaining Regions of Bulk Coretime to be sold, <em>including during the Interlude Period</em>, then certain Bulk Coretime assignmnents may be <em>Renewed</em>. This is similar to a purchase in that funds must be paid and it consumes one of the Regions of Bulk Coretime which would otherwise be placed for purchase. However there are two key differences.</p>
<p>Firstly, the price paid is the minimum of <code>RENEWAL_PRICE_CAP</code> more than what the purchase/renewal price was in the previous renewal and the current (or initial, if yet to begin) regular Sale Price.</p>
<p>Secondly, the purchased Region comes preassigned with exactly the same workload as before. It cannot be traded, repartitioned, interlaced or exchanged. As such unlike regular purchasing the Region never has an owner.</p>
<p>Renewal is only possible for either cores which have been assigned as a result of a previous renewal, which are migrating from legacy slot leases, or which fill their Bulk Coretime with an unsegmented, fully and finally assigned workload which does not include placement in the Instantaneous Coretime Pool. The renewed workload will be the same as this initial workload.</p>
<h4 id="manipulation"><a class="header" href="#manipulation">Manipulation</a></h4>
<p>Regions may be manipulated in various ways by its owner:</p>
<ol>
<li><em>Transferred</em> in ownership.</li>
<li><em>Partitioned</em> into quantized, non-overlapping segments of Bulk Coretime with the same ownership.</li>
<li><em>Interlaced</em> into multiple Regions over the same period whose eventual assignments take turns to be scheduled.</li>
<li><em>Assigned</em> to a single, specific task (identified by <code>TaskId</code> aka <code>ParaId</code>). This may be either <em>provisional</em> or <em>final</em>.</li>
<li><em>Pooled</em> into the Instantaneous Coretime Pool, in return for a pro-rata amount of the revenue from the Instantaneous Coretime Sales over its period.</li>
</ol>
<h4 id="enactment"><a class="header" href="#enactment">Enactment</a></h4>
<h3 id="specific-functions-of-the-coretime-chain"><a class="header" href="#specific-functions-of-the-coretime-chain">Specific functions of the Coretime-chain</a></h3>
<p>Several functions of the Coretime-chain SHALL be exposed through dispatchables and/or a <code>nonfungible</code> trait implementation integrated into XCM:</p>
<h4 id="1-transfer"><a class="header" href="#1-transfer">1. <code>transfer</code></a></h4>
<p>Regions may have their ownership transferred.</p>
<p>A <code>transfer(region: RegionId, new_owner: AccountId)</code> dispatchable shall have the effect of altering the current owner of the Region identified by <code>region</code> from the signed origin to <code>new_owner</code>.</p>
<p>An implementation of the <code>nonfungible</code> trait SHOULD include equivalent functionality. <code>RegionId</code> SHOULD be used for the <code>AssetInstance</code> value.</p>
<h4 id="2-partition"><a class="header" href="#2-partition">2. <code>partition</code></a></h4>
<p>Regions may be split apart into two non-overlapping interior Regions of the same Core Mask which together concatenate to the original Region.</p>
<p>A <code>partition(region: RegionId, pivot: Timeslice)</code> dispatchable SHALL have the effect of removing the Region identified by <code>region</code> and adding two new Regions of the same owner and Core Mask. One new Region will begin at the same point of the old Region but end at <code>pivot</code> timeslices into the Region, whereas the other will begin at this point and end at the end point of the original Region.</p>
<p>Also:</p>
<ul>
<li><code>owner</code> field of <code>region</code> must the equal to the Signed origin.</li>
<li><code>pivot</code> must equal neither the <code>begin</code> nor <code>end</code> fields of the <code>region</code>.</li>
</ul>
<h4 id="3-interlace"><a class="header" href="#3-interlace">3. <code>interlace</code></a></h4>
<p>Regions may be decomposed into two Regions of the same span whose eventual assignments take turns on the core by virtue of having complementary Core Masks.</p>
<p>An <code>interlace(region: RegionId, mask: CoreMask)</code> dispatchable shall have the effect of removing the Region identified by <code>region</code> and creating two new Regions. The new Regions will each have the same span and owner of the original Region, but one Region will have a Core Mask equal to <code>mask</code> and the other will have Core Mask equal to the XOR of <code>mask</code> and the Core Mask of the original Region.</p>
<p>Also:</p>
<ul>
<li><code>owner</code> field of <code>region</code> must the equal to the Signed origin.</li>
<li><code>mask</code> must have some bits set AND must not equal the Core Mask of the old Region AND must only have bits set which are also set in the old Region's' Core Mask.</li>
</ul>
<h4 id="4-assign"><a class="header" href="#4-assign">4. <code>assign</code></a></h4>
<p>Regions may be assigned to a core.</p>
<p>A <code>assign(region: RegionId, target: TaskId, finality: Finality)</code> dispatchable shall have the effect of placing an item in the workplan corresponding to the region's properties and assigned to the <code>target</code> task.</p>
<p>If the region's end has already passed (taking into account any advance notice requirements) then this operation is a no-op. If the region's begining has already passed, then it is effectively altered to become the next schedulable timeslice.</p>
<p><code>finality</code> may have the value of either <code>Final</code> or <code>Provisional</code>. If <code>Final</code>, then the operation is free, the <code>region</code> record is removed entirely from storage and renewal may be possible: if the Region's span is the entire <code>BULK_PERIOD</code>, then the Coretime-chain records in storage that the allocation happened during this period in order to facilitate the possibility for a renewal. (Renewal only becomes possible when the full Core Mask of a core is finally assigned for the full <code>BULK_PERIOD</code>.)</p>
<p>Also:</p>
<ul>
<li><code>owner</code> field of <code>region</code> must the equal to the Signed origin.</li>
</ul>
<h4 id="5-pool"><a class="header" href="#5-pool">5. <code>pool</code></a></h4>
<p>Regions may be consumed in exchange for a pro rata portion of the Instantaneous Coretime Sales Revenue from its period and regularity.</p>
<p>A <code>pool(region: RegionId, beneficiary: AccountId, finality: Finality)</code> dispatchable shall have the effect of placing an item in the workplan corresponding to the region's properties and assigned to the Instantaneous Coretime Pool. The details of the region will be recorded in order to allow for a pro rata share of the Instantaneous Coretime Sales Revenue at the time of the Region relative to any other providers in the Pool.</p>
<p>If the region's end has already passed (taking into account any advance notice requirements) then this operation is a no-op. If the region's begining has already passed, then it is effectively altered to become the next schedulable timeslice.</p>
<p><code>finality</code> may have the value of either <code>Final</code> or <code>Provisional</code>. If <code>Final</code>, then the operation is free and the <code>region</code> record is removed entirely from storage.</p>
<p>Also:</p>
<ul>
<li><code>owner</code> field of <code>region</code> must the equal to the Signed origin.</li>
</ul>
<h4 id="6-purchases"><a class="header" href="#6-purchases">6. Purchases</a></h4>
<p>A dispatchable <code>purchase(price_limit: Balance)</code> shall be provided. Any account may call <code>purchase</code> to purchase Bulk Coretime at the maximum price of <code>price_limit</code>.</p>
<p>This may be called successfully only:</p>
<ol>
<li>during the regular Purchasing Period;</li>
<li>when the caller is a Signed origin and their account balance is reducible by the current sale price;</li>
<li>when the current sale price is no greater than <code>price_limit</code>; and</li>
<li>when the number of cores already sold is less than <code>BULK_LIMIT</code>.</li>
</ol>
<p>If successful, the caller's account balance is reduced by the current sale price and a new Region item for the following Bulk Coretime span is issued with the owner equal to the caller's account.</p>
<h4 id="7-renewals"><a class="header" href="#7-renewals">7. Renewals</a></h4>
<p>A dispatchable <code>renew(core: CoreIndex)</code> shall be provided. Any account may call <code>renew</code> to purchase Bulk Coretime and renew an active allocation for the given <code>core</code>.</p>
<p>This may be called during the Interlude Period as well as the regular Purchasing Period and has the same effect as <code>purchase</code> followed by <code>assign</code>, except that:</p>
<ol>
<li>The price of the sale is the Renewal Price (see next).</li>
<li>The Region is allocated exactly the given <code>core</code> is currently allocated for the present Region.</li>
</ol>
<p>Renewal is only valid where a Region's span is assigned to Tasks (not placed in the Instantaneous Coretime Pool) for the entire unsplit <code>BULK_PERIOD</code> over all of the Core Mask and with Finality. There are thus three possibilities of a renewal being allowed:</p>
<ol>
<li>Purchased unsplit Coretime with final assignment to tasks over the full Core Mask.</li>
<li>Renewed Coretime.</li>
<li>A legacy lease which is ending.</li>
</ol>
<p><strong>Renewal Price</strong></p>
<p>The Renewal Price is the minimum of the current regular Sale Price (or the initial Sale Price if in the Interlude Period) and:</p>
<ul>
<li>If the workload being renewed came to be through the <em>Purchase and Assignment</em> of Bulk Coretime, then the price paid during that Purchase operation.</li>
<li>If the workload being renewed was previously renewed, then the price paid during this previous Renewal operation plus <code>RENEWAL_PRICE_CAP</code>.</li>
<li>If the workload being renewed is a migation from a legacy slot auction lease, then the nominal price for a Regular Purchase (outside of the Lead-in Period) of the Sale during which the legacy lease expires.</li>
</ul>
<h4 id="8-instantaneous-coretime-credits"><a class="header" href="#8-instantaneous-coretime-credits">8. Instantaneous Coretime Credits</a></h4>
<p>A dispatchable <code>purchase_credit(amount: Balance, beneficiary: RelayChainAccountId)</code> shall be provided. Any account with at least <code>amount</code> spendable funds may call this. This increases the Instantaneous Coretime Credit balance on the Relay-chain of the <code>beneficiary</code> by the given <code>amount</code>.</p>
<p>This Credit is consumable on the Relay-chain as part of the Task scheduling system and its specifics are out of the scope of this proposal. When consumed, revenue is recorded and provided to the Coretime-chain for proper distribution. The API for doing this is specified in RFC-5.</p>
<h3 id="notes-on-the-instantaneous-coretime-market"><a class="header" href="#notes-on-the-instantaneous-coretime-market">Notes on the Instantaneous Coretime Market</a></h3>
<p>For an efficient market to form around the provision of Bulk-purchased Cores into the pool of cores available for Instantaneous Coretime purchase, it is crucial to ensure that price changes for the purchase of Instantaneous Coretime are reflected well in the revenues of private Coretime providers during the same period.</p>
<p>In order to ensure this, then it is crucial that Instantaneous Coretime, once purchased, cannot be held indefinitely prior to eventual use since, if this were the case, a nefarious collator could purchase Coretime when cheap and utilize it some time later when expensive and deprive private Coretime providers of their revenue.</p>
<p>It must therefore be assumed that Instantaneous Coretime, once purchased, has a definite and short &quot;shelf-life&quot;, after which it becomes unusable. This incentivizes collators to avoid purchasing Coretime unless they expect to utilize it imminently and thus helps create an efficient market-feedback mechanism whereby a higher price will actually result in material revenues for private Coretime providers who contribute to the pool of Cores available to service Instantaneous Coretime purchases.</p>
<h3 id="notes-on-economics"><a class="header" href="#notes-on-economics">Notes on Economics</a></h3>
<p>The specific pricing mechanisms are out of scope for the present proposal. Proposals on economics should be properly described and discussed in another RFC. However, for the sake of completeness, I provide some basic illustration of how price setting could potentially work.</p>
<h4 id="bulk-price-progression"><a class="header" href="#bulk-price-progression">Bulk Price Progression</a></h4>
<p>The present proposal assumes the existence of a price-setting mechanism which takes into account several parameters:</p>
<ul>
<li><code>OLD_PRICE</code>: The price of the previous sale.</li>
<li><code>BULK_TARGET</code>: the target number of cores to be purchased as Bulk Coretime Regions or renewed during the previous sale.</li>
<li><code>BULK_LIMIT</code>: the maximum number of cores which could have been purchased/renewed during the previous sale.</li>
<li><code>CORES_SOLD</code>: the actual number of cores purchased/renewed in the previous sale.</li>
<li><code>SELLOUT_PRICE</code>: the price at which the most recent Bulk Coretime was purchased (<em>not</em> renewed) prior to selling more cores than <code>BULK_TARGET</code> (or immediately after, if none were purchased before). This may not have a value if no Bulk Coretime was purchased.</li>
</ul>
<p>In general we would expect the price to increase the closer <code>CORES_SOLD</code> gets to <code>BULK_LIMIT</code> and to decrease the closer it gets to zero. If it is exactly equal to <code>BULK_TARGET</code>, then we would expect the price to remain the same.</p>
<p>In the edge case that no cores were purchased yet more cores were sold (through renewals) than the target, then we would also avoid altering the price.</p>
<p>A simple example of this would be the formula:</p>
<pre><code>IF SELLOUT_PRICE == NULL AND CORES_SOLD &gt; BULK_TARGET THEN
RETURN OLD_PRICE
END IF
EFFECTIVE_PRICE := IF CORES_SOLD &gt; BULK_TARGET THEN
SELLOUT_PRICE
ELSE
OLD_PRICE
END IF
NEW_PRICE := IF CORES_SOLD &lt; BULK_TARGET THEN
EFFECTIVE_PRICE * MAX(CORES_SOLD, 1) / BULK_TARGET
ELSE
EFFECTIVE_PRICE + EFFECTIVE_PRICE *
(CORES_SOLD - BULK_TARGET) / (BULK_LIMIT - BULK_TARGET)
END IF
</code></pre>
<p>This exists only as a trivial example to demonstrate a basic solution exists, and should not be intended as a concrete proposal.</p>
<h4 id="intra-leadin-price-decrease"><a class="header" href="#intra-leadin-price-decrease">Intra-Leadin Price-decrease</a></h4>
<p>During the Leadin Period of a sale, the effective price starts higher than the Sale Price and falls to end at the Sale Price at the end of the Leadin Period. The price can thus be defined as a simple factor above one on which the Sale Price is multiplied. A function which returns this factor would accept a factor between zero and one specifying the portion of the Leadin Period which has passed.</p>
<p>Thus we assume <code>SALE_PRICE</code>, then we can define <code>PRICE</code> as:</p>
<pre><code>PRICE := SALE_PRICE * FACTOR((NOW - LEADIN_BEGIN) / LEADIN_PERIOD)
</code></pre>
<p>We can define a very simple progression where the price decreases monotonically from double the Sale Price at the beginning of the Leadin Period.</p>
<pre><code>FACTOR(T) := 2 - T
</code></pre>
<h4 id="parameter-values"><a class="header" href="#parameter-values">Parameter Values</a></h4>
<p>Parameters are either <em>suggested</em> or <em>specified</em>. If <em>suggested</em>, it is non-binding and the proposal should not be judged on the value since other RFCs and/or the governance mechanism of Polkadot is expected to specify/maintain it. If <em>specified</em>, then the proposal should be judged on the merit of the value as-is.</p>
<div class="table-wrapper"><table><thead><tr><th>Name</th><th>Value</th><th></th></tr></thead><tbody>
<tr><td><code>BULK_PERIOD</code></td><td><code>28 * DAYS</code></td><td>specified</td></tr>
<tr><td><code>INTERLUDE_PERIOD</code></td><td><code>7 * DAYS</code></td><td>specified</td></tr>
<tr><td><code>LEADIN_PERIOD</code></td><td><code>7 * DAYS</code></td><td>specified</td></tr>
<tr><td><code>TIMESLICE</code></td><td><code>8 * MINUTES</code></td><td>specified</td></tr>
<tr><td><code>BULK_TARGET</code></td><td><code>30</code></td><td>suggested</td></tr>
<tr><td><code>BULK_LIMIT</code></td><td><code>45</code></td><td>suggested</td></tr>
<tr><td><code>RENEWAL_PRICE_CAP</code></td><td><code>Perbill::from_percent(2)</code></td><td>suggested</td></tr>
</tbody></table>
</div>
<h4 id="instantaneous-price-progression"><a class="header" href="#instantaneous-price-progression">Instantaneous Price Progression</a></h4>
<p>This proposal assumes the existence of a Relay-chain-based price-setting mechanism for the Instantaneous Coretime Market which alters from block to block, taking into account several parameters: the last price, the size of the Instantaneous Coretime Pool (in terms of cores per Relay-chain block) and the amount of Instantaneous Coretime waiting for processing (in terms of Core-blocks queued).</p>
<p>The ideal situation is to have the size of the Instantaneous Coretime Pool be equal to some factor of the Instantaneous Coretime waiting. This allows all Instantaneous Coretime sales to be processed with some limited latency while giving limited flexibility over ordering to the Relay-chain apparatus which is needed for efficient operation.</p>
<p>If we set a factor of three, and thus aim to retain a queue of Instantaneous Coretime Sales which can be processed within three Relay-chain blocks, then we would increase the price if the queue goes above three times the amount of cores available, and decrease if it goes under.</p>
<p>Let us assume the values <code>OLD_PRICE</code>, <code>FACTOR</code>, <code>QUEUE_SIZE</code> and <code>POOL_SIZE</code>. A simple definition of the <code>NEW_PRICE</code> would be thus:</p>
<pre><code>NEW_PRICE := IF QUEUE_SIZE &lt; POOL_SIZE * FACTOR THEN
OLD_PRICE * 0.95
ELSE
OLD_PRICE / 0.95
END IF
</code></pre>
<p>This exists only as a trivial example to demonstrate a basic solution exists, and should not be intended as a concrete proposal.</p>
<h3 id="notes-on-types"><a class="header" href="#notes-on-types">Notes on Types</a></h3>
<p>This exists only as a short illustration of a potential technical implementation and should not be treated as anything more.</p>
<h4 id="regions-1"><a class="header" href="#regions-1">Regions</a></h4>
<p>This data schema achieves a number of goals:</p>
<ul>
<li>Coretime can be individually traded at a level of a single usage of a single core.</li>
<li>Coretime Regions, of arbitrary span and up to 1/80th interlacing can be exposed as NFTs and exchanged.</li>
<li>Any Coretime Region can be contributed to the Instantaneous Coretime Pool.</li>
<li>Unlimited number of individual Coretime contributors to the Instantaneous Coretime Pool. (Effectively limited only in number of cores and interlacing level; with current values this would allow 80,000 individual payees per timeslice).</li>
<li>All keys are self-describing.</li>
<li>Workload to communicate core (re-)assignments is well-bounded and low in weight.</li>
<li>All mandatory bookkeeping workload is well-bounded in weight.</li>
</ul>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>type Timeslice = u32; // 80 block amounts.
type CoreIndex = u16;
type CoreMask = [u8; 10]; // 80-bit bitmap.
// 128-bit (16 bytes)
struct RegionId {
begin: Timeslice,
core: CoreIndex,
mask: CoreMask,
}
// 296-bit (37 bytes)
struct RegionRecord {
end: Timeslice,
owner: AccountId,
}
map Regions = Map&lt;RegionId, RegionRecord&gt;;
// 40-bit (5 bytes). Could be 32-bit with a more specialised type.
enum CoreTask {
Off,
Assigned { target: TaskId },
InstaPool,
}
// 120-bit (15 bytes). Could be 14 bytes with a specialised 32-bit `CoreTask`.
struct ScheduleItem {
mask: CoreMask, // 80 bit
task: CoreTask, // 40 bit
}
/// The work we plan on having each core do at a particular time in the future.
type Workplan = Map&lt;(Timeslice, CoreIndex), BoundedVec&lt;ScheduleItem, 80&gt;&gt;;
/// The current workload of each core. This gets updated with workplan as timeslices pass.
type Workload = Map&lt;CoreIndex, BoundedVec&lt;ScheduleItem, 80&gt;&gt;;
enum Contributor {
System,
Private(AccountId),
}
struct ContributionRecord {
begin: Timeslice,
end: Timeslice,
core: CoreIndex,
mask: CoreMask,
payee: Contributor,
}
type InstaPoolContribution = Map&lt;ContributionRecord, ()&gt;;
type SignedTotalMaskBits = u32;
type InstaPoolIo = Map&lt;Timeslice, SignedTotalMaskBits&gt;;
type PoolSize = Value&lt;TotalMaskBits&gt;;
/// Counter for the total CoreMask which could be dedicated to a pool. `u32` so we don't ever get
/// an overflow.
type TotalMaskBits = u32;
struct InstaPoolHistoryRecord {
total_contributions: TotalMaskBits,
maybe_payout: Option&lt;Balance&gt;,
}
/// Total InstaPool rewards for each Timeslice and the number of core Mask which contributed.
type InstaPoolHistory = Map&lt;Timeslice, InstaPoolHistoryRecord&gt;;
<span class="boring">}</span></code></pre></pre>
<p><code>CoreMask</code> tracks unique &quot;parts&quot; of a single core. It is used with interlacing in order to give a unique identifier to each component of any possible interlacing configuration of a core, allowing for simple self-describing keys for all core ownership and allocation information. It also allows for each core's workload to be tracked and updated progressively, keeping ongoing compute costs well-bounded and low.</p>
<p>Regions are issued into the <code>Regions</code> map and can be transferred, partitioned and interlaced as the owner desires. Regions can only be tasked if they begin after the current scheduling deadline (if they have missed this, then the region can be auto-trimmed until it is).</p>
<p>Once tasked, they are removed from there and a record is placed in <code>Workplan</code>. In addition, if they are contributed to the Instantaneous Coretime Pool, then an entry is placing in <code>InstaPoolContribution</code> and <code>InstaPoolIo</code>.</p>
<p>Each timeslice, <code>InstaPoolIo</code> is used to update the current value of <code>PoolSize</code>. A new entry in <code>InstaPoolHistory</code> is inserted, with the <code>total_contributions</code> field of <code>InstaPoolHistoryRecord</code> being informed by the <code>PoolSize</code> value. Each core's has its <code>Workload</code> mutated according to its <code>Workplan</code> for the upcoming timeslice.</p>
<p>When Instantaneous Coretime Market Revenues are reported for a particular timeslice from the Relay-chain, this information gets placed in the <code>maybe_payout</code> field of the relevant record of <code>InstaPoolHistory</code>.</p>
<p>Payments can be requested made for any records in <code>InstaPoolContribution</code> whose <code>begin</code> is the key for a value in <code>InstaPoolHistory</code> whose <code>maybe_payout</code> is <code>Some</code>. In this case, the <code>total_contributions</code> is reduced by the <code>ContributionRecord</code>'s <code>mask</code> and a pro rata amount paid. The <code>ContributionRecord</code> is mutated by incrementing <code>begin</code>, or removed if <code>begin</code> becomes equal to <code>end</code>.</p>
<p>Example:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>// Simple example with a `u16` `CoreMask` and bulk sold in 100 timeslices.
Regions:
{ core: 0u16, begin: 100, mask: 0b1111_1111_1111_1111u16 } =&gt; { end: 200u32, owner: Alice };
// First split @ 50
Regions:
{ core: 0u16, begin: 100, mask: 0b1111_1111_1111_1111u16 } =&gt; { end: 150u32, owner: Alice };
{ core: 0u16, begin: 150, mask: 0b1111_1111_1111_1111u16 } =&gt; { end: 200u32, owner: Alice };
// Share half of first 50 blocks
Regions:
{ core: 0u16, begin: 100, mask: 0b1111_1111_0000_0000u16 } =&gt; { end: 150u32, owner: Alice };
{ core: 0u16, begin: 100, mask: 0b0000_0000_1111_1111u16 } =&gt; { end: 150u32, owner: Alice };
{ core: 0u16, begin: 150, mask: 0b1111_1111_1111_1111u16 } =&gt; { end: 200u32, owner: Alice };
// Sell half of them to Bob
Regions:
{ core: 0u16, begin: 100, mask: 0b1111_1111_0000_0000u16 } =&gt; { end: 150u32, owner: Alice };
{ core: 0u16, begin: 100, mask: 0b0000_0000_1111_1111u16 } =&gt; { end: 150u32, owner: Bob };
{ core: 0u16, begin: 150, mask: 0b1111_1111_1111_1111u16 } =&gt; { end: 200u32, owner: Alice };
// Bob splits first 10 and assigns them to himself.
Regions:
{ core: 0u16, begin: 100, mask: 0b1111_1111_0000_0000u16 } =&gt; { end: 150u32, owner: Alice };
{ core: 0u16, begin: 100, mask: 0b0000_0000_1111_1111u16 } =&gt; { end: 110u32, owner: Bob };
{ core: 0u16, begin: 110, mask: 0b0000_0000_1111_1111u16 } =&gt; { end: 150u32, owner: Bob };
{ core: 0u16, begin: 150, mask: 0b1111_1111_1111_1111u16 } =&gt; { end: 200u32, owner: Alice };
// Bob shares first 10 3 ways and sells smaller shares to Charlie and Dave
Regions:
{ core: 0u16, begin: 100, mask: 0b1111_1111_0000_0000u16 } =&gt; { end: 150u32, owner: Alice };
{ core: 0u16, begin: 100, mask: 0b0000_0000_1100_0000u16 } =&gt; { end: 110u32, owner: Charlie };
{ core: 0u16, begin: 100, mask: 0b0000_0000_0011_0000u16 } =&gt; { end: 110u32, owner: Dave };
{ core: 0u16, begin: 100, mask: 0b0000_0000_0000_1111u16 } =&gt; { end: 110u32, owner: Bob };
{ core: 0u16, begin: 110, mask: 0b0000_0000_1111_1111u16 } =&gt; { end: 150u32, owner: Bob };
{ core: 0u16, begin: 150, mask: 0b1111_1111_1111_1111u16 } =&gt; { end: 200u32, owner: Alice };
// Bob assigns to his para B, Charlie and Dave assign to their paras C and D; Alice assigns first 50 to A
Regions:
{ core: 0u16, begin: 150, mask: 0b1111_1111_1111_1111u16 } =&gt; { end: 200u32, owner: Alice };
Workplan:
(100, 0) =&gt; vec![
{ mask: 0b1111_1111_0000_0000u16, task: Assigned(A) },
{ mask: 0b0000_0000_1100_0000u16, task: Assigned(C) },
{ mask: 0b0000_0000_0011_0000u16, task: Assigned(D) },
{ mask: 0b0000_0000_0000_1111u16, task: Assigned(B) },
]
(110, 0) =&gt; vec![{ mask: 0b0000_0000_1111_1111u16, task: Assigned(B) }]
// Alice assigns her remaining 50 timeslices to the InstaPool paying herself:
Regions: (empty)
Workplan:
(100, 0) =&gt; vec![
{ mask: 0b1111_1111_0000_0000u16, task: Assigned(A) },
{ mask: 0b0000_0000_1100_0000u16, task: Assigned(C) },
{ mask: 0b0000_0000_0011_0000u16, task: Assigned(D) },
{ mask: 0b0000_0000_0000_1111u16, task: Assigned(B) },
]
(110, 0) =&gt; vec![{ mask: 0b0000_0000_1111_1111u16, task: Assigned(B) }]
(150, 0) =&gt; vec![{ mask: 0b1111_1111_1111_1111u16, task: InstaPool }]
InstaPoolContribution:
{ begin: 150, end: 200, core: 0, mask: 0b1111_1111_1111_1111u16, payee: Alice }
InstaPoolIo:
150 =&gt; 16
200 =&gt; -16
// Actual notifications to relay chain.
// Assumes:
// - Timeslice is 10 blocks.
// - Timeslice 0 begins at block #1000.
// - Relay needs 10 blocks notice of change.
//
Workload: 0 =&gt; vec![]
PoolSize: 0
// Block 990:
Relay &lt;= assign_core(core: 0u16, begin: 1000, assignment: vec![(A, 8), (C, 2), (D, 2), (B, 4)])
Workload: 0 =&gt; vec![
{ mask: 0b1111_1111_0000_0000u16, task: Assigned(A) },
{ mask: 0b0000_0000_1100_0000u16, task: Assigned(C) },
{ mask: 0b0000_0000_0011_0000u16, task: Assigned(D) },
{ mask: 0b0000_0000_0000_1111u16, task: Assigned(B) },
]
PoolSize: 0
// Block 1090:
Relay &lt;= assign_core(core: 0u16, begin: 1100, assignment: vec![(A, 8), (B, 8)])
Workload: 0 =&gt; vec![
{ mask: 0b1111_1111_0000_0000u16, task: Assigned(A) },
{ mask: 0b0000_0000_1111_1111u16, task: Assigned(B) },
]
PoolSize: 0
// Block 1490:
Relay &lt;= assign_core(core: 0u16, begin: 1500, assignment: vec![(Pool, 16)])
Workload: 0 =&gt; vec![
{ mask: 0b1111_1111_1111_1111u16, task: InstaPool },
]
PoolSize: 16
InstaPoolIo:
200 =&gt; -16
InstaPoolHistory:
150 =&gt; { total_contributions: 16, maybe_payout: None }
// Sometime after block 1500:
InstaPoolHistory:
150 =&gt; { total_contributions: 16, maybe_payout: Some(P) }
// Sometime after block 1990:
InstaPoolIo: (empty)
PoolSize: 0
InstaPoolHistory:
150 =&gt; { total_contributions: 16, maybe_payout: Some(P0) }
151 =&gt; { total_contributions: 16, maybe_payout: Some(P1) }
152 =&gt; { total_contributions: 16, maybe_payout: Some(P2) }
...
199 =&gt; { total_contributions: 16, maybe_payout: Some(P49) }
// Sometime later still Alice calls for a payout
InstaPoolContribution: (empty)
InstaPoolHistory: (empty)
// Alice gets rewarded P0 + P1 + ... P49.
<span class="boring">}</span></code></pre></pre>
<h3 id="rollout"><a class="header" href="#rollout">Rollout</a></h3>
<p>Rollout of this proposal comes in several phases:</p>
<ol>
<li>Finalise the specifics of implementation; this may be done through a design document or through a well-documented prototype implementation.</li>
<li>Implement the design, including all associated aspects such as unit tests, benchmarks and any support software needed.</li>
<li>If any new parachain is required, launch of this.</li>
<li>Formal audit of the implementation and any manual testing.</li>
<li>Announcement to the various stakeholders of the imminent changes.</li>
<li>Software integration and release.</li>
<li>Governance upgrade proposal(s).</li>
<li>Monitoring of the upgrade process.</li>
</ol>
<h2 id="performance-ergonomics-and-compatibility-18"><a class="header" href="#performance-ergonomics-and-compatibility-18">Performance, Ergonomics and Compatibility</a></h2>
<p>No specific considerations.</p>
<p>Parachains already deployed into the Polkadot UC must have a clear plan of action to migrate to an agile Coretime market.</p>
<p>While this proposal does not introduce documentable features per se, adequate documentation must be provided to potential purchasers of Polkadot Coretime. This SHOULD include any alterations to the Polkadot-SDK software collection.</p>
<h2 id="testing-security-and-privacy-18"><a class="header" href="#testing-security-and-privacy-18">Testing, Security and Privacy</a></h2>
<p>Regular testing through unit tests, integration tests, manual testnet tests, zombie-net tests and fuzzing SHOULD be conducted.</p>
<p>A regular security review SHOULD be conducted prior to deployment through a review by the Web3 Foundation economic research group.</p>
<p>Any final implementation MUST pass a professional external security audit.</p>
<p>The proposal introduces no new privacy concerns.</p>
<h2 id="future-directions-and-related-material-13"><a class="header" href="#future-directions-and-related-material-13">Future Directions and Related Material</a></h2>
<p>RFC-3 proposes a means of implementing the high-level allocations within the Relay-chain.</p>
<p>RFC-5 proposes the API for interacting with Relay-chain.</p>
<p>Additional work should specify the interface for the instantaneous market revenue so that the Coretime-chain can ensure Bulk Coretime placed in the instantaneous market is properly compensated.</p>
<h2 id="drawbacks-alternatives-and-unknowns"><a class="header" href="#drawbacks-alternatives-and-unknowns">Drawbacks, Alternatives and Unknowns</a></h2>
<p>Unknowns include the economic and resource parameterisations:</p>
<ul>
<li>The initial price of Bulk Coretime.</li>
<li>The price-change algorithm between Bulk Coretime sales.</li>
<li>The price increase per Bulk Coretime period for renewals.</li>
<li>The price decrease graph in the Leadin period for Bulk Coretime sales.</li>
<li>The initial price of Instantaneous Coretime.</li>
<li>The price-change algorithm for Instantaneous Coretime sales.</li>
<li>The percentage of cores to be sold as Bulk Coretime.</li>
<li>The fate of revenue collected.</li>
</ul>
<h2 id="prior-art-and-references-19"><a class="header" href="#prior-art-and-references-19">Prior Art and References</a></h2>
<p>Robert Habermeier initially wrote on the subject of Polkadot blockspace-centric in the article <a href="https://www.rob.tech/polkadot-blockspace-over-blockchains/">Polkadot Blockspace over Blockchains</a>. While not going into details, the article served as an early reframing piece for moving beyond one-slot-per-chain models and building out secondary market infrastructure for resource allocation.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0005-coretime-interface.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0005-coretime-interface.html#rfc-5-coretime-interface">RFC-5: Coretime Interface</a>
<ul>
<li><a href="approved/0005-coretime-interface.html#summary">Summary</a></li>
<li><a href="approved/0005-coretime-interface.html#motivation">Motivation</a></li>
<li><a href="approved/0005-coretime-interface.html#requirements">Requirements</a></li>
<li><a href="approved/0005-coretime-interface.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0005-coretime-interface.html#explanation">Explanation</a>
<ul>
<li><a href="approved/0005-coretime-interface.html#ump-message-types">UMP Message Types</a></li>
<li><a href="approved/0005-coretime-interface.html#dmp-message-types">DMP Message Types</a></li>
<li><a href="approved/0005-coretime-interface.html#realistic-limits-of-the-usage">Realistic Limits of the Usage</a></li>
</ul>
</li>
<li><a href="approved/0005-coretime-interface.html#performance-ergonomics-and-compatibility">Performance, Ergonomics and Compatibility</a></li>
<li><a href="approved/0005-coretime-interface.html#testing-security-and-privacy">Testing, Security and Privacy</a></li>
<li><a href="approved/0005-coretime-interface.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
<li><a href="approved/0005-coretime-interface.html#drawbacks-alternatives-and-unknowns">Drawbacks, Alternatives and Unknowns</a></li>
<li><a href="approved/0005-coretime-interface.html#prior-art-and-references">Prior Art and References</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-5-coretime-interface"><a class="header" href="#rfc-5-coretime-interface">RFC-5: Coretime Interface</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>06 July 2023</td></tr>
<tr><td><strong>Description</strong></td><td>Interface for manipulating the usage of cores on the Polkadot Ubiquitous Computer.</td></tr>
<tr><td><strong>Authors</strong></td><td>Gavin Wood, Robert Habermeier</td></tr>
</tbody></table>
</div>
<h2 id="summary-22"><a class="header" href="#summary-22">Summary</a></h2>
<p>In the Agile Coretime model of the Polkadot Ubiquitous Computer, as proposed in RFC-1 and RFC-3, it is necessary for the allocating parachain (envisioned to be one or more pallets on a specialised Brokerage System Chain) to communicate the core assignments to the Relay-chain, which is responsible for ensuring those assignments are properly enacted.</p>
<p>This is a proposal for the interface which will exist around the Relay-chain in order to communicate this information and instructions.</p>
<h2 id="motivation-22"><a class="header" href="#motivation-22">Motivation</a></h2>
<p>The background motivation for this interface is splitting out coretime allocation functions and secondary markets from the Relay-chain onto System parachains. A well-understood and general interface is necessary for ensuring the Relay-chain receives coretime allocation instructions from one or more System chains without introducing dependencies on the implementation details of either side.</p>
<h2 id="requirements-4"><a class="header" href="#requirements-4">Requirements</a></h2>
<ul>
<li>The interface MUST allow the Relay-chain to be scheduled on a low-latency basis.</li>
<li>Individual cores MUST be schedulable, both in full to a single task (a ParaId or the Instantaneous Coretime Pool) or to many unique tasks in differing ratios.</li>
<li>Typical usage of the interface SHOULD NOT overload the VMP message system.</li>
<li>The interface MUST allow for the allocating chain to be notified of all accounting information relevant for making accurate rewards for contributing to the Instantaneous Coretime Pool.</li>
<li>The interface MUST allow for Instantaneous Coretime Market Credits to be communicated.</li>
<li>The interface MUST allow for the allocating chain to instruct changes to the number of cores which it is able to allocate.</li>
<li>The interface MUST allow for the allocating chain to be notified of changes to the number of cores which are able to be allocated by the allocating chain.</li>
</ul>
<h2 id="stakeholders-21"><a class="header" href="#stakeholders-21">Stakeholders</a></h2>
<p>Primary stakeholder sets are:</p>
<ul>
<li>Developers of the Relay-chain core-management logic.</li>
<li>Developers of the Brokerage System Chain and its pallets.</li>
</ul>
<p><em>Socialization:</em></p>
<p>This content of this RFC was discussed in the Polkdot Fellows channel.</p>
<h2 id="explanation-21"><a class="header" href="#explanation-21">Explanation</a></h2>
<p>The interface has two sections: The messages which the Relay-chain is able to receive from the allocating parachain (the <em>UMP message types</em>), and messages which the Relay-chain is able to send to the allocating parachain (the <em>DMP message types</em>). These messages are expected to be able to be implemented in a well-known pallet and called with the XCM <code>Transact</code> instruction.</p>
<p>Future work may include these messages being introduced into the XCM standard.</p>
<h3 id="ump-message-types"><a class="header" href="#ump-message-types">UMP Message Types</a></h3>
<h4 id="request_core_count"><a class="header" href="#request_core_count"><code>request_core_count</code></a></h4>
<p>Prototype:</p>
<pre><code>fn request_core_count(
count: u16,
)
</code></pre>
<p>Requests the Relay-chain to alter the number of schedulable cores to <code>count</code>. Under normal operation, the Relay-chain SHOULD send a <code>notify_core_count(count)</code> message back.</p>
<h4 id="request_revenue_info_at"><a class="header" href="#request_revenue_info_at"><code>request_revenue_info_at</code></a></h4>
<p>Prototype:</p>
<pre><code>fn request_revenue_at(
when: BlockNumber,
)
</code></pre>
<p>Requests that the Relay-chain send a <code>notify_revenue</code> message back at or soon after Relay-chain block number <code>when</code> whose <code>until</code> parameter is equal to <code>when</code>.</p>
<p>The period in to the past which <code>when</code> is allowed to be may be limited; if so the limit should be understood on a channel outside of this proposal. In the case that the request cannot be serviced because <code>when</code> is too old a block then a <code>notify_revenue</code> message must still be returned, but its <code>revenue</code> field may be <code>None</code>.</p>
<h4 id="credit_account"><a class="header" href="#credit_account"><code>credit_account</code></a></h4>
<p>Prototype:</p>
<pre><code>fn credit_account(
who: AccountId,
amount: Balance,
)
</code></pre>
<p>Instructs the Relay-chain to add the <code>amount</code> of DOT to the Instantaneous Coretime Market Credit account of <code>who</code>.</p>
<p>It is expected that Instantaneous Coretime Market Credit on the Relay-chain is NOT transferrable and only redeemable when used to assign cores in the Instantaneous Coretime Pool.</p>
<h4 id="assign_core"><a class="header" href="#assign_core"><code>assign_core</code></a></h4>
<p>Prototype:</p>
<pre><code>type PartsOf57600 = u16;
enum CoreAssignment {
InstantaneousPool,
Task(ParaId),
}
fn assign_core(
core: CoreIndex,
begin: BlockNumber,
assignment: Vec&lt;(CoreAssignment, PartsOf57600)&gt;,
end_hint: Option&lt;BlockNumber&gt;,
)
</code></pre>
<p>Requirements:</p>
<pre><code>assert!(core &lt; core_count);
assert!(targets.iter().map(|x| x.0).is_sorted());
assert_eq!(targets.iter().map(|x| x.0).unique().count(), targets.len());
assert_eq!(targets.iter().map(|x| x.1).sum(), 57600);
</code></pre>
<p>Where:</p>
<ul>
<li><code>core_count</code> is assumed to be the sole parameter in the last received <code>notify_core_count</code> message.</li>
</ul>
<p>Instructs the Relay-chain to ensure that the core indexed as <code>core</code> is utilised for a number of assignments in specific ratios given by <code>assignment</code> starting as soon after <code>begin</code> as possible. Core assignments take the form of a <code>CoreAssignment</code> value which can either task the core to a <code>ParaId</code> value or indicate that the core should be used in the Instantaneous Pool. Each assignment comes with a ratio value, represented as the numerator of the fraction with a denominator of 57,600.</p>
<p>If <code>end_hint</code> is <code>Some</code> and the inner is greater than the current block number, then the Relay-chain should optimize in the expectation of receiving a new <code>assign_core(core, ...)</code> message at or prior to the block number of the inner value. Specific functionality should remain unchanged regardless of the <code>end_hint</code> value.</p>
<p>On the choice of denominator: 57,600 is a very composite number which factors into: 2 ** 8, 3 ** 2, 5 ** 2. By using it as the denominator we allow for various useful fractions to be perfectly represented including thirds, quarters, fifths, tenths, 80ths, percent and 256ths.</p>
<h3 id="dmp-message-types"><a class="header" href="#dmp-message-types">DMP Message Types</a></h3>
<h4 id="notify_core_count"><a class="header" href="#notify_core_count"><code>notify_core_count</code></a></h4>
<p>Prototype:</p>
<pre><code>fn notify_core_count(
count: u16,
)
</code></pre>
<p>Indicate that from this block onwards, the range of acceptable values of the <code>core</code> parameter of <code>assign_core</code> message is <code>[0, count)</code>. <code>assign_core</code> will be a no-op if provided with a value for <code>core</code> outside of this range.</p>
<h4 id="notify_revenue_info"><a class="header" href="#notify_revenue_info"><code>notify_revenue_info</code></a></h4>
<p>Prototype:</p>
<pre><code>fn notify_revenue_info(
until: BlockNumber,
revenue: Option&lt;Balance&gt;,
)
</code></pre>
<p>Provide the amount of revenue accumulated from Instantaneous Coretime Sales from Relay-chain block number <code>last_until</code> to <code>until</code>, not including <code>until</code> itself. <code>last_until</code> is defined as being the <code>until</code> argument of the last <code>notify_revenue</code> message sent, or zero for the first call. If <code>revenue</code> is <code>None</code>, this indicates that the information is no longer available.</p>
<p>This explicitly disregards the possibility of multiple parachains requesting and being notified of revenue information. The Relay-chain must be configured to ensure that only a single revenue information destination exists.</p>
<h3 id="realistic-limits-of-the-usage"><a class="header" href="#realistic-limits-of-the-usage">Realistic Limits of the Usage</a></h3>
<p>For <code>request_revenue_info</code>, a successful request should be possible if <code>when</code> is no less than the Relay-chain block number on arrival of the message less 100,000.</p>
<p>For <code>assign_core</code>, a successful request should be possible if <code>begin</code> is no less than the Relay-chain block number on arrival of the message plus 10 and <code>workload</code> contains no more than 100 items.</p>
<h2 id="performance-ergonomics-and-compatibility-19"><a class="header" href="#performance-ergonomics-and-compatibility-19">Performance, Ergonomics and Compatibility</a></h2>
<p>No specific considerations.</p>
<h2 id="testing-security-and-privacy-19"><a class="header" href="#testing-security-and-privacy-19">Testing, Security and Privacy</a></h2>
<p>Standard Polkadot testing and security auditing applies.</p>
<p>The proposal introduces no new privacy concerns.</p>
<h2 id="future-directions-and-related-material-14"><a class="header" href="#future-directions-and-related-material-14">Future Directions and Related Material</a></h2>
<p>RFC-1 proposes a means of determining allocation of Coretime using this interface.</p>
<p>RFC-3 proposes a means of implementing the high-level allocations within the Relay-chain.</p>
<h2 id="drawbacks-alternatives-and-unknowns-1"><a class="header" href="#drawbacks-alternatives-and-unknowns-1">Drawbacks, Alternatives and Unknowns</a></h2>
<p>None at present.</p>
<h2 id="prior-art-and-references-20"><a class="header" href="#prior-art-and-references-20">Prior Art and References</a></h2>
<p>None.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0007-system-collator-selection.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0007-system-collator-selection.html#rfc-0007-system-collator-selection">RFC-0007: System Collator Selection</a>
<ul>
<li><a href="approved/0007-system-collator-selection.html#summary">Summary</a></li>
<li><a href="approved/0007-system-collator-selection.html#motivation">Motivation</a>
<ul>
<li><a href="approved/0007-system-collator-selection.html#requirements">Requirements</a></li>
</ul>
</li>
<li><a href="approved/0007-system-collator-selection.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0007-system-collator-selection.html#explanation">Explanation</a>
<ul>
<li><a href="approved/0007-system-collator-selection.html#set-size">Set Size</a></li>
</ul>
</li>
<li><a href="approved/0007-system-collator-selection.html#drawbacks">Drawbacks</a></li>
<li><a href="approved/0007-system-collator-selection.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="approved/0007-system-collator-selection.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="approved/0007-system-collator-selection.html#performance">Performance</a></li>
<li><a href="approved/0007-system-collator-selection.html#ergonomics">Ergonomics</a></li>
<li><a href="approved/0007-system-collator-selection.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="approved/0007-system-collator-selection.html#prior-art-and-references">Prior Art and References</a>
<ul>
<li><a href="approved/0007-system-collator-selection.html#written-discussions">Written Discussions</a></li>
<li><a href="approved/0007-system-collator-selection.html#prior-feedback-and-input-from">Prior Feedback and Input From</a></li>
</ul>
</li>
<li><a href="approved/0007-system-collator-selection.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="approved/0007-system-collator-selection.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0007-system-collator-selection"><a class="header" href="#rfc-0007-system-collator-selection">RFC-0007: System Collator Selection</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>07 July 2023</td></tr>
<tr><td><strong>Description</strong></td><td>Mechanism for selecting collators of system chains.</td></tr>
<tr><td><strong>Authors</strong></td><td>Joe Petrowski</td></tr>
</tbody></table>
</div>
<h2 id="summary-23"><a class="header" href="#summary-23">Summary</a></h2>
<p>As core functionality moves from the Relay Chain into system chains, so increases the reliance on
the liveness of these chains for the use of the network. It is not economically scalable, nor
necessary from a game-theoretic perspective, to pay collators large rewards. This RFC proposes a
mechanism -- part technical and part social -- for ensuring reliable collator sets that are
resilient to attemps to stop any subsytem of the Polkadot protocol.</p>
<h2 id="motivation-23"><a class="header" href="#motivation-23">Motivation</a></h2>
<p>In order to guarantee access to Polkadot's system, the collators on its system chains must propose
blocks (provide liveness) and allow all transactions to eventually be included. That is, some
collators may censor transactions, but there must exist one collator in the set who will include a
given transaction. In fact, all collators may censor varying subsets of transactions, but as long
as no transaction is in the intersection of every subset, it will eventually be included. The
objective of this RFC is to propose a mechanism to select such a set on each system chain.</p>
<p>While the network as a whole uses staking (and inflationary rewards) to attract validators,
collators face different challenges in scale and have lower security assumptions than validators.
Regarding scale, there exist many system chains, and it is economically expensive to pay collators
a premium. Likewise, any staked DOT for collation is <em>not</em> staked for validation. Since collator
sets do not need to meet Byzantine Fault Tolerance criteria, staking as the primary mechanism for
collator selection would remove stake that is securing BFT assumptions, making the network less
secure.</p>
<p>Another problem with economic scalability relates to the increasing number of system chains, and
corresponding increase in need for collators (i.e., increase in collator slots). &quot;Good&quot; (highly
available, non-censoring) collators will not want to compete in elections on many chains when they
could use their resources to compete in the more profitable validator election. Such dilution
decreases the required bond on each chain, leaving them vulnerable to takeover by hostile
collator groups.</p>
<p>This RFC proposes a system whereby collation is primarily an infrastructure service, with the
on-chain Treasury reimbursing costs of semi-trusted node operators, referred to as &quot;Invulnerables&quot;.
The system need not trust the individual operators, only that as a <em>set</em> they would be resilient to
coordinated attempts to stop a single chain from halting or to censor a particular subset of
transactions.</p>
<p>In the case that users do not trust this set, this RFC also proposes that each chain always have
available collator positions that can be acquired by anyone by placing a bond.</p>
<h3 id="requirements-5"><a class="header" href="#requirements-5">Requirements</a></h3>
<ul>
<li>System MUST have at least one valid collator for every chain.</li>
<li>System MUST allow anyone to become a collator, provided they <code>reserve</code>/<code>hold</code> enough DOT.</li>
<li>System SHOULD select a set of collators with reasonable expectation that the set will not collude
to censor any subset of transactions.</li>
<li>Collators selected by governance SHOULD have a reasonable expectation that the Treasury will
reimburse their operating costs.</li>
</ul>
<h2 id="stakeholders-22"><a class="header" href="#stakeholders-22">Stakeholders</a></h2>
<ul>
<li>Infrastructure providers (people who run validator/collator nodes)</li>
<li>Polkadot Treasury</li>
</ul>
<h2 id="explanation-22"><a class="header" href="#explanation-22">Explanation</a></h2>
<p>This protocol builds on the existing
<a href="https://github.com/paritytech/cumulus/tree/b15da70/pallets/collator-selection">Collator Selection pallet</a>
and its notion of Invulnerables. Invulnerables are collators (identified by their <code>AccountId</code>s) who
will be selected as part of the collator set every session. Operations relating to the management
of the Invulnerables are done through privileged, governance origins. The implementation should
maintain an API for adding and removing Invulnerable collators.</p>
<p>In addition to Invulnerables, there are also open slots for &quot;Candidates&quot;. Anyone can register as a
Candidate by placing a fixed bond. However, with a fixed bond and fixed number of slots, there is
an obvious selection problem: The slots fill up without any logic to replace their occupants.</p>
<p>This RFC proposes that the collator selection protocol allow Candidates to increase (and decrease)
their individual bonds, sort the Candidates according to bond, and select the top <code>N</code> Candidates.
The selection and changeover should be coordinated by the session manager.</p>
<p>A FRAME pallet already exists for sorting (&quot;bagging&quot;) &quot;top N&quot; groups, the
<a href="https://github.com/paritytech/substrate/blob/5032b8d/frame/bags-list/src/lib.rs">Bags List pallet</a>.
This pallet's <code>SortedListProvider</code> should be integrated into the session manager of the Collator
Selection pallet.</p>
<p>Despite the lack of apparent economic incentives (i.e., inflation), several reasons exist why one
may want to bond funds to participate in the Candidates election, for example:</p>
<ul>
<li>They want to build credibility to be selected as Invulnerable;</li>
<li>They want to ensure availability of an application, e.g. a stablecoin issuer might run a collator
on Asset Hub to ensure transactions in its asset are included in blocks;</li>
<li>They fear censorship themselves, e.g. a voter might think their votes are being censored from
governance, so they run a collator on the governance chain to include their votes.</li>
</ul>
<p>Unlike the fixed-bond mechanism that fills up its Candidates, the election mechanism ensures that
anyone can join the collator set by placing the <code>Nth</code> highest bond.</p>
<h3 id="set-size"><a class="header" href="#set-size">Set Size</a></h3>
<p>In order to achieve the requirements listed under <em>Motivation</em>, it is reasonable to have
approximately:</p>
<ul>
<li>20 collators per system chain,</li>
<li>of which 15 are Invulnerable, and</li>
<li>five are elected by bond.</li>
</ul>
<h2 id="drawbacks-21"><a class="header" href="#drawbacks-21">Drawbacks</a></h2>
<p>The primary drawback is a reliance on governance for continued treasury funding of infrastructure
costs for Invulnerable collators.</p>
<h2 id="testing-security-and-privacy-20"><a class="header" href="#testing-security-and-privacy-20">Testing, Security, and Privacy</a></h2>
<p>The vast majority of cases can be covered by unit testing. Integration test should ensure that the
Collator Selection <code>UpdateOrigin</code>, which has permission to modify the Invulnerables and desired
number of Candidates, can handle updates over XCM from the system's governance location.</p>
<h2 id="performance-ergonomics-and-compatibility-20"><a class="header" href="#performance-ergonomics-and-compatibility-20">Performance, Ergonomics, and Compatibility</a></h2>
<p>This proposal has very little impact on most users of Polkadot, and should improve the performance
of system chains by reducing the number of missed blocks.</p>
<h3 id="performance-18"><a class="header" href="#performance-18">Performance</a></h3>
<p>As chains have strict PoV size limits, care must be taken in the PoV impact of the session manager.
Appropriate benchmarking and tests should ensure that conservative limits are placed on the number
of Invulnerables and Candidates.</p>
<h3 id="ergonomics-15"><a class="header" href="#ergonomics-15">Ergonomics</a></h3>
<p>The primary group affected is Candidate collators, who, after implementation of this RFC, will need
to compete in a bond-based election rather than a race to claim a Candidate spot.</p>
<h3 id="compatibility-15"><a class="header" href="#compatibility-15">Compatibility</a></h3>
<p>This RFC is compatible with the existing implementation and can be handled via upgrades and
migration.</p>
<h2 id="prior-art-and-references-21"><a class="header" href="#prior-art-and-references-21">Prior Art and References</a></h2>
<h3 id="written-discussions"><a class="header" href="#written-discussions">Written Discussions</a></h3>
<ul>
<li><a href="https://github.com/paritytech/roadmap/issues/34">GitHub: Collator Selection Roadmap</a></li>
<li><a href="https://github.com/paritytech/cumulus/issues/1159">GitHub: Revisit Collator Selection Mechanism</a></li>
<li><a href="https://forum.polkadot.network/t/economic-model-for-system-para-collators/1010">Polkadot Forum: Economic Model for System Para Collators</a></li>
</ul>
<h3 id="prior-feedback-and-input-from"><a class="header" href="#prior-feedback-and-input-from">Prior Feedback and Input From</a></h3>
<ul>
<li>Kian Paimani</li>
<li>Jeff Burdges</li>
<li>Rob Habermeier</li>
<li>SR Labs Auditors</li>
<li>Current collators including Paranodes, Stake Plus, Turboflakes, Peter Mensik, SIK, and many more.</li>
</ul>
<h2 id="unresolved-questions-19"><a class="header" href="#unresolved-questions-19">Unresolved Questions</a></h2>
<p>None at this time.</p>
<h2 id="future-directions-and-related-material-15"><a class="header" href="#future-directions-and-related-material-15">Future Directions and Related Material</a></h2>
<p>There may exist in the future system chains for which this model of collator selection is not
appropriate. These chains should be evaluated on a case-by-case basis.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0008-parachain-bootnodes-dht.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0008-parachain-bootnodes-dht.html#rfc-0008-store-parachain-bootnodes-in-relay-chain-dht">RFC-0008: Store parachain bootnodes in relay chain DHT</a>
<ul>
<li><a href="approved/0008-parachain-bootnodes-dht.html#summary">Summary</a></li>
<li><a href="approved/0008-parachain-bootnodes-dht.html#motivation">Motivation</a></li>
<li><a href="approved/0008-parachain-bootnodes-dht.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0008-parachain-bootnodes-dht.html#explanation">Explanation</a>
<ul>
<li><a href="approved/0008-parachain-bootnodes-dht.html#dht-provider-registration">DHT provider registration</a></li>
<li><a href="approved/0008-parachain-bootnodes-dht.html#new-networking-protocol">New networking protocol</a></li>
</ul>
</li>
<li><a href="approved/0008-parachain-bootnodes-dht.html#drawbacks">Drawbacks</a></li>
<li><a href="approved/0008-parachain-bootnodes-dht.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="approved/0008-parachain-bootnodes-dht.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="approved/0008-parachain-bootnodes-dht.html#performance">Performance</a></li>
<li><a href="approved/0008-parachain-bootnodes-dht.html#ergonomics">Ergonomics</a></li>
<li><a href="approved/0008-parachain-bootnodes-dht.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="approved/0008-parachain-bootnodes-dht.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="approved/0008-parachain-bootnodes-dht.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="approved/0008-parachain-bootnodes-dht.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0008-store-parachain-bootnodes-in-relay-chain-dht"><a class="header" href="#rfc-0008-store-parachain-bootnodes-in-relay-chain-dht">RFC-0008: Store parachain bootnodes in relay chain DHT</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>2023-07-14</td></tr>
<tr><td><strong>Description</strong></td><td>Parachain bootnodes shall register themselves in the DHT of the relay chain</td></tr>
<tr><td><strong>Authors</strong></td><td>Pierre Krieger</td></tr>
</tbody></table>
</div>
<h2 id="summary-24"><a class="header" href="#summary-24">Summary</a></h2>
<p>The full nodes of the Polkadot peer-to-peer network maintain a distributed hash table (DHT), which is currently used for full nodes discovery and validators discovery purposes.</p>
<p>This RFC proposes to extend this DHT to be used to discover full nodes of the parachains of Polkadot.</p>
<h2 id="motivation-24"><a class="header" href="#motivation-24">Motivation</a></h2>
<p>The maintenance of bootnodes has long been an annoyance for everyone.</p>
<p>When a bootnode is newly-deployed or removed, every chain specification must be updated in order to take the update into account. This has lead to various non-optimal solutions, such as pulling chain specifications from GitHub repositories.
When it comes to RPC nodes, UX developers often have trouble finding up-to-date addresses of parachain RPC nodes. With the ongoing migration from RPC nodes to light clients, similar problems would happen with chain specifications as well.</p>
<p>Furthermore, there exists multiple different possible variants of a certain chain specification: with the non-raw storage, with the raw storage, with just the genesis trie root hash, with or without checkpoint, etc. All of this creates confusion. Removing the need for parachain developers to be aware of and manage these different versions would be beneficial.</p>
<p>Since the PeerId and addresses of bootnodes needs to be stable, extra maintenance work is required from the chain maintainers. For example, they need to be extra careful when migrating nodes within their infrastructure. In some situations, bootnodes are put behind domain names, which also requires maintenance work.</p>
<p>Because the list of bootnodes in chain specifications is so annoying to modify, the consequence is that the number of bootnodes is rather low (typically between 2 and 15). In order to better resist downtimes and DoS attacks, a better solution would be to use every node of a certain chain as potential bootnode, rather than special-casing some specific nodes.</p>
<p>While this RFC doesn't solve these problems for relay chains, it aims at solving it for parachains by storing the list of all the full nodes of a parachain on the relay chain DHT.</p>
<p>Assuming that this RFC is implemented, and that light clients are used, deploying a parachain wouldn't require more work than registering it onto the relay chain and starting the collators. There wouldn't be any need for special infrastructure nodes anymore.</p>
<h2 id="stakeholders-23"><a class="header" href="#stakeholders-23">Stakeholders</a></h2>
<p>This RFC has been opened on my own initiative because I think that this is a good technical solution to a usability problem that many people are encountering and that they don't realize can be solved.</p>
<h2 id="explanation-23"><a class="header" href="#explanation-23">Explanation</a></h2>
<p>The content of this RFC only applies for parachains and parachain nodes that are &quot;Substrate-compatible&quot;. It is in no way mandatory for parachains to comply to this RFC.</p>
<p>Note that &quot;Substrate-compatible&quot; is very loosely defined as &quot;implements the same mechanisms and networking protocols as Substrate&quot;. The author of this RFC believes that &quot;Substrate-compatible&quot; should be very precisely specified, but there is controversy on this topic.</p>
<p>While a lot of this RFC concerns the implementation of parachain nodes, it makes use of the resources of the Polkadot chain, and as such it is important to describe them in the Polkadot specification.</p>
<p>This RFC adds two mechanisms: a registration in the DHT, and a new networking protocol.</p>
<h3 id="dht-provider-registration"><a class="header" href="#dht-provider-registration">DHT provider registration</a></h3>
<p>This RFC heavily relies on the functionalities of the Kademlia DHT already in use by Polkadot.
You can find a link to the specification <a href="https://github.com/libp2p/specs/tree/master/kad-dht">here</a>.</p>
<p>Full nodes of a parachain registered on Polkadot should register themselves onto the Polkadot DHT as the providers of a key corresponding to the parachain that they are serving, as described in <a href="https://github.com/libp2p/specs/tree/master/kad-dht#content-provider-advertisement">the <code>Content provider advertisement</code> section</a> of the specification. This uses the <code>ADD_PROVIDER</code> system of libp2p-kademlia.</p>
<p>This key is: <code>sha256(concat(scale_compact(para_id), randomness))</code> where the value of <code>randomness</code> can be found in the <code>randomness</code> field when calling the <code>BabeApi_currentEpoch</code> function.
For example, for a <code>para_id</code> equal to 1000, and at the time of writing of this RFC (July 14th 2023 at 09:13 UTC), it is <code>sha(0xa10f12872447958d50aa7b937b0106561a588e0e2628d33f81b5361b13dbcf8df708)</code>, which is equal to <code>0x483dd8084d50dbbbc962067f216c37b627831d9339f5a6e426a32e3076313d87</code>.</p>
<p>In order to avoid downtime when the key changes, parachain full nodes should also register themselves as a secondary key that uses a value of <code>randomness</code> equal to the <code>randomness</code> field when calling <code>BabeApi_nextEpoch</code>.</p>
<p>Implementers should be aware that their implementation of Kademlia might already hash the key before XOR'ing it. The key is not meant to be hashed twice.</p>
<p>The compact SCALE encoding has been chosen in order to avoid problems related to the number of bytes and endianness of the <code>para_id</code>.</p>
<h3 id="new-networking-protocol"><a class="header" href="#new-networking-protocol">New networking protocol</a></h3>
<p>A new request-response protocol should be added, whose name is <code>/91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3/paranode</code> (that hexadecimal number is the genesis hash of the Polkadot chain, and should be adjusted appropriately for Kusama and others).</p>
<p>The request consists in a SCALE-compact-encoded <code>para_id</code>. For example, for a <code>para_id</code> equal to 1000, this is <code>0xa10f</code>.</p>
<p>Note that because this is a request-response protocol, the request is always prefixed with its length in bytes. While the body of the request is simply the SCALE-compact-encoded <code>para_id</code>, the data actually sent onto the substream is both the length and body.</p>
<p>The response consists in a protobuf struct, defined as:</p>
<pre><code>syntax = &quot;proto2&quot;;
message Response {
// Peer ID of the node on the parachain side.
bytes peer_id = 1;
// Multiaddresses of the parachain side of the node. The list and format are the same as for the `listenAddrs` field of the `identify` protocol.
repeated bytes addrs = 2;
// Genesis hash of the parachain. Used to determine the name of the networking protocol to connect to the parachain. Untrusted.
bytes genesis_hash = 3;
// So-called &quot;fork ID&quot; of the parachain. Used to determine the name of the networking protocol to connect to the parachain. Untrusted.
optional string fork_id = 4;
};
</code></pre>
<p>The maximum size of a response is set to an arbitrary 16kiB. The responding side should make sure to conform to this limit. Given that <code>fork_id</code> is typically very small and that the only variable-length field is <code>addrs</code>, this is easily achieved by limiting the number of addresses.</p>
<p>Implementers should be aware that <code>addrs</code> might be very large, and are encouraged to limit the number of <code>addrs</code> to an implementation-defined value.</p>
<h2 id="drawbacks-22"><a class="header" href="#drawbacks-22">Drawbacks</a></h2>
<p>The <code>peer_id</code> and <code>addrs</code> fields are in theory not strictly needed, as the PeerId and addresses could be always equal to the PeerId and addresses of the node being registered as the provider and serving the response. However, the Cumulus implementation currently uses two different networking stacks, one of the parachain and one for the relay chain, using two separate PeerIds and addresses, and as such the PeerId and addresses of the other networking stack must be indicated. Asking them to use only one networking stack wouldn't feasible in a realistic time frame.</p>
<p>The values of the <code>genesis_hash</code> and <code>fork_id</code> fields cannot be verified by the requester and are expected to be unused at the moment. Instead, a client that desires connecting to a parachain is expected to obtain the genesis hash and fork ID of the parachain from the parachain chain specification. These fields are included in the networking protocol nonetheless in case an acceptable solution is found in the future, and in order to allow use cases such as discovering parachains in a not-strictly-trusted way.</p>
<h2 id="testing-security-and-privacy-21"><a class="header" href="#testing-security-and-privacy-21">Testing, Security, and Privacy</a></h2>
<p>Because not all nodes want to be used as bootnodes, implementers are encouraged to provide a way to disable this mechanism. However, it is very much encouraged to leave this mechanism on by default for all parachain nodes.</p>
<p>This mechanism doesn't add or remove any security by itself, as it relies on existing mechanisms.
However, if the principle of chain specification bootnodes is entirely replaced with the mechanism described in this RFC (which is the objective), then it becomes important whether the mechanism in this RFC can be abused in order to make a parachain unreachable.</p>
<p>Due to the way Kademlia works, it would become the responsibility of the 20 Polkadot nodes whose <code>sha256(peer_id)</code> is closest to the <code>key</code> (described in the explanations section) to store the list of bootnodes of each parachain.
Furthermore, when a large number of providers (here, a provider is a bootnode) are registered, only the providers closest to the <code>key</code> are kept, up to a certain implementation-defined limit.</p>
<p>For this reason, an attacker can abuse this mechanism by randomly generating libp2p PeerIds until they find the 20 entries closest to the <code>key</code> representing the target parachain. They are then in control of the parachain bootnodes.
Because the key changes periodically and isn't predictable, and assuming that the Polkadot DHT is sufficiently large, it is not realistic for an attack like this to be maintained in the long term.</p>
<p>Furthermore, parachain clients are expected to cache a list of known good nodes on their disk. If the mechanism described in this RFC went down, it would only prevent new nodes from accessing the parachain, while clients that have connected before would not be affected.</p>
<h2 id="performance-ergonomics-and-compatibility-21"><a class="header" href="#performance-ergonomics-and-compatibility-21">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-19"><a class="header" href="#performance-19">Performance</a></h3>
<p>The DHT mechanism generally has a low overhead, especially given that publishing providers is done only every 24 hours.</p>
<p>Doing a Kademlia iterative query then sending a provider record shouldn't take more than around 50 kiB in total of bandwidth for the parachain bootnode.</p>
<p>Assuming 1000 parachain full nodes, the 20 Polkadot full nodes corresponding to a specific parachain will each receive a sudden spike of a few megabytes of networking traffic when the <code>key</code> rotates. Again, this is relatively negligible. If this becomes a problem, one can add a random delay before a parachain full node registers itself to be the provider of the <code>key</code> corresponding to <code>BabeApi_next_epoch</code>.</p>
<p>Maybe the biggest uncertainty is the traffic that the 20 Polkadot full nodes will receive from light clients that desire knowing the bootnodes of a parachain. Light clients are generally encouraged to cache the peers that they use between restarts, so they should only query these 20 Polkadot full nodes at their first initialization.
If this every becomes a problem, this value of 20 is an arbitrary constant that can be increased for more redundancy.</p>
<h3 id="ergonomics-16"><a class="header" href="#ergonomics-16">Ergonomics</a></h3>
<p>Irrelevant.</p>
<h3 id="compatibility-16"><a class="header" href="#compatibility-16">Compatibility</a></h3>
<p>Irrelevant.</p>
<h2 id="prior-art-and-references-22"><a class="header" href="#prior-art-and-references-22">Prior Art and References</a></h2>
<p>None.</p>
<h2 id="unresolved-questions-20"><a class="header" href="#unresolved-questions-20">Unresolved Questions</a></h2>
<p>While it fundamentally doesn't change much to this RFC, using <code>BabeApi_currentEpoch</code> and <code>BabeApi_nextEpoch</code> might be inappropriate. I'm not familiar enough with good practices within the runtime to have an opinion here. Should it be an entirely new pallet?</p>
<h2 id="future-directions-and-related-material-16"><a class="header" href="#future-directions-and-related-material-16">Future Directions and Related Material</a></h2>
<p>It is possible that in the future a client could connect to a parachain without having to rely on a trusted parachain specification.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0010-burn-coretime-revenue.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0010-burn-coretime-revenue.html#rfc-0010-burn-coretime-revenue">RFC-0010: Burn Coretime Revenue</a>
<ul>
<li><a href="approved/0010-burn-coretime-revenue.html#summary">Summary</a></li>
<li><a href="approved/0010-burn-coretime-revenue.html#motivation">Motivation</a></li>
<li><a href="approved/0010-burn-coretime-revenue.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0010-burn-coretime-revenue.html#explanation">Explanation</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0010-burn-coretime-revenue"><a class="header" href="#rfc-0010-burn-coretime-revenue">RFC-0010: Burn Coretime Revenue</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>19.07.2023</td></tr>
<tr><td><strong>Description</strong></td><td>Revenue from Coretime sales should be burned</td></tr>
<tr><td><strong>Authors</strong></td><td>Jonas Gehrlein</td></tr>
</tbody></table>
</div>
<h2 id="summary-25"><a class="header" href="#summary-25">Summary</a></h2>
<p>The Polkadot UC will generate revenue from the sale of available Coretime. The question then arises: how should we handle these revenues? Broadly, there are two reasonable paths burning the revenue and thereby removing it from total issuance or divert it to the Treasury. This Request for Comment (RFC) presents arguments favoring burning as the preferred mechanism for handling revenues from Coretime sales.</p>
<h2 id="motivation-25"><a class="header" href="#motivation-25">Motivation</a></h2>
<p>How to handle the revenue accrued from Coretime sales is an important economic question that influences the value of DOT and should be properly discussed before deciding for either of the options. Now is the best time to start this discussion.</p>
<h2 id="stakeholders-24"><a class="header" href="#stakeholders-24">Stakeholders</a></h2>
<p>Polkadot DOT token holders.</p>
<h2 id="explanation-24"><a class="header" href="#explanation-24">Explanation</a></h2>
<p>This RFC discusses potential benefits of burning the revenue accrued from Coretime sales instead of diverting them to Treasury. Here are the following arguments for it.</p>
<p>It's in the interest of the Polkadot community to have a consistent and predictable Treasury income, because volatility in the inflow can be damaging, especially in situations when it is insufficient. As such, this RFC operates under the presumption of a steady and sustainable Treasury income flow, which is crucial for the Polkadot community's stability. The assurance of a predictable Treasury income, as outlined in a prior discussion <a href="https://forum.polkadot.network/t/adjusting-the-current-inflation-model-to-sustain-treasury-inflow/3301">here</a>, or through other equally effective measures, serves as a baseline assumption for this argument. </p>
<p>Consequently, we need not concern ourselves with this particular issue here. This naturally begs the question - why should we introduce additional volatility to the Treasury by aligning it with the variable Coretime sales? It's worth noting that Coretime revenues often exhibit an inverse relationship with periods when Treasury spending should ideally be ramped up. During periods of low Coretime utilization (indicated by lower revenue), Treasury should spend more on projects and endeavours to increase the demand for Coretime. This pattern underscores that Coretime sales, by their very nature, are an inconsistent and unpredictable source of funding for the Treasury. Given the importance of maintaining a steady and predictable inflow, it's unnecessary to rely on another volatile mechanism. Some might argue that we could have both: a steady inflow (from inflation) and some added bonus from Coretime sales, but burning the revenue would offer further benefits as described below.</p>
<ul>
<li>
<p><strong>Balancing Inflation:</strong> While DOT as a utility token inherently profits from a (reasonable) net inflation, it also benefits from a deflationary force that functions as a counterbalance to the overall inflation. Right now, the only mechanism on Polkadot that burns fees is the one for underutilized DOT in the Treasury. Finding other, more direct target for burns makes sense and the Coretime market is a good option.</p>
</li>
<li>
<p><strong>Clear incentives:</strong> By burning the revenue accrued on Coretime sales, prices paid by buyers are clearly costs. This removes distortion from the market that might arise when the paid tokens occur on some other places within the network. In that case, some actors might have secondary motives of influencing the price of Coretime sales, because they benefit down the line. For example, actors that actively participate in the Coretime sales are likely to also benefit from a higher Treasury balance, because they might frequently request funds for their projects. While those effects might appear far-fetched, they could accumulate. Burning the revenues makes sure that the prices paid are clearly costs to the actors themselves.</p>
</li>
<li>
<p><strong>Collective Value Accrual:</strong> Following the previous argument, burning the revenue also generates some externality, because it reduces the overall issuance of DOT and thereby increases the value of each remaining token. In contrast to the aforementioned argument, this benefits all token holders collectively and equally. Therefore, I'd consider this as the preferrable option, because burns lets all token holders participate at Polkadot's success as Coretime usage increases.</p>
</li>
</ul>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0012-process-for-adding-new-collectives.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0012-process-for-adding-new-collectives.html#rfc-0012-process-for-adding-new-system-collectives">RFC-0012: Process for Adding New System Collectives</a>
<ul>
<li><a href="approved/0012-process-for-adding-new-collectives.html#summary">Summary</a></li>
<li><a href="approved/0012-process-for-adding-new-collectives.html#motivation">Motivation</a></li>
<li><a href="approved/0012-process-for-adding-new-collectives.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0012-process-for-adding-new-collectives.html#explanation">Explanation</a>
<ul>
<li><a href="approved/0012-process-for-adding-new-collectives.html#removing-collectives">Removing Collectives</a></li>
</ul>
</li>
<li><a href="approved/0012-process-for-adding-new-collectives.html#drawbacks">Drawbacks</a></li>
<li><a href="approved/0012-process-for-adding-new-collectives.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="approved/0012-process-for-adding-new-collectives.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a></li>
<li><a href="approved/0012-process-for-adding-new-collectives.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="approved/0012-process-for-adding-new-collectives.html#unresolved-questions">Unresolved Questions</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0012-process-for-adding-new-system-collectives"><a class="header" href="#rfc-0012-process-for-adding-new-system-collectives">RFC-0012: Process for Adding New System Collectives</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>24 July 2023</td></tr>
<tr><td><strong>Description</strong></td><td>A process for adding new (and removing existing) system collectives.</td></tr>
<tr><td><strong>Authors</strong></td><td>Joe Petrowski</td></tr>
</tbody></table>
</div>
<h2 id="summary-26"><a class="header" href="#summary-26">Summary</a></h2>
<p>Since the introduction of the Collectives parachain, many groups have expressed interest in forming
new -- or migrating existing groups into -- on-chain collectives. While adding a new collective is
relatively simple from a technical standpoint, the Fellowship will need to merge new pallets into
the Collectives parachain for each new collective. This RFC proposes a means for the network to
ratify a new collective, thus instructing the Fellowship to instate it in the runtime.</p>
<h2 id="motivation-26"><a class="header" href="#motivation-26">Motivation</a></h2>
<p>Many groups have expressed interest in representing collectives on-chain. Some of these include:</p>
<ul>
<li>Parachain technical fellowship (new)</li>
<li>Fellowship(s) for media, education, and evangelism (new)</li>
<li>Polkadot Ambassador Program (existing)</li>
<li>Anti-Scam Team (existing)</li>
</ul>
<p>Collectives that form part of the core Polkadot protocol should have a mandate to serve the
Polkadot network. However, as part of the Polkadot protocol, the Fellowship, in its capacity of
maintaining system runtimes, will need to include modules and configurations for each collective.</p>
<p>Once a group has developed a value proposition for the Polkadot network, it should have a clear
path to having its collective accepted on-chain as part of the protocol. Acceptance should direct
the Fellowship to include the new collective with a given initial configuration into the runtime.
However, the network, not the Fellowship, should ultimately decide which collectives are in the
interest of the network.</p>
<h2 id="stakeholders-25"><a class="header" href="#stakeholders-25">Stakeholders</a></h2>
<ul>
<li>Polkadot stakeholders who would like to organize on-chain.</li>
<li>Technical Fellowship, in its role of maintaining system runtimes.</li>
</ul>
<h2 id="explanation-25"><a class="header" href="#explanation-25">Explanation</a></h2>
<p>The group that wishes to operate an on-chain collective should publish the following information:</p>
<ul>
<li>Charter, including the collective's mandate and how it benefits Polkadot. This would be similar
to the
<a href="https://github.com/polkadot-fellows/manifesto/blob/0c3df46/manifesto.pdf">Fellowship Manifesto</a>.</li>
<li>Seeding recommendation.</li>
<li>Member types, i.e. should members be individuals or organizations.</li>
<li>Member management strategy, i.e. how do members join and get promoted, if applicable.</li>
<li>How much, if at all, members should get paid in salary.</li>
<li>Any special origins this Collective should have outside its self. For example, the Fellowship
can whitelist calls for referenda via the <code>WhitelistOrigin</code>.</li>
</ul>
<p>This information could all be in a single document or, for example, a GitHub repository.</p>
<p>After publication, members should seek feedback from the community and Technical Fellowship, and
make any revisions needed. When the collective believes the proposal is ready, they should bring a
remark with the text <code>APPROVE_COLLECTIVE(&quot;{collective name}, {commitment}&quot;)</code> to a Root origin
referendum. The proposer should provide instructions for generating <code>commitment</code>. The passing of
this referendum would be unequivocal direction to the Fellowship that this collective should be
part of the Polkadot runtime.</p>
<p>Note: There is no need for a <code>REJECT</code> referendum. Proposals that have not been approved are simply
not included in the runtime.</p>
<h3 id="removing-collectives"><a class="header" href="#removing-collectives">Removing Collectives</a></h3>
<p>If someone believes that an existing collective is not acting in the interest of the network or in
accordance with its charter, they should likewise have a means to instruct the Fellowship to
<em>remove</em> that collective from Polkadot.</p>
<p>An on-chain remark from the Root origin with the text
<code>REMOVE_COLLECTIVE(&quot;{collective name}, {para ID}, [{pallet indices}]&quot;)</code> would instruct the
Fellowship to remove the collective via the listed pallet indices on <code>paraId</code>. Should someone want
to construct such a remark, they should have a reasonable expectation that a member of the
Fellowship would help them identify the pallet indices associated with a given collective, whether
or not the Fellowship member agrees with removal.</p>
<p>Collective removal may also come with other governance calls, for example voiding any scheduled
Treasury spends that would fund the given collective.</p>
<h2 id="drawbacks-23"><a class="header" href="#drawbacks-23">Drawbacks</a></h2>
<p>Passing a Root origin referendum is slow. However, given the network's investment (in terms of code
maintenance and salaries) in a new collective, this is an appropriate step.</p>
<h2 id="testing-security-and-privacy-22"><a class="header" href="#testing-security-and-privacy-22">Testing, Security, and Privacy</a></h2>
<p>No impacts.</p>
<h2 id="performance-ergonomics-and-compatibility-22"><a class="header" href="#performance-ergonomics-and-compatibility-22">Performance, Ergonomics, and Compatibility</a></h2>
<p>Generally all new collectives will be in the Collectives parachain. Thus, performance impacts
should strictly be limited to this parachain and not affect others. As the majority of logic for
collectives is generalized and reusable, we expect most collectives to be instances of similar
subsets of modules. That is, new collectives should generally be compatible with UIs and other
services that provide collective-related functionality, with little modifications to support new
ones.</p>
<h2 id="prior-art-and-references-23"><a class="header" href="#prior-art-and-references-23">Prior Art and References</a></h2>
<p>The launch of the Technical Fellowship, see the
<a href="https://forum.polkadot.network/t/calling-polkadot-core-developers/506">initial forum post</a>.</p>
<h2 id="unresolved-questions-21"><a class="header" href="#unresolved-questions-21">Unresolved Questions</a></h2>
<p>None at this time.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0013-prepare-blockbuilder-and-core-runtime-apis-for-mbms.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0013-prepare-blockbuilder-and-core-runtime-apis-for-mbms.html#rfc-0013-prepare-core-runtime-api-for-mbms">RFC-0013: Prepare <code>Core</code> runtime API for MBMs</a>
<ul>
<li><a href="approved/0013-prepare-blockbuilder-and-core-runtime-apis-for-mbms.html#summary">Summary</a></li>
<li><a href="approved/0013-prepare-blockbuilder-and-core-runtime-apis-for-mbms.html#motivation">Motivation</a></li>
<li><a href="approved/0013-prepare-blockbuilder-and-core-runtime-apis-for-mbms.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0013-prepare-blockbuilder-and-core-runtime-apis-for-mbms.html#explanation">Explanation</a>
<ul>
<li><a href="approved/0013-prepare-blockbuilder-and-core-runtime-apis-for-mbms.html#coreinitialize_block"><code>Core::initialize_block</code></a></li>
</ul>
</li>
<li><a href="approved/0013-prepare-blockbuilder-and-core-runtime-apis-for-mbms.html#drawbacks">Drawbacks</a></li>
<li><a href="approved/0013-prepare-blockbuilder-and-core-runtime-apis-for-mbms.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="approved/0013-prepare-blockbuilder-and-core-runtime-apis-for-mbms.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="approved/0013-prepare-blockbuilder-and-core-runtime-apis-for-mbms.html#performance">Performance</a></li>
<li><a href="approved/0013-prepare-blockbuilder-and-core-runtime-apis-for-mbms.html#ergonomics">Ergonomics</a></li>
<li><a href="approved/0013-prepare-blockbuilder-and-core-runtime-apis-for-mbms.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="approved/0013-prepare-blockbuilder-and-core-runtime-apis-for-mbms.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="approved/0013-prepare-blockbuilder-and-core-runtime-apis-for-mbms.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="approved/0013-prepare-blockbuilder-and-core-runtime-apis-for-mbms.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0013-prepare-core-runtime-api-for-mbms"><a class="header" href="#rfc-0013-prepare-core-runtime-api-for-mbms">RFC-0013: Prepare <code>Core</code> runtime API for MBMs</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>July 24, 2023</td></tr>
<tr><td><strong>Description</strong></td><td>Prepare the <code>Core</code> Runtime API for Multi-Block-Migrations</td></tr>
<tr><td><strong>Authors</strong></td><td>Oliver Tale-Yazdi</td></tr>
</tbody></table>
</div>
<h2 id="summary-27"><a class="header" href="#summary-27">Summary</a></h2>
<p>Introduces breaking changes to the <code>Core</code> runtime API by letting <code>Core::initialize_block</code> return an enum. The versions of <code>Core</code> is bumped from 4 to 5.</p>
<h2 id="motivation-27"><a class="header" href="#motivation-27">Motivation</a></h2>
<p>The main feature that motivates this RFC are Multi-Block-Migrations (MBM); these make it possible to split a migration over multiple blocks.<br />
Further it would be nice to not hinder the possibility of implementing a new hook <code>poll</code>, that runs at the beginning of the block when there are no MBMs and has access to <code>AllPalletsWithSystem</code>. This hook can then be used to replace the use of <code>on_initialize</code> and <code>on_finalize</code> for non-deadline critical logic.<br />
In a similar fashion, it should not hinder the future addition of a <code>System::PostInherents</code> callback that always runs after all inherents were applied.</p>
<h2 id="stakeholders-26"><a class="header" href="#stakeholders-26">Stakeholders</a></h2>
<ul>
<li>Substrate Maintainers: They have to implement this, including tests, audit and
maintenance burden.</li>
<li>Polkadot Runtime developers: They will have to adapt the runtime files to this breaking change.</li>
<li>Polkadot Parachain Teams: They have to adapt to the breaking changes but then eventually have
multi-block migrations available.</li>
</ul>
<h2 id="explanation-26"><a class="header" href="#explanation-26">Explanation</a></h2>
<h3 id="coreinitialize_block"><a class="header" href="#coreinitialize_block"><code>Core::initialize_block</code></a></h3>
<p>This runtime API function is changed from returning <code>()</code> to <code>ExtrinsicInclusionMode</code>:</p>
<pre><code class="language-patch">fn initialize_block(header: &amp;&lt;Block as BlockT&gt;::Header)
+ -&gt; ExtrinsicInclusionMode;
</code></pre>
<p>With <code>ExtrinsicInclusionMode</code> is defined as:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>enum ExtrinsicInclusionMode {
/// All extrinsics are allowed in this block.
AllExtrinsics,
/// Only inherents are allowed in this block.
OnlyInherents,
}
<span class="boring">}</span></code></pre></pre>
<p>A block author MUST respect the <code>ExtrinsicInclusionMode</code> that is returned by <code>initialize_block</code>. The runtime MUST reject blocks that have non-inherent extrinsics in them while <code>OnlyInherents</code> was returned.</p>
<p>Coming back to the motivations and how they can be implemented with this runtime API change:</p>
<p><strong>1. Multi-Block-Migrations</strong>: The runtime is being put into lock-down mode for the duration of the migration process by returning <code>OnlyInherents</code> from <code>initialize_block</code>. This ensures that no user provided transaction can interfere with the migration process. It is absolutely necessary to ensure this, otherwise a transaction could call into un-migrated storage and violate storage invariants.</p>
<p><strong>2. <code>poll</code></strong> is possible by using <code>apply_extrinsic</code> as entry-point and not hindered by this approach. It would not be possible to use a pallet inherent like <code>System::last_inherent</code> to achieve this for two reasons: First is that pallets do not have access to <code>AllPalletsWithSystem</code> which is required to invoke the <code>poll</code> hook on all pallets. Second is that the runtime does currently not enforce an order of inherents. </p>
<p><strong>3. <code>System::PostInherents</code></strong> can be done in the same manner as <code>poll</code>.</p>
<h2 id="drawbacks-24"><a class="header" href="#drawbacks-24">Drawbacks</a></h2>
<p>The previous drawback of cementing the order of inherents has been addressed and removed by redesigning the approach. No further drawbacks have been identified thus far.</p>
<h2 id="testing-security-and-privacy-23"><a class="header" href="#testing-security-and-privacy-23">Testing, Security, and Privacy</a></h2>
<p>The new logic of <code>initialize_block</code> can be tested by checking that the block-builder will skip transactions when <code>OnlyInherents</code> is returned.</p>
<p>Security: n/a</p>
<p>Privacy: n/a</p>
<h2 id="performance-ergonomics-and-compatibility-23"><a class="header" href="#performance-ergonomics-and-compatibility-23">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-20"><a class="header" href="#performance-20">Performance</a></h3>
<p>The performance overhead is minimal in the sense that no clutter was added after fulfilling the
requirements. The only performance difference is that <code>initialize_block</code> also returns an enum that needs to be passed through the WASM boundary. This should be negligible.</p>
<h3 id="ergonomics-17"><a class="header" href="#ergonomics-17">Ergonomics</a></h3>
<p>The new interface allows for more extensible runtime logic. In the future, this will be utilized for
multi-block-migrations which should be a huge ergonomic advantage for parachain developers.</p>
<h3 id="compatibility-17"><a class="header" href="#compatibility-17">Compatibility</a></h3>
<p>The advice here is OPTIONAL and outside of the RFC. To not degrade
user experience, it is recommended to ensure that an updated node can still import historic blocks.</p>
<h2 id="prior-art-and-references-24"><a class="header" href="#prior-art-and-references-24">Prior Art and References</a></h2>
<p>The RFC is currently being implemented in <a href="https://github.com/paritytech/polkadot-sdk/pull/1781">polkadot-sdk#1781</a> (formerly <a href="https://github.com/paritytech/substrate/pull/14275">substrate#14275</a>). Related issues and merge
requests:</p>
<ul>
<li><a href="https://github.com/paritytech/substrate/pull/14275">Simple multi block migrations</a></li>
<li><a href="https://github.com/paritytech/substrate/issues/9210">Execute a hook after inherent but before
transactions</a></li>
<li><a href="https://github.com/paritytech/substrate/issues/5757">There is no module hook after inherents and before
transactions</a></li>
</ul>
<h2 id="unresolved-questions-22"><a class="header" href="#unresolved-questions-22">Unresolved Questions</a></h2>
<p><del>Please suggest a better name for <code>BlockExecutiveMode</code>. We already tried: <code>RuntimeExecutiveMode</code>,
<code>ExtrinsicInclusionMode</code>. The names of the modes <code>Normal</code> and <code>Minimal</code> were also called
<code>AllExtrinsics</code> and <code>OnlyInherents</code>, so if you have naming preferences; please post them.</del><br />
=&gt; renamed to <code>ExtrinsicInclusionMode</code></p>
<p><del>Is <code>post_inherents</code> more consistent instead of <code>last_inherent</code>? Then we should change it.</del><br />
<del>=&gt; renamed to <code>last_inherent</code></del></p>
<h2 id="future-directions-and-related-material-17"><a class="header" href="#future-directions-and-related-material-17">Future Directions and Related Material</a></h2>
<p>The long-term future here is to move the block building logic into the runtime. Currently there is a tight dance between the block author and the runtime; the author has to call into different runtime functions in quick succession and exact order. Any misstep causes the block to be invalid.<br />
This can be unified and simplified by moving both parts into the runtime.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0014-improve-locking-mechanism-for-parachains.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0014-improve-locking-mechanism-for-parachains.html#rfc-0014-improve-locking-mechanism-for-parachains">RFC-0014: Improve locking mechanism for parachains</a>
<ul>
<li><a href="approved/0014-improve-locking-mechanism-for-parachains.html#summary">Summary</a></li>
<li><a href="approved/0014-improve-locking-mechanism-for-parachains.html#motivation">Motivation</a></li>
<li><a href="approved/0014-improve-locking-mechanism-for-parachains.html#requirements">Requirements</a></li>
<li><a href="approved/0014-improve-locking-mechanism-for-parachains.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0014-improve-locking-mechanism-for-parachains.html#explanation">Explanation</a>
<ul>
<li><a href="approved/0014-improve-locking-mechanism-for-parachains.html#status-quo">Status quo</a></li>
<li><a href="approved/0014-improve-locking-mechanism-for-parachains.html#proposed-changes">Proposed changes</a></li>
<li><a href="approved/0014-improve-locking-mechanism-for-parachains.html#migration">Migration</a></li>
</ul>
</li>
<li><a href="approved/0014-improve-locking-mechanism-for-parachains.html#drawbacks">Drawbacks</a></li>
<li><a href="approved/0014-improve-locking-mechanism-for-parachains.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="approved/0014-improve-locking-mechanism-for-parachains.html#performance">Performance</a></li>
<li><a href="approved/0014-improve-locking-mechanism-for-parachains.html#ergonomics">Ergonomics</a></li>
<li><a href="approved/0014-improve-locking-mechanism-for-parachains.html#compatibility">Compatibility</a></li>
<li><a href="approved/0014-improve-locking-mechanism-for-parachains.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="approved/0014-improve-locking-mechanism-for-parachains.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="approved/0014-improve-locking-mechanism-for-parachains.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0014-improve-locking-mechanism-for-parachains"><a class="header" href="#rfc-0014-improve-locking-mechanism-for-parachains">RFC-0014: Improve locking mechanism for parachains</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>July 25, 2023</td></tr>
<tr><td><strong>Description</strong></td><td>Improve locking mechanism for parachains</td></tr>
<tr><td><strong>Authors</strong></td><td>Bryan Chen</td></tr>
</tbody></table>
</div>
<h2 id="summary-28"><a class="header" href="#summary-28">Summary</a></h2>
<p>This RFC proposes a set of changes to the parachain lock mechanism. The goal is to allow a parachain manager to self-service the parachain without root track governance action.</p>
<p>This is achieved by remove existing lock conditions and only lock a parachain when:</p>
<ul>
<li>A parachain manager explicitly lock the parachain</li>
<li>OR a parachain block is produced successfully</li>
</ul>
<h2 id="motivation-28"><a class="header" href="#motivation-28">Motivation</a></h2>
<p>The manager of a parachain has permission to manage the parachain when the parachain is unlocked. Parachains are by default locked when onboarded to a slot. This requires the parachain wasm/genesis must be valid, otherwise a root track governance action on relaychain is required to update the parachain.</p>
<p>The current reliance on root track governance actions for managing parachains can be time-consuming and burdensome. This RFC aims to address this technical difficulty by allowing parachain managers to take self-service actions, rather than relying on general public voting.</p>
<p>The key scenarios this RFC seeks to improve are:</p>
<ol>
<li>Rescue a parachain with invalid wasm/genesis.</li>
</ol>
<p>While we have various resources and templates to build a new parachain, it is still not a trivial task. It is very easy to make a mistake and resulting an invalid wasm/genesis. With lack of tools to help detect those issues<sup class="footnote-reference"><a href="#1">1</a></sup>, it is very likely that the issues are only discovered after the parachain is onboarded on a slot. In this case, the parachain is locked and the parachain team has to go through a lengthy governance process to rescue the parachain.</p>
<ol start="2">
<li>Perform lease renewal for an existing parachain.</li>
</ol>
<p>One way to perform lease renewal for a parachain is by doing a least swap with another parachain with a longer lease. This requires the other parachain must be operational and able to perform XCM transact call into relaychain to dispatch the swap call. Combined with the overhead of setting up a new parachain, this is an time consuming and expensive process. Ideally, the parachain manager should be able to perform the lease swap call without having a running parachain<sup class="footnote-reference"><a href="#2">2</a></sup>.</p>
<h2 id="requirements-6"><a class="header" href="#requirements-6">Requirements</a></h2>
<ul>
<li>A parachain manager SHOULD be able to rescue a parachain by updating the wasm/genesis without root track governance action.</li>
<li>A parachain manager MUST NOT be able to update the wasm/genesis if the parachain is locked.</li>
<li>A parachain SHOULD be locked when it successfully produced the first block.</li>
<li>A parachain manager MUST be able to perform lease swap without having a running parachain.</li>
</ul>
<h2 id="stakeholders-27"><a class="header" href="#stakeholders-27">Stakeholders</a></h2>
<ul>
<li>Parachain teams</li>
<li>Parachain users</li>
</ul>
<h2 id="explanation-27"><a class="header" href="#explanation-27">Explanation</a></h2>
<h3 id="status-quo"><a class="header" href="#status-quo">Status quo</a></h3>
<p>A parachain can either be locked or unlocked<sup class="footnote-reference"><a href="#3">3</a></sup>. With parachain locked, the parachain manager does not have any privileges. With parachain unlocked, the parachain manager can perform following actions with the <code>paras_registrar</code> pallet:</p>
<ul>
<li><code>deregister</code>: Deregister a Para Id, freeing all data and returning any deposit.</li>
<li><code>swap</code>: Initiate or confirm lease swap with another parachain.</li>
<li><code>add_lock</code>: Lock the parachain.</li>
<li><code>schedule_code_upgrade</code>: Schedule a parachain upgrade to update parachain wasm.</li>
<li><code>set_current_head</code>: Set the parachain's current head.</li>
</ul>
<p>Currently, a parachain can be locked with following conditions:</p>
<ul>
<li>From <code>add_lock</code> call, which can be dispatched by relaychain Root origin, the parachain, or the parachain manager.</li>
<li>When a parachain is onboarded on a slot<sup class="footnote-reference"><a href="#4">4</a></sup>.</li>
<li>When a crowdloan is created.</li>
</ul>
<p>Only the relaychain Root origin or the parachain itself can unlock the lock<sup class="footnote-reference"><a href="#5">5</a></sup>.</p>
<p>This creates an issue that if the parachain is unable to produce block, the parachain manager is unable to do anything and have to rely on relaychain Root origin to manage the parachain.</p>
<h3 id="proposed-changes"><a class="header" href="#proposed-changes">Proposed changes</a></h3>
<p>This RFC proposes to change the lock and unlock conditions.</p>
<p>A parachain can be locked only with following conditions:</p>
<ul>
<li>Relaychain governance MUST be able to lock any parachain.</li>
<li>A parachain MUST be able to lock its own lock.</li>
<li>A parachain manager SHOULD be able to lock the parachain.</li>
<li>A parachain SHOULD be locked when it successfully produced a block for the first time.</li>
</ul>
<p>A parachain can be unlocked only with following conditions:</p>
<ul>
<li>Relaychain governance MUST be able to unlock any parachain.</li>
<li>A parachain MUST be able to unlock its own lock.</li>
</ul>
<p>Note that create crowdloan MUST NOT lock the parachain and onboard a parachain SHOULD NOT lock it until a new block is successfully produced.</p>
<h3 id="migration"><a class="header" href="#migration">Migration</a></h3>
<p>A one off migration is proposed in order to apply this change retrospectively so that existing parachains can also be benefited from this RFC. This migration will unlock parachains that confirms with following conditions:</p>
<ul>
<li>Parachain is locked.</li>
<li>Parachain never produced a block. Including from expired leases.</li>
<li>Parachain manager never explicitly lock the parachain.</li>
</ul>
<h2 id="drawbacks-25"><a class="header" href="#drawbacks-25">Drawbacks</a></h2>
<p>Parachain locks are designed in such way to ensure the decentralization of parachains. If parachains are not locked when it should be, it could introduce centralization risk for new parachains.</p>
<p>For example, one possible scenario is that a collective may decide to launch a parachain fully decentralized. However, if the parachain is unable to produce block, the parachain manager will be able to replace the wasm and genesis without the consent of the collective.</p>
<p>It is considered this risk is tolerable as it requires the wasm/genesis to be invalid at first place. It is not yet practically possible to develop a parachain without any centralized risk currently.</p>
<p>Another case is that a parachain team may decide to use crowdloan to help secure a slot lease. Previously, creating a crowdloan will lock a parachain. This means crowdloan participants will know exactly the genesis of the parachain for the crowdloan they are participating. However, this actually providers little assurance to crowdloan participants. For example, if the genesis block is determined before a crowdloan is started, it is not possible to have onchain mechanism to enforce reward distributions for crowdloan participants. They always have to rely on the parachain team to fulfill the promise after the parachain is alive.</p>
<p>Existing operational parachains will not be impacted.</p>
<h2 id="testing-security-and-privacy-24"><a class="header" href="#testing-security-and-privacy-24">Testing, Security, and Privacy</a></h2>
<p>The implementation of this RFC will be tested on testnets (Rococo and Westend) first.</p>
<p>An audit maybe required to ensure the implementation does not introduce unwanted side effects.</p>
<p>There is no privacy related concerns.</p>
<h2 id="performance-21"><a class="header" href="#performance-21">Performance</a></h2>
<p>This RFC should not introduce any performance impact.</p>
<h2 id="ergonomics-18"><a class="header" href="#ergonomics-18">Ergonomics</a></h2>
<p>This RFC should improve the developer experiences for new and existing parachain teams</p>
<h2 id="compatibility-18"><a class="header" href="#compatibility-18">Compatibility</a></h2>
<p>This RFC is fully compatibility with existing interfaces.</p>
<h2 id="prior-art-and-references-25"><a class="header" href="#prior-art-and-references-25">Prior Art and References</a></h2>
<ul>
<li>Parachain Slot Extension Story: https://github.com/paritytech/polkadot/issues/4758</li>
<li>Allow parachain to renew lease without actually run another parachain: https://github.com/paritytech/polkadot/issues/6685</li>
<li>Always treat parachain that never produced block for a significant amount of time as unlocked: https://github.com/paritytech/polkadot/issues/7539</li>
</ul>
<h2 id="unresolved-questions-23"><a class="header" href="#unresolved-questions-23">Unresolved Questions</a></h2>
<p>None at this stage.</p>
<h2 id="future-directions-and-related-material-18"><a class="header" href="#future-directions-and-related-material-18">Future Directions and Related Material</a></h2>
<p>This RFC is only intended to be a short term solution. Slots will be removed in future and lock mechanism is likely going to be replaced with a more generalized parachain manage &amp; recovery system in future. Therefore long term impacts of this RFC are not considered.</p>
<div class="footnote-definition" id="1"><sup class="footnote-definition-label">1</sup>
<p>https://github.com/paritytech/cumulus/issues/377
<sup class="footnote-reference"><a href="#2">2</a></sup>: https://github.com/paritytech/polkadot/issues/6685
<sup class="footnote-reference"><a href="#3">3</a></sup>: https://github.com/paritytech/polkadot/blob/994af3de79af25544bf39644844cbe70a7b4d695/runtime/common/src/paras_registrar.rs#L51-L52C15
<sup class="footnote-reference"><a href="#4">4</a></sup>: https://github.com/paritytech/polkadot/blob/994af3de79af25544bf39644844cbe70a7b4d695/runtime/common/src/paras_registrar.rs#L473-L475
<sup class="footnote-reference"><a href="#5">5</a></sup>: https://github.com/paritytech/polkadot/blob/994af3de79af25544bf39644844cbe70a7b4d695/runtime/common/src/paras_registrar.rs#L333-L340</p>
</div>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0022-adopt-encointer-runtime.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0022-adopt-encointer-runtime.html#rfc-0022-adopt-encointer-runtime">RFC-0022: Adopt Encointer Runtime</a>
<ul>
<li><a href="approved/0022-adopt-encointer-runtime.html#summary">Summary</a></li>
<li><a href="approved/0022-adopt-encointer-runtime.html#motivation">Motivation</a></li>
<li><a href="approved/0022-adopt-encointer-runtime.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0022-adopt-encointer-runtime.html#explanation">Explanation</a></li>
<li><a href="approved/0022-adopt-encointer-runtime.html#drawbacks">Drawbacks</a></li>
<li><a href="approved/0022-adopt-encointer-runtime.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="approved/0022-adopt-encointer-runtime.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a></li>
<li><a href="approved/0022-adopt-encointer-runtime.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="approved/0022-adopt-encointer-runtime.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="approved/0022-adopt-encointer-runtime.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0022-adopt-encointer-runtime"><a class="header" href="#rfc-0022-adopt-encointer-runtime">RFC-0022: Adopt Encointer Runtime</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>Aug 22nd 2023</td></tr>
<tr><td><strong>Description</strong></td><td>Permanently move the Encointer runtime into the Fellowship runtimes repo.</td></tr>
<tr><td><strong>Authors</strong></td><td>@brenzi for Encointer Association, 8000 Zurich, Switzerland</td></tr>
</tbody></table>
</div>
<h2 id="summary-29"><a class="header" href="#summary-29">Summary</a></h2>
<p>Encointer is a system chain on Kusama since Jan 2022 and has been developed and maintained by the Encointer association. This RFC proposes to treat Encointer like any other system chain and include it in the fellowship repo with <a href="https://github.com/polkadot-fellows/runtimes/pull/17">this PR</a>.</p>
<h2 id="motivation-29"><a class="header" href="#motivation-29">Motivation</a></h2>
<p>Encointer does not seek to be in control of its runtime repository. As a decentralized system, the fellowship has a more suitable structure to maintain a system chain runtime repo than the Encointer association does.</p>
<p>Also, Encointer aims to update its runtime in batches with other system chains in order to have consistency for interoperability across system chains. </p>
<h2 id="stakeholders-28"><a class="header" href="#stakeholders-28">Stakeholders</a></h2>
<ul>
<li>Fellowship: Will continue to take upon them the review and auditing work for the Encointer runtime, but the process is streamlined with other system chains and therefore less time-consuming compared to the separate repo and CI process we currently have.</li>
<li>Kusama Network: Tokenholders can easily see the changes of all system chains in one place.</li>
<li>Encointer Association: Further decentralization of the Encointer Network necessities like devops.</li>
<li>Encointer devs: Being able to work directly in the Fellowship runtimes repo to streamline and synergize with other developers. </li>
</ul>
<h2 id="explanation-28"><a class="header" href="#explanation-28">Explanation</a></h2>
<p><a href="https://github.com/polkadot-fellows/runtimes/pull/17">Our PR</a> has all details about our runtime and how we would move it into the fellowship repo.</p>
<p>Noteworthy: All Encointer-specific pallets will still be located in encointer's repo for the time being: https://github.com/encointer/pallets </p>
<p>It will still be the duty of the Encointer team to keep its runtime up to date and provide adequate test fixtures. Frequent dependency bumps with Polkadot releases would be beneficial for interoperability and could be streamlined with other system chains but that will not be a duty of fellowship. Whenever possible, all system chains could be upgraded jointly (including Encointer) with a batch referendum.</p>
<p>Further notes:</p>
<ul>
<li>Encointer will publish all its crates crates.io</li>
<li>Encointer does not carry out external auditing of its runtime nor pallets. It would be beneficial but not a requirement from our side if Encointer could join the auditing process of other system chains. </li>
</ul>
<h2 id="drawbacks-26"><a class="header" href="#drawbacks-26">Drawbacks</a></h2>
<p>Other than all other system chains, development and maintenance of the Encointer Network is mainly financed by the KSM Treasury and possibly the DOT Treasury in the future. Encointer is dedicated to maintaining its network and runtime code for as long as possible, but there is a dependency on funding which is not in the hands of the fellowship. The only risk in the context of funding, however, is that the Encointer runtime will see less frequent updates if there's less funding. </p>
<h2 id="testing-security-and-privacy-25"><a class="header" href="#testing-security-and-privacy-25">Testing, Security, and Privacy</a></h2>
<p>No changes to the existing system are proposed. Only changes to how maintenance is organized.</p>
<h2 id="performance-ergonomics-and-compatibility-24"><a class="header" href="#performance-ergonomics-and-compatibility-24">Performance, Ergonomics, and Compatibility</a></h2>
<p>No changes</p>
<h2 id="prior-art-and-references-26"><a class="header" href="#prior-art-and-references-26">Prior Art and References</a></h2>
<p><a href="https://github.com/encointer/encointer-parachain/tree/master/polkadot-parachains/encointer-runtime">Existing Encointer runtime repo</a></p>
<h2 id="unresolved-questions-24"><a class="header" href="#unresolved-questions-24">Unresolved Questions</a></h2>
<p>None identified</p>
<h2 id="future-directions-and-related-material-19"><a class="header" href="#future-directions-and-related-material-19">Future Directions and Related Material</a></h2>
<p>More info on Encointer: <a href="https://encointer.org">encointer.org</a></p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0026-sassafras-consensus.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0026-sassafras-consensus.html#rfc-0026-sassafras-consensus-protocol">RFC-0026: Sassafras Consensus Protocol</a>
<ul>
<li><a href="approved/0026-sassafras-consensus.html#abstract">Abstract</a></li>
<li><a href="approved/0026-sassafras-consensus.html#1-motivation">1. Motivation</a>
<ul>
<li><a href="approved/0026-sassafras-consensus.html#11-relevance-to-implementors">1.1. Relevance to Implementors</a></li>
<li><a href="approved/0026-sassafras-consensus.html#12-supporting-sassafras-for-polkadot">1.2. Supporting Sassafras for Polkadot</a></li>
</ul>
</li>
<li><a href="approved/0026-sassafras-consensus.html#2-stakeholders">2. Stakeholders</a>
<ul>
<li><a href="approved/0026-sassafras-consensus.html#21-blockchain-core-developers">2.1. Blockchain Core Developers</a></li>
<li><a href="approved/0026-sassafras-consensus.html#22-polkadot-ecosystem-contributors">2.2. Polkadot Ecosystem Contributors</a></li>
</ul>
</li>
<li><a href="approved/0026-sassafras-consensus.html#3-notation">3. Notation</a>
<ul>
<li><a href="approved/0026-sassafras-consensus.html#31-data-structures-definitions">3.1. Data Structures Definitions</a></li>
<li><a href="approved/0026-sassafras-consensus.html#32-types-alias">3.2. Types Alias</a></li>
<li><a href="approved/0026-sassafras-consensus.html#32-pseudo-code">3.2. Pseudo-Code</a></li>
<li><a href="approved/0026-sassafras-consensus.html#33-incremental-introduction-of-types-and-functions">3.3. Incremental Introduction of Types and Functions</a></li>
</ul>
</li>
<li><a href="approved/0026-sassafras-consensus.html#4-protocol-introduction">4. Protocol Introduction</a>
<ul>
<li><a href="approved/0026-sassafras-consensus.html#41-submission-of-candidate-tickets">4.1. Submission of Candidate Tickets</a></li>
<li><a href="approved/0026-sassafras-consensus.html#42-validation-of-candidate-tickets">4.2. Validation of Candidate Tickets</a></li>
<li><a href="approved/0026-sassafras-consensus.html#43-tickets-slots-binding">4.3. Tickets Slots Binding</a></li>
<li><a href="approved/0026-sassafras-consensus.html#44-claim-of-ticket-ownership">4.4. Claim of Ticket Ownership</a></li>
</ul>
</li>
<li><a href="approved/0026-sassafras-consensus.html#5-bandersnatch-vrfs-cryptographic-primitives">5. Bandersnatch VRFs Cryptographic Primitives</a>
<ul>
<li><a href="approved/0026-sassafras-consensus.html#51-bare-vrf-interface">5.1 Bare VRF Interface</a></li>
</ul>
</li>
<li><a href="approved/0026-sassafras-consensus.html#6-sassafras-protocol">6. Sassafras Protocol</a>
<ul>
<li><a href="approved/0026-sassafras-consensus.html#62-header-digest-log">6.2. Header Digest Log</a></li>
<li><a href="approved/0026-sassafras-consensus.html#63-on-chain-randomness">6.3. On-Chain Randomness</a></li>
<li><a href="approved/0026-sassafras-consensus.html#64-epoch-change-signal">6.4. Epoch Change Signal</a></li>
<li><a href="approved/0026-sassafras-consensus.html#65-tickets-creation-and-submission">6.5. Tickets Creation and Submission</a></li>
<li><a href="approved/0026-sassafras-consensus.html#66-on-chain-tickets-validation">6.6. On-chain Tickets Validation</a></li>
<li><a href="approved/0026-sassafras-consensus.html#67-ticket-slot-binding">6.7. Ticket-Slot Binding</a></li>
<li><a href="approved/0026-sassafras-consensus.html#68-slot-claim">6.8. Slot Claim</a></li>
<li><a href="approved/0026-sassafras-consensus.html#69-slot-claim-verification">6.9. Slot Claim Verification</a></li>
<li><a href="approved/0026-sassafras-consensus.html#691-primary-method">6.9.1. Primary Method</a></li>
<li><a href="approved/0026-sassafras-consensus.html#610-randomness-accumulator">6.10. Randomness Accumulator</a></li>
</ul>
</li>
<li><a href="approved/0026-sassafras-consensus.html#7-drawbacks">7. Drawbacks</a></li>
<li><a href="approved/0026-sassafras-consensus.html#8-testing-security-and-privacy">8. Testing, Security, and Privacy</a></li>
<li><a href="approved/0026-sassafras-consensus.html#9-performance-ergonomics-and-compatibility">9. Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="approved/0026-sassafras-consensus.html#91-performance">9.1. Performance</a></li>
<li><a href="approved/0026-sassafras-consensus.html#92-ergonomics">9.2. Ergonomics</a></li>
<li><a href="approved/0026-sassafras-consensus.html#93-compatibility">9.3. Compatibility</a></li>
</ul>
</li>
<li><a href="approved/0026-sassafras-consensus.html#10-prior-art-and-references">10. Prior Art and References</a></li>
<li><a href="approved/0026-sassafras-consensus.html#11-unresolved-questions">11. Unresolved Questions</a></li>
<li><a href="approved/0026-sassafras-consensus.html#12-future-directions-and-related-material">12. Future Directions and Related Material</a>
<ul>
<li><a href="approved/0026-sassafras-consensus.html#121-interactions-with-on-chain-code">12.1. Interactions with On-Chain Code</a></li>
<li><a href="approved/0026-sassafras-consensus.html#122-deployment-strategies">12.2. Deployment Strategies</a></li>
<li><a href="approved/0026-sassafras-consensus.html#123-zk-snark-parameters">12.3. ZK-SNARK Parameters</a></li>
<li><a href="approved/0026-sassafras-consensus.html#124-anonymous-submission-of-tickets">12.4. Anonymous Submission of Tickets.</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<h1 id="rfc-0026-sassafras-consensus-protocol"><a class="header" href="#rfc-0026-sassafras-consensus-protocol">RFC-0026: Sassafras Consensus Protocol</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>September 06, 2023</td></tr>
<tr><td><strong>Description</strong></td><td>Sassafras consensus protocol specification</td></tr>
<tr><td><strong>Authors</strong></td><td>Davide Galassi</td></tr>
</tbody></table>
</div>
<h2 id="abstract"><a class="header" href="#abstract">Abstract</a></h2>
<p>Sassafras is a novel consensus protocol designed to address the recurring
fork-related challenges encountered in other lottery-based protocols.</p>
<p>The protocol aims to create a mapping between each epoch's slots and the
authorities set while ensuring that the identity of authorities assigned to
the slots remains undisclosed until the slot is actively claimed during block
production.</p>
<h2 id="1-motivation"><a class="header" href="#1-motivation">1. Motivation</a></h2>
<p>Sassafras Protocol has been rigorously described in a comprehensive
<a href="https://eprint.iacr.org/2023/031.pdf">research paper</a> authored by the
<a href="https://web3.foundation">Web3 Foundation</a> research team.</p>
<p>This RFC is primarily intended to detail the critical implementation aspects
vital for ensuring interoperability and to clarify certain aspects that are
left open by the research paper and thus subject to interpretation during
implementation.</p>
<h3 id="11-relevance-to-implementors"><a class="header" href="#11-relevance-to-implementors">1.1. Relevance to Implementors</a></h3>
<p>This RFC focuses on providing implementors with the necessary insights into the
core protocol's operation.</p>
<p>In instances of inconsistency between this document and the research paper,
this RFC should be considered authoritative to eliminate ambiguities and ensure
interoperability.</p>
<h3 id="12-supporting-sassafras-for-polkadot"><a class="header" href="#12-supporting-sassafras-for-polkadot">1.2. Supporting Sassafras for Polkadot</a></h3>
<p>Beyond promoting interoperability, this RFC also aims to facilitate the
implementation of Sassafras within the greater Polkadot ecosystem.</p>
<p>Although the specifics of deployment strategies are beyond the scope of this
document, it lays the groundwork for the integration of Sassafras.</p>
<h2 id="2-stakeholders"><a class="header" href="#2-stakeholders">2. Stakeholders</a></h2>
<p>The protocol has a central role in the next generation block authoring consensus
systems.</p>
<h3 id="21-blockchain-core-developers"><a class="header" href="#21-blockchain-core-developers">2.1. Blockchain Core Developers</a></h3>
<p>Developers responsible for creating blockchains who intend to leverage the
benefits offered by the Sassafras Protocol.</p>
<h3 id="22-polkadot-ecosystem-contributors"><a class="header" href="#22-polkadot-ecosystem-contributors">2.2. Polkadot Ecosystem Contributors</a></h3>
<p>Developers contributing to the Polkadot ecosystem, both relay-chain and
para-chains.</p>
<h2 id="3-notation"><a class="header" href="#3-notation">3. Notation</a></h2>
<p>This section outlines the notation adopted throughout this document to ensure
clarity and consistency.</p>
<h3 id="31-data-structures-definitions"><a class="header" href="#31-data-structures-definitions">3.1. Data Structures Definitions</a></h3>
<p>Data structures are mostly defined using standard <a href="https://www.itu.int/en/ITU-T/asn1/Pages/introduction.aspx">ASN.1</a>
syntax with few exceptions.</p>
<p>To ensure interoperability of serialized structures, the order of the fields
must match the definitions found within this specification.</p>
<h3 id="32-types-alias"><a class="header" href="#32-types-alias">3.2. Types Alias</a></h3>
<ul>
<li>Unsigned integer: <code>Unsigned ::= INTEGER (0..MAX)</code></li>
<li>n-bit unsigned integer: <code>Unsigned&lt;n&gt; ::= INTEGER (0..2^n - 1)</code>
<ul>
<li>8-bit unsigned integer (octet) <code>Unsigned8 ::= Unsigned&lt;8&gt;</code></li>
<li>32-bit unsigned integer: <code>Unsigned32 ::= Unsigned&lt;32&gt;</code></li>
<li>64-bit unsigned integer: <code>Unsigned64 ::= Unsigned&lt;64&gt;</code></li>
</ul>
</li>
<li>Non-homogeneous sequence (struct/tuple): <code>Sequence ::= SEQUENCE</code></li>
<li>Variable length homogeneous sequence (vector): <code>Sequence&lt;T&gt; ::= SEQUENCE OF T</code></li>
<li>Fixed length homogeneous sequence (array): <code>Sequence&lt;T,n&gt; ::= Sequence&lt;T&gt; (SIZE(n))</code></li>
<li>Variable length octet-string: <code>OctetString ::= Sequence&lt;Unsigned8&gt;</code></li>
<li>Fixed length octet-string: <code>OctetString&lt;n&gt; ::= Sequence&lt;Unsigned8, n&gt;</code></li>
</ul>
<h3 id="32-pseudo-code"><a class="header" href="#32-pseudo-code">3.2. Pseudo-Code</a></h3>
<p>It is convenient to make use of code snippets as part of the protocol
description. As a convention, the code is formatted in a style similar to
<em>Rust</em>, and can make use of the following set of predefined procedures:</p>
<h4 id="sequences"><a class="header" href="#sequences">Sequences</a></h4>
<ul>
<li>
<p><code>CONCAT(x₀: OctetString, ..., xₖ: OctetString) -&gt; OctetString</code>: Concatenates the
input octet-strings as a new octet string.</p>
</li>
<li>
<p><code>LENGTH(s: Sequence) -&gt; Unsigned</code>: The number of elements in the sequence <code>s</code>.</p>
</li>
<li>
<p><code>GET(s: Sequence&lt;T&gt;, i: Unsigned) -&gt; T</code>: The <code>i</code>-th element of the sequence <code>s</code>.</p>
</li>
<li>
<p><code>PUSH(s: Sequence&lt;T&gt;, x: T)</code>: Appends <code>x</code> as the new last element of the sequence <code>s</code>.</p>
</li>
<li>
<p><code>POP(s: Sequence&lt;T&gt;) -&gt; T</code>: extract and returns the last element of the sequence <code>s</code>.</p>
</li>
</ul>
<h4 id="codec"><a class="header" href="#codec">Codec</a></h4>
<ul>
<li>
<p><code>ENCODE(x: T) -&gt; OctetString</code>: Encodes <code>x</code> as an <code>OctetString</code> according to
<a href="https://github.com/paritytech/parity-scale-codec">SCALE</a> codec.</p>
</li>
<li>
<p><code>DECODE&lt;T&gt;(x: OctetString) -&gt; T</code>: Decodes <code>x</code> as a type <code>T</code> object according
to <a href="https://github.com/paritytech/parity-scale-codec">SCALE</a> codec.</p>
</li>
</ul>
<h4 id="other"><a class="header" href="#other">Other</a></h4>
<ul>
<li><code>BLAKE2(x: OctetString) -&gt; OctetString&lt;32&gt;</code>: Standard <em>Blake2b</em> hash
of <code>x</code> with 256-bit digest.</li>
</ul>
<h3 id="33-incremental-introduction-of-types-and-functions"><a class="header" href="#33-incremental-introduction-of-types-and-functions">3.3. Incremental Introduction of Types and Functions</a></h3>
<p>More types and helper functions are introduced incrementally as they become
relevant within the document's context.</p>
<h2 id="4-protocol-introduction"><a class="header" href="#4-protocol-introduction">4. Protocol Introduction</a></h2>
<p>The timeline is segmented into a sequentially ordered sequence of <strong>slots</strong>.
This entire sequence of slots is further partitioned into distinct segments
known as <strong>epochs</strong>.</p>
<p>Sassafras aims to map each slot within a <em>target epoch</em> to the authorities
scheduled for that epoch, utilizing a ticketing system.</p>
<p>The core protocol operation can be roughly divided into four phases.</p>
<h3 id="41-submission-of-candidate-tickets"><a class="header" href="#41-submission-of-candidate-tickets">4.1. Submission of Candidate Tickets</a></h3>
<p>Each authority scheduled for the target epoch generates and shares a set of
candidate tickets. Every ticket has an <em>unbiasable</em> pseudo random score and is
bundled with an anonymous proof of validity.</p>
<h3 id="42-validation-of-candidate-tickets"><a class="header" href="#42-validation-of-candidate-tickets">4.2. Validation of Candidate Tickets</a></h3>
<p>Each candidate ticket undergoes a validation process for the associated validity
proof and compliance with other protocol-specific constraints. Valid tickets
are persisted on-chain.</p>
<h3 id="43-tickets-slots-binding"><a class="header" href="#43-tickets-slots-binding">4.3. Tickets Slots Binding</a></h3>
<p>After collecting all valid candidate tickets and before the beginning of the
<em>target epoch</em>, a deterministic method is used to uniquely associate a subset of
these tickets to the slots of the <em>target epoch</em>.</p>
<h3 id="44-claim-of-ticket-ownership"><a class="header" href="#44-claim-of-ticket-ownership">4.4. Claim of Ticket Ownership</a></h3>
<p>During block production phase of <em>target epoch</em>, the author is required to prove
ownership of the ticket associated to the block's slot. This step discloses the
identity of the ticket owner.</p>
<h2 id="5-bandersnatch-vrfs-cryptographic-primitives"><a class="header" href="#5-bandersnatch-vrfs-cryptographic-primitives">5. Bandersnatch VRFs Cryptographic Primitives</a></h2>
<p>This section is not intended to serve as an exhaustive exploration of the
mathematically intensive foundations of the cryptographic primitive. Rather, its
primary aim is to offer a concise and accessible explanation of the primitives
role and interface which is relevant within the scope of the protocol. For a more
detailed explanation, refer to the <a href="https://github.com/davxy/bandersnatch-vrfs-spec">Bandersnatch VRFs</a>
technical specification</p>
<p>Bandersnatch VRF comes in two variants:</p>
<ul>
<li><em>Bare</em> VRF: Extension to the IETF ECVRF <a href="https://datatracker.ietf.org/doc/rfc9381/">RFC 9381</a>,</li>
<li><em>Ring</em> VRF: Anonymous signatures leveraging <em>zk-SNARK</em>.</li>
</ul>
<p>Together with the <em>input</em>, which determines the VRF <em>output</em>, both variants
offer the capability to sign some arbitrary additional data (<em>extra</em>) which
doesn't contribute to the VRF output.</p>
<h3 id="51-bare-vrf-interface"><a class="header" href="#51-bare-vrf-interface">5.1 Bare VRF Interface</a></h3>
<p>VRF signature construction.</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> fn vrf_sign(
secret: SecretKey,
input: OctetString,
extra: OctetString,
) -&gt; VrfSignature
<span class="boring">}</span></code></pre></pre>
<p>VRF signature verification. Returns a Boolean indicating the validity of the
signature (<code>1</code> on success).</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> fn vrf_verify(
public: PublicKey,
input: OctetString,
extra: OctetString,
signature: VrfSignature
) -&gt; Unsigned&lt;1&gt;;
<span class="boring">}</span></code></pre></pre>
<p>VRF <em>output</em> derivation from <em>input</em> and <em>secret</em>.</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> fn vrf_output(
secret: SecretKey,
input: OctetString,
) -&gt; OctetString&lt;32&gt;;
<span class="boring">}</span></code></pre></pre>
<p>VRF <em>output</em> derivation from a VRF signature.</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> fn vrf_signed_output(
signature: VrfSignature,
) -&gt; OctetString&lt;32&gt;;
<span class="boring">}</span></code></pre></pre>
<p>The following condition is always satisfied:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> let signature = vrf_sign(secret, input, extra);
vrf_output(secret, input) == vrf_signed_output(signature)
<span class="boring">}</span></code></pre></pre>
<p><code>SecretKey</code>, <code>PublicKey</code> and <code>VrfSignature</code> types are intentionally left
undefined. Their definitions can be found in the Bandersnatch VRF specification
and related documents.</p>
<h4 id="542-ring-vrf-interface"><a class="header" href="#542-ring-vrf-interface">5.4.2. Ring VRF Interface</a></h4>
<p>Ring VRF signature construction.</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> fn ring_vrf_sign(
secret: SecretKey,
prover: RingProver,
input: OctetString,
extra: OctetString,
) -&gt; RingVrfSignature;
<span class="boring">}</span></code></pre></pre>
<p>Ring VRF signature verification. Returns a Boolean indicating the validity
of the signature (<code>1</code> on success). Note that verification doesn't require the
signer's public key.</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> fn ring_vrf_verify(
verifier: RingVerifier,
input: OctetString,
extra: OctetString,
signature: RingVrfSignature,
) -&gt; Unsigned&lt;1&gt;;
<span class="boring">}</span></code></pre></pre>
<p>VRF <em>output</em> derivation from a ring VRF <em>signature</em>.</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> fn ring_vrf_signed_output(
signature: RingVrfSignature,
) -&gt; OctetString&lt;32&gt;;
<span class="boring">}</span></code></pre></pre>
<p>The following condition is always satisfied:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> let signature = vrf_sign(secret, input, extra);
let ring_signature = ring_vrf_sign(secret, prover, input, extra);
vrf_signed_output(signature) == ring_vrf_signed_output(ring_signature);
<span class="boring">}</span></code></pre></pre>
<p><code>RingProver</code>, <code>RingVerifier</code>, and <code>RingVrfSignature</code> are intentionally left
undefined. Their definitions can be found in the Bandersnatch VRF specification
and related documents.</p>
<h2 id="6-sassafras-protocol"><a class="header" href="#6-sassafras-protocol">6. Sassafras Protocol</a></h2>
<h4 id="61-protocol-configuration"><a class="header" href="#61-protocol-configuration">6.1. Protocol Configuration</a></h4>
<p>The <code>ProtocolConfiguration</code> type contains some parameters to tweak the
protocol behavior and primarily influences certain checks carried out during
tickets validation. It is defined as:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> ProtocolConfiguration ::= Sequence {
epoch_length: Unsigned32,
attempts_number: Unsigned8,
redundancy_factor: Unsigned8,
}
<span class="boring">}</span></code></pre></pre>
<p>Where:</p>
<ul>
<li><code>epoch_length</code>: Number of slots for each epoch.</li>
<li><code>attempts_number</code>: Maximum number of tickets that each authority is allowed to submit.</li>
<li><code>redundancy_factor</code>: Expected ratio between the cumulative number of valid
tickets which can be submitted by the scheduled authorities and the epoch's
duration in slots.</li>
</ul>
<p>The <code>attempts_number</code> influences the anonymity of block producers. As all
published tickets have a <strong>public</strong> attempt number less than <code>attempts_number</code>,
all the tickets which share the attempt number value must belong to different
block producers, which reduces anonymity late as we approach the epoch tail.
Bigger values guarantee more anonymity but also more computation.</p>
<p>Details about how these parameters drive the tickets validity probability can be
found in section <a href="approved/0026-sassafras-consensus.html#652-tickets-threshold">6.5.2</a>.</p>
<h3 id="62-header-digest-log"><a class="header" href="#62-header-digest-log">6.2. Header Digest Log</a></h3>
<p>Each block header contains a <code>Digest</code> log, which is defined as an ordered
sequence of <code>DigestItem</code>s:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> DigestItem ::= Sequence {
id: OctetString&lt;4&gt;,
data: OctetString
}
Digest ::= Sequence&lt;DigestItem&gt;
<span class="boring">}</span></code></pre></pre>
<p>The <code>Digest</code> sequence is used to propagate information required for the
correct protocol progress. Outside the protocol's context, the information
within each <code>DigestItem</code> is opaque and maps to some SCALE-encoded
protocol-specific structure.</p>
<p>For Sassafras related items, the <code>DiegestItem</code>s <code>id</code> is set to the ASCII
string <code>&quot;SASS&quot;</code></p>
<p>Possible digest items for Sassafras:</p>
<ul>
<li>Epoch change signal: Information about next epoch. This is mandatory for the
first block of a new epoch.</li>
<li>Epoch tickets signal: Sequence of tickets for claiming slots in the next
epoch. This is mandatory for the first block in the <em>epoch's tail</em></li>
<li>Slot claim info: Additional data required for block verification. This is mandatory
for each block and must be the second-to-last entry in the log.</li>
<li>Seal: Block signature added by the block author. This is mandatory for each block
and must be the last entry in the log.</li>
</ul>
<p>If any digest entry is unexpected, not found where mandatory or found in the
wrong position, then the block is considered invalid.</p>
<h3 id="63-on-chain-randomness"><a class="header" href="#63-on-chain-randomness">6.3. On-Chain Randomness</a></h3>
<p>A sequence of four randomness entries is maintained on-chain.</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> RandomnessBuffer ::= Sequence&lt;OctetString&lt;32&gt;, 4&gt;
<span class="boring">}</span></code></pre></pre>
<p>During epoch <code>N</code>:</p>
<ul>
<li>
<p>The first entry is the current <em>randomness accumulator</em> and incorporates
verifiable random elements from all previously executed blocks. The
accumulation procedure is described in section <a href="approved/0026-sassafras-consensus.html#610-randomness-accumulator">6.10</a>.</p>
</li>
<li>
<p>The second entry is the snapshot of the accumulator <strong>before</strong> the execution
of the first block of epoch <code>N</code>. This is the randomness used for tickets
targeting epoch <code>N+2</code>.</p>
</li>
<li>
<p>The third entry is the snapshot of the accumulator <strong>before</strong> the execution
of the first block of epoch <code>N-1</code>. This is the randomness used for tickets
targeting epoch <code>N+1</code> (the next epoch).</p>
</li>
<li>
<p>The third entry is the snapshot of the accumulator <strong>before</strong> the execution
of the first block of epoch <code>N-2</code>. This is the randomness used for tickets
targeting epoch <code>N</code> (the current epoch).</p>
</li>
</ul>
<p>The buffer's entries are updated <strong>after</strong> each block execution.</p>
<h3 id="64-epoch-change-signal"><a class="header" href="#64-epoch-change-signal">6.4. Epoch Change Signal</a></h3>
<p>The first block produced during epoch <code>N</code> must include a descriptor for some
of the parameters to be used by the subsequent epoch (<code>N+1</code>).</p>
<p>This signal descriptor is defined as:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> NextEpochDescriptor ::= Sequence {
randomness: OctetString&lt;32&gt;,
authorities: Sequence&lt;PublicKey&gt;,
}
<span class="boring">}</span></code></pre></pre>
<p>Where:</p>
<ul>
<li><code>randomness</code>: Randomness accumulator snapshot relevant for validation of
next epoch blocks. In other words, randomness used to construct the tickets
targeting epoch <code>N+1</code>.</li>
<li><code>authorities</code>: List of authorities scheduled for next epoch.</li>
</ul>
<p>This descriptor is <code>SCALE</code> encoded and embedded in a <code>DigestItem</code>.</p>
<h4 id="641-startup-parameters"><a class="header" href="#641-startup-parameters">6.4.1. Startup Parameters</a></h4>
<p>Some of the initial parameters used by the first epoch (<code>#0</code>), are set through
the genesis configuration, which is defined as:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> GenesisConfig ::= Sequence {
authorities: Sequence&lt;PublicKey&gt;,
}
<span class="boring">}</span></code></pre></pre>
<p>The on-chain <code>RandomnessBuffer</code> is initialized <strong>after</strong> the genesis block
construction. The first buffer entry is set as the <em>Blake2b</em> hash of the genesis
block, each of the other entries is set as the <em>Blake2b</em> hash of the previous entry.</p>
<p>Since block <code>#0</code> is generated by each node as part of the genesis process, the
first block that an authority explicitly produces for epoch <code>#0</code> is block <code>#1</code>.
Therefore, block <code>#1</code> is required to contain the <code>NextEpochDescriptor</code> for the
following epoch.</p>
<p><code>NextEpochDescriptor</code> for epoch <code>#1</code>:</p>
<ul>
<li><code>randomness</code>: Third entry (index 2) of the randomness buffer.</li>
<li><code>authorities</code>: The same sequence as specified in the genesis configuration.</li>
</ul>
<h3 id="65-tickets-creation-and-submission"><a class="header" href="#65-tickets-creation-and-submission">6.5. Tickets Creation and Submission</a></h3>
<p>During epoch <code>N</code>, each authority scheduled for epoch <code>N+2</code> constructs a set
of tickets which may be eligible (<a href="approved/0026-sassafras-consensus.html#652-tickets-threshold">6.5.2</a>) for on-chain
submission.</p>
<p>These tickets are constructed using the on-chain randomness snapshot taken
<strong>before</strong> the execution of the first block of epoch <code>N</code> together with other
parameters and aims to secure ownership of one or more slots of epoch <code>N+2</code>
(<em>target epoch</em>).</p>
<p>Each authority is allowed to submit a maximum number of tickets, constrained by
<code>attempts_number</code> field of the <code>ProtocolConfiguration</code>.</p>
<p>The ideal timing for the candidate authority to start constructing the tickets
is subject to strategy. A recommended approach is to initiate tickets creation
once the last block of epoch <code>N-1</code> is either probabilistically or, even better,
deterministically finalized. This delay is suggested to prevent wasting
resources creating tickets that will be unusable if a different chain branch is
chosen as canonical.</p>
<p>Tickets generated during epoch <code>N</code> are shared with the <em>tickets relayers</em>,
which are the authorities scheduled for epoch <code>N+1</code>. Relayers validate and
collect (off-chain) the tickets targeting epoch <code>N+2</code>.</p>
<p>When epoch <code>N+1</code> starts, collected tickets are submitted on-chain by relayers
as <em>inherent extrinsics</em>, a special type of transaction inserted by the block
author at the beginning of the block's transactions sequence.</p>
<h4 id="651-ticket-identifier"><a class="header" href="#651-ticket-identifier">6.5.1. Ticket Identifier</a></h4>
<p>Each ticket has an associated identifier defined as:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> TicketId ::= OctetString&lt;32&gt;;
<span class="boring">}</span></code></pre></pre>
<p>The value of <code>TicketId</code> is completely determined by the output of Bandersnatch
VRFs given the following <strong>unbiasable</strong> input:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> let ticket_vrf_input = CONCAT(
BYTES(&quot;sassafras_ticket_seal&quot;),
target_epoch_randomness,
BYTES(attempt)
);
let ticket_id = vrf_output(authority_secret_key, ticket_vrf_input);
<span class="boring">}</span></code></pre></pre>
<p>Where:</p>
<ul>
<li><code>target_epoch_randomness</code>: element of <code>RandomnessBuffer</code> which contains the
randomness for the epoch the ticket is targeting.</li>
<li><code>attempt</code>: value going from <code>0</code> to the configured <code>attempts_number - 1</code>.</li>
</ul>
<h4 id="652-tickets-threshold"><a class="header" href="#652-tickets-threshold">6.5.2. Tickets Threshold</a></h4>
<p>A ticket is valid for on-chain submission if its <code>TicketId</code> value, when
interpreted as a big-endian 256-bit integer normalized as a float within the
range <code>[0..1]</code>, is less than the ticket threshold computed as:</p>
<pre><code>T = (r·s)/(a·v)
</code></pre>
<p>Where:</p>
<ul>
<li><code>v</code>: epoch's authorities number</li>
<li><code>s</code>: epoch's slots number</li>
<li><code>r</code>: redundancy factor</li>
<li><code>a</code>: attempts number</li>
</ul>
<p>In an epoch with <code>s</code> slots, the goal is to achieve an expected number of valid
tickets equal to <code>r·s</code>.</p>
<p>It's crucial to ensure that the probability of having fewer than <code>s</code> winning
tickets is very low, even in scenarios where up to <code>1/3</code> of the authorities
might be offline. To accomplish this, we first define the winning probability of
a single ticket as <code>T = (r·s)/(a·v)</code>.</p>
<p>Let <code>n</code> be the <strong>actual</strong> number of participating authorities, where <code>v·2/3 ≤ n ≤ v</code>.
These <code>n</code> authorities each make <code>a</code> attempts, for a total of <code>a·n</code> attempts.</p>
<p>Let <code>X</code> be the random variable associated to the number of winning tickets, then
its expected value is <code>E[X] = T·a·n = (r·s·n)/v</code>. By setting <code>r = 2</code>, we get
<code>s·4/3 ≤ E[X] ≤ s·2</code>. Using <em>Bernestein's inequality</em> we get <code>Pr[X &lt; s] ≤ e^(-s/21)</code>.</p>
<p>For instance, with <code>s = 600</code> this results in <code>Pr[X &lt; s] &lt; 4·10⁻¹³</code>.
Consequently, this approach offers considerable tolerance for offline nodes and
ensures that all slots are likely to be filled with tickets.</p>
<p>For more details about threshold formula refer to
<a href="https://research.web3.foundation/Polkadot/protocols/block-production/SASSAFRAS#probabilities-and-parameters">probabilities and parameters</a>
paragraph in the Web3 Foundation description of the protocol.</p>
<h4 id="653-ticket-envelope"><a class="header" href="#653-ticket-envelope">6.5.3. Ticket Envelope</a></h4>
<p>Each ticket candidate is represented by a <code>TicketEnvelope</code>:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> TicketEnvelope ::= Sequence {
attempt: Unsigned8,
extra: OctetString,
signature: RingVrfSignature
}
<span class="boring">}</span></code></pre></pre>
<p>Where:</p>
<ul>
<li><code>attempt</code>: Index associated to the ticket.</li>
<li><code>extra</code>: Additional data available for user-defined applications.</li>
<li><code>signature</code>: Ring VRF signature of the envelope data (<code>attempt</code> and <code>extra</code>).</li>
</ul>
<p>Envelope data is signed using Bandersnatch Ring VRF (<a href="approved/0026-sassafras-consensus.html#542-ring-vrf-interface">5.4.2</a>).</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> let signature = ring_vrf_sign(
secret_key,
ring_prover
ticket_vrf_input,
extra,
);
<span class="boring">}</span></code></pre></pre>
<p>With <code>ticket_vrf_input</code> defined as in <a href="approved/0026-sassafras-consensus.html#651-ticket-identifier">6.5.1</a>.</p>
<h3 id="66-on-chain-tickets-validation"><a class="header" href="#66-on-chain-tickets-validation">6.6. On-chain Tickets Validation</a></h3>
<p>Validation rules:</p>
<ol>
<li>
<p>Ring VRF signature is verified using the <code>ring_verifier</code> derived by the
constant ring context parameters (SNARK SRS) and the next epoch authorities
public keys.</p>
</li>
<li>
<p><code>TicketId</code> is locally computed from the <code>RingVrfSignature</code> and its value
is checked to be less than tickets' threshold.</p>
</li>
<li>
<p>On-chain tickets submission can't occur within a block part of the
<em>epoch's tail</em>, which encompasses a configurable number of slots at the end
of the epoch. This constraint is to give time to persisted on-chain tickets
to be probabilistically (or even better deterministically) finalized and thus
to further reduce the fork chances at the beginning of the target epoch.</p>
</li>
<li>
<p>All tickets which are proposed within a block must be valid and all of them
must end up being persisted on-chain. Because the total number of tickets
persisted on-chain is limited by to the epoch's length, this may require to
drop some of the previously persisted tickets. We remove tickets with greater
<code>TicketId</code> value first.</p>
</li>
<li>
<p>No tickets duplicates are allowed.</p>
</li>
</ol>
<p>If at least one of the checks fails then the block must be considered invalid.</p>
<p>Pseudo-code for ticket validation for steps 1 and 2:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> let ticket_vrf_input = CONCAT(
BYTES(&quot;sassafras_ticket_seal&quot;),
target_epoch_randomness,
BYTES(envelope.attempt)
);
let result = ring_vrf_verify(
ring_verifier,
ticket_vrf_input,
envelope.extra,
envelope.ring_signature
);
ASSERT(result == 1);
let ticket_id = ring_vrf_signed_output(envelope.ring_signature);
ASSERT(ticket_id &lt; ticket_threshold);
<span class="boring">}</span></code></pre></pre>
<p>Valid tickets are persisted on-chain in a bounded sorted sequence of
<code>TicketBody</code> objects. Items within this sequence are sorted according to
their <code>TicketId</code>, interpreted as a 256-bit big-endian unsigned integer.</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> TicketBody ::= Sequence {
id: TicketId,
attempt: Unsigned8,
extra: OctetString,
}
Tickets ::= Sequence&lt;TicketBody&gt;
<span class="boring">}</span></code></pre></pre>
<p>The on-chain tickets sequence length bound is set equal to the epoch length
in slots according to the protocol configuration.</p>
<h3 id="67-ticket-slot-binding"><a class="header" href="#67-ticket-slot-binding">6.7. Ticket-Slot Binding</a></h3>
<p>Before the beginning of the <em>target epoch</em>, the on-chain sequence of tickets
must be associated to epoch's slots such that there is at most one ticket per
slot.</p>
<p>Given an ordered sequence of tickets <code>[t₀, t₁, ..., tₙ]</code>, the tickets are
associated according to the following <strong>outside-in</strong> strategy:</p>
<pre><code> slot_index : [ 0, 1, 2, 3 , ... ]
tickets : [ t₀, tₙ, t₁, tₙ₋₁, ... ]
</code></pre>
<p>Here <code>slot_index</code> is the slot number relative to the epoch's first slot:
<code>slot_index = slot - epoch_first_slot</code>.</p>
<p>The association between tickets and a slots is recorded on-chain and thus
is public. What remains confidential is the ticket's author identity, and
consequently, who is enabled to claim the corresponding slot. This information
is known only to the ticket's author.</p>
<p>If the number of published tickets is less than the number of epoch's slots,
some <em>orphan</em> slots at the end of the epoch will remain unbounded to any ticket.
For <em>orphan</em> slots claiming strategy refer to <a href="approved/0026-sassafras-consensus.html#682-secondary-method">6.8.2</a>.
Note that this fallback situation always apply to the first two epochs after genesis.</p>
<h3 id="68-slot-claim"><a class="header" href="#68-slot-claim">6.8. Slot Claim</a></h3>
<p>With tickets bounded to the <em>target epoch</em> slots, every designated authority
acquires the information about the slots for which they are required to produce
a block.</p>
<p>The procedure for slot claiming depends on whether a given slot has an
associated ticket according to the on-chain state. If a slot has an associated
ticket, then the primary authoring method is used. Conversely, the protocol
resorts to the secondary method as a fallback.</p>
<h4 id="681-primary-method"><a class="header" href="#681-primary-method">6.8.1. Primary Method</a></h4>
<p>An authority, can claim a slot using the primary method if it is the legit
owner of the ticket associated to the given slot.</p>
<p>Let <code>target_epoch_randomness</code> be the entry in <code>RandomnessBuffer</code> relative to
the epoch the block is targeting and <code>attempt</code> be the attempt used to construct
the ticket associated to the slot to claim, the VRF input for slot claiming is
constructed as:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> let seal_vrf_input = CONCAT(
BYTES(&quot;sassafras_ticket_seal&quot;),
target_epoch_randomness,
BYTES(attempt)
);
<span class="boring">}</span></code></pre></pre>
<p>The <code>seal_vrf_input</code>, when signed with the correct authority secret key, must
generate the same <code>TicketId</code> which has been associated to the target slot
according to the on-chain state.</p>
<h4 id="682-secondary-method"><a class="header" href="#682-secondary-method">6.8.2. Secondary Method</a></h4>
<p>Given that the authorities scheduled for the <em>target epoch</em> are kept on-chain in
an ordered sequence, the index of the authority which has the privilege to claim an
<em>orphan</em> slot is given by the following procedure:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> let hash_input = CONCAT(
target_epoch_randomness,
ENCODE(relative_slot_index),
);
let hash = BLAKE2(hash_input);
let index_bytes = CONCAT(GET(hash, 0), GET(hash, 1), GET(hash, 2), GET(hash, 3));
let index = DECODE&lt;Unsigned32&gt;(index_bytes) % LENGTH(authorities);
<span class="boring">}</span></code></pre></pre>
<p>With <code>relative_slot_index</code> the slot offset relative to the target epoch's start
and <code>authorities</code> the sequence of target epoch authorities.</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> let seal_vrf_input = CONCAT(
BYTES(&quot;sassafras_fallback_seal&quot;),
target_epoch_randomness
);
<span class="boring">}</span></code></pre></pre>
<h4 id="683-claim-data"><a class="header" href="#683-claim-data">6.8.3. Claim Data</a></h4>
<p><code>ClaimData</code> is a digest entry which contains additional information required by
the protocol to verify the block:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> ClaimData ::= Sequence {
slot: Unsigned32,
authority_index: Unsigned32,
randomness_source: VrfSignature,
}
<span class="boring">}</span></code></pre></pre>
<ul>
<li><code>slot</code>: The slot number</li>
<li><code>authority_index</code>: Block's author index relative to the on-chain authorities sequence.</li>
<li><code>randomness_source</code>: VRF signature used to generate per-block randomness.</li>
</ul>
<p>Given the <code>seal_vrf_input</code> constructed using the primary or secondary method,
the randomness source signature is generated as follows:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> let randomness_vrf_input = CONCAT(
BYTES(&quot;sassafras_randomness&quot;),
vrf_output(authority_secret_key, seal_vrf_input)
);
let randomness_source = vrf_sign(
authority_secret_key,
randomness_vrf_input,
[]
);
let claim = SlotClaim {
slot,
authority_index,
randomness_source
};
PUSH(block_header.digest, ENCODE(claim));
<span class="boring">}</span></code></pre></pre>
<p>The <code>ClaimData</code> object is <em>SCALE</em> encoded and pushed as the second-to-last
element of the header digest log.</p>
<h4 id="684-block-seal"><a class="header" href="#684-block-seal">6.8.4. Block Seal</a></h4>
<p>A block is finally sealed as follows:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> let unsealed_header_byets = ENCODE(block_header);
let seal = vrf_sign(
authority_secret_key,
seal_vrf_input,
unsealed_header_bytes
);
PUSH(block_header.digest, ENCODE(seal));
<span class="boring">}</span></code></pre></pre>
<p>With <code>block_header</code> the block's header without the seal digest log entry.</p>
<p>The <code>seal</code> object is a <code>VrfSignature</code>, which is <em>SCALE</em> encoded and pushed as
the <strong>last</strong> entry of the header digest log.</p>
<h3 id="69-slot-claim-verification"><a class="header" href="#69-slot-claim-verification">6.9. Slot Claim Verification</a></h3>
<p>The last entry is extracted from the header digest log, and is SCALE decoded as
a <code>VrfSignature</code> object. The unsealed header is then SCALE encoded in order to be
verified.</p>
<p>The next entry is extracted from the header digest log, and is SCALE decoded as
a <code>ClaimData</code> object.</p>
<p>The validity of the two signatures is assessed using as the authority public key
corresponding to the <code>authority_index</code> found in the <code>ClaimData</code>, together with
the VRF input (which depends on primary/secondary method) and additional data
used by the block author.</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> let seal_signature = DECODE&lt;VrfSignature&gt;(POP(header.digest));
let unsealed_header_bytes = ENCODE(header);
let claim_data = DECODE&lt;ClaimData&gt;(POP(header.digest));
let authority_public_key = GET(authorities, claim_data.authority_index);
// Verify seal signature
let result = vrf_verify(
authority_public_key,
seal_vrf_input,
unsealed_header_bytes,
seal_signature
);
ASSERT(result == 1);
let randomness_vrf_input = CONCAT(
BYTES(&quot;sassafras_randomness&quot;),
vrf_signed_output(seal_signature)
);
// Verify per-block entropy source signature
let result = vrf_verify(
authority_public_key,
randomness_vrf_input,
[],
claim_data.randomness_source
);
ASSERT(result == 1);
<span class="boring">}</span></code></pre></pre>
<p>With:</p>
<ul>
<li><code>header</code>: The block's header.</li>
<li><code>authorities</code>: Sequence of authorities for the target epoch, as recorded on-chain.</li>
<li><code>seal_vrf_input</code>: VRF input data constructed as specified in <a href="approved/0026-sassafras-consensus.html#68-slot-claim">6.8</a>.</li>
</ul>
<p>If signatures verification is successful, then the verification process diverges
based on whether the slot is associated with a ticket according to the on-chain
state.</p>
<h3 id="691-primary-method"><a class="header" href="#691-primary-method">6.9.1. Primary Method</a></h3>
<p>For slots tied to a ticket, the primary verification method is employed.
This method verifies ticket ownership using the <code>TicketId</code> associated to the
slot.</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> let ticket_id = vrf_signed_output(seal_signature);
ASSERT(ticket_id == expected_ticket_id);
<span class="boring">}</span></code></pre></pre>
<p>With <code>expected_ticket_id</code> the ticket identifier committed on-chain in the
associated <code>TicketBody</code>.</p>
<h4 id="692-secondary-method"><a class="header" href="#692-secondary-method">6.9.2. Secondary Method</a></h4>
<p>If the slot doesn't have any associated ticket, then the <code>authority_index</code>
contained in the <code>ClaimData</code> must match the one returned by the procedure
outlined in section <a href="approved/0026-sassafras-consensus.html#682-secondary-method">6.8.2</a>.</p>
<h3 id="610-randomness-accumulator"><a class="header" href="#610-randomness-accumulator">6.10. Randomness Accumulator</a></h3>
<p>The randomness accumulator is updated using the <code>randomness_source</code> signature
found within the <code>ClaimData</code> object. In particular, fresh randomness is derived
and accumulated <strong>after</strong> block execution as follows:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span> let fresh_randomness = vrf_signed_output(claim.randomness_source);
randomness_buffer[0] = BLAKE2(CONCAT(randomness_buffer[0], fresh_randomness));
<span class="boring">}</span></code></pre></pre>
<h2 id="7-drawbacks"><a class="header" href="#7-drawbacks">7. Drawbacks</a></h2>
<p>None</p>
<h2 id="8-testing-security-and-privacy"><a class="header" href="#8-testing-security-and-privacy">8. Testing, Security, and Privacy</a></h2>
<p>It is critical that implementations of this RFC undergo thorough rigorous
testing. A security audit may be desirable to ensure the implementation does not
introduce emergent side effects.</p>
<h2 id="9-performance-ergonomics-and-compatibility"><a class="header" href="#9-performance-ergonomics-and-compatibility">9. Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="91-performance"><a class="header" href="#91-performance">9.1. Performance</a></h3>
<p>Adopting Sassafras consensus marks a significant improvement in reducing the
frequency of short-lived forks which are eliminated by design.</p>
<p>Forks may only result from network disruption or protocol attacks. In such
cases, the choice of which fork to follow upon recovery is clear-cut, with only
one valid option.</p>
<h3 id="92-ergonomics"><a class="header" href="#92-ergonomics">9.2. Ergonomics</a></h3>
<p>No specific considerations.</p>
<h3 id="93-compatibility"><a class="header" href="#93-compatibility">9.3. Compatibility</a></h3>
<p>The adoption of Sassafras affects the native client and thus can't be introduced
via a &quot;simple&quot; runtime upgrade.</p>
<p>A deployment strategy should be carefully engineered for live networks. This
subject is left open for a dedicated RFC.</p>
<h2 id="10-prior-art-and-references"><a class="header" href="#10-prior-art-and-references">10. Prior Art and References</a></h2>
<ul>
<li><a href="https://research.web3.foundation/Polkadot/protocols/block-production/SASSAFRAS">Sassafras layman introduction</a></li>
<li><a href="https://eprint.iacr.org/2023/031.pdf">Sassafras research paper</a></li>
<li><a href="https://github.com/davxy/bandersnatch-vrfs-spec">Bandersnatch VRFs specification</a></li>
<li><a href="https://github.com/davxy/ark-ec-vrfs">Bandersnatch VRFs reference implementation</a></li>
<li><a href="https://eprint.iacr.org/2023/002.pdf">W3F Ring VRF research paper</a></li>
<li><a href="https://github.com/paritytech/substrate/issues/11515">Sassafras reference implementation tracking issue</a></li>
<li><a href="https://github.com/paritytech/substrate/pull/11879">Sassafras reference implementation main PR</a></li>
</ul>
<h2 id="11-unresolved-questions"><a class="header" href="#11-unresolved-questions">11. Unresolved Questions</a></h2>
<p>None</p>
<h2 id="12-future-directions-and-related-material"><a class="header" href="#12-future-directions-and-related-material">12. Future Directions and Related Material</a></h2>
<p>While this RFC lays the groundwork and outlines the core aspects of the
protocol, several crucial topics remain to be addressed in future RFCs.</p>
<h3 id="121-interactions-with-on-chain-code"><a class="header" href="#121-interactions-with-on-chain-code">12.1. Interactions with On-Chain Code</a></h3>
<ul>
<li>
<p><strong>Storage</strong>: Types, organization and genesis configuration.</p>
</li>
<li>
<p><strong>Host interface</strong>: Interface that the hosting environment exposes to on-chain
code (also known as <em>host functions</em>).</p>
</li>
<li>
<p><strong>Unrecorded on-chain interface</strong>. Interface that on-chain code exposes to the
hosting environment (also known as <em>runtime API</em>).</p>
</li>
<li>
<p><strong>Transactional on-chain interface</strong>. Interface that on-chain code exposes
to the World to alter the state (also known as <em>transactions</em> or
<em>extrinsics</em> in the <em>Polkadot</em> ecosystem).</p>
</li>
</ul>
<h3 id="122-deployment-strategies"><a class="header" href="#122-deployment-strategies">12.2. Deployment Strategies</a></h3>
<ul>
<li><strong>Protocol Migration</strong>. Investigate of how Sassafras can seamlessly replace
an already operational instance of another protocol. Future RFCs may focus on
deployment strategies to facilitate a smooth transition.</li>
</ul>
<h3 id="123-zk-snark-parameters"><a class="header" href="#123-zk-snark-parameters">12.3. ZK-SNARK Parameters</a></h3>
<ul>
<li><strong>Parameters Setup</strong>: Determine the setup procedure for the <em>zk-SNARK</em> SRS
(Structured Reference String) initialization. Future RFCs may provide insights
into whether this process should include an ad-hoc initialization ceremony or
if we can reuse an SRS from another ecosystem (e.g. Zcash or Ethereum).</li>
</ul>
<h3 id="124-anonymous-submission-of-tickets"><a class="header" href="#124-anonymous-submission-of-tickets">12.4. Anonymous Submission of Tickets.</a></h3>
<ul>
<li><strong>Mixnet Integration</strong>: Submitting tickets directly to the relay can pose a
risk of potential deanonymization through traffic analysis. Subsequent RFCs
may investigate the potential for incorporating <em>mix network</em> protocol or
other privacy-enhancing mechanisms to address this concern.</li>
</ul>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0032-minimal-relay.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0032-minimal-relay.html#rfc-0032-minimal-relay">RFC-0032: Minimal Relay</a>
<ul>
<li><a href="approved/0032-minimal-relay.html#summary">Summary</a></li>
<li><a href="approved/0032-minimal-relay.html#motivation">Motivation</a></li>
<li><a href="approved/0032-minimal-relay.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0032-minimal-relay.html#explanation">Explanation</a>
<ul>
<li><a href="approved/0032-minimal-relay.html#migrations">Migrations</a></li>
<li><a href="approved/0032-minimal-relay.html#interfaces">Interfaces</a></li>
<li><a href="approved/0032-minimal-relay.html#functional-architecture">Functional Architecture</a></li>
<li><a href="approved/0032-minimal-relay.html#resource-allocation">Resource Allocation</a></li>
<li><a href="approved/0032-minimal-relay.html#deployment">Deployment</a></li>
<li><a href="approved/0032-minimal-relay.html#kusama">Kusama</a></li>
</ul>
</li>
<li><a href="approved/0032-minimal-relay.html#drawbacks">Drawbacks</a></li>
<li><a href="approved/0032-minimal-relay.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="approved/0032-minimal-relay.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="approved/0032-minimal-relay.html#performance">Performance</a></li>
<li><a href="approved/0032-minimal-relay.html#ergonomics">Ergonomics</a></li>
<li><a href="approved/0032-minimal-relay.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="approved/0032-minimal-relay.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="approved/0032-minimal-relay.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="approved/0032-minimal-relay.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0032-minimal-relay"><a class="header" href="#rfc-0032-minimal-relay">RFC-0032: Minimal Relay</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>20 September 2023</td></tr>
<tr><td><strong>Description</strong></td><td>Proposal to minimise Relay Chain functionality.</td></tr>
<tr><td><strong>Authors</strong></td><td>Joe Petrowski, Gavin Wood</td></tr>
</tbody></table>
</div>
<h2 id="summary-30"><a class="header" href="#summary-30">Summary</a></h2>
<p>The Relay Chain contains most of the core logic for the Polkadot network. While this was necessary
prior to the launch of parachains and development of XCM, most of this logic can exist in
parachains. This is a proposal to migrate several subsystems into system parachains.</p>
<h2 id="motivation-30"><a class="header" href="#motivation-30">Motivation</a></h2>
<p>Polkadot's scaling approach allows many distinct state machines (known generally as parachains) to
operate with common guarantees about the validity and security of their state transitions. Polkadot
provides these common guarantees by executing the state transitions on a strict subset (a backing
group) of the Relay Chain's validator set.</p>
<p>However, state transitions on the Relay Chain need to be executed by <em>all</em> validators. If any of
those state transitions can occur on parachains, then the resources of the complement of a single
backing group could be used to offer more cores. As in, they could be offering more coretime (a.k.a.
blockspace) to the network.</p>
<p>By minimising state transition logic on the Relay Chain by migrating it into &quot;system chains&quot; -- a
set of parachains that, with the Relay Chain, make up the Polkadot protocol -- the Polkadot
Ubiquitous Computer can maximise its primary offering: secure blockspace.</p>
<h2 id="stakeholders-29"><a class="header" href="#stakeholders-29">Stakeholders</a></h2>
<ul>
<li>Parachains that interact with affected logic on the Relay Chain;</li>
<li>Core protocol and XCM format developers;</li>
<li>Tooling, block explorer, and UI developers.</li>
</ul>
<h2 id="explanation-29"><a class="header" href="#explanation-29">Explanation</a></h2>
<p>The following pallets and subsystems are good candidates to migrate from the Relay Chain:</p>
<ul>
<li>Identity</li>
<li>Balances</li>
<li>Staking
<ul>
<li>Staking</li>
<li>Election Provider</li>
<li>Bags List</li>
<li>NIS</li>
<li>Nomination Pools</li>
<li>Fast Unstake</li>
</ul>
</li>
<li>Governance
<ul>
<li>Treasury and Bounties</li>
<li>Conviction Voting</li>
<li>Referenda</li>
</ul>
</li>
</ul>
<p>Note: The Auctions and Crowdloan pallets will be replaced by Coretime, its system chain and
interface described in RFC-1 and RFC-5, respectively.</p>
<h3 id="migrations"><a class="header" href="#migrations">Migrations</a></h3>
<p>Some subsystems are simpler to move than others. For example, migrating Identity can be done by
simply preventing state changes in the Relay Chain, using the Identity-related state as the genesis
for a new chain, and launching that new chain with the genesis and logic (pallet) needed.</p>
<p>Other subsystems cannot experience any downtime like this because they are essential to the
network's functioning, like Staking and Governance. However, these can likely coexist with a
similarly-permissioned system chain for some time, much like how &quot;Gov1&quot; and &quot;OpenGov&quot; coexisted at
the latter's introduction.</p>
<p>Specific migration plans will be included in release notes of runtimes from the Polkadot Fellowship
when beginning the work of migrating a particular subsystem.</p>
<h3 id="interfaces"><a class="header" href="#interfaces">Interfaces</a></h3>
<p>The Relay Chain, in many cases, will still need to interact with these subsystems, especially
Staking and Governance. These subsystems will require making some APIs available either via
dispatchable calls accessible to XCM <code>Transact</code> or possibly XCM <code>Instruction</code>s in future versions.</p>
<p>For example, Staking provides a pallet-API to register points (e.g. for block production) and
offences (e.g. equivocation). With Staking in a system chain, that chain would need to allow the
Relay Chain to update validator points periodically so that it can correctly calculate rewards.</p>
<p>A pub-sub protocol may also lend itself to these types of interactions.</p>
<h3 id="functional-architecture"><a class="header" href="#functional-architecture">Functional Architecture</a></h3>
<p>This RFC proposes that system chains form individual components within the system's architecture and
that these components are chosen as functional groups. This approach allows synchronous
composibility where it is most valuable, but isolates logic in such a way that provides flexibility
for optimal resource allocation (see <a href="approved/0032-minimal-relay.html#resource-allocation">Resource Allocation</a>). For the
subsystems discussed in this RFC, namely Identity, Governance, and Staking, this would mean:</p>
<ul>
<li>People Chain, for identity and personhood logic, providing functionality related to the attributes
of single actors;</li>
<li>Governance Chain, for governance and system collectives, providing functionality for pluralities
to express their voices within the system;</li>
<li>Staking Chain, for Polkadot's staking system, including elections, nominations, reward
distribution, slashing, and non-interactive staking; and</li>
<li>Asset Hub, for fungible and non-fungible assets, including DOT.</li>
</ul>
<p>The Collectives chain and Asset Hub already exist, so implementation of this RFC would mean two new
chains (People and Staking), with Governance moving to the <em>currently-known-as</em> Collectives chain
and Asset Hub being increasingly used for DOT over the Relay Chain.</p>
<p>Note that one functional group will likely include many pallets, as we do not know how pallet
configurations and interfaces will evolve over time.</p>
<h3 id="resource-allocation"><a class="header" href="#resource-allocation">Resource Allocation</a></h3>
<p>The system should minimise wasted blockspace. These three (and other) subsystems may not each
consistently require a dedicated core. However, core scheduling is far more agile than functional
grouping. While migrating functionality from one chain to another can be a multi-month endeavour,
cores can be rescheduled almost on-the-fly.</p>
<p>Migrations are also breaking changes to some use cases, for example other parachains that need to
route XCM programs to particular chains. It is thus preferable to do them a single time in migrating
off the Relay Chain, reducing the risk of needing parachain splits in the future.</p>
<p>Therefore, chain boundaries should be based on functional grouping where synchronous composibility
is most valuable; and efficient resource allocation should be managed by the core scheduling
protocol.</p>
<p>Many of these system chains (including Asset Hub) could often share a single core in a semi-round
robin fashion (the coretime may not be uniform). When needed, for example during NPoS elections or
slashing events, the scheduler could allocate a dedicated core to the chain in need of more
throughput.</p>
<h3 id="deployment"><a class="header" href="#deployment">Deployment</a></h3>
<p>Actual migrations should happen based on some prioritization. This RFC proposes to migrate Identity,
Staking, and Governance as the systems to work on first. A brief discussion on the factors involved
in each one:</p>
<h4 id="identity"><a class="header" href="#identity">Identity</a></h4>
<p>Identity will be one of the simpler pallets to migrate into a system chain, as its logic is largely
self-contained and it does not &quot;share&quot; balances with other subsystems. As in, any DOT is held in
reserve as a storage deposit and cannot be simultaneously used the way locked DOT can be locked for
multiple purposes.</p>
<p>Therefore, migration can take place as follows:</p>
<ol>
<li>The pallet can be put in a locked state, blocking most calls to the pallet and preventing updates
to identity info.</li>
<li>The frozen state will form the genesis of a new system parachain.</li>
<li>Functions will be added to the pallet that allow migrating the deposit to the parachain. The
parachain deposit is on the order of 1/100th of the Relay Chain's. Therefore, this will result in
freeing up Relay State as well as most of each user's reserved balance.</li>
<li>The pallet and any leftover state can be removed from the Relay Chain.</li>
</ol>
<p>User interfaces that render Identity information will need to source their data from the new system
parachain.</p>
<p>Note: In the future, it may make sense to decommission Kusama's Identity chain and do all account
identities via Polkadot's. However, the Kusama chain will serve as a dress rehearsal for Polkadot.</p>
<h4 id="staking"><a class="header" href="#staking">Staking</a></h4>
<p>Migrating the staking subsystem will likely be the most complex technical undertaking, as the
Staking system cannot stop (the system MUST always have a validator set) nor run in parallel (the
system MUST have only <em>one</em> validator set) and the subsystem itself is made up of subsystems in the
runtime and the node. For example, if offences are reported to the Staking parachain, validator
nodes will need to submit their reports there.</p>
<p>Handling balances also introduces complications. The same balance can be used for staking and
governance. Ideally, all balances stay on Asset Hub, and only report &quot;credits&quot; to system chains like
Staking and Governance. However, staking mutates balances by issuing new DOT on era changes and for
rewards. Allowing DOT directly on the Staking parachain would simplify staking changes.</p>
<p>Given the complexity, it would be pragmatic to include the Balances pallet in the Staking parachain
in its first version. Any other systems that use overlapping locks, most notably governance, will
need to recognise DOT held on both Asset Hub and the Staking parachain.</p>
<p>There is more discussion about staking in a parachain in <a href="https://github.com/paritytech/polkadot-sdk/issues/491">Moving Staking off the Relay
Chain</a>.</p>
<h4 id="governance"><a class="header" href="#governance">Governance</a></h4>
<p>Migrating governance into a parachain will be less complicated than staking. Most of the primitives
needed for the migration already exist. The Treasury supports spending assets on remote chains and
collectives like the Polkadot Technical Fellowship already function in a parachain. That is, XCM
already provides the ability to express system origins across chains.</p>
<p>Therefore, actually moving the governance logic into a parachain will be simple. It can run in
parallel with the Relay Chain's governance, which can be removed when the parachain has demonstrated
sufficient functionality. It's possible that the Relay Chain maintain a Root-level emergency track
for situations like <a href="https://forum.polkadot.network/t/stalled-parachains-on-kusama-post-mortem/3998">parachains
halting</a>.</p>
<p>The only complication arises from the fact that both Asset Hub and the Staking parachain will have
DOT balances; therefore, the Governance chain will need to be able to credit users' voting power
based on balances from both locations. This is not expected to be difficult to handle.</p>
<h3 id="kusama"><a class="header" href="#kusama">Kusama</a></h3>
<p>Although Polkadot and Kusama both have system chains running, they have to date only been used for
introducing new features or bodies, for example fungible assets or the Technical Fellowship. There
has not yet been a migration of logic/state from the Relay Chain into a parachain. Given its more
realistic network conditions than testnets, Kusama is the best stage for rehearsal.</p>
<p>In the case of identity, Polkadot's system may be sufficient for the ecosystem. Therefore, Kusama
should be used to test the migration of logic and state from Relay Chain to parachain, but these
features may be (at the will of Kusama's governance) dropped from Kusama entirely after a successful
migration on Polkadot.</p>
<p>For Governance, Polkadot already has the Collectives parachain, which would become the Governance
parachain. The entire group of DOT holders is itself a collective (the legislative body), and
governance provides the means to express voice. Launching a Kusama Governance chain would be
sensible to rehearse a migration.</p>
<p>The Staking subsystem is perhaps where Kusama would provide the most value in its canary capacity.
Staking is the subsystem most constrained by PoV limits. Ensuring that elections, payouts, session
changes, offences/slashes, etc. work in a parachain on Kusama -- with its larger validator set --
will give confidence to the chain's robustness on Polkadot.</p>
<h2 id="drawbacks-27"><a class="header" href="#drawbacks-27">Drawbacks</a></h2>
<p>These subsystems will have reduced resources in cores than on the Relay Chain. Staking in particular
may require some optimizations to deal with constraints.</p>
<h2 id="testing-security-and-privacy-26"><a class="header" href="#testing-security-and-privacy-26">Testing, Security, and Privacy</a></h2>
<p>Standard audit/review requirements apply. More powerful multi-chain integration test tools would be
useful in developement.</p>
<h2 id="performance-ergonomics-and-compatibility-25"><a class="header" href="#performance-ergonomics-and-compatibility-25">Performance, Ergonomics, and Compatibility</a></h2>
<p>Describe the impact of the proposal on the exposed functionality of Polkadot.</p>
<h3 id="performance-22"><a class="header" href="#performance-22">Performance</a></h3>
<p>This is an optimization. The removal of public/user transactions on the Relay Chain ensures that its
primary resources are allocated to system performance.</p>
<h3 id="ergonomics-19"><a class="header" href="#ergonomics-19">Ergonomics</a></h3>
<p>This proposal alters very little for coretime users (e.g. parachain developers). Application
developers will need to interact with multiple chains, making ergonomic light client tools
particularly important for application development.</p>
<p>For existing parachains that interact with these subsystems, they will need to configure their
runtimes to recognize the new locations in the network.</p>
<h3 id="compatibility-19"><a class="header" href="#compatibility-19">Compatibility</a></h3>
<p>Implementing this proposal will require some changes to pallet APIs and/or a pub-sub protocol.
Application developers will need to interact with multiple chains in the network.</p>
<h2 id="prior-art-and-references-27"><a class="header" href="#prior-art-and-references-27">Prior Art and References</a></h2>
<ul>
<li><a href="https://github.com/paritytech/polkadot/issues/323">Transactionless Relay-chain</a></li>
<li><a href="https://github.com/paritytech/polkadot-sdk/issues/491">Moving Staking off the Relay Chain</a></li>
</ul>
<h2 id="unresolved-questions-25"><a class="header" href="#unresolved-questions-25">Unresolved Questions</a></h2>
<p>There remain some implementation questions, like how to use balances for both Staking and
Governance. See, for example, <a href="https://github.com/paritytech/polkadot-sdk/issues/491">Moving Staking off the Relay
Chain</a>.</p>
<h2 id="future-directions-and-related-material-20"><a class="header" href="#future-directions-and-related-material-20">Future Directions and Related Material</a></h2>
<p>Ideally the Relay Chain becomes transactionless, such that not even balances are represented there.
With Staking and Governance off the Relay Chain, this is not an unreasonable next step.</p>
<p>With Identity on Polkadot, Kusama may opt to drop its People Chain.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0042-extrinsics-state-version.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0042-extrinsics-state-version.html#rfc-0042-add-system-version-that-replaces-stateversion-on-runtimeversion">RFC-0042: Add System version that replaces StateVersion on RuntimeVersion</a>
<ul>
<li><a href="approved/0042-extrinsics-state-version.html#summary">Summary</a></li>
<li><a href="approved/0042-extrinsics-state-version.html#motivation">Motivation</a></li>
<li><a href="approved/0042-extrinsics-state-version.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0042-extrinsics-state-version.html#explanation">Explanation</a></li>
<li><a href="approved/0042-extrinsics-state-version.html#drawbacks">Drawbacks</a></li>
<li><a href="approved/0042-extrinsics-state-version.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="approved/0042-extrinsics-state-version.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="approved/0042-extrinsics-state-version.html#performance">Performance</a></li>
<li><a href="approved/0042-extrinsics-state-version.html#ergonomics">Ergonomics</a></li>
<li><a href="approved/0042-extrinsics-state-version.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="approved/0042-extrinsics-state-version.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="approved/0042-extrinsics-state-version.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="approved/0042-extrinsics-state-version.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0042-add-system-version-that-replaces-stateversion-on-runtimeversion"><a class="header" href="#rfc-0042-add-system-version-that-replaces-stateversion-on-runtimeversion">RFC-0042: Add System version that replaces StateVersion on RuntimeVersion</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>25th October 2023</td></tr>
<tr><td><strong>Description</strong></td><td>Add System Version and remove State Version</td></tr>
<tr><td><strong>Authors</strong></td><td>Vedhavyas Singareddi</td></tr>
</tbody></table>
</div>
<h2 id="summary-31"><a class="header" href="#summary-31">Summary</a></h2>
<p>At the moment, we have <code>system_version</code> field on <code>RuntimeVersion</code> that derives which state version is used for the
Storage.
We have a use case where we want extrinsics root is derived using <code>StateVersion::V1</code>. Without defining a new field
under <code>RuntimeVersion</code>,
we would like to propose adding <code>system_version</code> that can be used to derive both storage and extrinsic state version.</p>
<h2 id="motivation-31"><a class="header" href="#motivation-31">Motivation</a></h2>
<p>Since the extrinsic state version is always <code>StateVersion::V0</code>, deriving extrinsic root requires full extrinsic data.
This would be problematic when we need to verify the extrinsics root if the extrinsic sizes are bigger. This problem is
further explored in https://github.com/polkadot-fellows/RFCs/issues/19</p>
<p>For <code>Subspace</code> project, we have an enshrined rollups called <code>Domain</code> with optimistic verification and Fraud proofs are
used to detect malicious behavior.
One of the <code>Fraud proof</code> variant is to derive <code>Domain</code> block extrinsic root on <code>Subspace</code>'s consensus chain.
Since <code>StateVersion::V0</code> requires full extrinsic data, we are forced to pass all the extrinsics through the Fraud proof.
One of the main challenge here is some extrinsics could be big enough that this variant of Fraud proof may not be
included in the Consensus block due to Block's weight restriction.
If the extrinsic root is derived using <code>StateVersion::V1</code>, then we do not need to pass the full extrinsic data but
rather at maximum, 32 byte of extrinsic data.</p>
<h2 id="stakeholders-30"><a class="header" href="#stakeholders-30">Stakeholders</a></h2>
<ul>
<li>Technical Fellowship, in its role of maintaining system runtimes.</li>
</ul>
<h2 id="explanation-30"><a class="header" href="#explanation-30">Explanation</a></h2>
<p>In order to use project specific StateVersion for extrinsic roots, we proposed
an <a href="https://github.com/paritytech/polkadot-sdk/pull/1691">implementation</a> that introduced
parameter to <code>frame_system::Config</code> but that unfortunately did not feel correct.
So we would like to <a href="https://github.com/paritytech/polkadot-sdk/pull/1968">propose</a> adding this change to
the <code>RuntimeVersion</code>
object. The system version, if introduced, will be used to derive both storage and extrinsic state version.
If system version is <code>0</code>, then both Storage and Extrinsic State version would use V0.
If system version is <code>1</code>, then Storage State version would use V1 and Extrinsic State version would use V0.
If system version is <code>2</code>, then both Storage and Extrinsic State version would use V1.</p>
<p>If implemented, the new <code>RuntimeVersion</code> definition would look something similar to</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>/// Runtime version (Rococo).
#[sp_version::runtime_version]
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!(&quot;rococo&quot;),
impl_name: create_runtime_str!(&quot;parity-rococo-v2.0&quot;),
authoring_version: 0,
spec_version: 10020,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 22,
system_version: 1,
};
<span class="boring">}</span></code></pre></pre>
<h2 id="drawbacks-28"><a class="header" href="#drawbacks-28">Drawbacks</a></h2>
<p>There should be no drawbacks as it would replace <code>state_version</code> with same behavior but documentation should be updated
so that chains know which <code>system_version</code> to use.</p>
<h2 id="testing-security-and-privacy-27"><a class="header" href="#testing-security-and-privacy-27">Testing, Security, and Privacy</a></h2>
<p>AFAIK, should not have any impact on the security or privacy.</p>
<h2 id="performance-ergonomics-and-compatibility-26"><a class="header" href="#performance-ergonomics-and-compatibility-26">Performance, Ergonomics, and Compatibility</a></h2>
<p>These changes should be compatible for existing chains if they use <code>state_version</code> value for <code>system_verision</code>.</p>
<h3 id="performance-23"><a class="header" href="#performance-23">Performance</a></h3>
<p>I do not believe there is any performance hit with this change.</p>
<h3 id="ergonomics-20"><a class="header" href="#ergonomics-20">Ergonomics</a></h3>
<p>This does not break any exposed Apis.</p>
<h3 id="compatibility-20"><a class="header" href="#compatibility-20">Compatibility</a></h3>
<p>This change should not break any compatibility.</p>
<h2 id="prior-art-and-references-28"><a class="header" href="#prior-art-and-references-28">Prior Art and References</a></h2>
<p>We <a href="https://github.com/paritytech/polkadot-sdk/pull/1691">proposed</a> introducing a similar change by introducing a
parameter to <code>frame_system::Config</code> but did not feel that
is the correct way of introducing this change.</p>
<h2 id="unresolved-questions-26"><a class="header" href="#unresolved-questions-26">Unresolved Questions</a></h2>
<p>I do not have any specific questions about this change at the moment.</p>
<h2 id="future-directions-and-related-material-21"><a class="header" href="#future-directions-and-related-material-21">Future Directions and Related Material</a></h2>
<p>IMO, this change is pretty self-contained and there won't be any future work necessary. </p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0043-storage-proof-size-hostfunction.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0043-storage-proof-size-hostfunction.html#rfc-0043-introduce-storage_proof_size-host-function-for-improved-parachain-block-utilization">RFC-0043: Introduce <code>storage_proof_size</code> Host Function for Improved Parachain Block Utilization</a>
<ul>
<li><a href="approved/0043-storage-proof-size-hostfunction.html#summary">Summary</a></li>
<li><a href="approved/0043-storage-proof-size-hostfunction.html#motivation">Motivation</a></li>
<li><a href="approved/0043-storage-proof-size-hostfunction.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0043-storage-proof-size-hostfunction.html#explanation">Explanation</a></li>
<li><a href="approved/0043-storage-proof-size-hostfunction.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="approved/0043-storage-proof-size-hostfunction.html#performance">Performance</a></li>
<li><a href="approved/0043-storage-proof-size-hostfunction.html#ergonomics">Ergonomics</a></li>
<li><a href="approved/0043-storage-proof-size-hostfunction.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="approved/0043-storage-proof-size-hostfunction.html#prior-art-and-references">Prior Art and References</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0043-introduce-storage_proof_size-host-function-for-improved-parachain-block-utilization"><a class="header" href="#rfc-0043-introduce-storage_proof_size-host-function-for-improved-parachain-block-utilization">RFC-0043: Introduce <code>storage_proof_size</code> Host Function for Improved Parachain Block Utilization</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>30 October 2023</td></tr>
<tr><td><strong>Description</strong></td><td>Host function to provide the storage proof size to runtimes.</td></tr>
<tr><td><strong>Authors</strong></td><td>Sebastian Kunert</td></tr>
</tbody></table>
</div>
<h2 id="summary-32"><a class="header" href="#summary-32">Summary</a></h2>
<p>This RFC proposes a new host function for parachains, <code>storage_proof_size</code>. It shall provide the size of the currently recorded storage proof to the runtime. Runtime authors can use the proof size to improve block utilization by retroactively reclaiming unused storage weight.</p>
<h2 id="motivation-32"><a class="header" href="#motivation-32">Motivation</a></h2>
<p>The number of extrinsics that are included in a parachain block is limited by two constraints: execution time and proof size. FRAME weights cover both concepts, and block-builders use them to decide how many extrinsics to include in a block. However, these weights are calculated ahead of time by benchmarking on a machine with reference hardware. The execution-time properties of the state-trie and its storage items are unknown at benchmarking time. Therefore, we make some assumptions about the state-trie:</p>
<ul>
<li><strong>Trie Depth:</strong> We assume a trie depth to account for intermediary nodes.</li>
<li><strong>Storage Item Size:</strong> We make a pessimistic assumption based on the <code>MaxEncodedLen</code> trait.</li>
</ul>
<p>These pessimistic assumptions lead to an overestimation of storage weight, negatively impacting block utilization on parachains.</p>
<p>In addition, the current model does not account for multiple accesses to the same storage items. While these repetitive accesses will not increase storage-proof size, the runtime-side weight monitoring will account for them multiple times. Since the proof size is completely opaque to the runtime, we can not implement retroactive storage weight correction.</p>
<p>A solution must provide a way for the runtime to track the exact storage-proof size consumed on a per-extrinsic basis.</p>
<h2 id="stakeholders-31"><a class="header" href="#stakeholders-31">Stakeholders</a></h2>
<ul>
<li><strong>Parachain Teams:</strong> They MUST include this host function in their runtime and node.</li>
<li><strong>Light-client Implementors:</strong> They SHOULD include this host function in their runtime and node.</li>
</ul>
<h2 id="explanation-31"><a class="header" href="#explanation-31">Explanation</a></h2>
<p>This RFC proposes a new host function that exposes the storage-proof size to the runtime. As a result, runtimes can implement storage weight reclaiming mechanisms that improve block utilization.</p>
<p>This RFC proposes the following host function signature:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>fn ext_storage_proof_size_version_1() -&gt; u64;
<span class="boring">}</span></code></pre></pre>
<p>The host function MUST return an unsigned 64-bit integer value representing the current proof size. In block-execution and block-import contexts, this function MUST return the current size of the proof. To achieve this, parachain node implementors need to enable proof recording for block imports. In other contexts, this function MUST return 18446744073709551615 (u64::MAX), which represents disabled proof recording.</p>
<h2 id="performance-ergonomics-and-compatibility-27"><a class="header" href="#performance-ergonomics-and-compatibility-27">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-24"><a class="header" href="#performance-24">Performance</a></h3>
<p>Parachain nodes need to enable proof recording during block import to correctly implement the proposed host function. Benchmarking conducted with balance transfers has shown a performance reduction of around 0.6% when proof recording is enabled. </p>
<h3 id="ergonomics-21"><a class="header" href="#ergonomics-21">Ergonomics</a></h3>
<p>The host function proposed in this RFC allows parachain runtime developers to keep track of the proof size. Typical usage patterns would be to keep track of the overall proof size or the difference between subsequent calls to the host function.</p>
<h3 id="compatibility-21"><a class="header" href="#compatibility-21">Compatibility</a></h3>
<p>Parachain teams will need to include this host function to upgrade.</p>
<h2 id="prior-art-and-references-29"><a class="header" href="#prior-art-and-references-29">Prior Art and References</a></h2>
<ul>
<li>Pull Request including proposed host function: <a href="https://github.com/paritytech/polkadot-sdk/pull/1462">PoV Reclaim (Clawback) Node Side</a>.</li>
<li>Issue with discussion: <a href="https://github.com/paritytech/polkadot-sdk/issues/209#top">[FRAME core] Clawback PoV Weights For Dispatchables</a></li>
</ul>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0045-nft-deposits-asset-hub.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0045-nft-deposits-asset-hub.html#rfc-0045-lowering-nft-deposits-on-asset-hub">RFC-0045: Lowering NFT Deposits on Asset Hub</a>
<ul>
<li><a href="approved/0045-nft-deposits-asset-hub.html#summary">Summary</a></li>
<li><a href="approved/0045-nft-deposits-asset-hub.html#motivation">Motivation</a>
<ul>
<li><a href="approved/0045-nft-deposits-asset-hub.html#requirements">Requirements</a></li>
</ul>
</li>
<li><a href="approved/0045-nft-deposits-asset-hub.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0045-nft-deposits-asset-hub.html#explanation">Explanation</a>
<ul>
<li><a href="approved/0045-nft-deposits-asset-hub.html#enhanced-approach-to-further-lower-barriers-for-entry">Enhanced Approach to Further Lower Barriers for Entry</a></li>
<li><a href="approved/0045-nft-deposits-asset-hub.html#short--and-long-term-plans">Short- and Long-Term Plans</a></li>
</ul>
</li>
<li><a href="approved/0045-nft-deposits-asset-hub.html#drawbacks">Drawbacks</a></li>
<li><a href="approved/0045-nft-deposits-asset-hub.html#testing-security-and-privacy">Testing, Security, and Privacy</a>
<ul>
<li><a href="approved/0045-nft-deposits-asset-hub.html#security-concerns">Security concerns</a></li>
</ul>
</li>
<li><a href="approved/0045-nft-deposits-asset-hub.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="approved/0045-nft-deposits-asset-hub.html#performance">Performance</a></li>
<li><a href="approved/0045-nft-deposits-asset-hub.html#ergonomics">Ergonomics</a></li>
<li><a href="approved/0045-nft-deposits-asset-hub.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="approved/0045-nft-deposits-asset-hub.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="approved/0045-nft-deposits-asset-hub.html#addendum">Addendum</a>
<ul>
<li><a href="approved/0045-nft-deposits-asset-hub.html#enhanced-weak-governance-origin-model">Enhanced Weak Governance Origin Model</a></li>
<li><a href="approved/0045-nft-deposits-asset-hub.html#function-based-pricing-model">Function-Based Pricing Model</a></li>
<li><a href="approved/0045-nft-deposits-asset-hub.html#linking-deposit-to-usdx-value">Linking Deposit to USD(x) Value</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<h1 id="rfc-0045-lowering-nft-deposits-on-asset-hub"><a class="header" href="#rfc-0045-lowering-nft-deposits-on-asset-hub">RFC-0045: Lowering NFT Deposits on Asset Hub</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>2 November 2023</td></tr>
<tr><td><strong>Description</strong></td><td>A proposal to reduce the minimum deposit required for collection creation on the Polkadot and Kusama Asset Hubs.</td></tr>
<tr><td><strong>Authors</strong></td><td><a href="https://github.com/poppyseedDev">Aurora Poppyseed</a>, <a href="https://github.com/justLuuuu">Just_Luuuu</a>, <a href="https://github.com/vikiival">Viki Val</a>, <a href="https://github.com/joepetrowski">Joe Petrowski</a></td></tr>
</tbody></table>
</div>
<h2 id="summary-33"><a class="header" href="#summary-33">Summary</a></h2>
<p>This RFC proposes changing the current deposit requirements on the Polkadot and Kusama Asset Hub for
creating an NFT collection, minting an individual NFT, and lowering its corresponding metadata and
attribute deposits. The objective is to lower the barrier to entry for NFT creators, fostering a
more inclusive and vibrant ecosystem while maintaining network integrity and preventing spam.</p>
<h2 id="motivation-33"><a class="header" href="#motivation-33">Motivation</a></h2>
<p>The current deposit of 10 DOT for collection creation (along with 0.01 DOT for item deposit and 0.2
DOT for metadata and attribute deposits) on the Polkadot Asset Hub and 0.1 KSM on Kusama Asset Hub
presents a significant financial barrier for many NFT creators. By lowering the deposit
requirements, we aim to encourage more NFT creators to participate in the Polkadot NFT ecosystem,
thereby enriching the diversity and vibrancy of the community and its offerings.</p>
<p>The initial introduction of a 10 DOT deposit was an arbitrary starting point that does not consider
the actual storage footprint of an NFT collection. This proposal aims to adjust the deposit first to
a value based on the <code>deposit</code> function, which calculates a deposit based on the number of keys
introduced to storage and the size of corresponding values stored.</p>
<p>Further, it suggests a direction for a future of calculating deposits variably based on adoption
and/or market conditions. There is a discussion on tradeoffs of setting deposits too high or too
low.</p>
<h3 id="requirements-7"><a class="header" href="#requirements-7">Requirements</a></h3>
<ul>
<li>Deposits SHOULD be derived from <code>deposit</code> function, adjusted by correspoding pricing mechansim.</li>
</ul>
<h2 id="stakeholders-32"><a class="header" href="#stakeholders-32">Stakeholders</a></h2>
<ul>
<li><strong>NFT Creators</strong>: Primary beneficiaries of the proposed change, particularly those who found the
current deposit requirements prohibitive.</li>
<li><strong>NFT Platforms</strong>: As the facilitator of artists' relations, NFT marketplaces have a vested
interest in onboarding new users and making their platforms more accessible.</li>
<li><strong>dApp Developers</strong>: Making the blockspace more accessible will encourage developers to create and
build unique dApps in the Polkadot ecosystem.</li>
<li><strong>Polkadot Community</strong>: Stands to benefit from an influx of artists, creators, and diverse NFT
collections, enhancing the overall ecosystem.</li>
</ul>
<p>Previous discussions have been held within the <a href="https://forum.polkadot.network/t/polkadot-assethub-high-nft-collection-deposit/4262">Polkadot
Forum</a>, with
artists expressing their concerns about the deposit amounts.</p>
<h2 id="explanation-32"><a class="header" href="#explanation-32">Explanation</a></h2>
<p>This RFC proposes a revision of the deposit constants in the configuration of the NFTs pallet on the
Polkadot Asset Hub. The new deposit amounts would be determined by a standard deposit formula.</p>
<p>As of v1.1.1, the Collection Deposit is 10 DOT and the Item Deposit is 0.01 DOT (see
<a href="https://github.com/polkadot-fellows/runtimes/blob/v1.1.1/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs#L687">here</a>).</p>
<p>Based on the storage footprint of these items, this RFC proposes changing them to:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>pub const NftsCollectionDeposit: Balance = system_para_deposit(1, 130);
pub const NftsItemDeposit: Balance = system_para_deposit(1, 164);
<span class="boring">}</span></code></pre></pre>
<p>This results in the following deposits (calculted using <a href="https://github.com/vikiival/rfc-pricing">this
repository</a>):</p>
<p><strong>Polkadot</strong></p>
<div class="table-wrapper"><table><thead><tr><th><strong>Name</strong></th><th style="text-align: center"><strong>Current Rate (DOT)</strong></th><th style="text-align: center"><strong>Calculated with Function (DOT)</strong></th></tr></thead><tbody>
<tr><td><code>collectionDeposit</code></td><td style="text-align: center">10</td><td style="text-align: center">0.20064</td></tr>
<tr><td><code>itemDeposit</code></td><td style="text-align: center">0.01</td><td style="text-align: center">0.20081</td></tr>
<tr><td><code>metadataDepositBase</code></td><td style="text-align: center">0.20129</td><td style="text-align: center">0.20076</td></tr>
<tr><td><code>attributeDepositBase</code></td><td style="text-align: center">0.2</td><td style="text-align: center">0.2</td></tr>
</tbody></table>
</div>
<p>Similarly, the prices for Kusama were calculated as:</p>
<p><strong>Kusama:</strong></p>
<div class="table-wrapper"><table><thead><tr><th><strong>Name</strong></th><th style="text-align: center"><strong>Current Rate (KSM)</strong></th><th style="text-align: center"><strong>Calculated with Function (KSM)</strong></th></tr></thead><tbody>
<tr><td><code>collectionDeposit</code></td><td style="text-align: center">0.1</td><td style="text-align: center">0.006688</td></tr>
<tr><td><code>itemDeposit</code></td><td style="text-align: center">0.001</td><td style="text-align: center">0.000167</td></tr>
<tr><td><code>metadataDepositBase</code></td><td style="text-align: center">0.006709666617</td><td style="text-align: center">0.0006709666617</td></tr>
<tr><td><code>attributeDepositBase</code></td><td style="text-align: center">0.00666666666</td><td style="text-align: center">0.000666666666</td></tr>
</tbody></table>
</div>
<h3 id="enhanced-approach-to-further-lower-barriers-for-entry"><a class="header" href="#enhanced-approach-to-further-lower-barriers-for-entry">Enhanced Approach to Further Lower Barriers for Entry</a></h3>
<p>This RFC proposes further lowering these deposits below the rate normally charged for such a storage
footprint. This is based on the economic argument that sub-rate deposits are a subsididy for growth
and adoption of a specific technology. If the NFT functionality on Polkadot gains adoption, it makes
it more attractive for future entrants, who would be willing to pay the non-subsidized rate because
of the existing community.</p>
<p><strong>Proposed Rate Adjustments</strong></p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>parameter_types! {
pub const NftsCollectionDeposit: Balance = system_para_deposit(1, 130);
pub const NftsItemDeposit: Balance = system_para_deposit(1, 164) / 40;
pub const NftsMetadataDepositBase: Balance = system_para_deposit(1, 129) / 10;
pub const NftsAttributeDepositBase: Balance = system_para_deposit(1, 0) / 10;
pub const NftsDepositPerByte: Balance = system_para_deposit(0, 1);
}
<span class="boring">}</span></code></pre></pre>
<p>This adjustment would result in the following DOT and KSM deposit values:</p>
<div class="table-wrapper"><table><thead><tr><th><strong>Name</strong></th><th style="text-align: center"><strong>Proposed Rate Polkadot</strong></th><th style="text-align: center"><strong>Proposed Rate Kusama</strong></th></tr></thead><tbody>
<tr><td><code>collectionDeposit</code></td><td style="text-align: center">0.20064 DOT</td><td style="text-align: center">0.006688 KSM</td></tr>
<tr><td><code>itemDeposit</code></td><td style="text-align: center">0.005 DOT</td><td style="text-align: center">0.000167 KSM</td></tr>
<tr><td><code>metadataDepositBase</code></td><td style="text-align: center">0.002 DOT</td><td style="text-align: center">0.0006709666617 KSM</td></tr>
<tr><td><code>attributeDepositBase</code></td><td style="text-align: center">0.002 DOT</td><td style="text-align: center">0.000666666666 KSM</td></tr>
</tbody></table>
</div>
<h3 id="short--and-long-term-plans"><a class="header" href="#short--and-long-term-plans">Short- and Long-Term Plans</a></h3>
<p>The plan presented above is recommended as an immediate step to make Polkadot a more attractive
place to launch NFTs, although one would note that a forty fold reduction in the Item Deposit is
just as arbitrary as the value it was replacing. As explained earlier, this is meant as a subsidy to
gain more momentum for NFTs on Polkadot.</p>
<p>In the long term, an implementation should account for what should happen to the deposit rates
assuming that the subsidy is successful and attracts a lot of deployments. Many options are
discussed in the <a href="approved/0045-nft-deposits-asset-hub.html#addendum">Addendum</a>.</p>
<p>The deposit should be calculated as a function of the number of existing collections with maximum
DOT and stablecoin values limiting the amount. With asset rates available via the Asset Conversion
pallet, the system could take the lower value required. A sigmoid curve would make sense for this
application to avoid sudden rate changes, as in:</p>
<p>$$ minDeposit + \frac{\mathrm{min(DotDeposit, StableDeposit) - minDeposit} }{\mathrm{1 + e^{a - b * x}} }$$</p>
<p>where the constant <code>a</code> moves the inflection to lower or higher <code>x</code> values, the constant <code>b</code> adjusts
the rate of the deposit increase, and the independent variable <code>x</code> is the number of collections or
items, depending on application.</p>
<h2 id="drawbacks-29"><a class="header" href="#drawbacks-29">Drawbacks</a></h2>
<p>Modifying deposit requirements necessitates a balanced assessment of the potential drawbacks.
Highlighted below are cogent points extracted from the discourse on the <a href="https://forum.polkadot.network/t/polkadot-assethub-high-nft-collection-deposit/4262">Polkadot Forum
conversation</a>,
which provide critical perspectives on the implications of such changes.</p>
<p>Adjusting NFT deposit requirements on Polkadot and Kusama Asset Hubs involves key challenges:</p>
<ol>
<li>
<p><strong>State Growth and Technical Concerns</strong>: Lowering deposit requirements can lead to increased
blockchain state size, potentially causing state bloat. This growth needs to be managed to
prevent strain on the network's resources and maintain operational efficiency. As stated earlier,
the deposit levels proposed here are intentionally low with the thesis that future participants
would pay the standard rate.</p>
</li>
<li>
<p><strong>Network Security and Market Response</strong>: Adapting to the cryptocurrency market's volatility is
crucial. The mechanism for setting deposit amounts must be responsive yet stable, avoiding undue
complexity for users.</p>
</li>
<li>
<p><strong>Economic Impact on Previous Stakeholders</strong>: The change could have varied economic effects on
previous (before the change) creators, platform operators, and investors. Balancing these
interests is essential to ensure the adjustment benefits the ecosystem without negatively
impacting its value dynamics. However in the particular case of Polkadot and Kusama Asset Hub
this does not pose a concern since there are very few collections currently and thus previous
stakeholders wouldn't be much affected. As of date 9th January 2024 there are 42 collections on
Polkadot Asset Hub and 191 on Kusama Asset Hub with a relatively low volume.</p>
</li>
</ol>
<h2 id="testing-security-and-privacy-28"><a class="header" href="#testing-security-and-privacy-28">Testing, Security, and Privacy</a></h2>
<h3 id="security-concerns"><a class="header" href="#security-concerns">Security concerns</a></h3>
<p>As noted above, state bloat is a security concern. In the case of abuse, governance could adapt by
increasing deposit rates and/or using <code>forceDestroy</code> on collections agreed to be spam.</p>
<h2 id="performance-ergonomics-and-compatibility-28"><a class="header" href="#performance-ergonomics-and-compatibility-28">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-25"><a class="header" href="#performance-25">Performance</a></h3>
<p>The primary performance consideration stems from the potential for state bloat due to increased
activity from lower deposit requirements. It's vital to monitor and manage this to avoid any
negative impact on the chain's performance. Strategies for mitigating state bloat, including
efficient data management and periodic reviews of storage requirements, will be essential.</p>
<h3 id="ergonomics-22"><a class="header" href="#ergonomics-22">Ergonomics</a></h3>
<p>The proposed change aims to enhance the user experience for artists, traders, and utilizers of
Kusama and Polkadot Asset Hubs, making Polkadot and Kusama more accessible and user-friendly.</p>
<h3 id="compatibility-22"><a class="header" href="#compatibility-22">Compatibility</a></h3>
<p>The change does not impact compatibility as a <code>redeposit</code> function is already implemented.</p>
<h2 id="unresolved-questions-27"><a class="header" href="#unresolved-questions-27">Unresolved Questions</a></h2>
<p>If this RFC is accepted, there should not be any unresolved questions regarding how to adapt the
implementation of deposits for NFT collections.</p>
<h2 id="addendum"><a class="header" href="#addendum">Addendum</a></h2>
<p>Several innovative proposals have been considered to enhance the network's adaptability and manage
deposit requirements more effectively. The RFC recommends a mixture of the function-based model and
the stablecoin model, but some tradeoffs of each are maintained here for those interested.</p>
<h3 id="enhanced-weak-governance-origin-model"><a class="header" href="#enhanced-weak-governance-origin-model">Enhanced Weak Governance Origin Model</a></h3>
<p>The concept of a weak governance origin, controlled by a consortium like a system collective, has
been proposed. This model would allow for dynamic adjustments of NFT deposit requirements in
response to market conditions, adhering to storage deposit norms.</p>
<ul>
<li><strong>Responsiveness</strong>: To address concerns about delayed responses, the model could incorporate
automated triggers based on predefined market indicators, ensuring timely adjustments.</li>
<li><strong>Stability vs. Flexibility</strong>: Balancing stability with the need for flexibility is challenging.
To mitigate the issue of frequent changes in DOT-based deposits, a mechanism for gradual and
predictable adjustments could be introduced.</li>
<li><strong>Scalability</strong>: The model's scalability is a concern, given the numerous deposits across the
system. A more centralized approach to deposit management might be needed to avoid constant,
decentralized adjustments.</li>
</ul>
<h3 id="function-based-pricing-model"><a class="header" href="#function-based-pricing-model">Function-Based Pricing Model</a></h3>
<p>Another proposal is to use a mathematical function to regulate deposit prices, initially allowing
low prices to encourage participation, followed by a gradual increase to prevent network bloat.</p>
<ul>
<li><strong>Choice of Function</strong>: A logarithmic or sigmoid function is favored over an exponential one, as
these functions increase prices at a rate that encourages participation while preventing
prohibitive costs.</li>
<li><strong>Adjustment of Constants</strong>: To finely tune the pricing rise, one of the function's constants
could correlate with the total number of NFTs on Asset Hub. This would align the deposit
requirements with the actual usage and growth of the network.</li>
</ul>
<h3 id="linking-deposit-to-usdx-value"><a class="header" href="#linking-deposit-to-usdx-value">Linking Deposit to USD(x) Value</a></h3>
<p>This approach suggests pegging the deposit value to a stable currency like the USD, introducing
predictability and stability for network users.</p>
<ul>
<li><strong>Market Dynamics</strong>: One perspective is that fluctuations in native currency value naturally
balance user participation and pricing, deterring network spam while encouraging higher-value
collections. Conversely, there's an argument for allowing broader participation if the DOT/KSM
value increases.</li>
<li><strong>Complexity and Risks</strong>: Implementing a USD-based pricing system could add complexity and
potential risks. The implementation needs to be carefully designed to avoid unintended
consequences, such as excessive reliance on external financial systems or currencies.</li>
</ul>
<p>Each of these proposals offers unique advantages and challenges. The optimal approach may involve a
combination of these ideas, carefully adjusted to address the specific needs and dynamics of the
Polkadot and Kusama networks.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0047-assignment-of-availability-chunks.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0047-assignment-of-availability-chunks.html#rfc-0047-assignment-of-availability-chunks-to-validators">RFC-0047: Assignment of availability chunks to validators</a>
<ul>
<li><a href="approved/0047-assignment-of-availability-chunks.html#summary">Summary</a></li>
<li><a href="approved/0047-assignment-of-availability-chunks.html#motivation">Motivation</a></li>
<li><a href="approved/0047-assignment-of-availability-chunks.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0047-assignment-of-availability-chunks.html#explanation">Explanation</a>
<ul>
<li><a href="approved/0047-assignment-of-availability-chunks.html#systematic-erasure-codes">Systematic erasure codes</a></li>
<li><a href="approved/0047-assignment-of-availability-chunks.html#availability-recovery-at-present">Availability recovery at present</a></li>
<li><a href="approved/0047-assignment-of-availability-chunks.html#availability-recovery-from-systematic-chunks">Availability recovery from systematic chunks</a></li>
<li><a href="approved/0047-assignment-of-availability-chunks.html#chunk-assignment-function">Chunk assignment function</a></li>
<li><a href="approved/0047-assignment-of-availability-chunks.html#network-protocol">Network protocol</a></li>
<li><a href="approved/0047-assignment-of-availability-chunks.html#upgrade-path">Upgrade path</a></li>
</ul>
</li>
<li><a href="approved/0047-assignment-of-availability-chunks.html#drawbacks">Drawbacks</a></li>
<li><a href="approved/0047-assignment-of-availability-chunks.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="approved/0047-assignment-of-availability-chunks.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="approved/0047-assignment-of-availability-chunks.html#performance">Performance</a></li>
<li><a href="approved/0047-assignment-of-availability-chunks.html#ergonomics">Ergonomics</a></li>
<li><a href="approved/0047-assignment-of-availability-chunks.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="approved/0047-assignment-of-availability-chunks.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="approved/0047-assignment-of-availability-chunks.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="approved/0047-assignment-of-availability-chunks.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
<li><a href="approved/0047-assignment-of-availability-chunks.html#appendix-a">Appendix A</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0047-assignment-of-availability-chunks-to-validators"><a class="header" href="#rfc-0047-assignment-of-availability-chunks-to-validators">RFC-0047: Assignment of availability chunks to validators</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>03 November 2023</td></tr>
<tr><td><strong>Description</strong></td><td>An evenly-distributing indirection layer between availability chunks and validators.</td></tr>
<tr><td><strong>Authors</strong></td><td>Alin Dima</td></tr>
</tbody></table>
</div>
<h2 id="summary-34"><a class="header" href="#summary-34">Summary</a></h2>
<p>Propose a way of permuting the availability chunk indices assigned to validators, in the context of
<a href="https://github.com/paritytech/polkadot-sdk/issues/598">recovering available data from systematic chunks</a>, with the
purpose of fairly distributing network bandwidth usage.</p>
<h2 id="motivation-34"><a class="header" href="#motivation-34">Motivation</a></h2>
<p>Currently, the ValidatorIndex is always identical to the ChunkIndex. Since the validator array is only shuffled once
per session, naively using the ValidatorIndex as the ChunkIndex would pose an unreasonable stress on the first N/3
validators during an entire session, when favouring availability recovery from systematic chunks.</p>
<p>Therefore, the relay chain node needs a deterministic way of evenly distributing the first ~(N_VALIDATORS / 3)
systematic availability chunks to different validators, based on the relay chain block and core.
The main purpose is to ensure fair distribution of network bandwidth usage for availability recovery in general and in
particular for systematic chunk holders. </p>
<h2 id="stakeholders-33"><a class="header" href="#stakeholders-33">Stakeholders</a></h2>
<p>Relay chain node core developers.</p>
<h2 id="explanation-33"><a class="header" href="#explanation-33">Explanation</a></h2>
<h3 id="systematic-erasure-codes"><a class="header" href="#systematic-erasure-codes">Systematic erasure codes</a></h3>
<p>An erasure coding algorithm is considered systematic if it preserves the original unencoded data as part of the
resulting code.
<a href="https://github.com/paritytech/reed-solomon-novelpoly">The implementation of the erasure coding algorithm used for polkadot's availability data</a> is systematic.
Roughly speaking, the first N_VALIDATORS/3 chunks of data can be cheaply concatenated to retrieve the original data,
without running the resource-intensive and time-consuming reconstruction algorithm.</p>
<p>You can find the concatenation procedure of systematic chunks for polkadot's erasure coding algorithm
<a href="https://github.com/paritytech/reed-solomon-novelpoly/blob/be3751093e60adc20c19967f5443158552829011/reed-solomon-novelpoly/src/novel_poly_basis/mod.rs#L247">here</a></p>
<p>In a nutshell, it performs a column-wise concatenation with 2-byte chunks.
The output could be zero-padded at the end, so scale decoding must be aware of the expected length in bytes and ignore
trailing zeros (this assertion is already being made for regular reconstruction).</p>
<h3 id="availability-recovery-at-present"><a class="header" href="#availability-recovery-at-present">Availability recovery at present</a></h3>
<p>According to the <a href="https://spec.polkadot.network/chapter-anv#sect-candidate-recovery">polkadot protocol spec</a>:</p>
<blockquote>
<p>A validator should request chunks by picking peers randomly and must recover at least <code>f+1</code> chunks, where
<code>n=3f+k</code> and <code>k in {1,2,3}</code>.</p>
</blockquote>
<p>For parity's polkadot node implementation, the process was further optimised. At this moment, it works differently based
on the estimated size of the available data:</p>
<p>(a) for small PoVs (up to 128 Kib), sequentially try requesting the unencoded data from the backing group, in a random
order. If this fails, fallback to option (b).</p>
<p>(b) for large PoVs (over 128 Kib), launch N parallel requests for the erasure coded chunks (currently, N has an upper
limit of 50), until enough chunks were recovered. Validators are tried in a random order. Then, reconstruct the
original data.</p>
<p>All options require that after reconstruction, validators then re-encode the data and re-create the erasure chunks trie
in order to check the erasure root.</p>
<h3 id="availability-recovery-from-systematic-chunks"><a class="header" href="#availability-recovery-from-systematic-chunks">Availability recovery from systematic chunks</a></h3>
<p>As part of the effort of
<a href="https://github.com/paritytech/roadmap/issues/26">increasing polkadot's resource efficiency, scalability and performance</a>,
work is under way to modify the Availability Recovery protocol by leveraging systematic chunks. See
<a href="https://github.com/paritytech/polkadot-sdk/issues/598#issuecomment-1792007099">this comment</a> for preliminary
performance results.</p>
<p>In this scheme, the relay chain node will first attempt to retrieve the ~N/3 systematic chunks from the validators that
should hold them, before falling back to recovering from regular chunks, as before.</p>
<p>A re-encoding step is still needed for verifying the erasure root, so the erasure coding overhead cannot be completely
brought down to 0.</p>
<p>Not being able to retrieve even one systematic chunk would make systematic reconstruction impossible. Therefore, backers
can be used as a backup to retrieve a couple of missing systematic chunks, before falling back to retrieving regular
chunks.</p>
<h3 id="chunk-assignment-function"><a class="header" href="#chunk-assignment-function">Chunk assignment function</a></h3>
<h4 id="properties"><a class="header" href="#properties">Properties</a></h4>
<p>The function that decides the chunk index for a validator will be parameterized by at least
<code>(validator_index, core_index)</code>
and have the following properties:</p>
<ol>
<li>deterministic</li>
<li>relatively quick to compute and resource-efficient.</li>
<li>when considering a fixed <code>core_index</code>, the function should describe a permutation of the chunk indices</li>
<li>the validators that map to the first N/3 chunk indices should have as little overlap as possible for different cores.</li>
</ol>
<p>In other words, we want a uniformly distributed, deterministic mapping from <code>ValidatorIndex</code> to <code>ChunkIndex</code> per core.</p>
<p>It's desirable to not embed this function in the runtime, for performance and complexity reasons.
However, this means that the function needs to be kept very simple and with minimal or no external dependencies.
Any change to this function could result in parachains being stalled and needs to be coordinated via a runtime upgrade
or governance call.</p>
<h4 id="proposed-function"><a class="header" href="#proposed-function">Proposed function</a></h4>
<p>Pseudocode:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>pub fn get_chunk_index(
n_validators: u32,
validator_index: ValidatorIndex,
core_index: CoreIndex
) -&gt; ChunkIndex {
let threshold = systematic_threshold(n_validators); // Roughly n_validators/3
let core_start_pos = core_index * threshold;
(core_start_pos + validator_index) % n_validators
}
<span class="boring">}</span></code></pre></pre>
<h3 id="network-protocol"><a class="header" href="#network-protocol">Network protocol</a></h3>
<p>The request-response <code>/req_chunk</code> protocol will be bumped to a new version (from v1 to v2).
For v1, the request and response payloads are:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>/// Request an availability chunk.
pub struct ChunkFetchingRequest {
/// Hash of candidate we want a chunk for.
pub candidate_hash: CandidateHash,
/// The index of the chunk to fetch.
pub index: ValidatorIndex,
}
/// Receive a requested erasure chunk.
pub enum ChunkFetchingResponse {
/// The requested chunk data.
Chunk(ChunkResponse),
/// Node was not in possession of the requested chunk.
NoSuchChunk,
}
/// This omits the chunk's index because it is already known by
/// the requester and by not transmitting it, we ensure the requester is going to use his index
/// value for validating the response, thus making sure he got what he requested.
pub struct ChunkResponse {
/// The erasure-encoded chunk of data belonging to the candidate block.
pub chunk: Vec&lt;u8&gt;,
/// Proof for this chunk's branch in the Merkle tree.
pub proof: Proof,
}
<span class="boring">}</span></code></pre></pre>
<p>Version 2 will add an <code>index</code> field to <code>ChunkResponse</code>:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>#[derive(Debug, Clone, Encode, Decode)]
pub struct ChunkResponse {
/// The erasure-encoded chunk of data belonging to the candidate block.
pub chunk: Vec&lt;u8&gt;,
/// Proof for this chunk's branch in the Merkle tree.
pub proof: Proof,
/// Chunk index.
pub index: ChunkIndex
}
<span class="boring">}</span></code></pre></pre>
<p>An important thing to note is that in version 1, the <code>ValidatorIndex</code> value is always equal to the <code>ChunkIndex</code>.
Until the chunk rotation feature is enabled, this will also be true for version 2. However, after the feature is
enabled, this will generally not be true.</p>
<p>The requester will send the request to validator with index <code>V</code>. The responder will map the <code>V</code> validator index to the
<code>C</code> chunk index and respond with the <code>C</code>-th chunk. This mapping can be seamless, by having each validator store their
chunk by <code>ValidatorIndex</code> (just as before).</p>
<p>The protocol implementation MAY check the returned <code>ChunkIndex</code> against the expected mapping to ensure that
it received the right chunk.
In practice, this is desirable during availability-distribution and systematic chunk recovery. However, regular
recovery may not check this index, which is particularly useful when participating in disputes that don't allow
for easy access to the validator-&gt;chunk mapping. See <a href="approved/0047-assignment-of-availability-chunks.html#appendix-a">Appendix A</a> for more details.</p>
<p>In any case, the requester MUST verify the chunk's proof using the provided index.</p>
<p>During availability-recovery, given that the requester may not know (if the mapping is not available) whether the
received chunk corresponds to the requested validator index, it has to keep track of received chunk indices and ignore
duplicates. Such duplicates should be considered the same as an invalid/garbage response (drop it and move on to the
next validator - we can't punish via reputation changes, because we don't know which validator misbehaved).</p>
<h3 id="upgrade-path"><a class="header" href="#upgrade-path">Upgrade path</a></h3>
<h4 id="step-1-enabling-new-network-protocol"><a class="header" href="#step-1-enabling-new-network-protocol">Step 1: Enabling new network protocol</a></h4>
<p>In the beginning, both <code>/req_chunk/1</code> and <code>/req_chunk/2</code> will be supported, until all validators and
collators have upgraded to use the new version. V1 will be considered deprecated. During this step, the mapping will
still be 1:1 (<code>ValidatorIndex</code> == <code>ChunkIndex</code>), regardless of protocol.
Once all nodes are upgraded, a new release will be cut that removes the v1 protocol. Only once all nodes have upgraded
to this version will step 2 commence.</p>
<h4 id="step-2-enabling-the-new-validator-chunk-mapping"><a class="header" href="#step-2-enabling-the-new-validator-chunk-mapping">Step 2: Enabling the new validator-&gt;chunk mapping</a></h4>
<p>Considering that the Validator-&gt;Chunk mapping is critical to para consensus, the change needs to be enacted atomically
via governance, only after all validators have upgraded the node to a version that is aware of this mapping,
functionality-wise.
It needs to be explicitly stated that after the governance enactment, validators that run older client versions that
don't support this mapping will not be able to participate in parachain consensus.</p>
<p>Additionally, an error will be logged when starting a validator with an older version, after the feature was enabled.</p>
<p>On the other hand, collators will not be required to upgrade in this step (but are still require to upgrade for step 1),
as regular chunk recovery will work as before, granted that version 1 of the networking protocol has been removed.
Note that collators only perform availability-recovery in rare, adversarial scenarios, so it is fine to not optimise for
this case and let them upgrade at their own pace.</p>
<p>To support enabling this feature via the runtime, we will use the <code>NodeFeatures</code> bitfield of the <code>HostConfiguration</code>
struct (added in <code>https://github.com/paritytech/polkadot-sdk/pull/2177</code>). Adding and enabling a feature
with this scheme does not require a runtime upgrade, but only a referendum that issues a
<code>Configuration::set_node_feature</code> extrinsic. Once the feature is enabled and new configuration is live, the
validator-&gt;chunk mapping ceases to be a 1:1 mapping and systematic recovery may begin.</p>
<h2 id="drawbacks-30"><a class="header" href="#drawbacks-30">Drawbacks</a></h2>
<ul>
<li>Getting access to the <code>core_index</code> that used to be occupied by a candidate in some parts of the dispute protocol is
very complicated (See <a href="approved/0047-assignment-of-availability-chunks.html#appendix-a">appendix A</a>). This RFC assumes that availability-recovery processes initiated during
disputes will only use regular recovery, as before. This is acceptable since disputes are rare occurrences in practice
and is something that can be optimised later, if need be. Adding the <code>core_index</code> to the <code>CandidateReceipt</code> would
mitigate this problem and will likely be needed in the future for CoreJam and/or Elastic scaling.
<a href="https://forum.polkadot.network/t/pre-rfc-discussion-candidate-receipt-format-v2/3738">Related discussion about updating <code>CandidateReceipt</code></a></li>
<li>It's a breaking change that requires all validators and collators to upgrade their node version at least once.</li>
</ul>
<h2 id="testing-security-and-privacy-29"><a class="header" href="#testing-security-and-privacy-29">Testing, Security, and Privacy</a></h2>
<p>Extensive testing will be conducted - both automated and manual.
This proposal doesn't affect security or privacy.</p>
<h2 id="performance-ergonomics-and-compatibility-29"><a class="header" href="#performance-ergonomics-and-compatibility-29">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-26"><a class="header" href="#performance-26">Performance</a></h3>
<p>This is a necessary data availability optimisation, as reed-solomon erasure coding has proven to be a top consumer of
CPU time in polkadot as we scale up the parachain block size and number of availability cores.</p>
<p>With this optimisation, preliminary performance results show that CPU time used for reed-solomon coding/decoding can be
halved and total POV recovery time decrease by 80% for large POVs. See more
<a href="https://github.com/paritytech/polkadot-sdk/issues/598#issuecomment-1792007099">here</a>.</p>
<h3 id="ergonomics-23"><a class="header" href="#ergonomics-23">Ergonomics</a></h3>
<p>Not applicable.</p>
<h3 id="compatibility-23"><a class="header" href="#compatibility-23">Compatibility</a></h3>
<p>This is a breaking change. See <a href="approved/0047-assignment-of-availability-chunks.html#upgrade-path">upgrade path</a> section above.
All validators and collators need to have upgraded their node versions before the feature will be enabled via a
governance call.</p>
<h2 id="prior-art-and-references-30"><a class="header" href="#prior-art-and-references-30">Prior Art and References</a></h2>
<p>See comments on the <a href="https://github.com/paritytech/polkadot-sdk/issues/598">tracking issue</a> and the
<a href="https://github.com/paritytech/polkadot-sdk/pull/1644">in-progress PR</a></p>
<h2 id="unresolved-questions-28"><a class="header" href="#unresolved-questions-28">Unresolved Questions</a></h2>
<p>Not applicable.</p>
<h2 id="future-directions-and-related-material-22"><a class="header" href="#future-directions-and-related-material-22">Future Directions and Related Material</a></h2>
<p>This enables future optimisations for the performance of availability recovery, such as retrieving batched systematic
chunks from backers/approval-checkers.</p>
<h2 id="appendix-a"><a class="header" href="#appendix-a">Appendix A</a></h2>
<p>This appendix details the intricacies of getting access to the core index of a candidate in parity's polkadot node.</p>
<p>Here, <code>core_index</code> refers to the index of the core that a candidate was occupying while it was pending availability
(from backing to inclusion).</p>
<p>Availability-recovery can currently be triggered by the following phases in the polkadot protocol:</p>
<ol>
<li>During the approval voting process.</li>
<li>By other collators of the same parachain.</li>
<li>During disputes.</li>
</ol>
<p>Getting the right core index for a candidate can be troublesome. Here's a breakdown of how different parts of the
node implementation can get access to it:</p>
<ol>
<li>
<p>The approval-voting process for a candidate begins after observing that the candidate was included. Therefore, the
node has easy access to the block where the candidate got included (and also the core that it occupied).</p>
</li>
<li>
<p>The <code>pov_recovery</code> task of the collators starts availability recovery in response to noticing a candidate getting
backed, which enables easy access to the core index the candidate started occupying.</p>
</li>
<li>
<p>Disputes may be initiated on a number of occasions:</p>
<p>3.a. is initiated by the validator as a result of finding an invalid candidate while participating in the
approval-voting protocol. In this case, availability-recovery is not needed, since the validator already issued their
vote.</p>
<p>3.b is initiated by the validator noticing dispute votes recorded on-chain. In this case, we can safely
assume that the backing event for that candidate has been recorded and kept in memory.</p>
<p>3.c is initiated as a result of getting a dispute statement from another validator. It is possible that the dispute
is happening on a fork that was not yet imported by this validator, so the subsystem may not have seen this candidate
being backed.</p>
</li>
</ol>
<p>A naive attempt of solving 3.c would be to add a new version for the disputes request-response networking protocol.
Blindly passing the core index in the network payload would not work, since there is no way of validating that
the reported core_index was indeed the one occupied by the candidate at the respective relay parent.</p>
<p>Another attempt could be to include in the message the relay block hash where the candidate was included.
This information would be used in order to query the runtime API and retrieve the core index that the candidate was
occupying. However, considering it's part of an unimported fork, the validator cannot call a runtime API on that block.</p>
<p>Adding the <code>core_index</code> to the <code>CandidateReceipt</code> would solve this problem and would enable systematic recovery for all
dispute scenarios.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0048-session-keys-runtime-api.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0048-session-keys-runtime-api.html#rfc-0048-generate-ownership-proof-for-sessionkeys">RFC-0048: Generate ownership proof for <code>SessionKeys</code></a>
<ul>
<li><a href="approved/0048-session-keys-runtime-api.html#summary">Summary</a></li>
<li><a href="approved/0048-session-keys-runtime-api.html#motivation">Motivation</a></li>
<li><a href="approved/0048-session-keys-runtime-api.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0048-session-keys-runtime-api.html#explanation">Explanation</a></li>
<li><a href="approved/0048-session-keys-runtime-api.html#drawbacks">Drawbacks</a></li>
<li><a href="approved/0048-session-keys-runtime-api.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="approved/0048-session-keys-runtime-api.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="approved/0048-session-keys-runtime-api.html#performance">Performance</a></li>
<li><a href="approved/0048-session-keys-runtime-api.html#ergonomics">Ergonomics</a></li>
<li><a href="approved/0048-session-keys-runtime-api.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="approved/0048-session-keys-runtime-api.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="approved/0048-session-keys-runtime-api.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="approved/0048-session-keys-runtime-api.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0048-generate-ownership-proof-for-sessionkeys"><a class="header" href="#rfc-0048-generate-ownership-proof-for-sessionkeys">RFC-0048: Generate ownership proof for <code>SessionKeys</code></a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>13 November 2023</td></tr>
<tr><td><strong>Description</strong></td><td>Change <code>SessionKeys</code> runtime api to support generating an ownership proof for the on chain registration.</td></tr>
<tr><td><strong>Authors</strong></td><td>Bastian Köcher</td></tr>
</tbody></table>
</div>
<h2 id="summary-35"><a class="header" href="#summary-35">Summary</a></h2>
<p>This RFC proposes to changes the <code>SessionKeys::generate_session_keys</code> runtime api interface. This runtime api is used by validator operators to
generate new session keys on a node. The public session keys are then registered manually on chain by the validator operator.
Before this RFC it was not possible by the on chain logic to ensure that the account setting the public session keys is also in
possession of the private session keys. To solve this the RFC proposes to pass the account id of the account doing the
registration on chain to <code>generate_session_keys</code>. Further this RFC proposes to change the return value of the <code>generate_session_keys</code>
function also to not only return the public session keys, but also the proof of ownership for the private session keys. The
validator operator will then need to send the public session keys and the proof together when registering new session keys on chain.</p>
<h2 id="motivation-35"><a class="header" href="#motivation-35">Motivation</a></h2>
<p>When submitting the new public session keys to the on chain logic there doesn't exist any verification of possession of the private session keys.
This means that users can basically register any kind of public session keys on chain. While the on chain logic ensures that there are
no duplicate keys, someone could try to prevent others from registering new session keys by setting them first. While this wouldn't bring
the &quot;attacker&quot; any kind of advantage, more like disadvantages (potential slashes on their account), it could prevent someone from
e.g. changing its session key in the event of a private session key leak.</p>
<p>After this RFC this kind of attack would not be possible anymore, because the on chain logic can verify that the sending account
is in ownership of the private session keys.</p>
<h2 id="stakeholders-34"><a class="header" href="#stakeholders-34">Stakeholders</a></h2>
<ul>
<li>Polkadot runtime implementors</li>
<li>Polkadot node implementors</li>
<li>Validator operators</li>
</ul>
<h2 id="explanation-34"><a class="header" href="#explanation-34">Explanation</a></h2>
<p>We are first going to explain the <code>proof</code> format being used:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>type Proof = (Signature, Signature, ..);
<span class="boring">}</span></code></pre></pre>
<p>The <code>proof</code> being a SCALE encoded tuple over all signatures of each private session
key signing the <code>account_id</code>. The actual type of each signature depends on the
corresponding session key cryptographic algorithm. The order of the signatures in
the <code>proof</code> is the same as the order of the session keys in the <code>SessionKeys</code> type
declared in the runtime.</p>
<p>The version of the <code>SessionKeys</code> needs to be bumped to <code>1</code> to reflect the changes to the
signature of <code>SessionKeys_generate_session_keys</code>:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>pub struct OpaqueGeneratedSessionKeys {
pub keys: Vec&lt;u8&gt;,
pub proof: Vec&lt;u8&gt;,
}
fn SessionKeys_generate_session_keys(account_id: Vec&lt;u8&gt;, seed: Option&lt;Vec&lt;u8&gt;&gt;) -&gt; OpaqueGeneratedSessionKeys;
<span class="boring">}</span></code></pre></pre>
<p>The default calling convention for runtime apis is applied, meaning the parameters
passed as SCALE encoded array and the length of the encoded array. The return value
being the SCALE encoded return value as <code>u64</code> (<code>array_ptr | length &lt;&lt; 32</code>). So, the
actual exported function signature looks like:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>fn SessionKeys_generate_session_keys(array: *const u8, len: usize) -&gt; u64;
<span class="boring">}</span></code></pre></pre>
<p>The on chain logic for setting the <code>SessionKeys</code> needs to be changed as well. It
already gets the <code>proof</code> passed as <code>Vec&lt;u8&gt;</code>. This <code>proof</code> needs to be decoded to
the actual <code>Proof</code> type as explained above. The <code>proof</code> and the SCALE encoded
<code>account_id</code> of the sender are used to verify the ownership of the <code>SessionKeys</code>.</p>
<h2 id="drawbacks-31"><a class="header" href="#drawbacks-31">Drawbacks</a></h2>
<p>Validator operators need to pass the their account id when rotating their session keys in a node.
This will require updating some high level docs and making users familiar with the slightly changed ergonomics.</p>
<h2 id="testing-security-and-privacy-30"><a class="header" href="#testing-security-and-privacy-30">Testing, Security, and Privacy</a></h2>
<p>Testing of the new changes only requires passing an appropriate <code>owner</code> for the current testing context.
The changes to the proof generation and verification got audited to ensure they are correct.</p>
<h2 id="performance-ergonomics-and-compatibility-30"><a class="header" href="#performance-ergonomics-and-compatibility-30">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-27"><a class="header" href="#performance-27">Performance</a></h3>
<p>The session key generation is an offchain process and thus, doesn't influence the performance of the
chain. Verifying the proof is done on chain as part of the transaction logic for setting the session keys.
The verification of the proof is a signature verification number of individual session keys times. As setting
the session keys is happening quite rarely, it should not influence the overall system performance.</p>
<h3 id="ergonomics-24"><a class="header" href="#ergonomics-24">Ergonomics</a></h3>
<p>The interfaces have been optimized to make it as easy as possible to generate the ownership proof.</p>
<h3 id="compatibility-24"><a class="header" href="#compatibility-24">Compatibility</a></h3>
<p>Introduces a new version of the <code>SessionKeys</code> runtime api. Thus, nodes should be updated before
a runtime is enacted that contains these changes otherwise they will fail to generate session keys.
The RPC that exists around this runtime api needs to be updated to support passing the account id
and for returning the ownership proof alongside the public session keys.</p>
<p>UIs would need to be updated to support the new RPC and the changed on chain logic.</p>
<h2 id="prior-art-and-references-31"><a class="header" href="#prior-art-and-references-31">Prior Art and References</a></h2>
<p>None.</p>
<h2 id="unresolved-questions-29"><a class="header" href="#unresolved-questions-29">Unresolved Questions</a></h2>
<p>None.</p>
<h2 id="future-directions-and-related-material-23"><a class="header" href="#future-directions-and-related-material-23">Future Directions and Related Material</a></h2>
<p>Substrate implementation of the <a href="https://github.com/paritytech/polkadot-sdk/pull/1739">RFC</a>.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0050-fellowship-salaries.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0050-fellowship-salaries.html#rfc-0050-fellowship-salaries">RFC-0050: Fellowship Salaries</a>
<ul>
<li><a href="approved/0050-fellowship-salaries.html#summary">Summary</a></li>
<li><a href="approved/0050-fellowship-salaries.html#motivation">Motivation</a></li>
<li><a href="approved/0050-fellowship-salaries.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0050-fellowship-salaries.html#explanation">Explanation</a>
<ul>
<li><a href="approved/0050-fellowship-salaries.html#salary-asset">Salary Asset</a></li>
<li><a href="approved/0050-fellowship-salaries.html#projections">Projections</a></li>
<li><a href="approved/0050-fellowship-salaries.html#updates">Updates</a></li>
</ul>
</li>
<li><a href="approved/0050-fellowship-salaries.html#drawbacks">Drawbacks</a></li>
<li><a href="approved/0050-fellowship-salaries.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="approved/0050-fellowship-salaries.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="approved/0050-fellowship-salaries.html#performance">Performance</a></li>
<li><a href="approved/0050-fellowship-salaries.html#ergonomics">Ergonomics</a></li>
<li><a href="approved/0050-fellowship-salaries.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="approved/0050-fellowship-salaries.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="approved/0050-fellowship-salaries.html#unresolved-questions">Unresolved Questions</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0050-fellowship-salaries"><a class="header" href="#rfc-0050-fellowship-salaries">RFC-0050: Fellowship Salaries</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>15 November 2023</td></tr>
<tr><td><strong>Description</strong></td><td>Proposal to set rank-based Fellowship salary levels.</td></tr>
<tr><td><strong>Authors</strong></td><td>Joe Petrowski, Gavin Wood</td></tr>
</tbody></table>
</div>
<h2 id="summary-36"><a class="header" href="#summary-36">Summary</a></h2>
<p>The Fellowship Manifesto states that members should receive a monthly allowance on par with gross
income in OECD countries. This RFC proposes concrete amounts.</p>
<h2 id="motivation-36"><a class="header" href="#motivation-36">Motivation</a></h2>
<p>One motivation for the Technical Fellowship is to provide an incentive mechanism that can induct and
retain technical talent for the continued progress of the network.</p>
<p>In order for members to uphold their commitment to the network, they should receive support to
ensure that their needs are met such that they have the time to dedicate to their work on Polkadot.
Given the high expectations of Fellows, it is reasonable to consider contributions and requirements
on par with a full-time job. Providing a livable wage to those making such contributions makes it
pragmatic to work full-time on Polkadot.</p>
<p>Note: Goals of the Fellowship, expectations for each Dan, and conditions for promotion and demotion
are all explained in the Manifesto. This RFC is only to propose concrete values for allowances.</p>
<h2 id="stakeholders-35"><a class="header" href="#stakeholders-35">Stakeholders</a></h2>
<ul>
<li>Fellowship members</li>
<li>Polkadot Treasury</li>
</ul>
<h2 id="explanation-35"><a class="header" href="#explanation-35">Explanation</a></h2>
<p>This RFC proposes agreeing on salaries relative to a single level, the III Dan. As such, changes to
the amount or asset used would only be on a single value, and all others would adjust relatively. A
III Dan is someone whose contributions match the expectations of a full-time individual contributor.
The salary at this level should be reasonably close to averages in OECD countries.</p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: center">Dan</th><th style="text-align: center">Factor</th></tr></thead><tbody>
<tr><td style="text-align: center">I</td><td style="text-align: center">0.125</td></tr>
<tr><td style="text-align: center">II</td><td style="text-align: center">0.25</td></tr>
<tr><td style="text-align: center">III</td><td style="text-align: center">1</td></tr>
<tr><td style="text-align: center">IV</td><td style="text-align: center">1.5</td></tr>
<tr><td style="text-align: center">V</td><td style="text-align: center">2.0</td></tr>
<tr><td style="text-align: center">VI</td><td style="text-align: center">2.5</td></tr>
<tr><td style="text-align: center">VII</td><td style="text-align: center">2.5</td></tr>
<tr><td style="text-align: center">VIII</td><td style="text-align: center">2.5</td></tr>
<tr><td style="text-align: center">IX</td><td style="text-align: center">2.5</td></tr>
</tbody></table>
</div>
<p>Note that there is a sizable increase between II Dan (Proficient) and III Dan (Fellow). By the third
Dan, it is generally expected that one is working on Polkadot as their primary focus in a full-time
capacity.</p>
<h3 id="salary-asset"><a class="header" href="#salary-asset">Salary Asset</a></h3>
<p>Although the Manifesto (Section 8) specifies a monthly allowance in DOT, this RFC proposes the use
of USDT instead. The allowance is meant to provide members stability in meeting their day-to-day
needs and recognize contributions. Using USDT provides more stability and less speculation.</p>
<p>This RFC proposes that a III Dan earn 80,000 USDT per year. The salary at this level is commensurate
with average salaries in OECD countries (note: 77,000 USD in the U.S., with an average engineer at
100,000 USD). The other ranks would thus earn:</p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: center">Dan</th><th style="text-align: center">Annual Salary</th></tr></thead><tbody>
<tr><td style="text-align: center">I</td><td style="text-align: center">10,000</td></tr>
<tr><td style="text-align: center">II</td><td style="text-align: center">20,000</td></tr>
<tr><td style="text-align: center">III</td><td style="text-align: center">80,000</td></tr>
<tr><td style="text-align: center">IV</td><td style="text-align: center">120,000</td></tr>
<tr><td style="text-align: center">V</td><td style="text-align: center">160,000</td></tr>
<tr><td style="text-align: center">VI</td><td style="text-align: center">200,000</td></tr>
<tr><td style="text-align: center">VII</td><td style="text-align: center">200,000</td></tr>
<tr><td style="text-align: center">VIII</td><td style="text-align: center">200,000</td></tr>
<tr><td style="text-align: center">IX</td><td style="text-align: center">200,000</td></tr>
</tbody></table>
</div>
<p>The salary levels for Architects (IV, V, and VI Dan) are typical of senior engineers.</p>
<p>Allowances will be managed by the Salary pallet.</p>
<h3 id="projections"><a class="header" href="#projections">Projections</a></h3>
<p>Based on the current membership, the maximum yearly and monthly costs are shown below:</p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: center">Dan</th><th style="text-align: center">Salary</th><th style="text-align: center">Members</th><th style="text-align: right">Yearly</th><th style="text-align: right">Monthly</th></tr></thead><tbody>
<tr><td style="text-align: center">I</td><td style="text-align: center">10,000</td><td style="text-align: center">27</td><td style="text-align: right">270,000</td><td style="text-align: right">22,500</td></tr>
<tr><td style="text-align: center">II</td><td style="text-align: center">20,000</td><td style="text-align: center">11</td><td style="text-align: right">220,000</td><td style="text-align: right">18,333</td></tr>
<tr><td style="text-align: center">III</td><td style="text-align: center">80,000</td><td style="text-align: center">8</td><td style="text-align: right">640,000</td><td style="text-align: right">53,333</td></tr>
<tr><td style="text-align: center">IV</td><td style="text-align: center">120,000</td><td style="text-align: center">3</td><td style="text-align: right">360,000</td><td style="text-align: right">30,000</td></tr>
<tr><td style="text-align: center">V</td><td style="text-align: center">160,000</td><td style="text-align: center">5</td><td style="text-align: right">800,000</td><td style="text-align: right">66,667</td></tr>
<tr><td style="text-align: center">VI</td><td style="text-align: center">200,000</td><td style="text-align: center">3</td><td style="text-align: right">600,000</td><td style="text-align: right">50,000</td></tr>
<tr><td style="text-align: center">&gt; VI</td><td style="text-align: center">200,000</td><td style="text-align: center">0</td><td style="text-align: right">0</td><td style="text-align: right">0</td></tr>
<tr><td style="text-align: center"></td><td style="text-align: center"></td><td style="text-align: center"></td><td style="text-align: right"></td><td style="text-align: right"></td></tr>
<tr><td style="text-align: center">Total</td><td style="text-align: center"></td><td style="text-align: center"></td><td style="text-align: right">2,890,000</td><td style="text-align: right">240,833</td></tr>
</tbody></table>
</div>
<p>Note that these are the maximum amounts; members may choose to take a passive (lower) level. On the
other hand, more people will likely join the Fellowship in the coming years.</p>
<h3 id="updates"><a class="header" href="#updates">Updates</a></h3>
<p>Updates to these levels, whether relative ratios, the asset used, or the amount, shall be done via
RFC.</p>
<h2 id="drawbacks-32"><a class="header" href="#drawbacks-32">Drawbacks</a></h2>
<p>By not using DOT for payment, the protocol relies on the stability of other assets and the ability
to acquire them. However, the asset of choice can be changed in the future.</p>
<h2 id="testing-security-and-privacy-31"><a class="header" href="#testing-security-and-privacy-31">Testing, Security, and Privacy</a></h2>
<p>N/A.</p>
<h2 id="performance-ergonomics-and-compatibility-31"><a class="header" href="#performance-ergonomics-and-compatibility-31">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-28"><a class="header" href="#performance-28">Performance</a></h3>
<p>N/A</p>
<h3 id="ergonomics-25"><a class="header" href="#ergonomics-25">Ergonomics</a></h3>
<p>N/A</p>
<h3 id="compatibility-25"><a class="header" href="#compatibility-25">Compatibility</a></h3>
<p>N/A</p>
<h2 id="prior-art-and-references-32"><a class="header" href="#prior-art-and-references-32">Prior Art and References</a></h2>
<ul>
<li><a href="https://github.com/polkadot-fellows/manifesto/blob/5e01eef15eded63f1db9be808b0f7c11bb9f4a12/manifesto.pdf">The Polkadot Fellowship
Manifesto</a></li>
<li><a href="https://data.oecd.org/earnwage/average-wages.htm#indicator-chart">OECD Average Wages</a></li>
<li><a href="https://www.indeed.com/career/engineer/salaries">Indeed: Average Salary for Engineers, United
States</a></li>
</ul>
<h2 id="unresolved-questions-30"><a class="header" href="#unresolved-questions-30">Unresolved Questions</a></h2>
<p>None at present.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0056-one-transaction-per-notification.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0056-one-transaction-per-notification.html#rfc-0056-enforce-only-one-transaction-per-notification">RFC-0056: Enforce only one transaction per notification</a>
<ul>
<li><a href="approved/0056-one-transaction-per-notification.html#summary">Summary</a></li>
<li><a href="approved/0056-one-transaction-per-notification.html#motivation">Motivation</a></li>
<li><a href="approved/0056-one-transaction-per-notification.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0056-one-transaction-per-notification.html#explanation">Explanation</a></li>
<li><a href="approved/0056-one-transaction-per-notification.html#drawbacks">Drawbacks</a></li>
<li><a href="approved/0056-one-transaction-per-notification.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="approved/0056-one-transaction-per-notification.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="approved/0056-one-transaction-per-notification.html#performance">Performance</a></li>
<li><a href="approved/0056-one-transaction-per-notification.html#ergonomics">Ergonomics</a></li>
<li><a href="approved/0056-one-transaction-per-notification.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="approved/0056-one-transaction-per-notification.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="approved/0056-one-transaction-per-notification.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="approved/0056-one-transaction-per-notification.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0056-enforce-only-one-transaction-per-notification"><a class="header" href="#rfc-0056-enforce-only-one-transaction-per-notification">RFC-0056: Enforce only one transaction per notification</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>2023-11-30</td></tr>
<tr><td><strong>Description</strong></td><td>Modify the transactions notifications protocol to always send only one transaction at a time</td></tr>
<tr><td><strong>Authors</strong></td><td>Pierre Krieger</td></tr>
</tbody></table>
</div>
<h2 id="summary-37"><a class="header" href="#summary-37">Summary</a></h2>
<p>When two peers connect to each other, they open (amongst other things) a so-called &quot;notifications protocol&quot; substream dedicated to gossiping transactions to each other.</p>
<p>Each notification on this substream currently consists in a SCALE-encoded <code>Vec&lt;Transaction&gt;</code> where <code>Transaction</code> is defined in the runtime.</p>
<p>This RFC proposes to modify the format of the notification to become <code>(Compact(1), Transaction)</code>. This maintains backwards compatibility, as this new format decodes as a <code>Vec</code> of length equal to 1.</p>
<h2 id="motivation-37"><a class="header" href="#motivation-37">Motivation</a></h2>
<p>There exists three motivations behind this change:</p>
<ul>
<li>
<p>It is technically impossible to decode a SCALE-encoded <code>Vec&lt;Transaction&gt;</code> into a list of SCALE-encoded transactions without knowing how to decode a <code>Transaction</code>. That's because a <code>Vec&lt;Transaction&gt;</code> consists in several <code>Transaction</code>s one after the other in memory, without any delimiter that indicates the end of a transaction and the start of the next. Unfortunately, the format of a <code>Transaction</code> is runtime-specific. This means that the code that receives notifications is necessarily tied to a specific runtime, and it is not possible to write runtime-agnostic code.</p>
</li>
<li>
<p>Notifications protocols are already designed to be optimized to send many items. Currently, when it comes to transactions, each item is a <code>Vec&lt;Transaction&gt;</code> that consists in multiple sub-items of type <code>Transaction</code>. This two-steps hierarchy is completely unnecessary, and was originally written at a time when the networking protocol of Substrate didn't have proper multiplexing.</p>
</li>
<li>
<p>It makes the implementation way more straight-forward by not having to repeat code related to back-pressure. See explanations below.</p>
</li>
</ul>
<h2 id="stakeholders-36"><a class="header" href="#stakeholders-36">Stakeholders</a></h2>
<p>Low-level developers.</p>
<h2 id="explanation-36"><a class="header" href="#explanation-36">Explanation</a></h2>
<p>To give an example, if you send one notification with three transactions, the bytes that are sent on the wire are:</p>
<pre><code>concat(
leb128(total-size-in-bytes-of-the-rest),
scale(compact(3)), scale(transaction1), scale(transaction2), scale(transaction3)
)
</code></pre>
<p>But you can also send three notifications of one transaction each, in which case it is:</p>
<pre><code>concat(
leb128(size(scale(transaction1)) + 1), scale(compact(1)), scale(transaction1),
leb128(size(scale(transaction2)) + 1), scale(compact(1)), scale(transaction2),
leb128(size(scale(transaction3)) + 1), scale(compact(1)), scale(transaction3)
)
</code></pre>
<p>Right now the sender can choose which of the two encoding to use. This RFC proposes to make the second encoding mandatory.</p>
<p>The format of the notification would become a SCALE-encoded <code>(Compact(1), Transaction)</code>.
A SCALE-compact encoded <code>1</code> is one byte of value <code>4</code>. In other words, the format of the notification would become <code>concat(&amp;[4], scale_encoded_transaction)</code>.
This is equivalent to forcing the <code>Vec&lt;Transaction&gt;</code> to always have a length of 1, and I expect the Substrate implementation to simply modify the sending side to add a <code>for</code> loop that sends one notification per item in the <code>Vec</code>.</p>
<p>As explained in the motivation section, this allows extracting <code>scale(transaction)</code> items without having to know how to decode them.</p>
<p>By &quot;flattening&quot; the two-steps hierarchy, an implementation only needs to back-pressure individual notifications rather than back-pressure notifications and transactions within notifications.</p>
<h2 id="drawbacks-33"><a class="header" href="#drawbacks-33">Drawbacks</a></h2>
<p>This RFC chooses to maintain backwards compatibility at the cost of introducing a very small wart (the <code>Compact(1)</code>).</p>
<p>An alternative could be to introduce a new version of the transactions notifications protocol that sends one <code>Transaction</code> per notification, but this is significantly more complicated to implement and can always be done later in case the <code>Compact(1)</code> is bothersome.</p>
<h2 id="testing-security-and-privacy-32"><a class="header" href="#testing-security-and-privacy-32">Testing, Security, and Privacy</a></h2>
<p>Irrelevant.</p>
<h2 id="performance-ergonomics-and-compatibility-32"><a class="header" href="#performance-ergonomics-and-compatibility-32">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-29"><a class="header" href="#performance-29">Performance</a></h3>
<p>Irrelevant.</p>
<h3 id="ergonomics-26"><a class="header" href="#ergonomics-26">Ergonomics</a></h3>
<p>Irrelevant.</p>
<h3 id="compatibility-26"><a class="header" href="#compatibility-26">Compatibility</a></h3>
<p>The change is backwards compatible if done in two steps: modify the sender to always send one transaction per notification, then, after a while, modify the receiver to enforce the new format.</p>
<h2 id="prior-art-and-references-33"><a class="header" href="#prior-art-and-references-33">Prior Art and References</a></h2>
<p>Irrelevant.</p>
<h2 id="unresolved-questions-31"><a class="header" href="#unresolved-questions-31">Unresolved Questions</a></h2>
<p>None.</p>
<h2 id="future-directions-and-related-material-24"><a class="header" href="#future-directions-and-related-material-24">Future Directions and Related Material</a></h2>
<p>None. This is a simple isolated change.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0059-nodes-capabilities-discovery.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0059-nodes-capabilities-discovery.html#rfc-0059-add-a-discovery-mechanism-for-nodes-based-on-their-capabilities">RFC-0059: Add a discovery mechanism for nodes based on their capabilities</a>
<ul>
<li><a href="approved/0059-nodes-capabilities-discovery.html#summary">Summary</a></li>
<li><a href="approved/0059-nodes-capabilities-discovery.html#motivation">Motivation</a></li>
<li><a href="approved/0059-nodes-capabilities-discovery.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0059-nodes-capabilities-discovery.html#explanation">Explanation</a>
<ul>
<li><a href="approved/0059-nodes-capabilities-discovery.html#capabilities">Capabilities</a></li>
<li><a href="approved/0059-nodes-capabilities-discovery.html#dht-provider-registration">DHT provider registration</a></li>
<li><a href="approved/0059-nodes-capabilities-discovery.html#secondary-dhts">Secondary DHTs</a></li>
<li><a href="approved/0059-nodes-capabilities-discovery.html#head-of-the-chain-providers">Head of the chain providers</a></li>
</ul>
</li>
<li><a href="approved/0059-nodes-capabilities-discovery.html#drawbacks">Drawbacks</a></li>
<li><a href="approved/0059-nodes-capabilities-discovery.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="approved/0059-nodes-capabilities-discovery.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="approved/0059-nodes-capabilities-discovery.html#performance">Performance</a></li>
<li><a href="approved/0059-nodes-capabilities-discovery.html#ergonomics">Ergonomics</a></li>
<li><a href="approved/0059-nodes-capabilities-discovery.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="approved/0059-nodes-capabilities-discovery.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="approved/0059-nodes-capabilities-discovery.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="approved/0059-nodes-capabilities-discovery.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0059-add-a-discovery-mechanism-for-nodes-based-on-their-capabilities"><a class="header" href="#rfc-0059-add-a-discovery-mechanism-for-nodes-based-on-their-capabilities">RFC-0059: Add a discovery mechanism for nodes based on their capabilities</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>2023-12-18</td></tr>
<tr><td><strong>Description</strong></td><td>Nodes having certain capabilities register themselves in the DHT to be discoverable</td></tr>
<tr><td><strong>Authors</strong></td><td>Pierre Krieger</td></tr>
</tbody></table>
</div>
<h2 id="summary-38"><a class="header" href="#summary-38">Summary</a></h2>
<p>This RFC proposes to make the mechanism of <a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0008-parachain-bootnodes-dht.md">RFC #8</a> more generic by introducing the concept of &quot;capabilities&quot;.</p>
<p>Implementations can implement certain &quot;capabilities&quot;, such as serving old block headers or being a parachain bootnode.</p>
<p>The discovery mechanism of RFC #8 is extended to be able to discover nodes of specific capabilities.</p>
<h2 id="motivation-38"><a class="header" href="#motivation-38">Motivation</a></h2>
<p>The Polkadot peer-to-peer network is made of nodes. Not all these nodes are equal. Some nodes store only the headers of recent blocks, some nodes store all the block headers and bodies since the genesis, some nodes store the storage of all blocks since the genesis, and so on.</p>
<p>It is currently not possible to know ahead of time (without connecting to it and asking) which nodes have which data available, and it is not easily possible to build a list of nodes that have a specific piece of data available.</p>
<p>If you want to download for example the header of block 500, you have to connect to a randomly-chosen node, ask it for block 500, and if it says that it doesn't have the block, disconnect and try another randomly-chosen node.
In certain situations such as downloading the storage of old blocks, nodes that have the information are relatively rare, and finding through trial and error a node that has the data can take a long time.</p>
<p>This RFC attempts to solve this problem by giving the possibility to build a list of nodes that are capable of serving specific data.</p>
<h2 id="stakeholders-37"><a class="header" href="#stakeholders-37">Stakeholders</a></h2>
<p>Low-level client developers.
People interested in accessing the archive of the chain.</p>
<h2 id="explanation-37"><a class="header" href="#explanation-37">Explanation</a></h2>
<p><em>Reading RFC #8 first might help with comprehension, as this RFC is very similar.</em></p>
<p>Please keep in mind while reading that everything below applies for both relay chains and parachains, except mentioned otherwise.</p>
<h3 id="capabilities"><a class="header" href="#capabilities">Capabilities</a></h3>
<p>This RFC defines a list of so-called <strong>capabilities</strong>:</p>
<ul>
<li><strong>Head of chain provider</strong>. An implementation with this capability must be able to serve to other nodes block headers, block bodies, justifications, calls proofs, and storage proofs of &quot;recent&quot; (see below) blocks, and, for relay chains, to serve to other nodes warp sync proofs where the starting block is a session change block and must participate in Grandpa and Beefy gossip.</li>
<li><strong>History provider</strong>. An implementation with this capability must be able to serve to other nodes block headers and block bodies of any block since the genesis, and must be able to serve to other nodes justifications of any session change block since the genesis up until and including their currently finalized block.</li>
<li><strong>Archive provider</strong>. This capability is a superset of <strong>History provider</strong>. In addition to the requirements of <strong>History provider</strong>, an implementation with this capability must be able to serve call proofs and storage proof requests of any block since the genesis up until and including their currently finalized block.</li>
<li><strong>Parachain bootnode</strong> (only for relay chains). An implementation with this capability must be able to serve the network request described in RFC 8.</li>
</ul>
<p>More capabilities might be added in the future.</p>
<p>In the context of the <em>head of chain provider</em>, the word &quot;recent&quot; means: any not-finalized-yet block that is equal to or an ancestor of a block that it has announced through a block announce, and any finalized block whose height is superior to its current finalized block minus <strong>16</strong>.
This does <em>not</em> include blocks that have been pruned because they're not a descendant of its current finalized block. In other words, blocks that aren't a descendant of the current finalized block can be thrown away.
A gap of blocks is required due to race conditions: when a node finalizes a block, it takes some time for its peers to be made aware of this, during which they might send requests concerning older blocks. The choice of the number of blocks in this gap is arbitrary.</p>
<p>Substrate is currently by default a <strong>head of chain provider</strong> provider. After it has finished warp syncing, it downloads the list of old blocks, after which it becomes a <strong>history provider</strong>.
If Substrate is instead configured as an archive node, then it downloads all blocks since the genesis and builds their state, after which it becomes an <strong>archive provider</strong>, <strong>history provider</strong>, and <strong>head of chain provider</strong>.
If blocks pruning is enabled and the chain is a relay chain, then Substrate unfortunately doesn't implement any of these capabilities, not even <strong>head of chain provider</strong>. This is considered as a bug that should be fixed, see <a href="https://github.com/paritytech/polkadot-sdk/issues/2733">https://github.com/paritytech/polkadot-sdk/issues/2733</a>.</p>
<h3 id="dht-provider-registration-1"><a class="header" href="#dht-provider-registration-1">DHT provider registration</a></h3>
<p>This RFC heavily relies on the functionalities of the Kademlia DHT already in use by Polkadot. You can find a link to the specification <a href="https://github.com/libp2p/specs/tree/master/kad-dht">here</a>.</p>
<p>Implementations that have the <strong>history provider</strong> capability should register themselves as providers under the key <code>sha256(concat(&quot;history&quot;, randomness))</code>.</p>
<p>Implementations that have the <strong>archive provider</strong> capability should register themselves as providers under the key <code>sha256(concat(&quot;archive&quot;, randomness))</code>.</p>
<p>Implementations that have the <strong>parachain bootnode</strong> capability should register themselves as provider under the key <code>sha256(concat(scale_compact(para_id), randomness))</code>, as described in RFC 8.</p>
<p>&quot;Register themselves as providers&quot; consists in sending <code>ADD_PROVIDER</code> requests to nodes close to the key, as described in <a href="https://github.com/libp2p/specs/tree/master/kad-dht#content-provider-advertisement">the <code>Content provider advertisement</code> section</a> of the specification.</p>
<p>The value of <code>randomness</code> can be found in the <code>randomness</code> field when calling the <code>BabeApi_currentEpoch</code> function.</p>
<p>In order to avoid downtimes when the key changes, nodes should also register themselves as a secondary key that uses a value of <code>randomness</code> equal to the <code>randomness</code> field when calling <code>BabeApi_nextEpoch</code>.</p>
<p>Implementers should be aware that their implementation of Kademlia might already hash the key before XOR'ing it. The key is not meant to be hashed twice.</p>
<p>Implementations must not register themselves if they don't fulfill the capability <em>yet</em>. For example, a node configured to be an archive node but that is still building its archive state in the background must register itself only after it has finished building its archive.</p>
<h3 id="secondary-dhts"><a class="header" href="#secondary-dhts">Secondary DHTs</a></h3>
<p>Implementations that have the <strong>history provider</strong> capability must also participate in a secondary DHT that comprises only of nodes with that capability. The protocol name of that secondary DHT must be <code>/&lt;genesis-hash&gt;/kad/history</code>.</p>
<p>Similarly, implementations that have the <strong>archive provider</strong> capability must also participate in a secondary DHT that comprises only of nodes with that capability and whose protocol name is <code>/&lt;genesis-hash&gt;/kad/archive</code>.</p>
<p>Just like implementations must not register themselves if they don't fulfill their capability yet, they must also not participate in the secondary DHT if they don't fulfill their capability yet.</p>
<h3 id="head-of-the-chain-providers"><a class="header" href="#head-of-the-chain-providers">Head of the chain providers</a></h3>
<p>Implementations that have the <strong>head of the chain provider</strong> capability do not register themselves as providers, but instead are the nodes that participate in the main DHT. In other words, they are the nodes that serve requests of the <code>/&lt;genesis_hash&gt;/kad</code> protocol.</p>
<p>Any implementation that isn't a head of the chain provider (read: light clients) must not participate in the main DHT. This is already presently the case.</p>
<p>Implementations must not participate in the main DHT if they don't fulfill the capability yet. For example, a node that is still in the process of warp syncing must not participate in the main DHT. However, assuming that warp syncing doesn't last more than a few seconds, it is acceptable to ignore this requirement in order to avoid complicating implementations too much.</p>
<h2 id="drawbacks-34"><a class="header" href="#drawbacks-34">Drawbacks</a></h2>
<p>None that I can see.</p>
<h2 id="testing-security-and-privacy-33"><a class="header" href="#testing-security-and-privacy-33">Testing, Security, and Privacy</a></h2>
<p><em>The content of this section is basically the same as the one in RFC 8.</em></p>
<p>This mechanism doesn't add or remove any security by itself, as it relies on existing mechanisms.</p>
<p>Due to the way Kademlia works, it would become the responsibility of the 20 Polkadot nodes whose <code>sha256(peer_id)</code> is closest to the <code>key</code> (described in the explanations section) to store the list of nodes that have specific capabilities.
Furthermore, when a large number of providers are registered, only the providers closest to the <code>key</code> are kept, up to a certain implementation-defined limit.</p>
<p>For this reason, an attacker can abuse this mechanism by randomly generating libp2p PeerIds until they find the 20 entries closest to the <code>key</code> representing the target capability. They are then in control of the list of nodes with that capability. While doing this can in no way be actually harmful, it could lead to eclipse attacks.</p>
<p>Because the key changes periodically and isn't predictable, and assuming that the Polkadot DHT is sufficiently large, it is not realistic for an attack like this to be maintained in the long term.</p>
<h2 id="performance-ergonomics-and-compatibility-33"><a class="header" href="#performance-ergonomics-and-compatibility-33">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-30"><a class="header" href="#performance-30">Performance</a></h3>
<p>The DHT mechanism generally has a low overhead, especially given that publishing providers is done only every 24 hours.</p>
<p>Doing a Kademlia iterative query then sending a provider record shouldn't take more than around 50 kiB in total of bandwidth for the parachain bootnode.</p>
<p>Assuming 1000 nodes with a specific capability, the 20 Polkadot full nodes corresponding to that capability will each receive a sudden spike of a few megabytes of networking traffic when the <code>key</code> rotates. Again, this is relatively negligible. If this becomes a problem, one can add a random delay before a node registers itself to be the provider of the <code>key</code> corresponding to <code>BabeApi_next_epoch</code>.</p>
<p>Maybe the biggest uncertainty is the traffic that the 20 Polkadot full nodes will receive from light clients that desire knowing the nodes with a capability. If this every becomes a problem, this value of 20 is an arbitrary constant that can be increased for more redundancy.</p>
<h3 id="ergonomics-27"><a class="header" href="#ergonomics-27">Ergonomics</a></h3>
<p>Irrelevant.</p>
<h3 id="compatibility-27"><a class="header" href="#compatibility-27">Compatibility</a></h3>
<p>Irrelevant.</p>
<h2 id="prior-art-and-references-34"><a class="header" href="#prior-art-and-references-34">Prior Art and References</a></h2>
<p>Unknown.</p>
<h2 id="unresolved-questions-32"><a class="header" href="#unresolved-questions-32">Unresolved Questions</a></h2>
<p>While it fundamentally doesn't change much to this RFC, using <code>BabeApi_currentEpoch</code> and <code>BabeApi_nextEpoch</code> might be inappropriate. I'm not familiar enough with good practices within the runtime to have an opinion here. Should it be an entirely new pallet?</p>
<h2 id="future-directions-and-related-material-25"><a class="header" href="#future-directions-and-related-material-25">Future Directions and Related Material</a></h2>
<p>This RFC would make it possible to reliably discover archive nodes, which would make it possible to reliably send archive node requests, something that isn't currently possible. This could solve the problem of finding archive RPC node providers by migrating archive-related request to using the native peer-to-peer protocol rather than JSON-RPC.</p>
<p>If we ever decide to break backwards compatibility, we could divide the &quot;history&quot; and &quot;archive&quot; capabilities in two, between nodes capable of serving older blocks and nodes capable of serving newer blocks.
We could even add to the peer-to-peer network nodes that are only capable of serving older blocks (by reading from a database) but do not participate in the head of the chain, and that just exist for historical purposes.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0078-merkleized-metadata.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0078-merkleized-metadata.html#rfc-0078-merkleized-metadata">RFC-0078: Merkleized Metadata</a>
<ul>
<li><a href="approved/0078-merkleized-metadata.html#summary">Summary</a></li>
<li><a href="approved/0078-merkleized-metadata.html#motivation">Motivation</a></li>
<li><a href="approved/0078-merkleized-metadata.html#requirements">Requirements</a>
<ul>
<li><a href="approved/0078-merkleized-metadata.html#reduce-metadata-size">Reduce metadata size</a></li>
</ul>
</li>
<li><a href="approved/0078-merkleized-metadata.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0078-merkleized-metadata.html#explanation">Explanation</a>
<ul>
<li><a href="approved/0078-merkleized-metadata.html#metadata-digest">Metadata digest</a></li>
<li><a href="approved/0078-merkleized-metadata.html#extrinsic-metadata">Extrinsic metadata</a></li>
<li><a href="approved/0078-merkleized-metadata.html#type-information">Type Information</a></li>
<li><a href="approved/0078-merkleized-metadata.html#prune-unrelated-types">Prune unrelated Types</a></li>
<li><a href="approved/0078-merkleized-metadata.html#generating-typeref">Generating <code>TypeRef</code></a></li>
<li><a href="approved/0078-merkleized-metadata.html#building-the-merkle-tree-root">Building the Merkle Tree Root</a></li>
<li><a href="approved/0078-merkleized-metadata.html#inclusion-in-an-extrinsic">Inclusion in an Extrinsic</a></li>
</ul>
</li>
<li><a href="approved/0078-merkleized-metadata.html#drawbacks">Drawbacks</a></li>
<li><a href="approved/0078-merkleized-metadata.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="approved/0078-merkleized-metadata.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="approved/0078-merkleized-metadata.html#performance">Performance</a></li>
<li><a href="approved/0078-merkleized-metadata.html#ergonomics--compatibility">Ergonomics &amp; Compatibility</a></li>
</ul>
</li>
<li><a href="approved/0078-merkleized-metadata.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="approved/0078-merkleized-metadata.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="approved/0078-merkleized-metadata.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0078-merkleized-metadata"><a class="header" href="#rfc-0078-merkleized-metadata">RFC-0078: Merkleized Metadata</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>22 February 2024</td></tr>
<tr><td><strong>Description</strong></td><td>Include merkleized metadata hash in extrinsic signature for trust-less metadata verification.</td></tr>
<tr><td><strong>Authors</strong></td><td>Zondax AG, Parity Technologies</td></tr>
</tbody></table>
</div>
<h2 id="summary-39"><a class="header" href="#summary-39">Summary</a></h2>
<p>To interact with chains in the Polkadot ecosystem it is required to know how transactions are encoded and how to read state. For doing this, Polkadot-SDK, the framework used by most of the chains in the Polkadot ecosystem, exposes metadata about the runtime to the outside. UIs, wallets, and others can use this metadata to interact with these chains. This makes the metadata a crucial piece of the transaction encoding as users are relying on the interacting software to encode the transactions in the correct format.</p>
<p>It gets even more important when the user signs the transaction in an offline wallet, as the device by its nature cannot get access to the metadata without relying on the online wallet to provide it. This makes it so that the offline wallet needs to <em>trust</em> an online party, deeming the security assumptions of the offline devices, mute. </p>
<p>This RFC proposes a way for offline wallets to leverage metadata, within the constraints of these. The design idea is that the metadata is chunked and these chunks are put into a merkle tree. The root hash of this merkle tree represents the metadata. The offline wallets can use the root hash to decode transactions by getting proofs for the individual chunks of the metadata. This root hash is also included in the signed data of the transaction (but not sent as part of the transaction). The runtime is then including its known metadata root hash when verifying the transaction. If the metadata root hash known by the runtime differs from the one that the offline wallet used, it very likely means that the online wallet provided some fake data and the verification of the transaction fails.</p>
<p>Users depend on offline wallets to correctly display decoded transactions before signing. With merkleized metadata, they can be assured of the transaction's legitimacy, as incorrect transactions will be rejected by the runtime.</p>
<h2 id="motivation-39"><a class="header" href="#motivation-39">Motivation</a></h2>
<p>Polkadot's innovative design (both relay chain and parachains) present the ability to developers to upgrade their network as frequently as they need. These systems manage to have integrations working after the upgrades with the help of FRAME Metadata. This Metadata, which is in the order of half a MiB for most Polkadot-SDK chains, completely describes chain interfaces and properties. Securing this metadata is key for users to be able to interact with the Polkadot-SDK chain in the expected way.</p>
<p>On the other hand, offline wallets provide a secure way for Blockchain users to hold their own keys (some do a better job than others). These devices seldomly get upgraded, usually account for one particular network and hold very small internal memories. Currently in the Polkadot ecosystem there is no secure way of having these offline devices know the latest Metadata of the Polkadot-SDK chain they are interacting with. This results in a plethora of similar yet slightly different offline wallets for all different Polkadot-SDK chains, as well as the impediment of keeping these regularly updated, thus not fully leveraging Polkadot-SDKs unique forkless upgrade feature.</p>
<p>The two main reasons why this is not possible today are:</p>
<ol>
<li><strong>Metadata is too large for offline devices</strong>. Currently Polkadot-SDK metadata is on average 500 KiB, which is more than what the mostly adopted offline devices can hold.</li>
<li><strong>Metadata is not authenticated</strong>. Even if there was enough space on offline devices to hold the metadata, the user would be trusting the entity providing this metadata to the hardware wallet. In the Polkadot ecosystem, this is how currently Polkadot Vault works.</li>
</ol>
<p><strong>This RFC proposes a solution to make FRAME Metadata compatible with offline signers in a secure way.</strong> As it leverages FRAME Metadata, it does not only ensure that offline devices can always keep up to date with every FRAME based chain, but also that every offline wallet will be compatible with all FRAME based chains, avoiding the need of per-chain implementations.</p>
<h2 id="requirements-8"><a class="header" href="#requirements-8">Requirements</a></h2>
<ol>
<li>Metadata's integrity MUST be preserved. If any compromise were to happen, extrinsics sent with compromised metadata SHOULD fail.</li>
<li>Metadata information that could be used in signable extrinsic decoding MAY be included in digest, yet its inclusion MUST be indicated in signed extensions.</li>
<li>Digest MUST be deterministic with respect to metadata.</li>
<li>Digest MUST be cryptographically strong against pre-image, both first (finding an input that results in given digest) and second (finding an input that results in same digest as some other input given).</li>
<li>Extra-metadata information necessary for extrinsic decoding and constant within runtime version MUST be included in digest.</li>
<li>It SHOULD be possible to quickly withdraw offline signing mechanism without access to cold signing devices.</li>
<li>Digest format SHOULD be versioned.</li>
<li>Work necessary for proving metadata authenticity MAY be omitted at discretion of signer device design (to support automation tools).</li>
</ol>
<h3 id="reduce-metadata-size"><a class="header" href="#reduce-metadata-size">Reduce metadata size</a></h3>
<p>Metadata should be stripped from parts that are not necessary to parse a signable extrinsic, then it should be separated into a finite set of self-descriptive chunks. Thus, a subset of chunks necessary for signable extrinsic decoding and rendering could be sent, possibly in small portions (ultimately, one at a time), to cold devices together with the proof.</p>
<ol>
<li>Single chunk with proof payload size SHOULD fit within few kB;</li>
<li>Chunks handling mechanism SHOULD support chunks being sent in any order without memory utilization overhead;</li>
<li>Unused enum variants MUST be stripped (this has great impact on transmitted metadata size; examples: era enum, enum with all calls for call batching).</li>
</ol>
<h2 id="stakeholders-38"><a class="header" href="#stakeholders-38">Stakeholders</a></h2>
<ul>
<li>Runtime implementors</li>
<li>UI/wallet implementors</li>
<li>Offline wallet implementors</li>
</ul>
<p>The idea for this RFC was brought up by runtime implementors and was extensively discussed with offline wallet implementors. It was designed in such a way that it can work easily with the existing offline wallet solutions in the Polkadot ecosystem.</p>
<h2 id="explanation-38"><a class="header" href="#explanation-38">Explanation</a></h2>
<p>The FRAME metadata provides a wide range of information about a FRAME based runtime. It contains information about the pallets, the calls per pallet, the storage entries per pallet, runtime APIs, and type information about most of the types that are used in the runtime. For decoding extrinsics on an offline wallet, what is mainly required is type information. Most of the other information in the FRAME metadata is actually not required for decoding extrinsics and thus it can be removed. Therefore, the following is a proposal on a custom representation of the metadata and how this custom metadata is chunked, ensuring that only the needed chunks required for decoding a particular extrinsic are sent to the offline wallet. The necessary information to transform the FRAME metadata type information into the type information presented in this RFC will be provided. However, not every single detail on how to convert from FRAME metadata into the RFC type information is described.</p>
<p>First, the <code>MetadataDigest</code> is introduced. After that, <code>ExtrinsicMetadata</code> is covered and finally the actual format of the type information. Then pruning of unrelated type information is covered and how to generate the <code>TypeRef</code>s. In the latest step, merkle tree calculation is explained.</p>
<h3 id="metadata-digest"><a class="header" href="#metadata-digest">Metadata digest</a></h3>
<p>The metadata digest is the compact representation of the metadata. The hash of this digest is the <em>metadata hash</em>. Below the type declaration of the <code>Hash</code> type and the <code>MetadataDigest</code> itself can be found:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>type Hash = [u8; 32];
enum MetadataDigest {
#[index = 1]
V1 {
type_information_tree_root: Hash,
extrinsic_metadata_hash: Hash,
spec_version: u32,
spec_name: String,
base58_prefix: u16,
decimals: u8,
token_symbol: String,
},
}
<span class="boring">}</span></code></pre></pre>
<p>The <code>Hash</code> is 32 bytes long and <code>blake3</code> is used for calculating it. The hash of the <code>MetadataDigest</code> is calculated by <code>blake3(SCALE(MetadataDigest))</code>. Therefore, <code>MetadataDigest</code> is at first <code>SCALE</code> encoded, and then those bytes are hashed.</p>
<p>The <code>MetadataDigest</code> itself is represented as an <code>enum</code>. This is done to make it future proof, because a <code>SCALE</code> encoded <code>enum</code> is prefixed by the <code>index</code> of the variant. This <code>index</code> represents the version of the digest. As seen above, there is no <code>index</code> zero and it starts directly with one. Version one of the digest contains the following elements:</p>
<ul>
<li><code>type_information_tree_root</code>: The root of the <a href="approved/0078-merkleized-metadata.html#type-information">merkleized type information</a> tree.</li>
<li><code>extrinsic_metadata_hash</code>: The hash of the <a href="approved/0078-merkleized-metadata.html#extrinsic-metadata">extrinsic metadata</a>.</li>
<li><code>spec_version</code>: The <code>spec_version</code> of the runtime as found in the <code>RuntimeVersion</code> when generating the metadata. While this information can also be found in the metadata, it is hidden in a big blob of data. To avoid transferring this big blob of data, we directly add this information here.</li>
<li><code>spec_name</code>: Similar to <code>spec_version</code>, but being the <code>spec_name</code> found in the <code>RuntimeVersion</code>.</li>
<li><code>ss58_prefix</code>: The <code>SS58</code> prefix used for address encoding.</li>
<li><code>decimals</code>: The number of decimals for the token.</li>
<li><code>token_symbol</code>: The symbol of the token.</li>
</ul>
<h3 id="extrinsic-metadata"><a class="header" href="#extrinsic-metadata">Extrinsic metadata</a></h3>
<p>For decoding an extrinsic, more information on what types are being used is required. The actual format of the extrinsic is the format as described in the <a href="https://spec.polkadot.network/id-extrinsics">Polkadot specification</a>. The metadata for an extrinsic is as follows:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>struct ExtrinsicMetadata {
version: u8,
address_ty: TypeRef,
call_ty: TypeRef,
signature_ty: TypeRef,
signed_extensions: Vec&lt;SignedExtensionMetadata&gt;,
}
struct SignedExtensionMetadata {
identifier: String,
included_in_extrinsic: TypeRef,
included_in_signed_data: TypeRef,
}
<span class="boring">}</span></code></pre></pre>
<p>To begin with, <code>TypeRef</code>. This is a unique identifier for a type as found in the type information. Using this <code>TypeRef</code>, it is possible to look up the type in the type information tree. More details on this process can be found in the section <a href="approved/0078-merkleized-metadata.html#generating-typeref">Generating <code>TypeRef</code></a>.</p>
<p>The actual <code>ExtrinsicMetadata</code> contains the following information:</p>
<ul>
<li><code>version</code>: The version of the extrinsic format. As of writing this, the latest version is <code>4</code>.</li>
<li><code>address_ty</code>: The address type used by the chain.</li>
<li><code>call_ty</code>: The <code>call</code> type used by the chain. The <code>call</code> in FRAME based runtimes represents the type of transaction being executed on chain. It references the actual function to execute and the parameters of this function.</li>
<li><code>signature_ty</code>: The signature type used by the chain.</li>
<li><code>signed_extensions</code>: FRAME based runtimes can extend the base extrinsic with extra information. This extra information that is put into an extrinsic is called &quot;signed extensions&quot;. These extensions offer the runtime developer the possibility to include data directly into the extrinsic, like <code>nonce</code>, <code>tip</code>, amongst others. This means that the this data is sent alongside the extrinsic to the runtime. The other possibility these extensions offer is to include extra information only in the signed data that is signed by the sender. This means that this data needs to be known by both sides, the signing side and the verification side. An example for this kind of data is the <em>genesis hash</em> that ensures that extrinsics are unique per chain. Another example is the <em>metadata hash</em> itself that will also be included in the signed data. The offline wallets need to know which signed extensions are present in the chain and this is communicated to them using this field.</li>
</ul>
<p>The <code>SignedExtensionMetadata</code> provides information about a signed extension:</p>
<ul>
<li><code>identifier</code>: The <code>identifier</code> of the signed extension. An <code>identifier</code> is required to be unique in the Polkadot ecosystem as otherwise extrinsics are maybe built incorrectly.</li>
<li><code>included_in_extrinsic</code>: The type that will be included in the extrinsic by this signed extension.</li>
<li><code>included_in_signed_data</code>: The type that will be included in the signed data by this signed extension.</li>
</ul>
<h3 id="type-information"><a class="header" href="#type-information">Type Information</a></h3>
<p>As SCALE is not self descriptive like JSON, a decoder always needs to know the format of the type to decode it properly. This is where the type information comes into play. The format of the extrinsic is fixed as described above and <code>ExtrinsicMetadata</code> provides information on which type information is required for which part of the extrinsic. So, offline wallets only need access to the actual type information. It is a requirement that the type information can be chunked into logical pieces to reduce the amount of data that is sent to the offline wallets for decoding the extrinsics. So, the type information is structured in the following way:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>struct Type {
path: Vec&lt;String&gt;,
type_def: TypeDef,
type_id: Compact&lt;u32&gt;,
}
enum TypeDef {
Composite(Vec&lt;Field&gt;),
Enumeration(EnumerationVariant),
Sequence(TypeRef),
Array(Array),
Tuple(Vec&lt;TypeRef&gt;),
BitSequence(BitSequence),
}
struct Field {
name: Option&lt;String&gt;,
ty: TypeRef,
type_name: Option&lt;String&gt;,
}
struct Array {
len: u32,
type_param: TypeRef,
}
struct BitSequence {
num_bytes: u8,
least_significant_bit_first: bool,
}
struct EnumerationVariant {
name: String,
fields: Vec&lt;Field&gt;,
index: Compact&lt;u32&gt;,
}
enum TypeRef {
Bool,
Char,
Str,
U8,
U16,
U32,
U64,
U128,
U256,
I8,
I16,
I32,
I64,
I128,
I256,
CompactU8,
CompactU16,
CompactU32,
CompactU64,
CompactU128,
CompactU256,
Void,
PerId(Compact&lt;u32&gt;),
}
<span class="boring">}</span></code></pre></pre>
<p>The <code>Type</code> declares the structure of a type. The <code>type</code> has the following fields:</p>
<ul>
<li><code>path</code>: A <code>path</code> declares the position of a type locally to the place where it is defined. The <code>path</code> is not globally unique, this means that there can be multiple types with the same <code>path</code>.</li>
<li><code>type_def</code>: The high-level type definition, e.g. the type is a composition of fields where each field has a type, the type is a composition of different types as <code>tuple</code> etc.</li>
<li><code>type_id</code>: The unique identifier of this type.</li>
</ul>
<p>Every <code>Type</code> is composed of multiple different types. Each of these &quot;sub types&quot; can reference either a full <code>Type</code> again or reference one of the primitive types. This is where <code>TypeRef</code> becomes relevant as the type referencing information. To reference a <code>Type</code> in the type information, a unique identifier is used. As primitive types can be represented using a single byte, they are not put as separate types into the type information. Instead the primitive types are directly part of <code>TypeRef</code> to not require the overhead of referencing them in an extra <code>Type</code>. The special primitive type <code>Void</code> represents a type that encodes to nothing and can be decoded from nothing. As FRAME doesn't support <code>Compact</code> as primitive type it requires a more involved implementation to convert a FRAME type to a <code>Compact</code> primitive type. SCALE only supports <code>u8</code>, <code>u16</code>, <code>u32</code>, <code>u64</code> and <code>u128</code> as <code>Compact</code> which maps onto the primitive type declaration in the RFC. One special case is a <code>Compact</code> that wraps an empty <code>Tuple</code> which is expressed as primitive type <code>Void</code>.</p>
<p>The <code>TypeDef</code> variants have the following meaning:</p>
<ul>
<li><code>Composite</code>: A <code>struct</code> like type that is composed of multiple different fields. Each <code>Field</code> can have its own type. The order of the fields is significant. A <code>Composite</code> with no fields is expressed as primitive type <code>Void</code>.</li>
<li><code>Enumeration</code>: Stores a <code>EnumerationVariant</code>. A <code>EnumerationVariant</code> is a struct that is described by a name, an index and a vector of <code>Field</code>s, each of which can have it's own type. Typically <code>Enumeration</code>s have more than just one variant, and in those cases <code>Enumeration</code> will appear multiple times, each time with a different variant, in the type information. <code>Enumeration</code>s can become quite large, yet usually for decoding a type only one variant is required, therefore this design brings optimizations and helps reduce the size of the proof. An <code>Enumeration</code> with no variants is expressed as primitive type <code>Void</code>.</li>
<li><code>Sequence</code>: A <code>vector</code> like type wrapping the given type.</li>
<li><code>BitSequence</code>: A <code>vector</code> storing bits. <code>num_bytes</code> represents the size in bytes of the internal storage. If <code>least_significant_bit_first</code> is <code>true</code> the least significant bit is first, otherwise the most significant bit is first.</li>
<li><code>Array</code>: A fixed-length array of a specific type.</li>
<li><code>Tuple</code>: A composition of multiple types. A <code>Tuple</code> that is composed of no types is expressed as primitive type <code>Void</code>.</li>
</ul>
<p>Using the type information together with the <a href="https://spec.polkadot.network/id-cryptography-encoding#sect-scale-codec">SCALE specification</a> provides enough information on how to decode types.</p>
<h3 id="prune-unrelated-types"><a class="header" href="#prune-unrelated-types">Prune unrelated Types</a></h3>
<p>The FRAME metadata contains not only the type information for decoding extrinsics, but it also contains type information about storage types. The scope of the RFC is only about decoding transactions on offline wallets. Thus, a lot of type information can be pruned. To know which type information are required to decode all possible extrinsics, <code>ExtrinsicMetadata</code> has been defined. The extrinsic metadata contains all the types that define the layout of an extrinsic. Therefore, all the types that are accessible from the types declared in the extrinsic metadata can be collected. To collect all accessible types, it requires to recursively iterate over all types starting from the types in <code>ExtrinsicMetadata</code>. Note that some types are accessible, but they don't appear in the final type information and thus, can be pruned as well. These are for example inner types of <code>Compact</code> or the types referenced by <code>BitSequence</code>. The result of collecting these accessible types is a list of all the types that are required to decode each possible extrinsic.</p>
<h3 id="generating-typeref"><a class="header" href="#generating-typeref">Generating <code>TypeRef</code></a></h3>
<p>Each <code>TypeRef</code> basically references one of the following types:</p>
<ul>
<li>One of the primitive types. All primitive types can be represented by 1 byte and thus, they are directly part of the <code>TypeRef</code> itself to remove an extra level of indirection.</li>
<li>A <code>Type</code> using its unique identifier.</li>
</ul>
<p>In FRAME metadata a primitive type is represented like any other type. So, the first step is to remove all the primitive only types from the list of types that were generated in the previous section. The resulting list of types is sorted using the <code>id</code> provided by FRAME metadata. In the last step the <code>TypeRef</code>s are created. Each reference to a primitive type is replaced by one of the corresponding <code>TypeRef</code> primitive type variants and every other reference is replaced by the type's unique identifier. The unique identifier of a type is the index of the type in our sorted list. For <code>Enumeration</code>s all variants have the same unique identifier, while they are represented as multiple type information. All variants need to have the same unique identifier as the reference doesn't know which variant will appear in the actual encoded data.</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>let pruned_types = get_pruned_types();
for ty in pruned_types {
if ty.is_primitive_type() {
pruned_types.remove(ty);
}
}
pruned_types.sort(|(left, right)|
if left.frame_metadata_id() == right.frame_metadata_id() {
left.variant_index() &lt; right.variant_index()
} else {
left.frame_metadata_id() &lt; right.frame_metadata_id()
}
);
fn generate_type_ref(ty, ty_list) -&gt; TypeRef {
if ty.is_primitive_type() {
TypeRef::primtive_from_ty(ty)
}
TypeRef::from_id(
// Determine the id by using the position of the type in the
// list of unique frame metadata ids.
ty_list.position_by_frame_metadata_id(ty.frame_metadata_id())
)
}
fn replace_all_sub_types_with_type_refs(ty, ty_list) -&gt; Type {
for sub_ty in ty.sub_types() {
replace_all_sub_types_with_type_refs(sub_ty, ty_list);
sub_ty = generate_type_ref(sub_ty, ty_list)
}
ty
}
let final_ty_list = Vec::new();
for ty in pruned_types {
final_ty_list.push(replace_all_sub_types_with_type_refs(ty, ty_list))
}
<span class="boring">}</span></code></pre></pre>
<h3 id="building-the-merkle-tree-root"><a class="header" href="#building-the-merkle-tree-root">Building the Merkle Tree Root</a></h3>
<p>A complete binary merkle tree with <code>blake3</code> as the hashing function is proposed. For building the merkle tree root, the initial data has to be hashed as a first step. This initial data is referred to as the <em>leaves</em> of the merkle tree. The leaves need to be sorted to make the tree root deterministic. The type information is sorted using their unique identifiers and for the <code>Enumeration</code>, variants are sort using their <code>index</code>. After sorting and hashing all leaves, two leaves have to be combined to one hash. The combination of these of two hashes is referred to as a <em>node</em>.</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>let nodes = leaves;
while nodes.len() &gt; 1 {
let right = nodes.pop_back();
let left = nodes.pop_back();
nodes.push_front(blake3::hash(scale::encode((left, right))));
}
let merkle_tree_root = if nodes.is_empty() { [0u8; 32] } else { nodes.back() };
<span class="boring">}</span></code></pre></pre>
<p>The <code>merkle_tree_root</code> in the end is the last node left in the list of nodes. If there are no nodes in the list left, it means that the initial data set was empty. In this case, all zeros hash is used to represent the empty tree. </p>
<p>Building a tree with 5 leaves (numbered 0 to 4):</p>
<pre><code>nodes: 0 1 2 3 4
nodes: [3, 4] 0 1 2
nodes: [1, 2] [3, 4] 0
nodes: [[3, 4], 0] [1, 2]
nodes: [[[3, 4], 0], [1, 2]]
</code></pre>
<p>The resulting tree visualized:</p>
<pre><code> [root]
/ \
* *
/ \ / \
* 0 1 2
/ \
3 4
</code></pre>
<p>Building a tree with 6 leaves (numbered 0 to 5):</p>
<pre><code>nodes: 0 1 2 3 4 5
nodes: [4, 5] 0 1 2 3
nodes: [2, 3] [4, 5] 0 1
nodes: [0, 1] [2, 3] [4, 5]
nodes: [[2, 3], [4, 5]] [0, 1]
nodes: [[[2, 3], [4, 5]], [0, 1]]
</code></pre>
<p>The resulting tree visualized:</p>
<pre><code> [root]
/ \
* *
/ \ / \
* * 0 1
/ \ / \
2 3 4 5
</code></pre>
<h3 id="inclusion-in-an-extrinsic"><a class="header" href="#inclusion-in-an-extrinsic">Inclusion in an Extrinsic</a></h3>
<p>To ensure that the offline wallet used the correct metadata to show the extrinsic to the user the metadata hash needs to be included in the extrinsic. The metadata hash is generated by hashing the SCALE encoded <code>MetadataDigest</code>:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>blake3::hash(SCALE::encode(MetadataDigest::V1 { .. }))
<span class="boring">}</span></code></pre></pre>
<p>For the runtime the metadata hash is generated at compile time. Wallets will have to generate the hash using the FRAME metadata. </p>
<p>The signing side should control whether it wants to add the metadata hash or if it wants to omit it. To accomplish this it is required to add one extra byte to the extrinsic itself. If this byte is <code>0</code> the metadata hash is not required and if the byte is <code>1</code> the metadata hash is added using <code>V1</code> of the <code>MetadataDigest</code>. This leaves room for future versions of the <code>MetadataDigest</code> format. When the metadata hash should be included, it is only added to the data that is signed. This brings the advantage of not requiring to include 32 bytes into the extrinsic itself, because the runtime knows the metadata hash as well and can add it to the signed data as well if required. This is similar to the genesis hash, while this isn't added conditionally to the signed data. So, to recap:</p>
<ul>
<li>Included in the extrinsic is <code>u8</code>, the &quot;mode&quot;. The mode is either <code>0</code> which means to not include the metadata hash in the signed data or the mode is <code>1</code> to include the metadata hash in <code>V1</code>.</li>
<li>Included in the signed data is an <code>Option&lt;[u8; 32]&gt;</code>. Depending on the mode the value is either <code>None</code> or <code>Some(metadata_hash)</code>.</li>
</ul>
<h2 id="drawbacks-35"><a class="header" href="#drawbacks-35">Drawbacks</a></h2>
<p>The chunking may not be the optimal case for every kind of offline wallet.</p>
<h2 id="testing-security-and-privacy-34"><a class="header" href="#testing-security-and-privacy-34">Testing, Security, and Privacy</a></h2>
<p>All implementations are required to strictly follow the RFC to generate the metadata hash. This includes which hash function to use and how to construct the metadata types tree. So, all implementations are following the same security criteria. As the chains will calculate the metadata hash at compile time, the build process needs to be trusted. However, this is already a solved problem in the Polkadot ecosystem by using reproducible builds. So, anyone can rebuild a chain runtime to ensure that a proposal is actually containing the changes as advertised.</p>
<p>Implementations can also be tested easily against each other by taking some metadata and ensuring that they all come to the same metadata hash.</p>
<p>Privacy of users should also not be impacted. This assumes that wallets will generate the metadata hash locally and don't leak any information to third party services about which chunks a user will send to their offline wallet. Besides that, there is no leak of private information as getting the raw metadata from the chain is an operation that is done by almost everyone.</p>
<h2 id="performance-ergonomics-and-compatibility-34"><a class="header" href="#performance-ergonomics-and-compatibility-34">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-31"><a class="header" href="#performance-31">Performance</a></h3>
<p>There should be no measurable impact on performance to Polkadot or any other chain using this feature. The metadata root hash is calculated at compile time and at runtime it is optionally used when checking the signature of a transaction. This means that at runtime no performance heavy operations are done. </p>
<h3 id="ergonomics--compatibility-2"><a class="header" href="#ergonomics--compatibility-2">Ergonomics &amp; Compatibility</a></h3>
<p>The proposal alters the way a transaction is built, signed, and verified. So, this imposes some required changes to any kind of developer who wants to construct transactions for Polkadot or any chain using this feature. As the developer can pass <code>0</code> for disabling the verification of the metadata root hash, it can be easily ignored.</p>
<h2 id="prior-art-and-references-35"><a class="header" href="#prior-art-and-references-35">Prior Art and References</a></h2>
<p><a href="https://github.com/polkadot-fellows/RFCs/pull/46">RFC 46</a> produced by the Alzymologist team is a previous work reference that goes in this direction as well.</p>
<p>On other ecosystems, there are other solutions to the problem of trusted signing. Cosmos for example has a standardized way of transforming a transaction into some textual representation and this textual representation is included in the signed data. Basically achieving the same as what the RFC proposes, but it requires that for every transaction applied in a block, every node in the network always has to generate this textual representation to ensure the transaction signature is valid.</p>
<h2 id="unresolved-questions-33"><a class="header" href="#unresolved-questions-33">Unresolved Questions</a></h2>
<p>None.</p>
<h2 id="future-directions-and-related-material-26"><a class="header" href="#future-directions-and-related-material-26">Future Directions and Related Material</a></h2>
<ul>
<li>Does it work with all kind of offline wallets?</li>
<li>Generic types currently appear multiple times in the metadata with each instantiation. It could be may be useful to have generic type only once in the metadata and declare the generic parameters at their instantiation. </li>
<li>The metadata doesn't contain any kind of semantic information. This means that the offline wallet for example doesn't know what is a balance etc. The current solution for this problem is to match on the type name, but this isn't a sustainable solution.</li>
<li><code>MetadataDigest</code> only provides one <code>token</code> and <code>decimal</code>. However, chains support a lot of chains support multiple tokens for paying fees etc. Probably more a question of having semantic information as mentioned above.</li>
</ul>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0084-general-transaction-extrinsic-format.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0084-general-transaction-extrinsic-format.html#rfc-0084-general-transactions-in-extrinsic-format">RFC-0084: General transactions in extrinsic format</a>
<ul>
<li><a href="approved/0084-general-transaction-extrinsic-format.html#summary">Summary</a></li>
<li><a href="approved/0084-general-transaction-extrinsic-format.html#motivation">Motivation</a></li>
<li><a href="approved/0084-general-transaction-extrinsic-format.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0084-general-transaction-extrinsic-format.html#explanation">Explanation</a></li>
<li><a href="approved/0084-general-transaction-extrinsic-format.html#drawbacks">Drawbacks</a></li>
<li><a href="approved/0084-general-transaction-extrinsic-format.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="approved/0084-general-transaction-extrinsic-format.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="approved/0084-general-transaction-extrinsic-format.html#performance">Performance</a></li>
<li><a href="approved/0084-general-transaction-extrinsic-format.html#ergonomics">Ergonomics</a></li>
<li><a href="approved/0084-general-transaction-extrinsic-format.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="approved/0084-general-transaction-extrinsic-format.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="approved/0084-general-transaction-extrinsic-format.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="approved/0084-general-transaction-extrinsic-format.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0084-general-transactions-in-extrinsic-format"><a class="header" href="#rfc-0084-general-transactions-in-extrinsic-format">RFC-0084: General transactions in extrinsic format</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>12 March 2024</td></tr>
<tr><td><strong>Description</strong></td><td>Support more extrinsic types by updating the extrinsic format</td></tr>
<tr><td><strong>Authors</strong></td><td>George Pisaltu</td></tr>
</tbody></table>
</div>
<h2 id="summary-40"><a class="header" href="#summary-40">Summary</a></h2>
<p>This RFC proposes a change to the extrinsic format to incorporate a new transaction type, the &quot;general&quot; transaction.</p>
<h2 id="motivation-40"><a class="header" href="#motivation-40">Motivation</a></h2>
<p>&quot;General&quot; transactions, a new type of transaction that this RFC aims to support, are transactions which obey the runtime's extensions and have according extension data yet do not have hard-coded signatures. They are first described in <a href="https://github.com/paritytech/polkadot-sdk/issues/2415">Extrinsic Horizon</a> and supported in <a href="https://github.com/paritytech/polkadot-sdk/pull/3685">3685</a>. They enable users to authorize origins in new, more flexible ways (e.g. ZK proofs, mutations over pre-authenticated origins). As of now, all transactions are limited to the account signing model for origin authorization and any additional origin changes happen in extrinsic logic, which cannot leverage the validation process of extensions.</p>
<p>An example of a use case for such an extension would be sponsoring the transaction fee for some other user. A new extension would be put in place to verify that a part of the initial payload was signed by the author under who the extrinsic should run and change the origin, but the payment for the whole transaction should be handled under a sponsor's account. A POC for this can be found in <a href="https://github.com/paritytech/polkadot-sdk/pull/3712">3712</a>.</p>
<p>The new &quot;general&quot; transaction type would coexist with both current transaction types for a while and, therefore, the current number of supported transaction types, capped at 2, is insufficient. A new extrinsic type must be introduced alongside the current signed and unsigned types. Currently, an encoded extrinsic's first byte indicate the type of extrinsic using the most significant bit - <code>0</code> for unsigned, <code>1</code> for signed - and the 7 following bits indicate the <a href="https://spec.polkadot.network/id-extrinsics#id-extrinsics-body">extrinsic format version</a>, which has been equal to <code>4</code> for a long time.</p>
<p>By taking one bit from the extrinsic format version encoding, we can support 2 additional extrinsic types while also having a minimal impact on our capability to extend and change the extrinsic format in the future.</p>
<h2 id="stakeholders-39"><a class="header" href="#stakeholders-39">Stakeholders</a></h2>
<ul>
<li>Runtime users</li>
<li>Runtime devs</li>
<li>Wallet devs</li>
</ul>
<h2 id="explanation-39"><a class="header" href="#explanation-39">Explanation</a></h2>
<p>An extrinsic is currently encoded as one byte to identify the extrinsic type and version. This RFC aims to change the interpretation of this byte regarding the reserved bits for the extrinsic type and version. In the following explanation, bits represented using <code>T</code> make up the extrinsic type and bits represented using <code>V</code> make up the extrinsic version.</p>
<p>Currently, the bit allocation within the leading encoded byte is <code>0bTVVV_VVVV</code>. In practice in the Polkadot ecosystem, the leading byte would be <code>0bT000_0100</code> as the version has been equal to <code>4</code> for a long time.</p>
<p>This RFC proposes for the bit allocation to change to <code>0bTTVV_VVVV</code>. As a result, the extrinsic format version will be bumped to <code>5</code> and the extrinsic type bit representation would change as follows:</p>
<div class="table-wrapper"><table><thead><tr><th>bits</th><th>type</th></tr></thead><tbody>
<tr><td>00</td><td>unsigned</td></tr>
<tr><td>10</td><td>signed</td></tr>
<tr><td>01</td><td>reserved</td></tr>
<tr><td>11</td><td>reserved</td></tr>
</tbody></table>
</div>
<h2 id="drawbacks-36"><a class="header" href="#drawbacks-36">Drawbacks</a></h2>
<p>This change would reduce the maximum possible transaction version from the current <code>127</code> to <code>63</code>. In order to bypass the new, lower limit, the extrinsic format would have to change again.</p>
<h2 id="testing-security-and-privacy-35"><a class="header" href="#testing-security-and-privacy-35">Testing, Security, and Privacy</a></h2>
<p>There is no impact on testing, security or privacy.</p>
<h2 id="performance-ergonomics-and-compatibility-35"><a class="header" href="#performance-ergonomics-and-compatibility-35">Performance, Ergonomics, and Compatibility</a></h2>
<p>This change would allow Polkadot to support new types of transactions, with the specific &quot;general&quot; transaction type in mind at the time of writing this proposal.</p>
<h3 id="performance-32"><a class="header" href="#performance-32">Performance</a></h3>
<p>There is no performance impact.</p>
<h3 id="ergonomics-28"><a class="header" href="#ergonomics-28">Ergonomics</a></h3>
<p>The impact to developers and end-users is minimal as it would just be a bitmask update on their part for parsing the extrinsic type along with the version.</p>
<h3 id="compatibility-28"><a class="header" href="#compatibility-28">Compatibility</a></h3>
<p>This change breaks backwards compatiblity because any transaction that is neither signed nor unsigned, but a new transaction type, would be interpreted as having a future extrinsic format version.</p>
<h2 id="prior-art-and-references-36"><a class="header" href="#prior-art-and-references-36">Prior Art and References</a></h2>
<p>The original design was originally proposed in the <a href="https://github.com/paritytech/polkadot-sdk/pull/2280"><code>TransactionExtension</code> PR</a>, which is also the motivation behind this effort.</p>
<h2 id="unresolved-questions-34"><a class="header" href="#unresolved-questions-34">Unresolved Questions</a></h2>
<p>None.</p>
<h2 id="future-directions-and-related-material-27"><a class="header" href="#future-directions-and-related-material-27">Future Directions and Related Material</a></h2>
<p>Following this change, the &quot;general&quot; transaction type will be introduced as part of the <a href="https://github.com/paritytech/polkadot-sdk/issues/2415">Extrinsic Horizon</a> effort, which will shape future work.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0091-dht-record-creation-time.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0091-dht-record-creation-time.html#rfc-0091-dht-authority-discovery-record-creation-time">RFC-0091: DHT Authority discovery record creation time</a>
<ul>
<li><a href="approved/0091-dht-record-creation-time.html#summary">Summary</a></li>
<li><a href="approved/0091-dht-record-creation-time.html#motivation">Motivation</a></li>
<li><a href="approved/0091-dht-record-creation-time.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0091-dht-record-creation-time.html#explanation">Explanation</a></li>
<li><a href="approved/0091-dht-record-creation-time.html#drawbacks">Drawbacks</a></li>
<li><a href="approved/0091-dht-record-creation-time.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="approved/0091-dht-record-creation-time.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="approved/0091-dht-record-creation-time.html#performance">Performance</a></li>
<li><a href="approved/0091-dht-record-creation-time.html#ergonomics">Ergonomics</a></li>
<li><a href="approved/0091-dht-record-creation-time.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="approved/0091-dht-record-creation-time.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="approved/0091-dht-record-creation-time.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="approved/0091-dht-record-creation-time.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0091-dht-authority-discovery-record-creation-time"><a class="header" href="#rfc-0091-dht-authority-discovery-record-creation-time">RFC-0091: DHT Authority discovery record creation time</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>2024-05-20</td></tr>
<tr><td><strong>Description</strong></td><td>Add creation time for DHT authority discovery records</td></tr>
<tr><td><strong>Authors</strong></td><td>Alex Gheorghe (alexggh)</td></tr>
</tbody></table>
</div>
<h2 id="summary-41"><a class="header" href="#summary-41">Summary</a></h2>
<p>Extend the DHT authority discovery records with a signed creation time, so that nodes can determine which record is newer and always decide to prefer the newer records to the old ones.</p>
<h2 id="motivation-41"><a class="header" href="#motivation-41">Motivation</a></h2>
<p>Currently, we use the Kademlia DHT for storing records regarding the p2p address of an authority discovery key, the problem is that if the nodes decide to change its PeerId/Network key it will publish a new record, however because of the distributed and replicated nature of the DHT there is no way to tell which record is newer so both old PeerId and the new PeerId will live in the network until the old one expires(36h), that creates all sort of problem and leads to the node changing its address not being properly connected for up to 36h. </p>
<p>After this RFC, nodes are extended to decide to keep the new record and propagate the new record to nodes that have the old record stored, so in the end all the nodes will converge faster to the new record(in the order of minutes, not 36h)</p>
<p>Implementation of the rfc: https://github.com/paritytech/polkadot-sdk/pull/3786.</p>
<p>Current issue without this enhacement: https://github.com/paritytech/polkadot-sdk/issues/3673 </p>
<h2 id="stakeholders-40"><a class="header" href="#stakeholders-40">Stakeholders</a></h2>
<p>Polkadot node developers.</p>
<h2 id="explanation-40"><a class="header" href="#explanation-40">Explanation</a></h2>
<p>This RFC heavily relies on the functionalities of the Kademlia DHT already in use by Polkadot.
You can find a link to the specification <a href="https://github.com/libp2p/specs/tree/master/kad-dht">here</a>.</p>
<p>In a nutshell, on a specific node the current authority-discovery protocol publishes Kademila DHT records at startup and periodically. The records contain the full address of the node for each authorithy key it owns. The node tries also to find the full address of all authorities in the network by querying the DHT and picking up the first record it finds for each of the authority id it found on chain.</p>
<p>The authority discovery DHT records use the protobuf protocol and the current format is specified <a href="https://github.com/paritytech/polkadot-sdk/blob/313fe0f9a277f27a4228634f0fb15a1c3fa21271/substrate/client/authority-discovery/src/worker/schema/dht-v2.proto#L4">here</a>. This RFC proposese extending the schema in a backwards compatible manner by adding a new optional <code>creation_time</code> field to <code>AuthorityRecord</code> and nodes can use this information to determine which of the record is newer.</p>
<p>Diff of <code>dht-v3.proto</code> vs <code>dht-v2.proto</code></p>
<pre><code>@@ -1,10 +1,10 @@
syntax = &quot;proto3&quot;;
-package authority_discovery_v2;
+package authority_discovery_v3;
// First we need to serialize the addresses in order to be able to sign them.
message AuthorityRecord {
repeated bytes addresses = 1;
+ // Time since UNIX_EPOCH in nanoseconds, scale encoded
+ TimestampInfo creation_time = 2;
}
message PeerSignature {
@@ -13,11 +15,17 @@
bytes public_key = 2;
}
+// Information regarding the creation data of the record
+message TimestampInfo {
+ // Time since UNIX_EPOCH in nanoseconds, scale encoded
+ bytes timestamp = 1;
+}
+
</code></pre>
<p>Each time a node wants to resolve an authorithy ID it will issue a query with a certain redundancy factor, and from all the results it receives it will decide to pick only the newest record. Additionally,
in order to speed up the time until all nodes have the newest record, nodes can optionaly implement a logic where they send the new record to nodes that answered with the older record.</p>
<h2 id="drawbacks-37"><a class="header" href="#drawbacks-37">Drawbacks</a></h2>
<p>In theory the new protocol creates a bit more traffic on the DHT network, because it waits for DHT records to be received from more than one node, while in the current implementation we just take the first record that we receive and cancel all in-flight requests to other peers. However, because the redundancy factor will be relatively small and this operation happens rarerly, every 10min, this cost is negligible.</p>
<h2 id="testing-security-and-privacy-36"><a class="header" href="#testing-security-and-privacy-36">Testing, Security, and Privacy</a></h2>
<p>This RFC's implementation https://github.com/paritytech/polkadot-sdk/pull/3786 had been tested on various local test networks and versi.</p>
<p>With regard to security the creation time is wrapped inside SignedAuthorityRecord wo it will be signed with the authority id key, so there is no way for other malicious nodes to manipulate this field without the received node observing.</p>
<h2 id="performance-ergonomics-and-compatibility-36"><a class="header" href="#performance-ergonomics-and-compatibility-36">Performance, Ergonomics, and Compatibility</a></h2>
<p>Irrelevant.</p>
<h3 id="performance-33"><a class="header" href="#performance-33">Performance</a></h3>
<p>Irrelevant.</p>
<h3 id="ergonomics-29"><a class="header" href="#ergonomics-29">Ergonomics</a></h3>
<p>Irrelevant.</p>
<h3 id="compatibility-29"><a class="header" href="#compatibility-29">Compatibility</a></h3>
<p>The changes are backwards compatible with the existing protocol, so nodes with both the old protocol and newer protocol can exist in the network, this is achieved by the fact that we use protobuf for serializing and deserializing the records, so new fields will be ignore when deserializing with the older protocol and vice-versa when deserializing an old record with the new protocol the new field will be <code>None</code> and the new code accepts this record as being valid.</p>
<h2 id="prior-art-and-references-37"><a class="header" href="#prior-art-and-references-37">Prior Art and References</a></h2>
<p>The enhancements have been inspired by the algorithm specified in <a href="https://github.com/libp2p/specs/blob/master/kad-dht/README.md#value-retrieval">here</a></p>
<h2 id="unresolved-questions-35"><a class="header" href="#unresolved-questions-35">Unresolved Questions</a></h2>
<p>N/A</p>
<h2 id="future-directions-and-related-material-28"><a class="header" href="#future-directions-and-related-material-28">Future Directions and Related Material</a></h2>
<p>N/A</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0097-unbonding_queue.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0097-unbonding_queue.html#rfc-0097-unbonding-queue">RFC-0097: Unbonding Queue</a>
<ul>
<li><a href="approved/0097-unbonding_queue.html#summary">Summary</a></li>
<li><a href="approved/0097-unbonding_queue.html#motivation">Motivation</a></li>
<li><a href="approved/0097-unbonding_queue.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0097-unbonding_queue.html#explanation">Explanation</a></li>
<li><a href="approved/0097-unbonding_queue.html#mechanism">Mechanism</a>
<ul>
<li><a href="approved/0097-unbonding_queue.html#proposed-parameters">Proposed Parameters</a></li>
<li><a href="approved/0097-unbonding_queue.html#rebonding">Rebonding</a></li>
<li><a href="approved/0097-unbonding_queue.html#empirical-analysis">Empirical Analysis</a></li>
</ul>
</li>
<li><a href="approved/0097-unbonding_queue.html#additional-considerations">Additional Considerations</a>
<ul>
<li><a href="approved/0097-unbonding_queue.html#deferred-slashing">Deferred slashing</a></li>
<li><a href="approved/0097-unbonding_queue.html#uxui">UX/UI</a></li>
<li><a href="approved/0097-unbonding_queue.html#conviction-voting">Conviction voting</a></li>
<li><a href="approved/0097-unbonding_queue.html#potential-extension">Potential Extension</a></li>
</ul>
</li>
<li><a href="approved/0097-unbonding_queue.html#drawbacks">Drawbacks</a></li>
<li><a href="approved/0097-unbonding_queue.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="approved/0097-unbonding_queue.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="approved/0097-unbonding_queue.html#performance">Performance</a></li>
<li><a href="approved/0097-unbonding_queue.html#ergonomics">Ergonomics</a></li>
<li><a href="approved/0097-unbonding_queue.html#compatibility">Compatibility</a></li>
<li><a href="approved/0097-unbonding_queue.html#prior-art-and-references">Prior Art and References</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<h1 id="rfc-0097-unbonding-queue"><a class="header" href="#rfc-0097-unbonding-queue">RFC-0097: Unbonding Queue</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Date</strong></td><td>19.06.2024</td></tr>
<tr><td><strong>Description</strong></td><td>This RFC proposes a safe mechanism to scale the unbonding time from staking on the Relay Chain proportionally to the overall unbonding stake. This approach significantly reduces the expected duration for unbonding, while ensuring that a substantial portion of the stake is always available to slash of validators behaving maliciously within a 28-day window.</td></tr>
<tr><td><strong>Authors</strong></td><td>Jonas Gehrlein &amp; Alistair Stewart</td></tr>
</tbody></table>
</div>
<h2 id="summary-42"><a class="header" href="#summary-42">Summary</a></h2>
<p>This RFC proposes a flexible unbonding mechanism for tokens that are locked from <a href="https://wiki.polkadot.network/docs/learn-staking">staking</a> on the Relay Chain (DOT/KSM), aiming to enhance user convenience without compromising system security. </p>
<p>Locking tokens for staking ensures that Polkadot is able to slash tokens backing misbehaving validators. With changing the locking period, we still need to make sure that Polkadot can slash enough tokens to deter misbehaviour. This means that not all tokens can be unbonded immediately, however we can still allow some tokens to be unbonded quickly.</p>
<p>The new mechanism leads to a signficantly reduced unbonding time on average, by queuing up new unbonding requests and scaling their unbonding duration relative to the size of the queue. New requests are executed with a minimum of 2 days, when the queue is comparatively empty, to the conventional 28 days, if the sum of requests (in terms of stake) exceed some threshold. In scenarios between these two bounds, the unbonding duration scales proportionately. The new mechanism will never be worse than the current fixed 28 days.</p>
<p>In this document we also present an empirical analysis by retrospectively fitting the proposed mechanism to the historic unbonding timeline and show that the average unbonding duration would drastically reduce, while still being sensitive to large unbonding events. Additionally, we discuss implications for UI, UX, and conviction voting.</p>
<p>Note: Our proposition solely focuses on the locks imposed from staking. Other locks, such as governance, remain unchanged. Also, this mechanism should not be confused with the already existing feature of <a href="https://wiki.polkadot.network/docs/learn-staking#fast-unstake">FastUnstake</a>, which lets users unstake tokens immediately that have not received rewards for 28 days or longer.</p>
<p>As an initial step to gauge its effectiveness and stability, it is recommended to implement and test this model on Kusama before considering its integration into Polkadot, with appropriate adjustments to the parameters. In the following, however, we limit our discussion to Polkadot.</p>
<h2 id="motivation-42"><a class="header" href="#motivation-42">Motivation</a></h2>
<p>Polkadot has one of the longest unbonding periods among all Proof-of-Stake protocols, because security is the most important goal. Staking on Polkadot is still attractive compared to other protocols because of its above-average staking APY. However the long unbonding period harms usability and deters potential participants that want to contribute to the security of the network. </p>
<p>The current length of the unbonding period imposes significant costs for any entity that even wants to perform basic tasks such as a reorganization / consolidation of their stashes, or updating their private key infrastructure. It also limits participation of users that have a large preference for liquidity.</p>
<p>The combination of long unbonding periods and high returns has lead to the proliferation of <a href="https://www.bitcoinsuisse.com/learn/what-is-liquid-staking">liquid staking</a>, where parachains or centralised exchanges offer users their staked tokens before the 28 days unbonding period is over either in original DOT/KSM form or derivative tokens. Liquid staking is harmless if few tokens are involved but it could result in many validators being selected by a few entities if a large fraction of DOTs were involved. This may lead to centralization (see <a href="https://dexola.medium.com/is-ethereum-about-to-get-crushed-by-liquid-staking-30652df9ec46">here</a> for more discussion on threats of liquid staking) and an opportunity for attacks.</p>
<p>The new mechanism greatly increases the competitiveness of Polkadot, while maintaining sufficient security.</p>
<h2 id="stakeholders-41"><a class="header" href="#stakeholders-41">Stakeholders</a></h2>
<ul>
<li>Every DOT/KSM token holder</li>
</ul>
<h2 id="explanation-41"><a class="header" href="#explanation-41">Explanation</a></h2>
<p>Before diving into the details of how to implement the unbonding queue, we give readers context about why Polkadot has a 28-day unbonding period in the first place. The reason for it is to prevent long-range attacks (LRA) that becomes theoretically possible if more than 1/3 of validators collude. In essence, a LRA describes the inability of users, who disconnect from the consensus at time t0 and reconnects later, to realize that validators which were legitimate at a certain time, say t0 but dropped out in the meantime, are not to be trusted anymore. That means, for example, a user syncing the state could be fooled by trusting validators that fell outside the active set of validators after t0, and are building a competitive and malicious chain (fork). </p>
<p>LRAs of longer than 28 days are mitigated by the use of trusted checkpoints, which are assumed to be no more than 28 days old. A new node that syncs Polkadot will start at the checkpoint and look for proofs of finality of later blocks, signed by 2/3 of the validators. In an LRA fork, some of the validator sets may be different but only if 2/3 of some validator set in the last 28 days signed something incorrect. </p>
<p>If we detect an LRA of no more than 28 days with the current unbonding period, then we should be able to detect misbehaviour from over 1/3 of validators whose nominators are still bonded. The stake backing these validators is considerable fraction of the total stake (empirically it is 0.287 or so). If we allowed more than this stake to unbond, without checking who it was backing, then the LRA attack might be free of cost for an attacker. The proposed mechansim allows up to half this stake to unbond within 28 days. This halves the amount of tokens that can be slashed, but this is still very high in absolute terms. For example, at the time of writing (19.06.2024) this would translate to around 120 millions DOTs.</p>
<p>Attacks other than an LRA, such as backing incorrect parachain blocks, should be detected and slashed within 2 days. This is why the mechanism has a minimum unbonding period.</p>
<p>In practice an LRA does not affect clients who follow consensus more frequently than every 2 days, such as running nodes or bridges. However any time a node syncs Polkadot if an attacker is able to connect to it first, it could be misled.</p>
<p>In short, in the light of the huge benefits obtained, we are fine by only keeping a fraction of the total stake of validators slashable against LRAs at any given time.</p>
<h2 id="mechanism"><a class="header" href="#mechanism">Mechanism</a></h2>
<p>When a user (<a href="https://wiki.polkadot.network/docs/learn-nominator">nominator</a> or validator) decides to unbond their tokens, they don't become instantly available. Instead, they enter an <em>unbonding queue</em>. The following specification illustrates how the queue works, given a user wants to unbond some portion of their stake denoted as <code>new_unbonding_stake</code>. We also store a variable, <code>max_unstake</code> that tracks how much stake we allow to unbond potentially earlier than 28 eras (28 days on Polkadot and 7 days on Kusama).</p>
<p>To calculate <code>max_unstake</code>, we record for each era how much stake was used to back the lowest-backed 1/3 of validators. We store this information for the last 28 eras and let <code>min_lowest_third_stake</code> be the minimum of this over the last 28 eras.
<code>max_unstake</code> is determined by <code>MIN_SLASHABLE_SHARE</code> x <code>min_lowest_third_stake</code>. In addition, we can use <code>UPPER_BOUND</code> and <code>LOWER_BOUND</code> as variables to scale the unbonding duration of the queue.</p>
<p>At any time we store <code>back_of_unbonding_queue_block_number</code> which expresses the block number when all the existing unbonders have unbonded.</p>
<p>Let's assume a user wants to unbond some of their stake, i.e., <code>new_unbonding_stake</code>, and issues the request at some arbitrary block number denoted as <code>current_block</code>. Then:</p>
<pre><code>unbonding_time_delta = new_unbonding_stake / max_unstake * UPPER_BOUND
</code></pre>
<p>This number needs to be added to the <code>back_of_unbonding_queue_block_number</code> under the conditions that it does not undercut <code>current_block + LOWER_BOUND</code> or exceed <code>current_block + UPPER_BOUND</code>. </p>
<pre><code>back_of_unbonding_queue_block_number = max(current_block_number, back_of_unbonding_queue_block_number) + unbonding_time_delta
</code></pre>
<p>This determines at which block the user has their tokens unbonded, making sure that it is in the limit of <code>LOWER_BOUND</code> and <code>UPPER_BOUND</code>.</p>
<pre><code>unbonding_block_number = min(UPPER_BOUND, max(back_of_unbonding_queue_block_number - current_block_number, LOWER_BOUND)) + current_block_number
</code></pre>
<p>Ultimately, the user's token are unbonded at <code>unbonding_block_number</code>.</p>
<h3 id="proposed-parameters"><a class="header" href="#proposed-parameters">Proposed Parameters</a></h3>
<p>There are a few constants to be exogenously set. They are up for discussion, but we make the following recommendation:</p>
<ul>
<li><code>MIN_SLASHABLE_SHARE</code>: <code>1/2</code> - This is the share of stake backing the lowest 1/3 of validators that is slashable at any point in time. It offers a trade-off between security and unbonding time. Half is a sensible choice. Here, we have sufficient stake to slash while allowing for a short average unbonding time.</li>
<li><code>LOWER_BOUND</code>: 28800 blocks (or 2 eras): This value resembles a minimum unbonding time for any stake of 2 days. </li>
<li><code>UPPER_BOUND</code>: 403200 blocks (or 28 eras): This value resembles the maximum time a user faces in their unbonding time. It equals to the current unbonding time and should be familiar to users.</li>
</ul>
<h3 id="rebonding"><a class="header" href="#rebonding">Rebonding</a></h3>
<p>Users that chose to unbond might want to cancel their request and rebond. There is no security loss in doing this, but with the scheme above, it could imply that a large unbond increases the unbonding time for everyone else later in the queue. When the large stake is rebonded, however, the participants later in the queue move forward and can unbond more quickly than originally estimated. It would require an additional extrinsic by the user though.</p>
<p>Thus, we should store the <code>unbonding_time_delta</code> with the unbonding account. If it rebonds when it is still unbonding, then this value should be subtracted from <code>back_of_unbonding_queue_block_number</code>. So unbonding and rebonding leaves this number unaffected. Note that we must store <code>unbonding_time_delta</code>, because in later eras <code>max_unstake</code> might have changed and we cannot recompute it.</p>
<h3 id="empirical-analysis"><a class="header" href="#empirical-analysis">Empirical Analysis</a></h3>
<p>We can use the proposed unbonding queue calculation, with the recommended parameters, and simulate the queue over the course of Polkadot's unbonding history. Instead of doing the analysis on a per-block basis, we calculate it on a daily basis. To simulate the unbonding queue, we require the ratio between the daily total stake of the lowest third backed validators and the daily total stake (which determines the <code>max_unstake</code>) and the sum of daily and newly unbonded tokens. Due to the <a href="https://wiki.polkadot.network/docs/learn-phragmen">NPoS algorithm</a>, the first number has only small variations and we used a constant as approximation (0.287) determined by sampling a bunch of empirical eras. At this point, we want to thank Parity's Data team for allowing us to leverage their data infrastructure in these analyses.</p>
<p>The following graph plots said statistics.</p>
<img src="https://raw.githubusercontent.com/polkadot-fellows/RFCs/fd7dbb2cc6defefaa0c601d463be8fa86347ec4e/text/empirical_analysis.png" alt="Empirical Queue" width="70%">
<p>The abovementioned graph combines two metrics into a single graph. </p>
<ul>
<li><code>Unbonded Amount</code>: The number of daily and newly unbonded token over time scaled to the y-axis of 28 days. In particular its normalized by <code>daily_unbonded / max(daily_unbonded) * 28</code>.</li>
<li><code>Unbonding Days</code>: The daily expected unbonding days given the history of <code>daily_unbonded</code>.</li>
</ul>
<p>We can observe that historical unbonds only trigger an unbonding time larger than <code>LOWER_BOUND</code> in situations with extensive and/or clustered unbonding amounts. The average unbonding time across the whole timeseries is ~2.67 days. We can, however, see it taking effect pushing unbonding times up during large unbonding events. In the largest events, we hit a maximum of 28 days. This gives us reassurance that it is sufficiently sensitive and it makes sense to match the <code>UPPER_BOUND</code> with the historically largest unbonds. </p>
<p>The main parameter affecting the situation is the <code>max_unstake</code>. The relationship is obvious: decreasing the <code>max_unstake</code> makes the queue more sensitive, i.e., having it spike more quickly and higher with unbonding events. Given that these events historically were mostly associated with parachain auctions, we can assume that, in the absence of major systemic events, users will experience drastically reduced unbonding times.
The analysis can be reproduced or changed to other parameters using <a href="https://github.com/jonasW3F/unbonding_queue_analysis">this repository</a>.</p>
<h2 id="additional-considerations"><a class="header" href="#additional-considerations">Additional Considerations</a></h2>
<h3 id="deferred-slashing"><a class="header" href="#deferred-slashing">Deferred slashing</a></h3>
<p>Currently we defer applying many slashes until around 28 days have passed. This was implemented so we can conveniently cancel slashes via governance in the case that the slashing was due to a bug. While rare on Polkadot, such bugs cause a significant fraction of slashes. This includes slashing for attacks other than LRAs for which we've assumed that 2 days is enough to slash. But 2 days in not enough to cancel slashes via OpenGov.</p>
<p>Owing to the way exposures, which nominators back validators with how many tokens, are stored, it is hard to search for whether a nominator has deferred slashes that need to be applied to them on chain as of now. So we cannot simply check when a nominator attempts to withdraw their bond. </p>
<p>We can solve this by freezing the unbonding queue while there are pending slashes in the staking system. In the worst case, where the slash is applied, we would forced all members of the queue to unbond with 28 days minus the days since they are in the queue (i.e., nobody ever needs to wait more than 28 days) and pause the unbonding queue until there are no deferred slashes in the system. This solution is potentially easier to implement but could cause disruptions for unbonding stakers that are not slashed, because they do not benefit from the queue. It is crucial to note that unbonding is still always possible for all stakers in the usual 28 days. Since slashes should occur rarely, this should not cause distruptions in reality too often. In addition, we could further complement the solution by adding a new extrinsic where any account is allowed to point out the unbonding accounts with the deferred slashes. Then, the chain would set the <code>unbonding_block_number</code> of the affected accounts to after the time when the slash would be applied, which will be no more than 28 days from the time the staker unbonded. After removing the offenders from the queue, we could unfreeze the unbonding queue and restore operation for unslashed accounts immediately. To find nominators with deferred slashes it is required, however, to iterate through all nominators, which is only feasible to do off chain. There should be plenty of incentive to do so by the non-slashed unbonding accounts that seek to reduce the opportunity costs of being forced wait potentially much longer than necessary. </p>
<p>This solution achieves resolve the situation securely and, in the worst case where no user submits the extrinsic, no staker would exceed an unbonding duration of the usual 28 days and apply all slashes as intended.</p>
<h3 id="uxui"><a class="header" href="#uxui">UX/UI</a></h3>
<p>As per the nature of the unbonding queue, the more a user slices up their stake to be unbonded, the quicker they find their expected unbonding time. This, however, comes at the cost of creating more and/or larger transactions, i.e., incurring higher transactions costs. We leave it to UI implementations to provide a good UX to inform users about this trade-off and help them find their individual willingness to pay to unbond even faster. For most users, splitting up their stake will not lead to any meaningful advantage because their effect on the queue is neglible.</p>
<h3 id="conviction-voting"><a class="header" href="#conviction-voting">Conviction voting</a></h3>
<p>Changing the (expected) unbonding period has an indirect impact on conviction voting, because the governance locks do not stack with the staking locks. In other words, if a user is already being locked in staking, they can, for free, choose a conviction vote that is lower or equal to that locking time. Currently and with an unbonding period of a fixed 28 days, that means, the <code>3x</code> conviction vote comes essentially for free. There has been discussions to <a href="https://github.com/polkadot-fellows/RFCs/pull/20#issuecomment-1673553108">rescale the conviction weights</a> to improved parametrization. But, the transition between the old locks and new locks pose significant challenges. </p>
<p><strong>We argue, that under our unbonding queue, the current conviction voting scheme logically better aligns with their impact on governance, avoiding an expensive solution to migrate existing locks to a new scheme.</strong> For example, if the average unbonding period is around 2 days from staking, locking tokens for an additional 26 days justifies a higher weight (in that regard of<code>3x</code>). Voters that seek maximum liquidity are free to do so but it is fair to be weighted less in governance decisions that are naturally affecting the long-term success of Polkadot.</p>
<h3 id="potential-extension"><a class="header" href="#potential-extension">Potential Extension</a></h3>
<p>In addition to a simple queue, we could add a market component that lets users always unbond from staking at the minimum possible waiting time)(== <code>LOWER_BOUND</code>, e.g., 2 days), by paying a variable fee. To achieve this, it is reasonable to split the total unbonding capacity into two chunks, with the first capacity for the simple queue and the remaining capacity for the fee-based unbonding. By doing so, we allow users to choose whether they want the quickest unbond and paying a dynamic fee or join the simple queue. Setting a capacity restriction for both queues enables us to guarantee a predictable unbonding time in the simple queue, while allowing users with the respective willingness to pay to get out even earlier. The fees are dynamically adjusted and are proportional to the unbonding stake (and thereby expressed in a percentage of the requested unbonding stake). In contrast to a unified queue, this prevents the issue that users paying a fee jump in front of other users not paying a fee, pushing their unbonding time back (which would be bad for UX). The revenue generated could be burned.</p>
<p>This extension and further specifications are left out of this RFC, because it adds further complexity and the empirical analysis above suggests that average unbonding times will already be close the <code>LOWER_BOUND</code>, making a more complex design unnecessary. We advise to first implement the discussed mechanism and assess after some experience whether an extension is desirable.</p>
<h2 id="drawbacks-38"><a class="header" href="#drawbacks-38">Drawbacks</a></h2>
<ul>
<li><strong>Lower security for LRAs:</strong> Without a doubt, the theoretical security against LRAs decreases. But, as we argue, the attack is still costly enough to deter attacks and the attack is sufficiently theoretical. Here, the benefits outweigh the costs.</li>
<li><strong>Griefing attacks:</strong> A large holder could pretend to unbond a large amount of their tokens to prevent other users to exit the network earlier. This would, however be costly due to the fact that the holder loses out on staking rewards. The larger the impact on the queue, the higher the costs. In any case it must be noted that the <code>UPPER_BOUND</code> is still 28 days, which means that nominators are never left with a longer unbonding period than currently. There is not enough gain for the attacker to endure this cost.</li>
<li><strong>Challenge for Custodians and Liquid Staking Providers</strong>: Changing the unbonding time, especially making it flexible, requires entities that offer staking derivatives to rethink and rework their products.</li>
</ul>
<h2 id="testing-security-and-privacy-37"><a class="header" href="#testing-security-and-privacy-37">Testing, Security, and Privacy</a></h2>
<p>NA</p>
<h2 id="performance-ergonomics-and-compatibility-37"><a class="header" href="#performance-ergonomics-and-compatibility-37">Performance, Ergonomics, and Compatibility</a></h2>
<p>NA</p>
<h3 id="performance-34"><a class="header" href="#performance-34">Performance</a></h3>
<p>The authors cannot see any potential impact on performance.</p>
<h3 id="ergonomics-30"><a class="header" href="#ergonomics-30">Ergonomics</a></h3>
<p>The authors cannot see any potential impact on ergonomics for developers. We discussed potential impact on UX/UI for users above.</p>
<h3 id="compatibility-30"><a class="header" href="#compatibility-30">Compatibility</a></h3>
<p>The authors cannot see any potential impact on compatibility. This should be assessed by the technical fellows.</p>
<h3 id="prior-art-and-references-38"><a class="header" href="#prior-art-and-references-38">Prior Art and References</a></h3>
<ul>
<li>Ethereum proposed a <a href="https://blog.stake.fish/ethereum-staking-all-you-need-to-know-about-the-validator-queue/">similar solution</a></li>
<li>Alistair did some initial <a href="https://hackmd.io/SpzFSNeXQM6YScW1iODC_A">write-up</a></li>
<li>There are <a href="https://arxiv.org/pdf/2208.05408.pdf">other solutions</a> that further mitigate the risk of LRAs.</li>
</ul>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0099-transaction-extension-version.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0099-transaction-extension-version.html#rfc-0099-introduce-a-transaction-extension-version">RFC-0099: Introduce a transaction extension version</a>
<ul>
<li><a href="approved/0099-transaction-extension-version.html#summary">Summary</a></li>
<li><a href="approved/0099-transaction-extension-version.html#motivation">Motivation</a></li>
<li><a href="approved/0099-transaction-extension-version.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0099-transaction-extension-version.html#explanation">Explanation</a></li>
<li><a href="approved/0099-transaction-extension-version.html#drawbacks">Drawbacks</a></li>
<li><a href="approved/0099-transaction-extension-version.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="approved/0099-transaction-extension-version.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="approved/0099-transaction-extension-version.html#performance">Performance</a></li>
<li><a href="approved/0099-transaction-extension-version.html#ergonomics">Ergonomics</a></li>
<li><a href="approved/0099-transaction-extension-version.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="approved/0099-transaction-extension-version.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="approved/0099-transaction-extension-version.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="approved/0099-transaction-extension-version.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0099-introduce-a-transaction-extension-version"><a class="header" href="#rfc-0099-introduce-a-transaction-extension-version">RFC-0099: Introduce a transaction extension version</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>03 July 2024</td></tr>
<tr><td><strong>Description</strong></td><td>Introduce a versioning for transaction extensions.</td></tr>
<tr><td><strong>Authors</strong></td><td>Bastian Köcher</td></tr>
</tbody></table>
</div>
<h2 id="summary-43"><a class="header" href="#summary-43">Summary</a></h2>
<p>This RFC proposes a change to the extrinsic format to include a transaction extension version.</p>
<h2 id="motivation-43"><a class="header" href="#motivation-43">Motivation</a></h2>
<p>The extrinsic format supports to be extended with transaction extensions. These transaction extensions are runtime specific and can be different per chain. Each transaction extension can add data to the extrinsic itself or extend the signed payload.
This means that adding a transaction extension is breaking the chain specific extrinsic format. A recent example was the introduction of the <a href="https://github.com/polkadot-fellows/runtimes/pull/337"><code>CheckMetadatHash</code></a> to Polkadot and all its system chains.
As the extension was adding one byte to the extrinsic, it broke a lot of tooling. By introducing an extra version for the transaction extensions it will be possible to introduce changes to these transaction extensions while still being backwards compatible.
Based on the version of the transaction extensions, each chain runtime could decode the extrinsic correctly and also create the correct signed payload.</p>
<h2 id="stakeholders-42"><a class="header" href="#stakeholders-42">Stakeholders</a></h2>
<ul>
<li>Runtime users</li>
<li>Runtime devs</li>
<li>Wallet devs</li>
</ul>
<h2 id="explanation-42"><a class="header" href="#explanation-42">Explanation</a></h2>
<p><a href="https://github.com/paritytech/polkadot-sdk/issues/2415">RFC84</a> introduced the extrinsic format <code>5</code>. The idea is to piggyback onto this change of the extrinsic format to add the extra version for the transaction extensions. If required, this could also come
as extrinsic format <code>6</code>, but <code>5</code> is not yet deployed anywhere. </p>
<p>The extrinsic format supports the following types of transactions:</p>
<ul>
<li><code>Bare</code>: Does not add anything to the extrinsic.</li>
<li><code>Signed</code>: <code>(Address, Signature, Extensions)</code></li>
<li><code>General</code>: <code>Extensions</code></li>
</ul>
<p>The <code>Signed</code> and <code>General</code> transaction would change to:</p>
<ul>
<li><code>Signed</code>: <code>(Address, Signature, Version, Extensions)</code></li>
<li><code>General</code>: <code>(Version, Extensions)</code></li>
</ul>
<p>The <code>Version</code> being a SCALE encoded <code>u8</code> representing the version of the transaction extensions.</p>
<p>In the chain runtime the version can be used to determine which set of transaction extensions should be used to decode and to validate the transaction.</p>
<h2 id="drawbacks-39"><a class="header" href="#drawbacks-39">Drawbacks</a></h2>
<p>This adds one byte more to each signed transaction. </p>
<h2 id="testing-security-and-privacy-38"><a class="header" href="#testing-security-and-privacy-38">Testing, Security, and Privacy</a></h2>
<p>There is no impact on testing, security or privacy.</p>
<h2 id="performance-ergonomics-and-compatibility-38"><a class="header" href="#performance-ergonomics-and-compatibility-38">Performance, Ergonomics, and Compatibility</a></h2>
<p>This will ensure that changes to the transactions extensions can be done in a backwards compatible way.</p>
<h3 id="performance-35"><a class="header" href="#performance-35">Performance</a></h3>
<p>There is no performance impact.</p>
<h3 id="ergonomics-31"><a class="header" href="#ergonomics-31">Ergonomics</a></h3>
<p>Runtime developers need to take care of the versioning and ensure to bump as required, so that there are no compatibility breaking changes without a bump of the version. It will also add a little bit more code in the runtime
to decode these old versions, but this should be neglectable.</p>
<h3 id="compatibility-31"><a class="header" href="#compatibility-31">Compatibility</a></h3>
<p>When introduced together with extrinsic format version <code>5</code> from <a href="https://github.com/paritytech/polkadot-sdk/issues/2415">RFC84</a>, it can be implemented in a backwards compatible way. So, transactions can still be send using the
old extrinsic format and decoded by the runtime.</p>
<h2 id="prior-art-and-references-39"><a class="header" href="#prior-art-and-references-39">Prior Art and References</a></h2>
<p>None.</p>
<h2 id="unresolved-questions-36"><a class="header" href="#unresolved-questions-36">Unresolved Questions</a></h2>
<p>None.</p>
<h2 id="future-directions-and-related-material-29"><a class="header" href="#future-directions-and-related-material-29">Future Directions and Related Material</a></h2>
<p>None.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0100-xcm-multi-type-asset-transfer.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0100-xcm-multi-type-asset-transfer.html#rfc-0100-new-xcm-instruction-initiateassetstransfer">RFC-0100: New XCM instruction: <code>InitiateAssetsTransfer</code></a>
<ul>
<li><a href="approved/0100-xcm-multi-type-asset-transfer.html#summary">Summary</a></li>
<li><a href="approved/0100-xcm-multi-type-asset-transfer.html#motivation">Motivation</a></li>
<li><a href="approved/0100-xcm-multi-type-asset-transfer.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0100-xcm-multi-type-asset-transfer.html#explanation">Explanation</a>
<ul>
<li><a href="approved/0100-xcm-multi-type-asset-transfer.html#example-usage-transferring-2-different-asset-types-across-3-chains">Example usage: transferring 2 different asset types across 3 chains</a></li>
</ul>
</li>
<li><a href="approved/0100-xcm-multi-type-asset-transfer.html#drawbacks">Drawbacks</a></li>
<li><a href="approved/0100-xcm-multi-type-asset-transfer.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="approved/0100-xcm-multi-type-asset-transfer.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="approved/0100-xcm-multi-type-asset-transfer.html#performance">Performance</a></li>
<li><a href="approved/0100-xcm-multi-type-asset-transfer.html#ergonomics">Ergonomics</a></li>
<li><a href="approved/0100-xcm-multi-type-asset-transfer.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="approved/0100-xcm-multi-type-asset-transfer.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="approved/0100-xcm-multi-type-asset-transfer.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="approved/0100-xcm-multi-type-asset-transfer.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0100-new-xcm-instruction-initiateassetstransfer"><a class="header" href="#rfc-0100-new-xcm-instruction-initiateassetstransfer">RFC-0100: New XCM instruction: <code>InitiateAssetsTransfer</code></a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>11 July 2024</td></tr>
<tr><td><strong>Description</strong></td><td>Add new XCM instruction: <code>InitiateAssetsTransfer</code> for mixing asset transfer types in same XCM</td></tr>
<tr><td><strong>Authors</strong></td><td>Adrian Catangiu</td></tr>
</tbody></table>
</div>
<h2 id="summary-44"><a class="header" href="#summary-44">Summary</a></h2>
<p>This RFC proposes a new instruction that provides a way to initiate on remote chains, asset transfers which
transfer multiple types (teleports, local-reserve, destination-reserve) of assets, using XCM alone.</p>
<p>The currently existing instructions are too opinionated and force each XCM asset transfer to a single
transfer type (teleport, local-reserve, destination-reserve). This results in inability to combine different
types of transfers in single transfer which results in overall poor UX when trying to move assets across
chains.</p>
<h2 id="motivation-44"><a class="header" href="#motivation-44">Motivation</a></h2>
<p>XCM is the de-facto cross-chain messaging protocol within the Polkadot ecosystem, and cross-chain
assets transfers is one of its main use-cases. Unfortunately, in its current spec, it does not support
initiating on a remote chain, one or more transfers that combine assets with different transfer types.<br />
For example, <code>ParachainA</code> cannot instruct <code>AssetHub</code> to teleport <code>ForeignAssetX</code> to <code>ParachainX</code> alongside
<code>USDT</code> (which has to be reserve transferred) using current XCM specification.</p>
<p>There currently exist <code>DepositReserveAsset</code>, <code>InitiateReserveWithdraw</code> and <code>InitiateTeleport</code> instructions
that initiate asset transfers on execution, but they are opinionated in the type of transfer to use.
Combining them is also not possible, because as a result of their individual execution, a message containing
a <code>ClearOrigin</code> instruction is sent to the destination chain, making subsequent transfers impossible after
the first instruction is executed.</p>
<p>The new instruction proposed by this RFC allows an XCM program to describe multiple asset transfer types,
then execute them in one shot with a single <code>remote_xcm</code> program sent to the target chain to effect
the transfer and subsequently clear origin.</p>
<p>Multi-hop asset transfers will benefit from this change by allowing single XCM program to handle multiple
types of transfers and reduce complexity.</p>
<p>Bridge asset transfers greatly benefit from this change by allowing building XCM programs to transfer multiple
assets across multiple hops in a single pseudo-atomic action.<br />
For example, allows single XCM program execution to transfer multiple assets from <code>ParaK</code> on Kusama, through
Kusama Asset Hub, over the bridge through Polkadot Asset Hub with final destination <code>ParaP</code> on Polkadot.</p>
<p>With current XCM, we are limited to doing multiple independent transfers for each individual hop in order to
move both &quot;interesting&quot; assets, but also &quot;supporting&quot; assets (used to pay fees).</p>
<h2 id="stakeholders-43"><a class="header" href="#stakeholders-43">Stakeholders</a></h2>
<ul>
<li>Runtime users</li>
<li>Runtime devs</li>
<li>Wallet devs</li>
<li>dApps devs</li>
</ul>
<h2 id="explanation-43"><a class="header" href="#explanation-43">Explanation</a></h2>
<p>A new instruction <code>InitiateAssetsTransfer</code> is introduced that initiates an assets transfer from the
chain it is executed on, to another chain. The executed transfer is point-to-point (chain-to-chain)
with all of the transfer properties specified in the instruction parameters. The instruction also
allows specifying another XCM program to be executed on the remote chain.
If a transfer requires going through multiple hops, an XCM program can compose this instruction
to be used at every chain along the path, on each hop describing that specific leg of the transfer.</p>
<p><strong>Note:</strong> Transferring assets that require different paths (chains along the way) is <em>not supported
within same XCM</em> because of the async nature of cross chain messages. This new instruction, however,
enables initiating transfers for multiple assets that take the same path even if they require
different transfer types along that path.</p>
<p>The usage and composition model of <code>InitiateAssetsTransfer</code> is the same as with existing
<code>DepositReserveAsset</code>, <code>InitiateReserveWithdraw</code> and <code>InitiateTeleport</code> instructions. The main
difference comes from the ability to handle assets that have different point-to-point transfer type
between A and B. The other benefit is that it also allows specifying remote fee payment and
transparently appends the required remote fees logic to the remote XCM.</p>
<p>We can specify the desired transfer type for some asset(s) using:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>/// Specify which type of asset transfer is required for a particular `(asset, dest)` combination.
pub enum AssetTransferFilter {
/// teleport assets matching `AssetFilter` to `dest`
Teleport(AssetFilter),
/// reserve-transfer assets matching `AssetFilter` to `dest`, using the local chain as reserve
ReserveDeposit(AssetFilter),
/// reserve-transfer assets matching `AssetFilter` to `dest`, using `dest` as reserve
ReserveWithdraw(AssetFilter),
}
<span class="boring">}</span></code></pre></pre>
<p>This RFC proposes 1 new XCM instruction:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>/// Cross-chain transfer matching `assets` in the holding register as follows:
///
/// Assets in the holding register are matched using the given list of `AssetTransferFilter`s,
/// they are then transferred based on their specified transfer type:
///
/// - teleport: burn local assets and append a `ReceiveTeleportedAsset` XCM instruction to
/// the XCM program to be sent onward to the `dest` location,
///
/// - reserve deposit: place assets under the ownership of `dest` within this consensus system
/// (i.e. its sovereign account), and append a `ReserveAssetDeposited` XCM instruction
/// to the XCM program to be sent onward to the `dest` location,
///
/// - reserve withdraw: burn local assets and append a `WithdrawAsset` XCM instruction
/// to the XCM program to be sent onward to the `dest` location,
///
/// The onward XCM is then appended a `ClearOrigin` to allow safe execution of any following
/// custom XCM instructions provided in `remote_xcm`.
///
/// The onward XCM also potentially contains a `BuyExecution` instruction based on the presence
/// of the `remote_fees` parameter (see below).
///
/// If a transfer requires going through multiple hops, an XCM program can compose this instruction
/// to be used at every chain along the path, describing that specific leg of the transfer.
///
/// Parameters:
/// - `dest`: The location of the transfer next hop.
/// - `remote_fees`: If set to `Some(asset_xfer_filter)`, the single asset matching
/// `asset_xfer_filter` in the holding register will be transferred first in the remote XCM
/// program, followed by a `BuyExecution(fee)`, then rest of transfers follow.
/// This guarantees `remote_xcm` will successfully pass a `AllowTopLevelPaidExecutionFrom` barrier.
/// - `remote_xcm`: Custom instructions that will be executed on the `dest` chain. Note that
/// these instructions will be executed after a `ClearOrigin` so their origin will be `None`.
///
/// Safety: No concerns.
///
/// Kind: *Command*.
///
InitiateAssetsTransfer {
destination: Location,
assets: Vec&lt;AssetTransferFilter&gt;,
remote_fees: Option&lt;AssetTransferFilter&gt;,
remote_xcm: Xcm&lt;()&gt;,
}
<span class="boring">}</span></code></pre></pre>
<p>An <code>InitiateAssetsTransfer { .. }</code> instruction shall transfer to <code>dest</code>, all assets in the <code>holding</code> register
that match the provided <code>assets</code> and <code>remote_fees</code> filters.
These filters identify the assets to be transferred as well as the transfer type to be used for transferring
them.
It shall handle the local side of the transfer, then forward an onward XCM to <code>dest</code> for handling
the remote side of the transfer.</p>
<p>It should do so using same mechanisms as existing <code>DepositReserveAsset</code>, <code>InitiateReserveWithdraw</code>, <code>InitiateTeleport</code>
instructions but practically combining all required XCM instructions to be remotely executed into a <em>single</em>
remote XCM program to be sent over to <code>dest</code>.</p>
<p>Furthermore, through <code>remote_fees: Option&lt;AssetTransferFilter&gt;</code>, it shall allow specifying a single asset to be used
for fees on <code>dest</code> chain. This single asset shall be remotely handled/received by the <strong>first instruction</strong> in the
onward XCM and shall be followed by a <code>BuyExecution</code> instruction using it.
If <code>remote_fees</code> is set to <code>None</code>, the <strong>first instruction</strong> in the onward XCM shall be a <code>UnpaidExecution</code> instruction.
The rest of the assets shall be handled by subsequent instructions, thus also finally allowing
<a href="https://github.com/paritytech/polkadot-sdk/issues/2423">single asset buy execution</a> barrier security recommendation.</p>
<p>The <code>BuyExecution</code> appended to the onward XCM specifies <code>WeightLimit::Unlimited</code>, thus being limited only by the
<code>remote_fees</code> asset &quot;amount&quot;. This is a deliberate decision for enhancing UX - in practice, people/dApps care about
limiting the amount of fee asset used and not the actually used weight.</p>
<p>The onward XCM, following the assets transfers instructions, <code>ClearOrigin</code> or <code>DescendOrigin</code> instructions shall be
appended to stop acting on behalf of the source chain, then the caller-provided <code>remote_xcm</code> shall also be appended,
allowing the caller to control what to do with the transferred assets.</p>
<h3 id="example-usage-transferring-2-different-asset-types-across-3-chains"><a class="header" href="#example-usage-transferring-2-different-asset-types-across-3-chains">Example usage: transferring 2 different asset types across 3 chains</a></h3>
<ul>
<li>Transferring ROCs as the native asset of <code>RococoAssetHub</code> and PENs as the native asset of <code>Penpal</code>,</li>
<li>Transfer origin is <code>Penpal</code> (on Rococo) and the destination is <code>WestendAssetHub</code> (across the bridge),</li>
<li>ROCs are native to <code>RococoAssetHub</code> and are registered as trust-backed assets on <code>Penpal</code> and <code>WestendAssetHub</code>,</li>
<li>PENs are native to <code>Penpal</code> and are registered as teleportable assets on <code>RococoAssetHub</code> and as
foreign assets on <code>WestendAssetHub</code>,</li>
<li>Fees on <code>RococoAssetHub</code> and <code>WestendAssetHub</code> are paid using ROCs.</li>
</ul>
<p>We can transfer them from <code>Penpal</code> (Rococo), through <code>RococoAssetHub</code>, over the bridge to <code>WestendAssetHub</code>
by executing a <em>single</em> XCM message, even though we'll be mixing multiple types of transfers along the path:</p>
<ol>
<li>1st leg of the transfer: Penpal -&gt; Rococo Asset Hub:
<ul>
<li>teleport PENs</li>
<li>reserve withdraw ROCs</li>
</ul>
</li>
<li>2nd leg of the transfer: Rococo Asset Hub -&gt; Westend Asset Hub:
<ul>
<li>reserve deposit both PENs and ROCs</li>
</ul>
</li>
</ol>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>Penpal::execute_with(|| {
let destination = Location::new(2, (GlobalConsensus(Westend), Parachain(1000)).into());
let rocs_id: AssetId = Parent.into();
let rocs: Asset = (rocs_id.clone(), rocs_amount).into();
let pens: Asset = (pens_id, pens_amount).into();
let assets: Assets = vec![rocs.clone(), pens.clone()].into();
// XCM to be executed at dest (Westend Asset Hub)
let xcm_on_dest =
Xcm(vec![DepositAsset { assets: Wild(All), beneficiary: beneficiary.clone() }]);
// XCM to be executed at Rococo Asset Hub
let context = PenpalUniversalLocation::get();
let reanchored_assets = assets.clone().reanchored(&amp;local_asset_hub, &amp;context).unwrap();
let reanchored_dest = destination.clone().reanchored(&amp;local_asset_hub, &amp;context).unwrap();
let reanchored_rocs_id = rocs_id.clone().reanchored(&amp;local_asset_hub, &amp;context).unwrap();
// from AHR, both ROCs and PENs are local-reserve transferred to Westend Asset Hub
let assets_filter = vec![
AssetTransferFilter::ReserveDeposit(reanchored_assets.clone().into())
];
// we want to pay with ROCs on WAH
let remote_fees = Some(AssetTransferFilter::ReserveDeposit(
AssetFilter::Wild(AllOf { id: reanchored_rocs_id.into(), fun: WildFungibility::Fungible }))
);
let xcm_on_ahr = Xcm(vec![
InitiateAssetsTransfer {
dest: reanchored_dest,
assets: assets_filter,
remote_fees: Some(),
remote_xcm: xcm_on_dest,
},
]);
// pay remote fees with ROCs
let remote_fees = Some(
AssetTransferFilter::ReserveWithdraw(
AssetFilter::Wild(AllOf { id: rocs_id.into(), fun: WildFungibility::Fungible })
)
);
// XCM to be executed locally
let xcm = Xcm::&lt;penpal_runtime::RuntimeCall&gt;(vec![
// Withdraw both ROCs and PENs from origin account
WithdrawAsset(assets.clone().into()),
// Execute the transfers while paying remote fees with ROCs
InitiateAssetsTransfer {
dest: local_asset_hub,
assets: vec![
// ROCs are reserve-withdrawn on AHR
ReserveWithdraw(rocs.into()),
// PENs are teleported to AHR
Teleport(pens.into()),
],
remote_fees,
remote_xcm: xcm_on_ahr,
},
]);
&lt;Penpal as PenpalPallet&gt;::PolkadotXcm::execute(
signed_origin,
bx!(xcm::VersionedXcm::V4(xcm.into())),
Weight::MAX,
).unwrap();
})
<span class="boring">}</span></code></pre></pre>
<h2 id="drawbacks-40"><a class="header" href="#drawbacks-40">Drawbacks</a></h2>
<p>No drawbacks identified.</p>
<h2 id="testing-security-and-privacy-39"><a class="header" href="#testing-security-and-privacy-39">Testing, Security, and Privacy</a></h2>
<p>There should be no security risks related to the new instruction from the XCVM perspective. It follows the same
pattern as with single-type asset transfers, only now it allows combining multiple types at once.</p>
<p><em>Improves</em> security by enabling
<a href="https://github.com/paritytech/polkadot-sdk/issues/2423">enforcement of single asset for buying execution</a>,
which minimizes the potential free/unpaid work that a receiving chain has to do. It does so, by making the
required execution fee payment, part of the instruction logic through the <code>remote_fees: Option&lt;AssetTransferFilter&gt;</code>
parameter, which will make sure the remote XCM starts with a single-asset-holding-loading-instruction,
immediately followed by a <code>BuyExecution</code> using said asset.</p>
<h2 id="performance-ergonomics-and-compatibility-39"><a class="header" href="#performance-ergonomics-and-compatibility-39">Performance, Ergonomics, and Compatibility</a></h2>
<p>This brings no impact to the rest of the XCM spec. It is a new, independent instruction, no changes to existing instructions.</p>
<p>Enhances the exposed functionality of Polkadot. Will allow multi-chain transfers that are currently forced to happen in
multiple programs per asset per &quot;hop&quot;, to be possible in a single XCM program.</p>
<h3 id="performance-36"><a class="header" href="#performance-36">Performance</a></h3>
<p>No performance changes/implications.</p>
<h3 id="ergonomics-32"><a class="header" href="#ergonomics-32">Ergonomics</a></h3>
<p>The proposal enhances developers' and users' cross-chain asset transfer capabilities. This enhancement is optimized for XCM
programs transferring multiple assets, needing to run their logic across multiple chains.</p>
<h3 id="compatibility-32"><a class="header" href="#compatibility-32">Compatibility</a></h3>
<p>Does this proposal break compatibility with existing interfaces, older versions of implementations? Summarize necessary
migrations or upgrade strategies, if any.</p>
<p>This enhancement is compatible with all <strong>existing</strong> XCM programs and versions.</p>
<p>New (XCMv5) programs using this instruction shall be best-effort downgraded to an older XCM version, but cannot guarantee
success.
A program where the new instruction is used to initiate multiple types of asset transfers, cannot be downgraded to older
XCM versions, because there is no equivalent capability there.
Such conversion attempts will explicitly fail.</p>
<h2 id="prior-art-and-references-40"><a class="header" href="#prior-art-and-references-40">Prior Art and References</a></h2>
<p>None.</p>
<h2 id="unresolved-questions-37"><a class="header" href="#unresolved-questions-37">Unresolved Questions</a></h2>
<p>None.</p>
<h2 id="future-directions-and-related-material-30"><a class="header" href="#future-directions-and-related-material-30">Future Directions and Related Material</a></h2>
<p>None.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0101-xcm-transact-remove-max-weight-param.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0101-xcm-transact-remove-max-weight-param.html#rfc-0101-xcm-transact-remove-require_weight_at_most-parameter">RFC-0101: XCM Transact remove <code>require_weight_at_most</code> parameter</a>
<ul>
<li><a href="approved/0101-xcm-transact-remove-max-weight-param.html#summary">Summary</a></li>
<li><a href="approved/0101-xcm-transact-remove-max-weight-param.html#motivation">Motivation</a></li>
<li><a href="approved/0101-xcm-transact-remove-max-weight-param.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0101-xcm-transact-remove-max-weight-param.html#explanation">Explanation</a></li>
<li><a href="approved/0101-xcm-transact-remove-max-weight-param.html#drawbacks">Drawbacks</a></li>
<li><a href="approved/0101-xcm-transact-remove-max-weight-param.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="approved/0101-xcm-transact-remove-max-weight-param.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="approved/0101-xcm-transact-remove-max-weight-param.html#performance">Performance</a></li>
<li><a href="approved/0101-xcm-transact-remove-max-weight-param.html#ergonomics">Ergonomics</a></li>
<li><a href="approved/0101-xcm-transact-remove-max-weight-param.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="approved/0101-xcm-transact-remove-max-weight-param.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="approved/0101-xcm-transact-remove-max-weight-param.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="approved/0101-xcm-transact-remove-max-weight-param.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0101-xcm-transact-remove-require_weight_at_most-parameter"><a class="header" href="#rfc-0101-xcm-transact-remove-require_weight_at_most-parameter">RFC-0101: XCM Transact remove <code>require_weight_at_most</code> parameter</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>12 July 2024</td></tr>
<tr><td><strong>Description</strong></td><td>Remove <code>require_weight_at_most</code> parameter from XCM Transact</td></tr>
<tr><td><strong>Authors</strong></td><td>Adrian Catangiu</td></tr>
</tbody></table>
</div>
<h2 id="summary-45"><a class="header" href="#summary-45">Summary</a></h2>
<p>The <code>Transact</code> XCM instruction currently forces the user to set a specific maximum weight allowed to the inner call and then also pay for that much weight regardless of how much the call actually needs in practice.</p>
<p>This RFC proposes improving the usability of <code>Transact</code> by removing that parameter and instead get and charge the actual weight of the inner call from its dispatch info on the remote chain.</p>
<h2 id="motivation-45"><a class="header" href="#motivation-45">Motivation</a></h2>
<p>The UX of using <code>Transact</code> is poor because of having to guess/estimate the <code>require_weight_at_most</code> weight used by the inner call on the target.</p>
<p>We've seen multiple <code>Transact</code> on-chain failures caused by guessing wrong values for this <code>require_weight_at_most</code> even though the rest of the XCM program would have worked.</p>
<p>In practice, this parameter only adds UX overhead with no real practical value. Use cases fall in one of two categories:</p>
<ol>
<li>Unpaid execution of Transacts - in these cases the <code>require_weight_at_most</code> is not really useful, caller doesn't
have to pay for it, and on the call site it either fits the block or not;</li>
<li>Paid execution of <em>single</em> Transact - the weight to be spent by the Transact is already covered by the <code>BuyExecution</code>
weight limit parameter.</li>
</ol>
<p>We've had multiple OpenGov <code>root/whitelisted_caller</code> proposals initiated by core-devs completely or partially fail
because of incorrect configuration of <code>require_weight_at_most</code> parameter. This is a strong indication that the
instruction is hard to use.</p>
<h2 id="stakeholders-44"><a class="header" href="#stakeholders-44">Stakeholders</a></h2>
<ul>
<li>Runtime Users,</li>
<li>Runtime Devs,</li>
<li>Wallets,</li>
<li>dApps,</li>
</ul>
<h2 id="explanation-44"><a class="header" href="#explanation-44">Explanation</a></h2>
<p>The proposed enhancement is simple: remove <code>require_weight_at_most</code> parameter from the instruction:</p>
<pre><code class="language-diff">- Transact { origin_kind: OriginKind, require_weight_at_most: Weight, call: DoubleEncoded&lt;Call&gt; },
+ Transact { origin_kind: OriginKind, call: DoubleEncoded&lt;Call&gt; },
</code></pre>
<p>The XCVM implementation shall no longer use <code>require_weight_at_most</code> for weighing. Instead, it shall weigh the Transact instruction by decoding and weighing the inner <code>call</code>.</p>
<h2 id="drawbacks-41"><a class="header" href="#drawbacks-41">Drawbacks</a></h2>
<p>No drawbacks, existing scenarios work as before, while this also allows new/easier flows.</p>
<h2 id="testing-security-and-privacy-40"><a class="header" href="#testing-security-and-privacy-40">Testing, Security, and Privacy</a></h2>
<p>Currently, an XCVM implementation can weigh a message just by looking at the decoded instructions without decoding the Transact's call, but assuming <code>require_weight_at_most</code> weight for it. With the new version it has to decode the inner call to know its actual weight.</p>
<p>But this does not actually change the security considerations, as can be seen below.</p>
<p>With the new <code>Transact</code> the weighing happens after decoding the inner <code>call</code>. The entirety of the XCM program containing this <code>Transact</code> needs to be either covered by enough bought weight using a <code>BuyExecution</code>, or the origin has to be allowed to do free execution.</p>
<p>The security considerations around how much can someone execute for free are the same for
both this new version and the old. In both cases, an &quot;attacker&quot; can do the XCM decoding (including Transact inner <code>call</code>s) for free by adding a large enough <code>BuyExecution</code> without actually having the funds available.</p>
<p>In both cases, decoding is done for free, but in both cases execution fails early on <code>BuyExecution</code>.</p>
<h2 id="performance-ergonomics-and-compatibility-40"><a class="header" href="#performance-ergonomics-and-compatibility-40">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-37"><a class="header" href="#performance-37">Performance</a></h3>
<p>No performance change.</p>
<h3 id="ergonomics-33"><a class="header" href="#ergonomics-33">Ergonomics</a></h3>
<p>Ergonomics are slightly improved by simplifying <code>Transact</code> API.</p>
<h3 id="compatibility-33"><a class="header" href="#compatibility-33">Compatibility</a></h3>
<p>Compatible with previous XCM programs.</p>
<h2 id="prior-art-and-references-41"><a class="header" href="#prior-art-and-references-41">Prior Art and References</a></h2>
<p>None.</p>
<h2 id="unresolved-questions-38"><a class="header" href="#unresolved-questions-38">Unresolved Questions</a></h2>
<p>None.</p>
<h2 id="future-directions-and-related-material-31"><a class="header" href="#future-directions-and-related-material-31">Future Directions and Related Material</a></h2>
<p>None.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0103-introduce-core-index-commitment.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0103-introduce-core-index-commitment.html#rfc-0103--introduce-a-coreindex-commitment-and-a-sessionindex-field-in-candidate-receipts">RFC-0103: Introduce a <code>CoreIndex</code> commitment and a <code>SessionIndex</code> field in candidate receipts</a>
<ul>
<li><a href="approved/0103-introduce-core-index-commitment.html#summary">Summary</a></li>
<li><a href="approved/0103-introduce-core-index-commitment.html#motivation">Motivation</a></li>
<li><a href="approved/0103-introduce-core-index-commitment.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0103-introduce-core-index-commitment.html#explanation">Explanation</a>
<ul>
<li><a href="approved/0103-introduce-core-index-commitment.html#reclaiming-unused-space-in-the-descriptor">Reclaiming unused space in the descriptor</a></li>
<li><a href="approved/0103-introduce-core-index-commitment.html#ump-transport">UMP transport</a></li>
<li><a href="approved/0103-introduce-core-index-commitment.html#polkadot-primitive-changes">Polkadot Primitive changes</a></li>
<li><a href="approved/0103-introduce-core-index-commitment.html#backwards-compatibility">Backwards compatibility</a></li>
<li><a href="approved/0103-introduce-core-index-commitment.html#parachain-block-validation">Parachain block validation</a></li>
<li><a href="approved/0103-introduce-core-index-commitment.html#on-chain-backing">On-chain backing</a></li>
</ul>
</li>
<li><a href="approved/0103-introduce-core-index-commitment.html#drawbacks">Drawbacks</a></li>
<li><a href="approved/0103-introduce-core-index-commitment.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="approved/0103-introduce-core-index-commitment.html#performance">Performance</a></li>
<li><a href="approved/0103-introduce-core-index-commitment.html#ergonomics">Ergonomics</a></li>
<li><a href="approved/0103-introduce-core-index-commitment.html#compatibility">Compatibility</a>
<ul>
<li><a href="approved/0103-introduce-core-index-commitment.html#relay-chain-runtime">Relay chain runtime</a></li>
<li><a href="approved/0103-introduce-core-index-commitment.html#validators">Validators</a></li>
<li><a href="approved/0103-introduce-core-index-commitment.html#tooling">Tooling</a></li>
</ul>
</li>
<li><a href="approved/0103-introduce-core-index-commitment.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="approved/0103-introduce-core-index-commitment.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="approved/0103-introduce-core-index-commitment.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0103--introduce-a-coreindex-commitment-and-a-sessionindex-field-in-candidate-receipts"><a class="header" href="#rfc-0103--introduce-a-coreindex-commitment-and-a-sessionindex-field-in-candidate-receipts">RFC-0103: Introduce a <code>CoreIndex</code> commitment and a <code>SessionIndex</code> field in candidate receipts</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>15 July 2024</td></tr>
<tr><td><strong>Description</strong></td><td>Constrain parachain block validity to a specific core and session</td></tr>
<tr><td><strong>Authors</strong></td><td>Andrei Sandu</td></tr>
</tbody></table>
</div>
<h2 id="summary-46"><a class="header" href="#summary-46">Summary</a></h2>
<p>Elastic scaling is not resilient against griefing attacks without a way for a PoV (Proof of Validity)
to commit to the particular core index it was intended for. This RFC proposes a way to include
core index information in the candidate commitments and the <code>CandidateDescriptor</code> data structure
in a backward compatible way. Additionally, it proposes the addition of a <code>SessionIndex</code> field in
the <code>CandidateDescriptor</code> to make dispute resolution more secure and robust.</p>
<h2 id="motivation-46"><a class="header" href="#motivation-46">Motivation</a></h2>
<p>This RFC proposes a way to solve two different problems:</p>
<ol>
<li>For Elastic Scaling, it prevents anyone who has acquired a valid collation to DoS the parachain
by providing the same collation to all backing groups assigned to the parachain. This can
happen before the next valid parachain block is authored and will prevent the chain of
candidates from being formed, reducing the throughput of the parachain to a single core.</li>
<li>The dispute protocol relies on validators trusting the session index provided by other
validators when initiating and participating in disputes. It is used to look up validator keys
and check dispute vote signatures. By adding a <code>SessionIndex</code> in the <code>CandidateDescriptor</code>,
validators no longer have to trust the <code>Sessionindex</code> provided by the validator raising a
dispute. The dispute may concern a relay chain block not yet imported by a
validator. In this case, validators can safely assume the session index refers to the session
the candidate has appeared in, otherwise, the chain would have rejected the candidate.</li>
</ol>
<h2 id="stakeholders-45"><a class="header" href="#stakeholders-45">Stakeholders</a></h2>
<ul>
<li>Polkadot core developers.</li>
<li>Cumulus node developers.</li>
<li>Tooling, block explorer developers.</li>
</ul>
<p>This approach and alternatives have been considered and discussed in <a href="https://github.com/polkadot-fellows/RFCs/issues/92">this issue</a>.</p>
<h2 id="explanation-45"><a class="header" href="#explanation-45">Explanation</a></h2>
<p>The approach proposed below was chosen primarily because it minimizes the number of breaking
changes, the complexity and takes less implementation and testing time. The proposal is to change
the existing primitives while keeping binary compatibility with the older versions. We repurpose
unused fields to introduce core index and a session index information in the <code>CandidateDescriptor</code>
and extend the UMP to transport non-XCM messages.</p>
<h3 id="reclaiming-unused-space-in-the-descriptor"><a class="header" href="#reclaiming-unused-space-in-the-descriptor">Reclaiming unused space in the descriptor</a></h3>
<p>The <code>CandidateDescriptor</code> includes <code>collator</code> and <code>signature</code> fields. The collator
includes a signature on the following descriptor fields: parachain id, relay parent, validation
data hash, validation code hash, and the PoV hash.</p>
<p>However, in practice, having a collator signature in the receipt on the relay chain does not
provide any benefits as there is no mechanism to punish or reward collators that have provided
bad parachain blocks.</p>
<p>This proposal aims to remove the collator signature and all the logic that checks the collator
signatures of candidate receipts. We use the first 7 reclaimed bytes to represent the version,
the core, session index, and fill the rest with zeroes. So, there is no change in the layout
and length of the receipt. The new primitive is binary-compatible with the old one.</p>
<h3 id="ump-transport"><a class="header" href="#ump-transport">UMP transport</a></h3>
<p><a href="https://github.com/paritytech/polkadot-sdk/blob/b5029eb4fd6c7ffd8164b2fe12b71bad0c59c9f2/polkadot/primitives/src/v7/mod.rs#L682">CandidateCommitments</a>
remains unchanged as we will store scale encoded <code>UMPSignal</code> messages directly in the parachain
UMP queue by outputting them in <a href="https://github.com/paritytech/polkadot-sdk/blob/b5029eb4fd6c7ffd8164b2fe12b71bad0c59c9f2/polkadot/primitives/src/v7/mod.rs#L684">upward_messages</a>.</p>
<p>The UMP queue layout is changed to allow the relay chain to receive both the XCM messages and
<code>UMPSignal</code> messages. An empty message (empty <code>Vec&lt;u8&gt;</code>) is used to mark the end of XCM messages and
the start of <code>UMPSignal</code> messages. The <code>UMPSignal</code> is optional and can be omitted by parachains
not using elastic scaling.</p>
<p>This way of representing the new messages has been chosen over introducing an enum wrapper to
minimize breaking changes of XCM message decoding in tools like Subscan for example.</p>
<p>Example:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>[ XCM message1, XCM message2, ..., EMPTY message, UMPSignal::SelectCore ]
<span class="boring">}</span></code></pre></pre>
<h4 id="umpsignal-messages"><a class="header" href="#umpsignal-messages"><code>UMPSignal</code> messages</a></h4>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>/// The selector that determines the core index.
pub struct CoreSelector(pub u8);
/// The offset in the relay chain claim queue.
///
/// The state of the claim queue is given by the relay chain block
/// that is used as context for the `PoV`.
pub struct ClaimQueueOffset(pub u8);
/// Signals sent by a parachain to the relay chain.
pub enum UMPSignal {
/// A message sent by a parachain to select the core the candidate is committed to.
/// Relay chain validators, in particular backers, use the `CoreSelector` and `ClaimQueueOffset`
/// to compute the index of the core the candidate has committed to.
SelectCore(CoreSelector, ClaimQueueOffset),
}
<span class="boring">}</span></code></pre></pre>
<p>The <code>CoreSelector</code> together with the <code>ClaimQueueOffset</code> are used to index the claim queue. This way
the validators can compute the <code>CoreIndex</code> and ensure that the collator put the correct <code>CoreIndex</code>
into the <code>CandidateDescriptor</code>.</p>
<p><strong>Example:</strong></p>
<p><code>cq_offset = 1</code> and <code>core_selector = 3</code></p>
<p>The table below represents a snapshot of the claim queue:</p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: center"></th><th style="text-align: center">offset = 0</th><th style="text-align: center">offset = 1</th><th style="text-align: center">offset = 2</th></tr></thead><tbody>
<tr><td style="text-align: center">Core 1</td><td style="text-align: center"><strong>Para A</strong></td><td style="text-align: center"><strong>Para A</strong></td><td style="text-align: center"><strong>Para A</strong></td></tr>
<tr><td style="text-align: center">Core 2</td><td style="text-align: center"><strong>Para A</strong></td><td style="text-align: center">Para B</td><td style="text-align: center"><strong>Para A</strong></td></tr>
<tr><td style="text-align: center">Core 3</td><td style="text-align: center">Para B</td><td style="text-align: center"><strong>Para A</strong></td><td style="text-align: center"><strong>Para A</strong></td></tr>
</tbody></table>
</div>
<p>The purpose of <code>ClaimQueueOffset</code> is to select the column from the above table.
For <code>cq_offset = 1</code> we get <code>[Para A, Para B, Para A]</code> and use as input to create
a sorted vec with the cores A is assigned to: <code>[Core 1, Core 3]</code> and call it <code>para_assigned_cores</code>.
We use <code>core_selector</code> and determine the committed core index is <code>Core 3</code> like this:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>let committed_core_index = para_assigned_cores[core_selector % para_assigned_cores.len()];
<span class="boring">}</span></code></pre></pre>
<h3 id="polkadot-primitive-changes"><a class="header" href="#polkadot-primitive-changes">Polkadot Primitive changes</a></h3>
<h4 id="new-candidatedescriptor"><a class="header" href="#new-candidatedescriptor">New <a href="https://github.com/paritytech/polkadot-sdk/blob/b5029eb4fd6c7ffd8164b2fe12b71bad0c59c9f2/polkadot/primitives/src/v7/mod.rs#L512">CandidateDescriptor</a></a></h4>
<ul>
<li>reclaim 32 bytes from <code>collator: CollatorId</code> and 64 bytes from <code>signature: CollatorSignature</code>
and rename to <code>reserved1</code> and <code>reserved2</code> fields.</li>
<li>take 1 bytes from <code>reserved1</code> for a new <code>version: u8</code> field.</li>
<li>take 2 bytes from <code>reserved1</code> for a new <code>core_index: u16</code> field.</li>
<li>take 4 bytes from <code>reserved1</code> for a new <code>session_index: u32</code> field.</li>
<li>the remaining <code>reserved1</code> and <code>reserved2</code> fields are zeroed</li>
</ul>
<p>The new primitive will look like this:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>pub struct CandidateDescriptorV2&lt;H = Hash&gt; {
/// The ID of the para this is a candidate for.
para_id: ParaId,
/// The hash of the relay-chain block this is executed in the context of.
relay_parent: H,
/// Version field. The raw value here is not exposed, instead, it is used
/// to determine the `CandidateDescriptorVersion`
version: InternalVersion,
/// The core index where the candidate is backed.
core_index: u16,
/// The session in which the candidate is backed.
session_index: SessionIndex,
/// Reserved bytes.
reserved1: [u8; 25],
/// The blake2-256 hash of the persisted validation data. This is extra data derived from
/// relay-chain state which may vary based on bitfields included before the candidate.
/// Thus it cannot be derived entirely from the relay parent.
persisted_validation_data_hash: Hash,
/// The blake2-256 hash of the PoV.
pov_hash: Hash,
/// The root of a block's erasure encoding Merkle tree.
erasure_root: Hash,
/// Reserved bytes.
reserved2: [u8; 64],
/// Hash of the para header that is being generated by this candidate.
para_head: Hash,
/// The blake2-256 hash of the validation code bytes.
validation_code_hash: ValidationCodeHash,
}
<span class="boring">}</span></code></pre></pre>
<p>In future format versions, parts of the <code>reserved1</code> and <code>reserved2</code> bytes can be used to include
additional information in the descriptor.</p>
<h3 id="backwards-compatibility"><a class="header" href="#backwards-compatibility">Backwards compatibility</a></h3>
<p>Two flavors of candidate receipts are used in network protocols, runtime and node
implementation:</p>
<ul>
<li><code>CommittedCandidateReceipt</code> which includes the <code>CandidateDescriptor</code> and the <code>CandidateCommitments</code></li>
<li><code>CandidateReceipt</code> which includes the <code>CandidateDescriptor</code> and just a hash of the commitments</li>
</ul>
<p>We want to support both the old and new versions in the runtime and node, so the implementation must
be able to detect the version of a given candidate receipt.</p>
<p>The version of the descriptor is detected by checking the reserved fields.
If they are not zeroed, it means it is a version 1 descriptor. Otherwise the <code>version</code> field
is used further to determine the version. It should be <code>0</code> for version 2 descriptors. If it is not
the descriptor has an unknown version and should be considered invalid.</p>
<h3 id="parachain-block-validation"><a class="header" href="#parachain-block-validation">Parachain block validation</a></h3>
<p>If the candidate descriptor is version 1, there are no changes.</p>
<p>Backers must check the validity of <code>core_index</code> and <code>session_index</code> fields.
A candidate must not be backed if any of the following are true:</p>
<ul>
<li>the <code>core_index</code> in the descriptor does not match the core the backer is assigned to</li>
<li>the <code>session_index</code> is not equal to the session index the candidate is backed in</li>
<li>the <code>core_index</code> in the descriptor does not match the one determined by the
<code>UMPSignal::SelectCore</code> message</li>
</ul>
<h3 id="on-chain-backing"><a class="header" href="#on-chain-backing">On-chain backing</a></h3>
<p>If the candidate descriptor is version 1, there are no changes.</p>
<p>For version 2 descriptors the runtime will determine the <code>core_index</code> using the same inputs
as backers did off-chain. It currently stores the claim queue at the newest allowed
relay parent corresponding to the claim queue offset <code>0</code>. The runtime needs to be changed to store
a claim queue snapshot at all allowed relay parents.</p>
<h2 id="drawbacks-42"><a class="header" href="#drawbacks-42">Drawbacks</a></h2>
<p>The only drawback is that further additions to the descriptor are limited to the amount of
remaining unused space.</p>
<h2 id="testing-security-and-privacy-41"><a class="header" href="#testing-security-and-privacy-41">Testing, Security, and Privacy</a></h2>
<p>Standard testing (unit tests, CI zombienet tests) for functionality and mandatory security audit
to ensure the implementation does not introduce any new security issues.</p>
<p>Backward compatibility of the implementation will be tested on testnets (Versi and Westend).</p>
<p>There is no impact on privacy.</p>
<h2 id="performance-38"><a class="header" href="#performance-38">Performance</a></h2>
<p>Overall performance will be improved by not checking the collator signatures in runtime and nodes.
The impact on the UMP queue and candidate receipt processing is negligible.</p>
<p>The <code>ClaimQueueOffset</code> along with the relay parent choice allows parachains to optimize their
block production for either throughput or lower XCM message processing latency. A value of <code>0</code>
with the newest relay parent provides the best latency while picking older relay parents avoids
re-orgs.</p>
<h2 id="ergonomics-34"><a class="header" href="#ergonomics-34">Ergonomics</a></h2>
<p>It is mandatory for elastic parachains to switch to the new receipt format and commit to a
core by sending the <code>UMPSignal::SelectCore</code> message. It is optional but desired that all
parachains switch to the new receipts for providing the session index for disputes.</p>
<p>The implementation of this RFC itself must not introduce any breaking changes for the parachain
runtime or collator nodes.</p>
<h2 id="compatibility-34"><a class="header" href="#compatibility-34">Compatibility</a></h2>
<p>The proposed changes are not fully backward compatible, because older validators verify the
collator signature of candidate descriptors.</p>
<p>Additional care must be taken before enabling the new descriptors by waiting for at least
<code>2/3 + 1</code> validators to upgrade. Validators that have not upgraded will not back candidates
using the new descriptor format and will also initiate disputes against these candidates.</p>
<h3 id="relay-chain-runtime"><a class="header" href="#relay-chain-runtime">Relay chain runtime</a></h3>
<p>The first step is to remove collator signature checking logic in the runtime but keep the node
side collator signature checks.</p>
<p>The runtime must be upgraded to support the new primitives before any collator or node is allowed
to use the new candidate receipts format.</p>
<h3 id="validators"><a class="header" href="#validators">Validators</a></h3>
<p>To ensure a smooth launch, a new node feature is required.
The feature acts as a signal for supporting the new candidate receipts on the node side and can
only be safely enabled if at least <code>2/3 + 1</code> of the validators are upgraded. Node implementations
need to decode the new candidate descriptor once the feature is enabled otherwise they might
raise disputes and get slashed.</p>
<p>Once the feature is enabled, the validators will skip checking the collator signature when
processing the candidate receipts and verify the <code>CoreIndex</code> and <code>SessionIndex</code> fields if
present in the receipt.</p>
<p>No new implementation of networking protocol versions for collation and validation is required.</p>
<h3 id="tooling"><a class="header" href="#tooling">Tooling</a></h3>
<p>Any tooling that decodes UMP XCM messages needs an update to support or ignore the new UMP
messages, but they should be fine to decode the regular XCM messages that come before the
separator.</p>
<h2 id="prior-art-and-references-42"><a class="header" href="#prior-art-and-references-42">Prior Art and References</a></h2>
<p>Forum discussion about a new <code>CandidateReceipt</code> format:
<a href="https://forum.polkadot.network/t/pre-rfc-discussion-candidate-receipt-format-v2/3738">https://forum.polkadot.network/t/pre-rfc-discussion-candidate-receipt-format-v2/3738</a></p>
<h2 id="unresolved-questions-39"><a class="header" href="#unresolved-questions-39">Unresolved Questions</a></h2>
<p>N/A</p>
<h2 id="future-directions-and-related-material-32"><a class="header" href="#future-directions-and-related-material-32">Future Directions and Related Material</a></h2>
<p>The implementation is extensible and future-proof to some extent. With minimal or no breaking
changes, additional fields can be added in the candidate descriptor until the reserved space is
exhausted</p>
<p>At this point, there is a simple way to determine the version of the receipt, by testing for zeroed
reserved bytes in the descriptor. Future versions of the receipt can be implemented and identified
by using the <code>version</code> field of the descriptor introduced in this RFC.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0105-xcm-improved-fee-mechanism.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0105-xcm-improved-fee-mechanism.html#rfc-0105-xcm-improved-fee-mechanism">RFC-0105: XCM improved fee mechanism</a>
<ul>
<li><a href="approved/0105-xcm-improved-fee-mechanism.html#summary">Summary</a></li>
<li><a href="approved/0105-xcm-improved-fee-mechanism.html#motivation">Motivation</a></li>
<li><a href="approved/0105-xcm-improved-fee-mechanism.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0105-xcm-improved-fee-mechanism.html#explanation">Explanation</a>
<ul>
<li><a href="approved/0105-xcm-improved-fee-mechanism.html#examples">Examples</a></li>
</ul>
</li>
<li><a href="approved/0105-xcm-improved-fee-mechanism.html#drawbacks">Drawbacks</a></li>
<li><a href="approved/0105-xcm-improved-fee-mechanism.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="approved/0105-xcm-improved-fee-mechanism.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="approved/0105-xcm-improved-fee-mechanism.html#performance">Performance</a></li>
<li><a href="approved/0105-xcm-improved-fee-mechanism.html#ergonomics">Ergonomics</a></li>
<li><a href="approved/0105-xcm-improved-fee-mechanism.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="approved/0105-xcm-improved-fee-mechanism.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="approved/0105-xcm-improved-fee-mechanism.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="approved/0105-xcm-improved-fee-mechanism.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0105-xcm-improved-fee-mechanism"><a class="header" href="#rfc-0105-xcm-improved-fee-mechanism">RFC-0105: XCM improved fee mechanism</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>23 July 2024</td></tr>
<tr><td><strong>Description</strong></td><td>Allow multiple types of fees to be paid</td></tr>
<tr><td><strong>Authors</strong></td><td>Francisco Aguirre</td></tr>
</tbody></table>
</div>
<h2 id="summary-47"><a class="header" href="#summary-47">Summary</a></h2>
<p>XCM already handles execution fees in an effective and efficient manner using the <code>BuyExecution</code> instruction.
However, other types of fees are not handled as effectively -- for example, delivery fees.
Fees exist that can't be measured using <code>Weight</code> -- as execution fees can -- so a new method should be thought up for those cases.
This RFC proposes making the fee handling system simpler and more general, by doing two things:</p>
<ul>
<li>Adding a <code>fees</code> register</li>
<li>Deprecating <code>BuyExecution</code> and adding a new instruction <code>PayFees</code> with new semantics to ultimately replace it.</li>
</ul>
<h2 id="motivation-47"><a class="header" href="#motivation-47">Motivation</a></h2>
<p>Execution fees are handled correctly by XCM right now.
However, the addition of extra fees, like for message delivery, result in awkward ways of integrating them into the XCVM implementation.
This is because these types of fees are not included in the language.
The standard should have a way to correctly deal with these implementation specific fees, that might not exist in every system that uses XCM.
The new instruction moves the specified amount of fees from the holding register to a dedicated fees register that the XCVM can use in flexible ways depending on its implementation.
The XCVM implementation is free to use these fees to pay for execution fees, transport fees, or any other type of fee that might be necessary.
This moves the specifics of fees further away from the XCM standard, and more into the actual underlying XCVM implementation, which is a good thing.</p>
<h2 id="stakeholders-46"><a class="header" href="#stakeholders-46">Stakeholders</a></h2>
<ul>
<li>Runtime Users</li>
<li>Runtime Devs</li>
<li>Wallets</li>
<li>dApps</li>
</ul>
<h2 id="explanation-46"><a class="header" href="#explanation-46">Explanation</a></h2>
<p>The new instruction that will replace <code>BuyExecution</code> is a much simpler and general version: <code>PayFees</code>.
This instruction takes one <code>Asset</code>, takes it from the holding register, and puts it into a new <code>fees</code> register.
The XCVM implementation can now use this <code>Asset</code> to make sure every necessary fee is paid for, this includes execution fees, delivery fees, and any other type of fee
necessary for the program to execute successfully.</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>PayFees { asset: Asset }
<span class="boring">}</span></code></pre></pre>
<p>This new instruction will reserve <strong>the entirety</strong> of the <code>asset</code> operand for fee payment.
There is not concept of returning the leftover fees to the holding register, to allow for the implementation to charge fees at different points during execution.
Because of this, the <code>asset</code> passed in can't be used for anything else during the entirety of the program.
This is different from the current semantics of <code>BuyExecution</code>.</p>
<p>If not all <code>Asset</code> in the <code>fees</code> register is used when the execution ends, then we trap them alongside any possible leftover assets from the holding register.
<code>RefundSurplus</code> can be used to move all leftover fees from the <code>fees</code> register to the <code>holding</code> register.
Care must be taken that this is used only after all possible instructions which might charge fees, else execution will fail.</p>
<h3 id="examples"><a class="header" href="#examples">Examples</a></h3>
<p>Most XCM programs that pay for execution are written like so:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>// Instruction that loads the holding register
BuyExecution { asset, weight_limit }
// ...rest
<span class="boring">}</span></code></pre></pre>
<p>With this RFC, the structure would be the same, but using the new instruction, that has different semantics:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>// Instruction that loads the holding register
PayFees { asset }
// ...rest
<span class="boring">}</span></code></pre></pre>
<h2 id="drawbacks-43"><a class="header" href="#drawbacks-43">Drawbacks</a></h2>
<p>There needs to be an explicit change from <code>BuyExecution</code> to <code>PayFees</code>, most often accompanied by a reduction in the assets passed in.</p>
<h2 id="testing-security-and-privacy-42"><a class="header" href="#testing-security-and-privacy-42">Testing, Security, and Privacy</a></h2>
<p>It might become a security concern if leftover fees are trapped, since a lot of them are expected.</p>
<h2 id="performance-ergonomics-and-compatibility-41"><a class="header" href="#performance-ergonomics-and-compatibility-41">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-39"><a class="header" href="#performance-39">Performance</a></h3>
<p>There should be no performance downsides to this approach.
The <code>fees</code> register is a simplification that may actually result in better performance, in the case an implementation is doing a workaround to achieve what this RFC proposes.</p>
<h3 id="ergonomics-35"><a class="header" href="#ergonomics-35">Ergonomics</a></h3>
<p>The interface is going to be very similar to the already existing one.
Even simpler since <code>PayFees</code> will only receive one asset.
That asset will allow users to limit the amount of fees they are willing to pay.</p>
<h3 id="compatibility-35"><a class="header" href="#compatibility-35">Compatibility</a></h3>
<p>This RFC can't just change the semantics of the <code>BuyExecution</code> instruction since that instruction accepts any funds, uses what it needs and returns the rest immediately.
The new proposed instruction, <code>PayFees</code>, doesn't return the leftover immediately, it keeps it in the <code>fees</code> register.
In practice, the deprecated <code>BuyExecution</code> needs to be slowly rolled out in favour of <code>PayFees</code>.</p>
<h2 id="prior-art-and-references-43"><a class="header" href="#prior-art-and-references-43">Prior Art and References</a></h2>
<p>The closed RFC PR on the xcm-format repository, before XCM RFCs got moved to fellowship RFCs: https://github.com/polkadot-fellows/xcm-format/pull/53.</p>
<h2 id="unresolved-questions-40"><a class="header" href="#unresolved-questions-40">Unresolved Questions</a></h2>
<p>None</p>
<h2 id="future-directions-and-related-material-33"><a class="header" href="#future-directions-and-related-material-33">Future Directions and Related Material</a></h2>
<p>This proposal would greatly benefit from an improved asset trapping system.</p>
<p><a href="https://github.com/polkadot-fellows/xcm-format/blob/master/proposals/0037-custom-asset-claimer.md">CustomAssetClaimer</a> is also related, as it directly improves the ergonomics of this proposal.</p>
<p><a href="https://github.com/polkadot-fellows/RFCs/pull/107">LeftoverAssetsDestination</a> execution hint would also similarly improve the ergonomics.</p>
<p><a href="https://github.com/polkadot-fellows/RFCs/pull/106/files">Removal of JIT fees</a> is also related, they are useless with this proposal.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0107-xcm-execution-hints.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0107-xcm-execution-hints.html#rfc-0107-xcm-execution-hints">RFC-0107: XCM Execution hints</a>
<ul>
<li><a href="approved/0107-xcm-execution-hints.html#summary">Summary</a></li>
<li><a href="approved/0107-xcm-execution-hints.html#motivation">Motivation</a></li>
<li><a href="approved/0107-xcm-execution-hints.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0107-xcm-execution-hints.html#explanation">Explanation</a></li>
<li><a href="approved/0107-xcm-execution-hints.html#drawbacks">Drawbacks</a></li>
<li><a href="approved/0107-xcm-execution-hints.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="approved/0107-xcm-execution-hints.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="approved/0107-xcm-execution-hints.html#performance">Performance</a></li>
<li><a href="approved/0107-xcm-execution-hints.html#ergonomics">Ergonomics</a></li>
<li><a href="approved/0107-xcm-execution-hints.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="approved/0107-xcm-execution-hints.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="approved/0107-xcm-execution-hints.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="approved/0107-xcm-execution-hints.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0107-xcm-execution-hints"><a class="header" href="#rfc-0107-xcm-execution-hints">RFC-0107: XCM Execution hints</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>23 July 2024</td></tr>
<tr><td><strong>Description</strong></td><td>Add a mechanism for configuring particular XCM executions</td></tr>
<tr><td><strong>Authors</strong></td><td>Francisco Aguirre</td></tr>
</tbody></table>
</div>
<h2 id="summary-48"><a class="header" href="#summary-48">Summary</a></h2>
<p>A previous XCM RFC (https://github.com/polkadot-fellows/xcm-format/pull/37) introduced a <code>SetAssetClaimer</code> instruction.
This idea of instructing the XCVM to change some implementation-specific behavior is useful.
In order to generalize this mechanism, this RFC introduces a new instruction <code>SetHints</code>
and makes the <code>SetAssetClaimer</code> be just one of many possible execution hints.</p>
<h2 id="motivation-48"><a class="header" href="#motivation-48">Motivation</a></h2>
<p>There is a need for specifying how certain implementation-specific things should behave.
Things like who can claim the assets or what can be done instead of trapping assets.
Another idea for a hint:</p>
<ul>
<li><code>AssetForFees</code>: to signify to the executor what asset the user prefers to use for fees.</li>
<li><code>LeftoverAssetsDestination</code>: for depositing leftover assets to a destination instead of trapping them</li>
</ul>
<h2 id="stakeholders-47"><a class="header" href="#stakeholders-47">Stakeholders</a></h2>
<ul>
<li>Runtime devs</li>
<li>Wallets</li>
<li>dApps</li>
</ul>
<h2 id="explanation-47"><a class="header" href="#explanation-47">Explanation</a></h2>
<p>A new instruction, <code>SetHints</code>, will be added.
This instruction will take a single parameter of type <code>Hint</code>, an enumeration.
The first variant for this enum is <code>AssetClaimer</code>, which allows to specify a location that should be able to claim trapped assets.
This means the instruction <code>SetAssetClaimer</code> would also be removed, in favor of this.</p>
<p>In Rust, the new definitions would look as follows:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>enum Instruction {
// ...snip...
SetHints(BoundedVec&lt;Hint, NumVariants&gt;),
// ...snip...
}
enum Hint {
AssetClaimer(Location),
// more can be added
}
type NumVariants = /* Number of variants of the `Hint` enum */;
<span class="boring">}</span></code></pre></pre>
<h2 id="drawbacks-44"><a class="header" href="#drawbacks-44">Drawbacks</a></h2>
<p>The <code>SetHints</code> instruction might be hard to benchmark, since we should look into the actual hints being set to know how much weight to attribute to it.</p>
<h2 id="testing-security-and-privacy-43"><a class="header" href="#testing-security-and-privacy-43">Testing, Security, and Privacy</a></h2>
<p><code>Hint</code>s are specified on a per-message basis, so they have to be specified at the beginning of a message.
If they were to be specified at the end, hints like <code>AssetClaimer</code> would be useless if an error occurs beforehand and assets get trapped before ever reaching the hint.</p>
<p>The instruction takes a bounded vector of hints so as to not force barriers to allow an arbitrary number of <code>SetHint</code> instructions.</p>
<h2 id="performance-ergonomics-and-compatibility-42"><a class="header" href="#performance-ergonomics-and-compatibility-42">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-40"><a class="header" href="#performance-40">Performance</a></h3>
<p>None.</p>
<h3 id="ergonomics-36"><a class="header" href="#ergonomics-36">Ergonomics</a></h3>
<p>The <code>SetHints</code> instruction provides a better integration with barriers.
If we had to add one barrier for <code>SetAssetClaimer</code> and another for each new hint that's added, barriers would need to be changed all the time.
Also, this instruction would make it simpler to write XCM programs.
You only need to specify the hints you want in one single instruction at the top of your program.</p>
<h3 id="compatibility-36"><a class="header" href="#compatibility-36">Compatibility</a></h3>
<p>None.</p>
<h2 id="prior-art-and-references-44"><a class="header" href="#prior-art-and-references-44">Prior Art and References</a></h2>
<p>The previous RFC PR in the xcm-format repository before XCM RFCs moved to fellowship RFCs: https://github.com/polkadot-fellows/xcm-format/pull/59.</p>
<h2 id="unresolved-questions-41"><a class="header" href="#unresolved-questions-41">Unresolved Questions</a></h2>
<p>None.</p>
<h2 id="future-directions-and-related-material-34"><a class="header" href="#future-directions-and-related-material-34">Future Directions and Related Material</a></h2>
<p>None.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/blob/main/text/0108-xcm-remove-testnet-ids.md">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="approved/0108-xcm-remove-testnet-ids.html#rfc-0108-remove-xcm-testnet-networkids">RFC-0108: Remove XCM testnet NetworkIds</a>
<ul>
<li><a href="approved/0108-xcm-remove-testnet-ids.html#summary">Summary</a></li>
<li><a href="approved/0108-xcm-remove-testnet-ids.html#motivation">Motivation</a></li>
<li><a href="approved/0108-xcm-remove-testnet-ids.html#stakeholders">Stakeholders</a></li>
<li><a href="approved/0108-xcm-remove-testnet-ids.html#explanation">Explanation</a></li>
<li><a href="approved/0108-xcm-remove-testnet-ids.html#drawbacks">Drawbacks</a></li>
<li><a href="approved/0108-xcm-remove-testnet-ids.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="approved/0108-xcm-remove-testnet-ids.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="approved/0108-xcm-remove-testnet-ids.html#performance">Performance</a></li>
<li><a href="approved/0108-xcm-remove-testnet-ids.html#ergonomics">Ergonomics</a></li>
<li><a href="approved/0108-xcm-remove-testnet-ids.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="approved/0108-xcm-remove-testnet-ids.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="approved/0108-xcm-remove-testnet-ids.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="approved/0108-xcm-remove-testnet-ids.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0108-remove-xcm-testnet-networkids"><a class="header" href="#rfc-0108-remove-xcm-testnet-networkids">RFC-0108: Remove XCM testnet NetworkIds</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>23 July 2024</td></tr>
<tr><td><strong>Description</strong></td><td>Remove the NetworkIds for testnets Westend and Rococo</td></tr>
<tr><td><strong>Authors</strong></td><td></td></tr>
</tbody></table>
</div>
<h2 id="summary-49"><a class="header" href="#summary-49">Summary</a></h2>
<p>This RFC aims to remove the <code>NetworkId</code>s of <code>Westend</code> and <code>Rococo</code>, arguing that testnets shouldn't go in the language.</p>
<h2 id="motivation-49"><a class="header" href="#motivation-49">Motivation</a></h2>
<p>We've already seen the plans to phase out Rococo and Paseo has appeared.
Instead of constantly changing the testnets included in the language, we should favor specifying them via their genesis hash,
using <code>NetworkId::ByGenesis</code>.</p>
<h2 id="stakeholders-48"><a class="header" href="#stakeholders-48">Stakeholders</a></h2>
<ul>
<li>Runtime devs</li>
<li>Wallets</li>
<li>dApps</li>
</ul>
<h2 id="explanation-48"><a class="header" href="#explanation-48">Explanation</a></h2>
<p>Remove <code>Westend</code> and <code>Rococo</code> from the included <code>NetworkId</code>s in the language.</p>
<h2 id="drawbacks-45"><a class="header" href="#drawbacks-45">Drawbacks</a></h2>
<p>This RFC will make it less convenient to specify a testnet, but not by a large amount.</p>
<h2 id="testing-security-and-privacy-44"><a class="header" href="#testing-security-and-privacy-44">Testing, Security, and Privacy</a></h2>
<p>None.</p>
<h2 id="performance-ergonomics-and-compatibility-43"><a class="header" href="#performance-ergonomics-and-compatibility-43">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-41"><a class="header" href="#performance-41">Performance</a></h3>
<p>None.</p>
<h3 id="ergonomics-37"><a class="header" href="#ergonomics-37">Ergonomics</a></h3>
<p>It will very slightly reduce the ergonomics of testnet developers but improve the stability of the language.</p>
<h3 id="compatibility-37"><a class="header" href="#compatibility-37">Compatibility</a></h3>
<p><code>NetworkId::Rococo</code> and <code>NetworkId::Westend</code> can just use <code>NetworkId::ByGenesis</code>, as can other testnets.</p>
<h2 id="prior-art-and-references-45"><a class="header" href="#prior-art-and-references-45">Prior Art and References</a></h2>
<p>A previous attempt to add <code>NetworkId::Paseo</code>: https://github.com/polkadot-fellows/xcm-format/pull/58.</p>
<h2 id="unresolved-questions-42"><a class="header" href="#unresolved-questions-42">Unresolved Questions</a></h2>
<p>None.</p>
<h2 id="future-directions-and-related-material-35"><a class="header" href="#future-directions-and-related-material-35">Future Directions and Related Material</a></h2>
<p>None.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/pull/102">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="stale/0102-offchain-parachain-runtime-upgrades.html#rfc-0000-feature-name-here">RFC-0000: Feature Name Here</a>
<ul>
<li><a href="stale/0102-offchain-parachain-runtime-upgrades.html#summary">Summary</a></li>
<li><a href="stale/0102-offchain-parachain-runtime-upgrades.html#motivation">Motivation</a></li>
<li><a href="stale/0102-offchain-parachain-runtime-upgrades.html#stakeholders">Stakeholders</a></li>
<li><a href="stale/0102-offchain-parachain-runtime-upgrades.html#explanation">Explanation</a>
<ul>
<li><a href="stale/0102-offchain-parachain-runtime-upgrades.html#introduce-a-new-ump-message-type-requestcodeupgrade">Introduce a new UMP message type <code>RequestCodeUpgrade</code></a></li>
<li><a href="stale/0102-offchain-parachain-runtime-upgrades.html#handle-requestcodeupgrade-on-backers">Handle <code>RequestCodeUpgrade</code> on backers</a></li>
<li><a href="stale/0102-offchain-parachain-runtime-upgrades.html#get-the-new-code-to-all-validators">Get the new code to all validators</a></li>
<li><a href="stale/0102-offchain-parachain-runtime-upgrades.html#on-chain-code-upgrade-process">On-chain code upgrade process</a></li>
<li><a href="stale/0102-offchain-parachain-runtime-upgrades.html#handling-new-validators">Handling new validators</a></li>
<li><a href="stale/0102-offchain-parachain-runtime-upgrades.html#how-do-other-parties-get-hold-of-the-pvf">How do other parties get hold of the PVF?</a></li>
<li><a href="stale/0102-offchain-parachain-runtime-upgrades.html#pruning">Pruning</a></li>
</ul>
</li>
<li><a href="stale/0102-offchain-parachain-runtime-upgrades.html#drawbacks">Drawbacks</a></li>
<li><a href="stale/0102-offchain-parachain-runtime-upgrades.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="stale/0102-offchain-parachain-runtime-upgrades.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="stale/0102-offchain-parachain-runtime-upgrades.html#performance">Performance</a></li>
<li><a href="stale/0102-offchain-parachain-runtime-upgrades.html#ergonomics">Ergonomics</a></li>
<li><a href="stale/0102-offchain-parachain-runtime-upgrades.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="stale/0102-offchain-parachain-runtime-upgrades.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="stale/0102-offchain-parachain-runtime-upgrades.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="stale/0102-offchain-parachain-runtime-upgrades.html#future-directions-and-related-material">Future Directions and Related Material</a>
<ul>
<li><a href="stale/0102-offchain-parachain-runtime-upgrades.html#further-hardening">Further Hardening</a></li>
<li><a href="stale/0102-offchain-parachain-runtime-upgrades.html#generalize-this-off-chain-storage-mechanism">Generalize this off-chain storage mechanism?</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<h1 id="rfc-0000-feature-name-here"><a class="header" href="#rfc-0000-feature-name-here">RFC-0000: Feature Name Here</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>13 July 2024</td></tr>
<tr><td><strong>Description</strong></td><td>Implement off-chain parachain runtime upgrades</td></tr>
<tr><td><strong>Authors</strong></td><td>eskimor</td></tr>
</tbody></table>
</div>
<h2 id="summary-50"><a class="header" href="#summary-50">Summary</a></h2>
<p>Change the upgrade process of a parachain runtime upgrade to become an off-chain
process with regards to the relay chain. Upgrades are still contained in
parachain blocks, but will no longer need to end up in relay chain blocks nor in
relay chain state.</p>
<h2 id="motivation-50"><a class="header" href="#motivation-50">Motivation</a></h2>
<p>Having parachain runtime upgrades go through the relay chain has always been
seen as a scalability concern. Due to optimizations in statement
distribution and asynchronous backing it became less crucial and got
de-prioritized, the original issue can be found
<a href="https://github.com/paritytech/polkadot-sdk/issues/971">here</a>.</p>
<p>With the introduction of Agile Coretime and in general our efforts to reduce
barrier to entry more for Polkadot more, the issue becomes more relevant again:
We would like to reduce the required storage deposit for PVF registration, with
the aim to not only make it cheaper to run a parachain (bulk + on-demand
coretime), but also reduce the amount of capital required for the deposit. With
this we would hope for far more parachains to get registered, thousands
potentially even ten thousands. With so many PVFs registered, updates are
expected to become more frequent and even attacks on service quality for other
parachains would become a higher risk.</p>
<h2 id="stakeholders-49"><a class="header" href="#stakeholders-49">Stakeholders</a></h2>
<ul>
<li>Parachain Teams</li>
<li>Relay Chain Node implementation teams</li>
<li>Relay Chain runtime developers</li>
</ul>
<h2 id="explanation-49"><a class="header" href="#explanation-49">Explanation</a></h2>
<p>The issues with on-chain runtime upgrades are:</p>
<ol>
<li>Needlessly costly.</li>
<li>A single runtime upgrade more or less occupies an entire relay chain block, thus it
might affect also other parachains, especially if their candidates are also
not negligible due to messages for example or they want to uprade their
runtime at the same time.</li>
<li>The signalling of the parachain to notify the relay chain of an upcoming
runtime upgrade already contains the upgrade. Therefore the only way to rate
limit upgrades is to drop an already distributed update in the size of
megabytes: With the result that the parachain missed a block and more
importantly it will try again with the very next block, until it finally
succeeds. If we imagine to reduce capacity of runtime upgrades to let's say 1
every 100 relay chain blocks, this results in lot's of wasted effort and lost
blocks.</li>
</ol>
<p>We discussed introducing a separate signalling before submitting the actual
runtime, but I think we should just go one step further and make upgrades fully
off-chain. Which also helps bringing down deposit costs in a secure way, as we
are also actually reducing costs for the network.</p>
<h3 id="introduce-a-new-ump-message-type-requestcodeupgrade"><a class="header" href="#introduce-a-new-ump-message-type-requestcodeupgrade">Introduce a new UMP message type <code>RequestCodeUpgrade</code></a></h3>
<p>As part of elastic scaling we are already planning to increase flexibility of <a href="https://github.com/polkadot-fellows/RFCs/issues/92#issuecomment-2144538974">UMP
messages</a>, we can now use this to our advantage and introduce another UMP message:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>enum UMPSignal {
// For elastic scaling
OnCore(CoreIndex),
// For off-chain upgrades
RequestCodeUpgrade(Hash),
}
<span class="boring">}</span></code></pre></pre>
<p>We could also make that new message a regular XCM, calling an extrinsic on the
relay chain, but we will want to look into that message right after validation
on the backers on the node side, making a straight forward semantic message more
apt for the purpose.</p>
<h3 id="handle-requestcodeupgrade-on-backers"><a class="header" href="#handle-requestcodeupgrade-on-backers">Handle <code>RequestCodeUpgrade</code> on backers</a></h3>
<p>We will introduce a new request/response protocol for both collators and
validators, with the following request/response:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>struct RequestBlob {
blob_hash: Hash,
}
struct BlobResponse {
blob: Vec&lt;u8&gt;
}
<span class="boring">}</span></code></pre></pre>
<p>This protocol will be used by backers to request the PVF from collators in the
following conditions:</p>
<ol>
<li>They received a collation sending <code>RequestCodeUpgrade</code>.</li>
<li>They received a collation, but they don't yet have the code that was
previously registered on the relaychain. (E.g. disk pruned, new validator)</li>
</ol>
<p>In case they received the collation via PoV distribution instead of from the
collator itself, they will use the exact same message to fetch from the valiator
they got the PoV from.</p>
<h3 id="get-the-new-code-to-all-validators"><a class="header" href="#get-the-new-code-to-all-validators">Get the new code to all validators</a></h3>
<p>Once the candidate issuing <code>RequestCodeUpgrade</code> got backed on chain, validators
will start fetching the code from the backers as part of availability
distribution.</p>
<p>To mitigate attack vectors we should make sure that serving requests for code
can be treated as low priority requests. Thus I am suggesting the following
scheme:</p>
<p>Validators will notice via a runtime API (TODO: Define) that a new code has been requested, the
API will return the <code>Hash</code> and a counter, which starts at some configurable
value e.g. 10. The validators are now aware of the new hash and start fetching,
but they don't have to wait for the fetch to succeed to sign their bitfield.</p>
<p>Then on each further candidate from that chain that counter gets decremented.
Validators which have not yet succeeded fetching will now try again. This game
continues until the counter reached <code>0</code>. Now it is mandatory to have to code in
order to sign a <code>1</code> in the bitfield.</p>
<p>PVF pre-checking will happen after the candidate which brought the counter to
<code>0</code> has been successfully included and thus is also able to assume that 2/3 of
the validators have the code.</p>
<p>This scheme serves two purposes:</p>
<ol>
<li>Fetching can happen over a longer period of time with low priority. E.g. if
we waited for the PVF at the very first avaialbility distribution, this might
actually affect liveness of other chains on the same core. Distributing
megabytes of data to a thousand validators, might take a bit. Thus this helps
isolating parachains from each other.</li>
<li>By configuring the initial counter value we can affect how much an upgrade
costs. E.g. forcing the parachain to produce 10 blocks, means 10x the cost
for issuing an update. If too frequent upgrades ever become a problem for the
system, we have a knob to make them more costly.</li>
</ol>
<h3 id="on-chain-code-upgrade-process"><a class="header" href="#on-chain-code-upgrade-process">On-chain code upgrade process</a></h3>
<p>First when a candidate is backed we need to make the new hash available
(together with a counter) via a
runtime API so validators in availability distribution can check for it and
fetch it if changed (see previous section). For performance reasons, I think we
should not do an additional call, but replace the <a href="https://github.com/paritytech/polkadot-sdk/blob/d2fd53645654d3b8e12cbf735b67b93078d70113/polkadot/node/subsystem-util/src/runtime/mod.rs#L355">existing one</a> with one containing the new additional information (Option&lt;(Hash, Counter)&gt;).</p>
<p>Once the candidate gets included (counter 0), the hash is given to pre-checking
and only after pre-checking succeeded (and a full session passed) it is finally
enacted and the parachain can switch to the new code. (Same process as it used
to be.)</p>
<h3 id="handling-new-validators"><a class="header" href="#handling-new-validators">Handling new validators</a></h3>
<h4 id="backers"><a class="header" href="#backers">Backers</a></h4>
<p>If a backer receives a collation for a parachain it does not yet have the code
as enacted on chain (see &quot;On-chain code upgrade process&quot;), it will use above
request/response protocol to fetch it from whom it received the collation.</p>
<h4 id="availablity-distribution"><a class="header" href="#availablity-distribution">Availablity Distribution</a></h4>
<p>Validators in availability distribution will be changed to only sign a <code>1</code> in
the bitfield of a candidate if they not only have the chunk, but also the
currently active PVF. They will fetch it from backers in case they don't have it
yet.</p>
<h3 id="how-do-other-parties-get-hold-of-the-pvf"><a class="header" href="#how-do-other-parties-get-hold-of-the-pvf">How do other parties get hold of the PVF?</a></h3>
<p>Two ways:</p>
<ol>
<li>Discover collators via <a href="https://github.com/polkadot-fellows/RFCs/pull/8">relay chain DHT</a> and request from them: Preferred way,
as it is less load on validators.</li>
<li>Request from validators, which will serve on a best effort basis.</li>
</ol>
<h3 id="pruning"><a class="header" href="#pruning">Pruning</a></h3>
<p>We covered how validators get hold of new code, but when can they prune old ones?
In principle it is not an issue, if some validors prune code, because:</p>
<ol>
<li>We changed it so that a candidate is not deemed available if validators were
not able to fetch the PVF.</li>
<li>Backers can always fetch the PVF from collators as part of the collation
fetching.</li>
</ol>
<p>But the majority of validators should always keep the latest code of any
parachain and only prune the previous one, once the first candidate using the
new code got finalized. This ensures that disputes will always be able to
resolve.</p>
<h2 id="drawbacks-46"><a class="header" href="#drawbacks-46">Drawbacks</a></h2>
<p>The major drawback of this solution is the same as any solution the moves work
off-chain, it adds complexity to the node. E.g. nodes needing the PVF, need to
store them separately, together with their own pruning strategy as well.</p>
<h2 id="testing-security-and-privacy-45"><a class="header" href="#testing-security-and-privacy-45">Testing, Security, and Privacy</a></h2>
<p>Implementations adhering to this RFC, will respond to PVF requests with the
actual PVF, if they have it. Requesters will persist received PVFs on disk for
as long as they are replaced by a new one. Implementations must not be lazy
here, if validators only fetched the PVF when needed, they can be prevented from
participating in disputes.</p>
<p>Validators should treat incoming requests for PVFs in general with rather low
priority, but should prefer fetches from other validators over requests from
random peers.</p>
<p>Given that we are altering what set bits in the availability bitfields mean (not
only chunk, but also PVF available), it is important to have enough validators
upgraded, before we allow collators to make use of the new runtime upgrade
mechanism. Otherwise we would risk disputes to not being able to succeed.</p>
<p>This RFC has no impact on privacy.</p>
<h2 id="performance-ergonomics-and-compatibility-44"><a class="header" href="#performance-ergonomics-and-compatibility-44">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-42"><a class="header" href="#performance-42">Performance</a></h3>
<p>This proposal lightens the load on the relay chain and is thus in general
beneficial for the performance of the network, this is achieved by the
following:</p>
<ol>
<li>Code upgrades are still propagated to all validators, but only once, not
twice (First statements, then via the containing relay chain block).</li>
<li>Code upgrades are only communicated to validators and other nodes which are
interested, not any full node as it has been before.</li>
<li>Relay chain block space is preserved. Previously we could only do one runtime
upgrade per relay chain block, occupying almost all of the blockspace.</li>
<li>Signalling an upgrade no longer contains the upgrade, hence if we need to
push back on an upgrade for whatever reason, no network bandwidth and core
time gets wasted because of this.</li>
</ol>
<h3 id="ergonomics-38"><a class="header" href="#ergonomics-38">Ergonomics</a></h3>
<p>End users are only affected by better performance and more stable block times.
Parachains will need to implement the introduced request/response protocol and
adapt to the new signalling mechanism via an <code>UMP</code> message, instead of sending
the code upgrade directly.</p>
<p>For parachain operators we should emit events on initiated runtime upgrade and
each block reporting the current counter and how many blocks to go until the
upgrade gets passed to pre-checking. This is especially important for on-demand
chains or bulk users not occupying a full core. Further more that behaviour of
requiring multiple blocks to fully initiate a runtime upgrade needs to be well
documented.</p>
<h3 id="compatibility-38"><a class="header" href="#compatibility-38">Compatibility</a></h3>
<p>We will continue to support the old mechanism for code upgrades for a while, but
will start to impose stricter limits over time, with the number of registered
parachains going up. With those limits in place parachains not migrating to the
new scheme might be having a harder time upgrading and will miss more blocks. I
guess we can be lenient for a while still, so the upgrade path for
parachains should be rather smooth.</p>
<p>In total the protocol changes we need are:</p>
<p>For validators and collators:</p>
<ol>
<li>New request/response protocol for fetching PVF data from collators and
validators.</li>
<li>New UMP message type for signalling a runtime upgrade.</li>
</ol>
<p>Only for validators:</p>
<ol>
<li>New runtime API for determining to be enacted code upgrades.</li>
<li>Different behaviour of bitfields (only sign a 1 bit, if validator has chunk +
&quot;hot&quot; PVF).</li>
<li>Altered behaviour in availability-distribution: Fetch missing PVFS.</li>
</ol>
<h2 id="prior-art-and-references-46"><a class="header" href="#prior-art-and-references-46">Prior Art and References</a></h2>
<p>Off-chain runtime upgrades have been discussed before, the architecture
described here is simpler though as it piggybacks on already existing features,
namely:</p>
<ol>
<li>availability-distribution: No separate <code>I have code</code> messages anymore.</li>
<li>Existing pre-checking.</li>
</ol>
<p>https://github.com/paritytech/polkadot-sdk/issues/971</p>
<h2 id="unresolved-questions-43"><a class="header" href="#unresolved-questions-43">Unresolved Questions</a></h2>
<ol>
<li>What about the initial runtime, shall we make that off-chain as well?</li>
<li>Good news, at least after the first upgrade, no code will be stored on chain
any more, this means that we also have to redefine the storage deposit now.
We no longer charge for chain storage, but validator disk storage -&gt; Should
be cheaper. Solution to this: Not only store the hash on chain, but also the
size of the data. Then define a price per byte and charge that, but:
<ul>
<li>how do we charge - I guess deposit has to be provided via other means,
runtime upgrade fails if not provided.</li>
<li>how do we signal to the chain that the code is too large for it to reject
the upgrade? Easy: Make available and vote nay in pre-checking.</li>
</ul>
</li>
</ol>
<p>TODO: Fully resolve these questions and incorporate in RFC text.</p>
<h2 id="future-directions-and-related-material-36"><a class="header" href="#future-directions-and-related-material-36">Future Directions and Related Material</a></h2>
<h3 id="further-hardening"><a class="header" href="#further-hardening">Further Hardening</a></h3>
<p>By no longer having code upgrade go through the relay chain, occupying a full relay
chain block, the impact on other parachains is already greatly reduced, if we
make distribution and PVF pre-checking low-priority processes on validators. The
only thing attackers might be able to do is delay upgrades of other parachains.</p>
<p>Which seems like a problem to be solved once we actually see it as a problem in
the wild (and can already be mitigated by adjusting the counter). The good thing
is that we have all the ingredients to go further if need be. Signalling no
longer actually includes the code, hence there is no need to reject the
candidate: The parachain can make progress even if we choose not to immediately
act on the request and no relay chain resources are wasted either.</p>
<p>We could for example introduce another UMP Signalling message
<code>RequestCodeUpgradeWithPriority</code> which not just requests a code upgrade, but
also offers some DOT to get ranked up in a queue.</p>
<h3 id="generalize-this-off-chain-storage-mechanism"><a class="header" href="#generalize-this-off-chain-storage-mechanism">Generalize this off-chain storage mechanism?</a></h3>
<p>Making this storage mechanism more general purpose is worth thinking about. E.g.
by resolving above &quot;fee&quot; question, we might also be able to resolve the pruning
question in a more generic way and thus could indeed open this storage facility
for other purposes as well. E.g. smart contracts, so the PoV would only need to
reference contracts by hash and the actual PoV is stored on validators and
collators and thus no longer needs to be part of the PoV.</p>
<p>A possible avenue would be to change the response to:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>enum BlobResponse {
Blob(Vec&lt;u8&gt;),
Blobs(MerkleTree),
}
<span class="boring">}</span></code></pre></pre>
<p>With this the hash specified in the request can also be a merkle root and the
responder will respond with the entire merkle tree (only hashes, no payload).
Then the requester can traverse the leaf hashes and use the same request
response protocol to request any locally missing blobs in that tree.</p>
<p>One leaf would for example be the PVF others could be smart contracts. With a
properly specified format (e.g. which leaf is the PVF?), what we got here is
that a parachain can not only update its PVF, but additional data,
incrementally. E.g. adding another smart contract, does not require resubmitting
the entire PVF to validators, only the root hash on the relay chain gets
updated, then validators fetch the merkle tree and only fetch any missing
leaves. That additional data could be made available to the PVF via a to be
added host function. The nice thing about this approach is, that while we can
upgrade incrementally, lifetime is still tied to the PVF and we get all the same
guarantees. Assuming the validators store blobs by hash, we even get disk
sharing if multiple parachains use the same data (e.g. same smart contracts).</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/pull/106">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="stale/0106-xcm-remove-fees-mode.html#rfc-0106-remove-xcm-fees-mode">RFC-0106: Remove XCM fees mode</a>
<ul>
<li><a href="stale/0106-xcm-remove-fees-mode.html#summary">Summary</a></li>
<li><a href="stale/0106-xcm-remove-fees-mode.html#motivation">Motivation</a></li>
<li><a href="stale/0106-xcm-remove-fees-mode.html#stakeholders">Stakeholders</a></li>
<li><a href="stale/0106-xcm-remove-fees-mode.html#explanation">Explanation</a></li>
<li><a href="stale/0106-xcm-remove-fees-mode.html#drawbacks">Drawbacks</a></li>
<li><a href="stale/0106-xcm-remove-fees-mode.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="stale/0106-xcm-remove-fees-mode.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="stale/0106-xcm-remove-fees-mode.html#performance">Performance</a></li>
<li><a href="stale/0106-xcm-remove-fees-mode.html#ergonomics">Ergonomics</a></li>
<li><a href="stale/0106-xcm-remove-fees-mode.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="stale/0106-xcm-remove-fees-mode.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="stale/0106-xcm-remove-fees-mode.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="stale/0106-xcm-remove-fees-mode.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0106-remove-xcm-fees-mode"><a class="header" href="#rfc-0106-remove-xcm-fees-mode">RFC-0106: Remove XCM fees mode</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>23 July 2024</td></tr>
<tr><td><strong>Description</strong></td><td>Remove the <code>SetFeesMode</code> instruction and <code>fees_mode</code> register from XCM</td></tr>
<tr><td><strong>Authors</strong></td><td>Francisco Aguirre</td></tr>
</tbody></table>
</div>
<h2 id="summary-51"><a class="header" href="#summary-51">Summary</a></h2>
<p>The <code>SetFeesMode</code> instruction and the <code>fees_mode</code> register allow for the existence of JIT withdrawal.
JIT withdrawal complicates the fee mechanism and leads to bugs and unexpected behaviour.
The proposal is to remove said functionality.
Another effort to simplify fee handling in XCM.</p>
<h2 id="motivation-51"><a class="header" href="#motivation-51">Motivation</a></h2>
<p>The JIT withdrawal mechanism creates bugs such as not being able to get fees when all assets are put into holding and none left in the origin location.
This is a confusing behavior, since there are funds for fees, just not where the XCVM wants them.
The XCVM should have only one entrypoint to fee payment, the holding register.
That way there is also less surface for bugs.</p>
<h2 id="stakeholders-50"><a class="header" href="#stakeholders-50">Stakeholders</a></h2>
<ul>
<li>Runtime Users</li>
<li>Runtime Devs</li>
<li>Wallets</li>
<li>dApps</li>
</ul>
<h2 id="explanation-50"><a class="header" href="#explanation-50">Explanation</a></h2>
<p>The <code>SetFeesMode</code> instruction will be removed.
The <code>Fees Mode</code> register will be removed.</p>
<h2 id="drawbacks-47"><a class="header" href="#drawbacks-47">Drawbacks</a></h2>
<p>Users will have to make sure to put enough assets in <code>WithdrawAsset</code> when
previously some things might have been charged directly from their accounts.
This leads to a more predictable behaviour though so it will only be
a drawback for the minority of users.</p>
<h2 id="testing-security-and-privacy-46"><a class="header" href="#testing-security-and-privacy-46">Testing, Security, and Privacy</a></h2>
<p>Implementations and benchmarking must change for most existing pallet calls
that send XCMs to other locations.</p>
<h2 id="performance-ergonomics-and-compatibility-45"><a class="header" href="#performance-ergonomics-and-compatibility-45">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-43"><a class="header" href="#performance-43">Performance</a></h3>
<p>Performance will be improved since unnecessary checks will be avoided.</p>
<h3 id="ergonomics-39"><a class="header" href="#ergonomics-39">Ergonomics</a></h3>
<p>JIT withdrawal was a way of side-stepping the regular flow of XCM programs.
By removing it, the spec is simplified but now old use-cases have to work with
the original intended behaviour, which may result in more implementation work.</p>
<p>Ergonomics for users will undoubtedly improve since the system is more predictable.</p>
<h3 id="compatibility-39"><a class="header" href="#compatibility-39">Compatibility</a></h3>
<p>Existing programs in the ecosystem will break.
The instruction should be deprecated as soon as this RFC is approved
(but still fully supported), then removed in a subsequent XCM version
(probably deprecate in v5, remove in v6).</p>
<h2 id="prior-art-and-references-47"><a class="header" href="#prior-art-and-references-47">Prior Art and References</a></h2>
<p>The previous RFC PR on the xcm-format repo, before XCM RFCs were moved to fellowship RFCs: https://github.com/polkadot-fellows/xcm-format/pull/57.</p>
<h2 id="unresolved-questions-44"><a class="header" href="#unresolved-questions-44">Unresolved Questions</a></h2>
<p>None.</p>
<h2 id="future-directions-and-related-material-37"><a class="header" href="#future-directions-and-related-material-37">Future Directions and Related Material</a></h2>
<p>The <a href="https://github.com/polkadot-fellows/RFCs/pull/105">new generic fees mechanism</a> is related to this proposal and further stimulates it as the JIT withdraw fees mechanism will become useless anyway.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/pull/109">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="stale/0109-xcm-descend-instead-of-clear-origin.html#rfc-0109-descend-xcm-origin-instead-of-clearing-it-where-possible">RFC-0109: Descend XCM origin instead of clearing it where possible</a>
<ul>
<li><a href="stale/0109-xcm-descend-instead-of-clear-origin.html#summary">Summary</a></li>
<li><a href="stale/0109-xcm-descend-instead-of-clear-origin.html#motivation">Motivation</a></li>
<li><a href="stale/0109-xcm-descend-instead-of-clear-origin.html#stakeholders">Stakeholders</a></li>
<li><a href="stale/0109-xcm-descend-instead-of-clear-origin.html#explanation">Explanation</a></li>
<li><a href="stale/0109-xcm-descend-instead-of-clear-origin.html#drawbacks">Drawbacks</a></li>
<li><a href="stale/0109-xcm-descend-instead-of-clear-origin.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="stale/0109-xcm-descend-instead-of-clear-origin.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="stale/0109-xcm-descend-instead-of-clear-origin.html#performance">Performance</a></li>
<li><a href="stale/0109-xcm-descend-instead-of-clear-origin.html#ergonomics">Ergonomics</a></li>
<li><a href="stale/0109-xcm-descend-instead-of-clear-origin.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="stale/0109-xcm-descend-instead-of-clear-origin.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="stale/0109-xcm-descend-instead-of-clear-origin.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="stale/0109-xcm-descend-instead-of-clear-origin.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-0109-descend-xcm-origin-instead-of-clearing-it-where-possible"><a class="header" href="#rfc-0109-descend-xcm-origin-instead-of-clearing-it-where-possible">RFC-0109: Descend XCM origin instead of clearing it where possible</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>23 Jul 2024.</td></tr>
<tr><td><strong>Description</strong></td><td>XCM programs should &quot;descend&quot; into a safe XCM origin rather than clearing it completely</td></tr>
<tr><td><strong>Authors</strong></td><td>Adrian Catangiu</td></tr>
</tbody></table>
</div>
<h2 id="summary-52"><a class="header" href="#summary-52">Summary</a></h2>
<p>XCM programs that want to ensure that the following XCM instructions cannot command the authority of the Original Origin (such as asset transfer programs) should consider, where possible, using <code>DescendOrigin</code> into a demoted, safer origin rather than <code>ClearOrigin</code> which clears the origin completely.</p>
<h2 id="motivation-52"><a class="header" href="#motivation-52">Motivation</a></h2>
<p>Currently, all XCM asset transfer instructions ultimately clear the origin in the remote XCM message by use of the <code>ClearOrigin</code> instruction. This is done for security considerations to ensure that later instructions cannot command the authority of the Original Origin (the sending chain).</p>
<p>The problem with this approach is that it limits what can be achieved on remote chains through XCM. Most XCM operations require having an origin, and following any asset transfer the origin is lost, meaning not much can be done other than depositing the transferred assets to some local account or transferring them onward to another chain.</p>
<p>For example, we cannot transfer some funds for buying execution, then do a <code>Transact</code> (all in the same XCM message).</p>
<p>The above example is a basic, core building block for cross-chain interactions and we should support it.</p>
<h2 id="stakeholders-51"><a class="header" href="#stakeholders-51">Stakeholders</a></h2>
<p>Runtime Users, Runtime Devs, wallets, cross-chain dApps.</p>
<h2 id="explanation-51"><a class="header" href="#explanation-51">Explanation</a></h2>
<p>In the case of XCM programs going from <code>origin-chain</code> directly to <code>dest-chain</code> without an intermediary hop, we can enable scenarios such as above by using the <code>DescendOrigin</code> instruction instead of the <code>ClearOrigin</code> instruction.</p>
<p>Instead of clearing the <code>origin-chain</code> origin, we can &quot;descend&quot; into a child location of <code>origin-chain</code>, specifically we could &quot;descend&quot; into the actual origin of the initiator. Most common such descension would be <code>X2(Parachain(origin-chain), AccountId32(origin-account))</code>, when the initiator is a (signed/pure/proxy) account <code>origin-account</code>.</p>
<p>This allows an actor on chain A to <code>Transact</code> on chain B without having to prefund its SA account on chain B, instead they can simply transfer the required fees in the same XCM program as the <code>Transact</code>.</p>
<p>Unfortunately, this approach only works when the asset transfer has the same XCM route/hops as the rest of the program. Meaning it only works if the assets can be directly transferred from chain A to chain B without going through intermediary hops or reserve chains. When going through a reserve-chain, the original <code>origin-chain/origin-account</code> origin is lost and cannot be recreated using just the <code>DescendOrigin</code> instruction
Even so, this proposal is still useful for the majority of usecases (where the asset transfer happens directly between A and B).</p>
<p>The <code>TransferReserveAsset</code>, <code>DepositReserveAsset</code>, <code>InitiateReserveWithdraw</code> and <code>InitiateTeleport</code> instructions should use a <code>DescendOrigin</code> instruction on the onward XCM program instead of the currently used <code>ClearOrigin</code> instruction. The <code>DescendOrigin</code> instruction should effectively mutate the origin on the remote chain to the SA of the origin on the local chain.</p>
<h2 id="drawbacks-48"><a class="header" href="#drawbacks-48">Drawbacks</a></h2>
<p>No performance, ergonomics, user experience, security, or privacy drawbacks.</p>
<p>In terms of ergonomics and user experience, the support for combining an asset transfer with a subsequent action (like Transact) is assymetrical:</p>
<ul>
<li>natively works when assets can be transferred directly,</li>
<li>doesn't natively work when assets have to go through a reserve location.</li>
</ul>
<p>But it is still a net positive for ergonomics and user experience, while being neutral for the rest.</p>
<h2 id="testing-security-and-privacy-47"><a class="header" href="#testing-security-and-privacy-47">Testing, Security, and Privacy</a></h2>
<p>Barriers should also allow <code>DescendOrigin</code>, not just <code>ClearOrigin</code>.
XCM program builders should audit their programs and eliminate assumptions of &quot;no origin&quot; on remote side. Instead, the working assumption is that the origin on the remote side is the local origin reanchored location. This new assumption is 100% in line with the behavior of remote XCM programs sent over using <code>pallet_xcm::send</code>.</p>
<h2 id="performance-ergonomics-and-compatibility-46"><a class="header" href="#performance-ergonomics-and-compatibility-46">Performance, Ergonomics, and Compatibility</a></h2>
<h3 id="performance-44"><a class="header" href="#performance-44">Performance</a></h3>
<p>No impact.</p>
<h3 id="ergonomics-40"><a class="header" href="#ergonomics-40">Ergonomics</a></h3>
<p>Improves ergonomics by allowing the local origin to operate on the remote chain even when the XCM program includes an asset transfer.</p>
<h3 id="compatibility-40"><a class="header" href="#compatibility-40">Compatibility</a></h3>
<p>At the executor-level this change is backwards and forwards compatible. Both types of programs can be executed on new and old versions of XCM with no changes in behavior.</p>
<p>Programs switching to the new approach is however a <strong>breaking</strong> change from the existing XCM barriers point of view.
For example, the <a href="https://github.com/paritytech/polkadot-sdk/blob/35fcac758ad1a7e3d98377c5ca4d0ab4b61b14e0/polkadot/xcm/xcm-builder/src/barriers.rs#L62">AllowTopLevelPaidExecutionFrom</a> barrier permits programs containing <code>ClearOrigin</code> before <code>BuyExecution</code>, but will reject programs with <code>DescendOrigin</code> before <code>BuyExecution</code>.</p>
<p>&quot;The fix&quot; is simple: upgrade the barrier to allow either <code>ClearOrigin</code> or <code>DescendOrigin</code>, but this new barrier needs to be rolled out (upgraded to) across the whole ecosystem before we can safely start rolling out the new <code>DescendOrigin</code> model (upgrade executor and pallets).</p>
<p>As such there are two options:</p>
<ol>
<li>Change the barrier in XCMv5 and change the actual XCM programs in XCMv6 (long, potentially multi-year horizon),</li>
<li>Change the barrier and backport it to older SDK versions so that any ecosystem runtime upgrade will pick it up, then change the actual programs in XCMv5 (practical gap of a couple of months between the two).</li>
</ol>
<h2 id="prior-art-and-references-48"><a class="header" href="#prior-art-and-references-48">Prior Art and References</a></h2>
<p>None.</p>
<h2 id="unresolved-questions-45"><a class="header" href="#unresolved-questions-45">Unresolved Questions</a></h2>
<p>How to achieve this for all workflows, not just point-to-point XCM programs with no intermediary hops?</p>
<p>As long as the intermediary hop(s) is/are not trusted to &quot;impersonate&quot; a location from the original origin chain, there is no way AFAICT to hold on to the original origin.</p>
<h2 id="future-directions-and-related-material-38"><a class="header" href="#future-directions-and-related-material-38">Future Directions and Related Material</a></h2>
<p>Similar (maybe even better) results can be achieved using XCMv5<a href="https://github.com/polkadot-fellows/xcm-format/blob/master/proposals/0038-execute-with-origin.md">ExecuteWithOrigin</a> instruction, instead of <code>DescendOrigin</code>. But that introduces version downgrade compatibility challenges.</p>
<div style="break-before: page; page-break-before: always;"></div><p><a href="https://github.com/polkadot-fellows/RFCs/pull/104">(source)</a></p>
<p><strong>Table of Contents</strong></p>
<ul>
<li><a href="stale/TODO-stale-nomination-reward-curve.html#rfc-todo-stale-nomination-reward-curve">RFC-TODO: Stale Nomination Reward Curve</a>
<ul>
<li><a href="stale/TODO-stale-nomination-reward-curve.html#summary">Summary</a></li>
<li><a href="stale/TODO-stale-nomination-reward-curve.html#motivation">Motivation</a></li>
<li><a href="stale/TODO-stale-nomination-reward-curve.html#stakeholders">Stakeholders</a></li>
<li><a href="stale/TODO-stale-nomination-reward-curve.html#explanation">Explanation</a></li>
<li><a href="stale/TODO-stale-nomination-reward-curve.html#drawbacks">Drawbacks</a></li>
<li><a href="stale/TODO-stale-nomination-reward-curve.html#testing-security-and-privacy">Testing, Security, and Privacy</a></li>
<li><a href="stale/TODO-stale-nomination-reward-curve.html#performance-ergonomics-and-compatibility">Performance, Ergonomics, and Compatibility</a>
<ul>
<li><a href="stale/TODO-stale-nomination-reward-curve.html#performance">Performance</a></li>
<li><a href="stale/TODO-stale-nomination-reward-curve.html#ergonomics">Ergonomics</a></li>
<li><a href="stale/TODO-stale-nomination-reward-curve.html#compatibility">Compatibility</a></li>
</ul>
</li>
<li><a href="stale/TODO-stale-nomination-reward-curve.html#prior-art-and-references">Prior Art and References</a></li>
<li><a href="stale/TODO-stale-nomination-reward-curve.html#unresolved-questions">Unresolved Questions</a></li>
<li><a href="stale/TODO-stale-nomination-reward-curve.html#future-directions-and-related-material">Future Directions and Related Material</a></li>
</ul>
</li>
</ul>
<h1 id="rfc-todo-stale-nomination-reward-curve"><a class="header" href="#rfc-todo-stale-nomination-reward-curve">RFC-TODO: Stale Nomination Reward Curve</a></h1>
<div class="table-wrapper"><table><thead><tr><th></th><th></th></tr></thead><tbody>
<tr><td><strong>Start Date</strong></td><td>10 July 2024</td></tr>
<tr><td><strong>Description</strong></td><td>Introduce a decaying reward curve for stale nominations in staking.</td></tr>
<tr><td><strong>Authors</strong></td><td>Shawn Tabrizi</td></tr>
</tbody></table>
</div>
<h2 id="summary-53"><a class="header" href="#summary-53">Summary</a></h2>
<p>This is a proposal to reduce the impact of stale nominations in the Polkadot staking system. With this proposal, nominators are incentivized to update or renew their selected validators once per time period. Nominators that do not update or renew their selected validators would be considered stale, and a decaying multiplier would be applied to their nominations, reducing the weight of their nomination and rewards.</p>
<h2 id="motivation-53"><a class="header" href="#motivation-53">Motivation</a></h2>
<p>Longer motivation behind the content of the RFC, presented as a combination of both problems and requirements for the solution.</p>
<p>One of Polkadot's primary utilities is providing a high quality security layer for applications built on top of it. To achieve this, Polkadot runs a Nominated Proof-of-Stake system, allowing nominators to vote on who they think are the best validators for Polkadot.</p>
<p>This system functions best when nominators and validators are active participants in the network. Nominators should consistently evaluate the quality and preferences of validators, and adjust their nominations accordingly.</p>
<p>Unfortunately, many Polkadot nominators do not play an active role in the NPoS system. For many, they set their nominations, and then seldomly look back at the.</p>
<p>This can lead to many negative behaviors:</p>
<ul>
<li>Incumbents who received early nominations basically achieve tenure.</li>
<li>Validator quality and performance can decrease without recourse.</li>
<li>The validator set are not the optimal for Polkadot.</li>
<li>New validators have a harder time entering the active set.</li>
<li>Validators are able to &quot;sneakily&quot; increase their commission.</li>
</ul>
<h2 id="stakeholders-52"><a class="header" href="#stakeholders-52">Stakeholders</a></h2>
<p>Primary stakeholders are:</p>
<ul>
<li>Nominators</li>
<li>Validators</li>
</ul>
<h2 id="explanation-52"><a class="header" href="#explanation-52">Explanation</a></h2>
<p>Detail-heavy explanation of the RFC, suitable for explanation to an implementer of the changeset. This should address corner cases in detail and provide justification behind decisions, and provide rationale for how the design meets the solution requirements.</p>
<h2 id="drawbacks-49"><a class="header" href="#drawbacks-49">Drawbacks</a></h2>
<p>Description of recognized drawbacks to the approach given in the RFC. Non-exhaustively, drawbacks relating to performance, ergonomics, user experience, security, or privacy.</p>
<h2 id="testing-security-and-privacy-48"><a class="header" href="#testing-security-and-privacy-48">Testing, Security, and Privacy</a></h2>
<p>Describe the the impact of the proposal on these three high-importance areas - how implementations can be tested for adherence, effects that the proposal has on security and privacy per-se, as well as any possible implementation pitfalls which should be clearly avoided.</p>
<h2 id="performance-ergonomics-and-compatibility-47"><a class="header" href="#performance-ergonomics-and-compatibility-47">Performance, Ergonomics, and Compatibility</a></h2>
<p>Describe the impact of the proposal on the exposed functionality of Polkadot.</p>
<h3 id="performance-45"><a class="header" href="#performance-45">Performance</a></h3>
<p>Is this an optimization or a necessary pessimization? What steps have been taken to minimize additional overhead?</p>
<h3 id="ergonomics-41"><a class="header" href="#ergonomics-41">Ergonomics</a></h3>
<p>If the proposal alters exposed interfaces to developers or end-users, which types of usage patterns have been optimized for?</p>
<h3 id="compatibility-41"><a class="header" href="#compatibility-41">Compatibility</a></h3>
<p>Does this proposal break compatibility with existing interfaces, older versions of implementations? Summarize necessary migrations or upgrade strategies, if any.</p>
<h2 id="prior-art-and-references-49"><a class="header" href="#prior-art-and-references-49">Prior Art and References</a></h2>
<p>Provide references to either prior art or other relevant research for the submitted design.</p>
<h2 id="unresolved-questions-46"><a class="header" href="#unresolved-questions-46">Unresolved Questions</a></h2>
<p>Provide specific questions to discuss and address before the RFC is voted on by the Fellowship. This should include, for example, alternatives to aspects of the proposed design where the appropriate trade-off to make is unclear.</p>
<h2 id="future-directions-and-related-material-39"><a class="header" href="#future-directions-and-related-material-39">Future Directions and Related Material</a></h2>
<p>Describe future work which could be enabled by this RFC, if it were accepted, as well as related RFCs. This is a place to brain-dump and explore possibilities, which themselves may become their own RFCs.</p>
</main>
<nav class="nav-wrapper" aria-label="Page navigation">
<!-- Mobile navigation buttons -->
<div style="clear: both"></div>
</nav>
</div>
</div>
<nav class="nav-wide-wrapper" aria-label="Page navigation">
</nav>
</div>
<script>
window.playground_copyable = true;
</script>
<script src="elasticlunr.min.js"></script>
<script src="mark.min.js"></script>
<script src="searcher.js"></script>
<script src="clipboard.min.js"></script>
<script src="highlight.js"></script>
<script src="book.js"></script>
<!-- Custom JS scripts -->
<script>
window.addEventListener('load', function() {
window.setTimeout(window.print, 100);
});
</script>
</div>
</body>
</html>