以太坊區塊與區塊頭資料結構解析
Block資料結構解析
原始碼
// Block represents an entire block in the Ethereum blockchain. type Block struct { header *Header uncles []*Header transactions Transactions // caches 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: 該區塊的資訊
- uncles: 該區塊所包含的叔塊的資訊
- transactions: 該區塊所包含的交易資訊
- td: 總難度,即從開始區塊到本區塊(包括本區塊)所有的難度的累加
- ReceivedAt: 用於跟蹤區塊的生成
- ReceivedFrom:用於跟蹤區塊的生成
Header資料結構解析
原始碼
// 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"` Extra2 []byte `json:"extraData2" gencodec:"required"` MixDigest common.Hash `json:"mixHash" gencodec:"required"` Nonce BlockNonce `json:"nonce" gencodec:"required"` }
主要屬性:
- ParentHash: 該區塊的父區塊的雜湊值
- UncleHash: 該區塊所包含的叔塊的雜湊值
- Coinbase: 打包該區塊礦工的地址,礦工費和打包區塊的獎金將傳送到這個地址
- Root: 儲存賬戶狀態的Merkle樹的根節點的雜湊
- TxHash: 儲存該區塊中的交易的Merkle樹的根節點的雜湊
- ReceiptHash:儲存該區塊的交易的回單的Merkle樹的根節點的雜湊
- Bloom: 交易日誌的布隆過濾器,用於查詢
- Difficulty: 該區塊的難度
- Number: 區塊號,也是區塊高度,也是所有祖先區塊的數量
- GasLimit: 該區塊的汽油(gas)上限
- GasUsed: 該區塊使用的汽油(gas)
- Time: 區塊開始打包時間戳(呼叫Engine.Prepare函式的時候設定)
- MixDigest: 該雜湊值與Nonce值一起證明該區塊上已經進行了足夠的計算,用於證明挖礦成功
- Nonce: 該雜湊值與MixDigest雜湊值一起證明該區塊上已經進行了足夠的計算,用於證明挖礦成功
- Extra: 預留它用(例如Clique共識機制使用)