Skip to content

udtrokia/darwinia

 
 

Repository files navigation

Darwinia

Build Status (Travis CI) License: GPL v3

1. Darwinia Network

image

Darwinia is the hub chain connecting different application chains and can be connected to Polkadot as a Polkadot Parachain.

Darwinia also support to build the internet of tokens by introducing token bridges between different blockchain networks.

It could have two models, the Solo model and the Polkadot model. For more details, go to RFC-0007.

2. Architecture

Darwinia Architecture

3. Road Map

Darwinia Network provides application developers the scalability, cross-chain interoperability with seamless integrations to Polkadot, token bridges to all major blockchains etc. For more details, go to Road Map.

4. Building

4.1. Hacking on Darwinia

If you’d actually like to hack on Darwinia, you can just grab the source code and build it. We also provide the script to help you setup your developing environment in bellow sections. Please ensure you have Rust and the support software installed:

4.1.1. Linux and Mac

For Unix-based operating systems, you should run the following commands:

curl https://sh.rustup.rs -sSf | sh

rustup default nightly
rustup target add wasm32-unknown-unknown

You will also need to install the following packages:

  • Linux:

    sudo apt install cmake pkg-config libssl-dev git clang libclang-dev
  • Linux on ARM: rust-lld is required for linking wasm, but is missing on non Tier 1 platforms. So, use this script to build lld and create the symlink /usr/bin/rust-lld to the build binary.

  • Mac:

    brew install cmake pkg-config openssl git llvm

To finish installation of Darwinia, jump down to shared steps.

4.1.2. Windows

If you are trying to set up Darwinia on Windows, you should do the following:

  1. First, you will need to download and install "Build Tools for Visual Studio:"

    • You can get it at this link: https://aka.ms/buildtools

    • Run the installation file: vs_buildtools.exe

    • Please ensure the Windows 10 SDK component is included when installing the Visual C++ Build Tools.

    • image

    • Restart your computer.

  2. Next, you need to install Rust:

    • Detailed instructions are provided by the Rust Book.

    • Download from: https://www.rust-lang.org/tools/install

    • Run the installation file: rustup-init.exe > Note that it should not prompt you to install vs_buildtools since you did it in step 1.

    • Choose "Default Installation."

    • To get started, you need Cargo’s bin directory (%USERPROFILE%\.cargo\bin) in your PATH environment variable. Future applications will automatically have the correct environment, but you may need to restart your current shell.

  3. Then, you will need to run some commands in CMD to set up your Wasm Build Environment:

    rustup default nightly
    rustup target add wasm32-unknown-unknown
  4. Then, you need to install LLVM: https://releases.llvm.org/download.html

  5. Next, you need to install OpenSSL, which we will do with vcpkg:

    mkdir \Tools
    cd \Tools
    git clone https://github.com/Microsoft/vcpkg.git
    cd vcpkg
    .\bootstrap-vcpkg.bat
    .\vcpkg.exe install openssl:x64-windows-static
  6. After, you need to add OpenSSL to your System Variables. Note that in order for the following commands to work, you need to use Windows Powershell:

    $env:OPENSSL_DIR = 'C:\Tools\vcpkg\installed\x64-windows-static'
    $env:OPENSSL_STATIC = 'Yes'
    [System.Environment]::SetEnvironmentVariable('OPENSSL_DIR', $env:OPENSSL_DIR, [System.EnvironmentVariableTarget]::User)
    [System.Environment]::SetEnvironmentVariable('OPENSSL_STATIC', $env:OPENSSL_STATIC, [System.EnvironmentVariableTarget]::User)
  7. Finally, you need to install cmake: https://cmake.org/download/

4.1.3. Shared Steps

Then, grab the Darwinia source code:

git clone https://github.com/darwinia-network/darwinia.git
cd darwinia

Then build the code:

cargo build                 # Builds all native code

You can run all the tests if you like:

cargo test --all

Or just run the tests of a specific package (i.e. cargo test -p darwinia-staking)

You can start a development chain with:

cargo run --release -- --dev

Detailed logs may be shown by running the node with the following environment variables set: RUST_LOG=debug RUST_BACKTRACE=1 cargo run --release -- --dev.

If you want to see the multi-node consensus algorithm in action locally, then you can create a local testnet with two validator nodes for Alice and Bob, who are the initial authorities of the genesis chain specification that have been endowed with a testnet Ring.

We’ll start Alice’s Darwinia node first with her chain database stored locally at /tmp/darwinia-develop/alice:

cargo run --release \-- \
  --alice \
  --rpc-external \
  --rpc-port 23333 \
  --ws-external \
  --ws-port 23334 \
  --rpc-cors all \
  --port 23335 \
  --base-path /tmp/darwinia-develop/alice

Or just:

cargo run --release -- --alice --conf=boot-conf/develop/alice.json

In the second terminal, we’ll run the following to start Bob’s Darwinia node on a different TCP port, and with his chain database stored locally at /tmp/darwinia-develop/bob:

