diff --git a/orderer/common/blockcutter/blockcutter.go b/orderer/common/blockcutter/blockcutter.go index ff318ea2a80..facd72866d7 100644 --- a/orderer/common/blockcutter/blockcutter.go +++ b/orderer/common/blockcutter/blockcutter.go @@ -90,7 +90,7 @@ func (r *receiver) Ordered(msg *cb.Envelope) ([][]*cb.Envelope, [][]filter.Commi r.curBatch = append(r.curBatch, msg) r.batchComs = append(r.batchComs, committer) - if len(r.curBatch) < r.sharedConfigManager.BatchSize() { + if uint32(len(r.curBatch)) < r.sharedConfigManager.BatchSize() { return nil, nil, true } diff --git a/orderer/common/blockcutter/blockcutter_test.go b/orderer/common/blockcutter/blockcutter_test.go index fd8e153cc18..d20d66128c0 100644 --- a/orderer/common/blockcutter/blockcutter_test.go +++ b/orderer/common/blockcutter/blockcutter_test.go @@ -73,7 +73,7 @@ var unmatchedTx = &cb.Envelope{Payload: []byte("UNMATCHED")} func TestNormalBatch(t *testing.T) { filters := getFilters() - batchSize := 2 + batchSize := uint32(2) r := NewReceiverImpl(&mocksharedconfig.Manager{BatchSizeVal: batchSize}, filters) batches, committers, ok := r.Ordered(goodTx) @@ -100,7 +100,7 @@ func TestNormalBatch(t *testing.T) { func TestBadMessageInBatch(t *testing.T) { filters := getFilters() - batchSize := 2 + batchSize := uint32(2) r := NewReceiverImpl(&mocksharedconfig.Manager{BatchSizeVal: batchSize}, filters) batches, committers, ok := r.Ordered(badTx) @@ -136,7 +136,7 @@ func TestBadMessageInBatch(t *testing.T) { func TestUnmatchedMessageInBatch(t *testing.T) { filters := getFilters() - batchSize := 2 + batchSize := uint32(2) r := NewReceiverImpl(&mocksharedconfig.Manager{BatchSizeVal: batchSize}, filters) batches, committers, ok := r.Ordered(unmatchedTx) @@ -172,7 +172,7 @@ func TestUnmatchedMessageInBatch(t *testing.T) { func TestIsolatedEmptyBatch(t *testing.T) { filters := getFilters() - batchSize := 2 + batchSize := uint32(2) r := NewReceiverImpl(&mocksharedconfig.Manager{BatchSizeVal: batchSize}, filters) batches, committers, ok := r.Ordered(isolatedTx) @@ -196,7 +196,7 @@ func TestIsolatedEmptyBatch(t *testing.T) { func TestIsolatedPartialBatch(t *testing.T) { filters := getFilters() - batchSize := 2 + batchSize := uint32(2) r := NewReceiverImpl(&mocksharedconfig.Manager{BatchSizeVal: batchSize}, filters) batches, committers, ok := r.Ordered(goodTx) diff --git a/orderer/common/bootstrap/static/static.go b/orderer/common/bootstrap/static/static.go index 75ba08bd223..22a7a1a3678 100644 --- a/orderer/common/bootstrap/static/static.go +++ b/orderer/common/bootstrap/static/static.go @@ -38,7 +38,7 @@ type bootstrapper struct { lastModified uint64 epoch uint64 consensusType string - batchSize int32 + batchSize uint32 } const ( diff --git a/orderer/common/sharedconfig/sharedconfig.go b/orderer/common/sharedconfig/sharedconfig.go index 630f7e642d1..db56f356b84 100644 --- a/orderer/common/sharedconfig/sharedconfig.go +++ b/orderer/common/sharedconfig/sharedconfig.go @@ -50,7 +50,7 @@ type Manager interface { ConsensusType() string // BatchSize returns the maximum number of messages to include in a block - BatchSize() int + BatchSize() uint32 // ChainCreators returns the policy names which are allowed for chain creation // This field is only set for the system ordering chain @@ -59,7 +59,7 @@ type Manager interface { type ordererConfig struct { consensusType string - batchSize int + batchSize uint32 chainCreators []string } @@ -83,7 +83,7 @@ func (pm *ManagerImpl) ConsensusType() string { } // BatchSize returns the maximum number of messages to include in a block -func (pm *ManagerImpl) BatchSize() int { +func (pm *ManagerImpl) BatchSize() uint32 { return pm.config.batchSize } @@ -148,7 +148,7 @@ func (pm *ManagerImpl) ProposeConfig(configItem *cb.ConfigurationItem) error { return fmt.Errorf("Attempted to set the batch size to %d which is less than or equal to 0", batchSize.Messages) } - pm.pendingConfig.batchSize = int(batchSize.Messages) + pm.pendingConfig.batchSize = batchSize.Messages case ChainCreatorsKey: chainCreators := &ab.ChainCreators{} err := proto.Unmarshal(configItem.Value, chainCreators) diff --git a/orderer/common/sharedconfig/sharedconfig_test.go b/orderer/common/sharedconfig/sharedconfig_test.go index 7b82cb989e6..40d4fc491a9 100644 --- a/orderer/common/sharedconfig/sharedconfig_test.go +++ b/orderer/common/sharedconfig/sharedconfig_test.go @@ -127,7 +127,7 @@ func TestConsensusType(t *testing.T) { } func TestBatchSize(t *testing.T) { - endBatchSize := 10 + endBatchSize := uint32(10) invalidMessage := &cb.ConfigurationItem{ Type: cb.ConfigurationItem_Orderer, @@ -139,15 +139,10 @@ func TestBatchSize(t *testing.T) { Key: BatchSizeKey, Value: utils.MarshalOrPanic(&ab.BatchSize{Messages: 0}), } - negativeBatchSize := &cb.ConfigurationItem{ - Type: cb.ConfigurationItem_Orderer, - Key: BatchSizeKey, - Value: utils.MarshalOrPanic(&ab.BatchSize{Messages: -1}), - } validMessage := &cb.ConfigurationItem{ Type: cb.ConfigurationItem_Orderer, Key: BatchSizeKey, - Value: utils.MarshalOrPanic(&ab.BatchSize{Messages: int32(endBatchSize)}), + Value: utils.MarshalOrPanic(&ab.BatchSize{Messages: endBatchSize}), } m := NewManagerImpl() m.BeginConfig() @@ -167,11 +162,6 @@ func TestBatchSize(t *testing.T) { t.Fatalf("Should have rejected batch size of 0") } - err = m.ProposeConfig(negativeBatchSize) - if err == nil { - t.Fatalf("Should have rejected negative batch size") - } - m.CommitConfig() if nowBatchSize := m.BatchSize(); nowBatchSize != endBatchSize { diff --git a/orderer/kafka/broadcast.go b/orderer/kafka/broadcast.go index fb4f28ecd61..c24f5f64dc2 100644 --- a/orderer/kafka/broadcast.go +++ b/orderer/kafka/broadcast.go @@ -109,7 +109,7 @@ func (b *broadcasterImpl) sendBlock() error { return b.producer.Send(blockBytes) } -func (b *broadcasterImpl) cutBlock(period time.Duration, maxSize uint) { +func (b *broadcasterImpl) cutBlock(period time.Duration, maxSize uint32) { timer := time.NewTimer(period) for { diff --git a/orderer/localconfig/config.go b/orderer/localconfig/config.go index 251029bc10f..ec3d17ea18f 100644 --- a/orderer/localconfig/config.go +++ b/orderer/localconfig/config.go @@ -42,9 +42,9 @@ type General struct { OrdererType string LedgerType string BatchTimeout time.Duration - BatchSize uint - QueueSize uint - MaxWindowSize uint + BatchSize uint32 + QueueSize uint32 + MaxWindowSize uint32 ListenAddress string ListenPort uint16 GenesisMethod string diff --git a/orderer/mocks/sharedconfig/sharedconfig.go b/orderer/mocks/sharedconfig/sharedconfig.go index 4349f47bf9e..e86b4acbc58 100644 --- a/orderer/mocks/sharedconfig/sharedconfig.go +++ b/orderer/mocks/sharedconfig/sharedconfig.go @@ -21,7 +21,7 @@ type Manager struct { // ConsensusTypeVal is returned as the result of ConsensusType() ConsensusTypeVal string // BatchSizeVal is returned as the result of BatchSize() - BatchSizeVal int + BatchSizeVal uint32 // ChainCreatorsVal is returned as the result of ChainCreators() ChainCreatorsVal []string } @@ -32,7 +32,7 @@ func (scm *Manager) ConsensusType() string { } // BatchSize returns the BatchSizeVal -func (scm *Manager) BatchSize() int { +func (scm *Manager) BatchSize() uint32 { return scm.BatchSizeVal } diff --git a/orderer/multichain/systemchain_test.go b/orderer/multichain/systemchain_test.go index 115f1f39f7a..f8270e73a06 100644 --- a/orderer/multichain/systemchain_test.go +++ b/orderer/multichain/systemchain_test.go @@ -54,7 +54,7 @@ func (msc *mockSharedConfig) ConsensusType() string { panic("Unimplemented") } -func (msc *mockSharedConfig) BatchSize() int { +func (msc *mockSharedConfig) BatchSize() uint32 { panic("Unimplemented") } diff --git a/protos/orderer/configuration.pb.go b/protos/orderer/configuration.pb.go index 1fe04e05fa6..b42d596d42b 100644 --- a/protos/orderer/configuration.pb.go +++ b/protos/orderer/configuration.pb.go @@ -25,7 +25,7 @@ func (*ConsensusType) Descriptor() ([]byte, []int) { return fileDescriptor1, []i type BatchSize struct { // Simply specified as messages for now, in the future we may want to allow this to be specified by size in bytes - Messages int32 `protobuf:"varint,1,opt,name=messages" json:"messages,omitempty"` + Messages uint32 `protobuf:"varint,1,opt,name=messages" json:"messages,omitempty"` } func (m *BatchSize) Reset() { *m = BatchSize{} } @@ -69,20 +69,20 @@ func init() { func init() { proto.RegisterFile("orderer/configuration.proto", fileDescriptor1) } var fileDescriptor1 = []byte{ - // 237 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x3c, 0x90, 0xc1, 0x4e, 0xf3, 0x30, - 0x10, 0x84, 0x95, 0xff, 0x87, 0x42, 0x2c, 0xca, 0xc1, 0x48, 0xa8, 0x2a, 0x97, 0x2a, 0x1c, 0x88, - 0x04, 0x8a, 0x0f, 0xbc, 0x00, 0x6a, 0x5e, 0x00, 0x05, 0x4e, 0xdc, 0x1c, 0x67, 0xeb, 0x58, 0x6a, - 0xbc, 0xd6, 0xda, 0x39, 0x84, 0xa7, 0x47, 0xdd, 0x5a, 0x3d, 0x79, 0x3e, 0x8f, 0x3d, 0xa3, 0x5d, - 0xf1, 0x84, 0x34, 0x00, 0x01, 0x29, 0x83, 0xfe, 0xe0, 0xec, 0x4c, 0x3a, 0x39, 0xf4, 0x4d, 0x20, - 0x4c, 0x28, 0x6f, 0xb2, 0xb9, 0x7d, 0x30, 0x38, 0x4d, 0xe8, 0xd5, 0xf9, 0x38, 0xbb, 0xd5, 0xb3, - 0x58, 0xb7, 0xe8, 0x23, 0xf8, 0x38, 0xc7, 0xef, 0x25, 0x80, 0x94, 0xe2, 0x2a, 0x2d, 0x01, 0x36, - 0xc5, 0xae, 0xa8, 0xcb, 0x8e, 0x75, 0xf5, 0x22, 0xca, 0xbd, 0x4e, 0x66, 0xfc, 0x72, 0xbf, 0x20, - 0xb7, 0xe2, 0x76, 0x82, 0x18, 0xb5, 0x85, 0xc8, 0x8f, 0xae, 0xbb, 0x0b, 0x57, 0x1f, 0xe2, 0xbe, - 0x25, 0xe0, 0xf6, 0x4f, 0x3c, 0x3a, 0xb3, 0xc8, 0x47, 0xb1, 0x0a, 0xac, 0x72, 0x60, 0xa6, 0xd3, - 0xfd, 0xe0, 0x2c, 0xc4, 0xb4, 0xf9, 0xb7, 0x2b, 0xea, 0xbb, 0x2e, 0x53, 0xf5, 0x2a, 0xd6, 0xed, - 0xa8, 0x9d, 0xe7, 0x18, 0xa4, 0x78, 0xaa, 0xe3, 0x2f, 0x8e, 0xeb, 0xfe, 0xd7, 0x65, 0x77, 0xe1, - 0x7d, 0xf3, 0xf3, 0x66, 0x5d, 0x1a, 0xe7, 0xbe, 0x31, 0x38, 0xa9, 0x71, 0x09, 0x40, 0x47, 0x18, - 0x2c, 0x90, 0x3a, 0xe8, 0x9e, 0x9c, 0x51, 0x3c, 0x63, 0x54, 0x79, 0x03, 0xfd, 0x8a, 0xf9, 0xfd, - 0x2f, 0x00, 0x00, 0xff, 0xff, 0xbe, 0x3d, 0xf4, 0x97, 0x30, 0x01, 0x00, 0x00, + // 236 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x3c, 0x90, 0x41, 0x4b, 0xc4, 0x30, + 0x10, 0x85, 0x59, 0x95, 0xd5, 0x06, 0xeb, 0x21, 0x82, 0x2c, 0xeb, 0x65, 0xa9, 0x07, 0x0b, 0x4a, + 0x73, 0xf0, 0x0f, 0xc8, 0xf6, 0x0f, 0x48, 0xf5, 0xe4, 0x2d, 0x4d, 0x67, 0xd3, 0xc0, 0x36, 0x13, + 0x26, 0xe9, 0xa1, 0xfe, 0x7a, 0xd9, 0xd9, 0xb0, 0xa7, 0xbc, 0x2f, 0x2f, 0x79, 0x8f, 0x19, 0xf1, + 0x8c, 0x34, 0x00, 0x01, 0x29, 0x83, 0xfe, 0xe0, 0xec, 0x4c, 0x3a, 0x39, 0xf4, 0x4d, 0x20, 0x4c, + 0x28, 0x6f, 0xb3, 0xb9, 0x7d, 0x34, 0x38, 0x4d, 0xe8, 0xd5, 0xf9, 0x38, 0xbb, 0xd5, 0x8b, 0x28, + 0x5b, 0xf4, 0x11, 0x7c, 0x9c, 0xe3, 0xcf, 0x12, 0x40, 0x4a, 0x71, 0x93, 0x96, 0x00, 0x9b, 0xd5, + 0x6e, 0x55, 0x17, 0x1d, 0xeb, 0xea, 0x55, 0x14, 0x7b, 0x9d, 0xcc, 0xf8, 0xed, 0xfe, 0x40, 0x6e, + 0xc5, 0xdd, 0x04, 0x31, 0x6a, 0x0b, 0x91, 0x1f, 0x95, 0xdd, 0x85, 0xab, 0x4f, 0xf1, 0xd0, 0x12, + 0x70, 0xfb, 0x17, 0x1e, 0x9d, 0x59, 0xe4, 0x93, 0x58, 0x07, 0x56, 0x39, 0x30, 0xd3, 0xe9, 0x7e, + 0x70, 0x16, 0x62, 0xda, 0x5c, 0xed, 0x56, 0xf5, 0x7d, 0x97, 0xa9, 0x7a, 0x13, 0x65, 0x3b, 0x6a, + 0xe7, 0x39, 0x06, 0x29, 0x9e, 0xea, 0xf8, 0x8b, 0xe3, 0xba, 0xeb, 0xba, 0xe8, 0x2e, 0xbc, 0x6f, + 0x7e, 0xdf, 0xad, 0x4b, 0xe3, 0xdc, 0x37, 0x06, 0x27, 0x35, 0x2e, 0x01, 0xe8, 0x08, 0x83, 0x05, + 0x52, 0x07, 0xdd, 0x93, 0x33, 0x8a, 0x67, 0x8c, 0x2a, 0x6f, 0xa0, 0x5f, 0x33, 0x7f, 0xfc, 0x07, + 0x00, 0x00, 0xff, 0xff, 0x8b, 0x76, 0xe7, 0x02, 0x30, 0x01, 0x00, 0x00, } diff --git a/protos/orderer/configuration.proto b/protos/orderer/configuration.proto index 1ade0e39e6f..b095ce519df 100644 --- a/protos/orderer/configuration.proto +++ b/protos/orderer/configuration.proto @@ -35,7 +35,7 @@ message ConsensusType { message BatchSize { // Simply specified as messages for now, in the future we may want to allow this to be specified by size in bytes - int32 messages = 1; + uint32 messages = 1; } // When submitting a new chain configuration transaction to create a new chain, the first configuration