Skip to content

Commit

Permalink
[FAB-2396] Move orderer config to common Proposer
Browse files Browse the repository at this point in the history
https://jira.hyperledger.org/browse/FAB-2396

This is the second in a series of CRs which will migrate the config
value handlers off of their own custom transaction handling code and
onto the common Proposer code.  This will not only reduce the amount of
reimplimented logic (and corresponding bugs) and will also facilitate
the two-way config translation for the configtxgen tool.

Change-Id: I0e4bd1228c12b02fbf074b05379e917d463bf877
Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Mar 7, 2017
1 parent 8b20459 commit c8ff4b1
Show file tree
Hide file tree
Showing 14 changed files with 366 additions and 677 deletions.
19 changes: 5 additions & 14 deletions common/configtx/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ package configtx
import (
"fmt"

"github.com/golang/protobuf/proto"
configtxorderer "github.com/hyperledger/fabric/common/configvalues/channel/orderer"
config "github.com/hyperledger/fabric/common/configvalues/root"
"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/msp"
cb "github.com/hyperledger/fabric/protos/common"
ab "github.com/hyperledger/fabric/protos/orderer"
"github.com/hyperledger/fabric/protos/utils"

"github.com/golang/protobuf/proto"
)

const (
Expand All @@ -34,16 +35,6 @@ const (
CreationPolicyKey = "CreationPolicy"
msgVersion = int32(0)
epoch = 0

// ApplicationGroup identifies the `groups` map key in the channel
// config, under which the application-related config group is set.
ApplicationGroup = "Application"
// OrdererGroup identifies the `groups` map key in the channel
// config, under which the orderer-related config group is set.
OrdererGroup = "Orderer"
// MSPKey identifies the config key in the channel config,
// under which the application-related config group is set.
MSPKey = "MSP"
)

// Template can be used to faciliate creation of config transactions
Expand Down Expand Up @@ -157,8 +148,8 @@ func (ct *compositeTemplate) Envelope(chainID string) (*cb.ConfigUpdateEnvelope,
// Template which outputs an appropriately constructed list of ConfigUpdateEnvelopes.
func NewChainCreationTemplate(creationPolicy string, template Template) Template {
result := cb.NewConfigGroup()
result.Groups[configtxorderer.GroupKey] = cb.NewConfigGroup()
result.Groups[configtxorderer.GroupKey].Values[CreationPolicyKey] = &cb.ConfigValue{
result.Groups[config.OrdererGroupKey] = cb.NewConfigGroup()
result.Groups[config.OrdererGroupKey].Values[CreationPolicyKey] = &cb.ConfigValue{
Value: utils.MarshalOrPanic(&ab.CreationPolicy{
Policy: creationPolicy,
}),
Expand Down
4 changes: 2 additions & 2 deletions common/configtx/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"testing"

"github.com/golang/protobuf/proto"
configtxorderer "github.com/hyperledger/fabric/common/configvalues/channel/orderer"
config "github.com/hyperledger/fabric/common/configvalues/root"
cb "github.com/hyperledger/fabric/protos/common"
ab "github.com/hyperledger/fabric/protos/orderer"

Expand Down Expand Up @@ -104,7 +104,7 @@ func TestNewChainTemplate(t *testing.T) {
assert.True(t, ok, "Expected to find %d but did not", i)
}

configValue, ok := configNext.WriteSet.Groups[configtxorderer.GroupKey].Values[CreationPolicyKey]
configValue, ok := configNext.WriteSet.Groups[config.OrdererGroupKey].Values[CreationPolicyKey]
assert.True(t, ok, "Did not find creation policy")

creationPolicyMessage := new(ab.CreationPolicy)
Expand Down
4 changes: 2 additions & 2 deletions common/configtx/test/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig"
"github.com/hyperledger/fabric/common/configtx/tool/provisional"
configtxapplication "github.com/hyperledger/fabric/common/configvalues/channel/application"
configtxorderer "github.com/hyperledger/fabric/common/configvalues/channel/orderer"
configtxmsp "github.com/hyperledger/fabric/common/configvalues/msp"
config "github.com/hyperledger/fabric/common/configvalues/root"
"github.com/hyperledger/fabric/common/genesis"
"github.com/hyperledger/fabric/msp"
cb "github.com/hyperledger/fabric/protos/common"
Expand Down Expand Up @@ -104,7 +104,7 @@ func OrdererOrgTemplate() configtx.Template {
if err != nil {
logger.Panicf("Could not load sample MSP config: %s", err)
}
return configtx.NewSimpleTemplate(configtxmsp.TemplateGroupMSP([]string{configtxorderer.GroupKey, sampleOrgID}, mspConf))
return configtx.NewSimpleTemplate(configtxmsp.TemplateGroupMSP([]string{config.OrdererGroupKey, sampleOrgID}, mspConf))
}

// CompositeTemplate returns the composite template of peer, orderer, and MSP
Expand Down
21 changes: 10 additions & 11 deletions common/configtx/tool/provisional/provisional.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/hyperledger/fabric/common/configtx"
genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig"
configtxapplication "github.com/hyperledger/fabric/common/configvalues/channel/application"
configtxorderer "github.com/hyperledger/fabric/common/configvalues/channel/orderer"
configvaluesmsp "github.com/hyperledger/fabric/common/configvalues/msp"
config "github.com/hyperledger/fabric/common/configvalues/root"
"github.com/hyperledger/fabric/common/genesis"
Expand Down Expand Up @@ -100,40 +99,40 @@ func New(conf *genesisconfig.Profile) Generator {
if conf.Orderer != nil {
bs.ordererGroups = []*cb.ConfigGroup{
// Orderer Config Types
configtxorderer.TemplateConsensusType(conf.Orderer.OrdererType),
configtxorderer.TemplateBatchSize(&ab.BatchSize{
config.TemplateConsensusType(conf.Orderer.OrdererType),
config.TemplateBatchSize(&ab.BatchSize{
MaxMessageCount: conf.Orderer.BatchSize.MaxMessageCount,
AbsoluteMaxBytes: conf.Orderer.BatchSize.AbsoluteMaxBytes,
PreferredMaxBytes: conf.Orderer.BatchSize.PreferredMaxBytes,
}),
configtxorderer.TemplateBatchTimeout(conf.Orderer.BatchTimeout.String()),
config.TemplateBatchTimeout(conf.Orderer.BatchTimeout.String()),

// Initialize the default Reader/Writer/Admins orderer policies, as well as block validation policy
policies.TemplateImplicitMetaPolicyWithSubPolicy([]string{configtxorderer.GroupKey}, BlockValidationPolicyKey, configvaluesmsp.WritersPolicyKey, cb.ImplicitMetaPolicy_ANY),
policies.TemplateImplicitMetaAnyPolicy([]string{configtxorderer.GroupKey}, configvaluesmsp.ReadersPolicyKey),
policies.TemplateImplicitMetaAnyPolicy([]string{configtxorderer.GroupKey}, configvaluesmsp.WritersPolicyKey),
policies.TemplateImplicitMetaMajorityPolicy([]string{configtxorderer.GroupKey}, configvaluesmsp.AdminsPolicyKey),
policies.TemplateImplicitMetaPolicyWithSubPolicy([]string{config.OrdererGroupKey}, BlockValidationPolicyKey, configvaluesmsp.WritersPolicyKey, cb.ImplicitMetaPolicy_ANY),
policies.TemplateImplicitMetaAnyPolicy([]string{config.OrdererGroupKey}, configvaluesmsp.ReadersPolicyKey),
policies.TemplateImplicitMetaAnyPolicy([]string{config.OrdererGroupKey}, configvaluesmsp.WritersPolicyKey),
policies.TemplateImplicitMetaMajorityPolicy([]string{config.OrdererGroupKey}, configvaluesmsp.AdminsPolicyKey),
}

for _, org := range conf.Orderer.Organizations {
mspConfig, err := msp.GetVerifyingMspConfig(org.MSPDir, org.BCCSP, org.ID)
if err != nil {
logger.Panicf("Error loading MSP configuration for org %s: %s", org.Name, err)
}
bs.ordererGroups = append(bs.ordererGroups, configvaluesmsp.TemplateGroupMSP([]string{configtxorderer.GroupKey, org.Name}, mspConfig))
bs.ordererGroups = append(bs.ordererGroups, configvaluesmsp.TemplateGroupMSP([]string{config.OrdererGroupKey, org.Name}, mspConfig))
}

switch conf.Orderer.OrdererType {
case ConsensusTypeSolo, ConsensusTypeSbft:
case ConsensusTypeKafka:
bs.ordererGroups = append(bs.ordererGroups, configtxorderer.TemplateKafkaBrokers(conf.Orderer.Kafka.Brokers))
bs.ordererGroups = append(bs.ordererGroups, config.TemplateKafkaBrokers(conf.Orderer.Kafka.Brokers))
default:
panic(fmt.Errorf("Wrong consenter type value given: %s", conf.Orderer.OrdererType))
}

bs.ordererSystemChannelGroups = []*cb.ConfigGroup{
// Policies
configtxorderer.TemplateChainCreationPolicyNames(DefaultChainCreationPolicyNames),
config.TemplateChainCreationPolicyNames(DefaultChainCreationPolicyNames),
}
}

Expand Down
Loading

0 comments on commit c8ff4b1

Please sign in to comment.