设置本地网络 (Setting up a local network)
启动本地网络 (Spinning up a local network)
先决条件 (Prerequisites)
为了运行本地网络,必须从源代码安装 Namada。
有一个专门为此目的编写的scripts
,可以在 Namada 仓库的脚本下找到。
安装脚本依赖项 (Installing script dependencies)
脚本有一些必须安装的依赖项,以便成功运行它:
必须安装 python3。
必须安装 toml Python pip 库 https://pypi.org/project/toml/。
脚本将需要一个创世配置文件,该文件是一个 TOML 文件,用于指定网络的参数。此类文件的示例可以在 anoma-network-config 仓库的templates
目录中找到。
修改创世配置文件 (Modifying the genesis configuration file)
为了成功运行脚本,必须从 toml 文件中删除所有验证器部分。这是因为脚本将为网络生成一组新的验证器。
下面的代码块显示了一个已经修改过的,以删除验证器部分的创世配置文件示例。
# Editing genesis config steps
# Developer network
genesis_time = "2021-12-20T15:00:00.00Z"
native_token = "NAM"
- # 3 genesis validators.
- [validator.validator-1]
- # Validator's token balance at genesis.
- tokens = 100000
- # Amount of the validator's genesis token balance which is not staked.
- non_staked_balance = 100000
- # VP for the validator account
- validator_vp = "vp_validator"
- # Commission rate for rewards
- commission_rate = 0.05
- # Maximum change per epoch in the commission rate
- max_commission_rate_change = 0.01
- # Public IP:port address
- net_address = "52.210.23.30:26656"
-
- [validator.validator-2]
- # Validator's token balance at genesis.
- tokens = 100000
- # Amount of the validator's genesis token balance which is not staked.
- non_staked_balance = 100000
- # VP for the validator account
- validator_vp = "vp_validator"
- # Commission rate for rewards
- commission_rate = 0.05
- # Maximum change per epoch in the commission rate
- max_commission_rate_change = 0.01
- # VP for the staking reward account
- staking_reward_vp = "vp_user"
- # Public IP:port address
- net_address = "63.32.203.239:26656"
-
- [validator.validator-3]
- # Validator's token balance at genesis.
- tokens = 100000
- # Amount of the validator's genesis token balance which is not staked.
- non_staked_balance = 100000
- # VP for the validator account
- validator_vp = "vp_validator"
- # Commission rate for rewards
- commission_rate = 0.05
- # Maximum change per epoch in the commission rate
- max_commission_rate_change = 0.01
- # VP for the staking reward account
- staking_reward_vp = "vp_user"
- # Public IP:port address
- net_address = "54.195.72.213:26656"
# Some tokens present at genesis.
[token.NAM]
address = "atest1v4ehgw36x3prswzxggunzv6pxqmnvdj9xvcyzvpsggeyvs3cg9qnywf589qnwvfsg5erg3fkl09rg5"
vp = "vp_token"
[token.NAM.balances]
atest1v4ehgw36gc6yxvpjxccyzvphxycrxw2xxsuyydesxgcnjs3cg9znwv3cxgmnj32yxy6rssf5tcqjm3 = 9223372036854
[token.BTC]
address = "atest1v4ehgw36xdzryve5gsc52veeg5cnsv2yx5eygvp38qcrvd29xy6rys6p8yc5xvp4xfpy2v694wgwcp"
vp = "vp_token"
[token.BTC.balances]
atest1v4ehgw36gc6yxvpjxccyzvphxycrxw2xxsuyydesxgcnjs3cg9znwv3cxgmnj32yxy6rssf5tcqjm3 = 9223372036854
[token.ETH]
address = "atest1v4ehgw36xqmr2d3nx3ryvd2xxgmrq33j8qcns33sxezrgv6zxdzrydjrxveygd2yxumrsdpsf9jc2p"
vp = "vp_token"
[token.ETH.balances]
atest1v4ehgw36gc6yxvpjxccyzvphxycrxw2xxsuyydesxgcnjs3cg9znwv3cxgmnj32yxy6rssf5tcqjm3 = 9223372036854
[token.DOT]
address = "atest1v4ehgw36gg6nvs2zgfpyxsfjgc65yv6pxy6nwwfsxgungdzrggeyzv35gveyxsjyxymyz335hur2jn"
vp = "vp_token"
[token.DOT.balances]
atest1v4ehgw36gc6yxvpjxccyzvphxycrxw2xxsuyydesxgcnjs3cg9znwv3cxgmnj32yxy6rssf5tcqjm3 = 9223372036854
[token.Schnitzel]
address = "atest1v4ehgw36xue5xvf5xvuyzvpjx5un2v3k8qeyvd3cxdqns32p89rrxd6xx9zngvpegccnzs699rdnnt"
vp = "vp_token"
[token.Schnitzel.balances]
atest1v4ehgw36gc6yxvpjxccyzvphxycrxw2xxsuyydesxgcnjs3cg9znwv3cxgmnj32yxy6rssf5tcqjm3 = 9223372036854
[token.Apfel]
address = "atest1v4ehgw36gfryydj9g3p5zv3kg9znyd358ycnzsfcggc5gvecgc6ygs2rxv6ry3zpg4zrwdfeumqcz9"
vp = "vp_token"
[token.Apfel.balances]
atest1v4ehgw36gc6yxvpjxccyzvphxycrxw2xxsuyydesxgcnjs3cg9znwv3cxgmnj32yxy6rssf5tcqjm3 = 9223372036854
[token.Kartoffel]
address = "atest1v4ehgw36gep5ysecxq6nyv3jg3zygv3e89qn2vp48pryxsf4xpznvve5gvmy23fs89pryvf5a6ht90"
public_key = ""
vp = "vp_token"
[token.Kartoffel.balances]
atest1v4ehgw36gc6yxvpjxccyzvphxycrxw2xxsuyydesxgcnjs3cg9znwv3cxgmnj32yxy6rssf5tcqjm3 = 9223372036854
# Some established accounts present at genesis.
[implicit.faucet]
address = "atest1v4ehgw36gc6yxvpjxccyzvphxycrxw2xxsuyydesxgcnjs3cg9znwv3cxgmnj32yxy6rssf5tcqjm3"
vp = "vp_user"
[established.masp]
address = "atest1v4ehgw36xaryysfsx5unvve4g5my2vjz89p52sjxxgenzd348yuyyv3hg3pnjs35g5unvde4ca36y5"
vp = "vp_masp"
# Wasm VP definitions
# Implicit VP
[wasm.vp_implicit]
filename = "vp_implicit.wasm"
# Default user VP in established accounts
[wasm.vp_user]
# filename (relative to wasm path used by the node)
filename = "vp_user.wasm"
# Validator VP
[wasm.vp_validator]
filename = "vp_validator.wasm"
# Token VP
[wasm.vp_token]
filename = "vp_token.wasm"
# MASP VP
[wasm.vp_masp]
filename = "vp_masp.wasm"
# General protocol parameters.
[parameters]
# Minimum number of blocks in an epoch.
min_num_of_blocks = 5
# Maximum expected time per block (in seconds).
max_expected_time_per_block = 11
# Implicit VP WASM name
implicit_vp = "vp_implicit"
# Expected number of epochs per year (also sets the min duration of an epoch in seconds)
epochs_per_year = 262800 # ~120 sec epoch duration (60*60*24\*365 / 120)
# The P gain factor in the Proof of Stake rewards controller
pos_gain_p = 0.1
# The D gain factor in the Proof of Stake rewards controller
pos_gain_d = 0.1
# The wrapper tx fixed fees
wrapper_tx_fees = "5"
# The max size of blocks in bytes
max_proposal_bytes = 5242880
vp_whitelist = []
tx_whitelist = []
max_public_key_per_account = 15
#Maximum number of signatures required per transaction
max_signature_per_tx = 15
# Proof of stake parameters.
[pos_params]
# Maximum number of active validators.
max_validator_slots = 128
# Pipeline length (in epochs). Any change in the validator set made in
# epoch 'n' will become active in epoch 'n + pipeline_len'.
pipeline_len = 2
# Unbonding length (in epochs). Validators may have their stake slashed
# for a fault in epoch 'n' up through epoch 'n + unbonding_len'.
unbonding_len = 4
# Votes per fundamental staking token (namnam)
tm_votes_per_token = 1.0
# Reward for proposing a block.
block_proposer_reward = 0.125
# Reward for voting on a block.
block_vote_reward = 0.1
# Maximum inflation rate per annum (10%)
max_inflation_rate = 0.1
# Targeted ratio of staked tokens to total tokens in the supply
target_staked_ratio = 0.6667
# Portion of a validator's stake that should be slashed on a duplicate
# vote.
duplicate_vote_min_slash_rate = 0.001
# Portion of a validator's stake that should be slashed on a light
# client attack.
light_client_attack_min_slash_rate = 0.001
cubic_slashing_window_length = 1
# Governance parameters.
[gov_params]
# minimum amount of xan token to lock
min_proposal_fund = 100
# proposal code size in kibibytes (KiB)
max_proposal_code_size = 300000
# min proposal period length in epochs
min_proposal_period = 3
# max proposal period length in epochs
max_proposal_period = 6
# maximum number of characters in the proposal content
max_proposal_content_size = 10000
# minimum epochs between end and grace epoch
min_proposal_grace_epochs = 0
构建 wasm (Building wasm)
该脚本还需要构建所有用于交易的 wasm
文件。可以通过运行以下命令完成此操作(同时位于 namada 目录中):
make build-wasm-scripts
运行脚本 (Running the script)
该脚本名为 build_network.sh
,可以使用以下命令运行:
# Ensure you are in the root of the namada repository directory
./scripts/build_network.sh <config_toml> <namada_dir> <OPTIONAL: base_dir>
更具体地说,该脚本接受三个参数:
config_toml
: 到(无验证器的)创世配置文件的路径。namada_dir
: 到 Namada 二进制文件目录的路径。如果使用make build-release
构建了二进制文件,这将意味着namada/target/release
目录。否则,如果使用make build
构建它们,则为namada/target/debug
目录。base_dir
: (可选参数)到 BASE_DIR 目录的路径,其中存储所有链数据。只有在 BASE_DIR 不是namadac utils default-base-dir
命令给出的默认值时,才需要这样做。
例如,MacOS 用户可能会运行类似以下内容的命令:
./scripts/build_network.sh \
~/anoma-network-config/templates/edited_genesis_config.toml \
./target/release # Assuming the binaries were built using `make build-release`
运行账本 (Running the ledger)
运行脚本后,一个 python 进程将在后台启动。可以通过熟悉的命令运行账本:
target/release/namada ledger # Assuming the binaries were built using `make build-release`
清理 (Cleaning up)
在本地网络实现其目的后,可以通过运行脚本的 cleanup 函数中找到的以下命令进行清理:
pkill -f ".hack/chains"
rm -r .hack/chains
rm local.*.tar.gz
Last updated