Skip to content

Commit

Permalink
[FAB-2101] Move orderer sharedconfig to common
Browse files Browse the repository at this point in the history
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 <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Feb 8, 2017
1 parent 14e3a11 commit 3b320c6
Show file tree
Hide file tree
Showing 18 changed files with 108 additions and 109 deletions.
30 changes: 30 additions & 0 deletions common/configtx/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,42 @@ limitations under the License.
package api

import (
"time"

"github.com/hyperledger/fabric/common/chainconfig"
"github.com/hyperledger/fabric/common/policies"
"github.com/hyperledger/fabric/msp"
cb "github.com/hyperledger/fabric/protos/common"
ab "github.com/hyperledger/fabric/protos/orderer"
)

// OrdererConfig stores the common shared orderer config
type OrdererConfig interface {
// ConsensusType returns the configured consensus type
ConsensusType() string

// BatchSize returns the maximum number of messages to include in a block
BatchSize() *ab.BatchSize

// BatchTimeout returns the amount of time to wait before creating a batch
BatchTimeout() time.Duration

// ChainCreationPolicyNames returns the policy names which are allowed for chain creation
// This field is only set for the system ordering chain
ChainCreationPolicyNames() []string

// KafkaBrokers returns the addresses (IP:port notation) of a set of "bootstrap"
// Kafka brokers, i.e. this is not necessarily the entire set of Kafka brokers
// used for ordering
KafkaBrokers() []string

// IngressPolicyNames returns the name of the policy to validate incoming broadcast messages against
IngressPolicyNames() []string

// EgressPolicyNames returns the name of the policy to validate incoming broadcast messages against
EgressPolicyNames() []string
}

