Skip to content

Commit

Permalink
[FAB-1649] Normalize orderer config item names
Browse files Browse the repository at this point in the history
https://jira.hyperledger.org/browse/FAB-1649

The orderer configuration items have been added one by one as needed, so
some commonalities have been ignored, and some names are inconsitent or
misleading. This CR is normalizes those names.

Suggested review start:
    protos/orderer/configuration.proto
    orderer/common/bootstrap/provisional/item.go

Change-Id: I415c5e7e3ed410f82d01a4ea30ff48a10bed7a98
Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Jan 18, 2017
1 parent 81d5152 commit daf29b8
Show file tree
Hide file tree
Showing 23 changed files with 277 additions and 257 deletions.
30 changes: 15 additions & 15 deletions common/configtx/inspector/orderer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,24 @@ func (ot ordererTypes) Value(configItem *cb.ConfigurationItem) Viewable {
return viewableError(name, err)
}
return viewableCreationPolicy(configItem.Key, value)
case "IngressPolicy":
value := &ab.IngressPolicy{}
case "IngressPolicyNames":
value := &ab.IngressPolicyNames{}
if err := proto.Unmarshal(configItem.Value, value); err != nil {
return viewableError(name, err)
}
return viewableIngressPolicy(configItem.Key, value)
case "EgressPolicy":
value := &ab.EgressPolicy{}
return viewableIngressPolicyNames(configItem.Key, value)
case "EgressPolicyNames":
value := &ab.EgressPolicyNames{}
if err := proto.Unmarshal(configItem.Value, value); err != nil {
return viewableError(name, err)
}
return viewableEgressPolicy(configItem.Key, value)
case "ChainCreators":
value := &ab.ChainCreators{}
return viewableEgressPolicyNames(configItem.Key, value)
case "ChainCreationPolicyNames":
value := &ab.ChainCreationPolicyNames{}
if err := proto.Unmarshal(configItem.Value, value); err != nil {
return viewableError(name, err)
}
return viewableChainCreators(configItem.Key, value)
return viewableChainCreationPolicyNames(configItem.Key, value)
case "KafkaBrokers":
value := &ab.KafkaBrokers{}
if err := proto.Unmarshal(configItem.Value, value); err != nil {
Expand All @@ -99,24 +99,24 @@ func viewableBatchTimeout(name string, batchTimeout *ab.BatchTimeout) Viewable {
}
}

