Ethereum學習筆記(一)

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

相關命令分析

  • eth.blockNumber
    查看當前塊高。
  • eth.getBlock()
    根據高度查看塊內容。
  • eth.syncing
    擷取同步狀態,可以看到全網最新塊高,提示使用者同步進度。

區塊分析

創世區塊:

{  difficulty: 17179869184,  extraData: "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",  gasLimit: 5000,  gasUsed: 0,  hash: "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",  logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",  miner: "0x0000000000000000000000000000000000000000",  mixHash: "0x0000000000000000000000000000000000000000000000000000000000000000",  nonce: "0x0000000000000042",  number: 0,  parentHash: "0x0000000000000000000000000000000000000000000000000000000000000000",  receiptsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",  sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",  size: 540,  stateRoot: "0xd7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544",  timestamp: 0,  totalDifficulty: 17179869184,  transactions: [],  transactionsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",  uncles: []}

以太坊主網第410000的區塊:

{  difficulty: 1390302857940436,  extraData: "0x7563776f6e67",  gasLimit: 6708771,  gasUsed: 105000,  hash: "0xa108580144142887e58cf074d4ea0be93b00c13ed1992d3897edb078fabe7118",  logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",  miner: "0x9435d50503aee35c8757ae4933f7a0ab56597805",  mixHash: "0xfe8975ce7e272e88243ce9ec91d1a826fa5fe930d9e18de6a72ef57b4f9aa954",  nonce: "0xf0d4aef0039682a8",  number: 4100000,  parentHash: "0xd060e9516fc2a26aab3728d7fad2f2301d9822e6b2100eff58a16abd185881a1",  receiptsRoot: "0xa36be6a4f6a8e9a63a6b90dfa174d5cc6e7662f0d05007f39ef8a14aab54da95",  sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",  size: 1095,  stateRoot: "0xf49e0946c05d675cafd607613b009a3121a7e9ed6ed1f614a0c05e3bf6bebea1",  timestamp: 1501511212,  totalDifficulty: 595854527970155343606,  transactions: ["0x5728a5597f1dd7bb3e8843bfd6a8fe4156ae4605408d990c54dced5945e4a7af", "0x902aa2582c63328fcca071296a389b55a1c84983f1a3553ef05b1a14b16bd913", "0x452169cbce264f8d30074d2ddcb8caca2ba7e7b4effdca26301696c6a242ea5f", "0x9dee172d17a82354010ad18c9a7d32e49141b406d4802a6b0d5b25359809a1b3", "0xaa1b5f94f285a344d3e99f85529343daa3f72741752cad946a995e6544bd14ab"],  transactionsRoot: "0xe3eec697b2dcc74678edff5b022e65263c8428e47f11c25b9d4ba9d518632269",  uncles: []}
key value
difficulty 表示當前區塊的難度水平, 這個值根據前一個區塊的難度水平和時間戳記計算得到。
extraData 附加資料,32位元組以內的位元組數組
gasLimit 目前每個區塊的燃料消耗上限
gasUsed 當前區塊的所有交易使用燃料之和
hash block hash,可以理解為這個block在整個blockchain中的索引
logsBloom 日記 Bloom 過濾器由可索引資訊(日誌地址和日誌主題)組成,這個資訊包含在每個日誌入口, 來自交易列表中每個交易的接受者
miner 打包這一個block的礦工地址
mixHash 混合雜湊, 與一個與隨機數 (nonce)相關的 256 位雜湊計算, 用於證明針對當前區塊已經完成了足夠的計算
nonce 隨機數, 一個 64 位元雜湊, 和計算混合雜湊相關, 用於證明針對當前區塊已經完成了足夠的計算
number 區塊編號, 等於當前區塊的直系前輩區塊數量(創始區塊的區塊編號為0)
parentHash 父雜湊(創世區塊沒有父雜湊,所以parentHash為0x0000000000000000000000000000000000000000000000000000000000000000)
receiptsRoot 接受者字典樹根節點雜湊: 接受者字典樹根節點的 Keccak 256 位雜湊, 在接受者字典樹含有區塊中的所有交易資訊中的接受者
sha3Uncles ????
size 猜測為block包體的大小
stateRoot 狀態字典樹根節點雜湊: 狀態字典樹根節點的 Keccak 256 位雜湊, 交易打包到當前區塊且區塊定稿後可以產生這個值
timestamp 時間戳記, 當前區塊初始化時的Unix時間戳記
totalDifficulty ???
transactions block所包含的交易
transactionsRoot 交易字典樹根節點雜湊: 交易字典樹根節點的 Keccak 256 位雜湊, 在交易字典樹含有區塊中的所有交易列表
uncles ????

