Ethereum genesis block


文件结构

使用geth搭建私有链的时候需要配置genesis.json(点击前往github查看genesis.json文件结构)文件用来初始化创世区块,文件结构如下:

{
  "config": {
        "chainId": 0,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
  "alloc": {
        "0x0000000000000000000000000000000000000001": {"balance": "111111111"},
        "0x0000000000000000000000000000000000000002": {"balance": "222222222"}
    },
  "coinbase"   : "0x0000000000000000000000000000000000000000",
  "difficulty" : "0x20000",
  "extraData"  : "",
  "gasLimit"   : "0x2fefd8",
  "nonce"      : "0x0000000000000042",
  "mixhash"    : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp"  : "0x00"
}

字段描述

chainId :区块链id
homesteadBlock :Homestead 硬分叉区块高度
eip155Block : EIP 155 硬分叉高度
eip158Block : EIP 158 硬分叉高度
alloc :预置账号及余额
coinbase :矿工账号
difficulty :难度值,值越大越难
extraData :附加信息,随便填
gasLimit :区块gas消耗总量限制,用来限制区块能包含的交易信息最大值
nonce :64位随机数
mixhash :与nonce配合用于挖矿,由上一个区块的一部分生成的hash值
parentHash :上一个区块的hash值

推荐阅读

What does each genesis.json parameter mean?

I’m trying to setup genesis.json for my private network. What does each parameter mean and what value can I set in genesis.json?

  • nonce: any data?
  • timestamp: any time?
  • parentHash: any hash?
  • extraData: put any data if you wish to add? what is the max size?
  • gasLimit: What is the max number?
  • difficulty: What is the lowest number?
  • mixhash: What is this?
  • coinbase: Ethereum address for coinbase, right?
  • alloc: first ether allocation

Sample genesis json file from How To Create A Private Ethereum Chain. Official document for private network genesis json is here. Connecting to the network

1
2
3
4
5
6
7
8
9
10
11
12
{
"nonce": "0xdeadbeefdeadbeef",
"timestamp": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x0",
"gasLimit": "0x8000000",
"difficulty": "0x400",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x3333333333333333333333333333333333333333",
"alloc": {
}
}

Genesis block Explanation

mixhash: A 256-bit hash which proves, combined with the nonce, that a sufficient amount of computation has been carried out on this block: the Proof-of-Work (PoW). The combination of nonce and mixhash must satisfy a mathematical condition described in the Yellowpaper, 4.3.4. Block Header Validity, (44). It allows to verify that the Block has really been cryptographically mined, thus, from this aspect, is valid.

nonce: A 64-bit hash, which proves, combined with the mix-hash, that a sufficient amount of computation has been carried out on this block: the Proof-of-Work (PoW). The combination of nonce and mixhash must satisfy a mathematical condition described in the Yellowpaper, 4.3.4. Block Header Validity, (44), and allows to verify that the Block has really been cryptographically mined and thus, from this aspect, is valid. The nonce is the cryptographically secure mining proof-of-work that proves beyond reasonable doubt that a particular amount of computation has been expended in the determination of this token value. (Yellowpager, 11.5. Mining Proof-of-Work).

difficulty: A scalar value corresponding to the difficulty level applied during the nonce discovering of this block. It defines the mining Target, which can be calculated from the previous block’s difficulty level and the timestamp. The higher the difficulty, the statistically more calculations a Miner must perform to discover a valid block. This value is used to control the Block generation time of a Blockchain, keeping the Block generation frequency within a target range. On the test network, we keep this value low to avoid waiting during tests, since the discovery of a valid Block is required to execute a transaction on the Blockchain.

alloc: Allows defining a list of pre-filled wallets. That’s an Ethereum specific functionality to handle the “Ether pre-sale” period. Since we can mine local Ether quickly, we don’t use this option.

coinbase The 160-bit address to which all rewards (in Ether) collected from the successful mining of this block have been transferred. They are a sum of the mining reward itself and the Contract transaction execution refunds. Often named “beneficiary” in the specifications, sometimes “etherbase” in the online documentation. This can be anything in the Genesis Block since the value is set by the setting of the Miner when a new Block is created.

timestamp: A scalar value equal to the reasonable output of Unix time() function at this block inception. This mechanism enforces a homeostasis in terms of the time between blocks. A smaller period between the last two blocks results in an increase in the difficulty level and thus additional computation required to find the next valid block. If the period is too large, the difficulty, and expected time to the next block, is reduced. The timestamp also allows verifying the order of block within the chain (Yellowpaper, 4.3.4. (43)).

parentHash: The Keccak 256-bit hash of the entire parent block header (including its nonce and mixhash). Pointer to the parent block, thus effectively building the chain of blocks. In the case of the Genesis block, and only in this case, it’s 0.

extraData: An optional free, but max. 32-byte long space to conserve smart things for ethernity. :)

