问题描述

采用最新的geth版本之后,按照之前的方法启动geth主网节点会出现如下问题:

Post-merge network, but no beacon client seen. Please launch one to follow the chain!

问题原因

The above message is emitted when Geth is run without a consensus client on a post-merge proof-of-stake network. Since Ethereum moved to proof-of-stake Geth alone is not enough to follow the chain because the consensus logic is now implemented by a separate piece of software called a consensus client. This log message is displayed when the consensus client is missing. Read more about this on our consensus clients page.

当 Geth 在合并后权益证明网络上没有共识客户端的情况下运行时,会发出上述消息。 由于以太坊转向权益证明,仅靠 Geth 不足以跟踪链,因为共识逻辑现在由称为共识客户端的单独软件实现。 缺少共识客户端时会显示此日志消息。 在我们的共识客户页面上阅读更多相关信息。

新版本geth启动

下载、安装并启动一个共识客户端。安装参考文档在这儿。

3.1 使用clef创建账户

1. 编译clef客户端

注:如果不能访问github.com需要科学上网

//下载ethertum源码git clone https://github.com/ethereum/go-ethereum.gitcd go-ethereum/cmd/clef/// 需要科学上网go build mv clef ../geth-linux

2. 生成账号

$ mkdir act$ clef initWARNING!Clef is an account management tool. It may, like any software, contain bugs.Please take care to- backup your keystore files,- verify that the keystore(s) can be opened with your password.Clef is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULARPURPOSE. See the GNU General Public License for more details.Enter 'ok' to proceed:> okThe master seed of clef will be locked with a password.Please specify a password. Do not forget this password!Password: // 生成账号$ clef newaccount --keystore [keystore path]WARNING!Clef is an account management tool. It may, like any software, contain bugs.Please take care to- backup your keystore files,- verify that the keystore(s) can be opened with your password.Clef is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULARPURPOSE. See the GNU General Public License for more details.Enter 'ok' to proceed:> ok## New account passwordPlease enter a password for the new account to be created (attempt 0 of 3)> -----------------------INFO [04-18|12:13:39.005] Your new key was generated address=0x9E7b07952Fcb2197AF96964e08579f5a2E969FeCWARN [04-18|12:13:39.005] Please backup your key file! path=/home/baas/data/ethereum/acts/UTC--2023-04-18T04-13-37.353476343Z--9e7b07952fcb2197af96964e08579f5a2e969fecWARN [04-18|12:13:39.005] Please remember your password! Generated account 0x9E7b07952Fcb2197AF96964e08579f5a2E969FeC

3. 启动clef

没搞清楚什么时候需要启动

// 连接主网clef --keystore acts --configdir clef// 连接其他网络,使用 --chainid 参数clef --keystore acts --configdir clef --chainid 11155111

更多的chainid参考网站:chainlist.org

4. 启动Consensus Client

目前支持的Consesus客户端有:

  • Lighthouse: written in Rust
  • Nimbus: written in Nim
  • Prysm: written in Go
  • Teku: written in Java
  • Lodestar: written in Typescript

共识客户端必须以正确的端口配置启动,以建立到本地 Geth 实例的 RPC 连接。 在上面的例子中,localhost:8551 被授权用于此目的。 共识客户端都有一个类似于 –http-webprovider 的命令,它将暴露的 Geth 端口作为参数。
共识客户端还需要 Geth 的 jwt-secret 路径,以便验证它们之间的 RPC 连接。 每个共识客户端都有一个类似于 –jwt-secret 的命令,它将文件路径作为参数。 这必须与提供给 Geth 的 –authrpc.jwtsecret 路径一致。
共识客户端都暴露了一个Beacon API,可用于检查Beacon客户端的状态或通过使用Curl等工具发送请求来下载区块和共识数据。 有关这方面的更多信息,请参阅每个共识客户端的文档。

下面使用Prysm启动共识客户端。
信标链节点的类型如下:

由于没有ETH,所以只能启动`beacon`普通节点。

// 下载 prysmmkdir consensuscd consensusmkdir prysm && cd prysmcurl https://raw.githubusercontent.com/prysmaticlabs/prysm/master/prysm.sh --output prysm.sh && chmod +x prysm.sh// Generate JWT Secret<!--信标节点和执行节点之间的 HTTP 连接需要使用 JWT 令牌进行身份验证。 有几种方法可以生成此 JWT 令牌:使用像这样的在线生成器。 将此值复制并粘贴到 jwt.hex 文件中。--><!--使用像 OpenSSL 这样的实用程序通过命令创建令牌:openssl rand -hex 32 |tr -d "\n" > "jwt.hex"。--><!--使用执行客户端生成 jwt.hex 文件。--><!--使用 Prysm 生成 jwt.hex 文件:--><!--Optional. This command is necessary only if you've previously configured USE_PRYSM_VERSION-->$ USE_PRYSM_VERSION=v4.0.0<!--Required.-->$ ./prysm.sh beacon-chain generate-auth-secret

beacon-chain介绍:

  • 信标链向以太坊生态系统引入了股权证明。
  • 它于 2022 年 9 月与最初的以太坊工作量证明链合并。
  • 信标链引入了现在保护以太坊的共识逻辑和块八卦协议。

