-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4707 from Lezek123/apps-metaprotocol-pre-release
Apps metaprotocol: Update from master and fix conflicts
- Loading branch information
Showing
14 changed files
with
623 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,4 +45,6 @@ runtime-inputs/ | |
|
||
.my_setup | ||
|
||
devops/infrastructure | ||
devops/infrastructure | ||
|
||
joystream.tar.gz |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Assuming cargo workspace root is same as the git repo root | ||
cd $(git rev-parse --show-toplevel) | ||
|
||
tar -czf joystream.tar.gz \ | ||
Cargo.lock \ | ||
Cargo.toml \ | ||
runtime \ | ||
runtime-modules \ | ||
joystream-node.Dockerfile \ | ||
bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
output.wasm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ApiPromise, WsProvider } from '@polkadot/api' | ||
import fs from 'fs' | ||
import { Bytes } from '@polkadot/types' | ||
|
||
async function main() { | ||
const outputFilePath = process.argv[2] || 'runtime.wasm' | ||
|
||
const endpoint = process.env.WS_URI || 'ws://127.0.0.1:9944' | ||
const provider = new WsProvider(endpoint) | ||
|
||
const api: ApiPromise = new ApiPromise({ provider }) | ||
await api.isReadyOrError | ||
|
||
const codeStorageKey = '0x3a636f6465' // hex(':code') | ||
const runtime = await api.rpc.state.getStorage<Bytes>(codeStorageKey) | ||
|
||
await api.disconnect() | ||
|
||
const wasm = runtime.toU8a(true) | ||
fs.writeFileSync(outputFilePath, wasm) | ||
} | ||
|
||
main() | ||
.catch(console.error) | ||
.finally(() => process.exit()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { ApiPromise, WsProvider } from '@polkadot/api' | ||
import fs from 'fs' | ||
|
||
// Fetch the proposed runtime from an active proposal | ||
// If proposal has already been decided, executed or rejected the proposal details will not be | ||
// available on chain, as they are cleaned up after the proposal is finalized. | ||
async function main() { | ||
const proposalId = parseInt(process.argv[2]) | ||
const outputFilePath = process.argv[3] || 'runtime.wasm' | ||
|
||
const endpoint = process.env.WS_URI || 'ws://127.0.0.1:9944' | ||
const provider = new WsProvider(endpoint) | ||
|
||
const api: ApiPromise = new ApiPromise({ provider }) | ||
await api.isReadyOrError | ||
|
||
const proposalCallCode = await api.query.proposalsEngine.dispatchableCallCode(proposalId) | ||
|
||
await api.disconnect() | ||
|
||
// attempt to decode as Call | ||
const extrinsicCall = api.createType('Call', proposalCallCode.toHex()) | ||
|
||
const { method, section } = api.registry.findMetaCall(extrinsicCall.callIndex) | ||
|
||
if (method !== 'executeRuntimeUpgradeProposal' || section !== 'joystreamUtility') { | ||
throw new Error('This is not the proposal you are looking for!') | ||
} | ||
|
||
// The first arg to joystreamUtility.executeRuntimeUpgradeProposal(wasm) is the proposed wasm code | ||
const wasm = extrinsicCall.args[0] | ||
|
||
fs.writeFileSync(outputFilePath, wasm.toU8a(true)) | ||
} | ||
|
||
main() | ||
.catch(console.error) | ||
.finally(() => process.exit()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
const BN = require('bn.js') | ||
const types = require('@joystream/types') | ||
|
||
async function getRuntimeVersionFromWasm(wasm) { | ||
const memory = new WebAssembly.Memory({ initial: 21 }) | ||
// pointer into heap used to keep track of malloc'ed memory | ||
// https://spec.polkadot.network/#defn-runtime-pointer | ||
let allocPointer = 0 | ||
|
||
const module = await WebAssembly.instantiate(wasm, { | ||
env: { | ||
memory, | ||
// Just a silly memory allocator :) sufficient to have Core_version() work. | ||
// https://spec.polkadot.network/#id-ext_allocator_malloc | ||
//! The runtime code must export a global symbol named `__heap_base` of type `i32`. Any memory | ||
//! whose offset is below the value of `__heap_base` can be used at will by the program, while | ||
//! any memory above `__heap_base` but below `__heap_base + heap_pages` (where `heap_pages` is | ||
//! the value passed as parameter to [`HostVmPrototype::new`]) is available for use by the | ||
//! implementation of `ext_allocator_malloc_version_1`. | ||
ext_allocator_malloc_version_1: (size) => { | ||
allocPointer += size | ||
return module.instance.exports.__heap_base + allocPointer | ||
}, | ||
// dummy runtime host functions for polkadot/substrate node | ||
ext_hashing_blake2_128_version_1: () => {}, | ||
ext_hashing_blake2_256_version_1: () => {}, | ||
ext_hashing_twox_128_version_1: () => {}, | ||
ext_hashing_twox_64_version_1: () => {}, | ||
ext_allocator_free_version_1: () => {}, | ||
ext_storage_append_version_1: () => {}, | ||
ext_storage_clear_version_1: () => {}, | ||
ext_storage_clear_prefix_version_2: () => {}, | ||
ext_storage_commit_transaction_version_1: () => {}, | ||
ext_storage_exists_version_1: () => {}, | ||
ext_storage_get_version_1: () => {}, | ||
ext_storage_next_key_version_1: () => {}, | ||
ext_storage_read_version_1: () => {}, | ||
ext_storage_rollback_transaction_version_1: () => {}, | ||
ext_storage_root_version_2: () => {}, | ||
ext_storage_set_version_1: () => {}, | ||
ext_storage_start_transaction_version_1: () => {}, | ||
ext_misc_print_hex_version_1: () => {}, | ||
ext_misc_print_num_version_1: () => {}, | ||
ext_misc_print_utf8_version_1: () => {}, | ||
ext_misc_runtime_version_version_1: () => {}, | ||
ext_trie_blake2_256_ordered_root_version_2: () => {}, | ||
ext_offchain_is_validator_version_1: () => {}, | ||
ext_offchain_local_storage_clear_version_1: () => {}, | ||
ext_offchain_local_storage_compare_and_set_version_1: () => {}, | ||
ext_offchain_local_storage_get_version_1: () => {}, | ||
ext_offchain_local_storage_set_version_1: () => {}, | ||
ext_offchain_network_state_version_1: () => {}, | ||
ext_offchain_random_seed_version_1: () => {}, | ||
ext_offchain_submit_transaction_version_1: () => {}, | ||
ext_offchain_timestamp_version_1: () => {}, | ||
ext_offchain_index_set_version_1: () => {}, | ||
ext_crypto_ed25519_generate_version_1: () => {}, | ||
ext_crypto_ed25519_verify_version_1: () => {}, | ||
ext_crypto_finish_batch_verify_version_1: () => {}, | ||
ext_crypto_secp256k1_ecdsa_recover_compressed_version_2: () => {}, | ||
ext_crypto_sr25519_generate_version_1: () => {}, | ||
ext_crypto_sr25519_public_keys_version_1: () => {}, | ||
ext_crypto_sr25519_sign_version_1: () => {}, | ||
ext_crypto_sr25519_verify_version_2: () => {}, | ||
ext_crypto_start_batch_verify_version_1: () => {}, | ||
ext_logging_log_version_1: (a) => {}, | ||
ext_logging_max_level_version_1: () => {}, | ||
}, | ||
}) | ||
|
||
//! ## Runtime version | ||
//! | ||
//! Wasm files can contain so-called custom sections. A runtime can contain two custom sections | ||
//! whose names are `"runtime_version"` and `"runtime_apis"`, in which case they must contain a | ||
//! so-called runtime version. | ||
//! | ||
//! The runtime version contains important field that identifies a runtime. | ||
//! | ||
//! If no `"runtime_version"` and `"runtime_apis"` custom sections can be found, the | ||
//! `Core_version` entry point is used as a fallback in order to obtain the runtime version. This | ||
//! fallback mechanism is maintained for backwards compatibility purposes, but is considered | ||
//! deprecated. | ||
// Couldn't figure out how to find these "custom sections" so just using Core_version entry point. | ||
const result = module.instance.exports.Core_version() | ||
|
||
//! The function returns a 64 bits number. The 32 less significant bits represent a pointer to the | ||
//! Wasm virtual machine's memory, and the 32 most significant bits a length. This pointer and | ||
//! length designate a buffer containing the actual return value. | ||
// https://spec.polkadot.network/#defn-runtime-pointer-size | ||
const pointerSize = new BN(result) | ||
const size = pointerSize.shrn(32).toNumber() // 32 most significant bits | ||
const pointer = pointerSize.maskn(32).toNumber() // 32 least significant bits | ||
|
||
// get data returned by the call from memory | ||
const data = memory.buffer.slice(pointer, pointer + size) | ||
// Decode data as `RuntimeVersion` struct | ||
return types.createType('RuntimeVersion', Buffer.from(data)) | ||
} | ||
|
||
module.exports = { | ||
getRuntimeVersionFromWasm, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env node --experimental-wasm-bigint | ||
|
||
// Run script with: node --experimental-wasm-bigint src/inspect-wasm-runtime-version.js ./runtime.wasm | ||
const fs = require('fs') | ||
const { decompress } = require('@mongodb-js/zstd') | ||
const { getRuntimeVersionFromWasm } = require('./helpers/runtimeVersion') | ||
|
||
// Reference from substrate: | ||
// https://github.com/paritytech/substrate/blob/master/primitives/maybe-compressed-blob/src/lib.rs | ||
const ZSTD_PREFIX = Buffer.from([82, 188, 83, 118, 70, 219, 142, 5]) | ||
|
||
function hasMagicPrefix(blob) { | ||
const prefix = blob.subarray(0, 8) | ||
return Buffer.compare(prefix, ZSTD_PREFIX) === 0 | ||
} | ||
|
||
async function main() { | ||
const inputWasmFilePath = process.argv[2] || 'runtime.wasm' | ||
|
||
let wasm = fs.readFileSync(inputWasmFilePath) | ||
|
||
if (hasMagicPrefix(wasm)) { | ||
console.error('Decompressing WASM blob') | ||
wasm = await decompress(Buffer.from(wasm.subarray(8))) | ||
} | ||
|
||
if (!WebAssembly.validate(wasm)) { | ||
return console.error('Input wasm is not valid') | ||
} | ||
|
||
const runtimeVersion = await getRuntimeVersionFromWasm(wasm) | ||
|
||
console.log(runtimeVersion.toHuman()) | ||
} | ||
|
||
main() | ||
.catch(console.error) | ||
.finally(() => process.exit()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters