---
# System prepended metadata

title: 如何把新节点加入到Sui的本地测试网络验证人集合中

---

# 如何把新节点加入到Sui的本地测试网络验证人集合中

## 步骤

1. 首先编译出我们需要的二进制文件：sui，sui-node等，二进制文件在`./target/debug/`目录下：
```bash
cargo build --bin sui sui-node
```
2. 创建new validator的账户keypair，包括account keypair, network keypair, worker keypair, protocol keypair等：
```bash
./sui keytool generate ed25519
./sui keytool load-keypair {key-file-generated-in-last-step}
```
3. 编辑config.yaml，初始化账户balance，并注意把`epoch_duration_ms`修改成合适的时间（默认24小时，为了测试方便这里是3分钟，因为validator candidate在下个epoch才会成为validator）：
```yaml
---
validator_config_info: ~
parameters:
  chain_start_timestamp_ms: 1684727806223
  protocol_version: 10
  allow_insertion_of_extra_objects: true
  epoch_duration_ms: 180000
  stake_subsidy_start_epoch: 0
  stake_subsidy_initial_distribution_amount: 1000000000000000
  stake_subsidy_period_length: 10
  stake_subsidy_decrease_rate: 1000
accounts:
  - address: 0fc530455ee4132b761ed82dab732990cb7af73e69cd6e719a2a5badeaed105b
    gas_amounts:
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
  - address: 1cf34ae2e006fbfa9cee6ae4703b1a6c4ef627ab22e92e226bc6975521d0d705
    gas_amounts:
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
  - address: 265254cffb43b73101579fecd21884d34336b3f23f61428a4e681bd96857ad66
    gas_amounts:
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
  - address: 3924d75ba4380a7f2ef0f1e2158eb72a1f7b2571af0cf04e994e31a38e95ef9e
    gas_amounts:
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
  - address: 4bbf7f41e39cc238f76758f5c1d139d4af363eba16fe558188a867fec4fe3258
    gas_amounts:
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
  - address: 4deb09f93afb1d6d1c0847a406d1224de7cd92f6041a5c6ba24c1db4b3e64c1f
    gas_amounts:
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
  - address: 5b8fd223087b3364d410c49f01dc4ba2b4efaae2381b36365d4bb5a498eb872c
    gas_amounts:
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
  - address: 65c577fa84aaee9e8101d0b3b5df2591d81627dfcc3ccef7dc6a2e6af67de336
    gas_amounts:
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
  - address: 6af1d467b1903e2f79a8c7bc11d51eeb8c827497b85bf8a9d27f0afe2397a189
    gas_amounts:
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
  - address: 7603f74da67d3e1d86c3d1f8baa8cdaa836bb779e5d4b96b45ee72e9f25dc0f7
    gas_amounts:
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
  - address: 7d26eb76b7f1bc860ebddc267c3ad2170ede002d70df903e0783131ae4a37a0e
    gas_amounts:
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
  - address: 8c66fda13388668dcb7bbe402c56e5819fa429f973070f094775711a4bb63b34
    gas_amounts:
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
  - address: bd0fd1261a56b8eb7aa00c9c61587bace432ad3adad35d6a230a39be0605a35a
    gas_amounts:
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
  - address: c7294a5cc946db818c4058c83c933ad6c28e73711bee21c7fa85553c90cb7244
    gas_amounts:
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
  - address: ef6e9dd8f30dea802e0474a7996e5c772c581cc1adee45afb660f15a081d1c49
    gas_amounts:
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
  - address: f7ae71f84fabc58662bd4209a8893f462c60f247095bb35b19ff659ad0081462
    gas_amounts:
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
      - 30000000000000000
```
可把上一步生成的new validator账号加入，并指定gas_amounts，validator_info为缺省状态，如果要修改本地测试网络初始状态中验证人节点的信息，需要补充此部分信息

4. 根据config.yaml生成本地测试网络的genesis state和配置文件等，相关配置文件等数据默认在~/.sui/sui-config中：
```bash=
./sui genesis --from-config {config.yaml-path}
```
5. 启动本地测试网络，测试网络的初始状态即是上一步我们生成的genesis
```bash=
./sui start
```
6. 在配置文件夹里找到validator.config.yaml并复制修改，用来启动new validator
```bash=
cd ./sui/sui-config
cp validator-config-0.yaml new-validator-config.yaml
```
在这一步主要是将各类keypair修改成new-validator的keypair，修改db-path以及各类端口等

