Hyperledger的區塊結構

來源:互聯網
上載者:User

> 之前學習比特幣和以太坊,必先學習其區塊結構,當時在銀行做Hyperledger相關項目時,我卻對結構很忽略,只關心智能合約,居然也能初步掌握並開始項目相關的開發。這說明超級賬本的區塊屬性其實比較弱,重要的是智能合約的屬性。效能也不錯。從這個意義上講Hyperledger用來做存證是大材小用的。 問題1:交易是怎麼存入區塊的。

Transactions are collected into blocks/batches on the ordering service first. Blocks are cut either when the BatchSize is met, or when BatchTimeout elapses (provided a non-empty block).

也就是說,滿足這2個條件,區塊產生了:

交易數量夠了

逾時時間到了

所以Hyperledger的區塊產生不是定時的,高峰時間,區塊產生速度明顯加快

configtx.yaml in the common/configtx/tool/ directory for more info on the block-cutting criteria.

The Block type definition in protos/common/common.proto

和以太坊一樣,hyperledger的區別,也有區塊號、指向前一個區塊的指標、指向資料的指標,因為沒有挖礦,頭部簡潔了很多

// This is finalized block structure to be shared among the orderer and peer

// Note that the BlockHeader chains to the previous BlockHeader, and the BlockData hash is embedded

// in the BlockHeader. This makes it natural and obvious that the Data is included in the hash, but

// the Metadata is not.

message Block {

BlockHeader header = 1;BlockData data = 2;BlockMetadata metadata = 3;

}

// BlockHeader is the element of the block which forms the block chain

// The block header is hashed using the configured chain hashing algorithm

// over the ASN.1 encoding of the BlockHeader

message BlockHeader {

**uint64 number = 1;** // The position in the blockchain**bytes previous_hash = 2;** // The hash of the previous block header**bytes data_hash = 3;** // The hash of the BlockData, by MerkleTree

}

message BlockData {

repeated bytes data = 1;

}

message BlockMetadata {

repeated bytes metadata = 1;

} 問題2:怎麼存入LevelDB

These blocks are stored locally to disk on every ordering service node along with a LevelDB to index these blocks by number – see orderer/ledger/file

// Append a new block to the ledgerfunc (fl *fileLedger) Append(block *cb.Block) error {    err := fl.blockStore.AddBlock(block)    if err == nil {        close(fl.signal)        fl.signal = make(chan struct{})    }    return err}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.