Skip to content

Commit

Permalink
[FAB-6033] Parse capabilities in channelconfig
Browse files Browse the repository at this point in the history
This CR adds parsing for the new capabilities structure into the
channel, channel application, and channel orderer configs.  There are
currently no consumers of this code, to be added in a later changeset.

Change-Id: I3cd1f8e510c905f820d6e0bb7458d51917ca810a
Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Sep 28, 2017
1 parent 64d1b8e commit 456283e
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 1 deletion.
27 changes: 27 additions & 0 deletions common/channelconfig/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type ApplicationOrg interface {
type Application interface {
// Organizations returns a map of org ID to ApplicationOrg
Organizations() map[string]ApplicationOrg

// Capabilities defines the capabilities for the application portion of a channel
Capabilities() ApplicationCapabilities
}

// Channel gives read only access to the channel configuration
Expand All @@ -52,6 +55,9 @@ type Channel interface {

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

// Capabilities defines the capabilities for a channel
Capabilities() ChannelCapabilities
}

// Consortiums represents the set of consortiums serviced by an ordering service
Expand Down Expand Up @@ -90,6 +96,27 @@ type Orderer interface {

// Organizations returns the organizations for the ordering service
Organizations() map[string]Org

// Capabilities defines the capabilities for the orderer portion of a channel
Capabilities() OrdererCapabilities
}

// ChannelCapabilities defines the capabilities for a channel
type ChannelCapabilities interface {
// Supported returns an error if there are unknown capabilities in this channel which are required
Supported() error
}

// ApplicationCapabilities defines the capabilities for the application portion of a channel
type ApplicationCapabilities interface {
// Supported returns an error if there are unknown capabilities in this channel which are required
Supported() error
}

// OrdererCapabilities defines the capabilities for the orderer portion of a channel
type OrdererCapabilities interface {
// Supported returns an error if there are unknown capabilities in this channel which are required
Supported() error
}

// Resources is the common set of config resources for all channels
Expand Down
20 changes: 20 additions & 0 deletions common/channelconfig/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,37 @@ SPDX-License-Identifier: Apache-2.0
package channelconfig

import (
"github.com/hyperledger/fabric/common/capabilities"
cb "github.com/hyperledger/fabric/protos/common"

"github.com/pkg/errors"
)

const (
// ApplicationGroupKey is the group name for the Application config
ApplicationGroupKey = "Application"
)

// ApplicationProtos is used as the source of the ApplicationConfig
type ApplicationProtos struct {
Capabilities *cb.Capabilities
}

// ApplicationConfig implements the Application interface
type ApplicationConfig struct {
applicationOrgs map[string]ApplicationOrg
protos *ApplicationProtos
}

// NewApplicationConfig creates config from an Application config group
func NewApplicationConfig(appGroup *cb.ConfigGroup, mspConfig *MSPConfigHandler) (*ApplicationConfig, error) {
ac := &ApplicationConfig{
applicationOrgs: make(map[string]ApplicationOrg),
protos: &ApplicationProtos{},
}

if err := DeserializeProtoValuesFromGroup(appGroup, ac.protos); err != nil {
return nil, errors.Wrap(err, "failed to deserialize values")
}

var err error
Expand All @@ -40,3 +55,8 @@ func NewApplicationConfig(appGroup *cb.ConfigGroup, mspConfig *MSPConfigHandler)
func (ac *ApplicationConfig) Organizations() map[string]ApplicationOrg {
return ac.applicationOrgs
}

// Capabilities returns a map of capability name to Capability
func (ac *ApplicationConfig) Capabilities() ApplicationCapabilities {
return capabilities.NewApplicationProvider(ac.protos.Capabilities.Capabilities)
}
7 changes: 7 additions & 0 deletions common/channelconfig/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"math"

"github.com/hyperledger/fabric/bccsp"
"github.com/hyperledger/fabric/common/capabilities"
"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/msp"
cb "github.com/hyperledger/fabric/protos/common"
Expand Down Expand Up @@ -56,6 +57,7 @@ type ChannelProtos struct {
BlockDataHashingStructure *cb.BlockDataHashingStructure
OrdererAddresses *cb.OrdererAddresses
Consortium *cb.Consortium
Capabilities *cb.Capabilities
}

// ChannelConfig stores the channel configuration
Expand Down Expand Up @@ -151,6 +153,11 @@ func (cc *ChannelConfig) ConsortiumName() string {
return cc.protos.Consortium.Name
}

// Capabilities returns information about the available capabilities for this channel
func (cc *ChannelConfig) Capabilities() ChannelCapabilities {
return capabilities.NewChannelProvider(cc.protos.Capabilities.Capabilities)
}

// Validate inspects the generated configuration protos and ensures that the values are correct
func (cc *ChannelConfig) Validate() error {
for _, validator := range []func() error{
Expand Down
7 changes: 7 additions & 0 deletions common/channelconfig/orderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"strings"
"time"

"github.com/hyperledger/fabric/common/capabilities"
cb "github.com/hyperledger/fabric/protos/common"
ab "github.com/hyperledger/fabric/protos/orderer"

Expand Down Expand Up @@ -48,6 +49,7 @@ type OrdererProtos struct {
BatchTimeout *ab.BatchTimeout
KafkaBrokers *ab.KafkaBrokers
ChannelRestrictions *ab.ChannelRestrictions
Capabilities *cb.Capabilities
}

// OrdererConfig holds the orderer configuration information
Expand Down Expand Up @@ -114,6 +116,11 @@ func (oc *OrdererConfig) Organizations() map[string]Org {
return oc.orgs
}

// Capabilities returns the capabilities the ordering network has for this channel
func (oc *OrdererConfig) Capabilities() OrdererCapabilities {
return capabilities.NewOrdererProvider(oc.protos.Capabilities.Capabilities)
}

func (oc *OrdererConfig) Validate() error {
for _, validator := range []func() error{
oc.validateBatchSize,
Expand Down
12 changes: 11 additions & 1 deletion common/mocks/config/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ limitations under the License.

package config

import "github.com/hyperledger/fabric/common/util"
import (
"github.com/hyperledger/fabric/common/channelconfig"
"github.com/hyperledger/fabric/common/util"
)

func nearIdentityHash(input []byte) []byte {
return util.ConcatenateBytes([]byte("FakeHash("), input, []byte(""))
Expand All @@ -30,6 +33,8 @@ type Channel struct {
BlockDataHashingStructureWidthVal uint32
// OrdererAddressesVal is returned as the result of OrdererAddresses()
OrdererAddressesVal []string
// CapabilitiesVal is returned as the result of Capabilities()
CapabilitiesVal channelconfig.ChannelCapabilities
}

// HashingAlgorithm returns the HashingAlgorithmVal if set, otherwise a fake simple hash function
Expand All @@ -49,3 +54,8 @@ func (scm *Channel) BlockDataHashingStructureWidth() uint32 {
func (scm *Channel) OrdererAddresses() []string {
return scm.OrdererAddressesVal
}

// Capabilities returns CapabilitiesVal
func (scm *Channel) Capabilities() channelconfig.ChannelCapabilities {
return scm.CapabilitiesVal
}
7 changes: 7 additions & 0 deletions common/mocks/config/orderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type Orderer struct {
MaxChannelsCountVal uint64
// OrganizationsVal is returned as the result of Organizations()
OrganizationsVal map[string]channelconfig.Org
// CapabilitiesVal is returned as the result of Capabilities()
CapabilitiesVal channelconfig.OrdererCapabilities
}

// ConsensusType returns the ConsensusTypeVal
Expand Down Expand Up @@ -58,3 +60,8 @@ func (scm *Orderer) MaxChannelsCount() uint64 {
func (scm *Orderer) Organizations() map[string]channelconfig.Org {
return scm.OrganizationsVal
}

// Capabilities returns CapabilitiesVal
func (scm *Orderer) Capabilities() channelconfig.OrdererCapabilities {
return scm.CapabilitiesVal
}

0 comments on commit 456283e

Please sign in to comment.