Xuperchain Quick Start-Environment Deployment! ! ! (Including make error resolution, command and result analysis)

introduction

This article is based on the official technical documentation of xuperchain, and organizes the problems encountered in environment deployment as well as the specific meanings of some commands and their output, so that everyone can understand and solve the problem more conveniently! ! ! , if you want to know more about xuperchain, you can read [xuperchain official technical document]

Table of contents

1.1. Prepare the environment

XuperChain is mainly developed by Golang and needs to first prepare the compilation and running environment.

  • Install the go language compilation environment

$ sudo apt update
$ sudo apt install golang
  • Install git
$ sudo apt update
$ sudo apt install git

1.2. Compile XuperChain

  • Switch to the root user and create a working directory in the / directory

    su - root
    mkdir blockchain
    cd blockchain 
    
  • Use git to download the source code locally

    git clone https://github.com/xuperchain/xuperchain.git

  • Excuting an order

$ cd xuperchain
$ git checkout -b v5.1.0 v5.1.0
$ make
  • Get three folders bin, conf, data and a control.sh script in the output directory

annotation

1. When making, the pull may fail. You can configure GOPROXY to solve this problem.

$ export GOPROXY=https://goproxy.cn,direct

GOPATH problem reports error, it is not recommended to use versions before go1.11

GCC version needs to be upgraded to 4 or above

2. When make compiles and reports the following error:

Environment variable XVM_BUILD_MAIN not set
make[1]: *** [Makefile:36: guard-XVM_BUILD_MAIN] Error 1
make[1]: *** Waiting for unfinished jobs…
g++ -I. -Isrc -MMD -MP -std=c++11 -c src/tools/wasm2c.cc -o build/src/tools/wasm2c.cc.o
make[1]: Leaving directory ‘/root/xuperchain/.compile_cache/xvm/xvm/compile/wabt’
complie xvm failed
make: *** [Makefile:24: xvm] Error 1

The problem here is that the guard-XVM_BUILD_MAIN variable is not set in the xuperchain/auto/build_xvm.sh script.

Solution:

vim auto/build_xvm.sh

Add export XVM_BUILD_MAIN=0
Insert image description here

3.Go module download timeout problem

go: github.com/ChainSafe/[email protected]: Get “https://proxy.golang.org/github.com/%21chain%21safe/go-schnorrkel/@v/v0.0.0-20200626160457-b38283118816.mod”: dial tcp 142.251.43.17:443: i/o timeout
go build -o /xuperchain/output/bin/xchain-cli -ldflags “-X main.Version=heads/v5.1.0 -X main.BuildTime=2023-06-15-19:26:37 -X main.CommitID=e235881” /xuperchain/cmd/client/main.go
go: github.com/ChainSafe/[email protected]: Get “https://proxy.golang.org/github.com/%21chain%21safe/go-schnorrkel/@v/v0.0.0-20200626160457-b38283118816.mod”: dial tcp 172.217.163.49:443: i/o timeout
go: downloading github.com/golang/protobuf v1.4.2
go: downloading github.com/manifoldco/promptui v0.7.0
go: downloading github.com/xuperchain/burrow v0.30.6-0.20210115120720-3da1be35a1e2
go: downloading github.com/spf13/cobra v1.0.0
go: downloading github.com/spf13/viper v1.6.2
go: downloading github.com/xuperchain/crypto v0.0.0-20201028025054-4d560674bcd6
go: downloading github.com/xuperchain/xupercore v0.0.0-20210608021245-b15f81dd9ecf
go: downloading google.golang.org/grpc v1.33.1
go: downloading github.com/grpc-ecosystem/grpc-gateway v1.16.0
go: downloading google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013
go: github.com/ChainSafe/[email protected]: Get “https://proxy.golang.org/github.com/%21chain%21safe/go-schnorrkel/@v/v0.0.0-20200626160457-b38283118816.mod”: dial tcp 172.217.163.49:443: i/o timeout
compile done!

The error message here shows that a connection timeout occurred while downloading the github.com/ChainSafe/[email protected] module

Solution:

Configure the proxy to solve the problem of Go module download

SetGOPROXY environment variable tohttps://goproxy.cn, which will use domestic mirror source as proxy

vim /etc/profile
加入export GOPROXY=https://goproxy.cn
source /etc/profile

After make is compiled, under output, there are three directories: bin, conf, data, and a control.sh script.

The functions of each directory are as follows:

