Skip to content

Commit

Permalink
[FAB-1358] Convert all batchSize refs to uint32
Browse files Browse the repository at this point in the history
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 <kostas@christidis.io>
  • Loading branch information
kchristidis committed Dec 13, 2016
1 parent fe16a6d commit addfd4d
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 48 deletions.
2 changes: 1 addition & 1 deletion orderer/common/blockcutter/blockcutter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
10 changes: 5 additions & 5 deletions orderer/common/blockcutter/blockcutter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion orderer/common/bootstrap/static/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type bootstrapper struct {
lastModified uint64
epoch uint64
consensusType string
batchSize int32
batchSize uint32
}

const (
Expand Down
8 changes: 4 additions & 4 deletions orderer/common/sharedconfig/sharedconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -59,7 +59,7 @@ type Manager interface {

type ordererConfig struct {
consensusType string
batchSize int
batchSize uint32
chainCreators []string
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down
14 changes: 2 additions & 12 deletions orderer/common/sharedconfig/sharedconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion orderer/kafka/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions orderer/localconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions orderer/mocks/sharedconfig/sharedconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion orderer/multichain/systemchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (msc *mockSharedConfig) ConsensusType() string {
panic("Unimplemented")
}

func (msc *mockSharedConfig) BatchSize() int {
func (msc *mockSharedConfig) BatchSize() uint32 {
panic("Unimplemented")
}

Expand Down
34 changes: 17 additions & 17 deletions protos/orderer/configuration.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion protos/orderer/configuration.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit addfd4d

Please sign in to comment.