Skip to content

Cyborg-Network/cyborg-parachain

Repository files navigation

Cyborg Network Parachain Implementation

Emblem Green

Decentralized Edge Computing


Official Repository for the Cyborg Network

💡 Built with Substrate.

Substrate version Medium License Twitter URL Telegram

Getting Started

Depending on your operating system and Rust version, there might be additional packages required to compile. Check the Install instructions for your platform for the most common dependencies. Alternatively, you can use one of the alternative installation options.

Build (For the PoC)

Use the following command to build the node without launching it:

Compile the code

cargo build --release --features ocw

Execute the off chain worker module

./target/release/cyborg-node --dev --enable-offchain-indexing=true

Connect with Polkadot-JS Apps Front-End

After you start the node locally, you can interact with it using the hosted version of the Polkadot/Substrate Portal front-end by connecting to the local node endpoint. A hosted version is also available on IPFS (redirect) here or IPNS (direct) here. You can also find the source code and instructions for hosting your own instance on the polkadot-js/apps repository.

Multi-Node Local Testnet

If you want to see the multi-node consensus algorithm in action, see Simulate a network.

Blockchain Structure

A Substrate-based project such as Cyborg Network consists of a number of components that are spread across a few directories.

Node

A blockchain node is an application that allows users to participate in a blockchain network. Substrate-based blockchain nodes expose a number of capabilities:

  • Networking: Substrate nodes use the libp2p networking stack to allow the nodes in the network to communicate with one another.
  • Consensus: Blockchains must have a way to come to consensus on the state of the network. Substrate makes it possible to supply custom consensus engines and also ships with several consensus mechanisms that have been built on top of Web3 Foundation research.
  • RPC Server: A remote procedure call (RPC) server is used to interact with Substrate nodes.

There are several files in the node directory. Take special note of the following:

  • chain_spec.rs: A chain specification is a source code file that defines a Substrate chain's initial (genesis) state. Chain specifications are useful for development and testing, and critical when architecting the launch of a production chain. Take note of the development_config and testnet_genesis functions,. These functions are used to define the genesis state for the local development chain configuration. These functions identify some well-known accounts and use them to configure the blockchain's initial state.
  • service.rs: This file defines the node implementation. Take note of the libraries that this file imports and the names of the functions it invokes. In particular, there are references to consensus-related topics, such as the block finalization and forks and other consensus mechanisms such as Aura for block authoring and GRANDPA for finality.
  • cli.rs: This file defines the command-line interface that allows users to interact with the node. Take note of the parameters that this file defines and how they are used to instantiate the node.
  • main.rs: This file defines the main function that starts the node. Take note of the parameters that this file passes to the service.rs file.

Runtime

In Substrate, the terms "runtime" and "state transition function" are analogous. Both terms refer to the core logic of the blockchain that is responsible for validating blocks and executing the state changes they define. The Substrate project in this repository uses FRAME to construct a blockchain runtime. FRAME allows runtime developers to declare domain-specific logic in modules called "pallets". At the heart of FRAME is a helpful macro language that makes it easy to create pallets and flexibly compose them to create blockchains that can address a variety of needs.

Review the FRAME runtime implementation included in this repository and note the following:

  • This file configures several pallets to include in the runtime. Each pallet configuration is defined by a code block that begins with impl $PALLET_NAME::Config for Runtime.
  • The pallets are composed into a single runtime by way of the construct_runtime! macro, which is part of the core FRAME Support system library.

Pallets

The runtime in this project is constructed using many FRAME pallets that ship with the core Substrate repository and a template pallet that is defined in the pallets directory.

A FRAME pallet is compromised of a number of blockchain primitives:

  • Storage: FRAME defines a rich set of powerful storage abstractions that makes it easy to use Substrate's efficient key-value database to manage the evolving state of a blockchain.
  • Dispatchables: FRAME pallets define special types of functions that can be invoked (dispatched) from outside of the runtime in order to update its state.
  • Events: Substrate uses events and errors to notify users of important changes in the runtime.
  • Errors: When a dispatchable fails, it returns an error.
  • Config: The Config configuration interface is used to define the types and parameters upon which a FRAME pallet depends.

Alternatives Installations

Instead of installing dependencies and building this source directly, consider the following alternatives.

Nix

Install nix, and optionally direnv and lorri for a fully plug-and-play experience for setting up the development environment. To get all the correct dependencies, activate direnv direnv allow and lorri lorri shell.

Dockernote of the Rust compiler output.

Build

🔨 Use the following command to build the node without launching it:

cargo build --release

🐳 Alternatively, build the docker image:

docker build . -t cyborg-parachain

Local Development Chain

🧟 This project uses Zombienet to orchestrate the relaychain and parachain nodes. You can grab a released binary or use an npm version.

This template produces a parachain node. You still need a relaychain node - you can download the polkadot (and the accompanying polkadot-prepare-worker and polkadot-execute-worker) binaries from Polkadot SDK releases.

Make sure to bring the parachain node - as well as polkadot, polkadot-prepare-worker, polkadot-execute-worker, and zombienet - into PATH like so:

export PATH="./target/release/:$PATH"

This way, we can conveniently use them un the following steps.

👥 The following command starts a local development chain, with a single relay chain node and a single parachain collator:

zombienet --provider native spawn ./zombienet.toml

# Alternatively, the npm version:
npx --yes @zombienet/cli --provider native spawn ./zombienet.toml

Task Examples:

(Just enter the name of the docker images in the UI to Execute)

  1. hello-world - Prints the docker hello world message
  2. cyborgnetwork/simple-python:new - A sample python program with arithmetic functions
  3. cyborgnetwork/flog_loader:latest - a loader app to test logs

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published