结构
现实生活中的一个以太币区块

image
- hash:该区块的hash
- size:该区块的大小
- td: Total Difficulty
type Block struct {
header *Header
//叔块信息,只保存叔块的Header,不保存交易
uncles []*Header
//该区块打包的所有的交易信息
transactions Transactions
// BlockHash
hash atomic.Value
size atomic.Value
// Td is used by package core to store the total difficulty of the chain up to and including the block.
td *big.Int
// These fields are used by package eth to track
// inter-peer block relay.
ReceivedAt time.Time
ReceivedFrom interface{}
}
Header
- Coinbase 奖励矿工的地址,矿工账户,也叫Miner
- Root //PMT的根节点的Hash,是以太坊stateTree,存储了所有账户的余额信息、Address信息、合约信息
- TxHash //PMT树,所有的交易信息都存在这个里面
- ReceiptHash //PMT树,所有的转账收款信息都在这里面
- Difficulty //该区块的难度
- Number :所有祖先区块的数量(也就是区块高度)
- GasLimit:该区块的gas上限
- GasUsed:该区块使用的gas
- Time:区块开始打包的时间
- MixDigest:该哈希值与Nonce值一起能够证明在该区块上已经进行了足够的计算(用于验证该区块挖矿成功与否的Hash值
- Nonce: 该哈希值与MixDigest值一起能够证明在该区块上已经进行了足够的计算(用于验证该区块挖矿成功与否的Hash值
// Header represents a block header in the Ethereum blockchain.
type Header struct {
ParentHash common.Hash `json:"parentHash" gencodec:"required"`
UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"`
Coinbase common.Address `json:"miner" gencodec:"required"`
Root common.Hash `json:"stateRoot" gencodec:"required"`
TxHash common.Hash `json:"transactionsRoot" gencodec:"required"`
ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"`
Bloom Bloom `json:"logsBloom" gencodec:"required"`
Difficulty *big.Int `json:"difficulty" gencodec:"required"`
Number *big.Int `json:"number" gencodec:"required"`
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
Time *big.Int `json:"timestamp" gencodec:"required"`
Extra []byte `json:"extraData" gencodec:"required"`
MixDigest common.Hash `json:"mixHash"`
Nonce BlockNonce `json:"nonce"`
}
其它
- BlockNonce 64位哈希,足够生成一个区块了
- Address账号地址在以太坊中就是20byte的字节
//go里面 type byte = uint8
//BlockNone是一个64位哈希,它证明(与//Mix-散列)已进行了足够数量的计算//在一个区块外。
type BlockNonce [8]byte
// Address represents the 20 byte address of an Ethereum account.
type Address [AddressLength]byte