cargo run --release \-- \
  --bob \
  --rpc-external \
  --rpc-port 23336 \
  --ws-external \
  --ws-port 23337 \
  --rpc-cors all \
  --port 23338 \
  --base-path /tmp/darwinia-develop/bob

Or just:

cargo run --release -- --bob --conf=boot-conf/develop/bob.json

Additional Darwinia CLI usage options are available and may be shown by running cargo run --release — --help.

4.2. WASM binaries

The WASM binaries are built during the normal cargo build process. To control the WASM binary building, we support multiple environment variables:

  • SKIP_WASM_BUILD - Skips building any WASM binary. This is useful when only native should be recompiled.

  • BUILD_DUMMY_WASM_BINARY - Builds dummy WASM binaries. These dummy binaries are empty and useful for cargo check runs.

  • WASM_BUILD_TYPE - Sets the build type for building WASM binaries. Supported values are release or debug. By default the build type is equal to the build type used by the main build.

  • TRIGGER_WASM_BUILD - Can be set to trigger a WASM build. On subsequent calls the value of the variable needs to change. As WASM builder instructs cargo to watch for file changes this environment variable should only be required in certain circumstances.

  • WASM_TARGET_DIRECTORY - Will copy any build WASM binary to the given directory. The path needs to be absolute.

  • WASM_BUILD_RUSTFLAGS - Extend RUSTFLAGS given to cargo build while building the wasm binary.

  • WASM_BUILD_NO_COLOR - Disable color output of the wasm build.

Each project can be skipped individually by using the environment variable SKIP_PROJECT_NAME_WASM_BUILD. Where PROJECT_NAME needs to be replaced by the name of the cargo project, e.g. node-runtime will be NODE_RUNTIME.

4.3. Precautions

If you run into problems when building this project, please kindly check following things before making an issue.

  • using the latest nightly Rust

  • build without sccache

5. Joining the Crab Testnet

5.1. Quick start (professional):

  • Telemetry

  • Darwinia Web Wallet

  • Bootnodes:

    • /ip4/45.249.244.33/tcp/20222/p2p/QmPCSb9yCRAXnqvG6AnX27X6gutvVDq4NBPDNJtnBmNk43

    • /ip4/121.199.60.87/tcp/20222/p2p/QmaRDRZZpmY9FwjSwW8JhfkyaHc6XRHsLWnp6cLtyb3FCF

    • /ip4/35.234.9.96/tcp/20223/p2p/QmdAZq8tFrei8qQAhbAe7NwrZzNVhitvUBp9pw8yLjk81r

5.2. Full tutorial (beginner):

6. Key management

Keys in Darwinia are stored in the keystore in the file system. To store keys into this keystore, you need to use one of the two provided RPC calls. If your keys are encrypted or should be encrypted by the keystore, you need to provide the key using one of the cli arguments --password, --password-interactive or --password-filename.

For most users who want to run a validator node, the author_rotateKeys RPC call is sufficient. The RPC call will generate N Session keys for you and return their public keys. N is the number of session keys configured in the runtime. The output of the RPC call can be used as input for the session::set_keys transaction.

curl -H 'Content-Type: application/json' --data '{ "jsonrpc":"2.0", "method":"author_rotateKeys", "id":1 }' localhost:9933

6.2. Advanced RPC call

If the Session keys need to match a fixed seed, they can be set individually key by key. The RPC call expects the key seed and the key type. The key types supported by default in Darwinia are listed here, but the user can declare any key type.

curl -H 'Content-Type: application/json' --data '{ "jsonrpc":"2.0", "method":"author_insertKey", "params":["KEY_TYPE", "SEED", "PUBLIC"],"id":1 }' localhost:9933

KEY_TYPE - needs to be replaced with the 4-character key type identifier. SEED - is the seed of the key. PUBLIC - public key for the given key.

7. Documentation

7.1. Viewing documentation for Darwinia packages

You can generate documentation for a Darwinia Rust package and have it automatically open in your web browser using rustdoc with Cargo, (of the The Rustdoc Book), by running the following command:

cargo doc --open

If you just want to generate document from specific package, you may use following command:

cargo doc --package <spec> --open

Replacing <spec> with one of the following (i.e. cargo doc --package darwinia-cli --open):

  • Darwinia Core

    darwinia-cli, ethash, fly-client,
    merkle-mountain-range, merkle-patricia-trie, eth-primitives
  • Darwinia Runtime Module Library

    darwinia-ring, darwinia-eth-backing, darwinia-eth-relay,
    darwinia-kton, darwinia-staking, darwinia-support
  • Node

    node-cli, node-primitives, node-runtime

8. Contributing

8.1. Environment

The scripts/bootstrap.sh help set up your develop environment. The nightly Rust, cargo, rustfmt will be installed, the git hooks will be set, and ready to code.

Besides, the script will install some essential packages depends on your OS, if you want to do it manually, use the --fast option to skip. We will appreciate your contribution.

8.2. Contributing Guidelines

9. License

About

Relay chain of Darwinia Network, can connect to Polkadot as parachain in Polkadot Model

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 99.1%
  • Other 0.9%