Skip to content

Commit

Permalink
[FAB-2526] Move consolidate config to one package
Browse files Browse the repository at this point in the history
https://jira.hyperledger.org/browse/FAB-2526

This CR consolidates config from fabric/common/configvalues/root and
fabric/common/configvalues to be in fabric/common/config.

This completes the refactoring of the config needed to support config
inspection which will follow in subsequent changesets.

Change-Id: I081547be49abc3d0839f0b3accd01d378f36bf81
Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Mar 7, 2017
1 parent efa8237 commit bcb9259
Show file tree
Hide file tree
Showing 44 changed files with 116 additions and 118 deletions.
14 changes: 14 additions & 0 deletions common/configvalues/api.go → common/config/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ type Application interface {
Organizations() map[string]ApplicationOrg
}

// Channel gives read only access to the channel configuration
type Channel interface {
// HashingAlgorithm returns the default algorithm to be used when hashing
// such as computing block hashes, and CreationPolicy digests
HashingAlgorithm() func(input []byte) []byte

// BlockDataHashingStructureWidth returns the width to use when constructing the
// Merkle tree to compute the BlockData hash
BlockDataHashingStructureWidth() uint32

// OrdererAddresses returns the list of valid orderer addresses to connect to to invoke Broadcast/Deliver
OrdererAddresses() []string
}