7. 启动new validator node，如果是修改过源码的非正常node就先编译新版本sui-node，否则使用我们编译好的sui-node:
```bash=
./sui-node --config-path {new-validator-config.yaml-path}
```
8. 生成validator.info文件，并将new-validator申请成为candidate:
```bash=
./sui validator make-validator-info {name}...
./sui validator become-candidate {validator.info-path}
```
9. 如果在config.yaml我们已经指定了new-validator的gas_amounts，此时new-validator已经有足够的sui可以用来质押给自己，否则需要切换到其他账号进行质押，注意最小质押数量是30e15：
```bash=
sui client call --package 0x3 --module sui_system --function request_add_stake --args 0x5 <sui_object> <val_address>--gas-budget 10000
```
或者通过rpc来质押：
- 生成txbytes
```bash=
curl -X POST \
     -H 'Content-Type: application/json' \
     -d '{
        "jsonrpc":"2.0",
        "id":"1",
        "method":"unsafe_requestAddStake",
        "params":["0x7b989bc3ab301b424e0e7a0be6ea7753f754a6a61d26eec45a4d9b48ba76c0cf", ["0x169615758b73ad42eee64e0395dd49a6cc12b69acda649227b67b261defff135", "0x255825df3945378b02c9434d8835078f2746e29f3f09236e3cd7fa78369d8684"], "29000000000000000", "0x7b989bc3ab301b424e0e7a0be6ea7753f754a6a61d26eec45a4d9b48ba76c0cf", "0xa2dff1fba372484ccd66b4fa1881830a51ec91d1249456d54e9cd50f73fac807", "1000000000"]
        }' \
     http://localhost:9000
```
- dryrun下
```bash=
curl -X POST \
     -H 'Content-Type: application/json' \
     -d '{
        "jsonrpc":"2.0",
        "id":"1",
        "method":"sui_dryRunTransactionBlock",
        "params":["AAAFAQEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQEAAAAAAAAAAQEAFpYVdYtzrULu5k4Dld1JpswStprNpkkie2eyYd7/8TVJAQAAAAAAACC5v0qe/Ptljkfrz0zMueAC6LPfbusVnmGkYc36XD0wYAEAJVgl3zlFN4sCyUNNiDUHjydG4p8/CSNuPNf6eDadhoQCAAAAAAAAACC28z6GuXUjRNsQpYio9QVb9ke70HdtGuJnvx57ufEONwAJAQCAfKpYB2cAACB7mJvDqzAbQk4Oegvm6ndT91Smph0m7sRaTZtIunbAzwIFAAIBAQABAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMKc3VpX3N5c3RlbRpyZXF1ZXN0X2FkZF9zdGFrZV9tdWxfY29pbgAEAQAAAgAAAQMAAQQAe5ibw6swG0JODnoL5up3U/dUpqYdJu7EWk2bSLp2wM8Bot/x+6NySEzNZrT6GIGDClHskdEklFbVTpzVD3P6yAdJAQAAAAAAACDV10yzcyUYnzeNV6MqDKnUZexd51s5DITgFSeFZBbyN3uYm8OrMBtCTg56C+bqd1P3VKamHSbuxFpNm0i6dsDP6AMAAAAAAAAAypo7AAAAAAA="]
        }' \
     http://localhost:9000
```
- 命令行工具对txbytes签名
```bash=
./sui keytool sign --data {txbytes} --address {address}
```
- 加载payload，执行交易：
```bash=
curl -X POST \
     -H 'Content-Type: application/json' \
     -d '{
            "jsonrpc": "2.0",
            "id": 1,
            "method": "sui_executeTransactionBlock",
            "params": [
                "AAAFAQEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQEAAAAAAAAAAQEAFpYVdYtzrULu5k4Dld1JpswStprNpkkie2eyYd7/8TVJAQAAAAAAACC5v0qe/Ptljkfrz0zMueAC6LPfbusVnmGkYc36XD0wYAEAJVgl3zlFN4sCyUNNiDUHjydG4p8/CSNuPNf6eDadhoQCAAAAAAAAACC28z6GuXUjRNsQpYio9QVb9ke70HdtGuJnvx57ufEONwAJAQCAfKpYB2cAACB7mJvDqzAbQk4Oegvm6ndT91Smph0m7sRaTZtIunbAzwIFAAIBAQABAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMKc3VpX3N5c3RlbRpyZXF1ZXN0X2FkZF9zdGFrZV9tdWxfY29pbgAEAQAAAgAAAQMAAQQAe5ibw6swG0JODnoL5up3U/dUpqYdJu7EWk2bSLp2wM8Bot/x+6NySEzNZrT6GIGDClHskdEklFbVTpzVD3P6yAdJAQAAAAAAACDV10yzcyUYnzeNV6MqDKnUZexd51s5DITgFSeFZBbyN3uYm8OrMBtCTg56C+bqd1P3VKamHSbuxFpNm0i6dsDP6AMAAAAAAAAAypo7AAAAAAA=",
                [
                "ALBMqXWnGF2igJiKOCIOUKJ5xP3NIIhq2dgltJVCJrR2OXBfWpU1+CKi4PMfvFwIorl1A3BuHoJ8/b9xVVnx3w96auo9CzzFf9RN0AUUSV96/cbw2gLArAbbvfA63qvj/g=="
                ],
                {
                "showInput": true,
                "showRawInput": true,
                "showEffects": true,
                "showEvents": true,
                "showObjectChanges": true,
                "showBalanceChanges": true
                },
                "WaitForLocalExecution"
            ]
        }' \
     http://localhost:9000
```

10. 质押成功后，成为正式validator：
```bash=
./sui validator join-committee --gas-budget 1000000000
```