Hyperledger Fabric出塊配置詳解

Hyperledger Fabric的出塊主要是Orderer節點負責,出塊配置位於創世區塊中,支持定時出塊、達到一定交易數出塊兩種條件。出塊配置位於configtx.yaml中,修改出塊配置後需要重新生成創世區塊。

相關參數

若需要修改fabric的出塊機制,則需要調整以下配置參數:

  • BatchTimeout:出塊超時時間,最長出塊間隔(但緩存中必須含有數據纔會出塊,否則無法出塊,即fabric不會強行產生空塊)
  • MaxMessageCount:區塊最大交易數量,當交易數量達到此參數後,會立即出塊。
  • PreferredMaxBytes:區塊首選字節數,正常情況下一個區塊中的交易數據大小會小於此參數。
  • AbsoluteMaxBytes:區塊最大字節數:所有情況下區塊的最大允許字節數,超過此參數的交易將無法打包,直接退回。

出塊機制和條件

基於上述指標,orderer會在兩種條件下打包區塊:

1.定時觸發:維護以 BatchTimeout 爲間隔的鬧鐘,定時檢測緩存中是否還有未出塊的交易,如果有則打包出塊;

2.新交易觸發:當滿足條件的新交易與緩存中的交易大小之和與 PreferredMaxBytes 進行比較,超過此限制則將緩存中的交易進行打包,新交易進入緩存。或者交易數目超過MaxMessageCount,也會進行打包。

默認參數配置

fabric的reslease-2.0分支中默認出塊配置如下:

    # Batch Timeout: The amount of time to wait before creating a batch.
    BatchTimeout: 2s

    # Batch Size: Controls the number of messages batched into a block.
    # The orderer views messages opaquely, but typically, messages may
    # be considered to be Fabric transactions.  The 'batch' is the group
    # of messages in the 'data' field of the block.  Blocks will be a few kb
    # larger than the batch size, when signatures, hashes, and other metadata
    # is applied.
    BatchSize:

        # Max Message Count: The maximum number of messages to permit in a
        # batch.  No block will contain more than this number of messages.
        MaxMessageCount: 500

        # Absolute Max Bytes: The absolute maximum number of bytes allowed for
        # the serialized messages in a batch. The maximum block size is this value
        # plus the size of the associated metadata (usually a few KB depending
        # upon the size of the signing identities). Any transaction larger than
        # this value will be rejected by ordering. If the "kafka" OrdererType is
        # selected, set 'message.max.bytes' and 'replica.fetch.max.bytes' on
        # the Kafka brokers to a value that is larger than this one.
        AbsoluteMaxBytes: 10 MB

        # Preferred Max Bytes: The preferred maximum number of bytes allowed
        # for the serialized messages in a batch. Roughly, this field may be considered
        # the best effort maximum size of a batch. A batch will fill with messages
        # until this size is reached (or the max message count, or batch timeout is
        # exceeded).  If adding a new message to the batch would cause the batch to
        # exceed the preferred max bytes, then the current batch is closed and written
        # to a block, and a new batch containing the new message is created.  If a
        # message larger than the preferred max bytes is received, then its batch
        # will contain only that message.  Because messages may be larger than
        # preferred max bytes (up to AbsoluteMaxBytes), some batches may exceed
        # the preferred max bytes, but will always contain exactly one transaction.
        PreferredMaxBytes: 2 MB
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章