Skip to content

Commit fcd00a1

Browse files
author
Jason Yellick
committed
Switch blockcutter to always use sharedconfig
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 <[email protected]>
1 parent 1093492 commit fcd00a1

File tree

5 files changed

+87
-16
lines changed

5 files changed

+87
-16
lines changed

orderer/common/blockcutter/blockcutter.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package blockcutter
1818

1919
import (
2020
"github.com/hyperledger/fabric/orderer/common/filter"
21+
"github.com/hyperledger/fabric/orderer/common/sharedconfig"
2122
cb "github.com/hyperledger/fabric/protos/common"
2223

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

4647
type receiver struct {
47-
batchSize int
48-
filters *filter.RuleSet
49-
curBatch []*cb.Envelope
50-
batchComs []filter.Committer
48+
sharedConfigManager sharedconfig.Manager
49+
filters *filter.RuleSet
50+
curBatch []*cb.Envelope
51+
batchComs []filter.Committer
5152
}
5253

53-
// NewReceiverImpl creates a Receiver implementation based on the given batchsize, filters, and configtx manager
54-
func NewReceiverImpl(batchSize int, filters *filter.RuleSet) Receiver {
54+
// NewReceiverImpl creates a Receiver implementation based on the given sharedconfig manager and filters
55+
func NewReceiverImpl(sharedConfigManager sharedconfig.Manager, filters *filter.RuleSet) Receiver {
5556
return &receiver{
56-
batchSize: batchSize,
57-
filters: filters,
57+
sharedConfigManager: sharedConfigManager,
58+
filters: filters,
5859
}
5960
}
6061

@@ -89,7 +90,7 @@ func (r *receiver) Ordered(msg *cb.Envelope) ([][]*cb.Envelope, [][]filter.Commi
8990
r.curBatch = append(r.curBatch, msg)
9091
r.batchComs = append(r.batchComs, committer)
9192

92-
if len(r.curBatch) < r.batchSize {
93+
if len(r.curBatch) < r.sharedConfigManager.BatchSize() {
9394
return nil, nil, true
9495
}
9596

orderer/common/blockcutter/blockcutter_test.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"testing"
2222

2323
"github.com/hyperledger/fabric/orderer/common/filter"
24+
"github.com/hyperledger/fabric/orderer/mocks"
2425
cb "github.com/hyperledger/fabric/protos/common"
2526
)
2627

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

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

@@ -100,7 +101,7 @@ func TestNormalBatch(t *testing.T) {
100101
func TestBadMessageInBatch(t *testing.T) {
101102
filters := getFilters()
102103
batchSize := 2
103-
r := NewReceiverImpl(batchSize, filters)
104+
r := NewReceiverImpl(&mocks.SharedConfigManager{BatchSizeVal: batchSize}, filters)
104105

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

@@ -136,7 +137,7 @@ func TestBadMessageInBatch(t *testing.T) {
136137
func TestUnmatchedMessageInBatch(t *testing.T) {
137138
filters := getFilters()
138139
batchSize := 2
139-
r := NewReceiverImpl(batchSize, filters)
140+
r := NewReceiverImpl(&mocks.SharedConfigManager{BatchSizeVal: batchSize}, filters)
140141

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

@@ -172,7 +173,7 @@ func TestUnmatchedMessageInBatch(t *testing.T) {
172173
func TestIsolatedEmptyBatch(t *testing.T) {
173174
filters := getFilters()
174175
batchSize := 2
175-
r := NewReceiverImpl(batchSize, filters)
176+
r := NewReceiverImpl(&mocks.SharedConfigManager{BatchSizeVal: batchSize}, filters)
176177

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

@@ -196,7 +197,7 @@ func TestIsolatedEmptyBatch(t *testing.T) {
196197
func TestIsolatedPartialBatch(t *testing.T) {
197198
filters := getFilters()
198199
batchSize := 2
199-
r := NewReceiverImpl(batchSize, filters)
200+
r := NewReceiverImpl(&mocks.SharedConfigManager{BatchSizeVal: batchSize}, filters)
200201

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

orderer/mocks/sharedconfig.go

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Copyright IBM Corp. 2016 All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package mocks
18+
19+
// MockSharedConfigManager is a mock implementation of sharedconfig.Manager
20+
type SharedConfigManager struct {
21+
// ConsensusTypeVal is returned as the result of ConsensusType()
22+
ConsensusTypeVal string
23+
// BatchSizeVal is returned as the result of BatchSize()
24+
BatchSizeVal int
25+
// ChainCreatorsVal is returned as the result of ChainCreators()
26+
ChainCreatorsVal []string
27+
}
28+
29+
// ConsensusType returns the configured consensus type
30+
func (scm *SharedConfigManager) ConsensusType() string {
31+
return scm.ConsensusTypeVal
32+
}
33+
34+
// BatchSize returns the maximum number of messages to include in a block
35+
func (scm *SharedConfigManager) BatchSize() int {
36+
return scm.BatchSizeVal
37+
}
38+
39+
// ChainCreators returns the policy names which are allowed for chain creation
40+
// This field is only set for the system ordering chain
41+
func (scm *SharedConfigManager) ChainCreators() []string {
42+
return scm.ChainCreatorsVal
43+
}

orderer/mocks/sharedconfig_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
Copyright IBM Corp. 2016 All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package mocks
18+
19+
import (
20+
"testing"
21+
22+
"github.com/hyperledger/fabric/orderer/common/sharedconfig"
23+
)
24+
25+
func TestSharedConfigInterface(t *testing.T) {
26+
_ = sharedconfig.Manager(&SharedConfigManager{})
27+
}

orderer/multichain/chainsupport.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ func newChainSupport(
9494
consenters map[string]Consenter,
9595
) *chainSupport {
9696

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

0 commit comments

Comments
 (0)