以太坊Block源碼分析

結(jié)構(gòu)

現(xiàn)實生活中的一個以太幣區(qū)塊


image
  • hash:該區(qū)塊的hash
  • size:該區(qū)塊的大小
  • td: Total Difficulty
type Block struct {
    header       *Header
    //叔塊信息,只保存叔塊的Header,不保存交易
    uncles       []*Header
    //該區(qū)塊打包的所有的交易信息
    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的根節(jié)點的Hash,是以太坊stateTree,存儲了所有賬戶的余額信息、Address信息、合約信息
  • TxHash //PMT樹,所有的交易信息都存在這個里面
  • ReceiptHash //PMT樹,所有的轉(zhuǎn)賬收款信息都在這里面
  • Difficulty //該區(qū)塊的難度
  • Number :所有祖先區(qū)塊的數(shù)量(也就是區(qū)塊高度)
  • GasLimit:該區(qū)塊的gas上限
  • GasUsed:該區(qū)塊使用的gas
  • Time:區(qū)塊開始打包的時間
  • MixDigest:該哈希值與Nonce值一起能夠證明在該區(qū)塊上已經(jīng)進行了足夠的計算(用于驗證該區(qū)塊挖礦成功與否的Hash值
  • Nonce: 該哈希值與MixDigest值一起能夠證明在該區(qū)塊上已經(jīng)進行了足夠的計算(用于驗證該區(qū)塊挖礦成功與否的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位哈希,足夠生成一個區(qū)塊了
  • Address賬號地址在以太坊中就是20byte的字節(jié)
//go里面  type byte = uint8
//BlockNone是一個64位哈希,它證明(與//Mix-散列)已進行了足夠數(shù)量的計算//在一個區(qū)塊外。
type BlockNonce [8]byte

// Address represents the 20 byte address of an Ethereum account.
type Address [AddressLength]byte
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1區(qū)塊 所有的交易都被分組為“區(qū)塊”。區(qū)塊鏈包含一系列鏈接在一 起的這樣的塊。 在以太坊,一個區(qū)塊包括: 區(qū)塊頭 ...
    布尼區(qū)塊鏈閱讀 2,512評論 0 2
  • 人生無意何如似? 百花枝頭空待死。 陌上紅顏歲月老, 一抔黃土荒墓詞。 圖片來自網(wǎng)絡(luò) 2018.10.15 妤諾
    天清曉閱讀 176評論 0 0
  • ①無論是熱戀期的情侶亦或是過了磨合期進入穩(wěn)定期的情侶,兩人在一塊時都會有美好的憧憬,兩人共同談?wù)撝髮W(xué)畢業(yè)以后、一...
    夜半聽雨_閱讀 398評論 0 0
  • 一本好書必然有其恰當(dāng)?shù)奈淖种馈_@個譯本讀來真是災(zāi)難!它的書名很有內(nèi)涵,金黃色的封面很有質(zhì)感,并且名聲頗好,只是...
    Reinhard_天寶閱讀 493評論 2 1

友情鏈接更多精彩內(nèi)容