Skip to content

Commit 3b320c6

Browse files
author
Jason Yellick
committed
[FAB-2101] Move orderer sharedconfig to common
https://jira.hyperledger.org/browse/FAB-2101 It has always been somewhat problematic that orderer config generation is done in the orderer package, even though other pieces of the system depend on it. This CR moves the orderer shared config definitions to the common package. This is necessary to define a config schema going forward in order to lock down the pending more flexible configuration format. Change-Id: I1b1a4c78eedbc18a90d6838af0829950d6d88e72 Signed-off-by: Jason Yellick <[email protected]>
1 parent 14e3a11 commit 3b320c6

File tree

18 files changed

+108
-109
lines changed

18 files changed

+108
-109
lines changed

common/configtx/api/api.go

+30
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,42 @@ limitations under the License.
1717
package api
1818

1919
import (
20+
"time"
21+
2022
"github.com/hyperledger/fabric/common/chainconfig"
2123
"github.com/hyperledger/fabric/common/policies"
2224
"github.com/hyperledger/fabric/msp"
2325
cb "github.com/hyperledger/fabric/protos/common"
26+
ab "github.com/hyperledger/fabric/protos/orderer"
2427
)
2528

29+
// OrdererConfig stores the common shared orderer config
30+
type OrdererConfig interface {
31+
// ConsensusType returns the configured consensus type
32+
ConsensusType() string
33+
34+
// BatchSize returns the maximum number of messages to include in a block
35+
BatchSize() *ab.BatchSize
36+
37+
// BatchTimeout returns the amount of time to wait before creating a batch
38+
BatchTimeout() time.Duration
39+
40+
// ChainCreationPolicyNames returns the policy names which are allowed for chain creation
41+
// This field is only set for the system ordering chain
42+
ChainCreationPolicyNames() []string
43+
44+
// KafkaBrokers returns the addresses (IP:port notation) of a set of "bootstrap"
45+
// Kafka brokers, i.e. this is not necessarily the entire set of Kafka brokers
46+
// used for ordering
47+
KafkaBrokers() []string
48+
49+
// IngressPolicyNames returns the name of the policy to validate incoming broadcast messages against
50+
IngressPolicyNames() []string
51+
52+
// EgressPolicyNames returns the name of the policy to validate incoming broadcast messages against
53+
EgressPolicyNames() []string
54+
}
55+
2656
// Handler provides a hook which allows other pieces of code to participate in config proposals
2757
type Handler interface {
2858
// BeginConfig called when a config proposal is begun

orderer/common/sharedconfig/sharedconfig.go common/configtx/handlers/orderer/sharedconfig.go

+4-35
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package sharedconfig
17+
package orderer
1818

1919
import (
2020
"fmt"
@@ -53,37 +53,7 @@ const (
5353
EgressPolicyNamesKey = "EgressPolicyNames"
5454
)
5555

56-
var logger = logging.MustGetLogger("orderer/common/sharedconfig")
57-
58-
// Manager stores the common shared orderer config
59-
// It is intended to be the primary accessor of ManagerImpl
60-
// It is intended to discourage use of the other exported ManagerImpl methods
61-
// which are used for updating the orderer config by the ConfigManager
62-
type Manager interface {
63-
// ConsensusType returns the configured consensus type
64-
ConsensusType() string
65-
66-
// BatchSize returns the maximum number of messages to include in a block
67-
BatchSize() *ab.BatchSize
68-
69-
// BatchTimeout returns the amount of time to wait before creating a batch
70-
BatchTimeout() time.Duration
71-
72-
// ChainCreationPolicyNames returns the policy names which are allowed for chain creation
73-
// This field is only set for the system ordering chain
74-
ChainCreationPolicyNames() []string
75-
76-
// KafkaBrokers returns the addresses (IP:port notation) of a set of "bootstrap"
77-
// Kafka brokers, i.e. this is not necessarily the entire set of Kafka brokers
78-
// used for ordering
79-
KafkaBrokers() []string
80-
81-
// IngressPolicyNames returns the name of the policy to validate incoming broadcast messages against
82-
IngressPolicyNames() []string
83-
84-
// EgressPolicyNames returns the name of the policy to validate incoming broadcast messages against
85-
EgressPolicyNames() []string
86-
}
56+
var logger = logging.MustGetLogger("configtx/handlers/orderer")
8757

8858
type ordererConfig struct {
8959
consensusType string
@@ -95,14 +65,13 @@ type ordererConfig struct {
9565
egressPolicyNames []string
9666
}
9767

98-
// ManagerImpl is an implementation of Manager and configtx.ConfigHandler
99-
// In general, it should only be referenced as an Impl for the configtx.ConfigManager
68+
// ManagerImpl is an implementation of configtxapi.OrdererConfig and configtxapi.Handler
10069
type ManagerImpl struct {
10170
pendingConfig *ordererConfig
10271
config *ordererConfig
10372
}
10473

105-
// NewManagerImpl creates a new ManagerImpl with the given CryptoHelper
74+
// NewManagerImpl creates a new ManagerImpl
10675
func NewManagerImpl() *ManagerImpl {
10776
return &ManagerImpl{
10877
config: &ordererConfig{},

orderer/common/sharedconfig/sharedconfig_test.go common/configtx/handlers/orderer/sharedconfig_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package sharedconfig
17+
package orderer
1818

1919
import (
2020
"os"

orderer/common/sharedconfig/sharedconfig_util.go common/configtx/handlers/orderer/sharedconfig_util.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package sharedconfig
17+
package orderer
1818

1919
import (
2020
cb "github.com/hyperledger/fabric/protos/common"

orderer/mocks/sharedconfig/sharedconfig.go common/mocks/configtx/handlers/orderer/sharedconfig.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ package sharedconfig
1919
import ab "github.com/hyperledger/fabric/protos/orderer"
2020
import "time"
2121

22-
// Manager is a mock implementation of sharedconfig.Manager
23-
type Manager struct {
22+
// SharedConfig is a mock implementation of sharedconfig.SharedConfig
23+
type SharedConfig struct {
2424
// ConsensusTypeVal is returned as the result of ConsensusType()
2525
ConsensusTypeVal string
2626
// BatchSizeVal is returned as the result of BatchSize()
@@ -38,36 +38,36 @@ type Manager struct {
3838
}
3939

4040
// ConsensusType returns the ConsensusTypeVal
41-
func (scm *Manager) ConsensusType() string {
41+
func (scm *SharedConfig) ConsensusType() string {
4242
return scm.ConsensusTypeVal
4343
}
4444

4545
// BatchSize returns the BatchSizeVal
46-
func (scm *Manager) BatchSize() *ab.BatchSize {
46+
func (scm *SharedConfig) BatchSize() *ab.BatchSize {
4747
return scm.BatchSizeVal
4848
}
4949

5050
// BatchTimeout returns the BatchTimeoutVal
51-
func (scm *Manager) BatchTimeout() time.Duration {
51+
func (scm *SharedConfig) BatchTimeout() time.Duration {
5252
return scm.BatchTimeoutVal
5353
}
5454

5555
// ChainCreationPolicyNames returns the ChainCreationPolicyNamesVal
56-
func (scm *Manager) ChainCreationPolicyNames() []string {
56+
func (scm *SharedConfig) ChainCreationPolicyNames() []string {
5757
return scm.ChainCreationPolicyNamesVal
5858
}
5959

6060
// KafkaBrokers returns the KafkaBrokersVal
61-
func (scm *Manager) KafkaBrokers() []string {
61+
func (scm *SharedConfig) KafkaBrokers() []string {
6262
return scm.KafkaBrokersVal
6363
}
6464

6565
// IngressPolicyNames returns the IngressPolicyNamesVal
66-
func (scm *Manager) IngressPolicyNames() []string {
66+
func (scm *SharedConfig) IngressPolicyNames() []string {
6767
return scm.IngressPolicyNamesVal
6868
}
6969

7070
// EgressPolicyNames returns the EgressPolicyNamesVal
71-
func (scm *Manager) EgressPolicyNames() []string {
71+
func (scm *SharedConfig) EgressPolicyNames() []string {
7272
return scm.EgressPolicyNamesVal
7373
}

orderer/mocks/sharedconfig/sharedconfig_test.go common/mocks/configtx/handlers/orderer/sharedconfig_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ package sharedconfig
1919
import (
2020
"testing"
2121

22-
"github.com/hyperledger/fabric/orderer/common/sharedconfig"
22+
configtxapi "github.com/hyperledger/fabric/common/configtx/api"
2323
)
2424

2525
func TestSharedConfigInterface(t *testing.T) {
26-
_ = sharedconfig.Manager(&Manager{})
26+
_ = configtxapi.OrdererConfig(&SharedConfig{})
2727
}

orderer/common/blockcutter/blockcutter.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ limitations under the License.
1717
package blockcutter
1818

1919
import (
20+
configtxapi "github.com/hyperledger/fabric/common/configtx/api"
2021
"github.com/hyperledger/fabric/orderer/common/filter"
21-
"github.com/hyperledger/fabric/orderer/common/sharedconfig"
2222
cb "github.com/hyperledger/fabric/protos/common"
2323

2424
"github.com/op/go-logging"
@@ -52,15 +52,15 @@ type Receiver interface {
5252
}
5353

5454
type receiver struct {
55-
sharedConfigManager sharedconfig.Manager
55+
sharedConfigManager configtxapi.OrdererConfig
5656
filters *filter.RuleSet
5757
pendingBatch []*cb.Envelope
5858
pendingBatchSizeBytes uint32
5959
pendingCommitters []filter.Committer
6060
}
6161

62-
// NewReceiverImpl creates a Receiver implementation based on the given sharedconfig manager and filters
63-
func NewReceiverImpl(sharedConfigManager sharedconfig.Manager, filters *filter.RuleSet) Receiver {
62+
// NewReceiverImpl creates a Receiver implementation based on the given configtxorderer manager and filters
63+
func NewReceiverImpl(sharedConfigManager configtxapi.OrdererConfig, filters *filter.RuleSet) Receiver {
6464
return &receiver{
6565
sharedConfigManager: sharedConfigManager,
6666
filters: filters,

orderer/common/blockcutter/blockcutter_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
"bytes"
2121
"testing"
2222

23+
mockconfigtxorderer "github.com/hyperledger/fabric/common/mocks/configtx/handlers/orderer"
2324
"github.com/hyperledger/fabric/orderer/common/filter"
24-
mocksharedconfig "github.com/hyperledger/fabric/orderer/mocks/sharedconfig"
2525
cb "github.com/hyperledger/fabric/protos/common"
2626
ab "github.com/hyperledger/fabric/protos/orderer"
2727
logging "github.com/op/go-logging"
@@ -83,7 +83,7 @@ func TestNormalBatch(t *testing.T) {
8383
maxMessageCount := uint32(2)
8484
absoluteMaxBytes := uint32(1000)
8585
preferredMaxBytes := uint32(100)
86-
r := NewReceiverImpl(&mocksharedconfig.Manager{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: absoluteMaxBytes, PreferredMaxBytes: preferredMaxBytes}}, filters)
86+
r := NewReceiverImpl(&mockconfigtxorderer.SharedConfig{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: absoluteMaxBytes, PreferredMaxBytes: preferredMaxBytes}}, filters)
8787

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

@@ -112,7 +112,7 @@ func TestBadMessageInBatch(t *testing.T) {
112112
maxMessageCount := uint32(2)
113113
absoluteMaxBytes := uint32(1000)
114114
preferredMaxBytes := uint32(100)
115-
r := NewReceiverImpl(&mocksharedconfig.Manager{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: absoluteMaxBytes, PreferredMaxBytes: preferredMaxBytes}}, filters)
115+
r := NewReceiverImpl(&mockconfigtxorderer.SharedConfig{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: absoluteMaxBytes, PreferredMaxBytes: preferredMaxBytes}}, filters)
116116

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

@@ -150,7 +150,7 @@ func TestUnmatchedMessageInBatch(t *testing.T) {
150150
maxMessageCount := uint32(2)
151151
absoluteMaxBytes := uint32(1000)
152152
preferredMaxBytes := uint32(100)
153-
r := NewReceiverImpl(&mocksharedconfig.Manager{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: absoluteMaxBytes, PreferredMaxBytes: preferredMaxBytes}}, filters)
153+
r := NewReceiverImpl(&mockconfigtxorderer.SharedConfig{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: absoluteMaxBytes, PreferredMaxBytes: preferredMaxBytes}}, filters)
154154

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

@@ -188,7 +188,7 @@ func TestIsolatedEmptyBatch(t *testing.T) {
188188
maxMessageCount := uint32(2)
189189
absoluteMaxBytes := uint32(1000)
190190
preferredMaxBytes := uint32(100)
191-
r := NewReceiverImpl(&mocksharedconfig.Manager{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: absoluteMaxBytes, PreferredMaxBytes: preferredMaxBytes}}, filters)
191+
r := NewReceiverImpl(&mockconfigtxorderer.SharedConfig{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: absoluteMaxBytes, PreferredMaxBytes: preferredMaxBytes}}, filters)
192192

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

@@ -214,7 +214,7 @@ func TestIsolatedPartialBatch(t *testing.T) {
214214
maxMessageCount := uint32(2)
215215
absoluteMaxBytes := uint32(1000)
216216
preferredMaxBytes := uint32(100)
217-
r := NewReceiverImpl(&mocksharedconfig.Manager{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: absoluteMaxBytes, PreferredMaxBytes: preferredMaxBytes}}, filters)
217+
r := NewReceiverImpl(&mockconfigtxorderer.SharedConfig{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: absoluteMaxBytes, PreferredMaxBytes: preferredMaxBytes}}, filters)
218218

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

@@ -264,7 +264,7 @@ func TestBatchSizePreferredMaxBytesOverflow(t *testing.T) {
264264
// set message count > 9
265265
maxMessageCount := uint32(20)
266266

267-
r := NewReceiverImpl(&mocksharedconfig.Manager{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: preferredMaxBytes * 2, PreferredMaxBytes: preferredMaxBytes}}, filters)
267+
r := NewReceiverImpl(&mockconfigtxorderer.SharedConfig{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: preferredMaxBytes * 2, PreferredMaxBytes: preferredMaxBytes}}, filters)
268268

269269
// enqueue 9 messages
270270
for i := 0; i < 9; i++ {
@@ -319,7 +319,7 @@ func TestBatchSizePreferredMaxBytesOverflowNoPending(t *testing.T) {
319319
// set message count > 1
320320
maxMessageCount := uint32(20)
321321

322-
r := NewReceiverImpl(&mocksharedconfig.Manager{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: preferredMaxBytes * 3, PreferredMaxBytes: preferredMaxBytes}}, filters)
322+
r := NewReceiverImpl(&mockconfigtxorderer.SharedConfig{BatchSizeVal: &ab.BatchSize{MaxMessageCount: maxMessageCount, AbsoluteMaxBytes: preferredMaxBytes * 3, PreferredMaxBytes: preferredMaxBytes}}, filters)
323323

324324
// submit large message
325325
batches, committers, ok := r.Ordered(goodTxLarge)

orderer/common/bootstrap/provisional/provisional.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import (
2222
"github.com/hyperledger/fabric/common/cauthdsl"
2323
"github.com/hyperledger/fabric/common/chainconfig"
2424
"github.com/hyperledger/fabric/common/configtx"
25+
configtxorderer "github.com/hyperledger/fabric/common/configtx/handlers/orderer"
2526
"github.com/hyperledger/fabric/common/genesis"
2627
"github.com/hyperledger/fabric/orderer/common/bootstrap"
27-
"github.com/hyperledger/fabric/orderer/common/sharedconfig"
2828
"github.com/hyperledger/fabric/orderer/localconfig"
2929
cb "github.com/hyperledger/fabric/protos/common"
3030
ab "github.com/hyperledger/fabric/protos/orderer"
@@ -74,30 +74,30 @@ func New(conf *config.TopLevel) Generator {
7474
chainconfig.TemplateOrdererAddresses([]string{fmt.Sprintf("%s:%d", conf.General.ListenAddress, conf.General.ListenPort)}),
7575

7676
// Orderer Config Types
77-
sharedconfig.TemplateConsensusType(conf.Genesis.OrdererType),
78-
sharedconfig.TemplateBatchSize(&ab.BatchSize{
77+
configtxorderer.TemplateConsensusType(conf.Genesis.OrdererType),
78+
configtxorderer.TemplateBatchSize(&ab.BatchSize{
7979
MaxMessageCount: conf.Genesis.BatchSize.MaxMessageCount,
8080
AbsoluteMaxBytes: conf.Genesis.BatchSize.AbsoluteMaxBytes,
8181
PreferredMaxBytes: conf.Genesis.BatchSize.PreferredMaxBytes,
8282
}),
83-
sharedconfig.TemplateBatchTimeout(conf.Genesis.BatchTimeout.String()),
84-
sharedconfig.TemplateIngressPolicyNames([]string{AcceptAllPolicyKey}),
85-
sharedconfig.TemplateEgressPolicyNames([]string{AcceptAllPolicyKey}),
83+
configtxorderer.TemplateBatchTimeout(conf.Genesis.BatchTimeout.String()),
84+
configtxorderer.TemplateIngressPolicyNames([]string{AcceptAllPolicyKey}),
85+
configtxorderer.TemplateEgressPolicyNames([]string{AcceptAllPolicyKey}),
8686

8787
// Policies
8888
cauthdsl.TemplatePolicy(configtx.NewConfigItemPolicyKey, cauthdsl.RejectAllPolicy),
8989
cauthdsl.TemplatePolicy(AcceptAllPolicyKey, cauthdsl.AcceptAllPolicy),
9090
},
9191

9292
systemChainItems: []*cb.ConfigItem{
93-
sharedconfig.TemplateChainCreationPolicyNames(DefaultChainCreationPolicyNames),
93+
configtxorderer.TemplateChainCreationPolicyNames(DefaultChainCreationPolicyNames),
9494
},
9595
}
9696

9797
switch conf.Genesis.OrdererType {
9898
case ConsensusTypeSolo, ConsensusTypeSbft:
9999
case ConsensusTypeKafka:
100-
bs.minimalItems = append(bs.minimalItems, sharedconfig.TemplateKafkaBrokers(conf.Kafka.Brokers))
100+
bs.minimalItems = append(bs.minimalItems, configtxorderer.TemplateKafkaBrokers(conf.Kafka.Brokers))
101101
default:
102102
panic(fmt.Errorf("Wrong consenter type value given: %s", conf.Genesis.OrdererType))
103103
}

orderer/common/deliver/deliver.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ package deliver
1919
import (
2020
"fmt"
2121

22+
configtxapi "github.com/hyperledger/fabric/common/configtx/api"
2223
"github.com/hyperledger/fabric/common/policies"
2324
"github.com/hyperledger/fabric/orderer/common/filter"
24-
"github.com/hyperledger/fabric/orderer/common/sharedconfig"
2525
"github.com/hyperledger/fabric/orderer/common/sigfilter"
2626
ordererledger "github.com/hyperledger/fabric/orderer/ledger"
2727
cb "github.com/hyperledger/fabric/protos/common"
@@ -52,7 +52,7 @@ type Support interface {
5252
Reader() ordererledger.Reader
5353

5454
// SharedConfig returns the shared config manager for this chain
55-
SharedConfig() sharedconfig.Manager
55+
SharedConfig() configtxapi.OrdererConfig
5656
}
5757

5858
type deliverServer struct {

0 commit comments

Comments
 (0)