gasLimit: A scalar value equal to the current chain-wide limit of Gas expenditure per block. High in our case to avoid being limited by this threshold during tests. Note: this does not indicate that we should not pay attention to the Gas consumption of our Contracts.

链接:what-does-each-genesis-json-parameter-mean

The meaning/specification of “config” in genesis.json?

As I tried to search from Google, there are some genesis.json example files to customize the parameter of genesis block in Ethereum private blockchain.

In the file, there is a part called “config”

1
2
3
4
5
6
"config": {
"chainId": 1,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
}

What is the meaning or specification for those parameter in “config”? May I setup part of parameter(s) only if necessary?

This is the chain configuration field, defined in config.go:

1
2
3
4
5
// ChainConfig is the core config which determines the blockchain settings.
//
// ChainConfig is stored in the database on a per block basis. This means
// that any network, identified by its genesis block, can have its own
// set of configuration options.

The available fields and their descriptions are shown below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
type ChainConfig struct {
ChainId *big.Int `json:"chainId"` // Chain id identifies the current chain and is used for replay protection

HomesteadBlock *big.Int `json:"homesteadBlock,omitempty"` // Homestead switch block (nil = no fork, 0 = already homestead)
DAOForkBlock *big.Int `json:"daoForkBlock,omitempty"` // TheDAO hard-fork switch block (nil = no fork)
DAOForkSupport bool `json:"daoForkSupport,omitempty"` // Whether the nodes supports or opposes the DAO hard-fork

// EIP150 implements the Gas price changes (https://github.com/ethereum/EIPs/issues/150)
EIP150Block *big.Int `json:"eip150Block,omitempty"` // EIP150 HF block (nil = no fork)
EIP150Hash common.Hash `json:"eip150Hash,omitempty"` // EIP150 HF hash (fast sync aid)

EIP155Block *big.Int `json:"eip155Block,omitempty"` // EIP155 HF block
EIP158Block *big.Int `json:"eip158Block,omitempty"` // EIP158 HF block

// Various consensus engines
Ethash *EthashConfig `json:"ethash,omitempty"`
Clique *CliqueConfig `json:"clique,omitempty"`
}

The config for the main chain is as follows (again in config.go):

1
2
3
4
5
6
7
8
9
10
MainnetChainConfig = &ChainConfig{
ChainId: MainNetChainID,
HomesteadBlock: MainNetHomesteadBlock,
DAOForkBlock: MainNetDAOForkBlock,
DAOForkSupport: true,
EIP150Block: MainNetHomesteadGasRepriceBlock,
EIP150Hash: MainNetHomesteadGasRepriceHash,
EIP155Block: MainNetSpuriousDragon,
EIP158Block: MainNetSpuriousDragon,
Ethash: new(EthashConfig),

With the actual values being defined in util.go.

So in answer to your questions…

1
"config": { "chainId": 1, "homesteadBlock": 0, "eip155Block": 0, "eip158Block": 0 }

What is the meaning or specification for those parameter in “config”?

Chain id - identifies the current chain and is used for replay protection. You should set it to a unique value for your private chain.
homesteadBlock - your chain won’t be undergoing the switch to Homestead, so leave this as 0.
eip155Block - your chain won’t be hard-forking for these changes, so leave as 0.
eip158Block - your chain won’t be hard-forking for these changes, so leave as 0.

May I setup part of parameter(s) only if necessary?
Yes. Any of the values that set a block or hash number can be ignored for a private chain - they’re only really relevant to the public main chain.

链接:the-meaning-specification-of-config-in-genesis-json

0%