func viewableIngressPolicy(name string, ingressPolicy *ab.IngressPolicy) Viewable {
func viewableIngressPolicyNames(name string, ingressPolicy *ab.IngressPolicyNames) Viewable {
return &field{
name: name,
values: []Viewable{viewableString("Name", ingressPolicy.Name)},
values: []Viewable{viewableStringSlice("Name", ingressPolicy.Names)},
}
}

func viewableEgressPolicy(name string, egressPolicy *ab.EgressPolicy) Viewable {
func viewableEgressPolicyNames(name string, egressPolicy *ab.EgressPolicyNames) Viewable {
return &field{
name: name,
values: []Viewable{viewableString("Name", egressPolicy.Name)},
values: []Viewable{viewableStringSlice("Names", egressPolicy.Names)},
}
}

func viewableChainCreators(name string, creators *ab.ChainCreators) Viewable {
func viewableChainCreationPolicyNames(name string, chainCreationPolicyNames *ab.ChainCreationPolicyNames) Viewable {
return &field{
name: name,
values: []Viewable{viewableStringSlice("Policies", creators.Policies)},
values: []Viewable{viewableStringSlice("Names", chainCreationPolicyNames.Names)},
}
}

Expand Down
6 changes: 3 additions & 3 deletions common/configtx/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ type Manager interface {
Sequence() uint64
}

// DefaultModificationPolicyID is the ID of the policy used when no other policy can be resolved, for instance when attempting to create a new config item
const DefaultModificationPolicyID = "DefaultModificationPolicy"
// NewConfigurationItemPolicyKey is the ID of the policy used when no other policy can be resolved, for instance when attempting to create a new config item
const NewConfigurationItemPolicyKey = "NewConfigurationItemPolicy"

type acceptAllPolicy struct{}

Expand Down Expand Up @@ -187,7 +187,7 @@ func (cm *configurationManager) processConfig(configtx *cb.ConfigurationEnvelope
return nil, fmt.Errorf("Config is for the wrong chain, expected %s, got %s", cm.chainID, chainID)
}

defaultModificationPolicy, defaultPolicySet := cm.pm.GetPolicy(DefaultModificationPolicyID)
defaultModificationPolicy, defaultPolicySet := cm.pm.GetPolicy(NewConfigurationItemPolicyKey)

// If the default modification policy is not set, it indicates this is an uninitialized chain, so be permissive of modification
if !defaultPolicySet {
Expand Down
Binary file modified common/configtx/test/orderer.template
Binary file not shown.
52 changes: 26 additions & 26 deletions orderer/common/bootstrap/provisional/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,83 +25,83 @@ import (
"github.com/hyperledger/fabric/protos/utils"
)

func (cbs *commonBootstrapper) encodeConsensusType() *cb.ConfigurationItem {
func (cbs *commonBootstrapper) templateConsensusType() *cb.ConfigurationItem {
configItemKey := sharedconfig.ConsensusTypeKey
configItemValue := utils.MarshalOrPanic(&ab.ConsensusType{Type: cbs.consensusType})
modPolicy := configtx.DefaultModificationPolicyID
modPolicy := configtx.NewConfigurationItemPolicyKey

configItemChainHeader := utils.MakeChainHeader(cb.HeaderType_CONFIGURATION_ITEM, msgVersion, cbs.chainID, epoch)
return utils.MakeConfigurationItem(configItemChainHeader, cb.ConfigurationItem_Orderer, lastModified, modPolicy, configItemKey, configItemValue)
}

func (cbs *commonBootstrapper) encodeBatchSize() *cb.ConfigurationItem {
func (cbs *commonBootstrapper) templateBatchSize() *cb.ConfigurationItem {
configItemKey := sharedconfig.BatchSizeKey
configItemValue := utils.MarshalOrPanic(cbs.batchSize)
modPolicy := configtx.DefaultModificationPolicyID
modPolicy := configtx.NewConfigurationItemPolicyKey

configItemChainHeader := utils.MakeChainHeader(cb.HeaderType_CONFIGURATION_ITEM, msgVersion, cbs.chainID, epoch)
return utils.MakeConfigurationItem(configItemChainHeader, cb.ConfigurationItem_Orderer, lastModified, modPolicy, configItemKey, configItemValue)
}

func (cbs *commonBootstrapper) encodeBatchTimeout() *cb.ConfigurationItem {
func (cbs *commonBootstrapper) templateBatchTimeout() *cb.ConfigurationItem {
configItemKey := sharedconfig.BatchTimeoutKey
configItemValue := utils.MarshalOrPanic(&ab.BatchTimeout{Timeout: cbs.batchTimeout})
modPolicy := configtx.DefaultModificationPolicyID
modPolicy := configtx.NewConfigurationItemPolicyKey

configItemChainHeader := utils.MakeChainHeader(cb.HeaderType_CONFIGURATION_ITEM, msgVersion, cbs.chainID, epoch)
return utils.MakeConfigurationItem(configItemChainHeader, cb.ConfigurationItem_Orderer, lastModified, modPolicy, configItemKey, configItemValue)
}

func (cbs *commonBootstrapper) encodeChainCreators() *cb.ConfigurationItem {
configItemKey := sharedconfig.ChainCreatorsKey
configItemValue := utils.MarshalOrPanic(&ab.ChainCreators{Policies: DefaultChainCreators})
modPolicy := configtx.DefaultModificationPolicyID
func (cbs *commonBootstrapper) templateChainCreationPolicyNames() *cb.ConfigurationItem {
configItemKey := sharedconfig.ChainCreationPolicyNamesKey
configItemValue := utils.MarshalOrPanic(&ab.ChainCreationPolicyNames{Names: DefaultChainCreationPolicyNames})
modPolicy := configtx.NewConfigurationItemPolicyKey

configItemChainHeader := utils.MakeChainHeader(cb.HeaderType_CONFIGURATION_ITEM, msgVersion, cbs.chainID, epoch)
return utils.MakeConfigurationItem(configItemChainHeader, cb.ConfigurationItem_Orderer, lastModified, modPolicy, configItemKey, configItemValue)
}

func (cbs *commonBootstrapper) encodeAcceptAllPolicy() *cb.ConfigurationItem {
func (cbs *commonBootstrapper) templateAcceptAllPolicy() *cb.ConfigurationItem {
configItemKey := AcceptAllPolicyKey
configItemValue := utils.MarshalOrPanic(utils.MakePolicyOrPanic(cauthdsl.AcceptAllPolicy))
modPolicy := configtx.DefaultModificationPolicyID
modPolicy := configtx.NewConfigurationItemPolicyKey

configItemChainHeader := utils.MakeChainHeader(cb.HeaderType_CONFIGURATION_ITEM, msgVersion, cbs.chainID, epoch)
return utils.MakeConfigurationItem(configItemChainHeader, cb.ConfigurationItem_Policy, lastModified, modPolicy, configItemKey, configItemValue)
}

func (cbs *commonBootstrapper) encodeIngressPolicy() *cb.ConfigurationItem {
configItemKey := sharedconfig.IngressPolicyKey
configItemValue := utils.MarshalOrPanic(&ab.IngressPolicy{Name: AcceptAllPolicyKey})
modPolicy := configtx.DefaultModificationPolicyID
func (cbs *commonBootstrapper) templateIngressPolicyNames() *cb.ConfigurationItem {
configItemKey := sharedconfig.IngressPolicyNamesKey
configItemValue := utils.MarshalOrPanic(&ab.IngressPolicyNames{Names: []string{AcceptAllPolicyKey}})
modPolicy := configtx.NewConfigurationItemPolicyKey

configItemChainHeader := utils.MakeChainHeader(cb.HeaderType_CONFIGURATION_ITEM, msgVersion, cbs.chainID, epoch)
return utils.MakeConfigurationItem(configItemChainHeader, cb.ConfigurationItem_Orderer, lastModified, modPolicy, configItemKey, configItemValue)
}

func (cbs *commonBootstrapper) encodeEgressPolicy() *cb.ConfigurationItem {
configItemKey := sharedconfig.EgressPolicyKey
configItemValue := utils.MarshalOrPanic(&ab.EgressPolicy{Name: AcceptAllPolicyKey})
modPolicy := configtx.DefaultModificationPolicyID
func (cbs *commonBootstrapper) templateEgressPolicyNames() *cb.ConfigurationItem {
configItemKey := sharedconfig.EgressPolicyNamesKey
configItemValue := utils.MarshalOrPanic(&ab.EgressPolicyNames{Names: []string{AcceptAllPolicyKey}})
modPolicy := configtx.NewConfigurationItemPolicyKey

configItemChainHeader := utils.MakeChainHeader(cb.HeaderType_CONFIGURATION_ITEM, msgVersion, cbs.chainID, epoch)
return utils.MakeConfigurationItem(configItemChainHeader, cb.ConfigurationItem_Orderer, lastModified, modPolicy, configItemKey, configItemValue)
}

func (cbs *commonBootstrapper) lockDefaultModificationPolicy() *cb.ConfigurationItem {
// Lock down the default modification policy to prevent any further policy modifications
configItemKey := configtx.DefaultModificationPolicyID
func (cbs *commonBootstrapper) templateRejectAllPolicy() *cb.ConfigurationItem {
// Lock down the new configuration item policy to prevent any new configuration items from being created
configItemKey := configtx.NewConfigurationItemPolicyKey
configItemValue := utils.MarshalOrPanic(utils.MakePolicyOrPanic(cauthdsl.RejectAllPolicy))
modPolicy := configtx.DefaultModificationPolicyID
modPolicy := configtx.NewConfigurationItemPolicyKey

configItemChainHeader := utils.MakeChainHeader(cb.HeaderType_CONFIGURATION_ITEM, msgVersion, cbs.chainID, epoch)
return utils.MakeConfigurationItem(configItemChainHeader, cb.ConfigurationItem_Policy, lastModified, modPolicy, configItemKey, configItemValue)
}

func (kbs *kafkaBootstrapper) encodeKafkaBrokers() *cb.ConfigurationItem {
func (kbs *kafkaBootstrapper) templateKafkaBrokers() *cb.ConfigurationItem {
configItemKey := sharedconfig.KafkaBrokersKey
configItemValue := utils.MarshalOrPanic(&ab.KafkaBrokers{Brokers: kbs.kafkaBrokers})
modPolicy := configtx.DefaultModificationPolicyID
modPolicy := configtx.NewConfigurationItemPolicyKey

configItemChainHeader := utils.MakeChainHeader(cb.HeaderType_CONFIGURATION_ITEM, msgVersion, kbs.chainID, epoch)
return utils.MakeConfigurationItem(configItemChainHeader, cb.ConfigurationItem_Orderer, lastModified, modPolicy, configItemKey, configItemValue)
Expand Down
4 changes: 2 additions & 2 deletions orderer/common/bootstrap/provisional/provisional.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ const (
epoch = 0
)

// DefaultChainCreators is the default value of ChainCreatorsKey.
var DefaultChainCreators = []string{AcceptAllPolicyKey}
// DefaultChainCreationPolicyNames is the default value of ChainCreatorsKey.
var DefaultChainCreationPolicyNames = []string{AcceptAllPolicyKey}

type commonBootstrapper struct {
chainID string
Expand Down
18 changes: 9 additions & 9 deletions orderer/common/bootstrap/provisional/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ import (
)

func (cbs *commonBootstrapper) makeOrdererSystemChainConfig() []*cb.ConfigurationItem {
return []*cb.ConfigurationItem{cbs.encodeChainCreators()}
return []*cb.ConfigurationItem{cbs.templateChainCreationPolicyNames()}
}

func (cbs *commonBootstrapper) TemplateItems() []*cb.ConfigurationItem {
return []*cb.ConfigurationItem{
cbs.encodeConsensusType(),
cbs.encodeBatchSize(),
cbs.encodeBatchTimeout(),
cbs.encodeAcceptAllPolicy(),
cbs.encodeIngressPolicy(),
cbs.encodeEgressPolicy(),
cbs.lockDefaultModificationPolicy(),
cbs.templateConsensusType(),
cbs.templateBatchSize(),
cbs.templateBatchTimeout(),
cbs.templateAcceptAllPolicy(),
cbs.templateIngressPolicyNames(),
cbs.templateEgressPolicyNames(),
cbs.templateRejectAllPolicy(),
}
}

func (kbs *kafkaBootstrapper) TemplateItems() []*cb.ConfigurationItem {
return append(kbs.commonBootstrapper.TemplateItems(), kbs.encodeKafkaBrokers())
return append(kbs.commonBootstrapper.TemplateItems(), kbs.templateKafkaBrokers())
}
2 changes: 1 addition & 1 deletion orderer/common/deliver/deliver.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (ds *deliverServer) Handle(srv ab.AtomicBroadcast_DeliverServer) error {
return sendStatusReply(srv, cb.Status_NOT_FOUND)
}

sf := sigfilter.New(chain.SharedConfig().EgressPolicy, chain.PolicyManager())
sf := sigfilter.New(chain.SharedConfig().EgressPolicyNames, chain.PolicyManager())
result, _ := sf.Apply(envelope)
if result != filter.Forward {
return sendStatusReply(srv, cb.Status_FORBIDDEN)
Expand Down
2 changes: 1 addition & 1 deletion orderer/common/deliver/deliver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func newMockMultichainManager() *mockSupportManager {
}
mm.chains[systemChainID] = &mockSupport{
ledger: rl,
sharedConfig: &mocksharedconfig.Manager{},
sharedConfig: &mocksharedconfig.Manager{EgressPolicyNamesVal: []string{"somePolicy"}},
policyManager: &mockpolicies.Manager{Policy: &mockpolicies.Policy{}},
}
return mm
Expand Down
84 changes: 42 additions & 42 deletions orderer/common/sharedconfig/sharedconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ const (
// BatchTimeoutKey is the cb.ConfigurationItem type key name for the BatchTimeout message
BatchTimeoutKey = "BatchTimeout"

// ChainCreatorsKey is the cb.ConfigurationItem type key name for the ChainCreators message
ChainCreatorsKey = "ChainCreators"
// ChainCreationPolicyNamesKey is the cb.ConfigurationItem type key name for the ChainCreationPolicyNames message
ChainCreationPolicyNamesKey = "ChainCreationPolicyNames"

// KafkaBrokersKey is the cb.ConfigurationItem type key name for the KafkaBrokers message
KafkaBrokersKey = "KafkaBrokers"

// IngressPolicyKey is the cb.ConfigurationItem type key name for the IngressPolicy message
IngressPolicyKey = "IngressPolicy"
// IngressPolicyNamesKey is the cb.ConfigurationItem type key name for the IngressPolicyNames message
IngressPolicyNamesKey = "IngressPolicyNames"

// EgressPolicyKey is the cb.ConfigurationItem type key name for the EgressPolicy message
EgressPolicyKey = "EgressPolicy"
// EgressPolicyNamesKey is the cb.ConfigurationItem type key name for the EgressPolicyNames message
EgressPolicyNamesKey = "EgressPolicyNames"
)

var logger = logging.MustGetLogger("orderer/common/sharedconfig")
Expand All @@ -69,30 +69,30 @@ type Manager interface {
// BatchTimeout returns the amount of time to wait before creating a batch
BatchTimeout() time.Duration

// ChainCreators returns the policy names which are allowed for chain creation
// ChainCreationPolicyNames returns the policy names which are allowed for chain creation
// This field is only set for the system ordering chain
ChainCreators() []string
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

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

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

type ordererConfig struct {
consensusType string
batchSize *ab.BatchSize
batchTimeout time.Duration
chainCreators []string
kafkaBrokers []string
ingressPolicy string
egressPolicy string
consensusType string
batchSize *ab.BatchSize
batchTimeout time.Duration
chainCreationPolicies []string
kafkaBrokers []string
ingressPolicyNames []string
egressPolicyNames []string
}

// ManagerImpl is an implementation of Manager and configtx.ConfigHandler
Expand Down Expand Up @@ -124,10 +124,10 @@ func (pm *ManagerImpl) BatchTimeout() time.Duration {
return pm.config.batchTimeout
}

// ChainCreators returns the policy names which are allowed for chain creation
// ChainCreationPolicyNames returns the policy names which are allowed for chain creation
// This field is only set for the system ordering chain
func (pm *ManagerImpl) ChainCreators() []string {
return pm.config.chainCreators
func (pm *ManagerImpl) ChainCreationPolicyNames() []string {
return pm.config.chainCreationPolicies
}

// KafkaBrokers returns the addresses (IP:port notation) of a set of "bootstrap"
Expand All @@ -137,14 +137,14 @@ func (pm *ManagerImpl) KafkaBrokers() []string {
return pm.config.kafkaBrokers
}

// IngressPolicy returns the name of the policy to validate incoming broadcast messages against
func (pm *ManagerImpl) IngressPolicy() string {
return pm.config.ingressPolicy
// IngressPolicyNames returns the name of the policy to validate incoming broadcast messages against
func (pm *ManagerImpl) IngressPolicyNames() []string {
return pm.config.ingressPolicyNames
}

// EgressPolicy returns the name of the policy to validate incoming deliver seeks against
func (pm *ManagerImpl) EgressPolicy() string {
return pm.config.egressPolicy
// EgressPolicyNames returns the name of the policy to validate incoming deliver seeks against
func (pm *ManagerImpl) EgressPolicyNames() []string {
return pm.config.egressPolicyNames
}

// BeginConfig is used to start a new configuration proposal
Expand Down Expand Up @@ -221,24 +221,24 @@ func (pm *ManagerImpl) ProposeConfig(configItem *cb.ConfigurationItem) error {
return fmt.Errorf("Attempted to set the batch timeout to a non-positive value: %s", timeoutValue.String())
}
pm.pendingConfig.batchTimeout = timeoutValue
case ChainCreatorsKey:
chainCreators := &ab.ChainCreators{}
if err := proto.Unmarshal(configItem.Value, chainCreators); err != nil {
case ChainCreationPolicyNamesKey:
chainCreationPolicies := &ab.ChainCreationPolicyNames{}
if err := proto.Unmarshal(configItem.Value, chainCreationPolicies); err != nil {
return fmt.Errorf("Unmarshaling error for ChainCreator: %s", err)
}
pm.pendingConfig.chainCreators = chainCreators.Policies
case IngressPolicyKey:
ingressPolicy := &ab.IngressPolicy{}
if err := proto.Unmarshal(configItem.Value, ingressPolicy); err != nil {
return fmt.Errorf("Unmarshaling error for IngressPolicy: %s", err)
pm.pendingConfig.chainCreationPolicies = chainCreationPolicies.Names
case IngressPolicyNamesKey:
ingressPolicyNames := &ab.IngressPolicyNames{}
if err := proto.Unmarshal(configItem.Value, ingressPolicyNames); err != nil {
return fmt.Errorf("Unmarshaling error for IngressPolicyNames: %s", err)
}
pm.pendingConfig.ingressPolicy = ingressPolicy.Name
case EgressPolicyKey:
egressPolicy := &ab.EgressPolicy{}
if err := proto.Unmarshal(configItem.Value, egressPolicy); err != nil {
return fmt.Errorf("Unmarshaling error for EgressPolicy: %s", err)
pm.pendingConfig.ingressPolicyNames = ingressPolicyNames.Names
case EgressPolicyNamesKey:
egressPolicyNames := &ab.EgressPolicyNames{}
if err := proto.Unmarshal(configItem.Value, egressPolicyNames); err != nil {
return fmt.Errorf("Unmarshaling error for EgressPolicyNames: %s", err)
}
pm.pendingConfig.egressPolicy = egressPolicy.Name
pm.pendingConfig.egressPolicyNames = egressPolicyNames.Names
case KafkaBrokersKey:
kafkaBrokers := &ab.KafkaBrokers{}
if err := proto.Unmarshal(configItem.Value, kafkaBrokers); err != nil {
Expand Down
Loading

0 comments on commit daf29b8

Please sign in to comment.