Giter VIP home page Giter VIP logo

canvas's Introduction

Canvas ‒ A Smart Contracts Parachain

matrix discord

⚠️ Note: Canvas was moved into the Cumulus repo. Please check there for the current version.

This is a node implementation of Canvas, a Substrate parachain for smart contracts.

If you have any questions, feel free to talk to us on Element or on Discord (in the ink_smart-contracts channel).

Developing Smart Contracts for Canvas

How it works

This node is based on the cumulus/parachain-template, which we configured to use Substrate's smart contracts module ‒ the contracts pallet. This contracts pallet takes smart contracts as WebAssembly blobs and defines an API for everything a smart contract needs (storage access, …). As long as a programming language compiles to WebAssembly and there exists an implementation of this API in it, you can write a smart contract for this pallet ‒ and thus for Canvas ‒ in that language.

This is a list of languages you can currently choose from:

There are also different user interfaces and command-line tools you can use to deploy or interact with contracts:

If you are looking for a quickstart, we can recommend ink!'s Guided Tutorial for Beginners.

Rococo Deployment

We have a live deployment of the Canvas parachain on Rococo ‒ a testnet for Polkadot and Kusama parachains. You can interact with the network through Polkadot JS Apps, click here for a direct link to Canvas.

The Canvas parachain uses the Rococo relay chain's native token (ROC) instead of having its own token. Due to this you'll need ROC in order to deploy contracts on Canvas.

As a first step, you should create an account. See here for a detailed guide.

As a second step, you have to get ROC testnet tokens through the Rococo Faucet. This is a chat room in which you need to write:

!drip YOUR_SS_58_ADDRESS:1002

The number 1002 is the parachain id of Canvas on Rococo, by supplying it the faucet will teleport ROC tokens directly to your account on the parachain.

If everything worked out, the teleported ROC tokens will show up under the "Accounts" tab for Canvas.

Once you have ROC on Canvas you can deploy a contract as you would normally. If you're unsure about this, our guided tutorial will clarify that for you in no time.

Run it Locally

Installation

You need to have executables of both Polkadot and Canvas.

Binary releases can be found here: Polkadot releases, Canvas releases.

Alternatively you can install (or build) the projects yourself:

  • cargo install --git https://github.com/paritytech/polkadot.git --force --locked
  • cargo install --git https://github.com/paritytech/canvas.git --force --locked

The --locked flag makes the installation (or build) use the same versions as the Cargo.lock in those repositories ‒ ensuring that the last known-to-work version of the dependencies is used.

Launching

Starting this project is best done using the polkadot-launch tool ‒ it starts Polkadot and registers the Canvas parachain on it automatically.

To use polkadot-launch you must ensure that you're using Node.js v14.x or newer. If you're on macOS, you must also ensure that your machine's firewall is disabled. You can do this by going to "System Preferences" > "Security & Privacy" > "Firewall" and ensuring that it's off.

Now that you have the prerequisites:

  1. Install it with yarn global add polkadot-launch or npm i polkadot-launch -g
  2. Check that the paths in polkadot-launch/config.json point to the polkadot and canvas executables
  3. Launch the network with polkadot-launch polkadot-launch/config.json

At this point you should be able to use Polkadot JS Apps to connect to the Polkadot relay chain nodes as well as the Canvas collator.

Building from source

Follow the official installation steps to set up all Substrate prerequisites.

Afterwards you can install this node via

git clone https://github.com/paritytech/canvas.git
cd canvas/
cargo build --release --locked 

Substrate Compatibility

The latest confirmed working Substrate commit which will then be used is 3aecef7ee350db9cf53369481ebd1cee26ecc7ff.

Unstable Features

If you're the type of person that likes to drink your soup before it cools, you might also be wondering about how to activate unstable pallet-contracts features. To do this you can run the previous installation command with the following flag: --features contracts-unstable-interface.

canvas's People

Contributors

alvicsam avatar ascjones avatar athei avatar cmichi avatar hcastano avatar jacogr avatar lovelaced avatar nikvolf avatar nuke-web3 avatar riusricardo avatar sergejparity avatar tripleight avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

