zk-genesis-tool 中文文档教程
ZK Genesis 工具
目录
先决条件
- < a href="https://nodejs.org/en/download/">Nodejs
使用
注意:在可能的情况下,Zk Genesis Tool 将根据所选的共识算法创建密钥以及 HLF Besu 和 Geth 的 genesis 文件,您可以选择您想要使用的一个。目前只有QBFT具有跨客户端兼容性。
密钥生成
使用以下内容创建工件:
npx zk-genesis-tool
____ __ __
/_ / / //_/
/ /_/ ,<
/___/_/|_| _
/ ___/__ ___ ___ ___ (_)__
/ (_ / -_) _ \/ -_|_-</ (_-<
\___/\__/_//_/\__/___/_/___/
/_ __/__ ___ / /
/ / / _ \/ _ \/ /
/_/ \___/\___/_/
Welcome to the ZK Genesis Tool. This tool can be used
to rapidly generate genesis, account keys, and configs for Besu and Geth.
To get started, be sure that you have read Besu and Geth documentation regarding
genesis config options, then answer the following questions.
Which consensus algorithm will you use? Default: QBFT
1. IBFT1
2. IBFT2
3. QBFT
4. Clique
5. RAFT
Set your chainID value: (integer) Default: 1337
Set your blockperiodseconds value: (integer) Default: 5
(GoQ only) Set your emptyblockperiodseconds value: (integer) Default: 60
Set your requestTimeoutSeconds value: (integer) Default: 10
Set your epoch length value: (integer) Default: 30000
Set your difficulty: (integer) Default: 1
Set your gas limit value: (string) Default: 0xFFFF
Set your coinbase address for rewards: (string) Default: 0x0000000000000000000000000000000000000000
Choose number of validator node keys to generate: (integer) Default: 4
Choose number of member node keys to generate: (integer) Default: 1
Choose number of bootnode node keys to generate: (integer) Default: 2
Set your account password: (empty for none)
这会提示您选择共识算法变体以及创世文件的详细信息。默认情况下, 工件文件存储在 ./output/
中,其中 TIMESTAMP 是用户友好字符串中的时间:
或者,您可以使用 cli 选项并跳过提示如上所述:
npx zk-genesis-tool --help
Options:
--help Show help [boolean]
--version Show version number [boolean]
--consensus Consensus algorithm to use
[string] [required] [choices: "ibft", "ibft2", "qbft", "clique", "raft"]
[default: "qbft"]
--chainID ChainID for blockchain
[number] [required] [default: 1337]
--blockperiod Number of seconds per block
[number] [required] [default: 5]
--requestTimeout Minimum request timeout for each round
[number] [default: 10]
--emptyBlockPeriod Reduce number (seconds) of blocks produced when there
are no transactions [number] [default: 60]
--epochLength Number of blocks after which votes reset
[number] [required] [default: 30000]
--difficulty Difficulty of network[number] [required] [default: 1]
--gasLimit Block gas limit
[string] [required] [default: "0xFFFF"]
--coinbase Address to pay mining rewards to
[string] [default: "0x0000000000000000000000000000000000000000"]
--validators Number of validator node keys to generate
[number] [required] [default: 4]
--members Number of member node keys to generate
[number] [required] [default: 1]
--bootnodes Number of bootnode node keys to generate
[number] [required] [default: 2]
--accountPassword Password for keys [string] [default: ""]
--outputPath Output path relative to current directory
[string] [default: "./output"]
--zkDevAccounts Include ZK test accounts
[boolean] [required] [default: false]
使用 4 个验证器、2 个引导节点和 2 个成员为 QBFT(默认)生成密钥:
npx ZK-genesis-tool --consensus QBFT
使用 QBFT 为 HLF Besu 生成配置
npx ZK-genesis-tool --consensus qbft --chainID 400 --blockperiod 5 --requestTimeout 10 --epochLength 30000 --difficulty 1 --gasLimit '0xFFFFFF' --coinbase '0x0000000000000000000000000000000000000000' --validators 4 --members 1 --bootnodes 0
为 Geth 生成配置
npx ZK-genesis-tool --consensus ibft --chainID 400 --blockperiod 5 --requestTimeout 10 --epochLength 30000 --difficulty 1 --gasLimit '0xFFFFFF' --coinbase '0x0000000000000000000000000000000000000000' --validators 4 --members 1 --bootnodes 0
使用 IBFT Eth 帐户和 Tessera 密码
Eth 帐户
对于每个节点(bootnode/validator/member)都会生成一个帐户(各自目录中的文件以account*
开头)来执行交易并预填充大量余额。如果您想在网络启动之前从创世中删除或编辑某些帐户,您可以在各自的目录下找到 Besu 和 Geth 的创世(besu/genesis.json
或Geth/genesis.json)。
如果标志 zkDevAccounts
设置为 true
,它将包含 ZK -dev-quickstart 测试帐户。 在投入生产时删除这些帐户非常重要!
如果未指定该标志,则它将默认为 false
并假设:起源将用于生产。仅当您想要测试/开发中的帐户时,才应指定该标志。
Tessera 密码和配置
如果您选择提供 tesseraPassword 来加密 tessera 私钥,则需要在文件中传递包含密码的 passwordFile
字段。您还需要将 privateKeyPath
和 publicKeyPath
更新为存储密钥的路径。请参阅此处了解更多信息。
在实例上使用密钥和创世文件
生成后,输出应类似于以下文件结构。
├── validator0
│ └── nodekey # the node private key
│ └── nodekey.pub # the node's public key which is used in the enode
│ └── address # the node's address which is used to vote the validator in/out
│ └── accountAddress # Geth only - the accountAddress
│ └── accountKeystore # Geth only - the account's v3 keystore
│ └── accountPassword # Geth only - the account's password (you would have supplied this)
│ └── accountPrivateKey # Geth only - the account's private key
│ └── ...
├── validatorN
│ └── nodekey # the node private key
│ └── nodekey.pub # the node's public key which is used in the enode
│ └── ...
|
├── bootnodeN
│ └── nodekey # the node private key
│ └── nodekey.pub # the node's public key which is used in the enode
│ └── ...
|
├── memberN
│ └── nodekey # the node private key
│ └── nodekey.pub # the node's public key which is used in the enode
│ └── ...
|
└── besu
│ └── static-nodes.json # a list of static nodes to make peering faster
│ └── genesis.json # this genesis file for any HLF Besu nodes
│ └── permissioned-nodes.json # local permissions for any HLF Besu node
│
└── Geth
│ └── static-nodes.json # a list of static nodes to make peering faster
│ └── genesis.json # this genesis file for any Geth nodes
│ └── permissioned-nodes.json # local permissions for any Geth node
│ └── disallowed-nodes.json # disallowed nodes for any Geth node ie this new nodes will not connect to any nodes on this list
│
└── userData.json # this answers provided in a single map
└── README.md # this file
请记住执行以下操作:
- 更新权限文件和静态节点文件中的
。请注意,所选端口是默认端口,如果使用备用端口,您可能需要检查防火墙规则 - 如上所述,更新permissions.json文件
- 更新每个Besu节点配置中的
。托姆尔
ZK Genesis Tool
Table of Contents
Prerequisites
Usage
NOTE: Where possible, based on the consensus algorithm selected, the Zk Genesis Tool will create keys and genesis files for both HLF Besu and Geth and you can pick the one you'd like to use. At present only QBFT has cross client compatibility.
Generation of Keys
Create the artifacts with:
npx zk-genesis-tool
____ __ __
/_ / / //_/
/ /_/ ,<
/___/_/|_| _
/ ___/__ ___ ___ ___ (_)__
/ (_ / -_) _ \/ -_|_-</ (_-<
\___/\__/_//_/\__/___/_/___/
/_ __/__ ___ / /
/ / / _ \/ _ \/ /
/_/ \___/\___/_/
Welcome to the ZK Genesis Tool. This tool can be used
to rapidly generate genesis, account keys, and configs for Besu and Geth.
To get started, be sure that you have read Besu and Geth documentation regarding
genesis config options, then answer the following questions.
Which consensus algorithm will you use? Default: QBFT
1. IBFT1
2. IBFT2
3. QBFT
4. Clique
5. RAFT
Set your chainID value: (integer) Default: 1337
Set your blockperiodseconds value: (integer) Default: 5
(GoQ only) Set your emptyblockperiodseconds value: (integer) Default: 60
Set your requestTimeoutSeconds value: (integer) Default: 10
Set your epoch length value: (integer) Default: 30000
Set your difficulty: (integer) Default: 1
Set your gas limit value: (string) Default: 0xFFFF
Set your coinbase address for rewards: (string) Default: 0x0000000000000000000000000000000000000000
Choose number of validator node keys to generate: (integer) Default: 4
Choose number of member node keys to generate: (integer) Default: 1
Choose number of bootnode node keys to generate: (integer) Default: 2
Set your account password: (empty for none)
This prompts you to pick a consensus algorithm variant, and specifics for your genesis file. By default, artifact files are stored at ./output/<TIMESTAMP>
, where TIMESTAMP is the time in a user friendly string:
Alternatively, you can use cli options and skip the prompt above like so:
npx zk-genesis-tool --help
Options:
--help Show help [boolean]
--version Show version number [boolean]
--consensus Consensus algorithm to use
[string] [required] [choices: "ibft", "ibft2", "qbft", "clique", "raft"]
[default: "qbft"]
--chainID ChainID for blockchain
[number] [required] [default: 1337]
--blockperiod Number of seconds per block
[number] [required] [default: 5]
--requestTimeout Minimum request timeout for each round
[number] [default: 10]
--emptyBlockPeriod Reduce number (seconds) of blocks produced when there
are no transactions [number] [default: 60]
--epochLength Number of blocks after which votes reset
[number] [required] [default: 30000]
--difficulty Difficulty of network[number] [required] [default: 1]
--gasLimit Block gas limit
[string] [required] [default: "0xFFFF"]
--coinbase Address to pay mining rewards to
[string] [default: "0x0000000000000000000000000000000000000000"]
--validators Number of validator node keys to generate
[number] [required] [default: 4]
--members Number of member node keys to generate
[number] [required] [default: 1]
--bootnodes Number of bootnode node keys to generate
[number] [required] [default: 2]
--accountPassword Password for keys [string] [default: ""]
--outputPath Output path relative to current directory
[string] [default: "./output"]
--zkDevAccounts Include ZK test accounts
[boolean] [required] [default: false]
To generate keys for QBFT (default) with 4 validators, 2 bootnodes and 2 members:
npx ZK-genesis-tool --consensus QBFT
To generate config for HLF Besu using QBFT
npx ZK-genesis-tool --consensus qbft --chainID 400 --blockperiod 5 --requestTimeout 10 --epochLength 30000 --difficulty 1 --gasLimit '0xFFFFFF' --coinbase '0x0000000000000000000000000000000000000000' --validators 4 --members 1 --bootnodes 0
To generate config for Geth using IBFT
npx ZK-genesis-tool --consensus ibft --chainID 400 --blockperiod 5 --requestTimeout 10 --epochLength 30000 --difficulty 1 --gasLimit '0xFFFFFF' --coinbase '0x0000000000000000000000000000000000000000' --validators 4 --members 1 --bootnodes 0
Eth Accounts and Tessera Passwords
Eth Accounts
For each node (bootnode/validator/member) an account is generated (files in their respective directories start with account*
) to perform transactions and prefilled with a large balance. If you would like to remove or edit certain accounts from the genesis before the network has been spun up, you can find the genesis for Besu and Geth under each of their respective directories (besu/genesis.json
or Geth/genesis.json
).
If the flag zkDevAccounts
is set to true
, it will include the ZK-dev-quickstart test accounts. It is important to remove these accounts when going into production!
If the flag is not specified, then it will default to false
with the assumption that the genesis is to be used in production. You should specify the flag only if you would like the accounts in testing/dev.
Tessera Passwords and Configuration
If you opt to provide a tesseraPassword to encrypt the tessera private keys, you will need to pass a passwordFile
field with the password in a file. You will also need to update the privateKeyPath
and publicKeyPath
to the paths where you store your keys. See more here.
Using the keys and genesis files on instances
Once generated, the output should resemble the file structure below.
├── validator0
│ └── nodekey # the node private key
│ └── nodekey.pub # the node's public key which is used in the enode
│ └── address # the node's address which is used to vote the validator in/out
│ └── accountAddress # Geth only - the accountAddress
│ └── accountKeystore # Geth only - the account's v3 keystore
│ └── accountPassword # Geth only - the account's password (you would have supplied this)
│ └── accountPrivateKey # Geth only - the account's private key
│ └── ...
├── validatorN
│ └── nodekey # the node private key
│ └── nodekey.pub # the node's public key which is used in the enode
│ └── ...
|
├── bootnodeN
│ └── nodekey # the node private key
│ └── nodekey.pub # the node's public key which is used in the enode
│ └── ...
|
├── memberN
│ └── nodekey # the node private key
│ └── nodekey.pub # the node's public key which is used in the enode
│ └── ...
|
└── besu
│ └── static-nodes.json # a list of static nodes to make peering faster
│ └── genesis.json # this genesis file for any HLF Besu nodes
│ └── permissioned-nodes.json # local permissions for any HLF Besu node
│
└── Geth
│ └── static-nodes.json # a list of static nodes to make peering faster
│ └── genesis.json # this genesis file for any Geth nodes
│ └── permissioned-nodes.json # local permissions for any Geth node
│ └── disallowed-nodes.json # disallowed nodes for any Geth node ie this new nodes will not connect to any nodes on this list
│
└── userData.json # this answers provided in a single map
└── README.md # this file
Please remember to do the following:
- Update the
in both the permissions file and the static nodes files. Please note the selected ports are default and you may need to check firewall rules if using alternate ports - As above, update the permissions.json files
- Update
in every Besu nodes' config.toml