// Orderer stores the common shared orderer config
type Orderer interface {
// ConsensusType returns the configured consensus type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ package config
import (
"fmt"

api "github.com/hyperledger/fabric/common/configvalues"
"github.com/hyperledger/fabric/common/configvalues/msp"
"github.com/hyperledger/fabric/common/config/msp"
)

const (
Expand All @@ -39,7 +38,7 @@ type ApplicationConfig struct {
*standardValues

applicationGroup *ApplicationGroup
applicationOrgs map[string]api.ApplicationOrg
applicationOrgs map[string]ApplicationOrg
}

// NewSharedConfigImpl creates a new SharedConfigImpl with the given CryptoHelper
Expand All @@ -52,7 +51,7 @@ func NewApplicationGroup(mspConfig *msp.MSPConfigHandler) *ApplicationGroup {
return ag
}

func (ag *ApplicationGroup) NewGroup(name string) (api.ValueProposer, error) {
func (ag *ApplicationGroup) NewGroup(name string) (ValueProposer, error) {
return NewApplicationOrgGroup(name, ag.mspConfig), nil
}

Expand All @@ -75,8 +74,8 @@ func NewApplicationConfig(ag *ApplicationGroup) *ApplicationConfig {
}
}

func (ac *ApplicationConfig) Validate(groups map[string]api.ValueProposer) error {
ac.applicationOrgs = make(map[string]api.ApplicationOrg)
func (ac *ApplicationConfig) Validate(groups map[string]ValueProposer) error {
ac.applicationOrgs = make(map[string]ApplicationOrg)
var ok bool
for key, value := range groups {
ac.applicationOrgs[key], ok = value.(*ApplicationOrgGroup)
Expand All @@ -92,6 +91,6 @@ func (ac *ApplicationConfig) Commit() {
}

// Organizations returns a map of org ID to ApplicationOrg
func (ac *ApplicationConfig) Organizations() map[string]api.ApplicationOrg {
func (ac *ApplicationConfig) Organizations() map[string]ApplicationOrg {
return ac.applicationOrgs
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package config
import (
"testing"

api "github.com/hyperledger/fabric/common/configvalues"

logging "github.com/op/go-logging"
)

Expand All @@ -29,5 +27,5 @@ func init() {
}

func TestApplicationInterface(t *testing.T) {
_ = api.Application((*ApplicationGroup)(nil))
_ = Application((*ApplicationGroup)(nil))
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ limitations under the License.
package config

import (
api "github.com/hyperledger/fabric/common/configvalues"
mspconfig "github.com/hyperledger/fabric/common/configvalues/msp"
mspconfig "github.com/hyperledger/fabric/common/config/msp"
pb "github.com/hyperledger/fabric/protos/peer"

logging "github.com/op/go-logging"
Expand Down Expand Up @@ -87,7 +86,7 @@ func NewApplicationOrgConfig(aog *ApplicationOrgGroup) *ApplicationOrgConfig {
return aoc
}

func (aoc *ApplicationOrgConfig) Validate(groups map[string]api.ValueProposer) error {
func (aoc *ApplicationOrgConfig) Validate(groups map[string]ValueProposer) error {
if logger.IsEnabledFor(logging.DEBUG) {
logger.Debugf("Anchor peers for org %s are %v", aoc.applicationOrgGroup.name, aoc.protos.AnchorPeers)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ package config

import (
"testing"

api "github.com/hyperledger/fabric/common/configvalues"
)

func TestApplicationOrgInterface(t *testing.T) {
_ = api.ValueProposer(NewApplicationOrgGroup("id", nil))
_ = ValueProposer(NewApplicationOrgGroup("id", nil))
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import (
"math"

"github.com/hyperledger/fabric/bccsp"
api "github.com/hyperledger/fabric/common/configvalues"
"github.com/hyperledger/fabric/common/configvalues/msp"
"github.com/hyperledger/fabric/common/config/msp"
"github.com/hyperledger/fabric/common/util"
cb "github.com/hyperledger/fabric/protos/common"
)
Expand Down Expand Up @@ -107,7 +106,7 @@ func (cg *ChannelGroup) ApplicationConfig() *ApplicationGroup {
}

// NewGroup instantiates either a new application or orderer config
func (cg *ChannelGroup) NewGroup(group string) (api.ValueProposer, error) {
func (cg *ChannelGroup) NewGroup(group string) (ValueProposer, error) {
switch group {
case ApplicationGroupKey:
return NewApplicationGroup(cg.mspConfigHandler), nil
Expand Down Expand Up @@ -160,7 +159,7 @@ func (cc *ChannelConfig) OrdererAddresses() []string {

// Validate inspects the generated configuration protos, ensures that the values are correct, and
// sets the ChannelConfig fields that may be referenced after Commit
func (cc *ChannelConfig) Validate(groups map[string]api.ValueProposer) error {
func (cc *ChannelConfig) Validate(groups map[string]ValueProposer) error {
for _, validator := range []func() error{
cc.validateHashingAlgorithm,
cc.validateBlockDataHashingStructure,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func init() {
}

func TestInterface(t *testing.T) {
_ = ChannelValues(NewChannelGroup(nil))
_ = Channel(NewChannelGroup(nil))
}

func TestHashingAlgorithm(t *testing.T) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import (
"strings"
"time"

api "github.com/hyperledger/fabric/common/configvalues"
"github.com/hyperledger/fabric/common/configvalues/msp"
"github.com/hyperledger/fabric/common/config/msp"
ab "github.com/hyperledger/fabric/protos/orderer"
)

Expand Down Expand Up @@ -78,7 +77,7 @@ func NewOrdererGroup(mspConfig *msp.MSPConfigHandler) *OrdererGroup {
}

// NewGroup returns an Org instance
func (og *OrdererGroup) NewGroup(name string) (api.ValueProposer, error) {
func (og *OrdererGroup) NewGroup(name string) (ValueProposer, error) {
return NewOrganizationGroup(name, og.mspConfig), nil
}

Expand Down Expand Up @@ -143,7 +142,7 @@ func (oc *OrdererConfig) KafkaBrokers() []string {
return oc.protos.KafkaBrokers.Brokers
}

func (oc *OrdererConfig) Validate(groups map[string]api.ValueProposer) error {
func (oc *OrdererConfig) Validate(groups map[string]ValueProposer) error {
for _, validator := range []func() error{
oc.validateConsensusType,
oc.validateBatchSize,
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ package config
import (
"fmt"

api "github.com/hyperledger/fabric/common/configvalues"
mspconfig "github.com/hyperledger/fabric/common/configvalues/msp"
mspconfig "github.com/hyperledger/fabric/common/config/msp"
"github.com/hyperledger/fabric/msp"
mspprotos "github.com/hyperledger/fabric/protos/msp"
)
Expand Down Expand Up @@ -74,7 +73,7 @@ func (og *OrganizationGroup) MSPID() string {
}

// NewGroup always errors
func (og *OrganizationGroup) NewGroup(name string) (api.ValueProposer, error) {
func (og *OrganizationGroup) NewGroup(name string) (ValueProposer, error) {
return nil, fmt.Errorf("Organization does not support subgroups")
}

Expand All @@ -99,7 +98,7 @@ func NewOrganizationConfig(og *OrganizationGroup) *OrganizationConfig {
}

// Validate returns whether the configuration is valid
func (oc *OrganizationConfig) Validate(groups map[string]api.ValueProposer) error {
func (oc *OrganizationConfig) Validate(groups map[string]ValueProposer) error {
return oc.validateMSP()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package config
import (
"fmt"

api "github.com/hyperledger/fabric/common/configvalues"
cb "github.com/hyperledger/fabric/protos/common"

"github.com/golang/protobuf/proto"
Expand All @@ -36,7 +35,7 @@ type Values interface {

// Validate should ensure that the values set into the proto messages are correct
// and that the new group values are allowed
Validate(map[string]api.ValueProposer) error
Validate(map[string]ValueProposer) error

// Commit should call back into the Value handler to update the config
Commit()
Expand All @@ -45,12 +44,12 @@ type Values interface {
// Handler
type Handler interface {
Allocate() Values
NewGroup(name string) (api.ValueProposer, error)
NewGroup(name string) (ValueProposer, error)
}

type config struct {
allocated Values
groups map[string]api.ValueProposer
groups map[string]ValueProposer
}

type Proposer struct {
Expand All @@ -67,20 +66,20 @@ func NewProposer(vh Handler) *Proposer {
}

// BeginValueProposals called when a config proposal is begun
func (p *Proposer) BeginValueProposals(groups []string) ([]api.ValueProposer, error) {
func (p *Proposer) BeginValueProposals(groups []string) ([]ValueProposer, error) {
if p.pending != nil {
logger.Panicf("Duplicated BeginValueProposals without Rollback or Commit")
}

result := make([]api.ValueProposer, len(groups))
result := make([]ValueProposer, len(groups))

p.pending = &config{
allocated: p.vh.Allocate(),
groups: make(map[string]api.ValueProposer),
groups: make(map[string]ValueProposer),
}

for i, groupName := range groups {
var group api.ValueProposer
var group ValueProposer
var ok bool

if p.current == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"fmt"
"testing"

api "github.com/hyperledger/fabric/common/configvalues"
cb "github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/utils"

Expand All @@ -43,7 +42,7 @@ func (v *mockValues) ProtoMsg(key string) (proto.Message, bool) {
return msg, ok
}

func (v *mockValues) Validate(map[string]api.ValueProposer) error {
func (v *mockValues) Validate(map[string]ValueProposer) error {
return v.ValidateReturn
}

Expand All @@ -57,15 +56,15 @@ func newMockValues() *mockValues {

type mockHandler struct {
AllocateReturn *mockValues
NewGroupMap map[string]api.ValueProposer
NewGroupMap map[string]ValueProposer
NewGroupError error
}

func (h *mockHandler) Allocate() Values {
return h.AllocateReturn
}

func (h *mockHandler) NewGroup(name string) (api.ValueProposer, error) {
func (h *mockHandler) NewGroup(name string) (ValueProposer, error) {
group, ok := h.NewGroupMap[name]
if !ok {
return nil, fmt.Errorf("Missing group implies error")
Expand All @@ -76,7 +75,7 @@ func (h *mockHandler) NewGroup(name string) (api.ValueProposer, error) {
func newMockHandler() *mockHandler {
return &mockHandler{
AllocateReturn: newMockValues(),
NewGroupMap: make(map[string]api.ValueProposer),
NewGroupMap: make(map[string]ValueProposer),
}
}

Expand Down Expand Up @@ -149,7 +148,7 @@ func TestGroups(t *testing.T) {
assert.NoError(t, err, "Both groups were present")
p.CommitProposals()

mh.NewGroupMap = make(map[string]api.ValueProposer)
mh.NewGroupMap = make(map[string]ValueProposer)
_, err = p.BeginValueProposals([]string{"foo", "bar"})
assert.NoError(t, err, "Should not have tried to recreate the groups")
p.CommitProposals()
Expand Down
9 changes: 4 additions & 5 deletions common/configvalues/root/root.go → common/config/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ package config
import (
"fmt"

configvaluesapi "github.com/hyperledger/fabric/common/configvalues"
"github.com/hyperledger/fabric/common/configvalues/msp"
"github.com/hyperledger/fabric/common/config/msp"
cb "github.com/hyperledger/fabric/protos/common"
)

Expand All @@ -32,7 +31,7 @@ type Root struct {
mspConfigHandler *msp.MSPConfigHandler
}

// NewRoot creates a new instance of the configvalues Root
// NewRoot creates a new instance of the Root
func NewRoot(mspConfigHandler *msp.MSPConfigHandler) *Root {
return &Root{
channel: NewChannelGroup(mspConfigHandler),
Expand All @@ -41,15 +40,15 @@ func NewRoot(mspConfigHandler *msp.MSPConfigHandler) *Root {
}

// BeginValueProposals is used to start a new config proposal
func (r *Root) BeginValueProposals(groups []string) ([]configvaluesapi.ValueProposer, error) {
func (r *Root) BeginValueProposals(groups []string) ([]ValueProposer, error) {
if len(groups) != 1 {
return nil, fmt.Errorf("Root config only supports having one base group")
}
if groups[0] != ChannelGroupKey {
return nil, fmt.Errorf("Root group must have channel")
}
r.mspConfigHandler.BeginConfig()
return []configvaluesapi.ValueProposer{r.channel}, nil
return []ValueProposer{r.channel}, nil
}

// RollbackConfig is used to abandon a new config proposal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package config
import (
"testing"

"github.com/hyperledger/fabric/common/configvalues/msp"
"github.com/hyperledger/fabric/common/config/msp"

logging "github.com/op/go-logging"
"github.com/stretchr/testify/assert"
Expand Down
File renamed without changes.
File renamed without changes.
11 changes: 5 additions & 6 deletions common/configtx/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ limitations under the License.
package api

import (
configvalues "github.com/hyperledger/fabric/common/configvalues"
config "github.com/hyperledger/fabric/common/configvalues/root"
"github.com/hyperledger/fabric/common/config"
"github.com/hyperledger/fabric/common/policies"
"github.com/hyperledger/fabric/msp"
cb "github.com/hyperledger/fabric/protos/common"
Expand Down Expand Up @@ -52,13 +51,13 @@ type Resources interface {
PolicyManager() policies.Manager

// ChannelConfig returns the ChannelConfig for the chain
ChannelConfig() config.ChannelValues
ChannelConfig() config.Channel

// OrdererConfig returns the configtxorderer.SharedConfig for the channel
OrdererConfig() configvalues.Orderer
OrdererConfig() config.Orderer

// ApplicationConfig returns the configtxapplication.SharedConfig for the channel
ApplicationConfig() configvalues.Application
ApplicationConfig() config.Application

// MSPManager returns the msp.MSPManager for the chain
MSPManager() msp.MSPManager
Expand Down Expand Up @@ -89,7 +88,7 @@ type PolicyHandler interface {
// for single Handlers to handle multiple paths
type Initializer interface {
// ValueProposer return the root value proposer
ValueProposer() configvalues.ValueProposer
ValueProposer() config.ValueProposer

// PolicyProposer return the root policy proposer
PolicyProposer() policies.Proposer
Expand Down
Loading

0 comments on commit bcb9259

Please sign in to comment.