Skip to content

Commit

Permalink
Switch blockcutter to always use sharedconfig
Browse files Browse the repository at this point in the history
There was a XXX in the multichain manager to push the blockcutter
batchSize into the blockcutter via sharedconfig, rather than to pass it
at construction time.  This is necessary to be able to dynamically
change the value of the batch size after genesis.

This changeset also introduces a sharedconfig mock structure in the
orderer/mocks package as it will likely be more broadly useful to other
tests going forward.

Change-Id: I1af47c3ca62a545236efa1e03280203ec5e75a76
Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Dec 12, 2016
1 parent 1093492 commit fcd00a1
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 16 deletions.
19 changes: 10 additions & 9 deletions orderer/common/blockcutter/blockcutter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package blockcutter

import (
"github.com/hyperledger/fabric/orderer/common/filter"
"github.com/hyperledger/fabric/orderer/common/sharedconfig"
cb "github.com/hyperledger/fabric/protos/common"

"github.com/op/go-logging"
Expand All @@ -44,17 +45,17 @@ type Receiver interface {
}

type receiver struct {
batchSize int
filters *filter.RuleSet
curBatch []*cb.Envelope
batchComs []filter.Committer
sharedConfigManager sharedconfig.Manager
filters *filter.RuleSet
curBatch []*cb.Envelope
batchComs []filter.Committer
}

// NewReceiverImpl creates a Receiver implementation based on the given batchsize, filters, and configtx manager
func NewReceiverImpl(batchSize int, filters *filter.RuleSet) Receiver {
// NewReceiverImpl creates a Receiver implementation based on the given sharedconfig manager and filters
func NewReceiverImpl(sharedConfigManager sharedconfig.Manager, filters *filter.RuleSet) Receiver {
return &receiver{
batchSize: batchSize,
filters: filters,
sharedConfigManager: sharedConfigManager,
filters: filters,
}
}

Expand Down Expand Up @@ -89,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.batchSize {
if len(r.curBatch) < r.sharedConfigManager.BatchSize() {
return nil, nil, true
}

Expand Down
11 changes: 6 additions & 5 deletions orderer/common/blockcutter/blockcutter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"testing"

"github.com/hyperledger/fabric/orderer/common/filter"
"github.com/hyperledger/fabric/orderer/mocks"
cb "github.com/hyperledger/fabric/protos/common"
)

Expand Down Expand Up @@ -73,7 +74,7 @@ var unmatchedTx = &cb.Envelope{Payload: []byte("UNMATCHED")}
func TestNormalBatch(t *testing.T) {
filters := getFilters()
batchSize := 2
r := NewReceiverImpl(batchSize, filters)
r := NewReceiverImpl(&mocks.SharedConfigManager{BatchSizeVal: batchSize}, filters)

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

Expand All @@ -100,7 +101,7 @@ func TestNormalBatch(t *testing.T) {
func TestBadMessageInBatch(t *testing.T) {
filters := getFilters()
batchSize := 2
r := NewReceiverImpl(batchSize, filters)
r := NewReceiverImpl(&mocks.SharedConfigManager{BatchSizeVal: batchSize}, filters)

batches, committers, ok := r.Ordered(badTx)

Expand Down Expand Up @@ -136,7 +137,7 @@ func TestBadMessageInBatch(t *testing.T) {
func TestUnmatchedMessageInBatch(t *testing.T) {
filters := getFilters()
batchSize := 2
r := NewReceiverImpl(batchSize, filters)
r := NewReceiverImpl(&mocks.SharedConfigManager{BatchSizeVal: batchSize}, filters)

batches, committers, ok := r.Ordered(unmatchedTx)

Expand Down Expand Up @@ -172,7 +173,7 @@ func TestUnmatchedMessageInBatch(t *testing.T) {
func TestIsolatedEmptyBatch(t *testing.T) {
filters := getFilters()
batchSize := 2
r := NewReceiverImpl(batchSize, filters)
r := NewReceiverImpl(&mocks.SharedConfigManager{BatchSizeVal: batchSize}, filters)

batches, committers, ok := r.Ordered(isolatedTx)

Expand All @@ -196,7 +197,7 @@ func TestIsolatedEmptyBatch(t *testing.T) {
func TestIsolatedPartialBatch(t *testing.T) {
filters := getFilters()
batchSize := 2
r := NewReceiverImpl(batchSize, filters)
r := NewReceiverImpl(&mocks.SharedConfigManager{BatchSizeVal: batchSize}, filters)

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

Expand Down
43 changes: 43 additions & 0 deletions orderer/mocks/sharedconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Copyright IBM Corp. 2016 All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package mocks

// MockSharedConfigManager is a mock implementation of sharedconfig.Manager
type SharedConfigManager struct {
// ConsensusTypeVal is returned as the result of ConsensusType()
ConsensusTypeVal string
// BatchSizeVal is returned as the result of BatchSize()
BatchSizeVal int
// ChainCreatorsVal is returned as the result of ChainCreators()
ChainCreatorsVal []string
}

// ConsensusType returns the configured consensus type
func (scm *SharedConfigManager) ConsensusType() string {
return scm.ConsensusTypeVal
}

// BatchSize returns the maximum number of messages to include in a block
func (scm *SharedConfigManager) BatchSize() int {
return scm.BatchSizeVal
}

// ChainCreators returns the policy names which are allowed for chain creation
// This field is only set for the system ordering chain
func (scm *SharedConfigManager) ChainCreators() []string {
return scm.ChainCreatorsVal
}
27 changes: 27 additions & 0 deletions orderer/mocks/sharedconfig_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
Copyright IBM Corp. 2016 All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package mocks

import (
"testing"

"github.com/hyperledger/fabric/orderer/common/sharedconfig"
)

func TestSharedConfigInterface(t *testing.T) {
_ = sharedconfig.Manager(&SharedConfigManager{})
}
3 changes: 1 addition & 2 deletions orderer/multichain/chainsupport.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ func newChainSupport(
consenters map[string]Consenter,
) *chainSupport {

batchSize := sharedConfigManager.BatchSize() // XXX this needs to be pushed deeper so that the blockcutter queries it after each write for reconfiguration support
cutter := blockcutter.NewReceiverImpl(batchSize, filters)
cutter := blockcutter.NewReceiverImpl(sharedConfigManager, filters)
consenterType := sharedConfigManager.ConsensusType()
consenter, ok := consenters[consenterType]
if !ok {
Expand Down

0 comments on commit fcd00a1

Please sign in to comment.