Skip to content

Commit

Permalink
[FAB-2130] Initialize configtx Handlers together
Browse files Browse the repository at this point in the history
https://jira.hyperledger.org/browse/FAB-2130

Now that the assorted configtx Handlers have been consolidated, the
piecemeal instantiation across peer/orderer is no longer necessary and
all components can be instantiated together.  This is needed in
preparation of the pending configtx overhaul.

Change-Id: Ie3a607d38cbaea75cd6497666a12ed6664c52af2
Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
Jason Yellick committed Feb 11, 2017
1 parent 4ae2508 commit 417eccb
Showing 6 changed files with 63 additions and 27 deletions.
10 changes: 8 additions & 2 deletions common/configtx/api/api.go
Original file line number Diff line number Diff line change
@@ -105,16 +105,22 @@ type Manager interface {
Sequence() uint64
}

// Resources is the common set of config resources for all chains
// Resources is the common set of config resources for all channels
// Depending on whether chain is used at the orderer or at the peer, other
// config resources may be available
type Resources interface {
// PolicyManager returns the policies.Manager for the chain
// PolicyManager returns the policies.Manager for the channel
PolicyManager() policies.Manager

// ChannelConfig returns the ChannelConfig for the chain
ChannelConfig() ChannelConfig

// OrdererConfig returns the configtxorderer.SharedConfig for the channel
OrdererConfig() OrdererConfig

// ApplicationConfig returns the configtxapplication.SharedConfig for the channel
ApplicationConfig() ApplicationConfig

// MSPManager returns the msp.MSPManager for the chain
MSPManager() msp.MSPManager
}
3 changes: 2 additions & 1 deletion common/configtx/handlers/application/template_test.go
Original file line number Diff line number Diff line change
@@ -14,11 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package application
package application_test

import (
"testing"

. "github.com/hyperledger/fabric/common/configtx/handlers/application"
configtxtest "github.com/hyperledger/fabric/common/configtx/test"
)

42 changes: 32 additions & 10 deletions common/configtx/resources.go
Original file line number Diff line number Diff line change
@@ -19,18 +19,22 @@ package configtx
import (
"github.com/hyperledger/fabric/common/cauthdsl"
"github.com/hyperledger/fabric/common/configtx/api"
"github.com/hyperledger/fabric/common/configtx/handlers/channel"
configtxapplication "github.com/hyperledger/fabric/common/configtx/handlers/application"
configtxchannel "github.com/hyperledger/fabric/common/configtx/handlers/channel"
configtxmsp "github.com/hyperledger/fabric/common/configtx/handlers/msp"
configtxorderer "github.com/hyperledger/fabric/common/configtx/handlers/orderer"
"github.com/hyperledger/fabric/common/policies"
"github.com/hyperledger/fabric/msp"
cb "github.com/hyperledger/fabric/protos/common"
)

type resources struct {
handlers map[cb.ConfigItem_ConfigType]api.Handler
policyManager policies.Manager
channelConfig api.ChannelConfig
mspConfigHandler *configtxmsp.MSPConfigHandler
handlers map[cb.ConfigItem_ConfigType]api.Handler
policyManager policies.Manager
channelConfig api.ChannelConfig
ordererConfig api.OrdererConfig
applicationConfig api.ApplicationConfig
mspConfigHandler *configtxmsp.MSPConfigHandler
}

// PolicyManager returns the policies.Manager for the chain
@@ -43,6 +47,16 @@ func (r *resources) ChannelConfig() api.ChannelConfig {
return r.channelConfig
}

// OrdererConfig returns the api.OrdererConfig for the chain
func (r *resources) OrdererConfig() api.OrdererConfig {
return r.ordererConfig
}

// ApplicationConfig returns the api.ApplicationConfig for the chain
func (r *resources) ApplicationConfig() api.ApplicationConfig {
return r.applicationConfig
}

