Skip to content

Commit 456283e

Browse files
author
Jason Yellick
committed
[FAB-6033] Parse capabilities in channelconfig
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>
1 parent 64d1b8e commit 456283e

File tree

6 files changed

+79
-1
lines changed

6 files changed

+79
-1
lines changed

common/channelconfig/api.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ type ApplicationOrg interface {
3838
type Application interface {
3939
// Organizations returns a map of org ID to ApplicationOrg
4040
Organizations() map[string]ApplicationOrg
41+
42+
// Capabilities defines the capabilities for the application portion of a channel
43+
Capabilities() ApplicationCapabilities
4144
}
4245

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

5356
// OrdererAddresses returns the list of valid orderer addresses to connect to to invoke Broadcast/Deliver
5457
OrdererAddresses() []string
58+
59+
// Capabilities defines the capabilities for a channel
60+
Capabilities() ChannelCapabilities
5561
}
5662

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

9197
// Organizations returns the organizations for the ordering service
9298
Organizations() map[string]Org
99+
100+
// Capabilities defines the capabilities for the orderer portion of a channel
101+
Capabilities() OrdererCapabilities
102+
}
103+
104+
// ChannelCapabilities defines the capabilities for a channel
105+
type ChannelCapabilities interface {
106+
// Supported returns an error if there are unknown capabilities in this channel which are required
107+
Supported() error
108+
}
109+
110+
// ApplicationCapabilities defines the capabilities for the application portion of a channel
111+
type ApplicationCapabilities interface {
112+
// Supported returns an error if there are unknown capabilities in this channel which are required
113+
Supported() error
114+
}
115+
116+
// OrdererCapabilities defines the capabilities for the orderer portion of a channel
117+
type OrdererCapabilities interface {
118+
// Supported returns an error if there are unknown capabilities in this channel which are required
119+
Supported() error
93120
}
94121

95122
// Resources is the common set of config resources for all channels

common/channelconfig/application.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,37 @@ SPDX-License-Identifier: Apache-2.0
77
package channelconfig
88

99
import (
10+
"github.com/hyperledger/fabric/common/capabilities"
1011
cb "github.com/hyperledger/fabric/protos/common"
12+
13+
"github.com/pkg/errors"
1114
)
1215

1316
const (
1417
// ApplicationGroupKey is the group name for the Application config
1518
ApplicationGroupKey = "Application"
1619
)
1720

21+
// ApplicationProtos is used as the source of the ApplicationConfig
22+
type ApplicationProtos struct {
23+
Capabilities *cb.Capabilities
24+
}
25+
26+
// ApplicationConfig implements the Application interface
1827
type ApplicationConfig struct {
1928
applicationOrgs map[string]ApplicationOrg
29+
protos *ApplicationProtos
2030
}
2131

