Skip to content

Commit d3419e7

Browse files
author
Jason Yellick
committed
[FAB-2104] Make channel shared config consistent
https://jira.hyperledger.org/browse/FAB-2104 The orderer and application shared config have just been moved under common/configtx. The channel configuration should be normalized to this pattern and location as well. Change-Id: I3cda8b73a4c94ff528db6e5cdbc987b4c69f90f8 Signed-off-by: Jason Yellick <[email protected]>
1 parent cc11fcb commit d3419e7

File tree

11 files changed

+71
-77
lines changed

11 files changed

+71
-77
lines changed

common/configtx/api/api.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,27 @@ package api
1919
import (
2020
"time"
2121

22-
"github.com/hyperledger/fabric/common/chainconfig"
2322
"github.com/hyperledger/fabric/common/policies"
2423
"github.com/hyperledger/fabric/msp"
2524
cb "github.com/hyperledger/fabric/protos/common"
2625
ab "github.com/hyperledger/fabric/protos/orderer"
2726
pb "github.com/hyperledger/fabric/protos/peer"
2827
)
2928

29+
// ChannelConfig stores the common channel config
30+
type ChannelConfig interface {
31+
// HashingAlgorithm returns the default algorithm to be used when hashing
32+
// such as computing block hashes, and CreationPolicy digests
33+
HashingAlgorithm() func(input []byte) []byte
34+
35+
// BlockDataHashingStructureWidth returns the width to use when constructing the
36+
// Merkle tree to compute the BlockData hash
37+
BlockDataHashingStructureWidth() uint32
38+
39+
// OrdererAddresses returns the list of valid orderer addresses to connect to to invoke Broadcast/Deliver
40+
OrdererAddresses() []string
41+
}
42+
3043
// ApplicationConfig stores the common shared application config
3144
type ApplicationConfig interface {
3245
// AnchorPeers returns the list of gossip anchor peers
@@ -99,8 +112,8 @@ type Resources interface {
99112
// PolicyManager returns the policies.Manager for the chain
100113
PolicyManager() policies.Manager
101114

102-
// ChainConfig returns the chainconfig.Descriptor for the chain
103-
ChainConfig() chainconfig.Descriptor
115+
// ChannelConfig returns the ChannelConfig for the chain
116+
ChannelConfig() ChannelConfig
104117

105118
// MSPManager returns the msp.MSPManager for the chain
106119
MSPManager() msp.MSPManager

common/chainconfig/chainconfig.go common/configtx/handlers/channel/sharedconfig.go

+14-31
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package chainconfig
17+
package channel
1818

1919
import (
2020
"fmt"
@@ -45,75 +45,58 @@ const (
4545
SHA3Shake256 = "SHAKE256"
4646
)
4747

48-
var logger = logging.MustGetLogger("common/chainconfig")
49-
50-
// Descriptor stores the common chain config
51-
// It is intended to be the primary accessor of DescriptorImpl
52-
// It is intended to discourage use of the other exported DescriptorImpl methods
53-
// which are used for updating the chain config by the configtx.Manager
54-
type Descriptor interface {
55-
// HashingAlgorithm returns the default algorithm to be used when hashing
56-
// such as computing block hashes, and CreationPolicy digests
57-
HashingAlgorithm() func(input []byte) []byte
58-
59-
// BlockDataHashingStructureWidth returns the width to use when constructing the
60-
// Merkle tree to compute the BlockData hash
61-
BlockDataHashingStructureWidth() uint32
62-
63-
// OrdererAddresses returns the list of valid orderer addresses to connect to to invoke Broadcast/Deliver
64-
OrdererAddresses() []string
65-
}
48+
var logger = logging.MustGetLogger("configtx/handlers/chainconfig")
6649

6750
type chainConfig struct {
6851
hashingAlgorithm func(input []byte) []byte
6952
blockDataHashingStructureWidth uint32
7053
ordererAddresses []string
7154
}
7255

73-
// DescriptorImpl is an implementation of Manager and configtx.ConfigHandler
56+
// SharedConfigImpl is an implementation of Manager and configtx.ConfigHandler
7457
// In general, it should only be referenced as an Impl for the configtx.Manager
75-
type DescriptorImpl struct {
58+
type SharedConfigImpl struct {
7659
pendingConfig *chainConfig
7760
config *chainConfig
7861
}
7962

80-
// NewDescriptorImpl creates a new DescriptorImpl with the given CryptoHelper
81-
func NewDescriptorImpl() *DescriptorImpl {
82-
return &DescriptorImpl{
63+
// NewSharedConfigImpl creates a new SharedConfigImpl with the given CryptoHelper
64+
func NewSharedConfigImpl() *SharedConfigImpl {
65+
return &SharedConfigImpl{
8366
config: &chainConfig{},
8467
}
8568
}
8669

8770
// HashingAlgorithm returns a function pointer to the chain hashing algorihtm
88-
func (pm *DescriptorImpl) HashingAlgorithm() func(input []byte) []byte {
71+
func (pm *SharedConfigImpl) HashingAlgorithm() func(input []byte) []byte {
8972
return pm.config.hashingAlgorithm
9073
}
9174

9275
// BlockDataHashingStructure returns the width to use when forming the block data hashing structure
93-
func (pm *DescriptorImpl) BlockDataHashingStructureWidth() uint32 {
76+
func (pm *SharedConfigImpl) BlockDataHashingStructureWidth() uint32 {
9477
return pm.config.blockDataHashingStructureWidth
9578
}
9679

9780
// OrdererAddresses returns the list of valid orderer addresses to connect to to invoke Broadcast/Deliver
98-
func (pm *DescriptorImpl) OrdererAddresses() []string {
81+
func (pm *SharedConfigImpl) OrdererAddresses() []string {
9982
return pm.config.ordererAddresses
10083
}
10184

10285
// BeginConfig is used to start a new config proposal
103-
func (pm *DescriptorImpl) BeginConfig() {
86+
func (pm *SharedConfigImpl) BeginConfig() {
10487
if pm.pendingConfig != nil {
10588
logger.Panicf("Programming error, cannot call begin in the middle of a proposal")
10689
}
10790
pm.pendingConfig = &chainConfig{}
10891
}
10992

11093
// RollbackConfig is used to abandon a new config proposal
111-
func (pm *DescriptorImpl) RollbackConfig() {
94+
func (pm *SharedConfigImpl) RollbackConfig() {
11295
pm.pendingConfig = nil
11396
}
11497

11598
// CommitConfig is used to commit a new config proposal
116-
func (pm *DescriptorImpl) CommitConfig() {
99+
func (pm *SharedConfigImpl) CommitConfig() {
117100
if pm.pendingConfig == nil {
118101
logger.Panicf("Programming error, cannot call commit without an existing proposal")
119102
}
@@ -122,7 +105,7 @@ func (pm *DescriptorImpl) CommitConfig() {
122105
}
123106

124107
// ProposeConfig is used to add new config to the config proposal
125-
func (pm *DescriptorImpl) ProposeConfig(configItem *cb.ConfigItem) error {
108+
func (pm *SharedConfigImpl) ProposeConfig(configItem *cb.ConfigItem) error {
126109
if configItem.Type != cb.ConfigItem_CHAIN {
127110
return fmt.Errorf("Expected type of ConfigItem_Chain, got %v", configItem.Type)
128111
}

common/chainconfig/chainconfig_test.go common/configtx/handlers/channel/sharedconfig_test.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package chainconfig
17+
package channel
1818

1919
import (
2020
"reflect"
2121
"testing"
2222

23+
configtxapi "github.com/hyperledger/fabric/common/configtx/api"
2324
cb "github.com/hyperledger/fabric/protos/common"
2425

2526
logging "github.com/op/go-logging"
@@ -38,7 +39,7 @@ func makeInvalidConfigItem(key string) *cb.ConfigItem {
3839
}
3940

4041
func TestInterface(t *testing.T) {
41-
_ = Descriptor(NewDescriptorImpl())
42+
_ = configtxapi.ChannelConfig(NewSharedConfigImpl())
4243
}
4344

4445
func TestDoubleBegin(t *testing.T) {
@@ -48,7 +49,7 @@ func TestDoubleBegin(t *testing.T) {
4849
}
4950
}()
5051

51-
m := NewDescriptorImpl()
52+
m := NewSharedConfigImpl()
5253
m.BeginConfig()
5354
m.BeginConfig()
5455
}
@@ -60,12 +61,12 @@ func TestCommitWithoutBegin(t *testing.T) {
6061
}
6162
}()
6263

63-
m := NewDescriptorImpl()
64+
m := NewSharedConfigImpl()
6465
m.CommitConfig()
6566
}
6667

6768
func TestRollback(t *testing.T) {
68-
m := NewDescriptorImpl()
69+
m := NewSharedConfigImpl()
6970
m.pendingConfig = &chainConfig{}
7071
m.RollbackConfig()
7172
if m.pendingConfig != nil {
@@ -78,7 +79,7 @@ func TestHashingAlgorithm(t *testing.T) {
7879
invalidAlgorithm := TemplateHashingAlgorithm("MD5")
7980
validAlgorithm := DefaultHashingAlgorithm()
8081

81-
m := NewDescriptorImpl()
82+
m := NewSharedConfigImpl()
8283
m.BeginConfig()
8384

8485
err := m.ProposeConfig(invalidMessage)
@@ -108,7 +109,7 @@ func TestBlockDataHashingStructure(t *testing.T) {
108109
invalidWidth := TemplateBlockDataHashingStructure(0)
109110
validWidth := DefaultBlockDataHashingStructure()
110111

111-
m := NewDescriptorImpl()
112+
m := NewSharedConfigImpl()
112113
m.BeginConfig()
113114

114115
err := m.ProposeConfig(invalidMessage)
@@ -136,7 +137,7 @@ func TestBlockDataHashingStructure(t *testing.T) {
136137
func TestOrdererAddresses(t *testing.T) {
137138
invalidMessage := makeInvalidConfigItem(OrdererAddressesKey)
138139
validMessage := DefaultOrdererAddresses()
139-
m := NewDescriptorImpl()
140+
m := NewSharedConfigImpl()
140141
m.BeginConfig()
141142

142143
err := m.ProposeConfig(invalidMessage)

common/chainconfig/chainconfig_util.go common/configtx/handlers/channel/sharedconfig_util.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package chainconfig
17+
package channel
1818

1919
import (
2020
"math"

common/configtx/resources.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ package configtx
1818

1919
import (
2020
"github.com/hyperledger/fabric/common/cauthdsl"
21-
"github.com/hyperledger/fabric/common/chainconfig"
2221
"github.com/hyperledger/fabric/common/configtx/api"
22+
"github.com/hyperledger/fabric/common/configtx/handlers/channel"
2323
"github.com/hyperledger/fabric/common/policies"
2424
"github.com/hyperledger/fabric/msp"
2525
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
@@ -29,7 +29,7 @@ import (
2929
type resources struct {
3030
handlers map[cb.ConfigItem_ConfigType]api.Handler
3131
policyManager policies.Manager
32-
chainConfig chainconfig.Descriptor
32+
channelConfig api.ChannelConfig
3333
mspConfigHandler *mspmgmt.MSPConfigHandler
3434
}
3535

@@ -38,9 +38,9 @@ func (r *resources) PolicyManager() policies.Manager {
3838
return r.policyManager
3939
}
4040

41-
// ChainConfig returns the chainconfig.Descriptor for the chain
42-
func (r *resources) ChainConfig() chainconfig.Descriptor {
43-
return r.chainConfig
41+
// ChannelConfig returns the api.ChannelConfig for the chain
42+
func (r *resources) ChannelConfig() api.ChannelConfig {
43+
return r.channelConfig
4444
}
4545

4646
// MSPManager returns the msp.MSPManager for the chain
@@ -70,14 +70,14 @@ func NewInitializer() api.Initializer {
7070
}
7171

7272
policyManager := policies.NewManagerImpl(policyProviderMap)
73-
chainConfig := chainconfig.NewDescriptorImpl()
73+
channelConfig := channel.NewSharedConfigImpl()
7474
handlers := make(map[cb.ConfigItem_ConfigType]api.Handler)
7575

7676
for ctype := range cb.ConfigItem_ConfigType_name {
7777
rtype := cb.ConfigItem_ConfigType(ctype)
7878
switch rtype {
7979
case cb.ConfigItem_CHAIN:
80-
handlers[rtype] = chainConfig
80+
handlers[rtype] = channelConfig
8181
case cb.ConfigItem_POLICY:
8282
handlers[rtype] = policyManager
8383
case cb.ConfigItem_MSP:
@@ -90,7 +90,7 @@ func NewInitializer() api.Initializer {
9090
return &resources{
9191
handlers: handlers,
9292
policyManager: policyManager,
93-
chainConfig: chainConfig,
93+
channelConfig: channelConfig,
9494
mspConfigHandler: mspConfigHandler,
9595
}
9696
}

common/mocks/configtx/configtx.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package configtx
1818

1919
import (
20-
"github.com/hyperledger/fabric/common/chainconfig"
2120
configtxapi "github.com/hyperledger/fabric/common/configtx/api"
2221
"github.com/hyperledger/fabric/common/policies"
2322
"github.com/hyperledger/fabric/msp"
@@ -31,8 +30,8 @@ type Initializer struct {
3130
// PolicyManagerVal is returned as the result of PolicyManager()
3231
PolicyManagerVal policies.Manager
3332

34-
// ChainConfigVal is returned as the result of ChainConfig()
35-
ChainConfigVal chainconfig.Descriptor
33+
// ChannelConfigVal is returned as the result of ChannelConfig()
34+
ChannelConfigVal configtxapi.ChannelConfig
3635

3736
// MSPManagerVal is returned as the result of MSPManager()
3837
MSPManagerVal msp.MSPManager
@@ -48,9 +47,9 @@ func (i *Initializer) PolicyManager() policies.Manager {
4847
return i.PolicyManagerVal
4948
}
5049

51-
// Returns the ChainConfigVal
52-
func (i *Initializer) ChainConfig() chainconfig.Descriptor {
53-
return i.ChainConfigVal
50+
// Returns the ChannelConfigVal
51+
func (i *Initializer) ChannelConfig() configtxapi.ChannelConfig {
52+
return i.ChannelConfigVal
5453
}
5554

5655
// Returns the MSPManagerVal

common/mocks/chainconfig/chainconfig.go common/mocks/configtx/handlers/channel/sharedconfig.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package chainconfig
17+
package channel
1818

1919
import "github.com/hyperledger/fabric/common/util"
2020

2121
func nearIdentityHash(input []byte) []byte {
2222
return util.ConcatenateBytes([]byte("FakeHash("), input, []byte(""))
2323
}
2424

25-
// Descriptor is a mock implementation of sharedconfig.Descriptor
26-
type Descriptor struct {
25+
// SharedConfig is a mock implementation of sharedconfig.SharedConfig
26+
type SharedConfig struct {
2727
// HashingAlgorithmVal is returned as the result of HashingAlgorithm() if set
2828
HashingAlgorithmVal func([]byte) []byte
2929
// BlockDataHashingStructureWidthVal is returned as the result of BlockDataHashingStructureWidth()
@@ -33,19 +33,19 @@ type Descriptor struct {
3333
}
3434

3535
// HashingAlgorithm returns the HashingAlgorithmVal if set, otherwise a fake simple hash function
36-
func (scm *Descriptor) HashingAlgorithm() func([]byte) []byte {
36+
func (scm *SharedConfig) HashingAlgorithm() func([]byte) []byte {
3737
if scm.HashingAlgorithmVal == nil {
3838
return nearIdentityHash
3939
}
4040
return scm.HashingAlgorithmVal
4141
}
4242

4343
// BlockDataHashingStructureWidth returns the BlockDataHashingStructureWidthVal
44-
func (scm *Descriptor) BlockDataHashingStructureWidth() uint32 {
44+
func (scm *SharedConfig) BlockDataHashingStructureWidth() uint32 {
4545
return scm.BlockDataHashingStructureWidthVal
4646
}
4747

4848
// OrdererAddresses returns the OrdererAddressesVal
49-
func (scm *Descriptor) OrdererAddresses() []string {
49+
func (scm *SharedConfig) OrdererAddresses() []string {
5050
return scm.OrdererAddressesVal
5151
}

common/mocks/chainconfig/chainconfig_test.go common/mocks/configtx/handlers/channel/sharedconfig_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package chainconfig
17+
package channel
1818

1919
import (
2020
"testing"
2121

22-
"github.com/hyperledger/fabric/common/chainconfig"
22+
configtxapi "github.com/hyperledger/fabric/common/configtx/api"
2323
)
2424

2525
func TestChainConfigInterface(t *testing.T) {
26-
_ = chainconfig.Descriptor(&Descriptor{})
26+
_ = configtxapi.ChannelConfig(&SharedConfig{})
2727
}

0 commit comments

Comments
 (0)