mirror of
https://github.com/pezkuwichain/pezkuwi-fellows.git
synced 2026-04-28 06:37:55 +00:00
748 lines
78 KiB
HTML
748 lines
78 KiB
HTML
|
|
<!DOCTYPE HTML>
|
|
<html lang="en" class="polkadot" dir="ltr">
|
|
<head>
|
|
<!-- Book generated using mdBook -->
|
|
<meta charset="UTF-8">
|
|
<title>RFC-0145: Remove the host-side runtime memory allocator - Polkadot Fellowship RFCs</title>
|
|
|
|
|
|
<!-- 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="chapter-item expanded "><a href="../new/0155-polkadot-dollar.html">RFC-0155: Polkadot$</a></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/0145-remove-unnecessary-allocator-usage.html" class="active">RFC-0145: Remove the host-side runtime memory allocator</a></li><li class="chapter-item expanded "><a href="../proposed/0150-voting-while-delegating.html">RFC-150: Allow Voting While Delegating</a></li><li class="chapter-item expanded "><a href="../proposed/0151-crowdsourced-decision-deposits.html">RFC-0151: Crowdsourced Decision Deposits</a></li><li class="chapter-item expanded "><a href="../proposed/0154-multi-slot-aura.html">RFC-0154: AURA Multi-Slot Collation </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/0009-improved-net-light-client-requests.html">RFC-0009: Improved light client requests networking protocol</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/0017-coretime-market-redesign.html">RFC-0017: Coretime Market Redesign</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="chapter-item expanded "><a href="../approved/0122-alias-origin-on-asset-transfers.html">RFC-0122: Asset transfers can alias XCM origin on destination to original origin</a></li><li class="chapter-item expanded "><a href="../approved/0123-pending-code-as-storage-location-for-runtime-upgrades.html">RFC-0123: Introduce :pending_code as intermediate storage key for the runtime code</a></li><li class="chapter-item expanded "><a href="../approved/0125-xcm-asset-metadata.html">RFC-0125: XCM Asset Metadata</a></li><li class="chapter-item expanded "><a href="../approved/0126-introduce-pvq.html">RFC-0126: Introduce PVQ (PolkaVM Query)</a></li><li class="chapter-item expanded "><a href="../approved/0135-compressed-blob-prefixes.html">RFC-0135: Compressed Blob Prefixes</a></li><li class="chapter-item expanded "><a href="../approved/0139-faster-erasure-coding.html">RFC-0139: Faster Erasure Coding</a></li><li class="chapter-item expanded "><a href="../approved/0146-deflationary-fee-proposal.html">RFC-0146: Deflationary Transaction Fee Model for the Relay Chain and its System Parachains</a></li><li class="chapter-item expanded "><a href="../approved/0149-rfc-1-renewal-adjustment.html">RFC-0149: Renewal Adjustment</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/0000-pre-elves_soft.html">RFC-0000: Pre-ELVES soft concensus</a></li><li class="chapter-item expanded "><a href="../stale/0000-rewards.html">RFC-0000: Validator Rewards</a></li><li class="chapter-item expanded "><a href="../stale/0004-remove-unnecessary-allocator-usage.html">RFC-0004: Remove the host-side runtime memory allocator</a></li><li class="chapter-item expanded "><a href="../stale/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="../stale/0034-xcm-absolute-location-account-derivation.html">RFC-34: XCM Absolute Location Account Derivation</a></li><li class="chapter-item expanded "><a href="../stale/0035-conviction-voting-delegation-modifications.html"> RFC-0035: Conviction Voting Delegation Modifications</a></li><li class="chapter-item expanded "><a href="../stale/0044-rent-based-registration.html">RFC-0044: Rent based registration model</a></li><li class="chapter-item expanded "><a href="../stale/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="../stale/0070-x-track-kusamanetwork.html">RFC-0070: X Track for @kusamanetwork</a></li><li class="chapter-item expanded "><a href="../stale/0073-referedum-deposit-track.html">RFC-0073: Decision Deposit Referendum Track</a></li><li class="chapter-item expanded "><a href="../stale/0074-stateful-multisig-pallet.html">RFC-0074: Stateful Multisig Pallet</a></li><li class="chapter-item expanded "><a href="../stale/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="../stale/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="../stale/00xx-secondary-marketplace-for-regions.html">RFC-0001: Secondary Market for Regions</a></li><li class="chapter-item expanded "><a href="../stale/00xx-smart-contracts-coretime-chain.html">RFC-0002: Smart Contracts on the Coretime Chain</a></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/0111-pure-proxy-replication.html">RFC-0111: Pure Proxy Replication</a></li><li class="chapter-item expanded "><a href="../stale/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="../stale/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="../stale/0117-unbrick-collective.html">RFC-0117: The Unbrick Collective</a></li><li class="chapter-item expanded "><a href="../stale/0120-referenda-confirmation-by-candle-mechanism.html">RFC-0120: Referenda Confirmation by Candle Mechanism</a></li><li class="chapter-item expanded "><a href="../stale/0124-extrinsic-version-5.html">RFC-0124: Extrinsic version 5</a></li><li class="chapter-item expanded "><a href="../stale/0138-invulnerable-collator-election.html">RFC-0138: Election mechanism for invulnerable collators on system chains</a></li><li class="chapter-item expanded "><a href="../stale/0152-decentralized-convex-preference-coretime-market-for-polkadot.html">RFC-0152: Decentralized Convex-Preference Coretime Market for Polkadot</a></li><li class="chapter-item expanded "><a href="../stale/RFC-114 Adjust Tipper Track Confirmation Periods.html">RFC-114: Adjust Tipper Track Confirmation Periods</a></li><li class="chapter-item expanded "><a href="../stale/TODO-stale-nomination-reward-curve.html">RFC-TODO: Stale Nomination Reward Curve</a></li><li class="chapter-item expanded "><a href="../stale/xxxx-improve-the-security-of-proof-of-possession.html">RFC-XXXX: Adding customized mandatory context to proof of possession statement</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><a href="https://github.com/polkadot-fellows/RFCs/pull/145">(source)</a></p>
|
|
<p><strong>Table of Contents</strong></p>
|
|
<ul>
|
|
<li><a href="#rfc-0145-remove-the-host-side-runtime-memory-allocator">RFC-0145: Remove the host-side runtime memory allocator</a>
|
|
<ul>
|
|
<li><a href="#summary">Summary</a></li>
|
|
<li><a href="#prior-art">Prior Art</a>
|
|
<ul>
|
|
<li><a href="#changes-from-rfc-4">Changes from RFC-4</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#motivation">Motivation</a></li>
|
|
<li><a href="#stakeholders">Stakeholders</a></li>
|
|
<li><a href="#explanation">Explanation</a>
|
|
<ul>
|
|
<li><a href="#new-definitions">New definitions</a></li>
|
|
<li><a href="#changes-to-host-functions">Changes to host functions</a></li>
|
|
<li><a href="#other-changes">Other changes</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<h1 id="rfc-0145-remove-the-host-side-runtime-memory-allocator"><a class="header" href="#rfc-0145-remove-the-host-side-runtime-memory-allocator">RFC-0145: 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>2025-05-16</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, Someone Unknown</td></tr>
|
|
<tr><td></td><td></td></tr>
|
|
</tbody></table>
|
|
</div>
|
|
<h2 id="summary"><a class="header" href="#summary">Summary</a></h2>
|
|
<p>Update the runtime-host interface so that it no longer uses the host-side allocator.</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 the API used by the C programming language.</p>
|
|
<p>This RFC is mainly based on <a href="https://github.com/polkadot-fellows/RFCs/pull/4">RFC-4</a> by @tomaka, which was never adopted, and this RFC supersedes it.</p>
|
|
<h3 id="changes-from-rfc-4"><a class="header" href="#changes-from-rfc-4">Changes from RFC-4</a></h3>
|
|
<ul>
|
|
<li>The original RFC required checking if an output buffer address provided to a host function is inside the VM address space range and to stop the runtime execution if that's not the case. That requirement has been removed in this version of the RFC, as in the general case, the host doesn't have exhaustive information about the VM's memory organization. Thus, attempting to write to an out-of-bounds region will result in a "normal" runtime panic.</li>
|
|
<li>Function signatures introduced by <a href="https://github.com/w3f/PPPs/pull/7">PPP#7</a> have been used in this RFC, as the PPP has already been <a href="https://github.com/paritytech/substrate/pull/11490">properly implemented</a> and <a href="https://github.com/w3f/polkadot-spec/pull/592/files">documented</a>. However, it has never been officially adopted, nor have its functions been in use.</li>
|
|
<li>Return values were harmonized to <code>i64</code> everywhere where they represent either a positive outcome as a positive integer or a negative outcome as a negative error code.</li>
|
|
<li><code>ext_offchain_network_peer_id_version_1</code> now returns a result code instead of silently failing if the network status is unavailable.</li>
|
|
<li>Added new versions of <code>ext_misc_runtime_version</code> and <code>ext_offchain_random_seed</code>.</li>
|
|
<li>Addressed discussions from the original RFC-4 discussion thread.</li>
|
|
</ul>
|
|
<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 contains buffer allocations. For example, when calling <code>ext_hashing_twox_256_version_1</code>, the host allocates a 32-byte 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 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 allocated by the runtime on its stack and passed by pointer to the function. Allocating a buffer on the stack, in the worst case, consists simply of decreasing a number; in the best case, it is free. Doing so would save many VM 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 through the runtime <-> host boundary twice (once for allocating and once for freeing). Moving the allocator to the runtime side would be a good idea, although it would increase the runtime size. But before the host-side allocator can be deprecated, all the host functions that use it must be updated to avoid using it.</p>
|
|
<h2 id="stakeholders"><a class="header" href="#stakeholders">Stakeholders</a></h2>
|
|
<p>No attempt was made to convince stakeholders.</p>
|
|
<h2 id="explanation"><a class="header" href="#explanation">Explanation</a></h2>
|
|
<h3 id="new-definitions"><a class="header" href="#new-definitions">New definitions</a></h3>
|
|
<h4 id="new-definition-i-runtime-optional-positive-integer"><a class="header" href="#new-definition-i-runtime-optional-positive-integer"><a name="new-def-i"></a>New Definition I: Runtime Optional Positive Integer</a></h4>
|
|
<p>The Runtime optional positive integer is a signed 64-bit value. Positive values in the range of [0..2³²) represent corresponding unsigned 32-bit values. The value of <code>-1</code> represents a non-existing value (an <em>absent</em> value). All other values are invalid.</p>
|
|
<h4 id="new-definition-ii-runtime-optional-pointer-size"><a class="header" href="#new-definition-ii-runtime-optional-pointer-size"><a name="new-def-ii"></a>New Definition II: Runtime Optional Pointer-Size</a></h4>
|
|
<p>The runtime optional pointer-size has exactly the same definition as runtime pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) with the value of 2⁶⁴-1 representing a non-existing value (an <em>absent</em> value).</p>
|
|
<h3 id="changes-to-host-functions"><a class="header" href="#changes-to-host-functions">Changes to host functions</a></h3>
|
|
<h4 id="ext_storage_get"><a class="header" href="#ext_storage_get">ext_storage_get</a></h4>
|
|
<p>The function is deprecated. Users are encouraged to use <code>ext_storage_read_version_2</code> instead.</p>
|
|
<h4 id="ext_storage_read"><a class="header" href="#ext_storage_read">ext_storage_read</a></h4>
|
|
<p>The new version 2 is introduced, deprecating <code>ext_storage_read_version_1</code>. The new signature is</p>
|
|
<pre><code class="language-wat">(func $ext_storage_read_version_2
|
|
(param $key i64) (param $value_out i64) (param $value_offset i32) (result i64))
|
|
</code></pre>
|
|
<h5 id="arguments"><a class="header" href="#arguments">Arguments</a></h5>
|
|
<ul>
|
|
<li><code>key</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to the storage key being read;</li>
|
|
<li><code>value_out</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to a buffer where the value read should be stored. If the buffer is not long enough to accommodate the value, the value is truncated to the length of the buffer;</li>
|
|
<li><code>value_offset</code> is a 32-bit offset from which the value reading should start.</li>
|
|
</ul>
|
|
<h5 id="result"><a class="header" href="#result">Result</a></h5>
|
|
<p>The result is an optional positive integer (<a href="#new-def-i">New Definition I</a>), representing either the full length of the value in storage or the <em>absence</em> of such a value in storage.</p>
|
|
<h5 id="changes"><a class="header" href="#changes">Changes</a></h5>
|
|
<p>The logic of the function is unchanged since the previous version. Only the result representation has changed.</p>
|
|
<h4 id="ext_storage_clear_prefix"><a class="header" href="#ext_storage_clear_prefix">ext_storage_clear_prefix</a></h4>
|
|
<p>The new version 3 is introduced, deprecating <code>ext_storage_clear_prefix_version_2</code>. The new signature is</p>
|
|
<pre><code class="language-wat">(func $ext_storage_clear_prefix_version_3
|
|
(param $maybe_prefix i64) (param $maybe_limit i64) (param $maybe_cursor_in i64)
|
|
(param $maybe_cursor_out i64) (param $backend i32) (param $unique i32) (param $loops i32)
|
|
(result i32))
|
|
</code></pre>
|
|
<h5 id="arguments-1"><a class="header" href="#arguments-1">Arguments</a></h5>
|
|
<ul>
|
|
<li><code>maybe_prefix</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) containing a (possibly empty) storage prefix being cleared;</li>
|
|
<li><code>maybe_limit</code> is an optional positive integer (<a href="#new-def-i">New Definition I</a>) representing either the maximum number of backend deletions which may happen, or the <em>absence</em> of such a limit. The number of backend iterations may surpass this limit by no more than one;</li>
|
|
<li><code>maybe_cursor_in</code> is an optional pointer-size (<a href="#new-def-ii">New Definition II</a>) representing the cursor returned by the previous (unfinished) call to this function. It should be <em>absent</em> on the first call;</li>
|
|
<li><code>maybe_cursor_out</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to a buffer where the continuation cursor will optionally be written (see also the Result section);</li>
|
|
<li><code>backend</code> is a pointer (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer">Definition 215</a>) to a 4-byte buffer where a 32-bit integer representing the number of items removed from the backend database will be written;</li>
|
|
<li><code>unique</code> is a pointer (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer">Definition 215</a>) to a 4-byte buffer where a 32-bit integer representing the number of unique keys removed, taking into account both the backend and the overlay;</li>
|
|
<li><code>loops</code> is a pointer (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer">Definition 215</a>) to a 4-byte buffer where a 32-bit integer representing the number of iterations (each requiring a storage seek/read) which were done will be written.</li>
|
|
</ul>
|
|
<h5 id="result-1"><a class="header" href="#result-1">Result</a></h5>
|
|
<p>The result represents the length of the continuation cursor which was written to the buffer provided in <code>maybe_cursor_out</code>. A zero value represents the absence of such a cursor and no need for continuation (the prefix has been completely cleared). If the buffer is not large enough to accommodate the cursor, the latter will be truncated, but the full length of the cursor will always be returned.</p>
|
|
<h5 id="changes-1"><a class="header" href="#changes-1">Changes</a></h5>
|
|
<p>The new version adopts <a href="https://github.com/w3f/PPPs/pull/7">PPP#7</a>, hence the significant change in the function interface with respect to the previous version. The reasoning for such a change was provided in the <a href="https://github.com/w3f/polkadot-spec/issues/588">original proposal discussion</a>.</p>
|
|
<h4 id="ext_storage_root"><a class="header" href="#ext_storage_root">ext_storage_root</a></h4>
|
|
<p>The new version 3 is introduced, deprecating <code>ext_storage_root_version_2</code>. The signature is</p>
|
|
<pre><code class="language-wat">(func $ext_storage_root_version_3
|
|
(param $out i64) (result i32))
|
|
</code></pre>
|
|
<h5 id="arguments-2"><a class="header" href="#arguments-2">Arguments</a></h5>
|
|
<ul>
|
|
<li><code>out</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to a buffer where the SCALE-encoded storage root, calculated after committing all the existing operations, will be stored.</li>
|
|
</ul>
|
|
<h5 id="results"><a class="header" href="#results">Results</a></h5>
|
|
<p>The result is the length of the output stored in the buffer provided in <code>out</code>. If the buffer is not large enough to accommodate the data, the latter will be truncated, but the full length of the output data will always be returned.</p>
|
|
<h5 id="changes-2"><a class="header" href="#changes-2">Changes</a></h5>
|
|
<p>The new version adopts <a href="https://github.com/w3f/PPPs/pull/6">PPP#6</a> deprecating the argument that used to represent the storage version.</p>
|
|
<h4 id="ext_storage_next_key"><a class="header" href="#ext_storage_next_key">ext_storage_next_key</a></h4>
|
|
<p>The new version 2 is introduced, deprecating <code>ext_storage_next_key_version_1</code>. The signature is</p>
|
|
<pre><code class="language-wat">(func $ext_storage_next_key_version_2
|
|
(param $key_in i64) (param $key_out i64) (result i32))
|
|
</code></pre>
|
|
<h5 id="changes-3"><a class="header" href="#changes-3">Changes</a></h5>
|
|
<p>The logic of the function is unchanged since the previous version. The signature has changed to align with the new memory allocation strategy.</p>
|
|
<h5 id="arguments-3"><a class="header" href="#arguments-3">Arguments</a></h5>
|
|
<ul>
|
|
<li><code>key_in</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to a buffer containing a storage key;</li>
|
|
<li><code>key_out</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to an output buffer where the next key in the storage in the lexicographical order will be written.</li>
|
|
</ul>
|
|
<h5 id="result-2"><a class="header" href="#result-2">Result</a></h5>
|
|
<p>The result is the length of the output key, or zero if no next key was found. If the buffer provided in <code>key_out</code> is not large enough to accommodate the data, the latter will be truncated, but the full length of the output data will always be returned.</p>
|
|
<h4 id="ext_default_child_storage_get"><a class="header" href="#ext_default_child_storage_get">ext_default_child_storage_get</a></h4>
|
|
<p>The function is deprecated. Users are encouraged to use <code>ext_default_child_storage_read_version_2</code> instead.</p>
|
|
<h4 id="ext_default_child_storage_read"><a class="header" href="#ext_default_child_storage_read">ext_default_child_storage_read</a></h4>
|
|
<p>The new version 2 is introduced, deprecating <code>ext_default_child_storage_read_version_1</code>. The new signature is</p>
|
|
<pre><code class="language-wat">(func $ext_storage_read_version_2
|
|
(param $storage_key i64) (param $key i64) (param $value_out i64) (param $value_offset i32)
|
|
(result i64))
|
|
</code></pre>
|
|
<h5 id="arguments-4"><a class="header" href="#arguments-4">Arguments</a></h5>
|
|
<ul>
|
|
<li><code>storage_key</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to the child storage key (<a href="https://spec.polkadot.network/chap-host-api#defn-child-storage-type">Definition 219</a>);</li>
|
|
<li><code>key</code> is the storage key being read;</li>
|
|
<li><code>value_out</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to a buffer where the value read should be stored. If the buffer is not long enough to accommodate the value, the value is truncated to the length of the buffer;</li>
|
|
<li><code>value_offset</code> is a 32-bit offset from which the value reading should start.</li>
|
|
</ul>
|
|
<h5 id="result-3"><a class="header" href="#result-3">Result</a></h5>
|
|
<p>The result is an optional positive integer (<a href="#new-def-i">New Definition I</a>), representing either the full length of the value in storage or the <em>absence</em> of such a value in storage.</p>
|
|
<h5 id="changes-4"><a class="header" href="#changes-4">Changes</a></h5>
|
|
<p>The logic of the function is unchanged since the previous version. Only the result representation has changed.</p>
|
|
<h4 id="ext_default_child_storage_storage_kill"><a class="header" href="#ext_default_child_storage_storage_kill">ext_default_child_storage_storage_kill</a></h4>
|
|
<p>The new version 4 is introduced, deprecating <code>ext_default_child_storage_storage_kill_version_3</code>. The new signature is</p>
|
|
<pre><code class="language-wat">(func $ext_default_child_storage_storage_kill_version_4
|
|
(param $storage_key i64) (param $maybe_limit i64) (param $maybe_cursor_in i64)
|
|
(param $maybe_cursor_out i64) (param $backend i32) (param $unique i32) (param $loops i32)
|
|
(result i32))
|
|
</code></pre>
|
|
<h5 id="arguments-5"><a class="header" href="#arguments-5">Arguments</a></h5>
|
|
<ul>
|
|
<li><code>storage_key</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to the child storage key (<a href="https://spec.polkadot.network/chap-host-api#defn-child-storage-type">Definition 219</a>);</li>
|
|
<li><code>maybe_limit</code> is an optional positive integer representing either the maximum number of backend deletions which may happen, or the absence of such a limit. The number of backend iterations may surpass this limit by no more than one;</li>
|
|
<li><code>maybe_cursor_in</code> is an optional pointer-size representing the cursor returned by the previous (unfinished) call to this function. It should be <em>absent</em> on the first call;</li>
|
|
<li><code>maybe_cursor_out</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to a buffer where the continuation cursor will optionally be written (see also the Result section);</li>
|
|
<li><code>backend</code> is a pointer (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer">Definition 215</a>) to a 4-byte buffer where a 32-bit integer representing the number of items removed from the backend database will be written;</li>
|
|
<li><code>unique</code> is a pointer (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer">Definition 215</a>) to a 4-byte buffer where a 32-bit integer representing the number of unique keys removed, taking into account both the backend and the overlay;</li>
|
|
<li><code>loops</code> is a pointer (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer">Definition 215</a>) to a 4-byte buffer where a 32-bit integer representing the number of iterations (each requiring a storage seek/read) which were done will be written.</li>
|
|
</ul>
|
|
<h5 id="result-4"><a class="header" href="#result-4">Result</a></h5>
|
|
<p>The result represents the length of the continuation cursor which was written to the buffer provided in <code>maybe_cursor_out</code>. A zero value represents the absence of such a cursor and no need for continuation (the prefix has been completely cleared). If the buffer is not large enough to accommodate the cursor, the latter will be truncated, but the full length of the cursor will always be returned.</p>
|
|
<h5 id="changes-5"><a class="header" href="#changes-5">Changes</a></h5>
|
|
<p>The new version adopts <a href="https://github.com/w3f/PPPs/pull/7">PPP#7</a>, hence the significant change in the function interface with respect to the previous version. The reasoning for such a change was provided in the <a href="https://github.com/w3f/polkadot-spec/issues/588">original proposal discussion</a>.</p>
|
|
<h4 id="ext_default_child_storage_clear_prefix"><a class="header" href="#ext_default_child_storage_clear_prefix">ext_default_child_storage_clear_prefix</a></h4>
|
|
<p>The new version 3 is introduced, deprecating <code>ext_default_child_storage_clear_prefix_version_2</code>. The new signature is</p>
|
|
<pre><code class="language-wat">(func $ext_default_child_storage_clear_prefix_version_3
|
|
(param $storage_key i64) (param $prefix i64) (param $maybe_limit i64)
|
|
(param $maybe_cursor_in i64) (param $maybe_cursor_out i64) (param $backend i32)
|
|
(param $unique i32) (param $loops i32) (result i32))
|
|
</code></pre>
|
|
<h5 id="arguments-6"><a class="header" href="#arguments-6">Arguments</a></h5>
|
|
<ul>
|
|
<li><code>storage_key</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to the child storage key (<a href="https://spec.polkadot.network/chap-host-api#defn-child-storage-type">Definition 219</a>);</li>
|
|
<li><code>prefix</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) containing a storage prefix being cleared;</li>
|
|
<li><code>maybe_limit</code> is an optional positive integer representing either the maximum number of backend deletions which may happen, or the absence of such a limit. The number of backend iterations may surpass this limit by no more than one;</li>
|
|
<li><code>maybe_cursor_in</code> is an optional pointer-size representing the cursor returned by the previous (unfinished) call to this function. It should be <em>absent</em> on the first call;</li>
|
|
<li><code>maybe_cursor_out</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to a buffer where the continuation cursor will optionally be written (see also the Result section);</li>
|
|
<li><code>backend</code> is a pointer (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer">Definition 215</a>) to a 4-byte buffer where a 32-bit integer representing the number of items removed from the backend database will be written;</li>
|
|
<li><code>unique</code> is a pointer (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer">Definition 215</a>) to a 4-byte buffer where a 32-bit integer representing the number of unique keys removed, taking into account both the backend and the overlay;</li>
|
|
<li><code>loops</code> is a pointer (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer">Definition 215</a>) to a 4-byte buffer where a 32-bit integer representing the number of iterations (each requiring a storage seek/read) which were done will be written.</li>
|
|
</ul>
|
|
<h5 id="result-5"><a class="header" href="#result-5">Result</a></h5>
|
|
<p>The result represents the length of the continuation cursor which was written to the buffer provided in <code>maybe_cursor_out</code>. A zero value represents the absence of such a cursor and no need for continuation (the prefix has been completely cleared). If the buffer is not large enough to accommodate the cursor, the latter will be truncated, but the full length of the cursor will always be returned.</p>
|
|
<h5 id="changes-6"><a class="header" href="#changes-6">Changes</a></h5>
|
|
<p>The new version adopts <a href="https://github.com/w3f/PPPs/pull/7">PPP#7</a>, hence the significant change in the function interface with respect to the previous version. The reasoning for such a change was provided in the <a href="https://github.com/w3f/polkadot-spec/issues/588">original proposal discussion</a>.</p>
|
|
<h4 id="ext_default_child_storage_root"><a class="header" href="#ext_default_child_storage_root">ext_default_child_storage_root</a></h4>
|
|
<p>The new version 3 is introduced, deprecating <code>ext_default_child_storage_root_version_2</code>. The signature is</p>
|
|
<pre><code class="language-wat">(func $ext_default_child_storage_root_version_3
|
|
(param $storage_key i64) (param $out i64) (result i32))
|
|
</code></pre>
|
|
<h5 id="arguments-7"><a class="header" href="#arguments-7">Arguments</a></h5>
|
|
<ul>
|
|
<li><code>storage_key</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to the child storage key (<a href="https://spec.polkadot.network/chap-host-api#defn-child-storage-type">Definition 219</a>);</li>
|
|
<li><code>out</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to a buffer where the SCALE-encoded storage root, calculated after committing all the existing operations, will be stored.</li>
|
|
</ul>
|
|
<h5 id="results-1"><a class="header" href="#results-1">Results</a></h5>
|
|
<p>The result is the length of the output stored in the buffer provided in <code>out</code>. If the buffer is not large enough to accommodate the data, the latter will be truncated, but the full length of the output data will always be returned.</p>
|
|
<h5 id="changes-7"><a class="header" href="#changes-7">Changes</a></h5>
|
|
<p>The new version adopts <a href="https://github.com/w3f/PPPs/pull/6">PPP#6</a> deprecating the argument that used to represent the storage version.</p>
|
|
<h4 id="ext_default_child_storage_next_key"><a class="header" href="#ext_default_child_storage_next_key">ext_default_child_storage_next_key</a></h4>
|
|
<p>The new version 2 is introduced, deprecating <code>ext_default_child_storage_next_key_version_1</code>. The signature is</p>
|
|
<pre><code class="language-wat">(func $ext_default_child_storage_next_key_version_2
|
|
(param $storage_key i64) (param $key_in i64) (param $key_out i64) (result i32))
|
|
</code></pre>
|
|
<h5 id="arguments-8"><a class="header" href="#arguments-8">Arguments</a></h5>
|
|
<ul>
|
|
<li><code>storage_key</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to the child storage key (<a href="https://spec.polkadot.network/chap-host-api#defn-child-storage-type">Definition 219</a>);</li>
|
|
<li><code>key_in</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to a buffer containing a storage key;</li>
|
|
<li><code>key_out</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to an output buffer where the next key in the storage in the lexicographical order will be written.</li>
|
|
</ul>
|
|
<h5 id="result-6"><a class="header" href="#result-6">Result</a></h5>
|
|
<p>The result is the length of the output key, or zero if no next key was found. If the buffer provided in <code>key_out</code> is not large enough to accommodate the data, the latter will be truncated, but the full length of the output data will always be returned.</p>
|
|
<h5 id="changes-8"><a class="header" href="#changes-8">Changes</a></h5>
|
|
<p>The logic of the function is unchanged since the previous version. The signature has changed to align with the new memory allocation strategy.</p>
|
|
<h4 id="ext_trie_blake2keccak_256_ordered_root"><a class="header" href="#ext_trie_blake2keccak_256_ordered_root">ext_trie_{blake2|keccak}_256_[ordered_]root</a></h4>
|
|
<p>The following functions share the same signatures and set of changes:</p>
|
|
<ul>
|
|
<li><code>ext_trie_blake2_256_root</code></li>
|
|
<li><code>ext_trie_blake2_256_ordered_root</code></li>
|
|
<li><code>ext_trie_keccak_256_root</code></li>
|
|
<li><code>ext_trie_keccak_256_ordered_root</code></li>
|
|
</ul>
|
|
<p>For the aforementioned functions, versions 3 were introduced, and the corresponding versions 2 were deprecated. The signature is:</p>
|
|
<pre><code class="language-wat">(func $ext_trie_{blake2|keccak}_256_[ordered_]root_version_3
|
|
(param $input i64) (param $version i32) (param $out i32))
|
|
</code></pre>
|
|
<h5 id="arguments-9"><a class="header" href="#arguments-9">Arguments</a></h5>
|
|
<ul>
|
|
<li><code>input</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to the SCALE-encoded vector of the trie key-value pairs;</li>
|
|
<li><code>version</code> is the state version, where <code>0</code> denotes V0 and <code>1</code> denotes V1 state version. Other state versions may be introduced in the future;</li>
|
|
<li><code>out</code> is a pointer (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer">Definition 215</a>) to a 32-byte buffer, where the calculated trie root will be stored.</li>
|
|
</ul>
|
|
<h5 id="changes-9"><a class="header" href="#changes-9">Changes</a></h5>
|
|
<p>The logic of the function is unchanged since the previous version. The signature has changed to align with the new memory allocation strategy.</p>
|
|
<h4 id="ext_misc_runtime_version"><a class="header" href="#ext_misc_runtime_version">ext_misc_runtime_version</a></h4>
|
|
<p>The new version 2 is introduced, deprecating <code>ext_default_child_storage_next_key_version_1</code>. The signature is</p>
|
|
<pre><code class="language-wat">(func $ext_misc_runtime_version_version_2
|
|
(param $wasm i64) (param $out i64) (result i64))
|
|
</code></pre>
|
|
<h5 id="arguments-10"><a class="header" href="#arguments-10">Arguments</a></h5>
|
|
<ul>
|
|
<li><code>wasm</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to the Wasm blob from which the version information should be extracted;</li>
|
|
<li><code>out</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to the buffer where the SCALE-encoded extracted version information will be stored.</li>
|
|
</ul>
|
|
<h5 id="result-7"><a class="header" href="#result-7">Result</a></h5>
|
|
<p>The result is an optional positive integer (<a href="#new-def-i">New Definition I</a>) representing the length of the output data. If the buffer is not large enough to accommodate the data, the latter will be truncated, but the full length of the output data will always be returned. An <em>absent</em> value represents the absence of the version information in the Wasm blob or a failure to read one.</p>
|
|
<h5 id="changes-10"><a class="header" href="#changes-10">Changes</a></h5>
|
|
<p>The logic of the function is unchanged since the previous version. The signature has changed to align with the new memory allocation strategy.</p>
|
|
<h4 id="ext_crypto_ed25519sr25519ecdsa_public_keys"><a class="header" href="#ext_crypto_ed25519sr25519ecdsa_public_keys">ext_crypto_{ed25519|sr25519|ecdsa}_public_keys</a></h4>
|
|
<p>The following functions are deprecated:</p>
|
|
<ul>
|
|
<li><code>ext_crypto_ed25519_public_keys_version_1</code></li>
|
|
<li><code>ext_crypto_sr25519_public_keys_version_1</code></li>
|
|
<li><code>ext_crypto_ecdsa_public_keys_version_1</code></li>
|
|
</ul>
|
|
<p>Users are encouraged to use the new <code>*_num_public_keys</code> and <code>*_public_key</code> counterparts.</p>
|
|
<h4 id="ext_crypto_ed25519sr25519ecdsa_num_public_keys"><a class="header" href="#ext_crypto_ed25519sr25519ecdsa_num_public_keys">ext_crypto_{ed25519|sr25519|ecdsa}_num_public_keys</a></h4>
|
|
<p>New functions, all sharing the same signature and logic, are introduced:</p>
|
|
<ul>
|
|
<li><code>ext_crypto_ed25519_num_public_keys_version_1</code></li>
|
|
<li><code>ext_crypto_sr25519_num_public_keys_version_1</code></li>
|
|
<li><code>ext_crypto_ecdsa_num_public_keys_version_1</code></li>
|
|
</ul>
|
|
<p>The signature is:</p>
|
|
<pre><code class="language-wat">(func $ext_crypto_{ed25519|sr25519|ecdsa}_num_public_keys
|
|
(param $id i32) (result i32))
|
|
</code></pre>
|
|
<h5 id="arguments-11"><a class="header" href="#arguments-11">Arguments</a></h5>
|
|
<ul>
|
|
<li><code>id</code> is a pointer (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer">Definition 215</a>) to the key type identifier (<a href="https://spec.polkadot.network/chap-host-api#defn-key-type-id">Definition 220</a>).</li>
|
|
</ul>
|
|
<h5 id="result-8"><a class="header" href="#result-8">Result</a></h5>
|
|
<p>The result represents a (possibly zero) number of keys of the given type known to the keystore.</p>
|
|
<h4 id="ext_crypto_ed25519sr25519ecdsa_public_key"><a class="header" href="#ext_crypto_ed25519sr25519ecdsa_public_key">ext_crypto_{ed25519|sr25519|ecdsa}_public_key</a></h4>
|
|
<p>New functions, all sharing the same signature and logic, are introduced:</p>
|
|
<ul>
|
|
<li><code>ext_crypto_ed25519_public_key_version_1</code></li>
|
|
<li><code>ext_crypto_sr25519_public_key_version_1</code></li>
|
|
<li><code>ext_crypto_ecdsa_public_key_version_1</code></li>
|
|
</ul>
|
|
<p>The signature is:</p>
|
|
<pre><code class="language-wat">(func $ext_crypto_{ed25519|sr25519|ecdsa}_public_key
|
|
(param $id i32) (param $index i32) (param $out))
|
|
</code></pre>
|
|
<h5 id="arguments-12"><a class="header" href="#arguments-12">Arguments</a></h5>
|
|
<ul>
|
|
<li><code>id</code> is a pointer (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer">Definition 215</a>) to the key type identifier (<a href="https://spec.polkadot.network/chap-host-api#defn-key-type-id">Definition 220</a>).</li>
|
|
<li><code>index</code> is the index of the key in the keystore. If the index is out of bounds (determined by the value returned by the respective <code>_num_public_keys</code> function) the function will panic;</li>
|
|
<li><code>out</code> is a pointer (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer">Definition 215</a>) to the output buffer of the respective size (depending on key type) where the key will be written.</li>
|
|
</ul>
|
|
<h4 id="ext_crypto_ed25519sr25519ecdsa_generate"><a class="header" href="#ext_crypto_ed25519sr25519ecdsa_generate">ext_crypto_{ed25519|sr25519|ecdsa}_generate</a></h4>
|
|
<p>The following functions share the same signatures and set of changes:</p>
|
|
<ul>
|
|
<li><code>ext_crypto_ed25519_generate</code></li>
|
|
<li><code>ext_crypto_sr25519_generate</code></li>
|
|
<li><code>ext_crypto_ecdsa_generate</code></li>
|
|
</ul>
|
|
<p>For the aforementioned functions, versions 2 are introduced, and the corresponding versions 1 are deprecated. The signature is:</p>
|
|
<pre><code class="language-wat">(func $ext_crypto_{ed25519|sr25519|ecdsa}_generate_version_2
|
|
(param $id i32) (param $seed i64) (param $out i32))
|
|
</code></pre>
|
|
<h5 id="arguments-13"><a class="header" href="#arguments-13">Arguments</a></h5>
|
|
<ul>
|
|
<li><code>id</code> is a pointer (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer">Definition 215</a>) to the key type identifier (<a href="https://spec.polkadot.network/chap-host-api#defn-key-type-id">Definition 220</a>). The function will panic if the identifier is invalid;</li>
|
|
<li><code>seed</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to the SCALE-encoded Option value (<a href="https://spec.polkadot.network/id-cryptography-encoding#defn-option-type">Definition 200</a>) containing the BIP-39 seed which must be valid UTF-8. The function will panic if the seed is not valid UTF-8;</li>
|
|
<li><code>out</code> is a pointer (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer">Definition 215</a>) to the output buffer of the respective size (depending on key type) where the generated key will be written.</li>
|
|
</ul>
|
|
<h5 id="changes-11"><a class="header" href="#changes-11">Changes</a></h5>
|
|
<p>The logic of the functions is unchanged since the previous version. The signature has changed to align with the new memory allocation strategy.</p>
|
|
<h4 id="ext_crypto_ed25519sr25519ecdsa_sign_prehashed"><a class="header" href="#ext_crypto_ed25519sr25519ecdsa_sign_prehashed">ext_crypto_{ed25519|sr25519|ecdsa}_sign[_prehashed]</a></h4>
|
|
<p>The following functions share the same signatures and set of changes:</p>
|
|
<ul>
|
|
<li><code>ext_crypto_ed25519_sign</code></li>
|
|
<li><code>ext_crypto_sr25519_sign</code></li>
|
|
<li><code>ext_crypto_ecdsa_sign</code></li>
|
|
<li><code>ext_crypto_ecdsa_sign_prehashed</code></li>
|
|
</ul>
|
|
<p>For the aforementioned functions, versions 2 are introduced, and the corresponding versions 1 are deprecated. The signature is:</p>
|
|
<pre><code class="language-wat">(func $ext_crypto_{ed25519|sr25519|ecdsa}_sign{_prehashed|}_version_2
|
|
(param $id i32) (param $pub_key i32) (param $msg i64) (param $out i64) (result i64))
|
|
</code></pre>
|
|
<h5 id="arguments-14"><a class="header" href="#arguments-14">Arguments</a></h5>
|
|
<ul>
|
|
<li><code>id</code> is a pointer (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer">Definition 215</a>) to the key type identifier (<a href="https://spec.polkadot.network/chap-host-api#defn-key-type-id">Definition 220</a>). The function will panic if the identifier is invalid;</li>
|
|
<li><code>pub_key</code> is a pointer (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer">Definition 215</a>) to the public key bytes (as returned by the respective <code>_public_key</code> function);</li>
|
|
<li><code>msg</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to the message that is to be signed;</li>
|
|
<li><code>out</code> is a pointer (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer">Definition 215</a>) to the output buffer of the respective size (depending on key type) where the signature will be written.</li>
|
|
</ul>
|
|
<h5 id="result-9"><a class="header" href="#result-9">Result</a></h5>
|
|
<p>The function returns <code>0</code> on success. On error, <code>-1</code> is returned and the output buffer should be considered uninitialized.</p>
|
|
<h5 id="changes-12"><a class="header" href="#changes-12">Changes</a></h5>
|
|
<p>The logic of the functions is unchanged since the previous version. The signature has changed to align with the new memory allocation strategy.</p>
|
|
<h4 id="ext_crypto_secp256k1_ecdsa_recover_compressed"><a class="header" href="#ext_crypto_secp256k1_ecdsa_recover_compressed">ext_crypto_secp256k1_ecdsa_recover[_compressed]</a></h4>
|
|
<p>The following functions share the same signatures and set of changes:</p>
|
|
<ul>
|
|
<li><code>ext_crypto_secp256k1_ecdsa_recover</code></li>
|
|
<li><code>ext_crypto_secp256k1_ecdsa_recover_compressed</code></li>
|
|
</ul>
|
|
<p>For the aforementioned functions, versions 3 are introduced, and the corresponding versions 2 are deprecated. The signature is:</p>
|
|
<pre><code class="language-wat">(func $ext_crypto_secp256k1_ecdsa_recover\[_compressed]_version_3
|
|
(param $sig i32) (param $msg i32) (param $out i32) (result i64))
|
|
</code></pre>
|
|
<h5 id="arguments-15"><a class="header" href="#arguments-15">Arguments</a></h5>
|
|
<ul>
|
|
<li><code>sig</code> is a pointer (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer">Definition 215</a>) to the buffer containing the 65-byte signature in RSV format. V must be either 0/1 or 27/28;</li>
|
|
<li><code>msg</code> is a pointer (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer">Definition 215</a>) to the buffer containing the 256-bit Blake2 hash of the message;</li>
|
|
<li><code>out</code> is a pointer (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer">Definition 215</a>) to the output buffer of the respective size (depending on key type) where the recovered public key will be written.</li>
|
|
</ul>
|
|
<h5 id="result-10"><a class="header" href="#result-10">Result</a></h5>
|
|
<p>The function returns <code>0</code> on success. On error, it returns a negative ECDSA verification error code, where <code>-1</code> stands for incorrect R or S, <code>-2</code> stands for invalid V, and <code>-3</code> stands for invalid signature.</p>
|
|
<h5 id="changes-13"><a class="header" href="#changes-13">Changes</a></h5>
|
|
<p>The signature has changed to align with the new memory allocation strategy. The return error encoding, defined under <a href="https://spec.polkadot.network/chap-host-api#defn-ecdsa-verify-error">Definition 221</a>, is changed to promote the unification of host function result reporting (zero and positive values are for success, and the negative values are for failure codes).</p>
|
|
<h4 id="ext_hashing_keccaksha2blake2twox_"><a class="header" href="#ext_hashing_keccaksha2blake2twox_">ext_hashing_{keccak|sha2|blake2|twox}_</a></h4>
|
|
<p>The following functions share the same signatures and set of changes:</p>
|
|
<ul>
|
|
<li><code>ext_hashing_keccak_256</code></li>
|
|
<li><code>ext_hashing_keccak_512</code></li>
|
|
<li><code>ext_hashing_sha2_256</code></li>
|
|
<li><code>ext_hashing_blake2_128</code></li>
|
|
<li><code>ext_hashing_blake2_256</code></li>
|
|
<li><code>ext_hashing_twox_64</code></li>
|
|
<li><code>ext_hashing_twox_128</code></li>
|
|
<li><code>ext_hashing_twox_256</code></li>
|
|
</ul>
|
|
<p>For the aforementioned functions, versions 2 are introduced, and the corresponding versions 1 are deprecated. The signature is:</p>
|
|
<pre><code class="language-wat">(func $ext_hashing_{keccak|sha2|blake2|twox}_{64|128|256|512}_version_2
|
|
(param $data i64) (param $out i32))
|
|
</code></pre>
|
|
<h5 id="arguments-16"><a class="header" href="#arguments-16">Arguments</a></h5>
|
|
<ul>
|
|
<li><code>data</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to the data to be hashed.</li>
|
|
<li><code>out</code> is a pointer (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer">Definition 215</a>) to the output buffer of the respective size (depending on hash type) where the calculated hash will be written.</li>
|
|
</ul>
|
|
<h5 id="changes-14"><a class="header" href="#changes-14">Changes</a></h5>
|
|
<p>The logic of the functions is unchanged since the previous version. The signature has changed to align with the new memory allocation strategy.</p>
|
|
<h4 id="ext_offchain_submit_transaction"><a class="header" href="#ext_offchain_submit_transaction">ext_offchain_submit_transaction</a></h4>
|
|
<p>The new version 2 is introduced, deprecating <code>ext_offchain_submit_transaction_version_1</code>. The signature is unchanged.</p>
|
|
<pre><code class="language-wat">(func $ext_offchain_submit_transaction_version_2
|
|
(param $data i64) (result i64))
|
|
</code></pre>
|
|
<h5 id="arguments-17"><a class="header" href="#arguments-17">Arguments</a></h5>
|
|
<ul>
|
|
<li><code>data</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to the byte array storing the encoded extrinsic.</li>
|
|
</ul>
|
|
<h5 id="result-11"><a class="header" href="#result-11">Result</a></h5>
|
|
<p>The result is <code>0</code> for success or <code>-1</code> for failure.</p>
|
|
<h5 id="changes-15"><a class="header" href="#changes-15">Changes</a></h5>
|
|
<p>The logic and the signature of the function are unchanged since the previous version. The only change is the interpretation of the result value to avoid an unneeded allocation and promote the unification of host function result reporting (zero and positive values are for success, and the negative values are for failure codes).</p>
|
|
<h4 id="ext_offchain_network_state"><a class="header" href="#ext_offchain_network_state">ext_offchain_network_state</a></h4>
|
|
<p>The function is deprecated. Users are encouraged to use <code>ext_offchain_network_peer_id_version_1</code> instead.</p>
|
|
<h4 id="ext_offchain_network_peer_id"><a class="header" href="#ext_offchain_network_peer_id">ext_offchain_network_peer_id</a></h4>
|
|
<p>A new function is introduced. The signature is</p>
|
|
<pre><code class="language-wat">(func $ext_offchain_submit_transaction_version_2
|
|
(param $out i32) (result i64))
|
|
</code></pre>
|
|
<h5 id="arguments-18"><a class="header" href="#arguments-18">Arguments</a></h5>
|
|
<ul>
|
|
<li><code>out</code> is a pointer (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer">Definition 215</a>) to the output buffer, 38 bytes long, where the network peer ID will be written.</li>
|
|
</ul>
|
|
<h5 id="result-12"><a class="header" href="#result-12">Result</a></h5>
|
|
<p>The result is <code>0</code> for success or <code>-1</code> for failure.</p>
|
|
<h4 id="ext_offchain_random_seed"><a class="header" href="#ext_offchain_random_seed">ext_offchain_random_seed</a></h4>
|
|
<p>The new version 2 is introduced, deprecating <code>ext_offchain_random_seed_version_1</code>. The signature is unchanged.</p>
|
|
<pre><code class="language-wat">(func $ext_offchain_random_seed_version_2
|
|
(param $out i32))
|
|
</code></pre>
|
|
<h5 id="arguments-19"><a class="header" href="#arguments-19">Arguments</a></h5>
|
|
<ul>
|
|
<li><code>out</code> is a pointer (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer">Definition 215</a>) to the output buffer, 32 bytes long, where the random seed will be written.</li>
|
|
</ul>
|
|
<h5 id="changes-16"><a class="header" href="#changes-16">Changes</a></h5>
|
|
<p>The logic of the functions is unchanged since the previous version. The signature has changed to align with the new memory allocation strategy and promote the unification of host function result returning (zero and positive values are for success, and the negative values are for failure codes).</p>
|
|
<h4 id="ext_offchain_local_storage_get"><a class="header" href="#ext_offchain_local_storage_get">ext_offchain_local_storage_get</a></h4>
|
|
<p>The function is deprecated. Users are encouraged to use <code>ext_offchain_local_storage_read_version_1</code> instead.</p>
|
|
<h4 id="ext_offchain_local_storage_read"><a class="header" href="#ext_offchain_local_storage_read">ext_offchain_local_storage_read</a></h4>
|
|
<p>A new function is introduced. The signature is</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>
|
|
<h5 id="arguments-20"><a class="header" href="#arguments-20">Arguments</a></h5>
|
|
<ul>
|
|
<li><code>kind</code> is an offchain storage kind, where <code>0</code> denotes the persistent storage (<a href="https://spec.polkadot.network/chap-host-api#defn-offchain-persistent-storage">Definition 222</a>), and <code>1</code> denotes the local storage (<a href="https://spec.polkadot.network/chap-host-api#defn-offchain-persistent-storage">Definition 223</a>);</li>
|
|
<li><code>key</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to the storage key being read;</li>
|
|
<li><code>value_out</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to a buffer where the value read should be stored. If the buffer is not large enough to accommodate the value, the value is truncated to the length of the buffer;</li>
|
|
<li><code>offset</code> is a 32-bit offset from which the value reading should start.</li>
|
|
</ul>
|
|
<h5 id="result-13"><a class="header" href="#result-13">Result</a></h5>
|
|
<p>The result is an optional positive integer (<a href="#new-def-i">New Definition I</a>), representing either the full length of the value in storage or the <em>absence</em> of such a value in storage.</p>
|
|
<h4 id="ext_offchain_http_request_start"><a class="header" href="#ext_offchain_http_request_start">ext_offchain_http_request_start</a></h4>
|
|
<p>The new version 2 is introduced, deprecating <code>ext_offchain_http_request_start_version_1</code>. The signature is unchanged.</p>
|
|
<pre><code class="language-wat">(func $ext_offchain_http_request_start_version_2
|
|
(param $method i64) (param $uri i64) (param $meta i64) (result i64))
|
|
</code></pre>
|
|
<h5 id="arguments-21"><a class="header" href="#arguments-21">Arguments</a></h5>
|
|
<p><code>method</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to the HTTP method. Possible values are “GET” and “POST”;
|
|
<code>uri</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to the URI;
|
|
<code>meta</code> is a future-reserved field containing additional, SCALE-encoded parameters. Currently, an empty array should be passed.</p>
|
|
<h5 id="result-14"><a class="header" href="#result-14">Result</a></h5>
|
|
<p>On success, a positive request identifier is returned. On error, <code>-1</code> is returned.</p>
|
|
<h5 id="changes-17"><a class="header" href="#changes-17">Changes</a></h5>
|
|
<p>The logic and the signature of the function are unchanged since the previous version. The only change is the interpretation of the result value to avoid an unneeded allocation and promote the unification of host function result returning (zero and positive values are for success, and the negative values are for failure codes).</p>
|
|
<h4 id="ext_offchain_http_request_add_header"><a class="header" href="#ext_offchain_http_request_add_header">ext_offchain_http_request_add_header</a></h4>
|
|
<p>The new version 2 is introduced, deprecating <code>ext_offchain_http_request_add_header_version_1</code>. The signature is unchanged.</p>
|
|
<pre><code class="language-wat">(func $ext_offchain_http_request_add_header_version_2
|
|
(param $request_id i32) (param $name i64) (param $value i64) (result i64))
|
|
</code></pre>
|
|
<h5 id="arguments-22"><a class="header" href="#arguments-22">Arguments</a></h5>
|
|
<ul>
|
|
<li><code>request_id</code> is an i32 integer indicating the ID of the started request, as returned by <code>ext_offchain_http_request_start</code>;</li>
|
|
<li><code>name</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to the HTTP header name;</li>
|
|
<li><code>value</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to the HTTP header value.</li>
|
|
</ul>
|
|
<h5 id="result-15"><a class="header" href="#result-15">Result</a></h5>
|
|
<p>The result is <code>0</code> for success or <code>-1</code> for failure.</p>
|
|
<h5 id="changes-18"><a class="header" href="#changes-18">Changes</a></h5>
|
|
<p>The logic and the signature of the function are unchanged since the previous version. The only change is the interpretation of the result value to avoid an unneeded allocation and promote the unification of host function result returning (zero and positive values are for success, and the negative values are for failure codes).</p>
|
|
<h4 id="ext_offchain_http_request_write_body"><a class="header" href="#ext_offchain_http_request_write_body">ext_offchain_http_request_write_body</a></h4>
|
|
<p>The new version 2 is introduced, deprecating <code>ext_offchain_http_request_write_body_version_1</code>. The signature is unchanged.</p>
|
|
<pre><code class="language-wat">(func $ext_offchain_http_request_write_body_version_2
|
|
(param $request_id i32) (param $chunk i64) (param $deadline i64) (result i64))
|
|
</code></pre>
|
|
<h5 id="arguments-23"><a class="header" href="#arguments-23">Arguments</a></h5>
|
|
<ul>
|
|
<li><code>request_id</code> is an i32 integer indicating the ID of the started request, as returned by <code>ext_offchain_http_request_start</code>;</li>
|
|
<li><code>chunk</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to the chunk of bytes. Writing an empty chunk finalizes the request;</li>
|
|
<li><code>deadline</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to the SCALE-encoded Option value (<a href="https://spec.polkadot.network/id-cryptography-encoding#defn-option-type">Definition 200</a>) containing the UNIX timestamp (<a href="https://spec.polkadot.network/id-cryptography-encoding#defn-unix-time">Definition 191</a>). Passing <code>None</code> blocks indefinitely.</li>
|
|
</ul>
|
|
<h5 id="result-16"><a class="header" href="#result-16">Result</a></h5>
|
|
<p>On success, <code>0</code> is returned. On failure, a negative error code is returned, where <code>-1</code> denotes the deadline was reached, <code>-2</code> denotes that an I/O error occurred, and <code>-3</code> denotes that the request ID provided was invalid.</p>
|
|
<h5 id="changes-19"><a class="header" href="#changes-19">Changes</a></h5>
|
|
<p>The logic and the signature of the function are unchanged since the previous version. The only change is the interpretation of the result value to avoid an unneeded allocation and promote the unification of host function result returning (zero and positive values are for success, and the negative values are for failure codes).</p>
|
|
<h4 id="ext_offchain_http_request_wait"><a class="header" href="#ext_offchain_http_request_wait">ext_offchain_http_request_wait</a></h4>
|
|
<p>The new version 2 is introduced, deprecating <code>ext_offchain_http_request_wait_version_1</code>. The signature is:</p>
|
|
<pre><code class="language-wat">(func $ext_offchain_http_request_wait_version_2
|
|
(param $ids i64) (param $deadline i64) (param $out i64))
|
|
</code></pre>
|
|
<h5 id="arguments-24"><a class="header" href="#arguments-24">Arguments</a></h5>
|
|
<ul>
|
|
<li><code>ids</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to the SCALE-encoded array of started request IDs, as returned by <code>ext_offchain_http_request_start</code>;</li>
|
|
<li><code>deadline</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to the SCALE-encoded Option value (<a href="https://spec.polkadot.network/id-cryptography-encoding#defn-option-type">Definition 200</a>) containing the UNIX timestamp (<a href="https://spec.polkadot.network/id-cryptography-encoding#defn-unix-time">Definition 191</a>). Passing <code>None</code> blocks indefinitely;</li>
|
|
<li><code>out</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to the buffer of <code>i32</code> integers where the request statuses will be stored. The number of elements of the buffer must be strictly equal to the number of elements in the <code>ids</code> array; otherwise, the function panics.</li>
|
|
</ul>
|
|
<h5 id="changes-20"><a class="header" href="#changes-20">Changes</a></h5>
|
|
<p>The logic of the functions is unchanged since the previous version. The signature has changed to align with the new memory allocation strategy.</p>
|
|
<h4 id="ext_offchain_http_response_read_body"><a class="header" href="#ext_offchain_http_response_read_body">ext_offchain_http_response_read_body</a></h4>
|
|
<p>The new version 2 is introduced, deprecating <code>ext_offchain_http_response_read_body_version_1</code>. The signature is unchanged.</p>
|
|
<pre><code class="language-wat">(func $ext_offchain_http_response_read_body_version_2
|
|
(param $request_id i32) (param $buffer i64) (param $deadline i64) (result i64))
|
|
</code></pre>
|
|
<h5 id="arguments-25"><a class="header" href="#arguments-25">Arguments</a></h5>
|
|
<ul>
|
|
<li><code>request_id</code> is an i32 integer indicating the ID of the started request, as returned by <code>ext_offchain_http_request_start</code>;</li>
|
|
<li><code>buffer</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to the buffer where the body is written;</li>
|
|
<li><code>deadline</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to the SCALE-encoded Option value (<a href="https://spec.polkadot.network/id-cryptography-encoding#defn-option-type">Definition 200</a>) containing the UNIX timestamp (<a href="https://spec.polkadot.network/id-cryptography-encoding#defn-unix-time">Definition 191</a>). Passing <code>None</code> blocks indefinitely.</li>
|
|
</ul>
|
|
<h5 id="result-17"><a class="header" href="#result-17">Result</a></h5>
|
|
<p>On success, the number of bytes written to the buffer is returned. A value of <code>0</code> means the entire response was consumed and no further calls to the function are needed for the provided request ID. On failure, a negative error code is returned, where <code>-1</code> denotes the deadline was reached, <code>-2</code> denotes that an I/O error occurred, and <code>-3</code> denotes that the request ID provided was invalid.</p>
|
|
<h5 id="changes-21"><a class="header" href="#changes-21">Changes</a></h5>
|
|
<p>The logic and the signature of the function are unchanged since the previous version. The only change is the interpretation of the result value to avoid an unneeded allocation and promote the unification of host function result returning (zero and positive values are for success, and the negative values are for failure codes).</p>
|
|
<h4 id="ext_allocator_"><a class="header" href="#ext_allocator_">ext_allocator_</a></h4>
|
|
<p>The functions are deprecated and must not be used in new code.</p>
|
|
<h4 id="ext_input_read"><a class="header" href="#ext_input_read">ext_input_read</a></h4>
|
|
<p>A new function is introduced. The signature is</p>
|
|
<pre><code class="language-wat">(func $ext_input_read_version_1
|
|
(param $buffer i64))
|
|
</code></pre>
|
|
<h5 id="arguments-26"><a class="header" href="#arguments-26">Arguments</a></h5>
|
|
<ul>
|
|
<li><code>buffer</code> is a pointer-size (<a href="https://spec.polkadot.network/chap-host-api#defn-runtime-pointer-size">Definition 216</a>) to the buffer where the input data will be written. If the buffer is not large enough to accommodate the input data, the function will panic.</li>
|
|
</ul>
|
|
<h3 id="other-changes"><a class="header" href="#other-changes">Other changes</a></h3>
|
|
<p>Currently, all runtime entrypoints have the following identical Wasm function signatures:</p>
|
|
<pre><code class="language-wat">(func $runtime_entrypoint (param $data i32) (param $len i32) (result i64))
|
|
</code></pre>
|
|
<p>After this RFC is implemented, such entrypoints are still supported, but considered deprecated. New entrypoints must have the following signature:</p>
|
|
<pre><code class="language-wat">(func $runtime_entrypoint (param $len i32) (result i64))
|
|
</code></pre>
|
|
<p>A runtime function called through such an entrypoint gets the length of SCALE-encoded input data as its only argument. After that, the function must allocate exactly the amount of bytes it is requested, and call the <code>ext_input_read</code> host function to obtain the encoded input data.</p>
|
|
|
|
</main>
|
|
|
|
<nav class="nav-wrapper" aria-label="Page navigation">
|
|
<!-- Mobile navigation buttons -->
|
|
<a rel="prev" href="../new/0155-polkadot-dollar.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
|
|
<i class="fa fa-angle-left"></i>
|
|
</a>
|
|
|
|
<a rel="next prefetch" href="../proposed/0150-voting-while-delegating.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
|
<i class="fa fa-angle-right"></i>
|
|
</a>
|
|
|
|
<div style="clear: both"></div>
|
|
</nav>
|
|
</div>
|
|
</div>
|
|
|
|
<nav class="nav-wide-wrapper" aria-label="Page navigation">
|
|
<a rel="prev" href="../new/0155-polkadot-dollar.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
|
|
<i class="fa fa-angle-left"></i>
|
|
</a>
|
|
|
|
<a rel="next prefetch" href="../proposed/0150-voting-while-delegating.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
|
|
<i class="fa fa-angle-right"></i>
|
|
</a>
|
|
</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 -->
|
|
|
|
|
|
</div>
|
|
</body>
|
|
</html>
|