2232
// NewApplicationConfig creates config from an Application config group
2333
func NewApplicationConfig(appGroup *cb.ConfigGroup, mspConfig *MSPConfigHandler) (*ApplicationConfig, error) {
2434
ac := &ApplicationConfig{
2535
applicationOrgs: make(map[string]ApplicationOrg),
36+
protos: &ApplicationProtos{},
37+
}
38+
39+
if err := DeserializeProtoValuesFromGroup(appGroup, ac.protos); err != nil {
40+
return nil, errors.Wrap(err, "failed to deserialize values")
2641
}
2742

2843
var err error
@@ -40,3 +55,8 @@ func NewApplicationConfig(appGroup *cb.ConfigGroup, mspConfig *MSPConfigHandler)
4055
func (ac *ApplicationConfig) Organizations() map[string]ApplicationOrg {
4156
return ac.applicationOrgs
4257
}
58+
59+
// Capabilities returns a map of capability name to Capability
60+
func (ac *ApplicationConfig) Capabilities() ApplicationCapabilities {
61+
return capabilities.NewApplicationProvider(ac.protos.Capabilities.Capabilities)
62+
}

common/channelconfig/channel.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"math"
1212

1313
"github.com/hyperledger/fabric/bccsp"
14+
"github.com/hyperledger/fabric/common/capabilities"
1415
"github.com/hyperledger/fabric/common/util"
1516
"github.com/hyperledger/fabric/msp"
1617
cb "github.com/hyperledger/fabric/protos/common"
@@ -56,6 +57,7 @@ type ChannelProtos struct {
5657
BlockDataHashingStructure *cb.BlockDataHashingStructure
5758
OrdererAddresses *cb.OrdererAddresses
5859
Consortium *cb.Consortium
60+
Capabilities *cb.Capabilities
5961
}
6062

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

156+
// Capabilities returns information about the available capabilities for this channel
157+
func (cc *ChannelConfig) Capabilities() ChannelCapabilities {
158+
return capabilities.NewChannelProvider(cc.protos.Capabilities.Capabilities)
159+
}
160+
154161
// Validate inspects the generated configuration protos and ensures that the values are correct
155162
func (cc *ChannelConfig) Validate() error {
156163
for _, validator := range []func() error{

common/channelconfig/orderer.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"strings"
1414
"time"
1515

16+
"github.com/hyperledger/fabric/common/capabilities"
1617
cb "github.com/hyperledger/fabric/protos/common"
1718
ab "github.com/hyperledger/fabric/protos/orderer"
1819

@@ -48,6 +49,7 @@ type OrdererProtos struct {
4849
BatchTimeout *ab.BatchTimeout
4950
KafkaBrokers *ab.KafkaBrokers
5051
ChannelRestrictions *ab.ChannelRestrictions
52+
Capabilities *cb.Capabilities
5153
}
5254

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

119+
// Capabilities returns the capabilities the ordering network has for this channel
120+
func (oc *OrdererConfig) Capabilities() OrdererCapabilities {
121+
return capabilities.NewOrdererProvider(oc.protos.Capabilities.Capabilities)
122+
}
123+
117124
func (oc *OrdererConfig) Validate() error {
118125
for _, validator := range []func() error{
119126
oc.validateBatchSize,

common/mocks/config/channel.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ limitations under the License.
1616

1717
package config
1818

19-
import "github.com/hyperledger/fabric/common/util"
19+
import (
20+
"github.com/hyperledger/fabric/common/channelconfig"
21+
"github.com/hyperledger/fabric/common/util"
22+
)
2023

2124
func nearIdentityHash(input []byte) []byte {
2225
return util.ConcatenateBytes([]byte("FakeHash("), input, []byte(""))
@@ -30,6 +33,8 @@ type Channel struct {
3033
BlockDataHashingStructureWidthVal uint32
3134
// OrdererAddressesVal is returned as the result of OrdererAddresses()
3235
OrdererAddressesVal []string
36+
// CapabilitiesVal is returned as the result of Capabilities()
37+
CapabilitiesVal channelconfig.ChannelCapabilities
3338
}
3439

3540
// HashingAlgorithm returns the HashingAlgorithmVal if set, otherwise a fake simple hash function
@@ -49,3 +54,8 @@ func (scm *Channel) BlockDataHashingStructureWidth() uint32 {
4954
func (scm *Channel) OrdererAddresses() []string {
5055
return scm.OrdererAddressesVal
5156
}
57+
58+
// Capabilities returns CapabilitiesVal
59+
func (scm *Channel) Capabilities() channelconfig.ChannelCapabilities {
60+
return scm.CapabilitiesVal
61+
}

common/mocks/config/orderer.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ type Orderer struct {
2727
MaxChannelsCountVal uint64
2828
// OrganizationsVal is returned as the result of Organizations()
2929
OrganizationsVal map[string]channelconfig.Org
30+
// CapabilitiesVal is returned as the result of Capabilities()
31+
CapabilitiesVal channelconfig.OrdererCapabilities
3032
}
3133

3234
// ConsensusType returns the ConsensusTypeVal
@@ -58,3 +60,8 @@ func (scm *Orderer) MaxChannelsCount() uint64 {
5860
func (scm *Orderer) Organizations() map[string]channelconfig.Org {
5961
return scm.OrganizationsVal
6062
}
63+
64+
// Capabilities returns CapabilitiesVal
65+
func (scm *Orderer) Capabilities() channelconfig.OrdererCapabilities {
66+
return scm.CapabilitiesVal
67+
}

0 commit comments

Comments
 (0)