directory name Function
output/ Node root directory
├─ bin Executable file storage directory
│ ··· ├─ wasm2c XVM virtual machine tool, convert WASM to C
│ ··· ├─ xchain Binaries for the xchain service
│ ··· ├─ xchain-cli xchain client tool, a command line tool for interacting with the XuperChain blockchain
├─ conf Configure related directories
│ ··· ├─ contract.yaml Contract configuration related
│ ··· ├─ engine.yaml Engine related configuration
│ ··· ├─ env.yaml Local environment related configuration, setting key storage path, etc.
│ ··· ├─ ledger.yaml Storage engine related configuration, levelDB, etc.
│ ··· ├─ log.yaml Log related configuration, log level, retention time, etc.
│ ··· ├─ network.yaml Network-related configuration, ports need to be changed when configuring a single machine with multiple nodes, etc.
│ ··· ├─ server.yaml Service related configuration, such as port, tls, etc.
│ ··· ├─ xchain-cli.yaml Xchain client related configuration, whether transactions need to be configured, transaction sending nodes, etc.
├─ control.sh startup script
├─ data Data storage directory, genesis block information, and examples of consensus and contracts
│ ··· ├─ blockchain Ledger directory (generated after starting the chain)
│ ··· ├─ keys The address of this node, which is globally unique
│ ··· ├─ netkeys The network identification ID of this node, which is globally unique
│ ··· └─ genesis Including the founding consensus, initial number of resources, miner reward mechanism, etc.
├─ logs Program log directory (generated after starting the chain)
├─ tmp Temporary folder, currently storing process pid (generated after starting the chain)

**
**

XuperChain command and option analysis:

**

XuperChain(一个高性能、可扩展的区块链底层引擎)的命令行工具xchain-cli的帮助文档。以下是主要的命令和选项:
account:操作账户或地址,如余额查询、新建账户等。
acl:操作访问控制列表(ACL)。
block:操作区块。
consensus:共识模块命令,如状态查询、调用等。
contract:操作合约命令,如查询。
evm:操作EVM合约,如部署、升级、调用、查询等。
governToken:管理代币,如初始化、转账、查询等。
help:获取任何命令的帮助信息。
multisig:使用多签名操作命令,如检查、生成、发送、签名、获取等。
native:操作原生合约,如部署、升级、调用、查询等。
netURL:操作网络URL,如生成、获取、预览、转换等。
proposal:提案命令,如发起提案、投票、解冻、查询等。
status:获取当前XuperChain服务器状态的命令。
tdpos:与TDPOS相关的命令,如查询候选节点、检查结果、提名记录等。
transfer:操作转账交易,如在账户或公钥之间转移代币。
tx:操作交易命令,如查询。
utxo:操作UTXO,如列表、合并、拆分等。
vote:操作投票命令。
wasm:与WASM相关的命令,如部署、调用、查询等。
watch:观察区块事件。
可选标志: -C, --conf string:客户端配置文件(默认为"./conf/xchain-cli.yaml")。 --crypto string:加密类型(默认为"default")。 -h, --help:xchain-cli的帮助信息。 -H, --host string:服务器节点IP和端口(默认为"127.0.0.1:37101")。 --keys string:密钥目录(默认为"./data/keys")。 --name string:区块链名称(默认为"xuper")。 -v, --version:xchain-cli的版本信息。
要获取有关特定命令的更多信息,请使用"xchain-cli [command] --help"

**

2.1. Deploy xchain service

2.1.1. Start the service

xuper5 provides a convenient script for us to start the service. Only one command is needed to use control.sh to start a single node single consensus chain.

# 启动xuper链
$ bash control.sh start
/xuperchain/output/bin/xchain
/xuperchain/output/conf/env.yaml
2023/06/15 19:39:41 start create chain.bc_name:xuper genesis_conf:./data/genesis/xuper.json env_conf:./conf/env.yaml
2023/06/15 19:39:41 create ledger succ.bc_name:xuper
start xchain. cmd:nohup /xuperchain/output/bin/xchain startup --conf /xuperchain/output/conf/env.yaml >/xuperchain/output/logs/nohup.out 2>&1 &
.start proc succ.
start finish.pid:16259
Done!

Run the bash control.sh start command to successfully start the XuperChain node. The following is an explanation of the command execution output:
/xuperchain/output/bin/xchain represents the path to the compiled executable file.

/xuperchain/output/conf/env.yaml is the path to the configuration file.

2023/06/15 19:39:41 start create chain.bc_name:xuper genesis_conf:./data/genesis/xuper.json env_conf:./conf/env.yaml means that a block named "xuper" is being created chain, and use the genesis configuration located at ./data/genesis/xuper.json and the environment configuration located at ./conf/env.yaml.

