Hyperledger Fabric 关于出块时间和区块大小

原创
03/04 15:36
阅读数 746

Hyperledger Fabric 关于出块时间和区块大小

刚开始接触 fabric 的同学可能会有这样的疑问:为什么每个区块里就只有一笔交易呢?会产生这样的疑问很正常,说明有去认真仔细的观察和思考了。

决定区块大小的配置在通道配置文件 configtx.yaml 中:

Orderer: &OrdererDefaults


    OrdererType: solo

    Addresses:
        # - 127.0.0.1:7050

    # 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.
        # It is recommended not to exceed 49 MB, given the default grpc max message size of 100 MB
        # configured on orderer and peer nodes (and allowing for message expansion during communication).
        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

BatchTimeout : 出块的时间间隔

MaxMessageCount: 一个块中最大交易数量

AbsoluteMaxBytes: 块的最大大小

PreferredMaxBytes: 块的优先选择的大小

这几个配置项决定了出块的时间和块的大小。

看到每个区块中只有一笔交易是因为在2s内网络中就只有一笔交易,所以在打包出块的时候这个块中就只有这一笔交易。

当在2s内增加了交易的次数后,产生的区块中就会包含多笔交易了。

展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部