@@ -21,6 +21,7 @@ import (
21
21
"regexp"
22
22
"strconv"
23
23
"strings"
24
+ "time"
24
25
25
26
cb "github.com/hyperledger/fabric/protos/common"
26
27
ab "github.com/hyperledger/fabric/protos/orderer"
@@ -36,6 +37,9 @@ const (
36
37
// BatchSizeKey is the cb.ConfigurationItem type key name for the BatchSize message
37
38
BatchSizeKey = "BatchSize"
38
39
40
+ // BatchTimeoutKey is the cb.ConfigurationItem type key name for the BatchTimeout message
41
+ BatchTimeoutKey = "BatchTimeout"
42
+
39
43
// ChainCreatorsKey is the cb.ConfigurationItem type key name for the ChainCreators message
40
44
ChainCreatorsKey = "ChainCreators"
41
45
@@ -60,6 +64,9 @@ type Manager interface {
60
64
// BatchSize returns the maximum number of messages to include in a block
61
65
BatchSize () * ab.BatchSize
62
66
67
+ // BatchTimeout returns the amount of time to wait before creating a batch
68
+ BatchTimeout () time.Duration
69
+
63
70
// ChainCreators returns the policy names which are allowed for chain creation
64
71
// This field is only set for the system ordering chain
65
72
ChainCreators () []string
@@ -73,6 +80,7 @@ type Manager interface {
73
80
type ordererConfig struct {
74
81
consensusType string
75
82
batchSize * ab.BatchSize
83
+ batchTimeout time.Duration
76
84
chainCreators []string
77
85
kafkaBrokers []string
78
86
}
@@ -101,6 +109,11 @@ func (pm *ManagerImpl) BatchSize() *ab.BatchSize {
101
109
return pm .config .batchSize
102
110
}
103
111
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
+
104
117
// ChainCreators returns the policy names which are allowed for chain creation
105
118
// This field is only set for the system ordering chain
106
119
func (pm * ManagerImpl ) ChainCreators () []string {
@@ -145,8 +158,7 @@ func (pm *ManagerImpl) ProposeConfig(configItem *cb.ConfigurationItem) error {
145
158
switch configItem .Key {
146
159
case ConsensusTypeKey :
147
160
consensusType := & ab.ConsensusType {}
148
- err := proto .Unmarshal (configItem .Value , consensusType )
149
- if err != nil {
161
+ if err := proto .Unmarshal (configItem .Value , consensusType ); err != nil {
150
162
return fmt .Errorf ("Unmarshaling error for ConsensusType: %s" , err )
151
163
}
152
164
if pm .config .consensusType == "" {
@@ -159,26 +171,36 @@ func (pm *ManagerImpl) ProposeConfig(configItem *cb.ConfigurationItem) error {
159
171
pm .pendingConfig .consensusType = consensusType .Type
160
172
case BatchSizeKey :
161
173
batchSize := & ab.BatchSize {}
162
- err := proto .Unmarshal (configItem .Value , batchSize )
163
- if err != nil {
174
+ if err := proto .Unmarshal (configItem .Value , batchSize ); err != nil {
164
175
return fmt .Errorf ("Unmarshaling error for BatchSize: %s" , err )
165
176
}
166
-
167
177
if batchSize .MaxMessageCount <= 0 {
168
178
return fmt .Errorf ("Attempted to set the batch size max message count to %d which is less than or equal to 0" , batchSize .MaxMessageCount )
169
179
}
170
180
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
171
195
case ChainCreatorsKey :
172
196
chainCreators := & ab.ChainCreators {}
173
- err := proto .Unmarshal (configItem .Value , chainCreators )
174
- if err != nil {
197
+ if err := proto .Unmarshal (configItem .Value , chainCreators ); err != nil {
175
198
return fmt .Errorf ("Unmarshaling error for ChainCreator: %s" , err )
176
199
}
177
200
pm .pendingConfig .chainCreators = chainCreators .Policies
178
201
case KafkaBrokersKey :
179
202
kafkaBrokers := & ab.KafkaBrokers {}
180
- err := proto .Unmarshal (configItem .Value , kafkaBrokers )
181
- if err != nil {
203
+ if err := proto .Unmarshal (configItem .Value , kafkaBrokers ); err != nil {
182
204
return fmt .Errorf ("Unmarshaling error for KafkaBrokers: %s" , err )
183
205
}
184
206
if len (kafkaBrokers .Brokers ) == 0 {
0 commit comments