Computational Component of Polkadot Network

Overview

GEAR

Computational Component of Polkadot Network


Gear is a new Polkadot/Kusama parachain and most advanced L2 smart-contract engine allowing anyone to launch any dApp for networks with untrusted code.

Gear provides the easiest and most cost-effective way to run WebAssembly programs (smart-contracts) compiled from many popular languages, such as C/C++, Rust and more.

Gear ensures very minimal, intuitive, and sufficient API for running both newly written and existing programs on other networks without the need to rewrite them.

Getting Started

Please refer to the technical paper for some insights about how Gear works internally.

TODO: Describe the easiest way to start with. Pay attention to smart contract examples.

Running Node

TODO: Prepare ready-to-install packages to make first steps simpler.

Prerequisites

  1. Install Rust using rustup:

    curl https://sh.rustup.rs -sSf | sh
  2. Add toolchains:

    make init

Build Gear Node and Run

  1. Build:

    make node
  2. Run:

    make node-run

Refer to the Gear Node docs for details.

Gear Components

  • core

    Gear engine for distributed computing core components.

  • node

    Gear substrate-based node, ready for hacking 🚀 .

  • gstd

    Standard library for Gear smart contracts.

  • examples

    Gear smart contract examples.

License

Gear is licensed under GPL v3.0 with a classpath linking exception.

