文章目录

前言
笔者的部署过程首先参考了油管上的Polygon CDK部署教程The ULTIMATE Guide to the Polygon CDK | Build A ZK-EVM Layer 2 Blockchain(需要科学上网),视频中使用sepolia测试网作为Layer1进行部署,不需要单独部署Layer1,而笔者的项目需要在私有的clique共识联盟链上进行部署,因此笔者在视频的基础上又通过多次实验和查看CDK源码最终整理出在私有clique共识网络上部署Polygon CDK的完整流程。
环境准备
在上一篇文章中笔者已部署好三节点的clique共识测试网,我们这里使用l1-test1
节点的HTTP RPC地址作为测试网的RPC入口地址:
http://10.20.0.100:8501
本篇中的操作均在/home/polygon
用户目录下进行:
$ pwd
/home/polygon
首先我们需要在用户目录下先将Polygon官方提供的kurtosis-cdk
部署项目clone下来:
$ git clone https://github.com/0xPolygon/kurtosis-cdk.git
clone下来的是最新的版本,我们需要切换到视频教程的版本上:
$ cd kurtosis-cdk/
$ git reset --hard 8898ab7
kurtosis-cdk
项目并不是CDK的项目代码,而是一系列的kurtosis部署脚本,kurtosis是一个开源容器编排工具,使用starlark语言(一种python方言)作为编排脚本,因此我们需要先安装kurtosis的客户端工具kurtosis-cli
,但是请注意,kurtosis-cdk
对kurtosis-cli
的版本有严格要求,8898ab7
这一版的kurtosis-cdk
只可以使用0.89.0
版本的kurtosis-cli
进行部署:
先配置kurtosis-cli
的仓库,然后更新一下apt:
$ sudo echo "deb [trusted=yes] https://apt.fury.io/kurtosis-tech/ /" | sudo tee /etc/apt/sources.list.d/kurtosis.list
$ sudo apt update -y
安装0.89.0
版的kurtosis-cli
:
$ sudo apt install kurtosis-cli=0.89.0 -y
安装完后测试一下版本,警告信息可以忽略:
$ kurtosis version
WARN[2024-12-01T09:27:36Z] You are running an old version of the Kurtosis CLI; we suggest you to update it to the latest version, '1.4.2'. You can manually upgrade the CLI tool following these instructions: https://docs.kurtosis.com/upgrade
CLI Version: 0.89.0
To see the engine version (provided it is running): kurtosis engine status
现在我们可以在kurtosis-cdk
目录下执行scripts
目录中的tool_check.sh
脚本来检查还需要安装哪些依赖工具:
$ ./scripts/tool_check.sh
Checking that you have the necessary tools to deploy the Kurtosis CDK package...
✅ kurtosis 0.89.0 is installed, meets the requirement (=0.89).
✅ docker 24.0.7 is installed, meets the requirement (>=24.7).
You might as well need the following tools to interact with the environment...
⚠️ jq is not installed. You can install jq at: https://jqlang.github.io/jq/download/
⚠️ yq is not installed. You can install yq at: https://pypi.org/project/yq/
⚠️ cast is not installed. You can install cast at: https://book.getfoundry.sh/getting-started/installation#using-foundryup
⚠️ polycli is not installed. You can install polycli at: https://github.com/maticnetwork/polygon-cli/releases
🎉 You are ready to go!
可以看到除了kurtosis和docker外还需要安装另外四个工具:jq
、yq
、cast
和polycli
,下面我们依次安装:
- 安装
jq
并检查版本
$ sudo apt install jq -y
$ jq --version
jq-1.6
- 安装
yq
,yq
需要使用pip
安装,我们先安装python
和pip
再安装yq
:
$ sudo apt install python3 -y
$ sudo apt install python3-pip -y
$ pip install yq
还需要将pip
的安装目录加入PATH
环境变量,然后检查yq
版本:
$ echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
$ source ~/.bashrc
$ yq --version
yq 3.4.3
- 安装
cast
,由于cast
是foundry工具箱的一部分(上一篇已使用过),我们直接安装foundry即可:
$ curl -L -proxy http://10.20.0.1:10809 https://foundry.paradigm.xyz | bash
先更新下环境变量,然后执行foundryup
命令,该命令会自动下载工具箱中的其他程序(如连接失败请在foundryup
命令前添加HTTP代理设置:HTTP_PROXY=10.20.0.1:10809 HTTPS_PROXY=10.20.0.1:10809
)
$ source ~/.bashrc
$ foundryup
如显示以下日志说明安装成功:
foundryup: installed - forge 0.2.0 (7a23a5c 2024-12-01T00:29:15.606542954Z)
foundryup: installed - cast 0.2.0 (7a23a5c 2024-12-01T00:29:15.562664824Z)
foundryup: installed - anvil 0.2.0 (7a23a5c 2024-12-01T00:29:15.516286677Z)
foundryup: installed - chisel 0.2.0 (7a23a5c 2024-12-01T00:29:15.567586053Z)
foundryup: done!
- 安装
polycli
,在/home/polygon
目录下下载polycli v0.1.64
(如下载失败请在curl
命令中添加代理设置--proxy http://10.20.0.1:10809
),解压并设置PATH
变量:
$ cd ..
$