// Handler provides a hook which allows other pieces of code to participate in config proposals
type Handler interface {
// BeginConfig called when a config proposal is begun
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package sharedconfig
package orderer

import (
"fmt"
Expand Down Expand Up @@ -53,37 +53,7 @@ const (
EgressPolicyNamesKey = "EgressPolicyNames"
)

var logger = logging.MustGetLogger("orderer/common/sharedconfig")

// Manager stores the common shared orderer config
// It is intended to be the primary accessor of ManagerImpl
// It is intended to discourage use of the other exported ManagerImpl methods
// which are used for updating the orderer config by the ConfigManager
type Manager interface {
// ConsensusType returns the configured consensus type
ConsensusType() string

// BatchSize returns the maximum number of messages to include in a block
BatchSize() *ab.BatchSize

// BatchTimeout returns the amount of time to wait before creating a batch
BatchTimeout() time.Duration

// ChainCreationPolicyNames returns the policy names which are allowed for chain creation
// This field is only set for the system ordering chain
ChainCreationPolicyNames() []string

// KafkaBrokers returns the addresses (IP:port notation) of a set of "bootstrap"
// Kafka brokers, i.e. this is not necessarily the entire set of Kafka brokers
// used for ordering
KafkaBrokers() []string

// IngressPolicyNames returns the name of the policy to validate incoming broadcast messages against
IngressPolicyNames() []string

// EgressPolicyNames returns the name of the policy to validate incoming broadcast messages against
EgressPolicyNames() []string
}
var logger = logging.MustGetLogger("configtx/handlers/orderer")

type ordererConfig struct {
consensusType string
Expand All @@ -95,14 +65,13 @@ type ordererConfig struct {
egressPolicyNames []string
}

// ManagerImpl is an implementation of Manager and configtx.ConfigHandler
// In general, it should only be referenced as an Impl for the configtx.ConfigManager
// ManagerImpl is an implementation of configtxapi.OrdererConfig and configtxapi.Handler
type ManagerImpl struct {
pendingConfig *ordererConfig
config *ordererConfig
}

// NewManagerImpl creates a new ManagerImpl with the given CryptoHelper
// NewManagerImpl creates a new ManagerImpl
func NewManagerImpl() *ManagerImpl {
return &ManagerImpl{
config: &ordererConfig{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package sharedconfig
package orderer

import (
"os"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package sharedconfig
package orderer

import (
cb "github.com/hyperledger/fabric/protos/common"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package sharedconfig
import ab "github.com/hyperledger/fabric/protos/orderer"
import "time"

// Manager is a mock implementation of sharedconfig.Manager
type Manager struct {
// SharedConfig is a mock implementation of sharedconfig.SharedConfig
type SharedConfig struct {
// ConsensusTypeVal is returned as the result of ConsensusType()
ConsensusTypeVal string
// BatchSizeVal is returned as the result of BatchSize()
Expand All @@ -38,36 +38,36 @@ type Manager struct {
}

// ConsensusType returns the ConsensusTypeVal
func (scm *Manager) ConsensusType() string {
func (scm *SharedConfig) ConsensusType() string {
return scm.ConsensusTypeVal
}

// BatchSize returns the BatchSizeVal
func (scm *Manager) BatchSize() *ab.BatchSize {
func (scm *SharedConfig) BatchSize() *ab.BatchSize {
return scm.BatchSizeVal
}

// BatchTimeout returns the BatchTimeoutVal
func (scm *Manager) BatchTimeout() time.Duration {
func (scm *SharedConfig) BatchTimeout() time.Duration {
return scm.BatchTimeoutVal
}

// ChainCreationPolicyNames returns the ChainCreationPolicyNamesVal
func (scm *Manager) ChainCreationPolicyNames() []string {
func (scm *SharedConfig) ChainCreationPolicyNames() []string {
return scm.ChainCreationPolicyNamesVal
}

// KafkaBrokers returns the KafkaBrokersVal
func (scm *Manager) KafkaBrokers() []string {
func (scm *SharedConfig) KafkaBrokers() []string {
return scm.KafkaBrokersVal
}

// IngressPolicyNames returns the IngressPolicyNamesVal
func (scm *Manager) IngressPolicyNames() []string {
func (scm *SharedConfig) IngressPolicyNames() []string {
return scm.IngressPolicyNamesVal
}

// EgressPolicyNames returns the EgressPolicyNamesVal
func (scm *Manager) EgressPolicyNames() []string {
func (scm *SharedConfig) EgressPolicyNames() []string {
return scm.EgressPolicyNamesVal
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package sharedconfig
import (
"testing"

"github.com/hyperledger/fabric/orderer/common/sharedconfig"
configtxapi "github.com/hyperledger/fabric/common/configtx/api"
)

func TestSharedConfigInterface(t *testing.T) {
_ = sharedconfig.Manager(&Manager{})
_ = configtxapi.OrdererConfig(&SharedConfig{})
}
8 changes: 4 additions & 4 deletions orderer/common/blockcutter/blockcutter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ limitations under the License.
package blockcutter

import (
configtxapi "github.com/hyperledger/fabric/common/configtx/api"
"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 Down Expand Up @@ -52,15 +52,15 @@ type Receiver interface {
}

type receiver struct {
sharedConfigManager sharedconfig.Manager
sharedConfigManager configtxapi.OrdererConfig
filters *filter.RuleSet
pendingBatch []*cb.Envelope
pendingBatchSizeBytes uint32
pendingCommitters []filter.Committer
}

// NewReceiverImpl creates a Receiver implementation based on the given sharedconfig manager and filters
func NewReceiverImpl(sharedConfigManager sharedconfig.Manager, filters *filter.RuleSet) Receiver {
// NewReceiverImpl creates a Receiver implementation based on the given configtxorderer manager and filters
func NewReceiverImpl(sharedConfigManager configtxapi.OrdererConfig, filters *filter.RuleSet) Receiver {
return &receiver{
sharedConfigManager: sharedConfigManager,
filters: filters,
Expand Down
16 changes: 8 additions & 8 deletions orderer/common/blockcutter/blockcutter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"bytes"
"testing"

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// submit large message
batches, committers, ok := r.Ordered(goodTxLarge)
Expand Down
16 changes: 8 additions & 8 deletions orderer/common/bootstrap/provisional/provisional.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
"github.com/hyperledger/fabric/common/cauthdsl"
"github.com/hyperledger/fabric/common/chainconfig"
"github.com/hyperledger/fabric/common/configtx"
configtxorderer "github.com/hyperledger/fabric/common/configtx/handlers/orderer"
"github.com/hyperledger/fabric/common/genesis"
"github.com/hyperledger/fabric/orderer/common/bootstrap"
"github.com/hyperledger/fabric/orderer/common/sharedconfig"
"github.com/hyperledger/fabric/orderer/localconfig"
cb "github.com/hyperledger/fabric/protos/common"
ab "github.com/hyperledger/fabric/protos/orderer"
Expand Down Expand Up @@ -74,30 +74,30 @@ func New(conf *config.TopLevel) Generator {
chainconfig.TemplateOrdererAddresses([]string{fmt.Sprintf("%s:%d", conf.General.ListenAddress, conf.General.ListenPort)}),

// Orderer Config Types
sharedconfig.TemplateConsensusType(conf.Genesis.OrdererType),
sharedconfig.TemplateBatchSize(&ab.BatchSize{
configtxorderer.TemplateConsensusType(conf.Genesis.OrdererType),
configtxorderer.TemplateBatchSize(&ab.BatchSize{
MaxMessageCount: conf.Genesis.BatchSize.MaxMessageCount,
AbsoluteMaxBytes: conf.Genesis.BatchSize.AbsoluteMaxBytes,
PreferredMaxBytes: conf.Genesis.BatchSize.PreferredMaxBytes,
}),
sharedconfig.TemplateBatchTimeout(conf.Genesis.BatchTimeout.String()),
sharedconfig.TemplateIngressPolicyNames([]string{AcceptAllPolicyKey}),
sharedconfig.TemplateEgressPolicyNames([]string{AcceptAllPolicyKey}),
configtxorderer.TemplateBatchTimeout(conf.Genesis.BatchTimeout.String()),
configtxorderer.TemplateIngressPolicyNames([]string{AcceptAllPolicyKey}),
configtxorderer.TemplateEgressPolicyNames([]string{AcceptAllPolicyKey}),

// Policies
cauthdsl.TemplatePolicy(configtx.NewConfigItemPolicyKey, cauthdsl.RejectAllPolicy),
cauthdsl.TemplatePolicy(AcceptAllPolicyKey, cauthdsl.AcceptAllPolicy),
},

systemChainItems: []*cb.ConfigItem{
sharedconfig.TemplateChainCreationPolicyNames(DefaultChainCreationPolicyNames),
configtxorderer.TemplateChainCreationPolicyNames(DefaultChainCreationPolicyNames),
},
}

switch conf.Genesis.OrdererType {
case ConsensusTypeSolo, ConsensusTypeSbft:
case ConsensusTypeKafka:
bs.minimalItems = append(bs.minimalItems, sharedconfig.TemplateKafkaBrokers(conf.Kafka.Brokers))
bs.minimalItems = append(bs.minimalItems, configtxorderer.TemplateKafkaBrokers(conf.Kafka.Brokers))
default:
panic(fmt.Errorf("Wrong consenter type value given: %s", conf.Genesis.OrdererType))
}
Expand Down
4 changes: 2 additions & 2 deletions orderer/common/deliver/deliver.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package deliver
import (
"fmt"

configtxapi "github.com/hyperledger/fabric/common/configtx/api"
"github.com/hyperledger/fabric/common/policies"
"github.com/hyperledger/fabric/orderer/common/filter"
"github.com/hyperledger/fabric/orderer/common/sharedconfig"
"github.com/hyperledger/fabric/orderer/common/sigfilter"
ordererledger "github.com/hyperledger/fabric/orderer/ledger"
cb "github.com/hyperledger/fabric/protos/common"
Expand Down Expand Up @@ -52,7 +52,7 @@ type Support interface {
Reader() ordererledger.Reader

// SharedConfig returns the shared config manager for this chain
SharedConfig() sharedconfig.Manager
SharedConfig() configtxapi.OrdererConfig
}

type deliverServer struct {
Expand Down
Loading

0 comments on commit 3b320c6

Please sign in to comment.