Comments
  • Add comparison of execution times for pallet tests and node runtime tests

    Add comparison of execution times for pallet tests and node runtime tests

    Resolves #900

    • enable output of JUnit XML for nextest in pallet tests
    • add execution time measurement in gear-runtime-test-cli
    • add output of similiar JUnit XML in gear-runtime-test-cli
    • add utility to compare execution times for provided junit.xml
    • adjust CI to collect data regularly
    • add script to collect measurements locally and compare results
    • add bot commenting PR with compare results

    @gear-tech/dev

    A2-mergeoncegreen D4-test 
    opened by gshep 13
  • Rename `gear-node` binary to `gear`

    Rename `gear-node` binary to `gear`

    • Resolves #1624
    • Removed gear-node crate.
    • Changed gear-cli crate to produce a binary.
    • Replaced gear-node binary with gear and gear-node crate with gear-cli.
    • Changed default --base-path to gear-node instead of executable name (gear[.exe]) for backward compatibility.

    @gear-tech/dev

    A2-mergeoncegreen D1-core 
    opened by shamilsan 12
  • Regular performance check

    Regular performance check

    Resolves #1131.

    gear-tech.github.io/performance-charts

    To do:

    • [x] Instruction weight charts
    • [x] 3 charts in a row in GH pages
    • [x] Make unit as ms
    • [x] Check SSH deploy keys work instead of personal access token https://github.com/marketplace/actions/push-directory-to-another-repository
    • [x] #1230
    A0-pleasereview D4-test D5-tooling 
    opened by ark0f 10
  • lazy pages optimization

    lazy pages optimization

    in order to optimise lazy pages work - move logic which calc keys for pages in signal handler. Also completely remove lazy_pages set because it can be very costly to support it when memory size is big

    Perf

    I have run gr_read benchmarks to test perf increase:

    perf record --all-user --call-graph=dwarf --freq 997 ./target/release/gear-node benchmark pallet --chain=dev --steps=50 --repeat=100 --pallet=pallet_gear --execution=native --extrinsic="gr_read"
    

    gear_core_processor::executor::prepare_memory (where lazy pages init info is called) takes

    master       :    24.9% from all samples
    this branch  :    0.01% from all samples
    

    time for gr_read:

    master       :    42.93 µs
    this branch  :    32.65 µs
    

    time for gr_reply_commit:

    master       :    68.2 µs
    this branch  :    49.92 µs
    

    Testing

    Run node with this patch over all test-net chain - all OK

    Important

    This patch requires node binary update after runtime update.

    A0-pleasereview 
    opened by grishasobol 10
  • Add ability to send scheduled messages

    Add ability to send scheduled messages

    Problem to Solve

    Sometimes we need to send the message after some delay instead of doing it immediately. It might be useful for time scheduled routines, e.g. in DAO, auctions, lotteries.

    Possible Solution

    Introduce new functions in gstd::msg (all names, parameters, and return types are to be discussed!):

    /// `msg` module
    
    /// Add the message to the shedule.
    fn schedule(dest, payload, delay, value) -> Result<MessageId, ...>;
    // fn schedule_with_gas(...)
    // async fn schedule_for_reply(...)
    
    /// Deny early sending.
    fn deny_triggering(msg_id) -> bool;
    
    /// Cancel sending scheduled message.
    fn cancel_scheduled(msg_id) -> Result<(), ...>;
    
    /// Send scheduled message immediately.
    fn trigger(msg_id) -> Result<(), ...>;
    // fn trigger_for_reply(...)
    

    Also need to add correspondent functionality to Gear core.

    Notes

    Using example (DAO):

    let msg_id = msg::schedule(
        exec::program_id(),
        DaoAction::ProcessProposal(self.proposal_id)),
        exec::block_timestamp() + self.voting_period,
        0,
    )
    .expect("Error while deferring message");
    msg::deny_triggering(msg_id);
    
    let reply: DaoEvent = 
        exec::trigger_as(msg_id).expect("Error while shoving scheduled message");
    
    exec::cancel_scheduled(msg_id).expect("Error while cancelling scheduled message");
    
    let reply: DaoEvent = msg::schedule_for_reply_as(
        exec::program_id(),
        DaoAction::ProcessProposal(self.proposal_id),
        exec::block_timestamp() + self.voting_period,
        0,
    )
    .expect("Error while scheduling message")
    .await
    .expect("Error while processing result");
    
    D1-core D3-gstd P1-asap C1-feature 
    opened by shamilsan 9
  • Don't compare memory pages after execution

    Don't compare memory pages after execution

    File Location(s)

    core-processor/src/executor.rs

    Proposal

    We have the following loop at the moment:

    for (page, new_data) in info.pages_data {
        // ...
    
        if let Some(initial_data) = pages_data.get(&page) {
                if new_data != *initial_data {
                    // ...
                }
            // ...
        }
    }
    

    Instead the pages could be marked as dirty during the execution it there were some changes to them. To sum up the beforementioned loop should look like this:

    for (page, new_data) in info.pages_data {
        // ...
    
        if let Some(initial_data) = pages_data.get(&page) {
                if new_data.modified {
                    // ...
                }
            // ...
        }
    }
    
    D1-core P2-sometimesoon C2-refactoring Q2-moderate 
    opened by gshep 9
  • Add support to calling `wait` in `init` on the node side

    Add support to calling `wait` in `init` on the node side

    Resolves #18. Resolves #515. Resolves #579.

    • Split examples/init-wait/lib.rs into two files: one with crate-level no_std attribute and the other with the program code. This trick allows to include code.rs in other modules/crates.
    • Add tests/init-wait that includes code.rs and exports WASM_BINARY_BLOATY.
    • Add three tests to pallet-gear/tests. They are ignored at the moment since node doesn't support calling wait ini init method.

    @gear-tech/dev

    Release Notes: Programs lifecycle has been changed so now their initialization can be deferred with wait/wake syscalls. This is the next step towards the asynchronous initialization of programs.

    A2-mergeoncegreen D2-node B1-releasenotes 
    opened by gshep 9
  • Refactor the algo of getting the gas spent in `get_gas_spent`

    Refactor the algo of getting the gas spent in `get_gas_spent`

    File Location(s)

    https://github.com/gear-tech/gear/blob/9bd56a0aa17931985c80ec3fa2377518eacc25bb/pallets/gear/src/lib.rs#L576

    Proposal

    We can just get the max gas spent via JournalNote::GasBurned { amount, .. }

    in case of fixing the node key issue in https://github.com/gear-tech/gear/pull/975, we can not get remaining_gas via T::GasHandler::get_limit(message_id) after the message has been consumed ( in some cases it would be None )

    C2-refactoring 
    opened by clearloop 8
  • Add list of forbidden syscalls to WASM executor

    Add list of forbidden syscalls to WASM executor

    Finally resolves #587.

    • Add functions (aka syscalls) blacklist.
    • Generate a trap when trying to call a forbidden function in a program.
    • Forbid to call gr_gas_available when executing WASM from get_gas_spent function.

    TODO:

    • [x] Fix tests

    Use case

    Now it is possible to pass a list of forbidden syscalls when calling the gear_core_processor::process() function. If the WASM program contains a call to that forbidden function, the execution will return a correspondent error.

    For example when we calculate the amount of gas needed for processing messages in the get_gas_spent() function, we forbid calling the gr_gas_available syscall in the program. get_gas_spent() will return Program terminated with a trap: Unable to call a forbidden function error if the program calls exec:gas_available() function during message processing.

    Up to now, the main end-user application is that he will receive an error when trying to calculate the gas amount to be spent for handling a message by the program that uses the exec::gas_available() function inside.

    Also, there are potential use cases in the future.

    @gear-tech/dev

    A2-mergeoncegreen D1-core D2-node 
    opened by shamilsan 8
  • Properly invoke free syscall on vec destructor

    Properly invoke free syscall on vec destructor

    Problem

    gtest/spec/test_vec.yaml "test-vec (20000 * size_of(i32) = 80 KiB = 2 pages)"

    Hello, the test creates vec which have size 0x13880 bytes (page is 0x10000). But as I can see in my allocator logs in the end of fn handle - destructor for vector is called, so the check for two pages is incorrect.

    C0-bug 
    opened by grishasobol 7
  • gtest specs fail when we use allocator with enabled checks

    gtest specs fail when we use allocator with enabled checks

    Problem

    First I found this problem when run gtest for compiled with debug_assertions wasm tests - some of them failed on execution.

    $ sh scripts/test.sh async 
    
    Fixture async-await (step: 1): Ok
    DEBUG: 1 total message(s) stored: 
    Fixture async-await (step: 2): Messages check [expected: 1, actual: 2]
    DEBUG: 1 total message(s) stored: 
    Fixture async-await (step: 3): Messages check [expected: 1, actual: 2]
    DEBUG: 1 total message(s) stored: 
    Fixture async-await (step: 4): Messages check [expected: 1, actual: 2]
    DEBUG: 1 total message(s) stored: 
    Fixture async-await (step: 5): Messages check [expected: 1, actual: 2]
    DEBUG: 1 total message(s) stored: 
    Fixture async-await (step: 6): Messages check [expected: 1, actual: 2]
    DEBUG: 1 total message(s) stored: 
    Fixture async-await (step: 7): Messages check [expected: 1, actual: 2]
    DEBUG: 1 total message(s) stored: 
    DEBUG: 1 total message(s) stored: 
    Fixture async-await (step: 8): Messages check [expected: 1, actual: 3]
    DEBUG: 1 total message(s) stored: 
    DEBUG: 1 total message(s) stored: 
    Fixture async-await (step: 9): Messages check [expected: 1, actual: 3]
    DEBUG: 1 total message(s) stored: 
    DEBUG: 1 total message(s) stored: 
    Fixture async-await (step: 10): Log check [expected: 1, actual: 0]
    Error: 9 tests failed
    
    

    Investigating problem I found that debug_assertion is not a reason and something fails tests in checks code. So I tried to localize problem - remove all unneeded checks and unneeded code. Only one check function is left and inside only one small loop is left:

    check_malloc_state(&mut self) {
            if !DL_CHECKS { return; }
            for i in 0..11 {
                let head_chunk : *mut Chunk = self.smallbin_at(i as u32);
            }
    }
    
    #[inline(never)]
     unsafe fn smallbin_at(&mut self, idx: u32) -> *mut Chunk {
            let idx = (idx * 2) as usize;
            dlassert!(idx < self.smallbins.len());
    
            let smallbins_ptr = &self.smallbins as *const *mut Chunk;
            let idx_ptr = smallbins_ptr.offset(idx as isize ) as *mut Chunk;
            return idx_ptr;
    }
    

    Here we just take few times mutable pointer and do nothing else. This function is called sometimes in allocator.

    So, if DL_CHECKS is true then gtest is failed, else all goes right. We can also tries to make function smallbin_at as inline - in that case tests goes well. If we change iterations number in loop, for example 0..10, then tests also goes well.

    I noticed that if iterations number >= 11 then we fails in other case goes well: 20..25 and 20..30 - goes well; 20..31 - fails

    Steps

    Linux kernel: 5.4.0-86-generic OS: 20.04.3 LTS (Focal Fossa) Proc: x86_64

    1. git fetch && git checkout gsobol_alloc_fail
    2. sh scripts/test.sh async // this must fail
    3. remove in galloc/Cargo.toml feature "gsobol_check" which is for dlallocator
    4. sh scripts/test.sh async // this runs well

    Possible Solution

    I think that problem may be in wasmtime compiler or when we compile from rust to wasm code. No other ideas.

    Notes

    No response

    Relevant Log Output

    No response

    C0-bug 
    opened by grishasobol 7
  • Provide example tests for the default program generated by `gprogram`

    Provide example tests for the default program generated by `gprogram`

    Problem to Solve

    gprogram new generates template from https://github.com/gear-tech/gear/blob/master/program/src/template.rs without tests, need to add tests for it.

    Possible Solution

    • add tests for example ping
    • generate template from ping with build script

    Notes

    No response

    C1-feature 
    opened by clearloop 0
  • Add a possibility to save and restore program's memory pages in `gtest`/`gclient`

    Add a possibility to save and restore program's memory pages in `gtest`/`gclient`

    Problem to Solve

    Sometimes it is helpful to have some not initial state of the program. E.g., you can perform some long during operation once and use its results in tests multiple times.

    Possible Solution

    Add to gtest/gclient:

    • Function for saving the whole program's memory to file: save_memory(program_id, file_path)
    • Function for restoring the program's memory from a file: restore_memory(program_id, file_path)

    Also:

    • Consider using a text format for the file to keep it in the version control system.
    • Don't keep empty memory blocks.
    • File format should be interchangeable between gtest and gclient.

    Notes

    No response

    C1-feature 
    opened by shamilsan 0
  • Rework block authorship

    Rework block authorship

    Resolves the issue with a flaky machinery of deciding wether the message queue should be processed in the end of each block depending on the outcome of previous runs.

    The old mechanism relied on the inherent-like extrinsic signalling a successful completion of the message queue processing by setting some storage value to a specific status. If not set, this was deemed as a panic having occurred during one of the previous runs so that a new attempt wouldn't (by default) take place. This creates an attack vector of a malicious validator opting for deliberately not including this inherent into a block thereby blocking the queue processing in all the blocks thereafter, until the issue would have been investigated and fixed via a runtime upgrade which would render the network useless in the meantime.

    The proposed solution changes this approach so that the inherent-like extrinsic is always included in a block; however, there is another storage value - ExecuteInherent, that is checked inside this extrinsic: if set to false, an error is returned thereby causing the block builder to drop this extrinsic. This value can only be altered by a root origin. This is useful to manually disable queue processing in case it panics and re-enable once the issue has been fixed.

    A0-pleasereview D2-node C2-refactoring 
    opened by ekovalev 1
  • Implement Gear stack end in `wasm-gen`

    Implement Gear stack end in `wasm-gen`

    Resolves #2050

    Add gear stack end to wasm-gen to test all cases depending on this

    ~1% of cases with invalid stack size not a multiple of the page size ~1% of cases with invalid stack size that is bigger than import memory ~1% of cases stack size is not generated at all all other cases should be valid

    A0-pleasereview 
    opened by MikitaS 1
