# 加入测试网

{% hint style="danger" %}
注意：

1. 本教程仅用于使用 Docker 方式，且为验证者节点。
2. <mark style="color:green;">欢迎加入 MoveMove 社区</mark>：<https://discord.gg/sUmS7pm2q2>
   {% endhint %}

## 一、初始化质押池

在 AIT3 中，我们将提供 UI 支持以允许所有者管理质押池，请参阅此处的详细信息，如果您已经通过 UI 完成了此操作，则可以忽略此步骤并跳转到“[运行节点](#yi-yun-hang-jie-dian)”。

{% hint style="warning" %} <mark style="color:orange;">本步骤需要等到测试币发放才能执行。(若您没有收到，请关注邮件耐心等待)</mark>
{% endhint %}

### 1.1 切换钱包网络 Testnet 并检查余额

{% hint style="danger" %} <mark style="color:red;">需要先安装 Petra 钱包插件（必须更新到 0.1.8）</mark>，并导入之前注册时使用的钱包地址。参考教程：[Petra 使用教程](/jiao-cheng/petra-qian-bao-cha-jian-an-zhuang-shi-yong.md)
{% endhint %}

<figure><img src="/files/Sk09t8c1r6mCWZEwcV55" alt=""><figcaption></figcaption></figure>

切换到测试网网络后，返回 Home 就能看到余额了。

### 1.2 参与质押

Aptos 治理页面（需切换到相应的测试网络）：<https://explorer.devnet.aptos.dev/proposals/staking>

* Staking Amount: 输入100000000000000，需要小于账户余额，并留足够的 gas。
* Operator Address: 节点名称/operator.yaml 文件中的 operator\_account\_address。

<figure><img src="/files/vGgS68wJQdxk2yq4i8Wf" alt=""><figcaption></figcaption></figure>

* Voter Address: 您的钱包地址。

填写质押的数量和操作者地址、投票者地址（您的钱包地址），并提交（点击提交按钮后，会有弹窗交易签名，点击“Approve”即可）：

<figure><img src="/files/PV2JtYfIeCywsN6j8xp0" alt=""><figcaption></figcaption></figure>

质押成功页面（可以修改和增加锁定时长）：

<figure><img src="/files/DwSRi2Mv27VpTYK3F44t" alt=""><figcaption></figcaption></figure>

### 1.3 给您的 Operator 地址发送一些 APT 测试币

{% hint style="danger" %}

* 这步是必须的，后面需要检查账户余额，否则会返回错误！！
* Operator 地址是上一步中的 Operator Address。
  {% endhint %}

<figure><img src="/files/7MMg9e6sgzGrfi4t6sl0" alt=""><figcaption></figcaption></figure>

## 二 、运行节点

### 备份所有文件

防止发生异常时无法恢复，请先备份如下文件，文件目录如下：

```
docker-compose.yaml
layout.yaml
您的节点名称目录
keys 目录
```

### 进入节点操作目录

本教程使用的目录为 `~/aptos-node/testnet3`，若您使用的其他教程，请自行修改命令。

```shell
cd ~/aptos-node/testnet3

```

### 关闭节点并删除数据卷

```shell
sudo docker-compose down --volumes

```

### 下载 genesis、waypoint 和 测试网 编排文件

<pre class="language-bash"><code class="lang-bash"><strong>sudo wget -O genesis.blob https://github.com/aptos-labs/aptos-genesis-waypoint/raw/main/testnet/genesis.blob
</strong>sudo wget -O waypoint.txt https://raw.githubusercontent.com/aptos-labs/aptos-genesis-waypoint/main/testnet/waypoint.txt
sudo wget -O docker-compose.yaml https://raw.githubusercontent.com/jiangydev/aptos-node/main/testnet/AT/docker-compose.yaml

</code></pre>

### 修改 validator-identity.yaml 中的 account\_address

文件路径：`keys/validator-identity.yaml`

只需要修改 account\_address，更换成您的钱包地址：

<figure><img src="/files/lz10RzFYJkdKxSkQ5FKB" alt=""><figcaption></figcaption></figure>

### 启动节点（Run node）

```bash
sudo docker-compose pull
sudo docker-compose up -d

```

{% hint style="warning" %}
如果您的节点端口不通，请关闭服务器防火墙，并在云服务器提供商的安全策略中放行如下端口：

验证者节点（本教程只提供验证者节点搭建）：

* 6180：validator 的 peer 通信端口；
* 6181

已关闭 80 API 端口及 9101 指标端口的外网访问，本地可访问。
{% endhint %}

### 检查节点

```shell
# 查询 chain id，应该返回 47
sudo curl 127.0.0.1:80/v1
```

## 三、加入验证者集合

### 初始化 Aptos CLI

您的操作者私钥 `account_private_key` 可以从 `keys/private-keys.yaml` 文件中获得。

```shell
# 这个命令中的私钥需要替换！！
sudo docker run --rm \
  -v $(pwd):/data/aptos-cli \
  jiangydev/aptos-cli:v0.3.4 \
  sh -c "cd /data/aptos-cli && rm -rf .aptos && aptos init --profile ait3-operator --private-key 您的私钥 --rest-url https://testnet.aptoslabs.com --skip-faucet"
```

<figure><img src="/files/3PNWsKnuu2MUU5jEQakP" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/F0YLh0auRZPlrrRMLxD6" alt=""><figcaption></figcaption></figure>

### 通过 Aptos CLI 检查余额

{% hint style="warning" %}
如果这一步执行返回异常：API error: API error Error(AccountNotFound): Account not found by Address，请参考 1.3 给您的 Operator 地址发送一些 APT 测试币。
{% endhint %}

```shell
sudo docker run --rm \
  -v $(pwd):/data/aptos-cli \
  jiangydev/aptos-cli:v0.3.4 \
  sh -c "cd /data/aptos-cli && aptos account list --profile ait3-operator"

```

<figure><img src="/files/Q0KBuVxI9yfzv8zo4VNO" alt=""><figcaption></figcaption></figure>

### 更新链上Validator网络地址

* 注意修改命令中的验证者配置文件为“您的节点名称/operator.yaml”，这里我使用的 MoveMove/operator.yaml。
* 注意修改所有者地址：您的钱包地址！！！

```shell
# 需要修改验证者配置文件：您的节点名称/operator.yaml
sudo docker run --rm \
  -v $(pwd):/data/aptos-cli \
  jiangydev/aptos-cli:v0.3.5 \
  sh -c "cd /data/aptos-cli && aptos node update-validator-network-addresses --pool-address 您的钱包地址 --operator-config-file MoveMove/operator.yaml --profile ait3-operator --assume-yes"
```

<figure><img src="/files/sRyo2ekmIBwmYC6mK2nx" alt=""><figcaption></figcaption></figure>

### 更新链上验证者共识 key

```bash
# 需要修改验证者配置文件：您的节点名称/operator.yaml
sudo docker run --rm \
  -v $(pwd):/data/aptos-cli \
  jiangydev/aptos-cli:v0.3.5 \
  sh -c "cd /data/aptos-cli && aptos node update-consensus-key --pool-address 您的钱包地址 --operator-config-file MoveMove/operator.yaml --profile ait3-operator --assume-yes"
```

<figure><img src="/files/r7d37PuFW8nb3AXHqW1x" alt=""><figcaption></figcaption></figure>

### 加入验证者集合

```bash
sudo docker run --rm \
  -v $(pwd):/data/aptos-cli \
  jiangydev/aptos-cli:v0.3.5 \
  sh -c "cd /data/aptos-cli && aptos node join-validator-set --pool-address 您的钱包地址 --profile ait3-operator --max-gas 5000 --assume-yes"

```

<figure><img src="/files/PdqpxOzygAcCcO1dw1Fe" alt=""><figcaption></figcaption></figure>

### 检查验证者集合

#### 方式一

<https://explorer.devnet.aptos.dev/account/><你的地址>?network=testnet

可以看到 Stake 相关的资源和交易。

#### 方式二

```bash
# 需要先安装 jq，如果已安装，可跳过
sudo apt install -y jq
```

在安装 jq 后，可以查询**加入中的验证者**：

```bash

sudo docker run --rm \
  -v $(pwd):/data/aptos-cli \
  jiangydev/aptos-cli:v0.3.4 \
  sh -c "cd /data/aptos-cli && aptos node show-validator-set --profile ait3-operator" \
  | jq -r '.Result.pending_active' \
  | grep '您的钱包地址'

```

查询**已加入的验证者**：

```bash

sudo docker run --rm \
  -v $(pwd):/data/aptos-cli \
  jiangydev/aptos-cli:v0.3.4 \
  sh -c "cd /data/aptos-cli && aptos node show-validator-set --profile ait3-operator" \
  | jq -r '.Result.active_validators' \
  | grep '您的钱包地址'

```

## 四、验证节点连接

一旦您的验证器节点加入验证器集，您可以按照以下步骤验证正确性：

### 验证 Peer

验证您的节点是否正在连接到测试网上的其他对等点，`127.0.0.1`（如果部署在云上，请替换为您的验证器 IP/DNS）

```shell
curl 127.0.0.1:9101/metrics 2> /dev/null | grep "aptos_connections{.*\"Validator\".*}"

```

该命令将输出验证器节点的入站和出站连接数。

只要其中一个指标大于零，您的节点就会连接到测试网上的至少一个对等节点。

### 是否连接到 AptosLabs 节点

您还可以检查您的节点是否连接到 AptosLabs 的节点，替换`<Aptos Peer ID>`为 Aptos 团队共享的 peer ID。

> 获得官方信息：<https://github.com/aptos-labs/aptos-ait3>

```shell
curl 127.0.0.1:9101/metrics 2> /dev/null \
  | grep "aptos_network_peer_connected{.*remote_peer_id=\"f326fd30\".*}"

```

### 检查共识

一旦您的节点状态同步到最新版本，您还可以检查共识是否正在取得进展，以及您的节点是否正在提议

```shell
curl 127.0.0.1:9101/metrics 2> /dev/null \
  | grep "aptos_consensus_current_round"

curl 127.0.0.1:9101/metrics 2> /dev/null \
  | grep "aptos_consensus_proposals_count"

```

您应该期望看到这个数字不断增加。

<mark style="color:green;">欢迎加入 MoveMove 社区</mark>：<https://discord.gg/sUmS7pm2q2>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.aptos.movemove.org/jiao-cheng/ce-shi-wang-testnet/she-qu-jiao-cheng/jia-ru-ce-shi-wang.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