// MSPManager returns the msp.MSPManager for the chain
func (r *resources) MSPManager() msp.MSPManager {
return r.mspConfigHandler
@@ -70,14 +84,20 @@ func NewInitializer() api.Initializer {
}

policyManager := policies.NewManagerImpl(policyProviderMap)
channelConfig := channel.NewSharedConfigImpl()
channelConfig := configtxchannel.NewSharedConfigImpl()
ordererConfig := configtxorderer.NewManagerImpl()
applicationConfig := configtxapplication.NewSharedConfigImpl()
handlers := make(map[cb.ConfigItem_ConfigType]api.Handler)

for ctype := range cb.ConfigItem_ConfigType_name {
rtype := cb.ConfigItem_ConfigType(ctype)
switch rtype {
case cb.ConfigItem_CHAIN:
handlers[rtype] = channelConfig
case cb.ConfigItem_ORDERER:
handlers[rtype] = ordererConfig
case cb.ConfigItem_PEER:
handlers[rtype] = applicationConfig
case cb.ConfigItem_POLICY:
handlers[rtype] = policyManager
case cb.ConfigItem_MSP:
@@ -88,9 +108,11 @@ func NewInitializer() api.Initializer {
}

return &resources{
handlers: handlers,
policyManager: policyManager,
channelConfig: channelConfig,
mspConfigHandler: mspConfigHandler,
handlers: handlers,
policyManager: policyManager,
channelConfig: channelConfig,
ordererConfig: ordererConfig,
applicationConfig: applicationConfig,
mspConfigHandler: mspConfigHandler,
}
}
16 changes: 16 additions & 0 deletions common/mocks/configtx/configtx.go
Original file line number Diff line number Diff line change
@@ -33,6 +33,12 @@ type Initializer struct {
// ChannelConfigVal is returned as the result of ChannelConfig()
ChannelConfigVal configtxapi.ChannelConfig

// OrdererConfigVal is returned as the result of OrdererConfig()
OrdererConfigVal configtxapi.OrdererConfig

// ApplicationConfigVal is returned as the result of ApplicationConfig()
ApplicationConfigVal configtxapi.ApplicationConfig

// MSPManagerVal is returned as the result of MSPManager()
MSPManagerVal msp.MSPManager
}
@@ -52,6 +58,16 @@ func (i *Initializer) ChannelConfig() configtxapi.ChannelConfig {
return i.ChannelConfigVal
}

// Returns the OrdererConfigVal
func (i *Initializer) OrdererConfig() configtxapi.OrdererConfig {
return i.OrdererConfigVal
}

// Returns the ApplicationConfigVal
func (i *Initializer) ApplicationConfig() configtxapi.ApplicationConfig {
return i.ApplicationConfigVal
}

// Returns the MSPManagerVal
func (i *Initializer) MSPManager() msp.MSPManager {
return i.MSPManagerVal
9 changes: 3 additions & 6 deletions core/peer/peer.go
Original file line number Diff line number Diff line change
@@ -24,7 +24,6 @@ import (

"github.com/hyperledger/fabric/common/configtx"
configtxapi "github.com/hyperledger/fabric/common/configtx/api"
configtxapplication "github.com/hyperledger/fabric/common/configtx/handlers/application"
"github.com/hyperledger/fabric/core/comm"
"github.com/hyperledger/fabric/core/committer"
"github.com/hyperledger/fabric/core/committer/txvalidator"
@@ -160,19 +159,17 @@ func createChain(cid string, ledger ledger.PeerLedger, cb *common.Block) error {
return err
}

sharedConfigHandler := configtxapplication.NewSharedConfigImpl()
configtxInitializer := configtx.NewInitializer()

gossipEventer := service.GetGossipService().NewConfigEventer()

gossipCallbackWrapper := func(cm configtxapi.Manager) {
gossipEventer.ProcessConfigUpdate(&chainSupport{
Manager: cm,
ApplicationConfig: sharedConfigHandler,
ApplicationConfig: configtxInitializer.ApplicationConfig(),
})
}

configtxInitializer := configtx.NewInitializer()
configtxInitializer.Handlers()[common.ConfigItem_PEER] = sharedConfigHandler
configtxManager, err := configtx.NewManagerImplNext(
configEnvelope,
configtxInitializer,
@@ -187,7 +184,7 @@ func createChain(cid string, ledger ledger.PeerLedger, cb *common.Block) error {

cs := &chainSupport{
Manager: configtxManager,
ApplicationConfig: sharedConfigHandler,
ApplicationConfig: configtxManager.ApplicationConfig(), // TODO, refactor as this is accessible through Manager
ledger: ledger,
}

10 changes: 2 additions & 8 deletions orderer/multichain/manager.go
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@ import (

"github.com/hyperledger/fabric/common/configtx"
configtxapi "github.com/hyperledger/fabric/common/configtx/api"
configtxorderer "github.com/hyperledger/fabric/common/configtx/handlers/orderer"
ordererledger "github.com/hyperledger/fabric/orderer/ledger"
cb "github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/utils"
@@ -46,11 +45,10 @@ type Manager interface {

type configResources struct {
configtxapi.Manager
sharedConfig configtxapi.OrdererConfig
}

func (cr *configResources) SharedConfig() configtxapi.OrdererConfig {
return cr.sharedConfig
return cr.OrdererConfig()
}

type ledgerResources struct {
@@ -148,18 +146,14 @@ func (ml *multiLedger) GetChain(chainID string) (ChainSupport, bool) {
}

func newConfigResources(configEnvelope *cb.ConfigEnvelope) (*configResources, error) {
sharedConfigManager := configtxorderer.NewManagerImpl()
initializer := configtx.NewInitializer()
initializer.Handlers()[cb.ConfigItem_ORDERER] = sharedConfigManager

configManager, err := configtx.NewManagerImplNext(configEnvelope, initializer, nil)
if err != nil {
return nil, fmt.Errorf("Error unpacking config transaction: %s", err)
}

return &configResources{
Manager: configManager,
sharedConfig: sharedConfigManager,
Manager: configManager,
}, nil
}

0 comments on commit 417eccb

Please sign in to comment.