5. 使用geth启动执行节点

为了连接到共识客户端,Geth 必须为客户端间 RPC 连接公开一个端口。
RPC 连接必须使用 jwtsecret 文件进行身份验证。 默认情况下创建并保存到 /geth/jwtsecret,但也可以创建并保存到自定义位置,或者可以通过将文件路径传递给 --authrpc.jwtsecret 自行生成并提供给 Geth。 Geth 和共识客户端都需要 jwtsecret 文件。
然后必须将授权应用于特定地址/端口。 这是通过将地址传递给 --authrpc.addr 并将端口号传递给 --authrpc.port 来实现的。 向 --authrpc.vhosts 提供 localhost 或通配符 * 也是安全的,这样 Geth 就会接受来自虚拟主机的传入请求,因为它仅适用于使用 jwtsecret 进行身份验证的端口。

// geth --datadir /home/baas/data/ethereum/geth-data --authrpc.addr localhost --authrpc.port 8551 --authrpc.vhosts localhost --authrpc.jwtsecret consensus/prysm/jwt.hex --http --http.api eth,net --signer=clef/clef.ipc --http // 如果不想被其他节点发现,则增加 --nodiscover 参数

6. 启动共识节点

// Run a beacon node using Prysm$ ./prysm.sh beacon-chain --execution-endpoint=http://localhost:8551 --jwt-secret=jwt.hex--suggested-fee-recipient=0x9E7b07952Fcb2197AF96964e08579f5a2E969FeCLatest Prysm version is v4.0.2.Beacon chain is up to date.Verifying binary integrity.beacon-chain-v4.0.2-linux-amd64: OKgpg: Signature made Thu 13 Apr 2023 12:01:31 PM CSTgpg:using RSA key 0AE0051D647BA3C1A917AF4072E33E4DF1A5036Egpg: Good signature from "Preston Van Loon " [unknown]gpg: aka "Preston Van Loon " [unknown]gpg: aka "Preston Van Loon " [unknown]gpg: aka "Preston Van Loon (0xf71E9C766Cdf169eDFbE2749490943C1DC6b8A55) " [unknown]gpg: WARNING: This key is not certified with a trusted signature!gpg:There is no indication that the signature belongs to the owner.Primary key fingerprint: 0AE0 051D 647B A3C1 A917AF40 72E3 3E4D F1A5 036EVerified /home/baas/data/ethereum/consensus/prysm/dist/beacon-chain-v4.0.2-linux-amd64 has been signed by Prysmatic Labs.Starting Prysm beacon-chain --execution-endpoint=http://localhost:8551 --jwt-secret=jwt.hex --suggested-fee-recipient=0x9E7b07952Fcb2197AF96964e08579f5a2E969FeCPrysmatic Labs Terms of UseBy downloading, accessing or using the Prysm implementation (“Prysm”), you (referenced hereinas “you” or the “user”) certify that you have read and agreed to the terms and conditions below.TERMS AND CONDITIONS: https://github.com/prysmaticlabs/prysm/blob/master/TERMS_OF_SERVICE.mdType "accept" to accept this terms and conditions [accept/decline]: (default: decline):// 输入 accept, 回车开始同步

7. 查看同步情况

状态监测项参考《Check node and validator status》

(1) geth node

$ geth attach http://localhost:8545> eth.syncingfalse

同步状态为 false 表示您的节点已完全同步。

(2)查看Beacon node 同步情况

$ curl http://localhost:3500/eth/v1/node/syncing | jq% Total% Received % XferdAverage Speed TimeTime TimeCurrent DloadUpload Total SpentLeftSpeed100 113100 1130 0565000 --:--:-- --:--:-- --:--:-- 56500{"data": {"head_slot": "8639","sync_distance": "6239308","is_syncing": true,"is_optimistic": false,"el_offline": true}}
  • 当看到“is_syncing”:false 时,您的信标节点已与信标链完全同步。
  • 当您看到“is_optimistic”:false 时,您的信标节点会看到您的执行节点:
      1. 尚未启动,
      1. 尚未同步通过合并块,或
      1. 与执行层区块链完全同步。
$ curl http://localhost:8080/healthz*prometheus.Service: OK*execution.Service: ERROR, retryExecutionClientConnection: processPastLogs: no contract code at given address*attestations.Service: OK*blockchain.Service: OK*sync.Service: ERROR, out of sync*rpc.Service: ERROR, syncing*p2p.Service: OK*initialsync.Service: ERROR, syncing*builder.Service: OK*gateway.Gateway: OK

processPastLogs: no contract code at given address表名当前仍然在同步账本中。

(3)查看Beacon Node 和 Geth Node连接情况

$ curl http://localhost:3500/eth/v1alpha1/node/eth1/connections{"currentAddress":"http://localhost:8551","currentConnectionError":"retryExecutionClientConnection: processPastLogs: no contract code at given address","addresses":["http://localhost:8551"],"connectionErrors":[]}

如果您看到 currentConnectionError: no contract code at given address,您的执行节点可能仍在同步。 否则,如果您没有看到任何错误,则您的信标节点已连接到您的执行节点。

所以等待几小时或者几天同步完成吧。