Fabric出块时间参数配置详解

Fabric出块时间配置

Fabric出块是将一个或者多个交易数据结构(即Envelope)打包成区块,这项工作由orderer节点完成。目前fabric配置文件(configtx-template.yaml )中的默认出块时间为2s

相关参数

若需要修改fabric的出块机制,则需要调整以下配置参数:

  • BatchTimeout:出块超时时间,最长出块间隔(但缓存中必须含有数据才会出块,否则无法出块,即fabric不会强行产生空块)
  • MaxMessageCount:区块最大交易数量,当交易数量达到此参数后,会立即出块。
  • PreferredMaxBytes:区块首选字节数,正常情况下一个区块中的交易数据大小会小于此参数。
  • AbsoluteMaxBytes:区块最大字节数:所有情况下区块的最大允许字节数,超过此参数的交易将无法打包,直接退回。

出块机制和条件

基于上述指标,orderer会在两种条件下打包区块:

  1. 定时触发:维护以 BatchTimeout 为间隔的闹钟,定时检测缓存中是否还有未出块的交易,如果有则打包出块;
  2. 新交易触发:当满足条件的新交易与缓存中的交易大小之和与 PreferredMaxBytes 进行比较,超过此限制则将缓存中的交易进行打包,新交易进入缓存。或者交易数目超过MaxMessageCount,也会进行打包。

默认参数配置

fabric-starter中,参数配置主要在configtx-template.yaml 文件中,与出块时间相关的参数及其默认值如下:

# 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
BatchSize:
	# Max Message Count: The maximum number of messages to permit in a batch
	MaxMessageCount: 10

    # Absolute Max Bytes: The absolute maximum number of bytes allowed for
    # the serialized messages in a batch.
    AbsoluteMaxBytes: 98 MB

    # Preferred Max Bytes: The preferred maximum number of bytes allowed for
    # the serialized messages in a batch. A message larger than the preferred
    # max bytes will result in a batch larger than preferred max bytes.
    PreferredMaxBytes: 512 KB

参考博客

https://www.tinywell.com/2020/03/08/blockcutter

坚持不懈地努力才能成为大神!

posted @ 2021-04-19 23:33  己平事  阅读(1069)  评论(0编辑  收藏  举报