@@ -21,6 +21,7 @@ import (
2121 "regexp"
2222 "strconv"
2323 "strings"
24+ "time"
2425
2526 cb "github.com/hyperledger/fabric/protos/common"
2627 ab "github.com/hyperledger/fabric/protos/orderer"
@@ -36,6 +37,9 @@ const (
3637 // BatchSizeKey is the cb.ConfigurationItem type key name for the BatchSize message
3738 BatchSizeKey = "BatchSize"
3839
40+ // BatchTimeoutKey is the cb.ConfigurationItem type key name for the BatchTimeout message
41+ BatchTimeoutKey = "BatchTimeout"
42+
3943 // ChainCreatorsKey is the cb.ConfigurationItem type key name for the ChainCreators message
4044 ChainCreatorsKey = "ChainCreators"
4145
@@ -60,6 +64,9 @@ type Manager interface {
6064 // BatchSize returns the maximum number of messages to include in a block
6165 BatchSize () * ab.BatchSize
6266
67+ // BatchTimeout returns the amount of time to wait before creating a batch
68+ BatchTimeout () time.Duration
69+
6370 // ChainCreators returns the policy names which are allowed for chain creation
6471 // This field is only set for the system ordering chain
6572 ChainCreators () []string
@@ -73,6 +80,7 @@ type Manager interface {
7380type ordererConfig struct {
7481 consensusType string
7582 batchSize * ab.BatchSize
83+ batchTimeout time.Duration
7684 chainCreators []string
7785 kafkaBrokers []string
7886}
@@ -101,6 +109,11 @@ func (pm *ManagerImpl) BatchSize() *ab.BatchSize {
101109 return pm .config .batchSize
102110}
103111
112+ // BatchTimeout returns the amount of time to wait before creating a batch
113+ func (pm * ManagerImpl ) BatchTimeout () time.Duration {
114+ return pm .config .batchTimeout
115+ }
116+
104117// ChainCreators returns the policy names which are allowed for chain creation
105118// This field is only set for the system ordering chain
106119func (pm * ManagerImpl ) ChainCreators () []string {
@@ -145,8 +158,7 @@ func (pm *ManagerImpl) ProposeConfig(configItem *cb.ConfigurationItem) error {
145158 switch configItem .Key {
146159 case ConsensusTypeKey :
147160 consensusType := & ab.ConsensusType {}
148- err := proto .Unmarshal (configItem .Value , consensusType )
149- if err != nil {
161+ if err := proto .Unmarshal (configItem .Value , consensusType ); err != nil {
150162 return fmt .Errorf ("Unmarshaling error for ConsensusType: %s" , err )
151163 }
152164 if pm .config .consensusType == "" {
@@ -159,26 +171,36 @@ func (pm *ManagerImpl) ProposeConfig(configItem *cb.ConfigurationItem) error {
159171 pm .pendingConfig .consensusType = consensusType .Type
160172 case BatchSizeKey :
161173 batchSize := & ab.BatchSize {}
162- err := proto .Unmarshal (configItem .Value , batchSize )
163- if err != nil {
174+ if err := proto .Unmarshal (configItem .Value , batchSize ); err != nil {
164175 return fmt .Errorf ("Unmarshaling error for BatchSize: %s" , err )
165176 }
166-
167177 if batchSize .MaxMessageCount <= 0 {
168178 return fmt .Errorf ("Attempted to set the batch size max message count to %d which is less than or equal to 0" , batchSize .MaxMessageCount )
169179 }
170180 pm .pendingConfig .batchSize = batchSize
181+ case BatchTimeoutKey :
182+ var timeoutValue time.Duration
183+ var err error
184+ batchTimeout := & ab.BatchTimeout {}
185+ if err = proto .Unmarshal (configItem .Value , batchTimeout ); err != nil {
186+ return fmt .Errorf ("Unmarshaling error for BatchTimeout: %s" , err )
187+ }
188+ if timeoutValue , err = time .ParseDuration (batchTimeout .Timeout ); err != nil {
189+ return fmt .Errorf ("Attempted to set the batch timeout to a invalid value: %s" , err )
190+ }
191+ if timeoutValue <= 0 {
192+ return fmt .Errorf ("Attempted to set the batch timeout to a non-positive value: %s" , timeoutValue .String ())
193+ }
194+ pm .pendingConfig .batchTimeout = timeoutValue
171195 case ChainCreatorsKey :
172196 chainCreators := & ab.ChainCreators {}
173- err := proto .Unmarshal (configItem .Value , chainCreators )
174- if err != nil {
197+ if err := proto .Unmarshal (configItem .Value , chainCreators ); err != nil {
175198 return fmt .Errorf ("Unmarshaling error for ChainCreator: %s" , err )
176199 }
177200 pm .pendingConfig .chainCreators = chainCreators .Policies
178201 case KafkaBrokersKey :
179202 kafkaBrokers := & ab.KafkaBrokers {}
180- err := proto .Unmarshal (configItem .Value , kafkaBrokers )
181- if err != nil {
203+ if err := proto .Unmarshal (configItem .Value , kafkaBrokers ); err != nil {
182204 return fmt .Errorf ("Unmarshaling error for KafkaBrokers: %s" , err )
183205 }
184206 if len (kafkaBrokers .Brokers ) == 0 {
0 commit comments