Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(polkadot): upgrade to v1.0.0 #898

Merged
merged 26 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 51 additions & 50 deletions clients/tfchain-client-go/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,83 +2,84 @@

# **TFchain go client**

- This library is a go implementation of a client for the TFChain.
- Internally, our own [fork](https://github.com/threefoldtech/go-substrate-rpc-client) of <https://github.com/centrifuge/go-substrate-rpc-client> is used to make substrate rpc calls.
- Used in multiple repos like [zos](https://github.com/threefoldtech/zos), [rmb-go](https://github.com/threefoldtech/rmb_go), and [terraform-provider-grid](https://github.com/threefoldtech/terraform-provider-grid).
* This library is a go implementation of a client for the TFChain.
* Internally, our own [fork](https://github.com/threefoldtech/go-substrate-rpc-client) of <https://github.com/centrifuge/go-substrate-rpc-client> is used to make substrate rpc calls.
* Used in multiple repos like [zos](https://github.com/threefoldtech/zos), [rmb-go](https://github.com/threefoldtech/rmb_go), and [terraform-provider-grid](https://github.com/threefoldtech/terraform-provider-grid).

## **Usage**

To make substrate calls:

- First, start a substrate connection against the desired url for the chain:
* First, start a substrate connection against the desired url for the chain:

```go
manager := NewManager("wss://tfchain.grid.tf/ws")
substrateConnection, err := manager.Substrate()
```
```go
manager := NewManager("wss://tfchain.grid.tf/ws")
substrateConnection, err := manager.Substrate()
```

* These are the urls for different chain networks:

- These are the urls for different chain networks:

- devnet: <wss://tfchain.dev.grid.tf/ws>
- testnet: <wss://tfchain.test.grid.tf/ws>
- qanet: <wss://tfchain.qa.grid.tf/ws>
- mainnet: <wss://tfchain.grid.tf/ws>
* devnet: <wss://tfchain.dev.grid.tf/ws>
* testnet: <wss://tfchain.test.grid.tf/ws>
* qanet: <wss://tfchain.qa.grid.tf/ws>
* mainnet: <wss://tfchain.grid.tf/ws>

- It is the user's responsibility to close the connection.
* It is the user's responsibility to close the connection.

```go
defer substrateConnection.Close()
```
```go
defer substrateConnection.Close()
```

- Then, a user could use the provided api calls to communicate with the chain. like:
* Then, a user could use the provided api calls to communicate with the chain. like:

```go
contractID, err := substrateConnection.CreateNodeContract(identity, nodeID, body, hash, publicIPsCount, solutionProviderID)
```
```go
contractID, err := substrateConnection.CreateNodeContract(identity, nodeID, body, hash, publicIPsCount, solutionProviderID)
```

- Also, if a connection is closed for some reason like timing out, internally, it is reopened if nothing blocks.
- All provided api calls are found under the Substrate struct.
* Also, if a connection is closed for some reason like timing out, internally, it is reopened if nothing blocks.

* All provided api calls are found under the Substrate struct.

## **Run tests**

To run the tests, you could either run it against a local docker image of the TFChain, or against devnet
To run the tests, you could either run it against a local docker image of the TFChain, or against devnet

- ### **Run against local docker image**
* ### **Run against local docker image**

To run tests against a local docker image of tfchain, you need to set CI environment variable to anything actually.
To run tests against a local docker image of tfchain, you need to set CI environment variable to anything actually.

```bash
docker run -d -p 9944:9944 threefolddev/tfchain:2.2.0-rc8 --dev --ws-external
sleep 3
export CI="true"
go test . -v
```
```bash
docker run -d -p 9944:9944 threefolddev/tfchain:2.2.0-rc8 --dev --rpc-external
sleep 3
export CI="true"
go test . -v
```

- ### **Run against devnet**
* ### **Run against devnet**

```bash
unset CI
go test . -v
```
```bash
unset CI
go test . -v
```

### **Test Coverage**

- 30.6% of statements
* 30.6% of statements

## **Workflows**

- ### **Test**

- This workflow runs all tests found in the root directory against a local docker image of the [TFChain](https://github.com/threefoldtech/tfchain) found [here](https://hub.docker.com/r/threefolddev/tfchain).
* ### **Test**

- ### **Lint**
* This workflow runs all tests found in the root directory against a local docker image of the [TFChain](https://github.com/threefoldtech/tfchain) found [here](https://hub.docker.com/r/threefolddev/tfchain).

- This workflow ensures linting, so make sure to run these commands without any errors before pushing code:
* ### **Lint**

```bash
golangci-lint run
```
* This workflow ensures linting, so make sure to run these commands without any errors before pushing code:

```bash
gofmt -d -l .
```
```bash
golangci-lint run
```

```bash
gofmt -d -l .
```
26 changes: 14 additions & 12 deletions docs/development/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ cargo build
```

## Run a dev node

A dev node is a single-node network that runs on your local machine. It is useful for testing and debugging purposes. To run a dev node, you need to do the following:

```sh
cd tfchain/substrate-node
cargo build

./target/debug/tfchain --dev --ws-external --pruning archive
./target/debug/tfchain --dev --rpc-external --pruning archive
```

This will run the node in default development mode. This flag sets `--chain=dev`, `--force-authoring`, `--rpc-cors=all`, `--alice`, and `--tmp` flags, unless explicitly overridden.

## Run multiple local nodes
Expand All @@ -45,11 +47,12 @@ If you want to run tfchain in a multi node network (more than one node), see [lo
You can use the Polkadot JS Apps ui to connect to your dev node. You can access the web interface at https://polkadot.js.org/apps/ and change the settings to use a local node with the address `ws://127.0.0.1:9944`.

This will allow you to interact with your dev node and perform basic operations.
- Use the Polkadot JS Apps to interact with your nodes. You can access the web interface at https://polkadot.js.org/apps/ and change the settings to use a local node or a remote node with the appropriate address.
- Use the `Accounts` tab to manage your accounts and balances. You can create new accounts, import existing accounts, transfer tokens, and view your transaction history.
- Use the `Explorer` tab to view the network status and activity. You can see the latest blocks, events, validators, and peers.
- Use the `Chain State` tab to query the state of the network. You can select a module and a storage item and see its value at any given block.
- Use the `Extrinsics` tab to submit extrinsics to the network. You can select an account, a module, and a function and provide any required parameters.

* Use the Polkadot JS Apps to interact with your nodes. You can access the web interface at https://polkadot.js.org/apps/ and change the settings to use a local node or a remote node with the appropriate address.
* Use the `Accounts` tab to manage your accounts and balances. You can create new accounts, import existing accounts, transfer tokens, and view your transaction history.
* Use the `Explorer` tab to view the network status and activity. You can see the latest blocks, events, validators, and peers.
* Use the `Chain State` tab to query the state of the network. You can select a module and a storage item and see its value at any given block.
* Use the `Extrinsics` tab to submit extrinsics to the network. You can select an account, a module, and a function and provide any required parameters.

## Create an account

Expand Down Expand Up @@ -79,19 +82,18 @@ A pallet is a modular component that defines some logic and functionality for th

To learn about pallet development, you can start by checking these resources:

- Get start by reading The substrate [Build application logic tutorials](https://docs.substrate.io/tutorials/build-application-logic/). these tutorials focus on how you can customize the runtime using pallets, creating a custom pallet using macros, adding it to the runtime, and testing its functionality.

- Check the [the Substrate collectibles workshop](https://docs.substrate.io/tutorials/collectibles-workshop/runtime-and-pallets/). This is an interactive, hands-on, and self-paced workshop that introduces the basic steps for building a blockchain-based application using Substrate.
* Get start by reading The substrate [Build application logic tutorials](https://docs.substrate.io/tutorials/build-application-logic/). these tutorials focus on how you can customize the runtime using pallets, creating a custom pallet using macros, adding it to the runtime, and testing its functionality.

- Explore other existing pallets on the [Substrate GitHub repository](https://github.com/paritytech/substrate/tree/master/frame) and learn from their code. You can see how different pallets implement different features and patterns, such as storage, events, errors, hooks, traits, weights, origins, calls, etc.
* Check the [the Substrate collectibles workshop](https://docs.substrate.io/tutorials/collectibles-workshop/runtime-and-pallets/). This is an interactive, hands-on, and self-paced workshop that introduces the basic steps for building a blockchain-based application using Substrate.

* Explore other existing pallets on the [Substrate GitHub repository](https://github.com/paritytech/substrate/tree/master/frame) and learn from their code. You can see how different pallets implement different features and patterns, such as storage, events, errors, hooks, traits, weights, origins, calls, etc.

## Writing tests for pallets

Every pallet should have all functionality tested, you can write unit tests and integration tests for a pallet:

- Unit tests: check this [guide](https://docs.substrate.io/reference/how-to-guides/testing/)
- Integration tests: see this [document](../../substrate-node/tests/readme.md)
* Unit tests: check this [guide](https://docs.substrate.io/reference/how-to-guides/testing/)
* Integration tests: see this [document](../../substrate-node/tests/readme.md)

## Upgrading Substrate version

Expand Down
28 changes: 15 additions & 13 deletions docs/development/fork-off-substrate.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,53 @@ The fork-off-substrate tool is a handy tool that allows you to download and run
In this guide, we will show you how to use the tool to create a local fork of the TFchain network.

### Prerequisites

Before you start, you need to have the following items:

- The executable binary and the runtime WASM blob of the target blockchain. You can either compile them from the source code of the blockchain project, or copy them from a trusted node that runs the blockchain. For TFchain, you can find the source code [here](https://github.com/threefoldtech/tfchain) and the instructions on how to compile it [here](https://github.com/threefoldtech/tfchain/tree/development/docs/development). Find the Wasm binary file in the target directory. The file name should be `tfchain_runtime.compact.wasm` and the file path should be something like this:
* The executable binary and the runtime WASM blob of the target blockchain. You can either compile them from the source code of the blockchain project, or copy them from a trusted node that runs the blockchain. For TFchain, you can find the source code [here](https://github.com/threefoldtech/tfchain) and the instructions on how to compile it [here](https://github.com/threefoldtech/tfchain/tree/development/docs/development). Find the Wasm binary file in the target directory. The file name should be `tfchain_runtime.compact.wasm` and the file path should be something like this:

```bash
./substrate-node/target/debug/wbuild/tfchain-runtime/tfchain_runtime.compact.wasm
```

### Steps
- Install the `fork-off-substrate` tool dependencies on your computer, go to `tfchain` directory then follow these steps:

* Install the `fork-off-substrate` tool dependencies on your computer, go to `tfchain` directory then follow these steps:
```bash
cd ./tools/fork-off-substrate
npm i
```
- Create a folder called data inside the top folder (fork-off-substrate).
* Create a folder called data inside the top folder (fork-off-substrate).
```bash
mkdir data
```
- Copy the executable/binary of your substrate based node inside the data folder and rename it to `binary`
* Copy the executable/binary of your substrate based node inside the data folder and rename it to `binary`
```bash
cp ../../substrate-node/target/debug/tfchain ./data/binary
```
- Copy the runtime WASM blob of your substrate based blockchain to the data folder and rename it to `runtime.wasm`.
* Copy the runtime WASM blob of your substrate based blockchain to the data folder and rename it to `runtime.wasm`.
```bash
cp ../../substrate-node/target/debug/wbuild/tfchain-runtime/tfchain_runtime.compact.wasm ./data/runtime.wasm
```
- Run a full node for your blockchain locally (Recommended but should be fully synced) or have an external endpoint handy (but should be running with `--rpc-methods Unsafe` flag)
* Run a full node for your blockchain locally (Recommended but should be fully synced) or have an external endpoint handy (but should be running with `--rpc-methods Unsafe` flag)
```bash
../../substrate-node/target/debug/tfchain --chain ../../substrate-node/chainspecs/dev/chainSpecRaw.json --ws-external --rpc-methods Unsafe
../../substrate-node/target/debug/tfchain --chain ../../substrate-node/chainspecs/dev/chainSpecRaw.json --rpc-external --rpc-methods Unsafe
```
- Run the script
* Run the script

- If using a local node, simply run the script using
* If using a local node, simply run the script using
```bash
npm start
```

- If you are using an external/non-default endpoint, you need to provide it to the script via the HTTP_RPC_ENDPOINT environment variable
* If you are using an external/non-default endpoint, you need to provide it to the script via the HTTP\_RPC\_ENDPOINT environment variable
```bash
HTTP_RPC_ENDPOINT=https://<EXTERNAL END POINT> npm start
```
- You should have the genesis file for the forked chain inside the data folder. It will be called `fork.json`.
- You can now run a new chain using this genesis file
* You should have the genesis file for the forked chain inside the data folder. It will be called `fork.json`.
* You can now run a new chain using this genesis file
```bash
./data/binary --chain ./data/fork.json --alice
```

for more information about this tool, you can read this [blog post](https://mudit.blog/fork-substrate-blockchain/).
for more information about this tool, you can read this [blog post](https://mudit.blog/fork-substrate-blockchain/).
35 changes: 16 additions & 19 deletions docs/development/local_multinode.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ cd substrate-node
cargo build
```

you can
you can

## Start the network

In a terminal window execute the following command:
Expand All @@ -20,8 +21,7 @@ In a terminal window execute the following command:
--chain local \
--alice \
--port 30333 \
--ws-port 9945 \
--rpc-port 9933 \
--rpc-port 9945 \
--node-key 0000000000000000000000000000000000000000000000000000000000000001 \
--validator
```
Expand All @@ -36,8 +36,7 @@ In a second terminal window executing the following command:
--chain local \
--bob \
--port 30334 \
--ws-port 9946 \
--rpc-port 9934 \
--rpc-port 9946 \
--telemetry-url "wss://telemetry.polkadot.io/submit/ 0" \
--validator \
--bootnodes /ip4/127.0.0.1/tcp/30333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp
Expand Down Expand Up @@ -73,25 +72,23 @@ Verify that you see lines similar to the following in the terminal where you sta

In these lines, you can see the following information about your blockchain:

- The second node identity was discovered on the network (12D3KooWBCbmQovz78Hq7MzPxdx9d1gZzXMsn6HtWj29bW51YUKB).
- The node has a one peer (1 peers).
- The nodes have produced some blocks (best: #3 (0x0c55…d51b)).
- The blocks are being finalized (finalized #1 (0xf086…9847)).
* The second node identity was discovered on the network (12D3KooWBCbmQovz78Hq7MzPxdx9d1gZzXMsn6HtWj29bW51YUKB).
* The node has a one peer (1 peers).
* The nodes have produced some blocks (best: #3 (0x0c55…d51b)).
* The blocks are being finalized (finalized #1 (0xf086…9847)).

## Review the command-line options

Before moving on, have a look at how the following options are used to start the node.

- --base-path Specifies the directory for storing all of the data related to this chain.
- --chain local Specifies the chain specification to use. Valid predefined chain specifications include local, development, and staging.
- --alice Adds the predefined keys for the alice account to the node's keystore. With this setting, the alice account is used for block production and finalization.
- --port 30333 Specifies the port to listen on for peer-to-peer (p2p) traffic. Because this tutorial uses two nodes running on the same physical computer to simulate a network, you must explicitly specify a different port for at least one account.
- --ws-port 9945 Specifies the port to listen on for incoming WebSocket traffic. The default port is 9944. This tutorial uses a custom web socket port number (9945).
- --rpc-port 9933 Specifies the port to listen on for incoming RPC traffic. The default port is 9933.
- --node-key <key> Specifies the Ed25519 secret key to use for libp2p networking. You should only use this option for development and testing.
- --telemetry-url Specifies where to send telemetry data. For this tutorial, you can send telemetry data to a server hosted by Parity that is available for anyone to use.
- --validator Specifies that this node participates in block production and finalization for the network.

* \--base-path Specifies the directory for storing all of the data related to this chain.
* \--chain local Specifies the chain specification to use. Valid predefined chain specifications include local, development, and staging.
* \--alice Adds the predefined keys for the alice account to the node's keystore. With this setting, the alice account is used for block production and finalization.
* \--port 30333 Specifies the port to listen on for peer-to-peer (p2p) traffic. Because this tutorial uses two nodes running on the same physical computer to simulate a network, you must explicitly specify a different port for at least one account.
* \--rpc-port 9945 Specifies the port to listen on for incoming RPC traffic. The default port is 9944.
* \--node-key <key> Specifies the Ed25519 secret key to use for libp2p networking. You should only use this option for development and testing.
* \--telemetry-url Specifies where to send telemetry data. For this tutorial, you can send telemetry data to a server hosted by Parity that is available for anyone to use.
* \--validator Specifies that this node participates in block production and finalization for the network.

## What next

Expand Down
Loading