可以看出從創世區塊到現在以太坊的block結構都未做更改,表格中是以太坊黃皮書對塊的資料結構的解釋。黃皮書地址

key value
difficulty 表示當前區塊的難度水平, 這個值根據前一個區塊的難度水平和時間戳記計算得到。
extraData 附加資料,32位元組以內的位元組數組
gasLimit 目前每個區塊的燃料消耗上限
gasUsed 當前區塊的所有交易使用燃料之和
hash block hash,可以理解為這個block在整個blockchain中的索引
logsBloom 日記 Bloom 過濾器由可索引資訊(日誌地址和日誌主題)組成,這個資訊包含在每個日誌入口, 來自交易列表中每個交易的接受者
miner 打包這一個block的礦工地址
mixHash 混合雜湊, 與一個與隨機數 (nonce)相關的 256 位雜湊計算, 用於證明針對當前區塊已經完成了足夠的計算
nonce 隨機數, 一個 64 位元雜湊, 和計算混合雜湊相關, 用於證明針對當前區塊已經完成了足夠的計算
number 區塊編號, 等於當前區塊的直系前輩區塊數量(創始區塊的區塊編號為0)
parentHash 父雜湊(創世區塊沒有父雜湊,所以parentHash為0x0000000000000000000000000000000000000000000000000000000000000000)
receiptsRoot 接受者字典樹根節點雜湊: 接受者字典樹根節點的 Keccak 256 位雜湊, 在接受者字典樹含有區塊中的所有交易資訊中的接受者
sha3Uncles ????
size 猜測為block包體的大小
stateRoot 狀態字典樹根節點雜湊: 狀態字典樹根節點的 Keccak 256 位雜湊, 交易打包到當前區塊且區塊定稿後可以產生這個值
timestamp 時間戳記, 當前區塊初始化時的Unix時間戳記
totalDifficulty ???
transactions block所包含的交易
transactionsRoot 交易字典樹根節點雜湊: 交易字典樹根節點的 Keccak 256 位雜湊, 在交易字典樹含有區塊中的所有交易列表
uncles ????
  • difficulty:是當前塊的難度,值根據前一個區塊的難度水平和時間戳記計算得到。推薦大家看一下知乎上的一篇文章以太坊是如何計算難度的。具體計算公式如下,有興趣的朋友可以嘗試計算一下。(以太坊規定任何區塊的難度都不可以低於創世區塊

periodCount = block_num / 100000
diff = (parent_diff + (parent_diff / 2048 * max(1 - (block_timestamp - parent_timestamp) / 10, -99)) ) + 2^(periodCount - 2)

  • transactionsRoot:為了防止資料篡改,eth沿用的btc的MerkleTree證明,相關技術內容後續會做單獨闡述。

Golang資料結構源碼

位置:core/types/block.go

// 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    *big.Int       `json:"gasLimit"         gencodec:"required"`    GasUsed     *big.Int       `json:"gasUsed"          gencodec:"required"`    Time        *big.Int       `json:"timestamp"        gencodec:"required"`    Extra       []byte         `json:"extraData"        gencodec:"required"`    MixDigest   common.Hash    `json:"mixHash"          gencodec:"required"`    Nonce       BlockNonce     `json:"nonce"            gencodec:"required"`}// 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{}}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.