canvas's Issues

Substrate type inference regression bug

I'm unable to install canvas-node to contracts CI image here.

And the error is:
error[E0282]: type annotations needed
    --> /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/sp-arithmetic-2.0.0/src/fixed_point.rs:541:9
     |
541  |                   let accuracy = P::ACCURACY.saturated_into();
     |                       ^^^^^^^^ consider giving `accuracy` a type
...
1595 | / implement_fixed!(
1596 | |     FixedI64,
1597 | |     test_fixed_i64,
1598 | |     i64,
...    |
1601 | |     "_Fixed Point 64 bits signed, range = [-9223372036.854775808, 9223372036.854775807]_",
1602 | | );
     | |__- in this macro invocation
     |
     = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0282]: type annotations needed
    --> /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/sp-arithmetic-2.0.0/src/fixed_point.rs:541:9
     |
541  |                   let accuracy = P::ACCURACY.saturated_into();
     |                       ^^^^^^^^ consider giving `accuracy` a type
...
1604 | / implement_fixed!(
1605 | |     FixedI128,
1606 | |     test_fixed_i128,
1607 | |     i128,
...    |
1611 | |         [-170141183460469231731.687303715884105728, 170141183460469231731.687303715884105727]_",
1612 | | );
     | |__- in this macro invocation
     |
     = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0282]: type annotations needed
    --> /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/sp-arithmetic-2.0.0/src/fixed_point.rs:541:9
     |
541  |                   let accuracy = P::ACCURACY.saturated_into();
     |                       ^^^^^^^^ consider giving `accuracy` a type
