如何计算chain_id?
-
-
可能重复的[如何使用Python对base58进行编码?](https://tezos.stackexchange.com/questions/465/how-do-i-base58-encode-the-chain-id-using-python)Possible duplicate of [How do I base58 encode the chain ID using Python?](https://tezos.stackexchange.com/questions/465/how-do-i-base58-encode-the-chain-id-using-python)
- 3
- 2019-02-19
- Ezy
-
问题的"使用Python"版本中的答案:(似乎并不能回答一般性的问题...因此,我将尝试回答这一问题.The answers in the "using Python" version of the question :( do not seem to answer the general question... So I will attempt to answer this one.
- 0
- 2019-02-27
- Tom
-
1 个回答
- 投票数
-
- 2019-02-27
chain_id
是根据创世块哈希计算得出的,如下所示.首先,使用伪代码:
tezosB58CheckEncode('Net', firstFourBytes( blake2b(msg = tezosB58CheckDecode('B', genesisBlockHash), size = 32)))
详细信息:
-
进行创世块哈希.例如,在主网中,这是
"BLockGenesisGenesisGenesisGenesisGenesisf79b5d1CoW2"
. -
Base58Check-decode
块哈希.您可以通过在tezos.git中执行git grep B\(
来看到),块" B"的前缀字节为[1,52](十进制).这为我们提供了0x8fcf233671b6a04fcf679d2a381c2544ea6c1ea29ba6157776ed8424c7ccd00b
. -
计算块哈希字节的
BLAKE2B
哈希(大小32).我们得到0x7a06a7709ff405d1791d856c52a3c55246e03ec913599b813ec2977398afb3be
.仅取前四个字节0x7a06a770
. -
Base58Check-encode
这四个字节的前缀为" Net" [87,82,0](git grep Net\(
).我们得到"NetXdQprcVkpaWU"
.
对于协议更新测试链,我相信'genesis'块将是主链中派生测试链的块.
您可以在
lib_crypto/chain_id.ml
,然后在各个地方用作Chain_id.of_block_hash
(例如lib_shell/state.ml
,lib_shell/chain_validator.ml
,lib_storage/context.ml
)./p>The
chain_id
is computed from the genesis block hash as follows.First, in pseudocode:
tezosB58CheckEncode('Net', firstFourBytes( blake2b(msg = tezosB58CheckDecode('B', genesisBlockHash), size = 32)))
In detail:
Take the genesis block hash. For example, in mainnet, this is
"BLockGenesisGenesisGenesisGenesisGenesisf79b5d1CoW2"
.Base58Check-decode
the block hash. The prefix bytes for blocks "B" are [1, 52] (in decimal), as you can see by doinggit grep B\(
in tezos.git. This gives us0x8fcf233671b6a04fcf679d2a381c2544ea6c1ea29ba6157776ed8424c7ccd00b
.Compute the
BLAKE2B
hash (size 32) of the block hash bytes. We get0x7a06a7709ff405d1791d856c52a3c55246e03ec913599b813ec2977398afb3be
. Take only the first four bytes,0x7a06a770
.Base58Check-encode
these four bytes with the "Net" prefix [87, 82, 0] (git grep Net\(
). We get"NetXdQprcVkpaWU"
.
For a protocol update test chain, I believe the 'genesis' block will be the block in the main chain from which the test chain was forked.
You can find this computation defined in
lib_crypto/chain_id.ml
and then used asChain_id.of_block_hash
in various places (e.g.lib_shell/state.ml
,lib_shell/chain_validator.ml
,lib_storage/context.ml
).-
感谢您的回答!如果可能,您能否提供此信息的参考源?thanks for your answer! could you provide if possible for reference a source for this information ?
- 0
- 2019-03-01
- Ezy
RPC
GET /chains/<chain_id>/chain_id
返回:该标识符如何计算?