# 全节点的网络身份

全节点将自动以随机生成的网络身份启动。这适用于常规的全节点。然而：

* 您可能希望将您的全节点添加到特定上游 全节点的允许列表（即 Aptos 网络中的另一个 全节点 参与者），因为
  * 您可能需要在此特定上游 全节点 上的 全节点 的特定权限，或者
  * 这个上游 全节点只允许已知身份连接到它，或者
  * 您可能希望宣传您的 全节点 以供其他 Aptos 全节点 连接（以帮助支持 Aptos 网络）。

在这种情况下，如果您使用静态网络身份运行 全节点，而不是每次启动 全节点 时都会不断变化的随机生成的网络身份，这会有所帮助。

### 本指南将向您展示如何：

* 为您的 全节点 创建一个静态网络身份。
* 启动具有静态网络标识的节点。
* 允许其他 全节点连接到您的 全节点

### 在您继续之前

在继续之前，请确保您已经知道如何启动本地 全节点。有关详细文档，请参阅[运行全节点](/aptos-kai-fa-zhe-wen-dang/gai-nian/quan-jie-dian.md)。

Docker 仅在 LINUX 上支持

目前仅 Linux x86-64 平台支持 Docker 容器。如果您在 macOS 或 Windows 平台上，请使用 Aptos-core 源方法。

### **为全节点创建静态身份**

为您的全节点创建一个静态身份：

1. 您首先为您的全节点创建一个私钥、公钥对。
2. 接下来，您从公钥中派生出 `peer_id`
3. 最后，您使用 `fullnode.yaml` 中的`peer_id`为您的全节点创建静态网络身份。

### 请按照以下详细步骤操作：

#### 1. 准备

**使用 Aptos-core 源代码**

