# 部署以太坊全节点教程系列之二：运行测试网验证节点

By [Trader Li](https://paragraph.com/@trader-li) · 2022-09-30

---

本文将演示如何通过质押以太坊，成为验证节点。

### 步骤一：加快节点同步速度

在上一篇文章（链接如下），介绍了如何运行以太坊的执行和共识节点。第一次运行时，通常节点同步要等待2-3天时间（共识链和执行层需要分别进行同步，但最慢的是共识层），这是由于共识层客户端需要从第一个区块开始重新验证和同步。

为了加快共识层的同步速度，可以选择使用checkpoint sync，即选择受信任的别的信标链最新确认区块开始同步，并假设此前的所有区块已经被验证：

[https://mirror.xyz/0x89912c3449006F0Db8a1E051f3b9fc87ea435330](https://mirror.xyz/0x89912c3449006F0Db8a1E051f3b9fc87ea435330)

添加checkpoint sync的方法也很简单，只要重新运行./prysm.sh，并添加两个额外参数，如果是goerli(prater)的话：

    --checkpoint-sync-url=https://goerli.checkpoint-sync.ethpandaops.io
    --genesis-beacon-api-url=https://goerli.checkpoint-sync.ethpandaops.io
    

上面的checkpoint sync节点来自：

[https://notes.ethereum.org/@launchpad/checkpoint-sync](https://notes.ethereum.org/@launchpad/checkpoint-sync)

更多的checkpoints，包括主网的可以选择下面的节点：

[https://eth-clients.github.io/checkpoint-sync-endpoints/#goerli](https://eth-clients.github.io/checkpoint-sync-endpoints/#goerli)

了解更多checkpoint sync的细节可以看这篇文章：

[https://docs.prylabs.network/docs/prysm-usage/checkpoint-sync](https://docs.prylabs.network/docs/prysm-usage/checkpoint-sync)

#### 如何判定共识层节点完成同步？

首先，可以通过Goerli Beacon Chain网站查看最新的slot：

[https://prater.beaconcha.in/](https://prater.beaconcha.in/)

![](https://storage.googleapis.com/papyrus_images/6eaaccd1fa6c7fd6484112b6a069aeb2f0665fd2dd4d80ed2d85b564cde9e033.png)

再去查看运行prysm的日志：

    tail -n 100 /home/master/ethereum/log/prysm.txt
    

![](https://storage.googleapis.com/papyrus_images/29e6808bfa459faf090c236b19e183a1e0e58a6bddcc4f21018d8c846976a398.png)

可以看到slot是匹配的，因此证明节点已经完成了同步。

#### 如何判定执行层节点完成同步？

#### 方法一：命令行查询

输入以下命令查询geth是否完成同步

    geth attach http://127.0.0.1:8545
    eth.syncing
    

如果返回的是false，则表示同步完成；true则表示仍在同步，同步尚未完成。

#### 方法二：手动查询日志

通常执行层同步需要几个小时时间，主网大概同步完会有600多G （通过在linux输入df -h 可以查看），通过打印geth.txt的log可以查看最新的同步到了哪个区块：

输入命令：

    tail -n 100 geth.txt
    

![](https://storage.googleapis.com/papyrus_images/ab2c2f8a65d8634ee2b866aafb161eed4f397ebfb1b95f15f6babca54332ed43.png)

number=15714797，而etherscan.io 网站上显示的最新区块为：

![](https://storage.googleapis.com/papyrus_images/724b136d1d17f82800d01f737f1a8662ad812a703bc555dce7c2b61d3842bfe5.png)

两者数字接近，就表示已经同步完成了。

### 步骤二：获得测试网的以太币

要想质押以太币成为验证节点，需要准备至少32个以太币。测试网的以太币可以前往@ethstaker的discord获得（下面的链接）：

[https://discord.io/ethstaker](https://discord.io/ethstaker)

首先，需要进行真人验证（注意，这里不是实名认证）。用户可以下载BrightID 软件并注册（图片、名字都可以是假的），然后前往discord 的 #testnet下面随便一个频道，输入 /verify 查询具体真人验证的流程。

用户需要通过参加BrightID的 zoom meeting来获得验证（下面的链接）。整个流程大概需要花费10分钟左右时间。

[https://meet.brightid.org/](https://meet.brightid.org/)

在BrightID获得验证后，返回discord，并扫描BrightID Bot提供的二维码即可绑定discord账号，之后前往 #request-goerli-eth 频道，手动输入命令：

    /request-goeth <钱包地址>
    

几乎是在瞬间机器人便会发起32个以太币的转账交易。

#### 10月初更新：discord不再支持32个以太币转账，但可以通过 discord下面的 #cheap-goerli-validator 频道进行尝试

### 步骤三：生成助记词和公私钥

用户可以用以下方法安装以太坊质押客户端Ethereum Staking CLI：

[https://github.com/ethereum/staking-deposit-cli](https://github.com/ethereum/staking-deposit-cli)

通常，用户只需要使用wget下载对应安装包，再解压即可（参考上一篇文章中安装geth的方法）。

    wget https://github.com/ethereum/staking-deposit-cli/releases/download/v2.3.0/staking_deposit-cli-76ed782-linux-amd64.tar.gz
    
    tar -xvf staking_deposit-cli-76ed782-linux-amd64.tar.gz
    
    cd staking-deposit-cli-2.3.0
    
    ./deposit new-mnemonic --num_validators=1 --mnemonic_language=english --chain=prater
    

也可以使用docker进行安装以太坊质押客户端，其中--network host . 和--net=host 是用来防止docker的虚拟网络无法连接网络的问题。

    wget https://github.com/ethereum/staking-deposit-cli/archive/refs/tags/v2.3.0.tar.gz
    
    tar -xvf v2.3.0.tar.gz
    
    cd staking-deposit-cli-2.3.0
    
    docker build -t ethereum/staking-deposit-cli --network host .
    
    docker run -it --rm --net=host -v $(pwd)/validator_keys:/app/validator_keys ethereum/staking-deposit-cli new-mnemonic --num_validators=1 --mnemonic_language=english --chain=prater
    

跟随页面进行操作，之后会生成助记词，注意这里一定要好好保存！

此外，命令还会生成 validator\_keys 文件夹，文件夹里包括：

1.  deposit\_data-_.json_ - 包含存储数据，之后要上传到Ethereum launchpad
    
2.  _keystore-m\__.json - 包含公钥和加密后的私钥
    

### 步骤四：将validator keys保存到共识层客户端和以太坊lanuchpad

首先，将validator\_keys 文件夹移动到consensus文件夹下：

     cp -r validator_keys /home/master/ethereum/consensus/
    

再将钥匙保存到共识层客户端中，方法是输入以下指令。其中，--keys-dir 是 consensus/validator\_keys 的完整路径。

    ./prysm.sh validator accounts import --keys-dir=/home/master/ethereum/consensus/validator_keys --prater
    

在跟随操作的步骤中，选择将钱包地址的路径保存在：/home/master/ethereum/consensus

如果一切顺利，会收到导入成功的消息：

> Successfully imported 1 accounts, view all of them by running `accounts list`

检查导入了的验证者节点钱包信息可以输入以下指令：

    ./prysm.sh validator accounts list --wallet-dir=/home/master/ethereum/consensus
    

之后，前往以太坊的launchpad网站质押以太币。按照上面的步骤，最终将deposit\_data-\*.json 文件上传，并绑定存有32个测试网以太坊的MetaMask，并将32个以太币进行质押。

#### 主网：

[https://launchpad.ethereum.org/en/upload-deposit-data](https://launchpad.ethereum.org/en/upload-deposit-data)

#### 测试网：

[https://goerli.launchpad.ethereum.org/en/upload-deposit-data](https://goerli.launchpad.ethereum.org/en/upload-deposit-data)

这时，网站会告诉你需要等待 16-24小时。之所以要等这么长时间，是为了确保32以太币质押被信标链最终确认，完整介绍可以查看下面的网址：

[https://kb.beaconcha.in/ethereum-2.0-depositing](https://kb.beaconcha.in/ethereum-2.0-depositing)

![](https://storage.googleapis.com/papyrus_images/f38a538c118e25fbd358eb706bb71fdcd1ed5b24ae0eba960c88c67c0108121e.png)

### 步骤五：运行验证节点并添加质押收益的钱包地址

输入以下命令运行节点，其中 是consensus文件夹的完整路径，这里假设是 /home/master/ethereum/consensus。 --wallet-password-file 字段则保存了钱包密码，这里假设密码保存在 /home/master/ethereum/consensus/wallet\_pwd.txt，使用该命令行可以避免使用tmux指令（本文末尾）。 cd /home/master/ethereum/consensus ./prysm.sh validator --wallet-dir=<YOUR\_FOLDER\_PATH> --suggested-fee-recipient=<接收质押收益的钱包地址> --wallet-password-file=/home/master/ethereum/consensus/wallet\_pwd.txt --prater 如果没有报错，可以调整至后台持续运行： 以nohup命令为例，将日志保存在log文件夹下面：： nohup ./prysm.sh validator --wallet-dir=<YOUR\_FOLDER\_PATH> --suggested-fee-recipient=<接收质押收益的钱包地址> --wallet-password-file=/home/master/ethereum/consensus/wallet\_pwd.txt --prater > /home/master/ethereum/log/validator.txt 2>&1 & 将质押获得收益的钱包地址输入prysm beacon-chain的命令中： 重新运行./prysm.sh beacon-chain 的命令行，并增加以下字段： --suggested-fee-recipient=<接收质押收益的钱包地址> 至此，用户已经已经完成了以太坊测试网的验证节点，并可以生成区块和获得奖励！ 下一篇文章，将介绍如何更好地监测节点运行状况。 以下部分可以暂时忽略： =============================================== 为了确保prysm保持运行，可以使用tmux。tmux是一个终端复用软件，用户即便关闭了窗口，也能让程序一直运行，当用户重新登录时，也能查看进程。 CentOS 系统需要首先安装： yum install tmux 之后，新开一个终端并取名为eth tmux new -s eth 前往consensus文件夹，并运行一遍之前的命令行以启动验证节点，并输入钱包地址。 如果想要关闭当前的窗口，可以输入ctrl +b，然后输入d即可。 如果想要查看所有终端的运行情况，可以新开一个窗口并输入： tmux ls 如果想返回特定终端，可以使用attach命令行 tmux attach -t eth 如果要停止运行这个终端 tmux kill-session -t session-name 完整的tmux使用手册可以查看： [http://louiszhai.github.io/2017/09/30/tmux/](http://louiszhai.github.io/2017/09/30/tmux/) ===============================================

---

*Originally published on [Trader Li](https://paragraph.com/@trader-li/egZZbX0C2lgPFlXNnRTU)*
