handover_doc/搭建polygon edge pos指南.md

267 lines
5.3 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 搭建polygon edge pos指南
## 0下载polygon edge pos
https://github.com/0xPolygon/polygon-edge/releases
选择对应的包然后下载解压
```
wget https://github.com/0xPolygon/polygon-edge/releases/download/v1.3.2/polygon-edge_1.3.2_linux_amd64.tar.gz
tar -xvzf polygon-edge_1.3.2_linux_amd64.tar.gz
```
## 1创建data
```\
./polygon-edge secrets init --data-dir data-dir --insecure
[WARNING: INSECURE LOCAL SECRETS - SHOULD NOT BE RUN IN PRODUCTION]
[SECRETS INIT]
Public key (address) = 0x1F1A35Eadf5a7a6ADd815Cae6e96FbC3aB815063
BLS Public key = 0x8ca47cf17f0d63daa4fb71fb74d4a981e5c4fb06e770d7b2e00ec36886c73ff8251d2ad9bacdda88c2e41fbd034d531e
Node ID = 16Uiu2HAm21iden9f68M4Lmin8KfYHQJSRWKJmN4yLJ9xH86h9Ca9
root@ca06-a13:/opt/polygon-edge# tree
.
├── config.yml
├── data-dir
│   ├── consensus
│   │   ├── validator-bls.key
│   │   └── validator.key
│   └── libp2p
│   └── libp2p.key
├── genesis.json
├── LICENSE
├── polygon-edge
└── README.md
4 directories, 8 files
root@ca06-a13:/opt/polygon-edge#
```
## 2 准备引导节点的多地址连接字符串
/ip4/<host ip>/tcp/1478/p2p/<Node ID>
1478实际上是libp2p的端口
## 3配置genesis文件
使用命令生成基本的配置文件。主要是他会添加质押合约的内容。在这基础上面更改
```
./polygon-edge genesis --consensus ibft --pos --validators <address>:<BLS Public key> --bootnode /ip4/<host ip>/tcp/1478/p2p/<Node id> --block-gas-limit 1000000000 --premine=<address>:1000000000000000000 --chain-id <your chain id> --name <your chain name>
```
## 4 配置config文件
我这里给我的config.yml文件
```
chain_config: ./genesis.json
data_dir: ./data-dir
block_gas_target: "0x0"
grpc_addr: 0.0.0.0:9632
jsonrpc_addr: 0.0.0.0:10001 //工作在10001端口上面 默认是8545
telemetry:
prometheus_addr: ""
network:
no_discover: false
libp2p_addr: 0.0.0.0:1478
nat_addr: 143.92.34.138
dns_addr: ""
max_peers: -1
max_outbound_peers: -1
max_inbound_peers: -1
seal: true
tx_pool:
price_limit: 0
max_slots: 4096
max_account_enqueued: 128
log_level: INFO
restore_file: ""
headers:
access_control_allow_origins:
- '*'
log_to: ""
json_rpc_batch_request_limit: 20
json_rpc_block_range_limit: 1000
json_log_format: false
cors_allowed_origins: []
relayer: false
num_block_confirmations: 64
concurrent_requests_debug: 32
web_socket_read_limit: 8192
metrics_interval: 8s
```
## 5 启动节点
我们现在目录底下是这样的
```
root@ca06-a13:/opt/polygon-edge# tree
.
├── config.yml
├── data-dir
│   ├── blockchain
│   │   ├── 000001.log
│   │   ├── CURRENT
│   │   ├── LOCK
│   │   ├── LOG
│   │   └── MANIFEST-000000
│   ├── consensus
│   │   ├── validator-bls.key
│   │   └── validator.key
│   ├── libp2p
│   │   └── libp2p.key
│   └── trie
│   ├── 000001.log
│   ├── CURRENT
│   ├── LOCK
│   ├── LOG
│   └── MANIFEST-000000
├── genesis.json
├── LICENSE
├── polygon-edge
└── README.md
```
因为节点需要后台运行
所以我们借助tmux这个工具来保持会话
```
tmux
sudo ./polygon-edge server --config config.yml
```
## 6测试是否启动成功
```
root@ca06-a13:/opt/polygon-edge# curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' http://143.92.34.138:10001
//你会看到
{"jsonrpc":"2.0","id":1,"result":"0x10"}
```
Note:
node的ws和http工作在同一个端口上面。使用ws//localhost:8545/ws 来访问。
可以参考命令` wscat -c ws://localhost:8545/ws`
## 搭建浏览器
因为浏览器消耗不小,所以简易使用两台服务器进行
## 简单tmux指令
### 基本用法
#### 启动tmux
```
tmux
```
#### 创建新会话
```
tmux new -s session_name
```
#### 分离和重新连接会话
- 分离当前会话/关闭tmux回到原始会话但是不关闭会话
```
Ctrl + b然后按 d
```
- 重新连接到一个会话:
```
tmux attach -t session_name
```
#### 管理窗口和窗格
- 创建新窗口:
```
Ctrl + b然后按 c
```
- 在窗口之间切换:
```
Ctrl + b然后按 n下一个窗口或 p上一个窗口
```
- 分割窗格(垂直分割):
```
Ctrl + b然后按 %
```
- 分割窗格(水平分割):
```
Ctrl + b然后按 "
```
- 在窗格之间切换:
```
 Ctrl + b然后按方向键
```
- 查看所有窗口
```
Ctrl + b然后按 w
```
#### 会话管理
- 列出所有会话:
```
tmux ls
```
- 杀死会话:
```
tmux kill-session -t session_name
```
#### 配置文件示例
下面是一个简单的`~/.tmux.conf`配置文件示例:
```
bash复制代码# 设置前缀键为Ctrl-a
set -g prefix C-a
unbind C-b
bind C-a send-prefix
# 启动时分割窗格
split-window -v
# 窗口命名
new-session -s my_session -n my_window
```