加入网络
本指南将引导您完成在本地设置独立网络的过程,以及在主网或测试网上运行节点的步骤。 您还可以在各自的标签中找到每个网络的硬件要求。
要轻松设置本地节点,请下载并运行 setup.sh
脚本。此脚本将初始化您的本地 Injective 网络。
wget https://raw.githubusercontent.com/InjectiveLabs/injective-chain-releases/master/scripts/setup.sh
chmod +x ./setup.sh # Make the script executable
./setup.sh
运行以下命令启动节点:
injectived start # Blocks should start coming in after running this
为了更详细地解释该脚本的功能,并提供对设置过程的更精细控制,请继续阅读下文。
I初始化链
在运行 Injective 节点之前,我们需要初始化链,并生成节点的创世文件:
# The <moniker> argument is the custom username of your node. It should be human-readable.
injectived init <moniker> --chain-id=injective-1
上述命令将创建节点运行所需的所有配置文件,以及默认的创世文件(genesis file),该文件定义了网络的初始状态。所有这些配置文件默认存储在 ~/.injectived
目录中,但您可以通过 --home
标志指定不同的位置。
请注意,如果选择使用 ~/.injectived
以外的目录,则每次运行 injectived
命令时,都必须使用 --home
标志指定该目录的位置。如果您已有创世文件,可以使用 --overwrite
或 -o
标志进行覆盖。
~/.injectived
目录的结构如下:
. # ~/.injectived
|- data # Contains the databases used by the node.
|- config/
|- app.toml # Application-related configuration file.
|- config.toml # Tendermint-related configuration file.
|- genesis.json # The genesis file.
|- node_key.json # Private key to use for node authentication in the p2p protocol.
|- priv_validator_key.json # Private key to use as a validator in the consensus protocol.
修改 genesis.json
文件
genesis.json
文件此时,需要修改 genesis.json
文件:
将 staking bond_denom、crisis denom、gov denom 和 mint denom 的值更改为
"inj"
,因为 INJ 是 Injective 的原生代币。
可以使用以下命令轻松完成此修改:
cat $HOME/.injectived/config/genesis.json | jq '.app_state["staking"]["params"]["bond_denom"]="inj"' > $HOME/.injectived/config/tmp_genesis.json && mv $HOME/.injectived/config/tmp_genesis.json $HOME/.injectived/config/genesis.json
cat $HOME/.injectived/config/genesis.json | jq '.app_state["crisis"]["constant_fee"]["denom"]="inj"' > $HOME/.injectived/config/tmp_genesis.json && mv $HOME/.injectived/config/tmp_genesis.json $HOME/.injectived/config/genesis.json
cat $HOME/.injectived/config/genesis.json | jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="inj"' > $HOME/.injectived/config/tmp_genesis.json && mv $HOME/.injectived/config/tmp_genesis.json $HOME/.injectived/config/genesis.json
cat $HOME/.injectived/config/genesis.json | jq '.app_state["mint"]["params"]["mint_denom"]="inj"' > $HOME/.injectived/config/tmp_genesis.json && mv $HOME/.injectived/config/tmp_genesis.json $HOME/.injectived/config/genesis.json
为验证人账户创建密钥
在启动链之前,您需要至少创建一个账户来填充状态。首先,在密钥存储(keyring)中创建一个名为 my_validator
的新账户,并使用 test
作为密钥存储后端(您可以选择其他名称或后端):
injectived keys add my_validator --keyring-backend=test
# Put the generated address in a variable for later use.
MY_VALIDATOR_ADDRESS=$(injectived keys show my_validator -a --keyring-backend=test)
现在,您已经创建了一个本地账户,接下来需要在链的创世文件中为其分配一定数量的 INJ 代币。这样做可以确保链在启动时就识别该账户的存在,并初始化其余额:
injectived add-genesis-account $MY_VALIDATOR_ADDRESS 100000000000000000000000000inj --chain-id=injective-1
$MY_VALIDATOR_ADDRESS
是一个变量,用于保存 my_validator 密钥在密钥存储中的地址。在 Injective 中,代币采用 {amount}{denom}
格式:amount
是一个精确到 18 位的小数数字,denom
是代币的唯一标识符及其面额(例如:inj)。在这里,我们分配 INJ 代币,因为 INJ 是 Injective 中用于质押的代币标识符。
将验证人添加到链中
现在,您的账户已经有了一些代币,接下来需要将一个验证人添加到链中。验证人是参与共识过程的特殊全节点,负责向链中添加新区块。任何账户都可以声明其成为验证人操作员的意图,但只有那些获得足够委托的账户才能进入活动集(active set)。
在本教程中,您将把本地节点(通过上述 init
命令创建)作为链的验证人添加到链中。验证人可以在链首次启动之前,通过创世文件中包含的特殊交易(称为 gentx
)进行声明。
# Create a gentx.
injectived gentx my_validator 1000000000000000000000inj --chain-id=injective-1 --keyring-backend=test
# Add the gentx to the genesis file.
injectived collect-gentxs
gentx
执行了三件事:
注册您创建的验证人账户作为验证人操作员账户(即控制验证人的账户)。
自我委托(self-delegates)所提供数量的质押代币。
将操作员账户与 Tendermint 节点的公钥关联,该公钥将用于签署区块。如果未提供
--pubkey
标志,则默认为通过injectived init
命令创建的本地节点公钥。
欲了解有关 gentx
的更多信息,请使用以下命令:
injectived gentx --help
使用 app.toml
和 config.toml
配置节点
app.toml
和 config.toml
配置节点在 ~/.injectived/config
目录下,自动生成了两个配置文件:
config.toml:用于配置 Tendermint(可以在 Tendermint 的文档中了解更多信息),
app.toml:由 Cosmos SDK(Injective 是基于 Cosmos SDK 构建的)生成,用于配置状态修剪策略、遥测、gRPC 和 REST 服务器配置、状态同步等。
这两个文件都有大量注释—请直接参考它们以调整您的节点。
一个需要调整的配置示例是 app.toml 中的 minimum-gas-prices 字段,该字段定义了验证人节点愿意接受的最低 gas 价格来处理交易。如果该字段为空,请确保用某个值进行编辑,例如 10inj
,否则节点将在启动时停止。对于本教程,我们将最低 gas 价格设置为 0
:
# The minimum gas prices a validator is willing to accept for processing a
# transaction. A transaction's fees must meet the minimum of any denomination
# specified in this config (e.g. 0.25token1;0.0001token2).
minimum-gas-prices = "0inj"
运行本地网络
现在,一切设置完成,您可以最终启动您的节点:
injectived start # Blocks should start coming in after running this
此命令允许您运行一个单节点,这足以通过该节点与链进行交互,但如果您希望查看多个节点之间是如何达成共识的,可以同时运行多个节点。
Last updated