Examples of interacting with a Polkadot node using Rust

Examples of interacting with a Polkadot node Some examples of using JSON RPC to interact with a Polkadot node, working up to manually building and sub

Parity Technologies 15 Dec 21, 2022
Docker containers on a synthetic network. Run applications in a context that lets you manipulate their network conditions.

Synthetic Network Docker containers on a synthetic network. Run applications in a context that lets you manipulate their network conditions. Dependenc

Daily 58 Dec 15, 2022
Network simulation in Rust

netsim - A Rust library for network simulation and testing (currently linux-only). netsim is a crate for simulating networks for the sake of testing n

Andrew Cann 115 Dec 15, 2022
A private network system that uses WireGuard under the hood.

innernet A private network system that uses WireGuard under the hood. See the announcement blog post for a longer-winded explanation. innernet is simi

Tonari, Inc 4.1k Dec 29, 2022
A Curve-like AMM for Secret Network

A Curve-like AMM for Secret Network. Supports a varibale number of tokens with the same underlying value.

Enigma 16 Dec 11, 2022
A multi-protocol network relay

A multi-protocol network relay

zephyr 43 Dec 13, 2022
A Rust library for parsing the SOME/IP network protocol (without payload interpretation).

someip_parse A Rust library for parsing the SOME/IP network protocol (without payload interpretation). Usage Add the following to your Cargo.toml: [de

Julian Schmid 18 Oct 31, 2022
Fullstack development framework for UTXO-based dapps on Nervos Network

Trampoline-rs The framework for building powerful dApps on the number one UTXO chain, Nervos Network CKB. This is an early-stage, currently very incom

TannrA 2 Mar 25, 2022
Official Implementation of Findora Network.

Findora Platform Wiki Contribution Guide Licensing The primary license for Platform is the Business Source License 1.1 (BUSL-1.1), see LICENSE. Except

Findora Foundation 61 Dec 9, 2022
Simple in-network file transfer with barely any overhead.

fftp fftp is the "Fast File Transport Protocol". It transfers files quickly between computers on a network with low overhead. Motivation FTP uses two

leo 4 May 12, 2022
netavark: A container network stack

netavark: A container network stack Netavark is a rust based network stack for containers. It is being designed to work with Podman but is also applic

Containers 230 Jan 2, 2023
A cross-platform, user-space WireGuard port-forwarder that requires no system network configurations.

Cross-platform, user-space WireGuard port-forwarder that requires no system network configurations.

Aram Peres 629 Jan 4, 2023
An implementation of the CESS network supported by CESS LAB.

--------- ?? ---------An infrastructure of decentralized cloud data network built with Substrate-------- ?? -------- ---------------- ?? -------------

Cess Project 249 Dec 26, 2022
A small utility to wake computers up or put them to sleep over the local network

WKSL - a wake and sleep utility An experiment in writing a small CLI utility in Rust. The program lets you wake a machine on your local network up fro

Henrik Ravn 0 Nov 14, 2021
Private swaps for Secret Network using a private entropy pool & differential privacy.

WIP SecretSwap: Anon Edition Private swaps for Secret Network! Uses private entropy pool for differential privacy when reporting pools sizes. Swap amo

SCRT Labs 5 Apr 5, 2022
Common Rust Lightning Network types

Common Rust Lightning Network types Warning: while in a good state, this is still considered a preview version! There are some planned changes. This l

Martin Habovštiak 5 Nov 8, 2022
Shade Protocol is an array of connected privacy-preserving dApps built on Secret Network

Shade Protocol Core Contracts Contract Reference Description mint doc Handles asset burning and silk minting oracle doc Handles asset price queries tr

Secure Secrets 58 Nov 15, 2022
The Safe Network Core. API message definitions, routing and nodes, client core api.

safe_network The Safe Network Core. API message definitions, routing and nodes, client core api. License This Safe Network repository is licensed unde

MaidSafe 101 Dec 19, 2022
Network Block Storage server, written in Rust. Supports pluggable and chainable underlying storage

nbd-rs Disclaimer DO NEVER USE THIS FOR PRODUCTION Do not use this for any data that you cannot afford to lose any moment. Expect data loss, corruptio

Rainlab Inc 10 Sep 30, 2022