TFchain is the official implementation of the ThreeFold blockchain, which is the ledger technology behind the ThreeFold Grid.
TFchain serves as a digitally distributed, decentralized, public ledger that tracks the storage and computing resources of ZOS nodes running on The ThreeFold Grid, manages the smart contracts that enable users to rent and use these resources and provides the incentive layer which ensures that the nodes are rewarded for their contributions to the network.
The ThreeFold Grid is a decentralized network of nodes that provide cloud resources without intermediaries. The nodes are operated by independent farmers who are incentivized by the ThreeFold Token (TFT). TFT is a utility token that is used to exchange resources on the network and to build and run digital workloads, also is used for paying transaction fees, staking, governance, and smart contract execution.
TFchain is based on Substrate, a framework for building blockchains in Rust. It has several custom pallets that implement its features.
TFchain also supports cross-chain transfers with other blockchains, such as Bitcoin, Binance Smart Chain and Stellar.
The project consists of several components, each with a specific purpose and functionality.
- activation-service: Contains all the GitHub workflows for this repository, such as testing, linting, and creating a release.
- bridge: Contains a program that runs in the background scanning a Stellar vault address for deposits and TFchain for withdrawals and executes upon them. This allows cross-chain transfers between Stellar and TFchain.
- clients: Contains various clients that provide all the functionality for interacting with TFchain.
- tfchain-client-js: JS TFchain client
- tfchain-client-rs: Rust TFchain client (Unfinished)
- tfchain-client-go: Go TFchain client
- docs: Contains all the development and production related documentation for TFchain, such as how to run a node, how to create an account, and how to upgrade the runtime.
- architecture: Architecture Decision Records
- development: Development docs, such as how to run a node, how to create an account.
- misc: Other docs
- production: Production related docs, such as release and runtime upgrade flows.
- research: Contains some research around proof of stake, which is the consensus mechanism used by TFchain. Proof of stake is a way of securing the network by requiring validators to stake their tokens and participate in the consensus process.
- tools: Contains tools for developing and testing TFchain.
- fork-off-substrate: A tool that can fork a live network to be used in development for testing out runtime migrations or upgrades. Runtime migrations or upgrades are changes in the runtime logic that require updating all nodes on the network.
- scripts: Contains JavaScript scripts for various purposes, such as subscribing to events.
- substrate-node: Contains the actual node code that runs the blockchain. It is based on a reference implementation of Substrate called
substrate-node-templat
, which is kept up to date with the latest Substrate release. The node code defines how to initialize and run a Substrate node with the TFchain runtime and pallets.- chainspecs: Contains initial TFchain specifications for all live networks, such as testnet and mainnet. Chain specifications are JSON files that define the genesis state and configuration of each network. They must be used in order to spin up a node from scratch.
- charts: Contains Kubernetes charts for deploying and managing TFchain nodes on cloud platforms. Kubernetes is a system for automating deployment, scaling, and management of containerized applications.
- node: Contains the application that allows users to participate in a blockchain network.
- support: Contains a shared types and configuration crate that is used across the runtime, pallets, and node. It defines common types, traits and constants that are used by different components of TFchain, such as
Farm
. It also declares the ZosNode
type, which is a special type of node that provides zero-os services on Tfgrid. - runtime: Contains the runtime crate that specifies what pallets are used by TFchain and their configuration. A crate is a compilation unit in Rust that can produce an executable or a library. The runtime crate is used by the node crate to run the blockchain with the desired logic and features.
- tests: Contains integration tests crate for TFchain. Integration tests are tests that run the entire system or some of its parts together to check if they work as expected. See the docs on how to develop and run these tests.
- target: Contains the compiled binary files of the Substrate node
- pallets: Contains the actual runtime implementation of TFchain. Runtime is the core logic of the blockchain that defines how it works and what it can do. Runtime is composed of modules called pallets, which provide specific functionality and can be plugged into a runtime. TFchain has several custom pallets that implement its features, such as Tfgrid, TFT Price, Dao, Smart Contract modules and bridge. Check modules documentations for what each module is about.
- Cargo.toml: Contains crate dependencies for the Substrate node project. These dependencies are shared across all sub-crates and specify what external libraries are used by TFchain. If you need to add dependencies for a specific runtime pallet use
Cargo.toml
file for that pallet instead.
- scripts: Contains JavaScript scripts for various purposes, such as subscribing to events.
The TFchain Runtime is built using FRAME and consists of pallets from substrate and pallet/
- System: provide core functionality that all other pallets depend on.
- Utility: Allows users to use derivative accounts, and batch calls.
- Balances: Tracks TFT token balances.
- Timestamp: On-Chain notion of time.
- Transaction Payment: Provides the basic logic to compute pre-dispatch transaction fees.
- Scheduler: Exposes capabilities for scheduling dispatches to occur at a specified block number or at a specified period.
- Session: Allows validators to manage their session keys, provides a function for changing the session length, and handles session rotation.
- Aura: Extends Aura consensus by managing offline reporting.
- Grandpa: Manage the GRANDPA finality authority set.
- Authorship: Tracks the current author of the block and recent uncles.
- Collective: Allows Members of a set of account IDs to make their collective feelings known through dispatched calls from one of two origins.
- Membership: Allows control of membership of a set of Account IDs.
The following pallets are stored in pallets/. They are designed for TFchain's specific requirements:
- pallet-dao: Enables the TFchain network to be governed by its stakeholders. See dao for more info.
- pallet-kvstore: Allow TFchain network participants to store and retrieve key-value pairs of data.
- pallet-runtime-upgrade: Wrapper for frame_system set_code extrinsic to execute it with a configurable origin.
- pallet-smart-contract: Enables the creation, billing and deletion of smart contracts.
- pallet-tfgrid: Registry for Nodes / Farms / Twins
- pallet-tft-bridge: Support bridging requirement between TFchain TFT and Stellar TFT
- pallet-tft-price: TFT price oracle. See price for more info.
- substrate-validator-set: For adding / removing authorities. fork of substrate validator set pallet.
- pallet-validator: (Kinda Deprecated).
- pallet-burning: Allow anyone to burn his TFT (Kinda Deprecated).
see docs for more information on how to work with TFchain.
See bridge for more information on the bridge between TFchain TFT and Stellar TFT.
See scripts for more information on how to use the scripts.
-
Development network:
- Polkadot UI: https://polkadot.js.org/apps/?rpc=wss%3A%2F%2F/tfchain.dev.grid.tf#/explorer
- Websocket url: wss://tfchain.dev.grid.tf
-
Qa testing network:
- Polkadot UI: https://polkadot.js.org/apps/?rpc=wss%3A%2F%2F/tfchain.qa.grid.tf#/explorer
- Websocket url: wss://tfchain.qa.grid.tf
-
Test network
- Polkadot UI: https://polkadot.js.org/apps/?rpc=wss%3A%2F%2F/tfchain.test.grid.tf#/explorer
- Websocket url: wss://tfchain.test.grid.tf
-
Production network
- Polkadot UI: https://polkadot.js.org/apps/?rpc=wss%3A%2F%2F/tfchain.grid.tf#/explorer
- Websocket url: wss://tfchain.grid.tf
In this repository conventional commits are used.
See releases for more information on how to create or validate a release.