Skip to content

Commit addfd4d

Browse files
committed
[FAB-1358] Convert all batchSize refs to uint32
https://jira.hyperledger.org/browse/FAB-1358 There is some mismatch between the batchSize type as expressed in the localconfig package versus the sharedconfig package and the orderer configuration proto. This changeset fixes that. This changeset also defines the precision for the integers in the localconfig package, for symmetry. Change-Id: I01d86ff80fff4498f683ad960dd443e189bd1599 Signed-off-by: Kostas Christidis <[email protected]>
1 parent fe16a6d commit addfd4d

File tree

11 files changed

+38
-48
lines changed

11 files changed

+38
-48
lines changed

orderer/common/blockcutter/blockcutter.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (r *receiver) Ordered(msg *cb.Envelope) ([][]*cb.Envelope, [][]filter.Commi
9090
r.curBatch = append(r.curBatch, msg)
9191
r.batchComs = append(r.batchComs, committer)
9292

93-
if len(r.curBatch) < r.sharedConfigManager.BatchSize() {
93+
if uint32(len(r.curBatch)) < r.sharedConfigManager.BatchSize() {
9494
return nil, nil, true
9595
}
9696

orderer/common/blockcutter/blockcutter_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ var unmatchedTx = &cb.Envelope{Payload: []byte("UNMATCHED")}
7373

7474
func TestNormalBatch(t *testing.T) {
7575
filters := getFilters()
76-
batchSize := 2
76+
batchSize := uint32(2)
7777
r := NewReceiverImpl(&mocksharedconfig.Manager{BatchSizeVal: batchSize}, filters)
7878

7979
batches, committers, ok := r.Ordered(goodTx)
@@ -100,7 +100,7 @@ func TestNormalBatch(t *testing.T) {
100100

101101
func TestBadMessageInBatch(t *testing.T) {
102102
filters := getFilters()
103-
batchSize := 2
103+
batchSize := uint32(2)
104104
r := NewReceiverImpl(&mocksharedconfig.Manager{BatchSizeVal: batchSize}, filters)
105105

106106
batches, committers, ok := r.Ordered(badTx)
@@ -136,7 +136,7 @@ func TestBadMessageInBatch(t *testing.T) {
136136

137137
func TestUnmatchedMessageInBatch(t *testing.T) {
138138
filters := getFilters()
139-
batchSize := 2
139+
batchSize := uint32(2)
140140
r := NewReceiverImpl(&mocksharedconfig.Manager{BatchSizeVal: batchSize}, filters)
141141

142142
batches, committers, ok := r.Ordered(unmatchedTx)
@@ -172,7 +172,7 @@ func TestUnmatchedMessageInBatch(t *testing.T) {
172172

173173
func TestIsolatedEmptyBatch(t *testing.T) {
174174
filters := getFilters()
175-
batchSize := 2
175+
batchSize := uint32(2)
176176
r := NewReceiverImpl(&mocksharedconfig.Manager{BatchSizeVal: batchSize}, filters)
177177

178178
batches, committers, ok := r.Ordered(isolatedTx)
@@ -196,7 +196,7 @@ func TestIsolatedEmptyBatch(t *testing.T) {
196196

197197
func TestIsolatedPartialBatch(t *testing.T) {
198198
filters := getFilters()
199-
batchSize := 2
199+
batchSize := uint32(2)
200200
r := NewReceiverImpl(&mocksharedconfig.Manager{BatchSizeVal: batchSize}, filters)
201201

202202
batches, committers, ok := r.Ordered(goodTx)

orderer/common/bootstrap/static/static.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type bootstrapper struct {
3838
lastModified uint64
3939
epoch uint64
4040
consensusType string
41-
batchSize int32
41+
batchSize uint32
4242
}
4343

4444
const (

orderer/common/sharedconfig/sharedconfig.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type Manager interface {
5050
ConsensusType() string
5151

5252
// BatchSize returns the maximum number of messages to include in a block
53-
BatchSize() int
53+
BatchSize() uint32
5454

5555
// ChainCreators returns the policy names which are allowed for chain creation
5656
// This field is only set for the system ordering chain
@@ -59,7 +59,7 @@ type Manager interface {
5959

6060
type ordererConfig struct {
6161
consensusType string
62-
batchSize int
62+
batchSize uint32
6363
chainCreators []string
6464
}
6565

@@ -83,7 +83,7 @@ func (pm *ManagerImpl) ConsensusType() string {
8383
}
8484

8585
// BatchSize returns the maximum number of messages to include in a block
86-
func (pm *ManagerImpl) BatchSize() int {
86+
func (pm *ManagerImpl) BatchSize() uint32 {
8787
return pm.config.batchSize
8888
}
8989

@@ -148,7 +148,7 @@ func (pm *ManagerImpl) ProposeConfig(configItem *cb.ConfigurationItem) error {
148148
return fmt.Errorf("Attempted to set the batch size to %d which is less than or equal to 0", batchSize.Messages)
149149
}
150150

151-
pm.pendingConfig.batchSize = int(batchSize.Messages)
151+
pm.pendingConfig.batchSize = batchSize.Messages
152152
case ChainCreatorsKey:
153153
chainCreators := &ab.ChainCreators{}
154154
err := proto.Unmarshal(configItem.Value, chainCreators)

orderer/common/sharedconfig/sharedconfig_test.go

+2-12
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func TestConsensusType(t *testing.T) {
127127
}
128128

129129
func TestBatchSize(t *testing.T) {
130-
endBatchSize := 10
130+
endBatchSize := uint32(10)
131131
invalidMessage :=
132132
&cb.ConfigurationItem{
133133
Type: cb.ConfigurationItem_Orderer,
@@ -139,15 +139,10 @@ func TestBatchSize(t *testing.T) {
139139
Key: BatchSizeKey,
140140
Value: utils.MarshalOrPanic(&ab.BatchSize{Messages: 0}),
141141
}
142-
negativeBatchSize := &cb.ConfigurationItem{
143-
Type: cb.ConfigurationItem_Orderer,
144-
Key: BatchSizeKey,
145-
Value: utils.MarshalOrPanic(&ab.BatchSize{Messages: -1}),
146-
}
147142
validMessage := &cb.ConfigurationItem{
148143
Type: cb.ConfigurationItem_Orderer,
149144
Key: BatchSizeKey,
150-
Value: utils.MarshalOrPanic(&ab.BatchSize{Messages: int32(endBatchSize)}),
145+
Value: utils.MarshalOrPanic(&ab.BatchSize{Messages: endBatchSize}),
151146
}
152147
m := NewManagerImpl()
153148
m.BeginConfig()
@@ -167,11 +162,6 @@ func TestBatchSize(t *testing.T) {
167162
t.Fatalf("Should have rejected batch size of 0")
168163
}
169164

170-
err = m.ProposeConfig(negativeBatchSize)
171-
if err == nil {
172-
t.Fatalf("Should have rejected negative batch size")
173-
}
174-
175165
m.CommitConfig()
176166

177167
if nowBatchSize := m.BatchSize(); nowBatchSize != endBatchSize {

orderer/kafka/broadcast.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (b *broadcasterImpl) sendBlock() error {
109109
return b.producer.Send(blockBytes)
110110
}
111111

112-
func (b *broadcasterImpl) cutBlock(period time.Duration, maxSize uint) {
112+
func (b *broadcasterImpl) cutBlock(period time.Duration, maxSize uint32) {
113113
timer := time.NewTimer(period)
114114

115115
for {

orderer/localconfig/config.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ type General struct {
4242
OrdererType string
4343
LedgerType string
4444
BatchTimeout time.Duration
45-
BatchSize uint
46-
QueueSize uint
47-
MaxWindowSize uint
45+
BatchSize uint32
46+
QueueSize uint32
47+
MaxWindowSize uint32
4848
ListenAddress string
4949
ListenPort uint16
5050
GenesisMethod string

orderer/mocks/sharedconfig/sharedconfig.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Manager struct {
2121
// ConsensusTypeVal is returned as the result of ConsensusType()
2222
ConsensusTypeVal string
2323
// BatchSizeVal is returned as the result of BatchSize()
24-
BatchSizeVal int
24+
BatchSizeVal uint32
2525
// ChainCreatorsVal is returned as the result of ChainCreators()
2626
ChainCreatorsVal []string
2727
}
@@ -32,7 +32,7 @@ func (scm *Manager) ConsensusType() string {
3232
}
3333

3434
// BatchSize returns the BatchSizeVal
35-
func (scm *Manager) BatchSize() int {
35+
func (scm *Manager) BatchSize() uint32 {
3636
return scm.BatchSizeVal
3737
}
3838

orderer/multichain/systemchain_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (msc *mockSharedConfig) ConsensusType() string {
5454
panic("Unimplemented")
5555
}
5656

57-
func (msc *mockSharedConfig) BatchSize() int {
57+
func (msc *mockSharedConfig) BatchSize() uint32 {
5858
panic("Unimplemented")
5959
}
6060

protos/orderer/configuration.pb.go

+17-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protos/orderer/configuration.proto

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ message ConsensusType {
3535

3636
message BatchSize {
3737
// Simply specified as messages for now, in the future we may want to allow this to be specified by size in bytes
38-
int32 messages = 1;
38+
uint32 messages = 1;
3939
}
4040

4141
// When submitting a new chain configuration transaction to create a new chain, the first configuration

0 commit comments

Comments
 (0)