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內增加了交易的次數後,產生的區塊中就會包含多筆交易了。