拷贝 [aptos-labs/aptos-core](https://github.com/aptos-labs/aptos-core) 存储库。例如：

```
$ git clone <https://github.com/aptos-labs/aptos-core.git>
$ cd aptos-core
$ ./scripts/dev_setup.sh
$ source ~/.cargo/env
```

**使用Docker**

或者，如果您使用的是 Linux x86-64 平台，则可以使用 Aptos Docker 映像。

`cd`进入本地公共全节点的目录并使用最新工具启动 Docker 容器，例如

```
$ cd ~/my-full-node
$ docker run -it aptoslabs/tools:devnet /bin/bash
```

#### 2. 生成私钥

**使用 Aptos-core 源代码**

运行  [Aptos CLI](https://github.com/aptos-labs/aptos-core/blob/main/crates/aptos/README.md) `aptos` s 以生成十六进制编码的静态 x25519 私钥。这将是您的网络身份的私钥\*\*。\*\*

注意

以下命令还将创建一个相应的 `private-key.txt.pub`文件，其中包含公共身份密钥。

```
aptos key generate --key-type x25519 --output-file /path/to/private-key.txt
```

示例 `private-key.txt` 和相关的 `private-key.txt.pub` 文件如下所示：

```
$ cat ~/private-key.txt
C83110913CBE4583F820FABEB7514293624E46862FAE1FD339B923F0CACC647D%

$ cat ~/private-key.txt.pub
B881EA2C174D8211C123E5A91D86227DB116A44BB345A6E66874F83D8993F813%
```

**使用Docker**

从`aptoslabs/tools`  Docker 容器内运行此步骤。打开一个新终端并 `cd` 进入您为全节点启动 Docker 容器的目录。确保提供要存储私钥 TXT 文件的完整路径，运行以下命令：

```
aptos key generate \\
    --key-type x25519 \\
    --output-file /path/to/private-key.txt
```

#### 3. 检索对等身份

**使用 Aptos-core 源代码**

```
aptos key extract-peer  --private-key-file private-key.txt  \\
    --output-file peer-info.yaml
```

**使用Docker**

从 `aptoslabs/tools`Docker 容器内部：

```
$ aptos key extract-peer \\
    --private-key-file /path/to/private-key.txt \\
    --output-file /path/to/peer-info.yaml
```

这将创建一个 YAML 文件，其中您的 `peer_id`与您提供的 `private-key.txt` 相对应。

示例输出 `peer-info.yaml`：

```
---
B881EA2C174D8211C123E5A91D86227DB116A44BB345A6E66874F83D8993F813:
  addresses: []
  keys:
    - "0xB881EA2C174D8211C123E5A91D86227DB116A44BB345A6E66874F83D8993F813"
role: Upstream
```

在此示例中，`B881EA2C174D8211C123E5A91D86227DB116A44BB345A6E66874F83D8993F813`  是 `peer_id`。在您的 `fullnode.yaml`  的`peer_id` 字段中使用它来为您的全节点创建一个静态身份。

### **以静态网络身份启动节点**

生成公钥后，您可以使用配置文件`fullnode.yaml`的 `peer_id` 字段中的公钥以静态网络身份启动 全节点：

```
full_node_networks:
- network_id: "public"
  discovery_method: "onchain"
  identity:
    type: "from_config"
    key: "<PRIVATE_KEY>"
    peer_id: "<PEER_ID>"
```

在我们的示例中，您将指定上面生成的`peer_id`来代替 `<PEER_ID>`：

```
full_node_networks:
- network_id: "public"
  discovery_method: "onchain"
  identity:
    type: "from_config"
    key: "C83110913CBE4583F820FABEB7514293624E46862FAE1FD339B923F0CACC647D"
    peer_id: "B881EA2C174D8211C123E5A91D86227DB116A44BB345A6E66874F83D8993F813"
```

### 允许其他全节点连接

**端口和端口设置**

有关端口设置及其使用方式的说明，请参阅[端口和端口设置](https://aptos.dev/nodes/ait/node-requirements#networking-requirements)。

使用静态身份启动 全节点 后，您可以允许其他人通过您的节点连接到 devnet。

**注意**

在以下步骤中，使用的端口号仅用于说明。您可以使用您选择的端口号。

* 确保打开端口 `6180`（或 `6182`，例如，取决于您的节点正在侦听的端口）并打开防火墙。
* 如果您使用 Docker，只需在 `docker-compose.yaml`文件的端口下添加`"6180:6180"`”或`"6182:6182"`。
* 与他人共享您的全节点 静态网络身份。然后他们可以在他们的`fullnode.yaml`文件的`seeds`键中使用它来连接到您的 全节点。
* 确保您在`addresses`中输入的端口号与您在 全节点 配置文件 `fullnode.yaml`中的端口号匹配（例如，`6180` 或 `6182`）。

在 Discord 频道 `advertise-full-nodes` 中以以下格式分享您的全节点 静态网络身份：

```
<Peer_ID>:
  addresses:
  # with DNS
  - "/dns4/<DNS_Name>/tcp/<Port_Number>/noise-ik/<Public_Key>/handshake/0"
  role: Upstream
<Peer_ID>:
  addresses:
  # with IP
  - "/ip4/<IP_Address>/tcp/<Port_Number>/noise-ik/<Public_Key>/handshake/0"
  role: Upstream
```

例如：

```
B881EA2C174D8211C123E5A91D86227DB116A44BB345A6E66874F83D8993F813:
  addresses:
  - "/dns4/pfn0.node.devnet.aptoslabs.com/tcp/6182/noise-ik/B881EA2C174D8211C123E5A91D86227DB116A44BB345A6E66874F83D8993F813/handshake/0"
  role: "Upstream"
B881EA2C174D8211C123E5A91D86227DB116A44BB345A6E66874F83D8993F813:
  addresses:
  - "/ip4/100.20.221.187/tcp/6182/noise-ik/B881EA2C174D8211C123E5A91D86227DB116A44BB345A6E66874F83D8993F813/handshake/0"
  role: "Upstream"
```

**注意**

对等 ID 与 `AccountAddress` 同义。请参阅 [NetworkAddress](https://github.com/aptos-labs/aptos-core/blob/main/documentation/specifications/network/network-address.md) 以了解`addresses`键值是如何构造的。


---

# 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://gushi10546.gitbook.io/aptos-kai-fa-zhe-wen-dang/jie-dian/fullnode-for-devnet/quan-jie-dian-de-wang-luo-shen-fen.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.