2023/06/15 19:39:41 create ledger succ.bc_name:xuper means that the ledger named "xuper" was successfully created.

start xchain. cmd:nohup /xuperchain/output/bin/xchain startup --conf /xuperchain/output/conf/env.yaml >/xuperchain/output/logs/nohup.out 2>&1 & means starting xchain The node command outputs the log to the /xuperchain/output/logs/nohup.out file.

.start proc succ. indicates that the startup process is successful.

start finish.pid:16259 indicates that the startup process has been completed and the process ID is 16259.

Done! indicates that the entire startup process has been completed.
Through these outputs, you can confirm that the XuperChain node has been successfully started.

In this way, we successfully started a chain.

The control.sh script provides four commands: start | stop | restart | forcestop, which can be viewed using bash control.sh help

2.1.2. Confirm service status

According to the default configuration, the xchain service will listen to port 37101. You can use the following command to check the running status of the xchain service.

 # check服务运行状况
 $ bin/xchain-cli status -H 127.0.0.1:37101
 {
   "blockchains": [
   {
     "name": "xuper",
     "ledger": {
       "rootBlockid": "d93c260ea5639a55e1fcad3df494495efad5c65d46e846b6db3a9194a4212886",
       "tipBlockid": "9555ca5af579db67734f27013dfaae48d93e4c3e8adcf6ca8f3dc1adb06d0b6f",
       "trunkHeight": 137
     },
     ....
         "9555ca5af579db67734f27013dfaae48d93e4c3e8adcf6ca8f3dc1adb06d0b6f"
      ]
     }
   ],
  "peers": null,
  "speeds": {}
}

2.2. Use of basic functions

2.2.1. Create a new account

In xchain, account types are divided into "ordinary account" and "contract account".

Ordinary accounts are generated offline by the program and saved locally;

The contract account is the unit used for smart contract management in XuperChain. A transaction is initiated by an ordinary account, and a 16-digit account is generated on the chain and stored on the chain. When initiating contract-related transactions, such as contract calls, you need to use a contract account.

# 创建普通用户, 生成的地址,公钥,私钥在--output 指定位置
$ bin/xchain-cli account newkeys --output data/bob
create account using crypto type default
create account in data/bob

# xuperchain 也支持国密算法,关于xuperchain中的密码学,可在 `密码学基础<../design_documents/crypto.html>` 了解更多
$ bin/xchain-cli account newkeys --output data/alice --crypto gm
create account using crypto type gm
create account in data/alice

## 创建合约账号
bin/xchain-cli account new --account 1111111111111111 --fee 2000
contract response:
    {
        "pm": {
            "rule": 1,
            "acceptValue": 1.0
        },
        "aksWeight": {
            "TeyyPLpp9L7QAcxHangtcHTu7HUZ6iydY": 1.0
        }
    }

The gas you cousume is: 1000
The fee you pay is: 2000
Tx id: b4c588a52e0d35a9388f0583a58c3adc0865b1fee1d5242268e66b9f3daae3c1
account name: XC1111111111111111@xuper

When executing the command bin/xchain-cli account new --account 1111111111111111 --fee 2000, the following operations and results occurred
Insert image description here

In the data/bob directory, you will see the files address, publickey, and privatekey generated.

2.2.2. Query resource balance

For ordinary accounts, you can use the following command to query the account resource balance, where the -H parameter is the address of the xchain service

# 根据账户存储的路径,查询该账户的余额。--keys为要查询的账户的地址,如 bob:--keys data/bob
$ bin/xchain-cli account balance --keys data/bob -H 127.0.0.1:37101
100000000000338000000

# 根据地址查询该账户余额
$ bin/xchain-cli account balance TeyyPLpp9L7QAcxHangtcHTu7HUZ6iydY -H 127.0.0.1:37101
100000000000401000000

# 查询合约账户余额
$ bin/xchain-cli account balance XC1111111111111111@xuper -H 127.0.0.1:37101
0

2.2.3. Transfer

The transfer operation requires the private key directory of the source account, which is similar to the directory generated in "2.1.1 Create a new account". Note here that you do not need to provide any key of the target account, only the address.

# --keys 从此地址 转给 --to地址 --amount 金额
$ bin/xchain-cli transfer --to czojZcZ6cHSiDVJ4jFoZMB1PjKnfUiuFQ --amount 10 --keys data/keys/ -H 127.0.0.1:37101
24d53ea6e61ede8dc4fe65a04fd30da17c079a359e700738f8795dfddc55ffb4

The return of the command execution is the transaction ID (txid) of the transfer operation... note:

转账操作如果不加参数 --keys,即未指定扣款账户,将会默认扣除 data/keys 下账户的资源,该账户是默认生成的,创建链时会预分配一些资源
给到该账户,具体可以参考 data/genesis/xuper.json

2.2.4. Query transaction information

You can query transaction information through the following commands, including transaction status, transaction source and target account, transaction amount, block (if it has been uploaded), etc.

# 可查询上一步生成的txid的交易信息
$ bin/xchain-cli tx query 24d53ea6e61ede8dc4fe65a04fd30da17c079a359e700738f8795dfddc55ffb4 -H 127.0.0.1:37101
{
   "txid": "24d53ea6e61ede8dc4fe65a04fd30da17c079a359e700738f8795dfddc55ffb4",
   "blockid": "e83eae0750d0f48cc2b45f25d853fb587d124552851bf6693757e0715837b377",
   "txInputs": [
    {
      "refTxid": "2650aa0c0e8088def98093a327b475fa7577fa8e266c5775435f7c022fe0f463",
      "refOffset": 0,
      "fromAddr": "TeyyPLpp9L7QAcxHangtcHTu7HUZ6iydY",
      "amount": "1000000"
    }
   ],
  ......
  "authRequireSigns": [
   {
      "publickey": "{\"Curvname\":\"P-256\",\"X\":36505150171354363400464126431978257855318414556425194490762274938603757905292,\"Y\":79656876957602994269528255245092635964473154458596947290316223079846501380076}",
      "sign": "30460221009509e35b1341284b5d1f22b48c862ecfe2856056196c5650bc203b8a4ed0d454022100f8d286c63ad8eb3bc605bc08da4ff417aaff3c0433a31039f608bb47a90b1267"
    }
   ],
  "receivedTimestamp": 1628596303271475925,
  "modifyBlock": {
    "marked": false,
    "effectiveHeight": 0,
    "effectiveTxid": ""
  }
}

Insert image description here

2.2.5. Query block information

Block-related information can be queried through blockid, including the transactions packaged in the block, the height of the chain, the ID of the predecessor/successor block, etc.

# 可查询上一步交易所在的block id信息
$ bin/xchain-cli block e83eae0750d0f48cc2b45f25d853fb587d124552851bf6693757e0715837b377 -H 127.0.0.1:37101

{
  "version": 1,
  "blockid": "e83eae0750d0f48cc2b45f25d853fb587d124552851bf6693757e0715837b377",
  "preHash": "41c74e22ccea7dcf1db6ba0d7e1eefd6cfbd7bac7659c3d8cd33d2a009201003",
  "proposer": "TeyyPLpp9L7QAcxHangtcHTu7HUZ6iydY",
  "sign": "3044021f349da2d5c238175a6e7df23262eeb122014f0a0040fc4ce109a3ab2c22b2700221009d92198061193fcd47e25c8f5c2b54e1ea2ffb4aaab675384c4d6408ab2b63de",
  "pubkey": "{\"Curvname\":\"P-256\",\"X\":36505150171354363400464126431978257855318414556425194490762274938603757905292,\"Y\":79656876957602994269528255245092635964473154458596947290316223079846501380076}",
  "merkleRoot": "d22d2423a93911e42f96370167d878f6780fea44fac6a13771c7532e1969c949",
  "height": 492,
  ......
  "txCount": 2,
  "merkleTree": [
    "4a7e42654cf79d6525f6b6d55673b57a92048ee96de950e962db99b102e048a4",
    "24d53ea6e61ede8dc4fe65a04fd30da17c079a359e700738f8795dfddc55ffb4",
    "d22d2423a93911e42f96370167d878f6780fea44fac6a13771c7532e1969c949"
  ],
  "inTrunk": true,
  "nextHash": "a541ed97789537166bec5778aad7ba0f68e52a04d1073b244ee1ea6cd38d8f63",
  "failedTxs": null,
  "curTerm": 0,
  "curBlockNum": 0,
  "justify": {}
}
6b6d55673b57a92048ee96de950e962db99b102e048a4",
    "24d53ea6e61ede8dc4fe65a04fd30da17c079a359e700738f8795dfddc55ffb4",
    "d22d2423a93911e42f96370167d878f6780fea44fac6a13771c7532e1969c949"
  ],
  "inTrunk": true,
  "nextHash": "a541ed97789537166bec5778aad7ba0f68e52a04d1073b244ee1ea6cd38d8f63",
  "failedTxs": null,
  "curTerm": 0,
  "curBlockNum": 0,
  "justify": {}
}

Guess you like

Origin blog.csdn.net/weixin_63706760/article/details/131242277