...
1614 | / implement_fixed!(
1615 | |     FixedU128,
1616 | |     test_fixed_u128,
1617 | |     u128,
...    |
1621 | |         [0.000000000000000000, 340282366920938463463.374607431768211455]_",
1622 | | );
     | |__- in this macro invocation
     |
     = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0282`.
error: could not compile `sp-arithmetic`

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: failed to compile `canvas-node v0.1.0 (https://github.com/paritytech/canvas-node?tag=v0.1.2#50143553)`, intermediate artifacts can be found at `/tmp/cargo-install6UH3ra`

Caused by:
  build failed
error building at STEP "RUN set -eux;   echo "deb https://dl.yarnpkg.com/debian/ stable main"           > /etc/apt/sources.list.d/yarn.list;    echo "deb http://apt.llvm.org/buster/ llvm-toolchain-buster-8 main"             > /etc/apt/sources.list.d/llvm.list;    echo "deb-src http://apt.llvm.org/buster/ llvm-toolchain-buster-8 main"           >> /etc/apt/sources.list.d/llvm.list;   apt-get -y update;      apt-get remove -y --purge clang;        apt-get install -y --no-install-recommends              llvm-8-dev clang-8 zlib1g-dev npm yarn wabt unzip;        update-alternatives --install /usr/bin/clang clang /usr/bin/clang-8 100;        update-alternatives --install /usr/bin/cc cc /usr/bin/clang-8 100;      rustup toolchain install nightly --target wasm32-unknown-unknown                        --profile minimal --component rustfmt rust-src;   rustup default nightly;         cargo install pwasm-utils-cli --bin wasm-prune;         cargo install cargo-contract;   cargo install --git https://github.com/hyperledger-labs/solang --tag m7;        cargo install --git https://github.com/paritytech/canvas-node --tag v0.1.2;       yarn --version;         rustup show;    cargo --version;        solang --version;       rm -rf "${CARGO_HOME}/registry" "${CARGO_HOME}/git" /root/.cache/sccache;       apt-get autoremove -y;  apt-get clean;  rm -rf /var/lib/apt/lists/*": error while running runtime: exit status 101

Get Canvas running on Rococo again

The parachain is currently no longer working.

ToDo

  • Update this repository to a newer cumulus version
  • Ping devops to upgrade the on-chain runtime

License

Add license file (GPL 3?) and headers to all source code files.

"multiple `intersperse` found"-Error when installing canvas-node

When installing canvas node using

cargo install canvas-node --git https://github.com/paritytech/canvas-node.git --tag v0.1.9 --force --locked

It fails with the following error:

error[E0034]: multiple applicable items in scope
   --> /Users/xxx/.cargo/registry/src/github.com-1ecc6299db9ec823/prost-derive-0.7.0/src/lib.rs:109:14
    |
109 |             .intersperse(quote!(|));
    |              ^^^^^^^^^^^ multiple `intersperse` found
    |
    = note: candidate #1 is defined in an impl of the trait `Iterator` for the type `Map<I, F>`
    = note: candidate #2 is defined in an impl of the trait `Itertools` for the type `T`
help: disambiguate the associated function for candidate #1
    |
105 ~         let tags = Iterator::intersperse(field
106 +             .tags()
107 +             .into_iter()
108 +             .map(|tag| quote!(#tag)), {
109 +         let mut _s = $crate::__private::TokenStream::new();
110 +         $crate::quote_each_token!(_s $($tt)*);
  ...
help: disambiguate the associated function for candidate #2
    |
105 ~         let tags = Itertools::intersperse(field
106 +             .tags()
107 +             .into_iter()
108 +             .map(|tag| quote!(#tag)), {
109 +         let mut _s = $crate::__private::TokenStream::new();
110 +         $crate::quote_each_token!(_s $($tt)*);
  ...

For more information about this error, try `rustc --explain E0034`.
error: could not compile `prost-derive` due to previous error
warning: build failed, waiting for other jobs to finish...
error: failed to compile `europa v0.3.2 (https://github.com/patractlabs/europa.git#f6da65d2)`, intermediate artifacts can be found at `/var/folders/qt/_kwnr6197b120zf0302c_p7r0000gn/T/cargo-installJ7sHVi`

Caused by:
  build failed

It seems like the compiler is unable to distinguish the two interperse functions that are located in different namespaces: Iterator::intersperse and Itertools::intersperse. Although in the prost-derive downstream package only the Itertools lib is imported. I'm new to Rust so I'm not sure why this is happening.

Follow up with `chain-spec` configuration

We want to make sure that we have a safe and functional chainspec for deployment to Rococo. This means not using the default well-known accounts (Alice, Bob, etc.), adding faucet and ink-waterfall accounts, as well as pointing to some live bootnodes.

Keep Persistent Contract State

Question
I was able to deploy an ink contract, query, transact on it etc. The issue is that i am losing the ability to interact with the smart contract around 2 hours after it is deployed. I understand that this is a persistence issue.

However i did start the node with the following command:

canvas --dev #(instead of canvas --dev --tmp)

Which i understand should keep the state.

Deploy smart contract with polkadot.js or canvas-ui
Interact with it for 2 hours and then sometime after any interaction will fail

Here is a snippit of the code i am using to deploy the contract and then interact with it, i also commented where the error occurs after two hours.

https://gist.github.com/ILoomans/e8cb55c72f8b1b274da7fc375cb5a6ba

Hope someone can help!

Tag

Which tag of this canvas-node repo should I use with v3.0.0-rc3 ink smart contract?

Look into adding `pallet-assets`

Using ERC-20 or ERC-721 contracts for asset management is considered un-idiomatic. We should push users to use pallet-assets instead.

There are two ways to integrate this into our chain's workflow:

  1. Adding it directly to the Canvas runtime
  2. Accessing it via Statemine/Statemint

Some investigation is necessary to see the tradeoffs between the different approaches, and the technical requirements for each.

Init.sh requires nightly-2020-10-05

set -e

echo "*** Initializing WASM build environment"

if [ -z $CI_PROJECT_NAME ] ; then
rustup update nightly
rustup update nightly-2020-10-05
rustup update stable
fi

rustup target add wasm32-unknown-unknown --toolchain nightly
rustup target add wasm32-unknown-unknown --toolchain nightly-2020-10-05

Unable to decode storage system.account [Error]

I have the following error when deploying the Flipper contract on a local substrate node. Does anyone what is the cause and how to solve this issue?

Unable to decode storage system.account: entry 0:: createType(AccountInfo):: {"nonce":"Index","consumers":"RefCount","providers":"RefCount","sufficients":"RefCount","data":"AccountData"}:: Decoded input doesn't match input, received 0x0000000000000000000000000000000000000000000000000000000000000000…0000000000000000000000000000000000000000000000000000000000000000 (76 bytes), created 0x0000000000000000000000000000000000000000000000000000000000000000…0000000000000000000000000000000000000000000000000000000000000000 (80 bytes)

Parachain

Currently canvas runs as a solo chain, but ultimately it should be a parachain. This will involve migrating to use cumulus, and if possible still allow it to run as a solochain for the testnet, Moonbeam appear to have achieved something along those lines.

According to @athei, there are still some outstanding issues which need to be resolved before the contracts pallet will work on a parachain:

  • Storage transactions
  • Child tries

Error starting a node: canvas --dev --tmp

  1. Install dependencies with: cargo install canvas-node --git https://github.com/paritytech/canvas-node.git --force --locked. It fails without using --locked.

  2. Run canvas --dev --tmp

  3. Get some errors in the terminal saying it is a bug and to create an issue

2021-08-14 14:07:03 Running in --dev mode, RPC CORS has been disabled.    
2021-08-14 14:07:03 Canvas Node    
2021-08-14 14:07:03 ✌️  version 0.1.0-42252ba-x86_64-macos    
2021-08-14 14:07:03 ❤️  by Canvas, 2020-2021    
2021-08-14 14:07:03 📋 Chain specification: Development    
2021-08-14 14:07:03 🏷 Node name: spotted-ring-7868    
2021-08-14 14:07:03 👤 Role: AUTHORITY    
2021-08-14 14:07:03 💾 Database: RocksDb at /var/folders/qf/31y_8fmd0ybc168g4kqkklw40000gn/T/substrateoPNlI2/chains/dev/db    
2021-08-14 14:07:03 ⛓  Native runtime: canvas-12 (canvas-0.tx1.au1)    
2021-08-14 14:07:03 🔨 Initializing Genesis block/state (state: 0xc64e…6c67, header-hash: 0xf67b…7bc0)    
2021-08-14 14:07:03 👴 Loading GRANDPA authority set from genesis on what appears to be first startup.    
2021-08-14 14:07:03 ⏱  Loaded block-time = 6s from block 0xf67bd5d8dfbfcc3ef1d57ac5ed74f1c918a1145a36ced46f25d862eaddec7bc0    
2021-08-14 14:07:03 Using default protocol ID "sup" because none is configured in the chain specs    
2021-08-14 14:07:03 🏷 Local node identity is: 12D3KooWQgVboU7PT7z7FMdsw8gXYkR4SGjsoQswpWiPNp2suxez    
2021-08-14 14:07:03 could not parse an IP from hosts file    

====================

Version: 0.1.0-42252ba-x86_64-macos

   0: backtrace::backtrace::trace
   1: backtrace::capture::Backtrace::new
   2: sp_panic_handler::set::{{closure}}
   3: std::panicking::rust_panic_with_hook
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:626:17
   4: std::panicking::begin_panic_handler::{{closure}}
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:519:13
   5: std::sys_common::backtrace::__rust_end_short_backtrace
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/sys_common/backtrace.rs:141:18
   6: rust_begin_unwind
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:515:5
   7: core::panicking::panic_fmt
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/panicking.rs:92:14
   8: core::result::unwrap_failed
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/result.rs:1355:5
   9: hyper_rustls::connector::HttpsConnector<hyper::client::connect::http::HttpConnector>::new
  10: sc_offchain::api::http::SharedClient::new
  11: sc_offchain::OffchainWorkers<Client,Block>::new
  12: sc_service::builder::build_offchain_workers
  13: canvas::command::run::{{closure}}::{{closure}}
  14: tokio::runtime::enter::Enter::block_on
  15: tokio::runtime::context::enter
  16: sc_cli::runner::Runner<C>::run_node_until_exit
  17: canvas::command::run
  18: canvas::main
  19: std::sys_common::backtrace::__rust_begin_short_backtrace
  20: std::rt::lang_start::{{closure}}
  21: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/ops/function.rs:259:13
      std::panicking::try::do_call
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:401:40
      std::panicking::try
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:365:19
      std::panic::catch_unwind
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panic.rs:434:14
      std::rt::lang_start_internal
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/rt.rs:34:21
  22: _main


Thread 'main' panicked at 'cannot access native cert store: Custom { kind: Other, error: Error { code: -25262, message: "The Trust Settings Record was corrupted." } }', /Users/alixe/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-rustls-0.21.0/src/connector.rs:46

Any suggestions to troubleshoot and fix?

Thanks

Verify Rococo deployment

  • Test if faucet works
  • Test if contract deployment works
  • Test if contract interaction works
  • Announce in our public channel.

Concurrent connection limit of websocket

Hi, I faced an issue when I made my node public. I get 1006 WebSocket error in my app and when I check my server the node shows this error:

Accepted a new tcp connection from 127.0.0.1:43022.
Unable to build WebSocket connection WS Error <Capacity>: Unable to add another connection to the event loop.

How can I increase the limit?

Cannot deploy contract

When trying to deploy a contract via @polkadot/api, I get an error Cannot read property 'batch' of undefined

According to polkadot-js/api#3268, this seems to be caused by the utility module being missing from the runtime, if I understood correctly

Provide latest release as binary

Problem

There should be an option to install canvas-node without compiling the entire project. In this blog post regarding working with ink! it's mentioned that it took him 31 minutes to compile the project. That's definitely too long if somebody just wants to write a contract and test it.

ToDo

  • Talk to ops how they do this for Polkadot, we can probably take a similar pipeline.

  • A canvas-node binary should be provided with the latest release.

  • Update docs/tutorials so that they mention installing the binary as the first option.

Error during compilation. Could not compile `multihash-derive`

I am trying to run canvas-node by follow command:
cargo install canvas-node --git https://github.com/paritytech/canvas-node.git --tag v0.1.6 --force --locked

Error message:

   Compiling frame-support-procedural-tools v3.0.0 (https://github.com/paritytech/substrate#4551b3c5)
thread 'rustc' panicked at 'assertion failed: self.start_pos.to_u32() + total_extra_bytes <= bpos.to_u32()', compiler/rustc_span/src/lib.rs:1511:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.53.0-nightly (7f4afdf02 2021-04-22) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z instrument-coverage -C prefer-dynamic -C embed-bitcode=no -C debug-assertions=off --crate-type proc-macro

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [mir_promoted] processing `Multihash`
#1 [mir_borrowck] borrow-checking `Multihash`
end of query stack
error: could not compile `multihash-derive`

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish..

`Gas instrumentation failed` when `--execution Wasm` is passed

Steps to reproduce:

  1. Build canvas-node from master
  2. Build flipper example from the ink repository
  3. cargo run -- --dev --execution Wasm -lruntime=debug
  4. Go to canvas UI and upload the .contract file
  5. Click "Sign & Submit" button
  6. Error is displayed in the UI popup
2021-01-21 17:53:55.163  DEBUG tokio-runtime-worker runtime:DispatchError    
2021-01-21 17:53:55.163  DEBUG tokio-runtime-worker runtime:gas instrumentation failed    
2021-01-21 17:53:55.163  DEBUG tokio-runtime-worker runtime:PostInfo:     
2021-01-21 17:53:55.163  DEBUG tokio-runtime-worker runtime:actual_weight=    
2021-01-21 17:53:55.163  DEBUG tokio-runtime-worker runtime:max-weight    
2021-01-21 17:53:55.163  DEBUG tokio-runtime-worker runtime:pays_fee=    
2021-01-21 17:53:55.163  DEBUG tokio-runtime-worker runtime:Yes    

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.