Skip to content

Commit

Permalink
Merge "[FAB-3831] Report empty application/orderer groups"
Browse files Browse the repository at this point in the history
  • Loading branch information
kchristidis authored and Gerrit Code Review committed Jun 9, 2017
2 parents ed19acc + 7918d5e commit c230992
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 20 deletions.
6 changes: 4 additions & 2 deletions common/configtx/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,16 @@ type Resources interface {
ChannelConfig() config.Channel

// OrdererConfig returns the config.Orderer for the channel
OrdererConfig() config.Orderer
// and whether the Orderer config exists
OrdererConfig() (config.Orderer, bool)

// ConsortiumsConfig() returns the config.Consortiums for the channel
// and whether the consortiums config exists
ConsortiumsConfig() (config.Consortiums, bool)

// ApplicationConfig returns the configtxapplication.SharedConfig for the channel
ApplicationConfig() config.Application
// and whether the Application config exists
ApplicationConfig() (config.Application, bool)

// MSPManager returns the msp.MSPManager for the chain
MSPManager() msp.MSPManager
Expand Down
16 changes: 12 additions & 4 deletions common/configtx/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,21 @@ func (r *resources) ChannelConfig() config.Channel {
}

// OrdererConfig returns the api.OrdererConfig for the chain
func (r *resources) OrdererConfig() config.Orderer {
return r.configRoot.Orderer()
func (r *resources) OrdererConfig() (config.Orderer, bool) {
result := r.configRoot.Orderer()
if result == nil {
return nil, false
}
return result, true
}

// ApplicationConfig returns the api.ApplicationConfig for the chain
func (r *resources) ApplicationConfig() config.Application {
return r.configRoot.Application()
func (r *resources) ApplicationConfig() (config.Application, bool) {
result := r.configRoot.Application()
if result == nil {
return nil, false
}
return result, true
}

// ConsortiumsConfig returns the api.ConsortiumsConfig for the chain and whether or not
Expand Down
8 changes: 4 additions & 4 deletions common/mocks/configtx/configtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ func (r *Resources) ChannelConfig() config.Channel {
}

// Returns the OrdererConfigVal
func (r *Resources) OrdererConfig() config.Orderer {
return r.OrdererConfigVal
func (r *Resources) OrdererConfig() (config.Orderer, bool) {
return r.OrdererConfigVal, r.OrdererConfigVal == nil
}

// Returns the ApplicationConfigVal
func (r *Resources) ApplicationConfig() config.Application {
return r.ApplicationConfigVal
func (r *Resources) ApplicationConfig() (config.Application, bool) {
return r.ApplicationConfigVal, r.ApplicationConfigVal == nil
}

func (r *Resources) ConsortiumsConfig() (config.Consortiums, bool) {
Expand Down
33 changes: 24 additions & 9 deletions core/peer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,14 @@ func createChain(cid string, ledger ledger.PeerLedger, cb *common.Block) error {
gossipEventer := service.GetGossipService().NewConfigEventer()

gossipCallbackWrapper := func(cm configtxapi.Manager) {
ac, ok := configtxInitializer.ApplicationConfig()
if !ok {
// TODO, handle a missing ApplicationConfig more gracefully
ac = nil
}
gossipEventer.ProcessConfigUpdate(&chainSupport{
Manager: cm,
Application: configtxInitializer.ApplicationConfig(),
Application: ac,
})
service.GetGossipService().SuspectPeers(func(identity api.PeerIdentityType) bool {
// TODO: this is a place-holder that would somehow make the MSP layer suspect
Expand All @@ -214,9 +219,13 @@ func createChain(cid string, ledger ledger.PeerLedger, cb *common.Block) error {
// TODO remove once all references to mspmgmt are gone from peer code
mspmgmt.XXXSetMSPManager(cid, configtxManager.MSPManager())

ac, ok := configtxInitializer.ApplicationConfig()
if !ok {
ac = nil
}
cs := &chainSupport{
Manager: configtxManager,
Application: configtxManager.ApplicationConfig(), // TODO, refactor as this is accessible through Manager
Application: ac, // TODO, refactor as this is accessible through Manager
ledger: ledger,
}

Expand Down Expand Up @@ -386,10 +395,14 @@ func buildTrustedRootsForChain(cm configtxapi.Manager) {
ordererRootCAs := [][]byte{}
appOrgMSPs := make(map[string]struct{})

//loop through app orgs and build map of MSPIDs
for _, appOrg := range cm.ApplicationConfig().Organizations() {
appOrgMSPs[appOrg.MSPID()] = struct{}{}
ac, ok := cm.ApplicationConfig()
if ok {
//loop through app orgs and build map of MSPIDs
for _, appOrg := range ac.Organizations() {
appOrgMSPs[appOrg.MSPID()] = struct{}{}
}
}

cid := cm.ChainID()
peerLogger.Debugf("updating root CAs for channel [%s]", cid)
msps, err := cm.MSPManager().GetMSPs()
Expand Down Expand Up @@ -452,13 +465,15 @@ func GetMSPIDs(cid string) []string {
return mockMSPIDGetter(cid)
}
if c, ok := chains.list[cid]; ok {
if c == nil || c.cs == nil ||
c.cs.ApplicationConfig() == nil ||
c.cs.ApplicationConfig().Organizations() == nil {
if c == nil || c.cs == nil {
return nil
}
ac, ok := c.cs.ApplicationConfig()
if !ok || ac.Organizations() == nil {
return nil
}

orgs := c.cs.ApplicationConfig().Organizations()
orgs := ac.Organizations()
toret := make([]string, len(orgs))
i := 0
for _, org := range orgs {
Expand Down
6 changes: 5 additions & 1 deletion orderer/multichain/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ type configResources struct {
}

func (cr *configResources) SharedConfig() config.Orderer {
return cr.OrdererConfig()
oc, ok := cr.OrdererConfig()
if !ok {
logger.Panicf("[channel %s] has no orderer configuration", cr.ChainID())
}
return oc
}

type ledgerResources struct {
Expand Down

0 comments on commit c230992

Please sign in to comment.